]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.3-201210231942.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.3-201210231942.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 39462cf..611a556 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 @@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56 +ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60 @@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64 +builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70 +clut_vga16.c
71 +common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78 +config.c
79 config.mak
80 config.mak.autogen
81 +config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85 @@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89 +dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93 +exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97 @@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101 +gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108 +hash
109 +hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113 @@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117 -kconfig
118 +kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125 -linux
126 +lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130 @@ -163,14 +181,15 @@ machtypes.h
131 map
132 map_hugetlb
133 maui_boot.h
134 -media
135 mconf
136 +mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143 +mkpiggy
144 mkprep
145 mkregtable
146 mktables
147 @@ -187,6 +206,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151 +parse-events*
152 +pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156 @@ -196,6 +217,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -205,7 +227,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168 +realmode.lds
169 +realmode.relocs
170 recordmcount
171 +regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175 @@ -215,8 +240,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179 +size_overflow_hash.h
180 sImage
181 +slabinfo
182 sm_tbl*
183 +sortextable
184 split-include
185 syscalltab.h
186 tables.c
187 @@ -226,6 +254,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191 +user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195 @@ -237,13 +266,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199 +vdsox32.lds
200 +vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207 +vmlinux.bin.bz2
208 vmlinux.lds
209 +vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213 @@ -251,9 +284,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217 +utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223 +zconf.lex.c
224 zoffset.h
225 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226 index ad7e2e5..199f49e 100644
227 --- a/Documentation/kernel-parameters.txt
228 +++ b/Documentation/kernel-parameters.txt
229 @@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 gpt [EFI] Forces disk with valid GPT signature but
231 invalid Protective MBR to be treated as GPT.
232
233 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234 + ignore grsecurity's /proc restrictions
235 +
236 hashdist= [KNL,NUMA] Large hashes allocated during boot
237 are distributed across NUMA nodes. Defaults on
238 for 64-bit NUMA, off otherwise.
239 @@ -2050,6 +2053,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
240 the specified number of seconds. This is to be used if
241 your oopses keep scrolling off the screen.
242
243 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
244 + virtualization environments that don't cope well with the
245 + expand down segment used by UDEREF on X86-32 or the frequent
246 + page table updates on X86-64.
247 +
248 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
249 +
250 pcbit= [HW,ISDN]
251
252 pcd. [PARIDE]
253 diff --git a/Makefile b/Makefile
254 index 6cdadf4..02df425 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -561,6 +562,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -715,7 +770,7 @@ export mod_strip_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -762,6 +817,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -922,6 +980,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
395 MRPROPER_DIRS += include/config usr/include include/generated \
396 arch/*/include/generated
397 MRPROPER_FILES += .config .config.old .version .old_version \
398 - include/linux/version.h \
399 + include/linux/version.h tools/gcc/size_overflow_hash.h\
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
401
402 # clean - Delete most, but leave enough to build external modules
403 @@ -1032,6 +1092,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1326,17 +1389,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1346,11 +1413,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index bc1acdd..a922a6d 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..2255c86 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421 index e4448e1..7bc86b7 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428 -};
1429 +} __no_const;
1430
1431 /*
1432 * Select the calling method
1433 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434 index 7eb18c1..e38b6d2 100644
1435 --- a/arch/arm/include/asm/cmpxchg.h
1436 +++ b/arch/arm/include/asm/cmpxchg.h
1437 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447 index 38050b1..9d90e8b 100644
1448 --- a/arch/arm/include/asm/elf.h
1449 +++ b/arch/arm/include/asm/elf.h
1450 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456 +
1457 +#ifdef CONFIG_PAX_ASLR
1458 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459 +
1460 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462 +#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470 -struct mm_struct;
1471 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472 -#define arch_randomize_brk arch_randomize_brk
1473 -
1474 #endif
1475 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476 index 83eb2f7..ed77159 100644
1477 --- a/arch/arm/include/asm/kmap_types.h
1478 +++ b/arch/arm/include/asm/kmap_types.h
1479 @@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483 -#define KM_TYPE_NR 16
1484 +#define KM_TYPE_NR 17
1485
1486 #endif
1487 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488 index 53426c6..c7baff3 100644
1489 --- a/arch/arm/include/asm/outercache.h
1490 +++ b/arch/arm/include/asm/outercache.h
1491 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495 -};
1496 +} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501 index ecf9019..b71d9a1 100644
1502 --- a/arch/arm/include/asm/page.h
1503 +++ b/arch/arm/include/asm/page.h
1504 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508 -};
1509 +} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514 index 943504f..bf8d667 100644
1515 --- a/arch/arm/include/asm/pgalloc.h
1516 +++ b/arch/arm/include/asm/pgalloc.h
1517 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522 +{
1523 + pud_populate(mm, pud, pmd);
1524 +}
1525 +
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538 index af7b0bd..6750a8c 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1543 #define TIF_SYSCALL_TRACE 8
1544 #define TIF_SYSCALL_AUDIT 9
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 10
1550 +
1551 #define TIF_POLLING_NRFLAG 16
1552 #define TIF_USING_IWMMXT 17
1553 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1554 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1563 + _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568 index 77bd79f..ad4cd27 100644
1569 --- a/arch/arm/include/asm/uaccess.h
1570 +++ b/arch/arm/include/asm/uaccess.h
1571 @@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576 +
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580 @@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588 +
1589 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590 +{
1591 + if (!__builtin_constant_p(n))
1592 + check_object_size(to, n, false);
1593 + return ___copy_from_user(to, from, n);
1594 +}
1595 +
1596 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597 +{
1598 + if (!__builtin_constant_p(n))
1599 + check_object_size(from, n, true);
1600 + return ___copy_to_user(to, from, n);
1601 +}
1602 +
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610 + if ((long)n < 0)
1611 + return n;
1612 +
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620 + if ((long)n < 0)
1621 + return n;
1622 +
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627 index 60d3b73..9168db0 100644
1628 --- a/arch/arm/kernel/armksyms.c
1629 +++ b/arch/arm/kernel/armksyms.c
1630 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634 -EXPORT_SYMBOL(__copy_from_user);
1635 -EXPORT_SYMBOL(__copy_to_user);
1636 +EXPORT_SYMBOL(___copy_from_user);
1637 +EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642 index 693b744..e684262 100644
1643 --- a/arch/arm/kernel/process.c
1644 +++ b/arch/arm/kernel/process.c
1645 @@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649 -#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652
1653 @@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657 + BUG();
1658 }
1659
1660 -void machine_restart(char *cmd)
1661 +__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1670 -{
1671 - unsigned long range_end = mm->brk + 0x02000000;
1672 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673 -}
1674 -
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679 index 3e0fc5f..a42d2ec 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -913,11 +913,20 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686 +#ifdef CONFIG_GRKERNSEC_SETXID
1687 +extern void gr_delayed_cred_worker(void);
1688 +#endif
1689 +
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 unsigned long ip;
1694
1695 +#ifdef CONFIG_GRKERNSEC_SETXID
1696 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1697 + gr_delayed_cred_worker();
1698 +#endif
1699 +
1700 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1701 return scno;
1702
1703 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1704 index a81dcec..ac42f0f 100644
1705 --- a/arch/arm/kernel/setup.c
1706 +++ b/arch/arm/kernel/setup.c
1707 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1708 struct cpu_tlb_fns cpu_tlb __read_mostly;
1709 #endif
1710 #ifdef MULTI_USER
1711 -struct cpu_user_fns cpu_user __read_mostly;
1712 +struct cpu_user_fns cpu_user __read_only;
1713 #endif
1714 #ifdef MULTI_CACHE
1715 -struct cpu_cache_fns cpu_cache __read_mostly;
1716 +struct cpu_cache_fns cpu_cache __read_only;
1717 #endif
1718 #ifdef CONFIG_OUTER_CACHE
1719 -struct outer_cache_fns outer_cache __read_mostly;
1720 +struct outer_cache_fns outer_cache __read_only;
1721 EXPORT_SYMBOL(outer_cache);
1722 #endif
1723
1724 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1725 index b0179b8..b54c6c1 100644
1726 --- a/arch/arm/kernel/traps.c
1727 +++ b/arch/arm/kernel/traps.c
1728 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1729 static int die_owner = -1;
1730 static unsigned int die_nest_count;
1731
1732 +extern void gr_handle_kernel_exploit(void);
1733 +
1734 static unsigned long oops_begin(void)
1735 {
1736 int cpu;
1737 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1738 panic("Fatal exception in interrupt");
1739 if (panic_on_oops)
1740 panic("Fatal exception");
1741 +
1742 + gr_handle_kernel_exploit();
1743 +
1744 if (signr)
1745 do_exit(signr);
1746 }
1747 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1748 index 66a477a..bee61d3 100644
1749 --- a/arch/arm/lib/copy_from_user.S
1750 +++ b/arch/arm/lib/copy_from_user.S
1751 @@ -16,7 +16,7 @@
1752 /*
1753 * Prototype:
1754 *
1755 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1756 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1757 *
1758 * Purpose:
1759 *
1760 @@ -84,11 +84,11 @@
1761
1762 .text
1763
1764 -ENTRY(__copy_from_user)
1765 +ENTRY(___copy_from_user)
1766
1767 #include "copy_template.S"
1768
1769 -ENDPROC(__copy_from_user)
1770 +ENDPROC(___copy_from_user)
1771
1772 .pushsection .fixup,"ax"
1773 .align 0
1774 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1775 index 6ee2f67..d1cce76 100644
1776 --- a/arch/arm/lib/copy_page.S
1777 +++ b/arch/arm/lib/copy_page.S
1778 @@ -10,6 +10,7 @@
1779 * ASM optimised string functions
1780 */
1781 #include <linux/linkage.h>
1782 +#include <linux/const.h>
1783 #include <asm/assembler.h>
1784 #include <asm/asm-offsets.h>
1785 #include <asm/cache.h>
1786 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1787 index d066df6..df28194 100644
1788 --- a/arch/arm/lib/copy_to_user.S
1789 +++ b/arch/arm/lib/copy_to_user.S
1790 @@ -16,7 +16,7 @@
1791 /*
1792 * Prototype:
1793 *
1794 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1795 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1796 *
1797 * Purpose:
1798 *
1799 @@ -88,11 +88,11 @@
1800 .text
1801
1802 ENTRY(__copy_to_user_std)
1803 -WEAK(__copy_to_user)
1804 +WEAK(___copy_to_user)
1805
1806 #include "copy_template.S"
1807
1808 -ENDPROC(__copy_to_user)
1809 +ENDPROC(___copy_to_user)
1810 ENDPROC(__copy_to_user_std)
1811
1812 .pushsection .fixup,"ax"
1813 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1814 index 025f742..8432b08 100644
1815 --- a/arch/arm/lib/uaccess_with_memcpy.c
1816 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1817 @@ -104,7 +104,7 @@ out:
1818 }
1819
1820 unsigned long
1821 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1822 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1823 {
1824 /*
1825 * This test is stubbed out of the main function above to keep
1826 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1827 index 1201191..eabbb2c 100644
1828 --- a/arch/arm/mach-kirkwood/common.c
1829 +++ b/arch/arm/mach-kirkwood/common.c
1830 @@ -160,7 +160,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1831 clk_gate_ops.disable(hw);
1832 }
1833
1834 -static struct clk_ops clk_gate_fn_ops;
1835 +static clk_ops_no_const clk_gate_fn_ops;
1836
1837 static struct clk __init *clk_register_gate_fn(struct device *dev,
1838 const char *name,
1839 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1840 index 677357f..8828dda 100644
1841 --- a/arch/arm/mach-omap2/board-n8x0.c
1842 +++ b/arch/arm/mach-omap2/board-n8x0.c
1843 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1844 }
1845 #endif
1846
1847 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1848 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1849 .late_init = n8x0_menelaus_late_init,
1850 };
1851
1852 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1853 index c3bd834..e81ef02 100644
1854 --- a/arch/arm/mm/fault.c
1855 +++ b/arch/arm/mm/fault.c
1856 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1857 }
1858 #endif
1859
1860 +#ifdef CONFIG_PAX_PAGEEXEC
1861 + if (fsr & FSR_LNX_PF) {
1862 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1863 + do_group_exit(SIGKILL);
1864 + }
1865 +#endif
1866 +
1867 tsk->thread.address = addr;
1868 tsk->thread.error_code = fsr;
1869 tsk->thread.trap_no = 14;
1870 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1871 }
1872 #endif /* CONFIG_MMU */
1873
1874 +#ifdef CONFIG_PAX_PAGEEXEC
1875 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1876 +{
1877 + long i;
1878 +
1879 + printk(KERN_ERR "PAX: bytes at PC: ");
1880 + for (i = 0; i < 20; i++) {
1881 + unsigned char c;
1882 + if (get_user(c, (__force unsigned char __user *)pc+i))
1883 + printk(KERN_CONT "?? ");
1884 + else
1885 + printk(KERN_CONT "%02x ", c);
1886 + }
1887 + printk("\n");
1888 +
1889 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1890 + for (i = -1; i < 20; i++) {
1891 + unsigned long c;
1892 + if (get_user(c, (__force unsigned long __user *)sp+i))
1893 + printk(KERN_CONT "???????? ");
1894 + else
1895 + printk(KERN_CONT "%08lx ", c);
1896 + }
1897 + printk("\n");
1898 +}
1899 +#endif
1900 +
1901 /*
1902 * First Level Translation Fault Handler
1903 *
1904 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1905 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1906 struct siginfo info;
1907
1908 +#ifdef CONFIG_PAX_REFCOUNT
1909 + if (fsr_fs(ifsr) == 2) {
1910 + unsigned int bkpt;
1911 +
1912 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1913 + current->thread.error_code = ifsr;
1914 + current->thread.trap_no = 0;
1915 + pax_report_refcount_overflow(regs);
1916 + fixup_exception(regs);
1917 + return;
1918 + }
1919 + }
1920 +#endif
1921 +
1922 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1923 return;
1924
1925 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1926 index ce8cb19..3ec539d 100644
1927 --- a/arch/arm/mm/mmap.c
1928 +++ b/arch/arm/mm/mmap.c
1929 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1930 if (len > TASK_SIZE)
1931 return -ENOMEM;
1932
1933 +#ifdef CONFIG_PAX_RANDMMAP
1934 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1935 +#endif
1936 +
1937 if (addr) {
1938 if (do_align)
1939 addr = COLOUR_ALIGN(addr, pgoff);
1940 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1941 addr = PAGE_ALIGN(addr);
1942
1943 vma = find_vma(mm, addr);
1944 - if (TASK_SIZE - len >= addr &&
1945 - (!vma || addr + len <= vma->vm_start))
1946 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1947 return addr;
1948 }
1949 if (len > mm->cached_hole_size) {
1950 - start_addr = addr = mm->free_area_cache;
1951 + start_addr = addr = mm->free_area_cache;
1952 } else {
1953 - start_addr = addr = mm->mmap_base;
1954 - mm->cached_hole_size = 0;
1955 + start_addr = addr = mm->mmap_base;
1956 + mm->cached_hole_size = 0;
1957 }
1958
1959 full_search:
1960 @@ -124,14 +127,14 @@ full_search:
1961 * Start a new search - just in case we missed
1962 * some holes.
1963 */
1964 - if (start_addr != TASK_UNMAPPED_BASE) {
1965 - start_addr = addr = TASK_UNMAPPED_BASE;
1966 + if (start_addr != mm->mmap_base) {
1967 + start_addr = addr = mm->mmap_base;
1968 mm->cached_hole_size = 0;
1969 goto full_search;
1970 }
1971 return -ENOMEM;
1972 }
1973 - if (!vma || addr + len <= vma->vm_start) {
1974 + if (check_heap_stack_gap(vma, addr, len)) {
1975 /*
1976 * Remember the place where we stopped the search:
1977 */
1978 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1979
1980 if (mmap_is_legacy()) {
1981 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1982 +
1983 +#ifdef CONFIG_PAX_RANDMMAP
1984 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1985 + mm->mmap_base += mm->delta_mmap;
1986 +#endif
1987 +
1988 mm->get_unmapped_area = arch_get_unmapped_area;
1989 mm->unmap_area = arch_unmap_area;
1990 } else {
1991 mm->mmap_base = mmap_base(random_factor);
1992 +
1993 +#ifdef CONFIG_PAX_RANDMMAP
1994 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1995 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1996 +#endif
1997 +
1998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1999 mm->unmap_area = arch_unmap_area_topdown;
2000 }
2001 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2002 index fd556f7..af2e7d2 100644
2003 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2004 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2005 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2006 value in bridge_virt_base */
2007 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2008 const int win);
2009 -};
2010 +} __no_const;
2011
2012 /*
2013 * Information needed to setup one address mapping.
2014 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2015 index f5144cd..71f6d1f 100644
2016 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2017 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2018 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2019 int (*started)(unsigned ch);
2020 int (*flush)(unsigned ch);
2021 int (*stop)(unsigned ch);
2022 -};
2023 +} __no_const;
2024
2025 extern void *samsung_dmadev_get_ops(void);
2026 extern void *s3c_dma_get_ops(void);
2027 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2028 index 5f28cae..3d23723 100644
2029 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2030 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2031 @@ -14,7 +14,7 @@
2032 struct s5p_ehci_platdata {
2033 int (*phy_init)(struct platform_device *pdev, int type);
2034 int (*phy_exit)(struct platform_device *pdev, int type);
2035 -};
2036 +} __no_const;
2037
2038 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2039
2040 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2041 index c3a58a1..78fbf54 100644
2042 --- a/arch/avr32/include/asm/cache.h
2043 +++ b/arch/avr32/include/asm/cache.h
2044 @@ -1,8 +1,10 @@
2045 #ifndef __ASM_AVR32_CACHE_H
2046 #define __ASM_AVR32_CACHE_H
2047
2048 +#include <linux/const.h>
2049 +
2050 #define L1_CACHE_SHIFT 5
2051 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2052 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2053
2054 /*
2055 * Memory returned by kmalloc() may be used for DMA, so we must make
2056 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2057 index 3b3159b..425ea94 100644
2058 --- a/arch/avr32/include/asm/elf.h
2059 +++ b/arch/avr32/include/asm/elf.h
2060 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2061 the loader. We need to make sure that it is out of the way of the program
2062 that it will "exec", and that there is sufficient room for the brk. */
2063
2064 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2065 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2066
2067 +#ifdef CONFIG_PAX_ASLR
2068 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2069 +
2070 +#define PAX_DELTA_MMAP_LEN 15
2071 +#define PAX_DELTA_STACK_LEN 15
2072 +#endif
2073
2074 /* This yields a mask that user programs can use to figure out what
2075 instruction set this CPU supports. This could be done in user space,
2076 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2077 index 479330b..53717a8 100644
2078 --- a/arch/avr32/include/asm/kmap_types.h
2079 +++ b/arch/avr32/include/asm/kmap_types.h
2080 @@ -2,9 +2,9 @@
2081 #define __ASM_AVR32_KMAP_TYPES_H
2082
2083 #ifdef CONFIG_DEBUG_HIGHMEM
2084 -# define KM_TYPE_NR 29
2085 +# define KM_TYPE_NR 30
2086 #else
2087 -# define KM_TYPE_NR 14
2088 +# define KM_TYPE_NR 15
2089 #endif
2090
2091 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2092 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2093 index b92e609..b69c101 100644
2094 --- a/arch/avr32/mm/fault.c
2095 +++ b/arch/avr32/mm/fault.c
2096 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2097
2098 int exception_trace = 1;
2099
2100 +#ifdef CONFIG_PAX_PAGEEXEC
2101 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2102 +{
2103 + unsigned long i;
2104 +
2105 + printk(KERN_ERR "PAX: bytes at PC: ");
2106 + for (i = 0; i < 20; i++) {
2107 + unsigned char c;
2108 + if (get_user(c, (unsigned char *)pc+i))
2109 + printk(KERN_CONT "???????? ");
2110 + else
2111 + printk(KERN_CONT "%02x ", c);
2112 + }
2113 + printk("\n");
2114 +}
2115 +#endif
2116 +
2117 /*
2118 * This routine handles page faults. It determines the address and the
2119 * problem, and then passes it off to one of the appropriate routines.
2120 @@ -173,6 +190,16 @@ bad_area:
2121 up_read(&mm->mmap_sem);
2122
2123 if (user_mode(regs)) {
2124 +
2125 +#ifdef CONFIG_PAX_PAGEEXEC
2126 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2127 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2128 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2129 + do_group_exit(SIGKILL);
2130 + }
2131 + }
2132 +#endif
2133 +
2134 if (exception_trace && printk_ratelimit())
2135 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2136 "sp %08lx ecr %lu\n",
2137 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2138 index 568885a..f8008df 100644
2139 --- a/arch/blackfin/include/asm/cache.h
2140 +++ b/arch/blackfin/include/asm/cache.h
2141 @@ -7,6 +7,7 @@
2142 #ifndef __ARCH_BLACKFIN_CACHE_H
2143 #define __ARCH_BLACKFIN_CACHE_H
2144
2145 +#include <linux/const.h>
2146 #include <linux/linkage.h> /* for asmlinkage */
2147
2148 /*
2149 @@ -14,7 +15,7 @@
2150 * Blackfin loads 32 bytes for cache
2151 */
2152 #define L1_CACHE_SHIFT 5
2153 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2154 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2155 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2156
2157 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2158 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2159 index aea2718..3639a60 100644
2160 --- a/arch/cris/include/arch-v10/arch/cache.h
2161 +++ b/arch/cris/include/arch-v10/arch/cache.h
2162 @@ -1,8 +1,9 @@
2163 #ifndef _ASM_ARCH_CACHE_H
2164 #define _ASM_ARCH_CACHE_H
2165
2166 +#include <linux/const.h>
2167 /* Etrax 100LX have 32-byte cache-lines. */
2168 -#define L1_CACHE_BYTES 32
2169 #define L1_CACHE_SHIFT 5
2170 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2171
2172 #endif /* _ASM_ARCH_CACHE_H */
2173 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2174 index 7caf25d..ee65ac5 100644
2175 --- a/arch/cris/include/arch-v32/arch/cache.h
2176 +++ b/arch/cris/include/arch-v32/arch/cache.h
2177 @@ -1,11 +1,12 @@
2178 #ifndef _ASM_CRIS_ARCH_CACHE_H
2179 #define _ASM_CRIS_ARCH_CACHE_H
2180
2181 +#include <linux/const.h>
2182 #include <arch/hwregs/dma.h>
2183
2184 /* A cache-line is 32 bytes. */
2185 -#define L1_CACHE_BYTES 32
2186 #define L1_CACHE_SHIFT 5
2187 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2188
2189 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2190
2191 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2192 index b86329d..6709906 100644
2193 --- a/arch/frv/include/asm/atomic.h
2194 +++ b/arch/frv/include/asm/atomic.h
2195 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2196 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2197 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2198
2199 +#define atomic64_read_unchecked(v) atomic64_read(v)
2200 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2201 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2202 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2203 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2204 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2205 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2206 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2207 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2208 +
2209 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2210 {
2211 int c, old;
2212 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2213 index 2797163..c2a401d 100644
2214 --- a/arch/frv/include/asm/cache.h
2215 +++ b/arch/frv/include/asm/cache.h
2216 @@ -12,10 +12,11 @@
2217 #ifndef __ASM_CACHE_H
2218 #define __ASM_CACHE_H
2219
2220 +#include <linux/const.h>
2221
2222 /* bytes per L1 cache line */
2223 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2224 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2225 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2226
2227 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2228 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2229 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2230 index 43901f2..0d8b865 100644
2231 --- a/arch/frv/include/asm/kmap_types.h
2232 +++ b/arch/frv/include/asm/kmap_types.h
2233 @@ -2,6 +2,6 @@
2234 #ifndef _ASM_KMAP_TYPES_H
2235 #define _ASM_KMAP_TYPES_H
2236
2237 -#define KM_TYPE_NR 17
2238 +#define KM_TYPE_NR 18
2239
2240 #endif
2241 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2242 index 385fd30..6c3d97e 100644
2243 --- a/arch/frv/mm/elf-fdpic.c
2244 +++ b/arch/frv/mm/elf-fdpic.c
2245 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2246 if (addr) {
2247 addr = PAGE_ALIGN(addr);
2248 vma = find_vma(current->mm, addr);
2249 - if (TASK_SIZE - len >= addr &&
2250 - (!vma || addr + len <= vma->vm_start))
2251 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2252 goto success;
2253 }
2254
2255 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2256 for (; vma; vma = vma->vm_next) {
2257 if (addr > limit)
2258 break;
2259 - if (addr + len <= vma->vm_start)
2260 + if (check_heap_stack_gap(vma, addr, len))
2261 goto success;
2262 addr = vma->vm_end;
2263 }
2264 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2265 for (; vma; vma = vma->vm_next) {
2266 if (addr > limit)
2267 break;
2268 - if (addr + len <= vma->vm_start)
2269 + if (check_heap_stack_gap(vma, addr, len))
2270 goto success;
2271 addr = vma->vm_end;
2272 }
2273 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2274 index c635028..6d9445a 100644
2275 --- a/arch/h8300/include/asm/cache.h
2276 +++ b/arch/h8300/include/asm/cache.h
2277 @@ -1,8 +1,10 @@
2278 #ifndef __ARCH_H8300_CACHE_H
2279 #define __ARCH_H8300_CACHE_H
2280
2281 +#include <linux/const.h>
2282 +
2283 /* bytes per L1 cache line */
2284 -#define L1_CACHE_BYTES 4
2285 +#define L1_CACHE_BYTES _AC(4,UL)
2286
2287 /* m68k-elf-gcc 2.95.2 doesn't like these */
2288
2289 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2290 index 0f01de2..d37d309 100644
2291 --- a/arch/hexagon/include/asm/cache.h
2292 +++ b/arch/hexagon/include/asm/cache.h
2293 @@ -21,9 +21,11 @@
2294 #ifndef __ASM_CACHE_H
2295 #define __ASM_CACHE_H
2296
2297 +#include <linux/const.h>
2298 +
2299 /* Bytes per L1 cache line */
2300 -#define L1_CACHE_SHIFT (5)
2301 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2302 +#define L1_CACHE_SHIFT 5
2303 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2304
2305 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2306 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2307 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2308 index 6e6fe18..a6ae668 100644
2309 --- a/arch/ia64/include/asm/atomic.h
2310 +++ b/arch/ia64/include/asm/atomic.h
2311 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2312 #define atomic64_inc(v) atomic64_add(1, (v))
2313 #define atomic64_dec(v) atomic64_sub(1, (v))
2314
2315 +#define atomic64_read_unchecked(v) atomic64_read(v)
2316 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2317 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2318 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2319 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2320 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2321 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2322 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2323 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2324 +
2325 /* Atomic operations are already serializing */
2326 #define smp_mb__before_atomic_dec() barrier()
2327 #define smp_mb__after_atomic_dec() barrier()
2328 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2329 index 988254a..e1ee885 100644
2330 --- a/arch/ia64/include/asm/cache.h
2331 +++ b/arch/ia64/include/asm/cache.h
2332 @@ -1,6 +1,7 @@
2333 #ifndef _ASM_IA64_CACHE_H
2334 #define _ASM_IA64_CACHE_H
2335
2336 +#include <linux/const.h>
2337
2338 /*
2339 * Copyright (C) 1998-2000 Hewlett-Packard Co
2340 @@ -9,7 +10,7 @@
2341
2342 /* Bytes per L1 (data) cache line. */
2343 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2344 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2345 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2346
2347 #ifdef CONFIG_SMP
2348 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2349 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2350 index b5298eb..67c6e62 100644
2351 --- a/arch/ia64/include/asm/elf.h
2352 +++ b/arch/ia64/include/asm/elf.h
2353 @@ -42,6 +42,13 @@
2354 */
2355 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2356
2357 +#ifdef CONFIG_PAX_ASLR
2358 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2359 +
2360 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2361 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2362 +#endif
2363 +
2364 #define PT_IA_64_UNWIND 0x70000001
2365
2366 /* IA-64 relocations: */
2367 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2368 index 96a8d92..617a1cf 100644
2369 --- a/arch/ia64/include/asm/pgalloc.h
2370 +++ b/arch/ia64/include/asm/pgalloc.h
2371 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2372 pgd_val(*pgd_entry) = __pa(pud);
2373 }
2374
2375 +static inline void
2376 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2377 +{
2378 + pgd_populate(mm, pgd_entry, pud);
2379 +}
2380 +
2381 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2382 {
2383 return quicklist_alloc(0, GFP_KERNEL, NULL);
2384 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2385 pud_val(*pud_entry) = __pa(pmd);
2386 }
2387
2388 +static inline void
2389 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2390 +{
2391 + pud_populate(mm, pud_entry, pmd);
2392 +}
2393 +
2394 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2395 {
2396 return quicklist_alloc(0, GFP_KERNEL, NULL);
2397 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2398 index 815810c..d60bd4c 100644
2399 --- a/arch/ia64/include/asm/pgtable.h
2400 +++ b/arch/ia64/include/asm/pgtable.h
2401 @@ -12,7 +12,7 @@
2402 * David Mosberger-Tang <davidm@hpl.hp.com>
2403 */
2404
2405 -
2406 +#include <linux/const.h>
2407 #include <asm/mman.h>
2408 #include <asm/page.h>
2409 #include <asm/processor.h>
2410 @@ -142,6 +142,17 @@
2411 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2412 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2413 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2414 +
2415 +#ifdef CONFIG_PAX_PAGEEXEC
2416 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2417 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2418 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2419 +#else
2420 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2421 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2422 +# define PAGE_COPY_NOEXEC PAGE_COPY
2423 +#endif
2424 +
2425 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2426 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2427 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2428 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2429 index 54ff557..70c88b7 100644
2430 --- a/arch/ia64/include/asm/spinlock.h
2431 +++ b/arch/ia64/include/asm/spinlock.h
2432 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2433 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2434
2435 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2436 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2437 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2438 }
2439
2440 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2441 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2442 index 449c8c0..432a3d2 100644
2443 --- a/arch/ia64/include/asm/uaccess.h
2444 +++ b/arch/ia64/include/asm/uaccess.h
2445 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2446 const void *__cu_from = (from); \
2447 long __cu_len = (n); \
2448 \
2449 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2450 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2451 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2452 __cu_len; \
2453 })
2454 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2455 long __cu_len = (n); \
2456 \
2457 __chk_user_ptr(__cu_from); \
2458 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2459 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2460 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2461 __cu_len; \
2462 })
2463 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2464 index 24603be..948052d 100644
2465 --- a/arch/ia64/kernel/module.c
2466 +++ b/arch/ia64/kernel/module.c
2467 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2468 void
2469 module_free (struct module *mod, void *module_region)
2470 {
2471 - if (mod && mod->arch.init_unw_table &&
2472 - module_region == mod->module_init) {
2473 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2474 unw_remove_unwind_table(mod->arch.init_unw_table);
2475 mod->arch.init_unw_table = NULL;
2476 }
2477 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2478 }
2479
2480 static inline int
2481 +in_init_rx (const struct module *mod, uint64_t addr)
2482 +{
2483 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2484 +}
2485 +
2486 +static inline int
2487 +in_init_rw (const struct module *mod, uint64_t addr)
2488 +{
2489 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2490 +}
2491 +
2492 +static inline int
2493 in_init (const struct module *mod, uint64_t addr)
2494 {
2495 - return addr - (uint64_t) mod->module_init < mod->init_size;
2496 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2497 +}
2498 +
2499 +static inline int
2500 +in_core_rx (const struct module *mod, uint64_t addr)
2501 +{
2502 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2503 +}
2504 +
2505 +static inline int
2506 +in_core_rw (const struct module *mod, uint64_t addr)
2507 +{
2508 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2509 }
2510
2511 static inline int
2512 in_core (const struct module *mod, uint64_t addr)
2513 {
2514 - return addr - (uint64_t) mod->module_core < mod->core_size;
2515 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2516 }
2517
2518 static inline int
2519 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2520 break;
2521
2522 case RV_BDREL:
2523 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2524 + if (in_init_rx(mod, val))
2525 + val -= (uint64_t) mod->module_init_rx;
2526 + else if (in_init_rw(mod, val))
2527 + val -= (uint64_t) mod->module_init_rw;
2528 + else if (in_core_rx(mod, val))
2529 + val -= (uint64_t) mod->module_core_rx;
2530 + else if (in_core_rw(mod, val))
2531 + val -= (uint64_t) mod->module_core_rw;
2532 break;
2533
2534 case RV_LTV:
2535 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2536 * addresses have been selected...
2537 */
2538 uint64_t gp;
2539 - if (mod->core_size > MAX_LTOFF)
2540 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2541 /*
2542 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2543 * at the end of the module.
2544 */
2545 - gp = mod->core_size - MAX_LTOFF / 2;
2546 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2547 else
2548 - gp = mod->core_size / 2;
2549 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2550 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2551 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2552 mod->arch.gp = gp;
2553 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2554 }
2555 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2556 index d9439ef..b9a4303 100644
2557 --- a/arch/ia64/kernel/sys_ia64.c
2558 +++ b/arch/ia64/kernel/sys_ia64.c
2559 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2560 if (REGION_NUMBER(addr) == RGN_HPAGE)
2561 addr = 0;
2562 #endif
2563 +
2564 +#ifdef CONFIG_PAX_RANDMMAP
2565 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2566 + addr = mm->free_area_cache;
2567 + else
2568 +#endif
2569 +
2570 if (!addr)
2571 addr = mm->free_area_cache;
2572
2573 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2574 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2575 /* At this point: (!vma || addr < vma->vm_end). */
2576 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2577 - if (start_addr != TASK_UNMAPPED_BASE) {
2578 + if (start_addr != mm->mmap_base) {
2579 /* Start a new search --- just in case we missed some holes. */
2580 - addr = TASK_UNMAPPED_BASE;
2581 + addr = mm->mmap_base;
2582 goto full_search;
2583 }
2584 return -ENOMEM;
2585 }
2586 - if (!vma || addr + len <= vma->vm_start) {
2587 + if (check_heap_stack_gap(vma, addr, len)) {
2588 /* Remember the address where we stopped this search: */
2589 mm->free_area_cache = addr + len;
2590 return addr;
2591 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2592 index 0ccb28f..8992469 100644
2593 --- a/arch/ia64/kernel/vmlinux.lds.S
2594 +++ b/arch/ia64/kernel/vmlinux.lds.S
2595 @@ -198,7 +198,7 @@ SECTIONS {
2596 /* Per-cpu data: */
2597 . = ALIGN(PERCPU_PAGE_SIZE);
2598 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2599 - __phys_per_cpu_start = __per_cpu_load;
2600 + __phys_per_cpu_start = per_cpu_load;
2601 /*
2602 * ensure percpu data fits
2603 * into percpu page size
2604 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2605 index 8443daf..0a01e30 100644
2606 --- a/arch/ia64/mm/fault.c
2607 +++ b/arch/ia64/mm/fault.c
2608 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2609 return pte_present(pte);
2610 }
2611
2612 +#ifdef CONFIG_PAX_PAGEEXEC
2613 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2614 +{
2615 + unsigned long i;
2616 +
2617 + printk(KERN_ERR "PAX: bytes at PC: ");
2618 + for (i = 0; i < 8; i++) {
2619 + unsigned int c;
2620 + if (get_user(c, (unsigned int *)pc+i))
2621 + printk(KERN_CONT "???????? ");
2622 + else
2623 + printk(KERN_CONT "%08x ", c);
2624 + }
2625 + printk("\n");
2626 +}
2627 +#endif
2628 +
2629 # define VM_READ_BIT 0
2630 # define VM_WRITE_BIT 1
2631 # define VM_EXEC_BIT 2
2632 @@ -149,8 +166,21 @@ retry:
2633 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2634 goto bad_area;
2635
2636 - if ((vma->vm_flags & mask) != mask)
2637 + if ((vma->vm_flags & mask) != mask) {
2638 +
2639 +#ifdef CONFIG_PAX_PAGEEXEC
2640 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2641 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2642 + goto bad_area;
2643 +
2644 + up_read(&mm->mmap_sem);
2645 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2646 + do_group_exit(SIGKILL);
2647 + }
2648 +#endif
2649 +
2650 goto bad_area;
2651 + }
2652
2653 /*
2654 * If for any reason at all we couldn't handle the fault, make
2655 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2656 index 5ca674b..e0e1b70 100644
2657 --- a/arch/ia64/mm/hugetlbpage.c
2658 +++ b/arch/ia64/mm/hugetlbpage.c
2659 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2660 /* At this point: (!vmm || addr < vmm->vm_end). */
2661 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2662 return -ENOMEM;
2663 - if (!vmm || (addr + len) <= vmm->vm_start)
2664 + if (check_heap_stack_gap(vmm, addr, len))
2665 return addr;
2666 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2667 }
2668 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2669 index 0eab454..bd794f2 100644
2670 --- a/arch/ia64/mm/init.c
2671 +++ b/arch/ia64/mm/init.c
2672 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2673 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2674 vma->vm_end = vma->vm_start + PAGE_SIZE;
2675 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2676 +
2677 +#ifdef CONFIG_PAX_PAGEEXEC
2678 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2679 + vma->vm_flags &= ~VM_EXEC;
2680 +
2681 +#ifdef CONFIG_PAX_MPROTECT
2682 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2683 + vma->vm_flags &= ~VM_MAYEXEC;
2684 +#endif
2685 +
2686 + }
2687 +#endif
2688 +
2689 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2690 down_write(&current->mm->mmap_sem);
2691 if (insert_vm_struct(current->mm, vma)) {
2692 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2693 index 40b3ee9..8c2c112 100644
2694 --- a/arch/m32r/include/asm/cache.h
2695 +++ b/arch/m32r/include/asm/cache.h
2696 @@ -1,8 +1,10 @@
2697 #ifndef _ASM_M32R_CACHE_H
2698 #define _ASM_M32R_CACHE_H
2699
2700 +#include <linux/const.h>
2701 +
2702 /* L1 cache line size */
2703 #define L1_CACHE_SHIFT 4
2704 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2705 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2706
2707 #endif /* _ASM_M32R_CACHE_H */
2708 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2709 index 82abd15..d95ae5d 100644
2710 --- a/arch/m32r/lib/usercopy.c
2711 +++ b/arch/m32r/lib/usercopy.c
2712 @@ -14,6 +14,9 @@
2713 unsigned long
2714 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2715 {
2716 + if ((long)n < 0)
2717 + return n;
2718 +
2719 prefetch(from);
2720 if (access_ok(VERIFY_WRITE, to, n))
2721 __copy_user(to,from,n);
2722 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2723 unsigned long
2724 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2725 {
2726 + if ((long)n < 0)
2727 + return n;
2728 +
2729 prefetchw(to);
2730 if (access_ok(VERIFY_READ, from, n))
2731 __copy_user_zeroing(to,from,n);
2732 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2733 index 0395c51..5f26031 100644
2734 --- a/arch/m68k/include/asm/cache.h
2735 +++ b/arch/m68k/include/asm/cache.h
2736 @@ -4,9 +4,11 @@
2737 #ifndef __ARCH_M68K_CACHE_H
2738 #define __ARCH_M68K_CACHE_H
2739
2740 +#include <linux/const.h>
2741 +
2742 /* bytes per L1 cache line */
2743 #define L1_CACHE_SHIFT 4
2744 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2745 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2746
2747 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2748
2749 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2750 index 4efe96a..60e8699 100644
2751 --- a/arch/microblaze/include/asm/cache.h
2752 +++ b/arch/microblaze/include/asm/cache.h
2753 @@ -13,11 +13,12 @@
2754 #ifndef _ASM_MICROBLAZE_CACHE_H
2755 #define _ASM_MICROBLAZE_CACHE_H
2756
2757 +#include <linux/const.h>
2758 #include <asm/registers.h>
2759
2760 #define L1_CACHE_SHIFT 5
2761 /* word-granular cache in microblaze */
2762 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2763 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2764
2765 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2766
2767 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2768 index 3f4c5cb..3439c6e 100644
2769 --- a/arch/mips/include/asm/atomic.h
2770 +++ b/arch/mips/include/asm/atomic.h
2771 @@ -21,6 +21,10 @@
2772 #include <asm/cmpxchg.h>
2773 #include <asm/war.h>
2774
2775 +#ifdef CONFIG_GENERIC_ATOMIC64
2776 +#include <asm-generic/atomic64.h>
2777 +#endif
2778 +
2779 #define ATOMIC_INIT(i) { (i) }
2780
2781 /*
2782 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2783 */
2784 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2785
2786 +#define atomic64_read_unchecked(v) atomic64_read(v)
2787 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2788 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2789 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2790 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2791 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2792 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2793 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2794 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2795 +
2796 #endif /* CONFIG_64BIT */
2797
2798 /*
2799 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2800 index b4db69f..8f3b093 100644
2801 --- a/arch/mips/include/asm/cache.h
2802 +++ b/arch/mips/include/asm/cache.h
2803 @@ -9,10 +9,11 @@
2804 #ifndef _ASM_CACHE_H
2805 #define _ASM_CACHE_H
2806
2807 +#include <linux/const.h>
2808 #include <kmalloc.h>
2809
2810 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2811 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2812 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2813
2814 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2815 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2816 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2817 index 455c0ac..ad65fbe 100644
2818 --- a/arch/mips/include/asm/elf.h
2819 +++ b/arch/mips/include/asm/elf.h
2820 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2821 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2822 #endif
2823
2824 +#ifdef CONFIG_PAX_ASLR
2825 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2826 +
2827 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2828 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2829 +#endif
2830 +
2831 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2832 struct linux_binprm;
2833 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2834 int uses_interp);
2835
2836 -struct mm_struct;
2837 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2838 -#define arch_randomize_brk arch_randomize_brk
2839 -
2840 #endif /* _ASM_ELF_H */
2841 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2842 index c1f6afa..38cc6e9 100644
2843 --- a/arch/mips/include/asm/exec.h
2844 +++ b/arch/mips/include/asm/exec.h
2845 @@ -12,6 +12,6 @@
2846 #ifndef _ASM_EXEC_H
2847 #define _ASM_EXEC_H
2848
2849 -extern unsigned long arch_align_stack(unsigned long sp);
2850 +#define arch_align_stack(x) ((x) & ~0xfUL)
2851
2852 #endif /* _ASM_EXEC_H */
2853 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2854 index da9bd7d..91aa7ab 100644
2855 --- a/arch/mips/include/asm/page.h
2856 +++ b/arch/mips/include/asm/page.h
2857 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2858 #ifdef CONFIG_CPU_MIPS32
2859 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2860 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2861 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2862 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2863 #else
2864 typedef struct { unsigned long long pte; } pte_t;
2865 #define pte_val(x) ((x).pte)
2866 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2867 index 881d18b..cea38bc 100644
2868 --- a/arch/mips/include/asm/pgalloc.h
2869 +++ b/arch/mips/include/asm/pgalloc.h
2870 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2871 {
2872 set_pud(pud, __pud((unsigned long)pmd));
2873 }
2874 +
2875 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2876 +{
2877 + pud_populate(mm, pud, pmd);
2878 +}
2879 #endif
2880
2881 /*
2882 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2883 index ca97e0e..cd08920 100644
2884 --- a/arch/mips/include/asm/thread_info.h
2885 +++ b/arch/mips/include/asm/thread_info.h
2886 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2887 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2888 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2889 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2890 +/* li takes a 32bit immediate */
2891 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2892 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2893
2894 #ifdef CONFIG_MIPS32_O32
2895 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2896 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2897 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2898 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2899 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2900 +
2901 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2902
2903 /* work to do in syscall_trace_leave() */
2904 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2905 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2906
2907 /* work to do on interrupt/exception return */
2908 #define _TIF_WORK_MASK (0x0000ffef & \
2909 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2910 /* work to do on any return to u-space */
2911 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2912 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2913
2914 #endif /* __KERNEL__ */
2915
2916 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2917 index 9fdd8bc..4bd7f1a 100644
2918 --- a/arch/mips/kernel/binfmt_elfn32.c
2919 +++ b/arch/mips/kernel/binfmt_elfn32.c
2920 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2921 #undef ELF_ET_DYN_BASE
2922 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2923
2924 +#ifdef CONFIG_PAX_ASLR
2925 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2926 +
2927 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2928 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2929 +#endif
2930 +
2931 #include <asm/processor.h>
2932 #include <linux/module.h>
2933 #include <linux/elfcore.h>
2934 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2935 index ff44823..97f8906 100644
2936 --- a/arch/mips/kernel/binfmt_elfo32.c
2937 +++ b/arch/mips/kernel/binfmt_elfo32.c
2938 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2939 #undef ELF_ET_DYN_BASE
2940 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2941
2942 +#ifdef CONFIG_PAX_ASLR
2943 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2944 +
2945 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2947 +#endif
2948 +
2949 #include <asm/processor.h>
2950
2951 /*
2952 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2953 index e9a5fd7..378809a 100644
2954 --- a/arch/mips/kernel/process.c
2955 +++ b/arch/mips/kernel/process.c
2956 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2957 out:
2958 return pc;
2959 }
2960 -
2961 -/*
2962 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2963 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2964 - */
2965 -unsigned long arch_align_stack(unsigned long sp)
2966 -{
2967 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2968 - sp -= get_random_int() & ~PAGE_MASK;
2969 -
2970 - return sp & ALMASK;
2971 -}
2972 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2973 index 4812c6d..2069554 100644
2974 --- a/arch/mips/kernel/ptrace.c
2975 +++ b/arch/mips/kernel/ptrace.c
2976 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2977 return arch;
2978 }
2979
2980 +#ifdef CONFIG_GRKERNSEC_SETXID
2981 +extern void gr_delayed_cred_worker(void);
2982 +#endif
2983 +
2984 /*
2985 * Notification of system call entry/exit
2986 * - triggered by current->work.syscall_trace
2987 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2988 /* do the secure computing check first */
2989 secure_computing_strict(regs->regs[2]);
2990
2991 +#ifdef CONFIG_GRKERNSEC_SETXID
2992 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2993 + gr_delayed_cred_worker();
2994 +#endif
2995 +
2996 if (!(current->ptrace & PT_PTRACED))
2997 goto out;
2998
2999 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3000 index a632bc1..0b77c7c 100644
3001 --- a/arch/mips/kernel/scall32-o32.S
3002 +++ b/arch/mips/kernel/scall32-o32.S
3003 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3004
3005 stack_done:
3006 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3007 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3008 + li t1, _TIF_SYSCALL_WORK
3009 and t0, t1
3010 bnez t0, syscall_trace_entry # -> yes
3011
3012 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3013 index 3b5a5e9..e1ee86d 100644
3014 --- a/arch/mips/kernel/scall64-64.S
3015 +++ b/arch/mips/kernel/scall64-64.S
3016 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3017
3018 sd a3, PT_R26(sp) # save a3 for syscall restarting
3019
3020 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3021 + li t1, _TIF_SYSCALL_WORK
3022 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3023 and t0, t1, t0
3024 bnez t0, syscall_trace_entry
3025 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3026 index 6be6f70..1859577 100644
3027 --- a/arch/mips/kernel/scall64-n32.S
3028 +++ b/arch/mips/kernel/scall64-n32.S
3029 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3030
3031 sd a3, PT_R26(sp) # save a3 for syscall restarting
3032
3033 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3034 + li t1, _TIF_SYSCALL_WORK
3035 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3036 and t0, t1, t0
3037 bnez t0, n32_syscall_trace_entry
3038 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3039 index 5422855..74e63a3 100644
3040 --- a/arch/mips/kernel/scall64-o32.S
3041 +++ b/arch/mips/kernel/scall64-o32.S
3042 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3043 PTR 4b, bad_stack
3044 .previous
3045
3046 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3047 + li t1, _TIF_SYSCALL_WORK
3048 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3049 and t0, t1, t0
3050 bnez t0, trace_a_syscall
3051 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3052 index c14f6df..537e729 100644
3053 --- a/arch/mips/mm/fault.c
3054 +++ b/arch/mips/mm/fault.c
3055 @@ -27,6 +27,23 @@
3056 #include <asm/highmem.h> /* For VMALLOC_END */
3057 #include <linux/kdebug.h>
3058
3059 +#ifdef CONFIG_PAX_PAGEEXEC
3060 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3061 +{
3062 + unsigned long i;
3063 +
3064 + printk(KERN_ERR "PAX: bytes at PC: ");
3065 + for (i = 0; i < 5; i++) {
3066 + unsigned int c;
3067 + if (get_user(c, (unsigned int *)pc+i))
3068 + printk(KERN_CONT "???????? ");
3069 + else
3070 + printk(KERN_CONT "%08x ", c);
3071 + }
3072 + printk("\n");
3073 +}
3074 +#endif
3075 +
3076 /*
3077 * This routine handles page faults. It determines the address,
3078 * and the problem, and then passes it off to one of the appropriate
3079 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3080 index 302d779..7d35bf8 100644
3081 --- a/arch/mips/mm/mmap.c
3082 +++ b/arch/mips/mm/mmap.c
3083 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3084 do_color_align = 1;
3085
3086 /* requesting a specific address */
3087 +
3088 +#ifdef CONFIG_PAX_RANDMMAP
3089 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3090 +#endif
3091 +
3092 if (addr) {
3093 if (do_color_align)
3094 addr = COLOUR_ALIGN(addr, pgoff);
3095 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3096 addr = PAGE_ALIGN(addr);
3097
3098 vma = find_vma(mm, addr);
3099 - if (TASK_SIZE - len >= addr &&
3100 - (!vma || addr + len <= vma->vm_start))
3101 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3102 return addr;
3103 }
3104
3105 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3106 /* At this point: (!vma || addr < vma->vm_end). */
3107 if (TASK_SIZE - len < addr)
3108 return -ENOMEM;
3109 - if (!vma || addr + len <= vma->vm_start)
3110 + if (check_heap_stack_gap(vmm, addr, len))
3111 return addr;
3112 addr = vma->vm_end;
3113 if (do_color_align)
3114 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3115 /* make sure it can fit in the remaining address space */
3116 if (likely(addr > len)) {
3117 vma = find_vma(mm, addr - len);
3118 - if (!vma || addr <= vma->vm_start) {
3119 + if (check_heap_stack_gap(vmm, addr - len, len))
3120 /* cache the address as a hint for next time */
3121 return mm->free_area_cache = addr - len;
3122 }
3123 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3124 * return with success:
3125 */
3126 vma = find_vma(mm, addr);
3127 - if (likely(!vma || addr + len <= vma->vm_start)) {
3128 + if (check_heap_stack_gap(vmm, addr, len)) {
3129 /* cache the address as a hint for next time */
3130 return mm->free_area_cache = addr;
3131 }
3132 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3133 mm->unmap_area = arch_unmap_area_topdown;
3134 }
3135 }
3136 -
3137 -static inline unsigned long brk_rnd(void)
3138 -{
3139 - unsigned long rnd = get_random_int();
3140 -
3141 - rnd = rnd << PAGE_SHIFT;
3142 - /* 8MB for 32bit, 256MB for 64bit */
3143 - if (TASK_IS_32BIT_ADDR)
3144 - rnd = rnd & 0x7ffffful;
3145 - else
3146 - rnd = rnd & 0xffffffful;
3147 -
3148 - return rnd;
3149 -}
3150 -
3151 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3152 -{
3153 - unsigned long base = mm->brk;
3154 - unsigned long ret;
3155 -
3156 - ret = PAGE_ALIGN(base + brk_rnd());
3157 -
3158 - if (ret < mm->brk)
3159 - return mm->brk;
3160 -
3161 - return ret;
3162 -}
3163 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3164 index 967d144..db12197 100644
3165 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3166 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3167 @@ -11,12 +11,14 @@
3168 #ifndef _ASM_PROC_CACHE_H
3169 #define _ASM_PROC_CACHE_H
3170
3171 +#include <linux/const.h>
3172 +
3173 /* L1 cache */
3174
3175 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3176 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3177 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3178 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3179 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3180 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3181
3182 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3183 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3184 index bcb5df2..84fabd2 100644
3185 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3186 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3187 @@ -16,13 +16,15 @@
3188 #ifndef _ASM_PROC_CACHE_H
3189 #define _ASM_PROC_CACHE_H
3190
3191 +#include <linux/const.h>
3192 +
3193 /*
3194 * L1 cache
3195 */
3196 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3197 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3198 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3199 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3200 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3201 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3202
3203 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3204 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3205 index 4ce7a01..449202a 100644
3206 --- a/arch/openrisc/include/asm/cache.h
3207 +++ b/arch/openrisc/include/asm/cache.h
3208 @@ -19,11 +19,13 @@
3209 #ifndef __ASM_OPENRISC_CACHE_H
3210 #define __ASM_OPENRISC_CACHE_H
3211
3212 +#include <linux/const.h>
3213 +
3214 /* FIXME: How can we replace these with values from the CPU...
3215 * they shouldn't be hard-coded!
3216 */
3217
3218 -#define L1_CACHE_BYTES 16
3219 #define L1_CACHE_SHIFT 4
3220 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3221
3222 #endif /* __ASM_OPENRISC_CACHE_H */
3223 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3224 index af9cf30..2aae9b2 100644
3225 --- a/arch/parisc/include/asm/atomic.h
3226 +++ b/arch/parisc/include/asm/atomic.h
3227 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3228
3229 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3230
3231 +#define atomic64_read_unchecked(v) atomic64_read(v)
3232 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3233 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3234 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3235 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3236 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3237 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3238 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3239 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3240 +
3241 #endif /* !CONFIG_64BIT */
3242
3243
3244 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3245 index 47f11c7..3420df2 100644
3246 --- a/arch/parisc/include/asm/cache.h
3247 +++ b/arch/parisc/include/asm/cache.h
3248 @@ -5,6 +5,7 @@
3249 #ifndef __ARCH_PARISC_CACHE_H
3250 #define __ARCH_PARISC_CACHE_H
3251
3252 +#include <linux/const.h>
3253
3254 /*
3255 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3256 @@ -15,13 +16,13 @@
3257 * just ruin performance.
3258 */
3259 #ifdef CONFIG_PA20
3260 -#define L1_CACHE_BYTES 64
3261 #define L1_CACHE_SHIFT 6
3262 #else
3263 -#define L1_CACHE_BYTES 32
3264 #define L1_CACHE_SHIFT 5
3265 #endif
3266
3267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3268 +
3269 #ifndef __ASSEMBLY__
3270
3271 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3272 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3273 index 19f6cb1..6c78cf2 100644
3274 --- a/arch/parisc/include/asm/elf.h
3275 +++ b/arch/parisc/include/asm/elf.h
3276 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3277
3278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3279
3280 +#ifdef CONFIG_PAX_ASLR
3281 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3282 +
3283 +#define PAX_DELTA_MMAP_LEN 16
3284 +#define PAX_DELTA_STACK_LEN 16
3285 +#endif
3286 +
3287 /* This yields a mask that user programs can use to figure out what
3288 instruction set this CPU supports. This could be done in user space,
3289 but it's not easy, and we've already done it here. */
3290 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3291 index fc987a1..6e068ef 100644
3292 --- a/arch/parisc/include/asm/pgalloc.h
3293 +++ b/arch/parisc/include/asm/pgalloc.h
3294 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3295 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3296 }
3297
3298 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3299 +{
3300 + pgd_populate(mm, pgd, pmd);
3301 +}
3302 +
3303 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3304 {
3305 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3306 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3307 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3308 #define pmd_free(mm, x) do { } while (0)
3309 #define pgd_populate(mm, pmd, pte) BUG()
3310 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3311
3312 #endif
3313
3314 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3315 index ee99f23..802b0a1 100644
3316 --- a/arch/parisc/include/asm/pgtable.h
3317 +++ b/arch/parisc/include/asm/pgtable.h
3318 @@ -212,6 +212,17 @@ struct vm_area_struct;
3319 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3320 #define PAGE_COPY PAGE_EXECREAD
3321 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3322 +
3323 +#ifdef CONFIG_PAX_PAGEEXEC
3324 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3325 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3326 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3327 +#else
3328 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3329 +# define PAGE_COPY_NOEXEC PAGE_COPY
3330 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3331 +#endif
3332 +
3333 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3334 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3335 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3336 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3337 index 4ba2c93..f5e3974 100644
3338 --- a/arch/parisc/include/asm/uaccess.h
3339 +++ b/arch/parisc/include/asm/uaccess.h
3340 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3341 const void __user *from,
3342 unsigned long n)
3343 {
3344 - int sz = __compiletime_object_size(to);
3345 + size_t sz = __compiletime_object_size(to);
3346 int ret = -EFAULT;
3347
3348 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3349 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3350 ret = __copy_from_user(to, from, n);
3351 else
3352 copy_from_user_overflow();
3353 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3354 index 5e34ccf..672bc9c 100644
3355 --- a/arch/parisc/kernel/module.c
3356 +++ b/arch/parisc/kernel/module.c
3357 @@ -98,16 +98,38 @@
3358
3359 /* three functions to determine where in the module core
3360 * or init pieces the location is */
3361 +static inline int in_init_rx(struct module *me, void *loc)
3362 +{
3363 + return (loc >= me->module_init_rx &&
3364 + loc < (me->module_init_rx + me->init_size_rx));
3365 +}
3366 +
3367 +static inline int in_init_rw(struct module *me, void *loc)
3368 +{
3369 + return (loc >= me->module_init_rw &&
3370 + loc < (me->module_init_rw + me->init_size_rw));
3371 +}
3372 +
3373 static inline int in_init(struct module *me, void *loc)
3374 {
3375 - return (loc >= me->module_init &&
3376 - loc <= (me->module_init + me->init_size));
3377 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3378 +}
3379 +
3380 +static inline int in_core_rx(struct module *me, void *loc)
3381 +{
3382 + return (loc >= me->module_core_rx &&
3383 + loc < (me->module_core_rx + me->core_size_rx));
3384 +}
3385 +
3386 +static inline int in_core_rw(struct module *me, void *loc)
3387 +{
3388 + return (loc >= me->module_core_rw &&
3389 + loc < (me->module_core_rw + me->core_size_rw));
3390 }
3391
3392 static inline int in_core(struct module *me, void *loc)
3393 {
3394 - return (loc >= me->module_core &&
3395 - loc <= (me->module_core + me->core_size));
3396 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3397 }
3398
3399 static inline int in_local(struct module *me, void *loc)
3400 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3401 }
3402
3403 /* align things a bit */
3404 - me->core_size = ALIGN(me->core_size, 16);
3405 - me->arch.got_offset = me->core_size;
3406 - me->core_size += gots * sizeof(struct got_entry);
3407 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3408 + me->arch.got_offset = me->core_size_rw;
3409 + me->core_size_rw += gots * sizeof(struct got_entry);
3410
3411 - me->core_size = ALIGN(me->core_size, 16);
3412 - me->arch.fdesc_offset = me->core_size;
3413 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3414 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3415 + me->arch.fdesc_offset = me->core_size_rw;
3416 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3417
3418 me->arch.got_max = gots;
3419 me->arch.fdesc_max = fdescs;
3420 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3421
3422 BUG_ON(value == 0);
3423
3424 - got = me->module_core + me->arch.got_offset;
3425 + got = me->module_core_rw + me->arch.got_offset;
3426 for (i = 0; got[i].addr; i++)
3427 if (got[i].addr == value)
3428 goto out;
3429 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3430 #ifdef CONFIG_64BIT
3431 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3432 {
3433 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3434 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3435
3436 if (!value) {
3437 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3438 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3439
3440 /* Create new one */
3441 fdesc->addr = value;
3442 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3443 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3444 return (Elf_Addr)fdesc;
3445 }
3446 #endif /* CONFIG_64BIT */
3447 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3448
3449 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3450 end = table + sechdrs[me->arch.unwind_section].sh_size;
3451 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3452 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3453
3454 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3455 me->arch.unwind_section, table, end, gp);
3456 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3457 index 7426e40..30c8dbe 100644
3458 --- a/arch/parisc/kernel/sys_parisc.c
3459 +++ b/arch/parisc/kernel/sys_parisc.c
3460 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3461 /* At this point: (!vma || addr < vma->vm_end). */
3462 if (TASK_SIZE - len < addr)
3463 return -ENOMEM;
3464 - if (!vma || addr + len <= vma->vm_start)
3465 + if (check_heap_stack_gap(vma, addr, len))
3466 return addr;
3467 addr = vma->vm_end;
3468 }
3469 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3470 /* At this point: (!vma || addr < vma->vm_end). */
3471 if (TASK_SIZE - len < addr)
3472 return -ENOMEM;
3473 - if (!vma || addr + len <= vma->vm_start)
3474 + if (check_heap_stack_gap(vma, addr, len))
3475 return addr;
3476 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3477 if (addr < vma->vm_end) /* handle wraparound */
3478 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3479 if (flags & MAP_FIXED)
3480 return addr;
3481 if (!addr)
3482 - addr = TASK_UNMAPPED_BASE;
3483 + addr = current->mm->mmap_base;
3484
3485 if (filp) {
3486 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3487 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3488 index 45ba99f..8e22c33 100644
3489 --- a/arch/parisc/kernel/traps.c
3490 +++ b/arch/parisc/kernel/traps.c
3491 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3492
3493 down_read(&current->mm->mmap_sem);
3494 vma = find_vma(current->mm,regs->iaoq[0]);
3495 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3496 - && (vma->vm_flags & VM_EXEC)) {
3497 -
3498 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3499 fault_address = regs->iaoq[0];
3500 fault_space = regs->iasq[0];
3501
3502 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3503 index 18162ce..94de376 100644
3504 --- a/arch/parisc/mm/fault.c
3505 +++ b/arch/parisc/mm/fault.c
3506 @@ -15,6 +15,7 @@
3507 #include <linux/sched.h>
3508 #include <linux/interrupt.h>
3509 #include <linux/module.h>
3510 +#include <linux/unistd.h>
3511
3512 #include <asm/uaccess.h>
3513 #include <asm/traps.h>
3514 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3515 static unsigned long
3516 parisc_acctyp(unsigned long code, unsigned int inst)
3517 {
3518 - if (code == 6 || code == 16)
3519 + if (code == 6 || code == 7 || code == 16)
3520 return VM_EXEC;
3521
3522 switch (inst & 0xf0000000) {
3523 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3524 }
3525 #endif
3526
3527 +#ifdef CONFIG_PAX_PAGEEXEC
3528 +/*
3529 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3530 + *
3531 + * returns 1 when task should be killed
3532 + * 2 when rt_sigreturn trampoline was detected
3533 + * 3 when unpatched PLT trampoline was detected
3534 + */
3535 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3536 +{
3537 +
3538 +#ifdef CONFIG_PAX_EMUPLT
3539 + int err;
3540 +
3541 + do { /* PaX: unpatched PLT emulation */
3542 + unsigned int bl, depwi;
3543 +
3544 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3545 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3546 +
3547 + if (err)
3548 + break;
3549 +
3550 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3551 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3552 +
3553 + err = get_user(ldw, (unsigned int *)addr);
3554 + err |= get_user(bv, (unsigned int *)(addr+4));
3555 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3556 +
3557 + if (err)
3558 + break;
3559 +
3560 + if (ldw == 0x0E801096U &&
3561 + bv == 0xEAC0C000U &&
3562 + ldw2 == 0x0E881095U)
3563 + {
3564 + unsigned int resolver, map;
3565 +
3566 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3567 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3568 + if (err)
3569 + break;
3570 +
3571 + regs->gr[20] = instruction_pointer(regs)+8;
3572 + regs->gr[21] = map;
3573 + regs->gr[22] = resolver;
3574 + regs->iaoq[0] = resolver | 3UL;
3575 + regs->iaoq[1] = regs->iaoq[0] + 4;
3576 + return 3;
3577 + }
3578 + }
3579 + } while (0);
3580 +#endif
3581 +
3582 +#ifdef CONFIG_PAX_EMUTRAMP
3583 +
3584 +#ifndef CONFIG_PAX_EMUSIGRT
3585 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3586 + return 1;
3587 +#endif
3588 +
3589 + do { /* PaX: rt_sigreturn emulation */
3590 + unsigned int ldi1, ldi2, bel, nop;
3591 +
3592 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3593 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3594 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3595 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3596 +
3597 + if (err)
3598 + break;
3599 +
3600 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3601 + ldi2 == 0x3414015AU &&
3602 + bel == 0xE4008200U &&
3603 + nop == 0x08000240U)
3604 + {
3605 + regs->gr[25] = (ldi1 & 2) >> 1;
3606 + regs->gr[20] = __NR_rt_sigreturn;
3607 + regs->gr[31] = regs->iaoq[1] + 16;
3608 + regs->sr[0] = regs->iasq[1];
3609 + regs->iaoq[0] = 0x100UL;
3610 + regs->iaoq[1] = regs->iaoq[0] + 4;
3611 + regs->iasq[0] = regs->sr[2];
3612 + regs->iasq[1] = regs->sr[2];
3613 + return 2;
3614 + }
3615 + } while (0);
3616 +#endif
3617 +
3618 + return 1;
3619 +}
3620 +
3621 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3622 +{
3623 + unsigned long i;
3624 +
3625 + printk(KERN_ERR "PAX: bytes at PC: ");
3626 + for (i = 0; i < 5; i++) {
3627 + unsigned int c;
3628 + if (get_user(c, (unsigned int *)pc+i))
3629 + printk(KERN_CONT "???????? ");
3630 + else
3631 + printk(KERN_CONT "%08x ", c);
3632 + }
3633 + printk("\n");
3634 +}
3635 +#endif
3636 +
3637 int fixup_exception(struct pt_regs *regs)
3638 {
3639 const struct exception_table_entry *fix;
3640 @@ -192,8 +303,33 @@ good_area:
3641
3642 acc_type = parisc_acctyp(code,regs->iir);
3643
3644 - if ((vma->vm_flags & acc_type) != acc_type)
3645 + if ((vma->vm_flags & acc_type) != acc_type) {
3646 +
3647 +#ifdef CONFIG_PAX_PAGEEXEC
3648 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3649 + (address & ~3UL) == instruction_pointer(regs))
3650 + {
3651 + up_read(&mm->mmap_sem);
3652 + switch (pax_handle_fetch_fault(regs)) {
3653 +
3654 +#ifdef CONFIG_PAX_EMUPLT
3655 + case 3:
3656 + return;
3657 +#endif
3658 +
3659 +#ifdef CONFIG_PAX_EMUTRAMP
3660 + case 2:
3661 + return;
3662 +#endif
3663 +
3664 + }
3665 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3666 + do_group_exit(SIGKILL);
3667 + }
3668 +#endif
3669 +
3670 goto bad_area;
3671 + }
3672
3673 /*
3674 * If for any reason at all we couldn't handle the fault, make
3675 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3676 index da29032..f76c24c 100644
3677 --- a/arch/powerpc/include/asm/atomic.h
3678 +++ b/arch/powerpc/include/asm/atomic.h
3679 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3680 return t1;
3681 }
3682
3683 +#define atomic64_read_unchecked(v) atomic64_read(v)
3684 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3685 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3686 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3687 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3688 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3689 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3690 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3691 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3692 +
3693 #endif /* __powerpc64__ */
3694
3695 #endif /* __KERNEL__ */
3696 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3697 index 9e495c9..b6878e5 100644
3698 --- a/arch/powerpc/include/asm/cache.h
3699 +++ b/arch/powerpc/include/asm/cache.h
3700 @@ -3,6 +3,7 @@
3701
3702 #ifdef __KERNEL__
3703
3704 +#include <linux/const.h>
3705
3706 /* bytes per L1 cache line */
3707 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3708 @@ -22,7 +23,7 @@
3709 #define L1_CACHE_SHIFT 7
3710 #endif
3711
3712 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3713 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3714
3715 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3716
3717 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3718 index 3bf9cca..e7457d0 100644
3719 --- a/arch/powerpc/include/asm/elf.h
3720 +++ b/arch/powerpc/include/asm/elf.h
3721 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3722 the loader. We need to make sure that it is out of the way of the program
3723 that it will "exec", and that there is sufficient room for the brk. */
3724
3725 -extern unsigned long randomize_et_dyn(unsigned long base);
3726 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3727 +#define ELF_ET_DYN_BASE (0x20000000)
3728 +
3729 +#ifdef CONFIG_PAX_ASLR
3730 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3731 +
3732 +#ifdef __powerpc64__
3733 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3734 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3735 +#else
3736 +#define PAX_DELTA_MMAP_LEN 15
3737 +#define PAX_DELTA_STACK_LEN 15
3738 +#endif
3739 +#endif
3740
3741 /*
3742 * Our registers are always unsigned longs, whether we're a 32 bit
3743 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3744 (0x7ff >> (PAGE_SHIFT - 12)) : \
3745 (0x3ffff >> (PAGE_SHIFT - 12)))
3746
3747 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3748 -#define arch_randomize_brk arch_randomize_brk
3749 -
3750 #endif /* __KERNEL__ */
3751
3752 /*
3753 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3754 index 8196e9c..d83a9f3 100644
3755 --- a/arch/powerpc/include/asm/exec.h
3756 +++ b/arch/powerpc/include/asm/exec.h
3757 @@ -4,6 +4,6 @@
3758 #ifndef _ASM_POWERPC_EXEC_H
3759 #define _ASM_POWERPC_EXEC_H
3760
3761 -extern unsigned long arch_align_stack(unsigned long sp);
3762 +#define arch_align_stack(x) ((x) & ~0xfUL)
3763
3764 #endif /* _ASM_POWERPC_EXEC_H */
3765 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3766 index 5acabbd..7ea14fa 100644
3767 --- a/arch/powerpc/include/asm/kmap_types.h
3768 +++ b/arch/powerpc/include/asm/kmap_types.h
3769 @@ -10,7 +10,7 @@
3770 * 2 of the License, or (at your option) any later version.
3771 */
3772
3773 -#define KM_TYPE_NR 16
3774 +#define KM_TYPE_NR 17
3775
3776 #endif /* __KERNEL__ */
3777 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3778 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3779 index d4a7f64..451de1c 100644
3780 --- a/arch/powerpc/include/asm/mman.h
3781 +++ b/arch/powerpc/include/asm/mman.h
3782 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3783 }
3784 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3785
3786 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3787 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3788 {
3789 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3790 }
3791 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3792 index f072e97..b436dee 100644
3793 --- a/arch/powerpc/include/asm/page.h
3794 +++ b/arch/powerpc/include/asm/page.h
3795 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3796 * and needs to be executable. This means the whole heap ends
3797 * up being executable.
3798 */
3799 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3800 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3801 +#define VM_DATA_DEFAULT_FLAGS32 \
3802 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3803 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3804
3805 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3806 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3807 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3808 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3809 #endif
3810
3811 +#define ktla_ktva(addr) (addr)
3812 +#define ktva_ktla(addr) (addr)
3813 +
3814 /*
3815 * Use the top bit of the higher-level page table entries to indicate whether
3816 * the entries we point to contain hugepages. This works because we know that
3817 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3818 index fed85e6..da5c71b 100644
3819 --- a/arch/powerpc/include/asm/page_64.h
3820 +++ b/arch/powerpc/include/asm/page_64.h
3821 @@ -146,15 +146,18 @@ do { \
3822 * stack by default, so in the absence of a PT_GNU_STACK program header
3823 * we turn execute permission off.
3824 */
3825 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3826 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3827 +#define VM_STACK_DEFAULT_FLAGS32 \
3828 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3829 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3830
3831 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3832 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3833
3834 +#ifndef CONFIG_PAX_PAGEEXEC
3835 #define VM_STACK_DEFAULT_FLAGS \
3836 (is_32bit_task() ? \
3837 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3838 +#endif
3839
3840 #include <asm-generic/getorder.h>
3841
3842 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3843 index 292725c..f87ae14 100644
3844 --- a/arch/powerpc/include/asm/pgalloc-64.h
3845 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3846 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3847 #ifndef CONFIG_PPC_64K_PAGES
3848
3849 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3850 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3851
3852 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3853 {
3854 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3855 pud_set(pud, (unsigned long)pmd);
3856 }
3857
3858 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859 +{
3860 + pud_populate(mm, pud, pmd);
3861 +}
3862 +
3863 #define pmd_populate(mm, pmd, pte_page) \
3864 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3865 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3866 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3867 #else /* CONFIG_PPC_64K_PAGES */
3868
3869 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3870 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3871
3872 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3873 pte_t *pte)
3874 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3875 index 2e0e411..7899c68 100644
3876 --- a/arch/powerpc/include/asm/pgtable.h
3877 +++ b/arch/powerpc/include/asm/pgtable.h
3878 @@ -2,6 +2,7 @@
3879 #define _ASM_POWERPC_PGTABLE_H
3880 #ifdef __KERNEL__
3881
3882 +#include <linux/const.h>
3883 #ifndef __ASSEMBLY__
3884 #include <asm/processor.h> /* For TASK_SIZE */
3885 #include <asm/mmu.h>
3886 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3887 index 4aad413..85d86bf 100644
3888 --- a/arch/powerpc/include/asm/pte-hash32.h
3889 +++ b/arch/powerpc/include/asm/pte-hash32.h
3890 @@ -21,6 +21,7 @@
3891 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3892 #define _PAGE_USER 0x004 /* usermode access allowed */
3893 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3894 +#define _PAGE_EXEC _PAGE_GUARDED
3895 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3896 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3897 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3898 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3899 index 6386086..6982225 100644
3900 --- a/arch/powerpc/include/asm/reg.h
3901 +++ b/arch/powerpc/include/asm/reg.h
3902 @@ -212,6 +212,7 @@
3903 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3904 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3905 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3906 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3907 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3908 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3909 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3910 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3911 index faf9352..ab2ccec 100644
3912 --- a/arch/powerpc/include/asm/thread_info.h
3913 +++ b/arch/powerpc/include/asm/thread_info.h
3914 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3915 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3916 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3917 #define TIF_SINGLESTEP 8 /* singlestepping active */
3918 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3919 #define TIF_SECCOMP 10 /* secure computing */
3920 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3921 #define TIF_NOERROR 12 /* Force successful syscall return */
3922 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3923 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3924 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3925 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3926 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3927
3928 /* as above, but as bit values */
3929 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3930 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3931 #define _TIF_NOERROR (1<<TIF_NOERROR)
3932 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3933 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3934 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3935 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3936 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3937 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3938 + _TIF_GRSEC_SETXID)
3939
3940 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3941 _TIF_NOTIFY_RESUME)
3942 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3943 index 17bb40c..353c98b 100644
3944 --- a/arch/powerpc/include/asm/uaccess.h
3945 +++ b/arch/powerpc/include/asm/uaccess.h
3946 @@ -13,6 +13,8 @@
3947 #define VERIFY_READ 0
3948 #define VERIFY_WRITE 1
3949
3950 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3951 +
3952 /*
3953 * The fs value determines whether argument validity checking should be
3954 * performed or not. If get_fs() == USER_DS, checking is performed, with
3955 @@ -329,52 +331,6 @@ do { \
3956 extern unsigned long __copy_tofrom_user(void __user *to,
3957 const void __user *from, unsigned long size);
3958
3959 -#ifndef __powerpc64__
3960 -
3961 -static inline unsigned long copy_from_user(void *to,
3962 - const void __user *from, unsigned long n)
3963 -{
3964 - unsigned long over;
3965 -
3966 - if (access_ok(VERIFY_READ, from, n))
3967 - return __copy_tofrom_user((__force void __user *)to, from, n);
3968 - if ((unsigned long)from < TASK_SIZE) {
3969 - over = (unsigned long)from + n - TASK_SIZE;
3970 - return __copy_tofrom_user((__force void __user *)to, from,
3971 - n - over) + over;
3972 - }
3973 - return n;
3974 -}
3975 -
3976 -static inline unsigned long copy_to_user(void __user *to,
3977 - const void *from, unsigned long n)
3978 -{
3979 - unsigned long over;
3980 -
3981 - if (access_ok(VERIFY_WRITE, to, n))
3982 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3983 - if ((unsigned long)to < TASK_SIZE) {
3984 - over = (unsigned long)to + n - TASK_SIZE;
3985 - return __copy_tofrom_user(to, (__force void __user *)from,
3986 - n - over) + over;
3987 - }
3988 - return n;
3989 -}
3990 -
3991 -#else /* __powerpc64__ */
3992 -
3993 -#define __copy_in_user(to, from, size) \
3994 - __copy_tofrom_user((to), (from), (size))
3995 -
3996 -extern unsigned long copy_from_user(void *to, const void __user *from,
3997 - unsigned long n);
3998 -extern unsigned long copy_to_user(void __user *to, const void *from,
3999 - unsigned long n);
4000 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4001 - unsigned long n);
4002 -
4003 -#endif /* __powerpc64__ */
4004 -
4005 static inline unsigned long __copy_from_user_inatomic(void *to,
4006 const void __user *from, unsigned long n)
4007 {
4008 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4009 if (ret == 0)
4010 return 0;
4011 }
4012 +
4013 + if (!__builtin_constant_p(n))
4014 + check_object_size(to, n, false);
4015 +
4016 return __copy_tofrom_user((__force void __user *)to, from, n);
4017 }
4018
4019 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4020 if (ret == 0)
4021 return 0;
4022 }
4023 +
4024 + if (!__builtin_constant_p(n))
4025 + check_object_size(from, n, true);
4026 +
4027 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4028 }
4029
4030 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4031 return __copy_to_user_inatomic(to, from, size);
4032 }
4033
4034 +#ifndef __powerpc64__
4035 +
4036 +static inline unsigned long __must_check copy_from_user(void *to,
4037 + const void __user *from, unsigned long n)
4038 +{
4039 + unsigned long over;
4040 +
4041 + if ((long)n < 0)
4042 + return n;
4043 +
4044 + if (access_ok(VERIFY_READ, from, n)) {
4045 + if (!__builtin_constant_p(n))
4046 + check_object_size(to, n, false);
4047 + return __copy_tofrom_user((__force void __user *)to, from, n);
4048 + }
4049 + if ((unsigned long)from < TASK_SIZE) {
4050 + over = (unsigned long)from + n - TASK_SIZE;
4051 + if (!__builtin_constant_p(n - over))
4052 + check_object_size(to, n - over, false);
4053 + return __copy_tofrom_user((__force void __user *)to, from,
4054 + n - over) + over;
4055 + }
4056 + return n;
4057 +}
4058 +
4059 +static inline unsigned long __must_check copy_to_user(void __user *to,
4060 + const void *from, unsigned long n)
4061 +{
4062 + unsigned long over;
4063 +
4064 + if ((long)n < 0)
4065 + return n;
4066 +
4067 + if (access_ok(VERIFY_WRITE, to, n)) {
4068 + if (!__builtin_constant_p(n))
4069 + check_object_size(from, n, true);
4070 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4071 + }
4072 + if ((unsigned long)to < TASK_SIZE) {
4073 + over = (unsigned long)to + n - TASK_SIZE;
4074 + if (!__builtin_constant_p(n))
4075 + check_object_size(from, n - over, true);
4076 + return __copy_tofrom_user(to, (__force void __user *)from,
4077 + n - over) + over;
4078 + }
4079 + return n;
4080 +}
4081 +
4082 +#else /* __powerpc64__ */
4083 +
4084 +#define __copy_in_user(to, from, size) \
4085 + __copy_tofrom_user((to), (from), (size))
4086 +
4087 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4088 +{
4089 + if ((long)n < 0 || n > INT_MAX)
4090 + return n;
4091 +
4092 + if (!__builtin_constant_p(n))
4093 + check_object_size(to, n, false);
4094 +
4095 + if (likely(access_ok(VERIFY_READ, from, n)))
4096 + n = __copy_from_user(to, from, n);
4097 + else
4098 + memset(to, 0, n);
4099 + return n;
4100 +}
4101 +
4102 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4103 +{
4104 + if ((long)n < 0 || n > INT_MAX)
4105 + return n;
4106 +
4107 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4108 + if (!__builtin_constant_p(n))
4109 + check_object_size(from, n, true);
4110 + n = __copy_to_user(to, from, n);
4111 + }
4112 + return n;
4113 +}
4114 +
4115 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4116 + unsigned long n);
4117 +
4118 +#endif /* __powerpc64__ */
4119 +
4120 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4121
4122 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4123 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4124 index 98be7f0..8ef62de 100644
4125 --- a/arch/powerpc/kernel/exceptions-64e.S
4126 +++ b/arch/powerpc/kernel/exceptions-64e.S
4127 @@ -661,6 +661,7 @@ storage_fault_common:
4128 std r14,_DAR(r1)
4129 std r15,_DSISR(r1)
4130 addi r3,r1,STACK_FRAME_OVERHEAD
4131 + bl .save_nvgprs
4132 mr r4,r14
4133 mr r5,r15
4134 ld r14,PACA_EXGEN+EX_R14(r13)
4135 @@ -669,8 +670,7 @@ storage_fault_common:
4136 cmpdi r3,0
4137 bne- 1f
4138 b .ret_from_except_lite
4139 -1: bl .save_nvgprs
4140 - mr r5,r3
4141 +1: mr r5,r3
4142 addi r3,r1,STACK_FRAME_OVERHEAD
4143 ld r4,_DAR(r1)
4144 bl .bad_page_fault
4145 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4146 index 39aa97d..dc916ee 100644
4147 --- a/arch/powerpc/kernel/exceptions-64s.S
4148 +++ b/arch/powerpc/kernel/exceptions-64s.S
4149 @@ -890,10 +890,10 @@ handle_page_fault:
4150 11: ld r4,_DAR(r1)
4151 ld r5,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 + bl .save_nvgprs
4154 bl .do_page_fault
4155 cmpdi r3,0
4156 beq+ 12f
4157 - bl .save_nvgprs
4158 mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 lwz r4,_DAR(r1)
4161 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4162 index 2e3200c..72095ce 100644
4163 --- a/arch/powerpc/kernel/module_32.c
4164 +++ b/arch/powerpc/kernel/module_32.c
4165 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4166 me->arch.core_plt_section = i;
4167 }
4168 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4169 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4170 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4171 return -ENOEXEC;
4172 }
4173
4174 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4175
4176 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4177 /* Init, or core PLT? */
4178 - if (location >= mod->module_core
4179 - && location < mod->module_core + mod->core_size)
4180 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4181 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4182 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4183 - else
4184 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4185 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4186 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4187 + else {
4188 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4189 + return ~0UL;
4190 + }
4191
4192 /* Find this entry, or if that fails, the next avail. entry */
4193 while (entry->jump[0]) {
4194 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4195 index 1a1f2dd..f4d1bb4 100644
4196 --- a/arch/powerpc/kernel/process.c
4197 +++ b/arch/powerpc/kernel/process.c
4198 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4199 * Lookup NIP late so we have the best change of getting the
4200 * above info out without failing
4201 */
4202 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4203 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4204 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4205 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4206 #endif
4207 show_stack(current, (unsigned long *) regs->gpr[1]);
4208 if (!user_mode(regs))
4209 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4210 newsp = stack[0];
4211 ip = stack[STACK_FRAME_LR_SAVE];
4212 if (!firstframe || ip != lr) {
4213 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4214 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4215 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4216 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4217 - printk(" (%pS)",
4218 + printk(" (%pA)",
4219 (void *)current->ret_stack[curr_frame].ret);
4220 curr_frame--;
4221 }
4222 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4223 struct pt_regs *regs = (struct pt_regs *)
4224 (sp + STACK_FRAME_OVERHEAD);
4225 lr = regs->link;
4226 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4227 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4228 regs->trap, (void *)regs->nip, (void *)lr);
4229 firstframe = 1;
4230 }
4231 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4232 mtspr(SPRN_CTRLT, ctrl);
4233 }
4234 #endif /* CONFIG_PPC64 */
4235 -
4236 -unsigned long arch_align_stack(unsigned long sp)
4237 -{
4238 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4239 - sp -= get_random_int() & ~PAGE_MASK;
4240 - return sp & ~0xf;
4241 -}
4242 -
4243 -static inline unsigned long brk_rnd(void)
4244 -{
4245 - unsigned long rnd = 0;
4246 -
4247 - /* 8MB for 32bit, 1GB for 64bit */
4248 - if (is_32bit_task())
4249 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4250 - else
4251 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4252 -
4253 - return rnd << PAGE_SHIFT;
4254 -}
4255 -
4256 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4257 -{
4258 - unsigned long base = mm->brk;
4259 - unsigned long ret;
4260 -
4261 -#ifdef CONFIG_PPC_STD_MMU_64
4262 - /*
4263 - * If we are using 1TB segments and we are allowed to randomise
4264 - * the heap, we can put it above 1TB so it is backed by a 1TB
4265 - * segment. Otherwise the heap will be in the bottom 1TB
4266 - * which always uses 256MB segments and this may result in a
4267 - * performance penalty.
4268 - */
4269 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4270 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4271 -#endif
4272 -
4273 - ret = PAGE_ALIGN(base + brk_rnd());
4274 -
4275 - if (ret < mm->brk)
4276 - return mm->brk;
4277 -
4278 - return ret;
4279 -}
4280 -
4281 -unsigned long randomize_et_dyn(unsigned long base)
4282 -{
4283 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4284 -
4285 - if (ret < base)
4286 - return base;
4287 -
4288 - return ret;
4289 -}
4290 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4291 index c10fc28..c4ef063 100644
4292 --- a/arch/powerpc/kernel/ptrace.c
4293 +++ b/arch/powerpc/kernel/ptrace.c
4294 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4295 return ret;
4296 }
4297
4298 +#ifdef CONFIG_GRKERNSEC_SETXID
4299 +extern void gr_delayed_cred_worker(void);
4300 +#endif
4301 +
4302 /*
4303 * We must return the syscall number to actually look up in the table.
4304 * This can be -1L to skip running any syscall at all.
4305 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4306
4307 secure_computing_strict(regs->gpr[0]);
4308
4309 +#ifdef CONFIG_GRKERNSEC_SETXID
4310 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4311 + gr_delayed_cred_worker();
4312 +#endif
4313 +
4314 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4315 tracehook_report_syscall_entry(regs))
4316 /*
4317 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4318 {
4319 int step;
4320
4321 +#ifdef CONFIG_GRKERNSEC_SETXID
4322 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4323 + gr_delayed_cred_worker();
4324 +#endif
4325 +
4326 audit_syscall_exit(regs);
4327
4328 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4329 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4330 index 8b4c049..dcd6ef3 100644
4331 --- a/arch/powerpc/kernel/signal_32.c
4332 +++ b/arch/powerpc/kernel/signal_32.c
4333 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4334 /* Save user registers on the stack */
4335 frame = &rt_sf->uc.uc_mcontext;
4336 addr = frame;
4337 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4338 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4339 if (save_user_regs(regs, frame, 0, 1))
4340 goto badframe;
4341 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4342 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4343 index d183f87..1867f1a 100644
4344 --- a/arch/powerpc/kernel/signal_64.c
4345 +++ b/arch/powerpc/kernel/signal_64.c
4346 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4347 current->thread.fpscr.val = 0;
4348
4349 /* Set up to return from userspace. */
4350 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4351 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4352 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4353 } else {
4354 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4355 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4356 index ae0843f..f16372c 100644
4357 --- a/arch/powerpc/kernel/traps.c
4358 +++ b/arch/powerpc/kernel/traps.c
4359 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4360 return flags;
4361 }
4362
4363 +extern void gr_handle_kernel_exploit(void);
4364 +
4365 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4366 int signr)
4367 {
4368 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4369 panic("Fatal exception in interrupt");
4370 if (panic_on_oops)
4371 panic("Fatal exception");
4372 +
4373 + gr_handle_kernel_exploit();
4374 +
4375 do_exit(signr);
4376 }
4377
4378 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4379 index b67db22..38825d2 100644
4380 --- a/arch/powerpc/kernel/vdso.c
4381 +++ b/arch/powerpc/kernel/vdso.c
4382 @@ -34,6 +34,7 @@
4383 #include <asm/firmware.h>
4384 #include <asm/vdso.h>
4385 #include <asm/vdso_datapage.h>
4386 +#include <asm/mman.h>
4387
4388 #include "setup.h"
4389
4390 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4391 vdso_base = VDSO32_MBASE;
4392 #endif
4393
4394 - current->mm->context.vdso_base = 0;
4395 + current->mm->context.vdso_base = ~0UL;
4396
4397 /* vDSO has a problem and was disabled, just don't "enable" it for the
4398 * process
4399 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4400 vdso_base = get_unmapped_area(NULL, vdso_base,
4401 (vdso_pages << PAGE_SHIFT) +
4402 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4403 - 0, 0);
4404 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4405 if (IS_ERR_VALUE(vdso_base)) {
4406 rc = vdso_base;
4407 goto fail_mmapsem;
4408 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4409 index 5eea6f3..5d10396 100644
4410 --- a/arch/powerpc/lib/usercopy_64.c
4411 +++ b/arch/powerpc/lib/usercopy_64.c
4412 @@ -9,22 +9,6 @@
4413 #include <linux/module.h>
4414 #include <asm/uaccess.h>
4415
4416 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4417 -{
4418 - if (likely(access_ok(VERIFY_READ, from, n)))
4419 - n = __copy_from_user(to, from, n);
4420 - else
4421 - memset(to, 0, n);
4422 - return n;
4423 -}
4424 -
4425 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4426 -{
4427 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4428 - n = __copy_to_user(to, from, n);
4429 - return n;
4430 -}
4431 -
4432 unsigned long copy_in_user(void __user *to, const void __user *from,
4433 unsigned long n)
4434 {
4435 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4436 return n;
4437 }
4438
4439 -EXPORT_SYMBOL(copy_from_user);
4440 -EXPORT_SYMBOL(copy_to_user);
4441 EXPORT_SYMBOL(copy_in_user);
4442
4443 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4444 index 08ffcf5..a0ab912 100644
4445 --- a/arch/powerpc/mm/fault.c
4446 +++ b/arch/powerpc/mm/fault.c
4447 @@ -32,6 +32,10 @@
4448 #include <linux/perf_event.h>
4449 #include <linux/magic.h>
4450 #include <linux/ratelimit.h>
4451 +#include <linux/slab.h>
4452 +#include <linux/pagemap.h>
4453 +#include <linux/compiler.h>
4454 +#include <linux/unistd.h>
4455
4456 #include <asm/firmware.h>
4457 #include <asm/page.h>
4458 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4459 }
4460 #endif
4461
4462 +#ifdef CONFIG_PAX_PAGEEXEC
4463 +/*
4464 + * PaX: decide what to do with offenders (regs->nip = fault address)
4465 + *
4466 + * returns 1 when task should be killed
4467 + */
4468 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4469 +{
4470 + return 1;
4471 +}
4472 +
4473 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4474 +{
4475 + unsigned long i;
4476 +
4477 + printk(KERN_ERR "PAX: bytes at PC: ");
4478 + for (i = 0; i < 5; i++) {
4479 + unsigned int c;
4480 + if (get_user(c, (unsigned int __user *)pc+i))
4481 + printk(KERN_CONT "???????? ");
4482 + else
4483 + printk(KERN_CONT "%08x ", c);
4484 + }
4485 + printk("\n");
4486 +}
4487 +#endif
4488 +
4489 /*
4490 * Check whether the instruction at regs->nip is a store using
4491 * an update addressing form which will update r1.
4492 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4493 * indicate errors in DSISR but can validly be set in SRR1.
4494 */
4495 if (trap == 0x400)
4496 - error_code &= 0x48200000;
4497 + error_code &= 0x58200000;
4498 else
4499 is_write = error_code & DSISR_ISSTORE;
4500 #else
4501 @@ -366,7 +397,7 @@ good_area:
4502 * "undefined". Of those that can be set, this is the only
4503 * one which seems bad.
4504 */
4505 - if (error_code & 0x10000000)
4506 + if (error_code & DSISR_GUARDED)
4507 /* Guarded storage error. */
4508 goto bad_area;
4509 #endif /* CONFIG_8xx */
4510 @@ -381,7 +412,7 @@ good_area:
4511 * processors use the same I/D cache coherency mechanism
4512 * as embedded.
4513 */
4514 - if (error_code & DSISR_PROTFAULT)
4515 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4516 goto bad_area;
4517 #endif /* CONFIG_PPC_STD_MMU */
4518
4519 @@ -463,6 +494,23 @@ bad_area:
4520 bad_area_nosemaphore:
4521 /* User mode accesses cause a SIGSEGV */
4522 if (user_mode(regs)) {
4523 +
4524 +#ifdef CONFIG_PAX_PAGEEXEC
4525 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4526 +#ifdef CONFIG_PPC_STD_MMU
4527 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4528 +#else
4529 + if (is_exec && regs->nip == address) {
4530 +#endif
4531 + switch (pax_handle_fetch_fault(regs)) {
4532 + }
4533 +
4534 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4535 + do_group_exit(SIGKILL);
4536 + }
4537 + }
4538 +#endif
4539 +
4540 _exception(SIGSEGV, regs, code, address);
4541 return 0;
4542 }
4543 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4544 index 67a42ed..1c7210c 100644
4545 --- a/arch/powerpc/mm/mmap_64.c
4546 +++ b/arch/powerpc/mm/mmap_64.c
4547 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4548 */
4549 if (mmap_is_legacy()) {
4550 mm->mmap_base = TASK_UNMAPPED_BASE;
4551 +
4552 +#ifdef CONFIG_PAX_RANDMMAP
4553 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4554 + mm->mmap_base += mm->delta_mmap;
4555 +#endif
4556 +
4557 mm->get_unmapped_area = arch_get_unmapped_area;
4558 mm->unmap_area = arch_unmap_area;
4559 } else {
4560 mm->mmap_base = mmap_base();
4561 +
4562 +#ifdef CONFIG_PAX_RANDMMAP
4563 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4564 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4565 +#endif
4566 +
4567 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4568 mm->unmap_area = arch_unmap_area_topdown;
4569 }
4570 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4571 index 73709f7..6b90313 100644
4572 --- a/arch/powerpc/mm/slice.c
4573 +++ b/arch/powerpc/mm/slice.c
4574 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4575 if ((mm->task_size - len) < addr)
4576 return 0;
4577 vma = find_vma(mm, addr);
4578 - return (!vma || (addr + len) <= vma->vm_start);
4579 + return check_heap_stack_gap(vma, addr, len);
4580 }
4581
4582 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4583 @@ -256,7 +256,7 @@ full_search:
4584 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4585 continue;
4586 }
4587 - if (!vma || addr + len <= vma->vm_start) {
4588 + if (check_heap_stack_gap(vma, addr, len)) {
4589 /*
4590 * Remember the place where we stopped the search:
4591 */
4592 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4593 }
4594 }
4595
4596 - addr = mm->mmap_base;
4597 - while (addr > len) {
4598 + if (mm->mmap_base < len)
4599 + addr = -ENOMEM;
4600 + else
4601 + addr = mm->mmap_base - len;
4602 +
4603 + while (!IS_ERR_VALUE(addr)) {
4604 /* Go down by chunk size */
4605 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4606 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4607
4608 /* Check for hit with different page size */
4609 mask = slice_range_to_mask(addr, len);
4610 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4611 * return with success:
4612 */
4613 vma = find_vma(mm, addr);
4614 - if (!vma || (addr + len) <= vma->vm_start) {
4615 + if (check_heap_stack_gap(vma, addr, len)) {
4616 /* remember the address as a hint for next time */
4617 if (use_cache)
4618 mm->free_area_cache = addr;
4619 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4620 mm->cached_hole_size = vma->vm_start - addr;
4621
4622 /* try just below the current vma->vm_start */
4623 - addr = vma->vm_start;
4624 + addr = skip_heap_stack_gap(vma, len);
4625 }
4626
4627 /*
4628 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4629 if (fixed && addr > (mm->task_size - len))
4630 return -EINVAL;
4631
4632 +#ifdef CONFIG_PAX_RANDMMAP
4633 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4634 + addr = 0;
4635 +#endif
4636 +
4637 /* If hint, make sure it matches our alignment restrictions */
4638 if (!fixed && addr) {
4639 addr = _ALIGN_UP(addr, 1ul << pshift);
4640 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4641 index c797832..ce575c8 100644
4642 --- a/arch/s390/include/asm/atomic.h
4643 +++ b/arch/s390/include/asm/atomic.h
4644 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4645 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4646 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4647
4648 +#define atomic64_read_unchecked(v) atomic64_read(v)
4649 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4650 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4651 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4652 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4653 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4654 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4655 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4656 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4657 +
4658 #define smp_mb__before_atomic_dec() smp_mb()
4659 #define smp_mb__after_atomic_dec() smp_mb()
4660 #define smp_mb__before_atomic_inc() smp_mb()
4661 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4662 index 4d7ccac..d03d0ad 100644
4663 --- a/arch/s390/include/asm/cache.h
4664 +++ b/arch/s390/include/asm/cache.h
4665 @@ -9,8 +9,10 @@
4666 #ifndef __ARCH_S390_CACHE_H
4667 #define __ARCH_S390_CACHE_H
4668
4669 -#define L1_CACHE_BYTES 256
4670 +#include <linux/const.h>
4671 +
4672 #define L1_CACHE_SHIFT 8
4673 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4674 #define NET_SKB_PAD 32
4675
4676 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4677 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4678 index 9b94a16..63d4034 100644
4679 --- a/arch/s390/include/asm/elf.h
4680 +++ b/arch/s390/include/asm/elf.h
4681 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4682 the loader. We need to make sure that it is out of the way of the program
4683 that it will "exec", and that there is sufficient room for the brk. */
4684
4685 -extern unsigned long randomize_et_dyn(unsigned long base);
4686 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4687 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4688 +
4689 +#ifdef CONFIG_PAX_ASLR
4690 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4691 +
4692 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4693 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4694 +#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. */
4698 @@ -209,7 +215,4 @@ struct linux_binprm;
4699 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4700 int arch_setup_additional_pages(struct linux_binprm *, int);
4701
4702 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4703 -#define arch_randomize_brk arch_randomize_brk
4704 -
4705 #endif
4706 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4707 index c4a93d6..4d2a9b4 100644
4708 --- a/arch/s390/include/asm/exec.h
4709 +++ b/arch/s390/include/asm/exec.h
4710 @@ -7,6 +7,6 @@
4711 #ifndef __ASM_EXEC_H
4712 #define __ASM_EXEC_H
4713
4714 -extern unsigned long arch_align_stack(unsigned long sp);
4715 +#define arch_align_stack(x) ((x) & ~0xfUL)
4716
4717 #endif /* __ASM_EXEC_H */
4718 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4719 index a8ab18b..75ddbf0 100644
4720 --- a/arch/s390/include/asm/uaccess.h
4721 +++ b/arch/s390/include/asm/uaccess.h
4722 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4723 copy_to_user(void __user *to, const void *from, unsigned long n)
4724 {
4725 might_fault();
4726 +
4727 + if ((long)n < 0)
4728 + return n;
4729 +
4730 if (access_ok(VERIFY_WRITE, to, n))
4731 n = __copy_to_user(to, from, n);
4732 return n;
4733 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4734 static inline unsigned long __must_check
4735 __copy_from_user(void *to, const void __user *from, unsigned long n)
4736 {
4737 + if ((long)n < 0)
4738 + return n;
4739 +
4740 if (__builtin_constant_p(n) && (n <= 256))
4741 return uaccess.copy_from_user_small(n, from, to);
4742 else
4743 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4744 static inline unsigned long __must_check
4745 copy_from_user(void *to, const void __user *from, unsigned long n)
4746 {
4747 - unsigned int sz = __compiletime_object_size(to);
4748 + size_t sz = __compiletime_object_size(to);
4749
4750 might_fault();
4751 - if (unlikely(sz != -1 && sz < n)) {
4752 +
4753 + if ((long)n < 0)
4754 + return n;
4755 +
4756 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4757 copy_from_user_overflow();
4758 return n;
4759 }
4760 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4761 index 46412b1..e32874f 100644
4762 --- a/arch/s390/kernel/module.c
4763 +++ b/arch/s390/kernel/module.c
4764 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4765
4766 /* Increase core size by size of got & plt and set start
4767 offsets for got and plt. */
4768 - me->core_size = ALIGN(me->core_size, 4);
4769 - me->arch.got_offset = me->core_size;
4770 - me->core_size += me->arch.got_size;
4771 - me->arch.plt_offset = me->core_size;
4772 - me->core_size += me->arch.plt_size;
4773 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4774 + me->arch.got_offset = me->core_size_rw;
4775 + me->core_size_rw += me->arch.got_size;
4776 + me->arch.plt_offset = me->core_size_rx;
4777 + me->core_size_rx += me->arch.plt_size;
4778 return 0;
4779 }
4780
4781 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4782 if (info->got_initialized == 0) {
4783 Elf_Addr *gotent;
4784
4785 - gotent = me->module_core + me->arch.got_offset +
4786 + gotent = me->module_core_rw + me->arch.got_offset +
4787 info->got_offset;
4788 *gotent = val;
4789 info->got_initialized = 1;
4790 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4791 else if (r_type == R_390_GOTENT ||
4792 r_type == R_390_GOTPLTENT)
4793 *(unsigned int *) loc =
4794 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4795 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4796 else if (r_type == R_390_GOT64 ||
4797 r_type == R_390_GOTPLT64)
4798 *(unsigned long *) loc = val;
4799 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4800 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4801 if (info->plt_initialized == 0) {
4802 unsigned int *ip;
4803 - ip = me->module_core + me->arch.plt_offset +
4804 + ip = me->module_core_rx + me->arch.plt_offset +
4805 info->plt_offset;
4806 #ifndef CONFIG_64BIT
4807 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4808 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4809 val - loc + 0xffffUL < 0x1ffffeUL) ||
4810 (r_type == R_390_PLT32DBL &&
4811 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4812 - val = (Elf_Addr) me->module_core +
4813 + val = (Elf_Addr) me->module_core_rx +
4814 me->arch.plt_offset +
4815 info->plt_offset;
4816 val += rela->r_addend - loc;
4817 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4818 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4819 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4820 val = val + rela->r_addend -
4821 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4822 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4823 if (r_type == R_390_GOTOFF16)
4824 *(unsigned short *) loc = val;
4825 else if (r_type == R_390_GOTOFF32)
4826 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4827 break;
4828 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4829 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4830 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4831 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4832 rela->r_addend - loc;
4833 if (r_type == R_390_GOTPC)
4834 *(unsigned int *) loc = val;
4835 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4836 index 7331753..dd71de4 100644
4837 --- a/arch/s390/kernel/process.c
4838 +++ b/arch/s390/kernel/process.c
4839 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4840 }
4841 return 0;
4842 }
4843 -
4844 -unsigned long arch_align_stack(unsigned long sp)
4845 -{
4846 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4847 - sp -= get_random_int() & ~PAGE_MASK;
4848 - return sp & ~0xf;
4849 -}
4850 -
4851 -static inline unsigned long brk_rnd(void)
4852 -{
4853 - /* 8MB for 32bit, 1GB for 64bit */
4854 - if (is_32bit_task())
4855 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4856 - else
4857 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4858 -}
4859 -
4860 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4861 -{
4862 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4863 -
4864 - if (ret < mm->brk)
4865 - return mm->brk;
4866 - return ret;
4867 -}
4868 -
4869 -unsigned long randomize_et_dyn(unsigned long base)
4870 -{
4871 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4872 -
4873 - if (!(current->flags & PF_RANDOMIZE))
4874 - return base;
4875 - if (ret < base)
4876 - return base;
4877 - return ret;
4878 -}
4879 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4880 index c59a5ef..3fae59c 100644
4881 --- a/arch/s390/mm/mmap.c
4882 +++ b/arch/s390/mm/mmap.c
4883 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4884 */
4885 if (mmap_is_legacy()) {
4886 mm->mmap_base = TASK_UNMAPPED_BASE;
4887 +
4888 +#ifdef CONFIG_PAX_RANDMMAP
4889 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4890 + mm->mmap_base += mm->delta_mmap;
4891 +#endif
4892 +
4893 mm->get_unmapped_area = arch_get_unmapped_area;
4894 mm->unmap_area = arch_unmap_area;
4895 } else {
4896 mm->mmap_base = mmap_base();
4897 +
4898 +#ifdef CONFIG_PAX_RANDMMAP
4899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4900 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4901 +#endif
4902 +
4903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4904 mm->unmap_area = arch_unmap_area_topdown;
4905 }
4906 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4907 */
4908 if (mmap_is_legacy()) {
4909 mm->mmap_base = TASK_UNMAPPED_BASE;
4910 +
4911 +#ifdef CONFIG_PAX_RANDMMAP
4912 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4913 + mm->mmap_base += mm->delta_mmap;
4914 +#endif
4915 +
4916 mm->get_unmapped_area = s390_get_unmapped_area;
4917 mm->unmap_area = arch_unmap_area;
4918 } else {
4919 mm->mmap_base = mmap_base();
4920 +
4921 +#ifdef CONFIG_PAX_RANDMMAP
4922 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4923 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4924 +#endif
4925 +
4926 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4927 mm->unmap_area = arch_unmap_area_topdown;
4928 }
4929 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4930 index ae3d59f..f65f075 100644
4931 --- a/arch/score/include/asm/cache.h
4932 +++ b/arch/score/include/asm/cache.h
4933 @@ -1,7 +1,9 @@
4934 #ifndef _ASM_SCORE_CACHE_H
4935 #define _ASM_SCORE_CACHE_H
4936
4937 +#include <linux/const.h>
4938 +
4939 #define L1_CACHE_SHIFT 4
4940 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4941 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4942
4943 #endif /* _ASM_SCORE_CACHE_H */
4944 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4945 index f9f3cd5..58ff438 100644
4946 --- a/arch/score/include/asm/exec.h
4947 +++ b/arch/score/include/asm/exec.h
4948 @@ -1,6 +1,6 @@
4949 #ifndef _ASM_SCORE_EXEC_H
4950 #define _ASM_SCORE_EXEC_H
4951
4952 -extern unsigned long arch_align_stack(unsigned long sp);
4953 +#define arch_align_stack(x) (x)
4954
4955 #endif /* _ASM_SCORE_EXEC_H */
4956 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4957 index 637970c..0b6556b 100644
4958 --- a/arch/score/kernel/process.c
4959 +++ b/arch/score/kernel/process.c
4960 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4961
4962 return task_pt_regs(task)->cp0_epc;
4963 }
4964 -
4965 -unsigned long arch_align_stack(unsigned long sp)
4966 -{
4967 - return sp;
4968 -}
4969 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4970 index ef9e555..331bd29 100644
4971 --- a/arch/sh/include/asm/cache.h
4972 +++ b/arch/sh/include/asm/cache.h
4973 @@ -9,10 +9,11 @@
4974 #define __ASM_SH_CACHE_H
4975 #ifdef __KERNEL__
4976
4977 +#include <linux/const.h>
4978 #include <linux/init.h>
4979 #include <cpu/cache.h>
4980
4981 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4982 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4983
4984 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4985
4986 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4987 index afeb710..d1d1289 100644
4988 --- a/arch/sh/mm/mmap.c
4989 +++ b/arch/sh/mm/mmap.c
4990 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4991 addr = PAGE_ALIGN(addr);
4992
4993 vma = find_vma(mm, addr);
4994 - if (TASK_SIZE - len >= addr &&
4995 - (!vma || addr + len <= vma->vm_start))
4996 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4997 return addr;
4998 }
4999
5000 @@ -106,7 +105,7 @@ full_search:
5001 }
5002 return -ENOMEM;
5003 }
5004 - if (likely(!vma || addr + len <= vma->vm_start)) {
5005 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5006 /*
5007 * Remember the place where we stopped the search:
5008 */
5009 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5010 addr = PAGE_ALIGN(addr);
5011
5012 vma = find_vma(mm, addr);
5013 - if (TASK_SIZE - len >= addr &&
5014 - (!vma || addr + len <= vma->vm_start))
5015 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5016 return addr;
5017 }
5018
5019 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5020 /* make sure it can fit in the remaining address space */
5021 if (likely(addr > len)) {
5022 vma = find_vma(mm, addr-len);
5023 - if (!vma || addr <= vma->vm_start) {
5024 + if (check_heap_stack_gap(vma, addr - len, len)) {
5025 /* remember the address as a hint for next time */
5026 return (mm->free_area_cache = addr-len);
5027 }
5028 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5029 if (unlikely(mm->mmap_base < len))
5030 goto bottomup;
5031
5032 - addr = mm->mmap_base-len;
5033 - if (do_colour_align)
5034 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5035 + addr = mm->mmap_base - len;
5036
5037 do {
5038 + if (do_colour_align)
5039 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5040 /*
5041 * Lookup failure means no vma is above this address,
5042 * else if new region fits below vma->vm_start,
5043 * return with success:
5044 */
5045 vma = find_vma(mm, addr);
5046 - if (likely(!vma || addr+len <= vma->vm_start)) {
5047 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5048 /* remember the address as a hint for next time */
5049 return (mm->free_area_cache = addr);
5050 }
5051 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5052 mm->cached_hole_size = vma->vm_start - addr;
5053
5054 /* try just below the current vma->vm_start */
5055 - addr = vma->vm_start-len;
5056 - if (do_colour_align)
5057 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5058 - } while (likely(len < vma->vm_start));
5059 + addr = skip_heap_stack_gap(vma, len);
5060 + } while (!IS_ERR_VALUE(addr));
5061
5062 bottomup:
5063 /*
5064 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5065 index ce35a1c..2e7b8f9 100644
5066 --- a/arch/sparc/include/asm/atomic_64.h
5067 +++ b/arch/sparc/include/asm/atomic_64.h
5068 @@ -14,18 +14,40 @@
5069 #define ATOMIC64_INIT(i) { (i) }
5070
5071 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5072 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5073 +{
5074 + return v->counter;
5075 +}
5076 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5077 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5078 +{
5079 + return v->counter;
5080 +}
5081
5082 #define atomic_set(v, i) (((v)->counter) = i)
5083 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5084 +{
5085 + v->counter = i;
5086 +}
5087 #define atomic64_set(v, i) (((v)->counter) = i)
5088 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5089 +{
5090 + v->counter = i;
5091 +}
5092
5093 extern void atomic_add(int, atomic_t *);
5094 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5095 extern void atomic64_add(long, atomic64_t *);
5096 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5097 extern void atomic_sub(int, atomic_t *);
5098 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5099 extern void atomic64_sub(long, atomic64_t *);
5100 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5101
5102 extern int atomic_add_ret(int, atomic_t *);
5103 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5104 extern long atomic64_add_ret(long, atomic64_t *);
5105 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5106 extern int atomic_sub_ret(int, atomic_t *);
5107 extern long atomic64_sub_ret(long, atomic64_t *);
5108
5109 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5110 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5111
5112 #define atomic_inc_return(v) atomic_add_ret(1, v)
5113 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5114 +{
5115 + return atomic_add_ret_unchecked(1, v);
5116 +}
5117 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5118 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5119 +{
5120 + return atomic64_add_ret_unchecked(1, v);
5121 +}
5122
5123 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5124 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5125
5126 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5127 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5128 +{
5129 + return atomic_add_ret_unchecked(i, v);
5130 +}
5131 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5132 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5133 +{
5134 + return atomic64_add_ret_unchecked(i, v);
5135 +}
5136
5137 /*
5138 * atomic_inc_and_test - increment and test
5139 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5140 * other cases.
5141 */
5142 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5143 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5144 +{
5145 + return atomic_inc_return_unchecked(v) == 0;
5146 +}
5147 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5148
5149 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5150 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5151 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5152
5153 #define atomic_inc(v) atomic_add(1, v)
5154 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5155 +{
5156 + atomic_add_unchecked(1, v);
5157 +}
5158 #define atomic64_inc(v) atomic64_add(1, v)
5159 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5160 +{
5161 + atomic64_add_unchecked(1, v);
5162 +}
5163
5164 #define atomic_dec(v) atomic_sub(1, v)
5165 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5166 +{
5167 + atomic_sub_unchecked(1, v);
5168 +}
5169 #define atomic64_dec(v) atomic64_sub(1, v)
5170 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5171 +{
5172 + atomic64_sub_unchecked(1, v);
5173 +}
5174
5175 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5176 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5177
5178 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5179 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5180 +{
5181 + return cmpxchg(&v->counter, old, new);
5182 +}
5183 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5184 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5185 +{
5186 + return xchg(&v->counter, new);
5187 +}
5188
5189 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5190 {
5191 - int c, old;
5192 + int c, old, new;
5193 c = atomic_read(v);
5194 for (;;) {
5195 - if (unlikely(c == (u)))
5196 + if (unlikely(c == u))
5197 break;
5198 - old = atomic_cmpxchg((v), c, c + (a));
5199 +
5200 + asm volatile("addcc %2, %0, %0\n"
5201 +
5202 +#ifdef CONFIG_PAX_REFCOUNT
5203 + "tvs %%icc, 6\n"
5204 +#endif
5205 +
5206 + : "=r" (new)
5207 + : "0" (c), "ir" (a)
5208 + : "cc");
5209 +
5210 + old = atomic_cmpxchg(v, c, new);
5211 if (likely(old == c))
5212 break;
5213 c = old;
5214 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5215 #define atomic64_cmpxchg(v, o, n) \
5216 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5217 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5218 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5219 +{
5220 + return xchg(&v->counter, new);
5221 +}
5222
5223 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5224 {
5225 - long c, old;
5226 + long c, old, new;
5227 c = atomic64_read(v);
5228 for (;;) {
5229 - if (unlikely(c == (u)))
5230 + if (unlikely(c == u))
5231 break;
5232 - old = atomic64_cmpxchg((v), c, c + (a));
5233 +
5234 + asm volatile("addcc %2, %0, %0\n"
5235 +
5236 +#ifdef CONFIG_PAX_REFCOUNT
5237 + "tvs %%xcc, 6\n"
5238 +#endif
5239 +
5240 + : "=r" (new)
5241 + : "0" (c), "ir" (a)
5242 + : "cc");
5243 +
5244 + old = atomic64_cmpxchg(v, c, new);
5245 if (likely(old == c))
5246 break;
5247 c = old;
5248 }
5249 - return c != (u);
5250 + return c != u;
5251 }
5252
5253 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5254 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5255 index 5bb6991..5c2132e 100644
5256 --- a/arch/sparc/include/asm/cache.h
5257 +++ b/arch/sparc/include/asm/cache.h
5258 @@ -7,10 +7,12 @@
5259 #ifndef _SPARC_CACHE_H
5260 #define _SPARC_CACHE_H
5261
5262 +#include <linux/const.h>
5263 +
5264 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5265
5266 #define L1_CACHE_SHIFT 5
5267 -#define L1_CACHE_BYTES 32
5268 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5269
5270 #ifdef CONFIG_SPARC32
5271 #define SMP_CACHE_BYTES_SHIFT 5
5272 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5273 index 2d4d755..81b6662 100644
5274 --- a/arch/sparc/include/asm/elf_32.h
5275 +++ b/arch/sparc/include/asm/elf_32.h
5276 @@ -114,6 +114,13 @@ typedef struct {
5277
5278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5279
5280 +#ifdef CONFIG_PAX_ASLR
5281 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5282 +
5283 +#define PAX_DELTA_MMAP_LEN 16
5284 +#define PAX_DELTA_STACK_LEN 16
5285 +#endif
5286 +
5287 /* This yields a mask that user programs can use to figure out what
5288 instruction set this cpu supports. This can NOT be done in userspace
5289 on Sparc. */
5290 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5291 index 7df8b7f..4946269 100644
5292 --- a/arch/sparc/include/asm/elf_64.h
5293 +++ b/arch/sparc/include/asm/elf_64.h
5294 @@ -180,6 +180,13 @@ typedef struct {
5295 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5296 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5297
5298 +#ifdef CONFIG_PAX_ASLR
5299 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5300 +
5301 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5302 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5303 +#endif
5304 +
5305 extern unsigned long sparc64_elf_hwcap;
5306 #define ELF_HWCAP sparc64_elf_hwcap
5307
5308 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5309 index 9b1c36d..209298b 100644
5310 --- a/arch/sparc/include/asm/pgalloc_32.h
5311 +++ b/arch/sparc/include/asm/pgalloc_32.h
5312 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5313 }
5314
5315 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5316 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5317
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5319 unsigned long address)
5320 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5321 index 40b2d7a..22a665b 100644
5322 --- a/arch/sparc/include/asm/pgalloc_64.h
5323 +++ b/arch/sparc/include/asm/pgalloc_64.h
5324 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5325 }
5326
5327 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5328 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5329
5330 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5331 {
5332 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5333 index 6fc1348..390c50a 100644
5334 --- a/arch/sparc/include/asm/pgtable_32.h
5335 +++ b/arch/sparc/include/asm/pgtable_32.h
5336 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5337 #define PAGE_SHARED SRMMU_PAGE_SHARED
5338 #define PAGE_COPY SRMMU_PAGE_COPY
5339 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5340 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5341 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5342 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5343 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5344
5345 /* Top-level page directory - dummy used by init-mm.
5346 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5347
5348 /* xwr */
5349 #define __P000 PAGE_NONE
5350 -#define __P001 PAGE_READONLY
5351 -#define __P010 PAGE_COPY
5352 -#define __P011 PAGE_COPY
5353 +#define __P001 PAGE_READONLY_NOEXEC
5354 +#define __P010 PAGE_COPY_NOEXEC
5355 +#define __P011 PAGE_COPY_NOEXEC
5356 #define __P100 PAGE_READONLY
5357 #define __P101 PAGE_READONLY
5358 #define __P110 PAGE_COPY
5359 #define __P111 PAGE_COPY
5360
5361 #define __S000 PAGE_NONE
5362 -#define __S001 PAGE_READONLY
5363 -#define __S010 PAGE_SHARED
5364 -#define __S011 PAGE_SHARED
5365 +#define __S001 PAGE_READONLY_NOEXEC
5366 +#define __S010 PAGE_SHARED_NOEXEC
5367 +#define __S011 PAGE_SHARED_NOEXEC
5368 #define __S100 PAGE_READONLY
5369 #define __S101 PAGE_READONLY
5370 #define __S110 PAGE_SHARED
5371 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5372 index 79da178..c2eede8 100644
5373 --- a/arch/sparc/include/asm/pgtsrmmu.h
5374 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5375 @@ -115,6 +115,11 @@
5376 SRMMU_EXEC | SRMMU_REF)
5377 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5378 SRMMU_EXEC | SRMMU_REF)
5379 +
5380 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5381 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5382 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5383 +
5384 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5385 SRMMU_DIRTY | SRMMU_REF)
5386
5387 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5388 index 9689176..63c18ea 100644
5389 --- a/arch/sparc/include/asm/spinlock_64.h
5390 +++ b/arch/sparc/include/asm/spinlock_64.h
5391 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5392
5393 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5394
5395 -static void inline arch_read_lock(arch_rwlock_t *lock)
5396 +static inline void arch_read_lock(arch_rwlock_t *lock)
5397 {
5398 unsigned long tmp1, tmp2;
5399
5400 __asm__ __volatile__ (
5401 "1: ldsw [%2], %0\n"
5402 " brlz,pn %0, 2f\n"
5403 -"4: add %0, 1, %1\n"
5404 +"4: addcc %0, 1, %1\n"
5405 +
5406 +#ifdef CONFIG_PAX_REFCOUNT
5407 +" tvs %%icc, 6\n"
5408 +#endif
5409 +
5410 " cas [%2], %0, %1\n"
5411 " cmp %0, %1\n"
5412 " bne,pn %%icc, 1b\n"
5413 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5414 " .previous"
5415 : "=&r" (tmp1), "=&r" (tmp2)
5416 : "r" (lock)
5417 - : "memory");
5418 + : "memory", "cc");
5419 }
5420
5421 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5422 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5423 {
5424 int tmp1, tmp2;
5425
5426 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5427 "1: ldsw [%2], %0\n"
5428 " brlz,a,pn %0, 2f\n"
5429 " mov 0, %0\n"
5430 -" add %0, 1, %1\n"
5431 +" addcc %0, 1, %1\n"
5432 +
5433 +#ifdef CONFIG_PAX_REFCOUNT
5434 +" tvs %%icc, 6\n"
5435 +#endif
5436 +
5437 " cas [%2], %0, %1\n"
5438 " cmp %0, %1\n"
5439 " bne,pn %%icc, 1b\n"
5440 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5441 return tmp1;
5442 }
5443
5444 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5445 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5446 {
5447 unsigned long tmp1, tmp2;
5448
5449 __asm__ __volatile__(
5450 "1: lduw [%2], %0\n"
5451 -" sub %0, 1, %1\n"
5452 +" subcc %0, 1, %1\n"
5453 +
5454 +#ifdef CONFIG_PAX_REFCOUNT
5455 +" tvs %%icc, 6\n"
5456 +#endif
5457 +
5458 " cas [%2], %0, %1\n"
5459 " cmp %0, %1\n"
5460 " bne,pn %%xcc, 1b\n"
5461 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 : "memory");
5463 }
5464
5465 -static void inline arch_write_lock(arch_rwlock_t *lock)
5466 +static inline void arch_write_lock(arch_rwlock_t *lock)
5467 {
5468 unsigned long mask, tmp1, tmp2;
5469
5470 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5471 : "memory");
5472 }
5473
5474 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5475 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5476 {
5477 __asm__ __volatile__(
5478 " stw %%g0, [%0]"
5479 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5480 : "memory");
5481 }
5482
5483 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5484 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5485 {
5486 unsigned long mask, tmp1, tmp2, result;
5487
5488 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5489 index e6cd224..3a71793 100644
5490 --- a/arch/sparc/include/asm/thread_info_32.h
5491 +++ b/arch/sparc/include/asm/thread_info_32.h
5492 @@ -49,6 +49,8 @@ struct thread_info {
5493 unsigned long w_saved;
5494
5495 struct restart_block restart_block;
5496 +
5497 + unsigned long lowest_stack;
5498 };
5499
5500 /*
5501 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5502 index cfa8c38..13f30d3 100644
5503 --- a/arch/sparc/include/asm/thread_info_64.h
5504 +++ b/arch/sparc/include/asm/thread_info_64.h
5505 @@ -63,6 +63,8 @@ struct thread_info {
5506 struct pt_regs *kern_una_regs;
5507 unsigned int kern_una_insn;
5508
5509 + unsigned long lowest_stack;
5510 +
5511 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5512 };
5513
5514 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5515 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5516 /* flag bit 6 is available */
5517 #define TIF_32BIT 7 /* 32-bit binary */
5518 -/* flag bit 8 is available */
5519 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5520 #define TIF_SECCOMP 9 /* secure computing */
5521 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5522 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5523 +
5524 /* NOTE: Thread flags >= 12 should be ones we have no interest
5525 * in using in assembly, else we can't use the mask as
5526 * an immediate value in instructions such as andcc.
5527 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5528 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5529 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5530 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5531 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5532
5533 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5534 _TIF_DO_NOTIFY_RESUME_MASK | \
5535 _TIF_NEED_RESCHED)
5536 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5537
5538 +#define _TIF_WORK_SYSCALL \
5539 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5540 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5541 +
5542 +
5543 /*
5544 * Thread-synchronous status.
5545 *
5546 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5547 index 0167d26..9acd8ed 100644
5548 --- a/arch/sparc/include/asm/uaccess.h
5549 +++ b/arch/sparc/include/asm/uaccess.h
5550 @@ -1,5 +1,13 @@
5551 #ifndef ___ASM_SPARC_UACCESS_H
5552 #define ___ASM_SPARC_UACCESS_H
5553 +
5554 +#ifdef __KERNEL__
5555 +#ifndef __ASSEMBLY__
5556 +#include <linux/types.h>
5557 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5558 +#endif
5559 +#endif
5560 +
5561 #if defined(__sparc__) && defined(__arch64__)
5562 #include <asm/uaccess_64.h>
5563 #else
5564 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5565 index 53a28dd..50c38c3 100644
5566 --- a/arch/sparc/include/asm/uaccess_32.h
5567 +++ b/arch/sparc/include/asm/uaccess_32.h
5568 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5569
5570 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5571 {
5572 - if (n && __access_ok((unsigned long) to, n))
5573 + if ((long)n < 0)
5574 + return n;
5575 +
5576 + if (n && __access_ok((unsigned long) to, n)) {
5577 + if (!__builtin_constant_p(n))
5578 + check_object_size(from, n, true);
5579 return __copy_user(to, (__force void __user *) from, n);
5580 - else
5581 + } else
5582 return n;
5583 }
5584
5585 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5586 {
5587 + if ((long)n < 0)
5588 + return n;
5589 +
5590 + if (!__builtin_constant_p(n))
5591 + check_object_size(from, n, true);
5592 +
5593 return __copy_user(to, (__force void __user *) from, n);
5594 }
5595
5596 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5597 {
5598 - if (n && __access_ok((unsigned long) from, n))
5599 + if ((long)n < 0)
5600 + return n;
5601 +
5602 + if (n && __access_ok((unsigned long) from, n)) {
5603 + if (!__builtin_constant_p(n))
5604 + check_object_size(to, n, false);
5605 return __copy_user((__force void __user *) to, from, n);
5606 - else
5607 + } else
5608 return n;
5609 }
5610
5611 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5612 {
5613 + if ((long)n < 0)
5614 + return n;
5615 +
5616 return __copy_user((__force void __user *) to, from, n);
5617 }
5618
5619 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5620 index 7c831d8..d440ca7 100644
5621 --- a/arch/sparc/include/asm/uaccess_64.h
5622 +++ b/arch/sparc/include/asm/uaccess_64.h
5623 @@ -10,6 +10,7 @@
5624 #include <linux/compiler.h>
5625 #include <linux/string.h>
5626 #include <linux/thread_info.h>
5627 +#include <linux/kernel.h>
5628 #include <asm/asi.h>
5629 #include <asm/spitfire.h>
5630 #include <asm-generic/uaccess-unaligned.h>
5631 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5632 static inline unsigned long __must_check
5633 copy_from_user(void *to, const void __user *from, unsigned long size)
5634 {
5635 - unsigned long ret = ___copy_from_user(to, from, size);
5636 + unsigned long ret;
5637
5638 + if ((long)size < 0 || size > INT_MAX)
5639 + return size;
5640 +
5641 + if (!__builtin_constant_p(size))
5642 + check_object_size(to, size, false);
5643 +
5644 + ret = ___copy_from_user(to, from, size);
5645 if (unlikely(ret))
5646 ret = copy_from_user_fixup(to, from, size);
5647
5648 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5649 static inline unsigned long __must_check
5650 copy_to_user(void __user *to, const void *from, unsigned long size)
5651 {
5652 - unsigned long ret = ___copy_to_user(to, from, size);
5653 + unsigned long ret;
5654
5655 + if ((long)size < 0 || size > INT_MAX)
5656 + return size;
5657 +
5658 + if (!__builtin_constant_p(size))
5659 + check_object_size(from, size, true);
5660 +
5661 + ret = ___copy_to_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_to_user_fixup(to, from, size);
5664 return ret;
5665 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5666 index 6cf591b..b49e65a 100644
5667 --- a/arch/sparc/kernel/Makefile
5668 +++ b/arch/sparc/kernel/Makefile
5669 @@ -3,7 +3,7 @@
5670 #
5671
5672 asflags-y := -ansi
5673 -ccflags-y := -Werror
5674 +#ccflags-y := -Werror
5675
5676 extra-y := head_$(BITS).o
5677
5678 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5679 index 14006d8..8146238 100644
5680 --- a/arch/sparc/kernel/process_32.c
5681 +++ b/arch/sparc/kernel/process_32.c
5682 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5683
5684 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5685 r->psr, r->pc, r->npc, r->y, print_tainted());
5686 - printk("PC: <%pS>\n", (void *) r->pc);
5687 + printk("PC: <%pA>\n", (void *) r->pc);
5688 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5689 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5690 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5691 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5692 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5693 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5694 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5695 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5696
5697 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5698 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5699 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5700 rw = (struct reg_window32 *) fp;
5701 pc = rw->ins[7];
5702 printk("[%08lx : ", pc);
5703 - printk("%pS ] ", (void *) pc);
5704 + printk("%pA ] ", (void *) pc);
5705 fp = rw->ins[6];
5706 } while (++count < 16);
5707 printk("\n");
5708 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5709 index aff0c72..9067b39 100644
5710 --- a/arch/sparc/kernel/process_64.c
5711 +++ b/arch/sparc/kernel/process_64.c
5712 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5713 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5714 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5715 if (regs->tstate & TSTATE_PRIV)
5716 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5717 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5718 }
5719
5720 void show_regs(struct pt_regs *regs)
5721 {
5722 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5723 regs->tpc, regs->tnpc, regs->y, print_tainted());
5724 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5725 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5726 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5727 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5728 regs->u_regs[3]);
5729 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5730 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5731 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5732 regs->u_regs[15]);
5733 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5734 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5735 show_regwindow(regs);
5736 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5737 }
5738 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5739 ((tp && tp->task) ? tp->task->pid : -1));
5740
5741 if (gp->tstate & TSTATE_PRIV) {
5742 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5743 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5744 (void *) gp->tpc,
5745 (void *) gp->o7,
5746 (void *) gp->i7,
5747 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5748 index 484daba..0674139 100644
5749 --- a/arch/sparc/kernel/ptrace_64.c
5750 +++ b/arch/sparc/kernel/ptrace_64.c
5751 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5752 return ret;
5753 }
5754
5755 +#ifdef CONFIG_GRKERNSEC_SETXID
5756 +extern void gr_delayed_cred_worker(void);
5757 +#endif
5758 +
5759 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5760 {
5761 int ret = 0;
5762 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5763 /* do the secure computing check first */
5764 secure_computing_strict(regs->u_regs[UREG_G1]);
5765
5766 +#ifdef CONFIG_GRKERNSEC_SETXID
5767 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5768 + gr_delayed_cred_worker();
5769 +#endif
5770 +
5771 if (test_thread_flag(TIF_SYSCALL_TRACE))
5772 ret = tracehook_report_syscall_entry(regs);
5773
5774 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5775
5776 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5777 {
5778 +#ifdef CONFIG_GRKERNSEC_SETXID
5779 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5780 + gr_delayed_cred_worker();
5781 +#endif
5782 +
5783 audit_syscall_exit(regs);
5784
5785 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5786 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5787 index 0c9b31b..7cb7aee 100644
5788 --- a/arch/sparc/kernel/sys_sparc_32.c
5789 +++ b/arch/sparc/kernel/sys_sparc_32.c
5790 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5791 if (len > TASK_SIZE - PAGE_SIZE)
5792 return -ENOMEM;
5793 if (!addr)
5794 - addr = TASK_UNMAPPED_BASE;
5795 + addr = current->mm->mmap_base;
5796
5797 if (flags & MAP_SHARED)
5798 addr = COLOUR_ALIGN(addr);
5799 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5800 /* At this point: (!vmm || addr < vmm->vm_end). */
5801 if (TASK_SIZE - PAGE_SIZE - len < addr)
5802 return -ENOMEM;
5803 - if (!vmm || addr + len <= vmm->vm_start)
5804 + if (check_heap_stack_gap(vmm, addr, len))
5805 return addr;
5806 addr = vmm->vm_end;
5807 if (flags & MAP_SHARED)
5808 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5809 index 11c6c96..3ec33e8 100644
5810 --- a/arch/sparc/kernel/sys_sparc_64.c
5811 +++ b/arch/sparc/kernel/sys_sparc_64.c
5812 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5813 /* We do not accept a shared mapping if it would violate
5814 * cache aliasing constraints.
5815 */
5816 - if ((flags & MAP_SHARED) &&
5817 + if ((filp || (flags & MAP_SHARED)) &&
5818 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5819 return -EINVAL;
5820 return addr;
5821 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5822 if (filp || (flags & MAP_SHARED))
5823 do_color_align = 1;
5824
5825 +#ifdef CONFIG_PAX_RANDMMAP
5826 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5827 +#endif
5828 +
5829 if (addr) {
5830 if (do_color_align)
5831 addr = COLOUR_ALIGN(addr, pgoff);
5832 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5833 addr = PAGE_ALIGN(addr);
5834
5835 vma = find_vma(mm, addr);
5836 - if (task_size - len >= addr &&
5837 - (!vma || addr + len <= vma->vm_start))
5838 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5839 return addr;
5840 }
5841
5842 if (len > mm->cached_hole_size) {
5843 - start_addr = addr = mm->free_area_cache;
5844 + start_addr = addr = mm->free_area_cache;
5845 } else {
5846 - start_addr = addr = TASK_UNMAPPED_BASE;
5847 + start_addr = addr = mm->mmap_base;
5848 mm->cached_hole_size = 0;
5849 }
5850
5851 @@ -157,14 +160,14 @@ full_search:
5852 vma = find_vma(mm, VA_EXCLUDE_END);
5853 }
5854 if (unlikely(task_size < addr)) {
5855 - if (start_addr != TASK_UNMAPPED_BASE) {
5856 - start_addr = addr = TASK_UNMAPPED_BASE;
5857 + if (start_addr != mm->mmap_base) {
5858 + start_addr = addr = mm->mmap_base;
5859 mm->cached_hole_size = 0;
5860 goto full_search;
5861 }
5862 return -ENOMEM;
5863 }
5864 - if (likely(!vma || addr + len <= vma->vm_start)) {
5865 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5866 /*
5867 * Remember the place where we stopped the search:
5868 */
5869 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5870 /* We do not accept a shared mapping if it would violate
5871 * cache aliasing constraints.
5872 */
5873 - if ((flags & MAP_SHARED) &&
5874 + if ((filp || (flags & MAP_SHARED)) &&
5875 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5876 return -EINVAL;
5877 return addr;
5878 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5879 addr = PAGE_ALIGN(addr);
5880
5881 vma = find_vma(mm, addr);
5882 - if (task_size - len >= addr &&
5883 - (!vma || addr + len <= vma->vm_start))
5884 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5885 return addr;
5886 }
5887
5888 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5889 /* make sure it can fit in the remaining address space */
5890 if (likely(addr > len)) {
5891 vma = find_vma(mm, addr-len);
5892 - if (!vma || addr <= vma->vm_start) {
5893 + if (check_heap_stack_gap(vma, addr - len, len)) {
5894 /* remember the address as a hint for next time */
5895 return (mm->free_area_cache = addr-len);
5896 }
5897 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5898 if (unlikely(mm->mmap_base < len))
5899 goto bottomup;
5900
5901 - addr = mm->mmap_base-len;
5902 - if (do_color_align)
5903 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5904 + addr = mm->mmap_base - len;
5905
5906 do {
5907 + if (do_color_align)
5908 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5909 /*
5910 * Lookup failure means no vma is above this address,
5911 * else if new region fits below vma->vm_start,
5912 * return with success:
5913 */
5914 vma = find_vma(mm, addr);
5915 - if (likely(!vma || addr+len <= vma->vm_start)) {
5916 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5917 /* remember the address as a hint for next time */
5918 return (mm->free_area_cache = addr);
5919 }
5920 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5921 mm->cached_hole_size = vma->vm_start - addr;
5922
5923 /* try just below the current vma->vm_start */
5924 - addr = vma->vm_start-len;
5925 - if (do_color_align)
5926 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5927 - } while (likely(len < vma->vm_start));
5928 + addr = skip_heap_stack_gap(vma, len);
5929 + } while (!IS_ERR_VALUE(addr));
5930
5931 bottomup:
5932 /*
5933 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5934 gap == RLIM_INFINITY ||
5935 sysctl_legacy_va_layout) {
5936 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5937 +
5938 +#ifdef CONFIG_PAX_RANDMMAP
5939 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5940 + mm->mmap_base += mm->delta_mmap;
5941 +#endif
5942 +
5943 mm->get_unmapped_area = arch_get_unmapped_area;
5944 mm->unmap_area = arch_unmap_area;
5945 } else {
5946 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5947 gap = (task_size / 6 * 5);
5948
5949 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5950 +
5951 +#ifdef CONFIG_PAX_RANDMMAP
5952 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5953 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5954 +#endif
5955 +
5956 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5957 mm->unmap_area = arch_unmap_area_topdown;
5958 }
5959 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5960 index 1d7e274..b39c527 100644
5961 --- a/arch/sparc/kernel/syscalls.S
5962 +++ b/arch/sparc/kernel/syscalls.S
5963 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5964 #endif
5965 .align 32
5966 1: ldx [%g6 + TI_FLAGS], %l5
5967 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5968 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5969 be,pt %icc, rtrap
5970 nop
5971 call syscall_trace_leave
5972 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5973
5974 srl %i5, 0, %o5 ! IEU1
5975 srl %i2, 0, %o2 ! IEU0 Group
5976 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5977 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5978 bne,pn %icc, linux_syscall_trace32 ! CTI
5979 mov %i0, %l5 ! IEU1
5980 call %l7 ! CTI Group brk forced
5981 @@ -202,7 +202,7 @@ linux_sparc_syscall:
5982
5983 mov %i3, %o3 ! IEU1
5984 mov %i4, %o4 ! IEU0 Group
5985 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5986 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5987 bne,pn %icc, linux_syscall_trace ! CTI Group
5988 mov %i0, %l5 ! IEU0
5989 2: call %l7 ! CTI Group brk forced
5990 @@ -226,7 +226,7 @@ ret_sys_call:
5991
5992 cmp %o0, -ERESTART_RESTARTBLOCK
5993 bgeu,pn %xcc, 1f
5994 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
5995 + andcc %l0, _TIF_WORK_SYSCALL, %l6
5996 80:
5997 /* System call success, clear Carry condition code. */
5998 andn %g3, %g2, %g3
5999 @@ -241,7 +241,7 @@ ret_sys_call:
6000 /* System call failure, set Carry condition code.
6001 * Also, get abs(errno) to return to the process.
6002 */
6003 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6004 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6005 sub %g0, %o0, %o0
6006 or %g3, %g2, %g3
6007 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6008 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6009 index a5785ea..405c5f7 100644
6010 --- a/arch/sparc/kernel/traps_32.c
6011 +++ b/arch/sparc/kernel/traps_32.c
6012 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6013 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6014 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6015
6016 +extern void gr_handle_kernel_exploit(void);
6017 +
6018 void die_if_kernel(char *str, struct pt_regs *regs)
6019 {
6020 static int die_counter;
6021 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6022 count++ < 30 &&
6023 (((unsigned long) rw) >= PAGE_OFFSET) &&
6024 !(((unsigned long) rw) & 0x7)) {
6025 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6026 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6027 (void *) rw->ins[7]);
6028 rw = (struct reg_window32 *)rw->ins[6];
6029 }
6030 }
6031 printk("Instruction DUMP:");
6032 instruction_dump ((unsigned long *) regs->pc);
6033 - if(regs->psr & PSR_PS)
6034 + if(regs->psr & PSR_PS) {
6035 + gr_handle_kernel_exploit();
6036 do_exit(SIGKILL);
6037 + }
6038 do_exit(SIGSEGV);
6039 }
6040
6041 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6042 index 3b05e66..6ea2917 100644
6043 --- a/arch/sparc/kernel/traps_64.c
6044 +++ b/arch/sparc/kernel/traps_64.c
6045 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6046 i + 1,
6047 p->trapstack[i].tstate, p->trapstack[i].tpc,
6048 p->trapstack[i].tnpc, p->trapstack[i].tt);
6049 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6050 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6051 }
6052 }
6053
6054 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6055
6056 lvl -= 0x100;
6057 if (regs->tstate & TSTATE_PRIV) {
6058 +
6059 +#ifdef CONFIG_PAX_REFCOUNT
6060 + if (lvl == 6)
6061 + pax_report_refcount_overflow(regs);
6062 +#endif
6063 +
6064 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6065 die_if_kernel(buffer, regs);
6066 }
6067 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6068 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6069 {
6070 char buffer[32];
6071 -
6072 +
6073 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6074 0, lvl, SIGTRAP) == NOTIFY_STOP)
6075 return;
6076
6077 +#ifdef CONFIG_PAX_REFCOUNT
6078 + if (lvl == 6)
6079 + pax_report_refcount_overflow(regs);
6080 +#endif
6081 +
6082 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6083
6084 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6085 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6086 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6087 printk("%s" "ERROR(%d): ",
6088 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6089 - printk("TPC<%pS>\n", (void *) regs->tpc);
6090 + printk("TPC<%pA>\n", (void *) regs->tpc);
6091 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6092 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6093 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6094 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6095 smp_processor_id(),
6096 (type & 0x1) ? 'I' : 'D',
6097 regs->tpc);
6098 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6099 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6100 panic("Irrecoverable Cheetah+ parity error.");
6101 }
6102
6103 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6104 smp_processor_id(),
6105 (type & 0x1) ? 'I' : 'D',
6106 regs->tpc);
6107 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6108 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6109 }
6110
6111 struct sun4v_error_entry {
6112 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6113
6114 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6115 regs->tpc, tl);
6116 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6117 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6118 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6119 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6120 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6121 (void *) regs->u_regs[UREG_I7]);
6122 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6123 "pte[%lx] error[%lx]\n",
6124 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6125
6126 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6127 regs->tpc, tl);
6128 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6129 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6130 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6131 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6132 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6133 (void *) regs->u_regs[UREG_I7]);
6134 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6135 "pte[%lx] error[%lx]\n",
6136 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6137 fp = (unsigned long)sf->fp + STACK_BIAS;
6138 }
6139
6140 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6141 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6142 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6143 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6144 int index = tsk->curr_ret_stack;
6145 if (tsk->ret_stack && index >= graph) {
6146 pc = tsk->ret_stack[index - graph].ret;
6147 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6148 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6149 graph++;
6150 }
6151 }
6152 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6153 return (struct reg_window *) (fp + STACK_BIAS);
6154 }
6155
6156 +extern void gr_handle_kernel_exploit(void);
6157 +
6158 void die_if_kernel(char *str, struct pt_regs *regs)
6159 {
6160 static int die_counter;
6161 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6162 while (rw &&
6163 count++ < 30 &&
6164 kstack_valid(tp, (unsigned long) rw)) {
6165 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6166 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6167 (void *) rw->ins[7]);
6168
6169 rw = kernel_stack_up(rw);
6170 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6171 }
6172 user_instruction_dump ((unsigned int __user *) regs->tpc);
6173 }
6174 - if (regs->tstate & TSTATE_PRIV)
6175 + if (regs->tstate & TSTATE_PRIV) {
6176 + gr_handle_kernel_exploit();
6177 do_exit(SIGKILL);
6178 + }
6179 do_exit(SIGSEGV);
6180 }
6181 EXPORT_SYMBOL(die_if_kernel);
6182 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6183 index f81d038..e7a4680 100644
6184 --- a/arch/sparc/kernel/unaligned_64.c
6185 +++ b/arch/sparc/kernel/unaligned_64.c
6186 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6187 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6188
6189 if (__ratelimit(&ratelimit)) {
6190 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6191 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6192 regs->tpc, (void *) regs->tpc);
6193 }
6194 }
6195 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6196 index dff4096..bd9a388 100644
6197 --- a/arch/sparc/lib/Makefile
6198 +++ b/arch/sparc/lib/Makefile
6199 @@ -2,7 +2,7 @@
6200 #
6201
6202 asflags-y := -ansi -DST_DIV0=0x02
6203 -ccflags-y := -Werror
6204 +#ccflags-y := -Werror
6205
6206 lib-$(CONFIG_SPARC32) += ashrdi3.o
6207 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6208 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6209 index 4d502da..527c48d 100644
6210 --- a/arch/sparc/lib/atomic_64.S
6211 +++ b/arch/sparc/lib/atomic_64.S
6212 @@ -17,7 +17,12 @@
6213 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6214 BACKOFF_SETUP(%o2)
6215 1: lduw [%o1], %g1
6216 - add %g1, %o0, %g7
6217 + addcc %g1, %o0, %g7
6218 +
6219 +#ifdef CONFIG_PAX_REFCOUNT
6220 + tvs %icc, 6
6221 +#endif
6222 +
6223 cas [%o1], %g1, %g7
6224 cmp %g1, %g7
6225 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6226 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6227 2: BACKOFF_SPIN(%o2, %o3, 1b)
6228 ENDPROC(atomic_add)
6229
6230 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6231 + BACKOFF_SETUP(%o2)
6232 +1: lduw [%o1], %g1
6233 + add %g1, %o0, %g7
6234 + cas [%o1], %g1, %g7
6235 + cmp %g1, %g7
6236 + bne,pn %icc, 2f
6237 + nop
6238 + retl
6239 + nop
6240 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6241 +ENDPROC(atomic_add_unchecked)
6242 +
6243 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6244 BACKOFF_SETUP(%o2)
6245 1: lduw [%o1], %g1
6246 - sub %g1, %o0, %g7
6247 + subcc %g1, %o0, %g7
6248 +
6249 +#ifdef CONFIG_PAX_REFCOUNT
6250 + tvs %icc, 6
6251 +#endif
6252 +
6253 cas [%o1], %g1, %g7
6254 cmp %g1, %g7
6255 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6256 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6257 2: BACKOFF_SPIN(%o2, %o3, 1b)
6258 ENDPROC(atomic_sub)
6259
6260 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6261 + BACKOFF_SETUP(%o2)
6262 +1: lduw [%o1], %g1
6263 + sub %g1, %o0, %g7
6264 + cas [%o1], %g1, %g7
6265 + cmp %g1, %g7
6266 + bne,pn %icc, 2f
6267 + nop
6268 + retl
6269 + nop
6270 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6271 +ENDPROC(atomic_sub_unchecked)
6272 +
6273 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6274 BACKOFF_SETUP(%o2)
6275 1: lduw [%o1], %g1
6276 - add %g1, %o0, %g7
6277 + addcc %g1, %o0, %g7
6278 +
6279 +#ifdef CONFIG_PAX_REFCOUNT
6280 + tvs %icc, 6
6281 +#endif
6282 +
6283 cas [%o1], %g1, %g7
6284 cmp %g1, %g7
6285 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6286 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6287 2: BACKOFF_SPIN(%o2, %o3, 1b)
6288 ENDPROC(atomic_add_ret)
6289
6290 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6291 + BACKOFF_SETUP(%o2)
6292 +1: lduw [%o1], %g1
6293 + addcc %g1, %o0, %g7
6294 + cas [%o1], %g1, %g7
6295 + cmp %g1, %g7
6296 + bne,pn %icc, 2f
6297 + add %g7, %o0, %g7
6298 + sra %g7, 0, %o0
6299 + retl
6300 + nop
6301 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6302 +ENDPROC(atomic_add_ret_unchecked)
6303 +
6304 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6305 BACKOFF_SETUP(%o2)
6306 1: lduw [%o1], %g1
6307 - sub %g1, %o0, %g7
6308 + subcc %g1, %o0, %g7
6309 +
6310 +#ifdef CONFIG_PAX_REFCOUNT
6311 + tvs %icc, 6
6312 +#endif
6313 +
6314 cas [%o1], %g1, %g7
6315 cmp %g1, %g7
6316 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6317 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6318 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6319 BACKOFF_SETUP(%o2)
6320 1: ldx [%o1], %g1
6321 - add %g1, %o0, %g7
6322 + addcc %g1, %o0, %g7
6323 +
6324 +#ifdef CONFIG_PAX_REFCOUNT
6325 + tvs %xcc, 6
6326 +#endif
6327 +
6328 casx [%o1], %g1, %g7
6329 cmp %g1, %g7
6330 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6331 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6332 2: BACKOFF_SPIN(%o2, %o3, 1b)
6333 ENDPROC(atomic64_add)
6334
6335 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6336 + BACKOFF_SETUP(%o2)
6337 +1: ldx [%o1], %g1
6338 + addcc %g1, %o0, %g7
6339 + casx [%o1], %g1, %g7
6340 + cmp %g1, %g7
6341 + bne,pn %xcc, 2f
6342 + nop
6343 + retl
6344 + nop
6345 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6346 +ENDPROC(atomic64_add_unchecked)
6347 +
6348 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6349 BACKOFF_SETUP(%o2)
6350 1: ldx [%o1], %g1
6351 - sub %g1, %o0, %g7
6352 + subcc %g1, %o0, %g7
6353 +
6354 +#ifdef CONFIG_PAX_REFCOUNT
6355 + tvs %xcc, 6
6356 +#endif
6357 +
6358 casx [%o1], %g1, %g7
6359 cmp %g1, %g7
6360 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6361 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6362 2: BACKOFF_SPIN(%o2, %o3, 1b)
6363 ENDPROC(atomic64_sub)
6364
6365 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6366 + BACKOFF_SETUP(%o2)
6367 +1: ldx [%o1], %g1
6368 + subcc %g1, %o0, %g7
6369 + casx [%o1], %g1, %g7
6370 + cmp %g1, %g7
6371 + bne,pn %xcc, 2f
6372 + nop
6373 + retl
6374 + nop
6375 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6376 +ENDPROC(atomic64_sub_unchecked)
6377 +
6378 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6379 BACKOFF_SETUP(%o2)
6380 1: ldx [%o1], %g1
6381 - add %g1, %o0, %g7
6382 + addcc %g1, %o0, %g7
6383 +
6384 +#ifdef CONFIG_PAX_REFCOUNT
6385 + tvs %xcc, 6
6386 +#endif
6387 +
6388 casx [%o1], %g1, %g7
6389 cmp %g1, %g7
6390 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6391 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6392 2: BACKOFF_SPIN(%o2, %o3, 1b)
6393 ENDPROC(atomic64_add_ret)
6394
6395 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6396 + BACKOFF_SETUP(%o2)
6397 +1: ldx [%o1], %g1
6398 + addcc %g1, %o0, %g7
6399 + casx [%o1], %g1, %g7
6400 + cmp %g1, %g7
6401 + bne,pn %xcc, 2f
6402 + add %g7, %o0, %g7
6403 + mov %g7, %o0
6404 + retl
6405 + nop
6406 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6407 +ENDPROC(atomic64_add_ret_unchecked)
6408 +
6409 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6410 BACKOFF_SETUP(%o2)
6411 1: ldx [%o1], %g1
6412 - sub %g1, %o0, %g7
6413 + subcc %g1, %o0, %g7
6414 +
6415 +#ifdef CONFIG_PAX_REFCOUNT
6416 + tvs %xcc, 6
6417 +#endif
6418 +
6419 casx [%o1], %g1, %g7
6420 cmp %g1, %g7
6421 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6422 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6423 index 3b31218..345c609 100644
6424 --- a/arch/sparc/lib/ksyms.c
6425 +++ b/arch/sparc/lib/ksyms.c
6426 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6427
6428 /* Atomic counter implementation. */
6429 EXPORT_SYMBOL(atomic_add);
6430 +EXPORT_SYMBOL(atomic_add_unchecked);
6431 EXPORT_SYMBOL(atomic_add_ret);
6432 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6433 EXPORT_SYMBOL(atomic_sub);
6434 +EXPORT_SYMBOL(atomic_sub_unchecked);
6435 EXPORT_SYMBOL(atomic_sub_ret);
6436 EXPORT_SYMBOL(atomic64_add);
6437 +EXPORT_SYMBOL(atomic64_add_unchecked);
6438 EXPORT_SYMBOL(atomic64_add_ret);
6439 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6440 EXPORT_SYMBOL(atomic64_sub);
6441 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6442 EXPORT_SYMBOL(atomic64_sub_ret);
6443
6444 /* Atomic bit operations. */
6445 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6446 index 30c3ecc..736f015 100644
6447 --- a/arch/sparc/mm/Makefile
6448 +++ b/arch/sparc/mm/Makefile
6449 @@ -2,7 +2,7 @@
6450 #
6451
6452 asflags-y := -ansi
6453 -ccflags-y := -Werror
6454 +#ccflags-y := -Werror
6455
6456 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6457 obj-y += fault_$(BITS).o
6458 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6459 index 77ac917..baf45db 100644
6460 --- a/arch/sparc/mm/fault_32.c
6461 +++ b/arch/sparc/mm/fault_32.c
6462 @@ -21,6 +21,9 @@
6463 #include <linux/perf_event.h>
6464 #include <linux/interrupt.h>
6465 #include <linux/kdebug.h>
6466 +#include <linux/slab.h>
6467 +#include <linux/pagemap.h>
6468 +#include <linux/compiler.h>
6469
6470 #include <asm/page.h>
6471 #include <asm/pgtable.h>
6472 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6473 return safe_compute_effective_address(regs, insn);
6474 }
6475
6476 +#ifdef CONFIG_PAX_PAGEEXEC
6477 +#ifdef CONFIG_PAX_DLRESOLVE
6478 +static void pax_emuplt_close(struct vm_area_struct *vma)
6479 +{
6480 + vma->vm_mm->call_dl_resolve = 0UL;
6481 +}
6482 +
6483 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6484 +{
6485 + unsigned int *kaddr;
6486 +
6487 + vmf->page = alloc_page(GFP_HIGHUSER);
6488 + if (!vmf->page)
6489 + return VM_FAULT_OOM;
6490 +
6491 + kaddr = kmap(vmf->page);
6492 + memset(kaddr, 0, PAGE_SIZE);
6493 + kaddr[0] = 0x9DE3BFA8U; /* save */
6494 + flush_dcache_page(vmf->page);
6495 + kunmap(vmf->page);
6496 + return VM_FAULT_MAJOR;
6497 +}
6498 +
6499 +static const struct vm_operations_struct pax_vm_ops = {
6500 + .close = pax_emuplt_close,
6501 + .fault = pax_emuplt_fault
6502 +};
6503 +
6504 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6505 +{
6506 + int ret;
6507 +
6508 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6509 + vma->vm_mm = current->mm;
6510 + vma->vm_start = addr;
6511 + vma->vm_end = addr + PAGE_SIZE;
6512 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6513 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6514 + vma->vm_ops = &pax_vm_ops;
6515 +
6516 + ret = insert_vm_struct(current->mm, vma);
6517 + if (ret)
6518 + return ret;
6519 +
6520 + ++current->mm->total_vm;
6521 + return 0;
6522 +}
6523 +#endif
6524 +
6525 +/*
6526 + * PaX: decide what to do with offenders (regs->pc = fault address)
6527 + *
6528 + * returns 1 when task should be killed
6529 + * 2 when patched PLT trampoline was detected
6530 + * 3 when unpatched PLT trampoline was detected
6531 + */
6532 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6533 +{
6534 +
6535 +#ifdef CONFIG_PAX_EMUPLT
6536 + int err;
6537 +
6538 + do { /* PaX: patched PLT emulation #1 */
6539 + unsigned int sethi1, sethi2, jmpl;
6540 +
6541 + err = get_user(sethi1, (unsigned int *)regs->pc);
6542 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6543 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6544 +
6545 + if (err)
6546 + break;
6547 +
6548 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6549 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6550 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6551 + {
6552 + unsigned int addr;
6553 +
6554 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6555 + addr = regs->u_regs[UREG_G1];
6556 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6557 + regs->pc = addr;
6558 + regs->npc = addr+4;
6559 + return 2;
6560 + }
6561 + } while (0);
6562 +
6563 + do { /* PaX: patched PLT emulation #2 */
6564 + unsigned int ba;
6565 +
6566 + err = get_user(ba, (unsigned int *)regs->pc);
6567 +
6568 + if (err)
6569 + break;
6570 +
6571 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6572 + unsigned int addr;
6573 +
6574 + if ((ba & 0xFFC00000U) == 0x30800000U)
6575 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6576 + else
6577 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6578 + regs->pc = addr;
6579 + regs->npc = addr+4;
6580 + return 2;
6581 + }
6582 + } while (0);
6583 +
6584 + do { /* PaX: patched PLT emulation #3 */
6585 + unsigned int sethi, bajmpl, nop;
6586 +
6587 + err = get_user(sethi, (unsigned int *)regs->pc);
6588 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6589 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6590 +
6591 + if (err)
6592 + break;
6593 +
6594 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6595 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6596 + nop == 0x01000000U)
6597 + {
6598 + unsigned int addr;
6599 +
6600 + addr = (sethi & 0x003FFFFFU) << 10;
6601 + regs->u_regs[UREG_G1] = addr;
6602 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6603 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6604 + else
6605 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606 + regs->pc = addr;
6607 + regs->npc = addr+4;
6608 + return 2;
6609 + }
6610 + } while (0);
6611 +
6612 + do { /* PaX: unpatched PLT emulation step 1 */
6613 + unsigned int sethi, ba, nop;
6614 +
6615 + err = get_user(sethi, (unsigned int *)regs->pc);
6616 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6617 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618 +
6619 + if (err)
6620 + break;
6621 +
6622 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6624 + nop == 0x01000000U)
6625 + {
6626 + unsigned int addr, save, call;
6627 +
6628 + if ((ba & 0xFFC00000U) == 0x30800000U)
6629 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6630 + else
6631 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6632 +
6633 + err = get_user(save, (unsigned int *)addr);
6634 + err |= get_user(call, (unsigned int *)(addr+4));
6635 + err |= get_user(nop, (unsigned int *)(addr+8));
6636 + if (err)
6637 + break;
6638 +
6639 +#ifdef CONFIG_PAX_DLRESOLVE
6640 + if (save == 0x9DE3BFA8U &&
6641 + (call & 0xC0000000U) == 0x40000000U &&
6642 + nop == 0x01000000U)
6643 + {
6644 + struct vm_area_struct *vma;
6645 + unsigned long call_dl_resolve;
6646 +
6647 + down_read(&current->mm->mmap_sem);
6648 + call_dl_resolve = current->mm->call_dl_resolve;
6649 + up_read(&current->mm->mmap_sem);
6650 + if (likely(call_dl_resolve))
6651 + goto emulate;
6652 +
6653 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6654 +
6655 + down_write(&current->mm->mmap_sem);
6656 + if (current->mm->call_dl_resolve) {
6657 + call_dl_resolve = current->mm->call_dl_resolve;
6658 + up_write(&current->mm->mmap_sem);
6659 + if (vma)
6660 + kmem_cache_free(vm_area_cachep, vma);
6661 + goto emulate;
6662 + }
6663 +
6664 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6665 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6666 + up_write(&current->mm->mmap_sem);
6667 + if (vma)
6668 + kmem_cache_free(vm_area_cachep, vma);
6669 + return 1;
6670 + }
6671 +
6672 + if (pax_insert_vma(vma, call_dl_resolve)) {
6673 + up_write(&current->mm->mmap_sem);
6674 + kmem_cache_free(vm_area_cachep, vma);
6675 + return 1;
6676 + }
6677 +
6678 + current->mm->call_dl_resolve = call_dl_resolve;
6679 + up_write(&current->mm->mmap_sem);
6680 +
6681 +emulate:
6682 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6683 + regs->pc = call_dl_resolve;
6684 + regs->npc = addr+4;
6685 + return 3;
6686 + }
6687 +#endif
6688 +
6689 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6690 + if ((save & 0xFFC00000U) == 0x05000000U &&
6691 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6692 + nop == 0x01000000U)
6693 + {
6694 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6695 + regs->u_regs[UREG_G2] = addr + 4;
6696 + addr = (save & 0x003FFFFFU) << 10;
6697 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6698 + regs->pc = addr;
6699 + regs->npc = addr+4;
6700 + return 3;
6701 + }
6702 + }
6703 + } while (0);
6704 +
6705 + do { /* PaX: unpatched PLT emulation step 2 */
6706 + unsigned int save, call, nop;
6707 +
6708 + err = get_user(save, (unsigned int *)(regs->pc-4));
6709 + err |= get_user(call, (unsigned int *)regs->pc);
6710 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6711 + if (err)
6712 + break;
6713 +
6714 + if (save == 0x9DE3BFA8U &&
6715 + (call & 0xC0000000U) == 0x40000000U &&
6716 + nop == 0x01000000U)
6717 + {
6718 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6719 +
6720 + regs->u_regs[UREG_RETPC] = regs->pc;
6721 + regs->pc = dl_resolve;
6722 + regs->npc = dl_resolve+4;
6723 + return 3;
6724 + }
6725 + } while (0);
6726 +#endif
6727 +
6728 + return 1;
6729 +}
6730 +
6731 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6732 +{
6733 + unsigned long i;
6734 +
6735 + printk(KERN_ERR "PAX: bytes at PC: ");
6736 + for (i = 0; i < 8; i++) {
6737 + unsigned int c;
6738 + if (get_user(c, (unsigned int *)pc+i))
6739 + printk(KERN_CONT "???????? ");
6740 + else
6741 + printk(KERN_CONT "%08x ", c);
6742 + }
6743 + printk("\n");
6744 +}
6745 +#endif
6746 +
6747 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6748 int text_fault)
6749 {
6750 @@ -230,6 +504,24 @@ good_area:
6751 if (!(vma->vm_flags & VM_WRITE))
6752 goto bad_area;
6753 } else {
6754 +
6755 +#ifdef CONFIG_PAX_PAGEEXEC
6756 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6757 + up_read(&mm->mmap_sem);
6758 + switch (pax_handle_fetch_fault(regs)) {
6759 +
6760 +#ifdef CONFIG_PAX_EMUPLT
6761 + case 2:
6762 + case 3:
6763 + return;
6764 +#endif
6765 +
6766 + }
6767 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6768 + do_group_exit(SIGKILL);
6769 + }
6770 +#endif
6771 +
6772 /* Allow reads even for write-only mappings */
6773 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6774 goto bad_area;
6775 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6776 index 1fe0429..8dd5dd5 100644
6777 --- a/arch/sparc/mm/fault_64.c
6778 +++ b/arch/sparc/mm/fault_64.c
6779 @@ -21,6 +21,9 @@
6780 #include <linux/kprobes.h>
6781 #include <linux/kdebug.h>
6782 #include <linux/percpu.h>
6783 +#include <linux/slab.h>
6784 +#include <linux/pagemap.h>
6785 +#include <linux/compiler.h>
6786
6787 #include <asm/page.h>
6788 #include <asm/pgtable.h>
6789 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6790 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6791 regs->tpc);
6792 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6793 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6794 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6795 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6796 dump_stack();
6797 unhandled_fault(regs->tpc, current, regs);
6798 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6799 show_regs(regs);
6800 }
6801
6802 +#ifdef CONFIG_PAX_PAGEEXEC
6803 +#ifdef CONFIG_PAX_DLRESOLVE
6804 +static void pax_emuplt_close(struct vm_area_struct *vma)
6805 +{
6806 + vma->vm_mm->call_dl_resolve = 0UL;
6807 +}
6808 +
6809 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6810 +{
6811 + unsigned int *kaddr;
6812 +
6813 + vmf->page = alloc_page(GFP_HIGHUSER);
6814 + if (!vmf->page)
6815 + return VM_FAULT_OOM;
6816 +
6817 + kaddr = kmap(vmf->page);
6818 + memset(kaddr, 0, PAGE_SIZE);
6819 + kaddr[0] = 0x9DE3BFA8U; /* save */
6820 + flush_dcache_page(vmf->page);
6821 + kunmap(vmf->page);
6822 + return VM_FAULT_MAJOR;
6823 +}
6824 +
6825 +static const struct vm_operations_struct pax_vm_ops = {
6826 + .close = pax_emuplt_close,
6827 + .fault = pax_emuplt_fault
6828 +};
6829 +
6830 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6831 +{
6832 + int ret;
6833 +
6834 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6835 + vma->vm_mm = current->mm;
6836 + vma->vm_start = addr;
6837 + vma->vm_end = addr + PAGE_SIZE;
6838 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6839 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6840 + vma->vm_ops = &pax_vm_ops;
6841 +
6842 + ret = insert_vm_struct(current->mm, vma);
6843 + if (ret)
6844 + return ret;
6845 +
6846 + ++current->mm->total_vm;
6847 + return 0;
6848 +}
6849 +#endif
6850 +
6851 +/*
6852 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6853 + *
6854 + * returns 1 when task should be killed
6855 + * 2 when patched PLT trampoline was detected
6856 + * 3 when unpatched PLT trampoline was detected
6857 + */
6858 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6859 +{
6860 +
6861 +#ifdef CONFIG_PAX_EMUPLT
6862 + int err;
6863 +
6864 + do { /* PaX: patched PLT emulation #1 */
6865 + unsigned int sethi1, sethi2, jmpl;
6866 +
6867 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6868 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6869 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6870 +
6871 + if (err)
6872 + break;
6873 +
6874 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6875 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6876 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6877 + {
6878 + unsigned long addr;
6879 +
6880 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6881 + addr = regs->u_regs[UREG_G1];
6882 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6883 +
6884 + if (test_thread_flag(TIF_32BIT))
6885 + addr &= 0xFFFFFFFFUL;
6886 +
6887 + regs->tpc = addr;
6888 + regs->tnpc = addr+4;
6889 + return 2;
6890 + }
6891 + } while (0);
6892 +
6893 + do { /* PaX: patched PLT emulation #2 */
6894 + unsigned int ba;
6895 +
6896 + err = get_user(ba, (unsigned int *)regs->tpc);
6897 +
6898 + if (err)
6899 + break;
6900 +
6901 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6902 + unsigned long addr;
6903 +
6904 + if ((ba & 0xFFC00000U) == 0x30800000U)
6905 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6906 + else
6907 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6908 +
6909 + if (test_thread_flag(TIF_32BIT))
6910 + addr &= 0xFFFFFFFFUL;
6911 +
6912 + regs->tpc = addr;
6913 + regs->tnpc = addr+4;
6914 + return 2;
6915 + }
6916 + } while (0);
6917 +
6918 + do { /* PaX: patched PLT emulation #3 */
6919 + unsigned int sethi, bajmpl, nop;
6920 +
6921 + err = get_user(sethi, (unsigned int *)regs->tpc);
6922 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6923 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6924 +
6925 + if (err)
6926 + break;
6927 +
6928 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6929 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6930 + nop == 0x01000000U)
6931 + {
6932 + unsigned long addr;
6933 +
6934 + addr = (sethi & 0x003FFFFFU) << 10;
6935 + regs->u_regs[UREG_G1] = addr;
6936 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6937 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6938 + else
6939 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6940 +
6941 + if (test_thread_flag(TIF_32BIT))
6942 + addr &= 0xFFFFFFFFUL;
6943 +
6944 + regs->tpc = addr;
6945 + regs->tnpc = addr+4;
6946 + return 2;
6947 + }
6948 + } while (0);
6949 +
6950 + do { /* PaX: patched PLT emulation #4 */
6951 + unsigned int sethi, mov1, call, mov2;
6952 +
6953 + err = get_user(sethi, (unsigned int *)regs->tpc);
6954 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6955 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6956 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6957 +
6958 + if (err)
6959 + break;
6960 +
6961 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6962 + mov1 == 0x8210000FU &&
6963 + (call & 0xC0000000U) == 0x40000000U &&
6964 + mov2 == 0x9E100001U)
6965 + {
6966 + unsigned long addr;
6967 +
6968 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6969 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6970 +
6971 + if (test_thread_flag(TIF_32BIT))
6972 + addr &= 0xFFFFFFFFUL;
6973 +
6974 + regs->tpc = addr;
6975 + regs->tnpc = addr+4;
6976 + return 2;
6977 + }
6978 + } while (0);
6979 +
6980 + do { /* PaX: patched PLT emulation #5 */
6981 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6982 +
6983 + err = get_user(sethi, (unsigned int *)regs->tpc);
6984 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6985 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6986 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6987 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6988 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6989 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6990 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6991 +
6992 + if (err)
6993 + break;
6994 +
6995 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6996 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6997 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6998 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6999 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7000 + sllx == 0x83287020U &&
7001 + jmpl == 0x81C04005U &&
7002 + nop == 0x01000000U)
7003 + {
7004 + unsigned long addr;
7005 +
7006 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7007 + regs->u_regs[UREG_G1] <<= 32;
7008 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7009 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7010 + regs->tpc = addr;
7011 + regs->tnpc = addr+4;
7012 + return 2;
7013 + }
7014 + } while (0);
7015 +
7016 + do { /* PaX: patched PLT emulation #6 */
7017 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7018 +
7019 + err = get_user(sethi, (unsigned int *)regs->tpc);
7020 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7021 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7022 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7023 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7024 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7025 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7026 +
7027 + if (err)
7028 + break;
7029 +
7030 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7031 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7032 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7033 + sllx == 0x83287020U &&
7034 + (or & 0xFFFFE000U) == 0x8A116000U &&
7035 + jmpl == 0x81C04005U &&
7036 + nop == 0x01000000U)
7037 + {
7038 + unsigned long addr;
7039 +
7040 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7041 + regs->u_regs[UREG_G1] <<= 32;
7042 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7043 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7044 + regs->tpc = addr;
7045 + regs->tnpc = addr+4;
7046 + return 2;
7047 + }
7048 + } while (0);
7049 +
7050 + do { /* PaX: unpatched PLT emulation step 1 */
7051 + unsigned int sethi, ba, nop;
7052 +
7053 + err = get_user(sethi, (unsigned int *)regs->tpc);
7054 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7055 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7056 +
7057 + if (err)
7058 + break;
7059 +
7060 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7061 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7062 + nop == 0x01000000U)
7063 + {
7064 + unsigned long addr;
7065 + unsigned int save, call;
7066 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7067 +
7068 + if ((ba & 0xFFC00000U) == 0x30800000U)
7069 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7070 + else
7071 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7072 +
7073 + if (test_thread_flag(TIF_32BIT))
7074 + addr &= 0xFFFFFFFFUL;
7075 +
7076 + err = get_user(save, (unsigned int *)addr);
7077 + err |= get_user(call, (unsigned int *)(addr+4));
7078 + err |= get_user(nop, (unsigned int *)(addr+8));
7079 + if (err)
7080 + break;
7081 +
7082 +#ifdef CONFIG_PAX_DLRESOLVE
7083 + if (save == 0x9DE3BFA8U &&
7084 + (call & 0xC0000000U) == 0x40000000U &&
7085 + nop == 0x01000000U)
7086 + {
7087 + struct vm_area_struct *vma;
7088 + unsigned long call_dl_resolve;
7089 +
7090 + down_read(&current->mm->mmap_sem);
7091 + call_dl_resolve = current->mm->call_dl_resolve;
7092 + up_read(&current->mm->mmap_sem);
7093 + if (likely(call_dl_resolve))
7094 + goto emulate;
7095 +
7096 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7097 +
7098 + down_write(&current->mm->mmap_sem);
7099 + if (current->mm->call_dl_resolve) {
7100 + call_dl_resolve = current->mm->call_dl_resolve;
7101 + up_write(&current->mm->mmap_sem);
7102 + if (vma)
7103 + kmem_cache_free(vm_area_cachep, vma);
7104 + goto emulate;
7105 + }
7106 +
7107 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7108 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7109 + up_write(&current->mm->mmap_sem);
7110 + if (vma)
7111 + kmem_cache_free(vm_area_cachep, vma);
7112 + return 1;
7113 + }
7114 +
7115 + if (pax_insert_vma(vma, call_dl_resolve)) {
7116 + up_write(&current->mm->mmap_sem);
7117 + kmem_cache_free(vm_area_cachep, vma);
7118 + return 1;
7119 + }
7120 +
7121 + current->mm->call_dl_resolve = call_dl_resolve;
7122 + up_write(&current->mm->mmap_sem);
7123 +
7124 +emulate:
7125 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7126 + regs->tpc = call_dl_resolve;
7127 + regs->tnpc = addr+4;
7128 + return 3;
7129 + }
7130 +#endif
7131 +
7132 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7133 + if ((save & 0xFFC00000U) == 0x05000000U &&
7134 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7135 + nop == 0x01000000U)
7136 + {
7137 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7138 + regs->u_regs[UREG_G2] = addr + 4;
7139 + addr = (save & 0x003FFFFFU) << 10;
7140 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7141 +
7142 + if (test_thread_flag(TIF_32BIT))
7143 + addr &= 0xFFFFFFFFUL;
7144 +
7145 + regs->tpc = addr;
7146 + regs->tnpc = addr+4;
7147 + return 3;
7148 + }
7149 +
7150 + /* PaX: 64-bit PLT stub */
7151 + err = get_user(sethi1, (unsigned int *)addr);
7152 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7153 + err |= get_user(or1, (unsigned int *)(addr+8));
7154 + err |= get_user(or2, (unsigned int *)(addr+12));
7155 + err |= get_user(sllx, (unsigned int *)(addr+16));
7156 + err |= get_user(add, (unsigned int *)(addr+20));
7157 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7158 + err |= get_user(nop, (unsigned int *)(addr+28));
7159 + if (err)
7160 + break;
7161 +
7162 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7163 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7164 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7165 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7166 + sllx == 0x89293020U &&
7167 + add == 0x8A010005U &&
7168 + jmpl == 0x89C14000U &&
7169 + nop == 0x01000000U)
7170 + {
7171 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7172 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7173 + regs->u_regs[UREG_G4] <<= 32;
7174 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7175 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7176 + regs->u_regs[UREG_G4] = addr + 24;
7177 + addr = regs->u_regs[UREG_G5];
7178 + regs->tpc = addr;
7179 + regs->tnpc = addr+4;
7180 + return 3;
7181 + }
7182 + }
7183 + } while (0);
7184 +
7185 +#ifdef CONFIG_PAX_DLRESOLVE
7186 + do { /* PaX: unpatched PLT emulation step 2 */
7187 + unsigned int save, call, nop;
7188 +
7189 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7190 + err |= get_user(call, (unsigned int *)regs->tpc);
7191 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7192 + if (err)
7193 + break;
7194 +
7195 + if (save == 0x9DE3BFA8U &&
7196 + (call & 0xC0000000U) == 0x40000000U &&
7197 + nop == 0x01000000U)
7198 + {
7199 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7200 +
7201 + if (test_thread_flag(TIF_32BIT))
7202 + dl_resolve &= 0xFFFFFFFFUL;
7203 +
7204 + regs->u_regs[UREG_RETPC] = regs->tpc;
7205 + regs->tpc = dl_resolve;
7206 + regs->tnpc = dl_resolve+4;
7207 + return 3;
7208 + }
7209 + } while (0);
7210 +#endif
7211 +
7212 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7213 + unsigned int sethi, ba, nop;
7214 +
7215 + err = get_user(sethi, (unsigned int *)regs->tpc);
7216 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7217 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7218 +
7219 + if (err)
7220 + break;
7221 +
7222 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7223 + (ba & 0xFFF00000U) == 0x30600000U &&
7224 + nop == 0x01000000U)
7225 + {
7226 + unsigned long addr;
7227 +
7228 + addr = (sethi & 0x003FFFFFU) << 10;
7229 + regs->u_regs[UREG_G1] = addr;
7230 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7231 +
7232 + if (test_thread_flag(TIF_32BIT))
7233 + addr &= 0xFFFFFFFFUL;
7234 +
7235 + regs->tpc = addr;
7236 + regs->tnpc = addr+4;
7237 + return 2;
7238 + }
7239 + } while (0);
7240 +
7241 +#endif
7242 +
7243 + return 1;
7244 +}
7245 +
7246 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7247 +{
7248 + unsigned long i;
7249 +
7250 + printk(KERN_ERR "PAX: bytes at PC: ");
7251 + for (i = 0; i < 8; i++) {
7252 + unsigned int c;
7253 + if (get_user(c, (unsigned int *)pc+i))
7254 + printk(KERN_CONT "???????? ");
7255 + else
7256 + printk(KERN_CONT "%08x ", c);
7257 + }
7258 + printk("\n");
7259 +}
7260 +#endif
7261 +
7262 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7263 {
7264 struct mm_struct *mm = current->mm;
7265 @@ -343,6 +806,29 @@ retry:
7266 if (!vma)
7267 goto bad_area;
7268
7269 +#ifdef CONFIG_PAX_PAGEEXEC
7270 + /* PaX: detect ITLB misses on non-exec pages */
7271 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7272 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7273 + {
7274 + if (address != regs->tpc)
7275 + goto good_area;
7276 +
7277 + up_read(&mm->mmap_sem);
7278 + switch (pax_handle_fetch_fault(regs)) {
7279 +
7280 +#ifdef CONFIG_PAX_EMUPLT
7281 + case 2:
7282 + case 3:
7283 + return;
7284 +#endif
7285 +
7286 + }
7287 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7288 + do_group_exit(SIGKILL);
7289 + }
7290 +#endif
7291 +
7292 /* Pure DTLB misses do not tell us whether the fault causing
7293 * load/store/atomic was a write or not, it only says that there
7294 * was no match. So in such a case we (carefully) read the
7295 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7296 index 07e1453..0a7d9e9 100644
7297 --- a/arch/sparc/mm/hugetlbpage.c
7298 +++ b/arch/sparc/mm/hugetlbpage.c
7299 @@ -67,7 +67,7 @@ full_search:
7300 }
7301 return -ENOMEM;
7302 }
7303 - if (likely(!vma || addr + len <= vma->vm_start)) {
7304 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7305 /*
7306 * Remember the place where we stopped the search:
7307 */
7308 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7309 /* make sure it can fit in the remaining address space */
7310 if (likely(addr > len)) {
7311 vma = find_vma(mm, addr-len);
7312 - if (!vma || addr <= vma->vm_start) {
7313 + if (check_heap_stack_gap(vma, addr - len, len)) {
7314 /* remember the address as a hint for next time */
7315 return (mm->free_area_cache = addr-len);
7316 }
7317 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7318 if (unlikely(mm->mmap_base < len))
7319 goto bottomup;
7320
7321 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7322 + addr = mm->mmap_base - len;
7323
7324 do {
7325 + addr &= HPAGE_MASK;
7326 /*
7327 * Lookup failure means no vma is above this address,
7328 * else if new region fits below vma->vm_start,
7329 * return with success:
7330 */
7331 vma = find_vma(mm, addr);
7332 - if (likely(!vma || addr+len <= vma->vm_start)) {
7333 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7334 /* remember the address as a hint for next time */
7335 return (mm->free_area_cache = addr);
7336 }
7337 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7338 mm->cached_hole_size = vma->vm_start - addr;
7339
7340 /* try just below the current vma->vm_start */
7341 - addr = (vma->vm_start-len) & HPAGE_MASK;
7342 - } while (likely(len < vma->vm_start));
7343 + addr = skip_heap_stack_gap(vma, len);
7344 + } while (!IS_ERR_VALUE(addr));
7345
7346 bottomup:
7347 /*
7348 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7349 if (addr) {
7350 addr = ALIGN(addr, HPAGE_SIZE);
7351 vma = find_vma(mm, addr);
7352 - if (task_size - len >= addr &&
7353 - (!vma || addr + len <= vma->vm_start))
7354 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7355 return addr;
7356 }
7357 if (mm->get_unmapped_area == arch_get_unmapped_area)
7358 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7359 index f4500c6..889656c 100644
7360 --- a/arch/tile/include/asm/atomic_64.h
7361 +++ b/arch/tile/include/asm/atomic_64.h
7362 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7363
7364 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7365
7366 +#define atomic64_read_unchecked(v) atomic64_read(v)
7367 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7368 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7369 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7370 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7371 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7372 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7373 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7374 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7375 +
7376 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7377 #define smp_mb__before_atomic_dec() smp_mb()
7378 #define smp_mb__after_atomic_dec() smp_mb()
7379 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7380 index a9a5299..0fce79e 100644
7381 --- a/arch/tile/include/asm/cache.h
7382 +++ b/arch/tile/include/asm/cache.h
7383 @@ -15,11 +15,12 @@
7384 #ifndef _ASM_TILE_CACHE_H
7385 #define _ASM_TILE_CACHE_H
7386
7387 +#include <linux/const.h>
7388 #include <arch/chip.h>
7389
7390 /* bytes per L1 data cache line */
7391 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7392 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7393 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7394
7395 /* bytes per L2 cache line */
7396 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7397 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7398 index 9ab078a..d6635c2 100644
7399 --- a/arch/tile/include/asm/uaccess.h
7400 +++ b/arch/tile/include/asm/uaccess.h
7401 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7402 const void __user *from,
7403 unsigned long n)
7404 {
7405 - int sz = __compiletime_object_size(to);
7406 + size_t sz = __compiletime_object_size(to);
7407
7408 - if (likely(sz == -1 || sz >= n))
7409 + if (likely(sz == (size_t)-1 || sz >= n))
7410 n = _copy_from_user(to, from, n);
7411 else
7412 copy_from_user_overflow();
7413 diff --git a/arch/um/Makefile b/arch/um/Makefile
7414 index 0970910..9f65c40 100644
7415 --- a/arch/um/Makefile
7416 +++ b/arch/um/Makefile
7417 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7418 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7419 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7420
7421 +ifdef CONSTIFY_PLUGIN
7422 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7423 +endif
7424 +
7425 #This will adjust *FLAGS accordingly to the platform.
7426 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7427
7428 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7429 index 19e1bdd..3665b77 100644
7430 --- a/arch/um/include/asm/cache.h
7431 +++ b/arch/um/include/asm/cache.h
7432 @@ -1,6 +1,7 @@
7433 #ifndef __UM_CACHE_H
7434 #define __UM_CACHE_H
7435
7436 +#include <linux/const.h>
7437
7438 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7439 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7440 @@ -12,6 +13,6 @@
7441 # define L1_CACHE_SHIFT 5
7442 #endif
7443
7444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 #endif
7448 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7449 index 2e0a6b1..a64d0f5 100644
7450 --- a/arch/um/include/asm/kmap_types.h
7451 +++ b/arch/um/include/asm/kmap_types.h
7452 @@ -8,6 +8,6 @@
7453
7454 /* No more #include "asm/arch/kmap_types.h" ! */
7455
7456 -#define KM_TYPE_NR 14
7457 +#define KM_TYPE_NR 15
7458
7459 #endif
7460 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7461 index 7cfc3ce..cbd1a58 100644
7462 --- a/arch/um/include/asm/page.h
7463 +++ b/arch/um/include/asm/page.h
7464 @@ -14,6 +14,9 @@
7465 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7466 #define PAGE_MASK (~(PAGE_SIZE-1))
7467
7468 +#define ktla_ktva(addr) (addr)
7469 +#define ktva_ktla(addr) (addr)
7470 +
7471 #ifndef __ASSEMBLY__
7472
7473 struct page;
7474 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7475 index 0032f92..cd151e0 100644
7476 --- a/arch/um/include/asm/pgtable-3level.h
7477 +++ b/arch/um/include/asm/pgtable-3level.h
7478 @@ -58,6 +58,7 @@
7479 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7480 #define pud_populate(mm, pud, pmd) \
7481 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7482 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7483
7484 #ifdef CONFIG_64BIT
7485 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7486 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7487 index c5f5afa..6abce4b 100644
7488 --- a/arch/um/kernel/process.c
7489 +++ b/arch/um/kernel/process.c
7490 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7491 return 2;
7492 }
7493
7494 -/*
7495 - * Only x86 and x86_64 have an arch_align_stack().
7496 - * All other arches have "#define arch_align_stack(x) (x)"
7497 - * in their asm/system.h
7498 - * As this is included in UML from asm-um/system-generic.h,
7499 - * we can use it to behave as the subarch does.
7500 - */
7501 -#ifndef arch_align_stack
7502 -unsigned long arch_align_stack(unsigned long sp)
7503 -{
7504 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7505 - sp -= get_random_int() % 8192;
7506 - return sp & ~0xf;
7507 -}
7508 -#endif
7509 -
7510 unsigned long get_wchan(struct task_struct *p)
7511 {
7512 unsigned long stack_page, sp, ip;
7513 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7514 index ad8f795..2c7eec6 100644
7515 --- a/arch/unicore32/include/asm/cache.h
7516 +++ b/arch/unicore32/include/asm/cache.h
7517 @@ -12,8 +12,10 @@
7518 #ifndef __UNICORE_CACHE_H__
7519 #define __UNICORE_CACHE_H__
7520
7521 -#define L1_CACHE_SHIFT (5)
7522 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7523 +#include <linux/const.h>
7524 +
7525 +#define L1_CACHE_SHIFT 5
7526 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7527
7528 /*
7529 * Memory returned by kmalloc() may be used for DMA, so we must make
7530 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7531 index 50a1d1f..c26369f 100644
7532 --- a/arch/x86/Kconfig
7533 +++ b/arch/x86/Kconfig
7534 @@ -220,7 +220,7 @@ config X86_HT
7535
7536 config X86_32_LAZY_GS
7537 def_bool y
7538 - depends on X86_32 && !CC_STACKPROTECTOR
7539 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7540
7541 config ARCH_HWEIGHT_CFLAGS
7542 string
7543 @@ -1049,7 +1049,7 @@ choice
7544
7545 config NOHIGHMEM
7546 bool "off"
7547 - depends on !X86_NUMAQ
7548 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7549 ---help---
7550 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7551 However, the address space of 32-bit x86 processors is only 4
7552 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7553
7554 config HIGHMEM4G
7555 bool "4GB"
7556 - depends on !X86_NUMAQ
7557 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7558 ---help---
7559 Select this if you have a 32-bit processor and between 1 and 4
7560 gigabytes of physical RAM.
7561 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7562 hex
7563 default 0xB0000000 if VMSPLIT_3G_OPT
7564 default 0x80000000 if VMSPLIT_2G
7565 - default 0x78000000 if VMSPLIT_2G_OPT
7566 + default 0x70000000 if VMSPLIT_2G_OPT
7567 default 0x40000000 if VMSPLIT_1G
7568 default 0xC0000000
7569 depends on X86_32
7570 @@ -1528,6 +1528,7 @@ config SECCOMP
7571
7572 config CC_STACKPROTECTOR
7573 bool "Enable -fstack-protector buffer overflow detection"
7574 + depends on X86_64 || !PAX_MEMORY_UDEREF
7575 ---help---
7576 This option turns on the -fstack-protector GCC feature. This
7577 feature puts, at the beginning of functions, a canary value on
7578 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7579 config PHYSICAL_START
7580 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7581 default "0x1000000"
7582 + range 0x400000 0x40000000
7583 ---help---
7584 This gives the physical address where the kernel is loaded.
7585
7586 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7587 config PHYSICAL_ALIGN
7588 hex "Alignment value to which kernel should be aligned" if X86_32
7589 default "0x1000000"
7590 + range 0x400000 0x1000000 if PAX_KERNEXEC
7591 range 0x2000 0x1000000
7592 ---help---
7593 This value puts the alignment restrictions on physical address
7594 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7595 Say N if you want to disable CPU hotplug.
7596
7597 config COMPAT_VDSO
7598 - def_bool y
7599 + def_bool n
7600 prompt "Compat VDSO support"
7601 depends on X86_32 || IA32_EMULATION
7602 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7603 ---help---
7604 Map the 32-bit VDSO to the predictable old-style address too.
7605
7606 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7607 index 706e12e..62e4feb 100644
7608 --- a/arch/x86/Kconfig.cpu
7609 +++ b/arch/x86/Kconfig.cpu
7610 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7611
7612 config X86_F00F_BUG
7613 def_bool y
7614 - depends on M586MMX || M586TSC || M586 || M486 || M386
7615 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7616
7617 config X86_INVD_BUG
7618 def_bool y
7619 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7620
7621 config X86_ALIGNMENT_16
7622 def_bool y
7623 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7624 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7625
7626 config X86_INTEL_USERCOPY
7627 def_bool y
7628 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7629 # generates cmov.
7630 config X86_CMOV
7631 def_bool y
7632 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7633 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7634
7635 config X86_MINIMUM_CPU_FAMILY
7636 int
7637 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7638 index b322f12..652d0d9 100644
7639 --- a/arch/x86/Kconfig.debug
7640 +++ b/arch/x86/Kconfig.debug
7641 @@ -84,7 +84,7 @@ config X86_PTDUMP
7642 config DEBUG_RODATA
7643 bool "Write protect kernel read-only data structures"
7644 default y
7645 - depends on DEBUG_KERNEL
7646 + depends on DEBUG_KERNEL && BROKEN
7647 ---help---
7648 Mark the kernel read-only data as write-protected in the pagetables,
7649 in order to catch accidental (and incorrect) writes to such const
7650 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7651
7652 config DEBUG_SET_MODULE_RONX
7653 bool "Set loadable kernel module data as NX and text as RO"
7654 - depends on MODULES
7655 + depends on MODULES && BROKEN
7656 ---help---
7657 This option helps catch unintended modifications to loadable
7658 kernel module's text and read-only data. It also prevents execution
7659 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7660
7661 config DEBUG_STRICT_USER_COPY_CHECKS
7662 bool "Strict copy size checks"
7663 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7664 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7665 ---help---
7666 Enabling this option turns a certain set of sanity checks for user
7667 copy operations into compile time failures.
7668 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7669 index 05afcca..b6ecb51 100644
7670 --- a/arch/x86/Makefile
7671 +++ b/arch/x86/Makefile
7672 @@ -50,6 +50,7 @@ else
7673 UTS_MACHINE := x86_64
7674 CHECKFLAGS += -D__x86_64__ -m64
7675
7676 + biarch := $(call cc-option,-m64)
7677 KBUILD_AFLAGS += -m64
7678 KBUILD_CFLAGS += -m64
7679
7680 @@ -229,3 +230,12 @@ define archhelp
7681 echo ' FDARGS="..." arguments for the booted kernel'
7682 echo ' FDINITRD=file initrd for the booted kernel'
7683 endef
7684 +
7685 +define OLD_LD
7686 +
7687 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7688 +*** Please upgrade your binutils to 2.18 or newer
7689 +endef
7690 +
7691 +archprepare:
7692 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7693 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7694 index f7535be..37db2d1 100644
7695 --- a/arch/x86/boot/Makefile
7696 +++ b/arch/x86/boot/Makefile
7697 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7698 $(call cc-option, -fno-stack-protector) \
7699 $(call cc-option, -mpreferred-stack-boundary=2)
7700 KBUILD_CFLAGS += $(call cc-option, -m32)
7701 +ifdef CONSTIFY_PLUGIN
7702 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7703 +endif
7704 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7705 GCOV_PROFILE := n
7706
7707 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7708 index 878e4b9..20537ab 100644
7709 --- a/arch/x86/boot/bitops.h
7710 +++ b/arch/x86/boot/bitops.h
7711 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7712 u8 v;
7713 const u32 *p = (const u32 *)addr;
7714
7715 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7716 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7717 return v;
7718 }
7719
7720 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7721
7722 static inline void set_bit(int nr, void *addr)
7723 {
7724 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7725 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7726 }
7727
7728 #endif /* BOOT_BITOPS_H */
7729 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7730 index 18997e5..83d9c67 100644
7731 --- a/arch/x86/boot/boot.h
7732 +++ b/arch/x86/boot/boot.h
7733 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7734 static inline u16 ds(void)
7735 {
7736 u16 seg;
7737 - asm("movw %%ds,%0" : "=rm" (seg));
7738 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7739 return seg;
7740 }
7741
7742 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7743 static inline int memcmp(const void *s1, const void *s2, size_t len)
7744 {
7745 u8 diff;
7746 - asm("repe; cmpsb; setnz %0"
7747 + asm volatile("repe; cmpsb; setnz %0"
7748 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7749 return diff;
7750 }
7751 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7752 index 8a84501..b2d165f 100644
7753 --- a/arch/x86/boot/compressed/Makefile
7754 +++ b/arch/x86/boot/compressed/Makefile
7755 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7756 KBUILD_CFLAGS += $(cflags-y)
7757 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7758 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7759 +ifdef CONSTIFY_PLUGIN
7760 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7761 +endif
7762
7763 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7764 GCOV_PROFILE := n
7765 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7766 index b3e0227..f2c02d5 100644
7767 --- a/arch/x86/boot/compressed/eboot.c
7768 +++ b/arch/x86/boot/compressed/eboot.c
7769 @@ -142,7 +142,6 @@ again:
7770 *addr = max_addr;
7771 }
7772
7773 -free_pool:
7774 efi_call_phys1(sys_table->boottime->free_pool, map);
7775
7776 fail:
7777 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7778 if (i == map_size / desc_size)
7779 status = EFI_NOT_FOUND;
7780
7781 -free_pool:
7782 efi_call_phys1(sys_table->boottime->free_pool, map);
7783 fail:
7784 return status;
7785 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7786 index aa4aaf1..6656f2f 100644
7787 --- a/arch/x86/boot/compressed/head_32.S
7788 +++ b/arch/x86/boot/compressed/head_32.S
7789 @@ -116,7 +116,7 @@ preferred_addr:
7790 notl %eax
7791 andl %eax, %ebx
7792 #else
7793 - movl $LOAD_PHYSICAL_ADDR, %ebx
7794 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7795 #endif
7796
7797 /* Target address to relocate to for decompression */
7798 @@ -202,7 +202,7 @@ relocated:
7799 * and where it was actually loaded.
7800 */
7801 movl %ebp, %ebx
7802 - subl $LOAD_PHYSICAL_ADDR, %ebx
7803 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7804 jz 2f /* Nothing to be done if loaded at compiled addr. */
7805 /*
7806 * Process relocations.
7807 @@ -210,8 +210,7 @@ relocated:
7808
7809 1: subl $4, %edi
7810 movl (%edi), %ecx
7811 - testl %ecx, %ecx
7812 - jz 2f
7813 + jecxz 2f
7814 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7815 jmp 1b
7816 2:
7817 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7818 index 2c4b171..e1fa5b1 100644
7819 --- a/arch/x86/boot/compressed/head_64.S
7820 +++ b/arch/x86/boot/compressed/head_64.S
7821 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7822 notl %eax
7823 andl %eax, %ebx
7824 #else
7825 - movl $LOAD_PHYSICAL_ADDR, %ebx
7826 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7827 #endif
7828
7829 /* Target address to relocate to for decompression */
7830 @@ -273,7 +273,7 @@ preferred_addr:
7831 notq %rax
7832 andq %rax, %rbp
7833 #else
7834 - movq $LOAD_PHYSICAL_ADDR, %rbp
7835 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7836 #endif
7837
7838 /* Target address to relocate to for decompression */
7839 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7840 index 88f7ff6..ed695dd 100644
7841 --- a/arch/x86/boot/compressed/misc.c
7842 +++ b/arch/x86/boot/compressed/misc.c
7843 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7844 case PT_LOAD:
7845 #ifdef CONFIG_RELOCATABLE
7846 dest = output;
7847 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7848 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7849 #else
7850 dest = (void *)(phdr->p_paddr);
7851 #endif
7852 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7853 error("Destination address too large");
7854 #endif
7855 #ifndef CONFIG_RELOCATABLE
7856 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7857 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7858 error("Wrong destination address");
7859 #endif
7860
7861 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7862 index 4d3ff03..e4972ff 100644
7863 --- a/arch/x86/boot/cpucheck.c
7864 +++ b/arch/x86/boot/cpucheck.c
7865 @@ -74,7 +74,7 @@ static int has_fpu(void)
7866 u16 fcw = -1, fsw = -1;
7867 u32 cr0;
7868
7869 - asm("movl %%cr0,%0" : "=r" (cr0));
7870 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7871 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7872 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7873 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7874 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7875 {
7876 u32 f0, f1;
7877
7878 - asm("pushfl ; "
7879 + asm volatile("pushfl ; "
7880 "pushfl ; "
7881 "popl %0 ; "
7882 "movl %0,%1 ; "
7883 @@ -115,7 +115,7 @@ static void get_flags(void)
7884 set_bit(X86_FEATURE_FPU, cpu.flags);
7885
7886 if (has_eflag(X86_EFLAGS_ID)) {
7887 - asm("cpuid"
7888 + asm volatile("cpuid"
7889 : "=a" (max_intel_level),
7890 "=b" (cpu_vendor[0]),
7891 "=d" (cpu_vendor[1]),
7892 @@ -124,7 +124,7 @@ static void get_flags(void)
7893
7894 if (max_intel_level >= 0x00000001 &&
7895 max_intel_level <= 0x0000ffff) {
7896 - asm("cpuid"
7897 + asm volatile("cpuid"
7898 : "=a" (tfms),
7899 "=c" (cpu.flags[4]),
7900 "=d" (cpu.flags[0])
7901 @@ -136,7 +136,7 @@ static void get_flags(void)
7902 cpu.model += ((tfms >> 16) & 0xf) << 4;
7903 }
7904
7905 - asm("cpuid"
7906 + asm volatile("cpuid"
7907 : "=a" (max_amd_level)
7908 : "a" (0x80000000)
7909 : "ebx", "ecx", "edx");
7910 @@ -144,7 +144,7 @@ static void get_flags(void)
7911 if (max_amd_level >= 0x80000001 &&
7912 max_amd_level <= 0x8000ffff) {
7913 u32 eax = 0x80000001;
7914 - asm("cpuid"
7915 + asm volatile("cpuid"
7916 : "+a" (eax),
7917 "=c" (cpu.flags[6]),
7918 "=d" (cpu.flags[1])
7919 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7920 u32 ecx = MSR_K7_HWCR;
7921 u32 eax, edx;
7922
7923 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7924 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7925 eax &= ~(1 << 15);
7926 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7927 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7928
7929 get_flags(); /* Make sure it really did something */
7930 err = check_flags();
7931 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7932 u32 ecx = MSR_VIA_FCR;
7933 u32 eax, edx;
7934
7935 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7936 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7937 eax |= (1<<1)|(1<<7);
7938 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7939 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7940
7941 set_bit(X86_FEATURE_CX8, cpu.flags);
7942 err = check_flags();
7943 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7944 u32 eax, edx;
7945 u32 level = 1;
7946
7947 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7948 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7949 - asm("cpuid"
7950 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7951 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7952 + asm volatile("cpuid"
7953 : "+a" (level), "=d" (cpu.flags[0])
7954 : : "ecx", "ebx");
7955 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7957
7958 err = check_flags();
7959 }
7960 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7961 index b4e15dd..8ac59ce 100644
7962 --- a/arch/x86/boot/header.S
7963 +++ b/arch/x86/boot/header.S
7964 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7965 # single linked list of
7966 # struct setup_data
7967
7968 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7969 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7970
7971 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7972 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7973 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7974 +#else
7975 #define VO_INIT_SIZE (VO__end - VO__text)
7976 +#endif
7977 #if ZO_INIT_SIZE > VO_INIT_SIZE
7978 #define INIT_SIZE ZO_INIT_SIZE
7979 #else
7980 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7981 index db75d07..8e6d0af 100644
7982 --- a/arch/x86/boot/memory.c
7983 +++ b/arch/x86/boot/memory.c
7984 @@ -19,7 +19,7 @@
7985
7986 static int detect_memory_e820(void)
7987 {
7988 - int count = 0;
7989 + unsigned int count = 0;
7990 struct biosregs ireg, oreg;
7991 struct e820entry *desc = boot_params.e820_map;
7992 static struct e820entry buf; /* static so it is zeroed */
7993 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7994 index 11e8c6e..fdbb1ed 100644
7995 --- a/arch/x86/boot/video-vesa.c
7996 +++ b/arch/x86/boot/video-vesa.c
7997 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7998
7999 boot_params.screen_info.vesapm_seg = oreg.es;
8000 boot_params.screen_info.vesapm_off = oreg.di;
8001 + boot_params.screen_info.vesapm_size = oreg.cx;
8002 }
8003
8004 /*
8005 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8006 index 43eda28..5ab5fdb 100644
8007 --- a/arch/x86/boot/video.c
8008 +++ b/arch/x86/boot/video.c
8009 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8010 static unsigned int get_entry(void)
8011 {
8012 char entry_buf[4];
8013 - int i, len = 0;
8014 + unsigned int i, len = 0;
8015 int key;
8016 unsigned int v;
8017
8018 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8019 index 5b577d5..3c1fed4 100644
8020 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8021 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8022 @@ -8,6 +8,8 @@
8023 * including this sentence is retained in full.
8024 */
8025
8026 +#include <asm/alternative-asm.h>
8027 +
8028 .extern crypto_ft_tab
8029 .extern crypto_it_tab
8030 .extern crypto_fl_tab
8031 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8032 je B192; \
8033 leaq 32(r9),r9;
8034
8035 +#define ret pax_force_retaddr 0, 1; ret
8036 +
8037 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8038 movq r1,r2; \
8039 movq r3,r4; \
8040 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8041 index 3470624..201259d 100644
8042 --- a/arch/x86/crypto/aesni-intel_asm.S
8043 +++ b/arch/x86/crypto/aesni-intel_asm.S
8044 @@ -31,6 +31,7 @@
8045
8046 #include <linux/linkage.h>
8047 #include <asm/inst.h>
8048 +#include <asm/alternative-asm.h>
8049
8050 #ifdef __x86_64__
8051 .data
8052 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8053 pop %r14
8054 pop %r13
8055 pop %r12
8056 + pax_force_retaddr 0, 1
8057 ret
8058 +ENDPROC(aesni_gcm_dec)
8059
8060
8061 /*****************************************************************************
8062 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8063 pop %r14
8064 pop %r13
8065 pop %r12
8066 + pax_force_retaddr 0, 1
8067 ret
8068 +ENDPROC(aesni_gcm_enc)
8069
8070 #endif
8071
8072 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8073 pxor %xmm1, %xmm0
8074 movaps %xmm0, (TKEYP)
8075 add $0x10, TKEYP
8076 + pax_force_retaddr_bts
8077 ret
8078
8079 .align 4
8080 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8081 shufps $0b01001110, %xmm2, %xmm1
8082 movaps %xmm1, 0x10(TKEYP)
8083 add $0x20, TKEYP
8084 + pax_force_retaddr_bts
8085 ret
8086
8087 .align 4
8088 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8089
8090 movaps %xmm0, (TKEYP)
8091 add $0x10, TKEYP
8092 + pax_force_retaddr_bts
8093 ret
8094
8095 .align 4
8096 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8097 pxor %xmm1, %xmm2
8098 movaps %xmm2, (TKEYP)
8099 add $0x10, TKEYP
8100 + pax_force_retaddr_bts
8101 ret
8102
8103 /*
8104 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8105 #ifndef __x86_64__
8106 popl KEYP
8107 #endif
8108 + pax_force_retaddr 0, 1
8109 ret
8110 +ENDPROC(aesni_set_key)
8111
8112 /*
8113 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8114 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8115 popl KLEN
8116 popl KEYP
8117 #endif
8118 + pax_force_retaddr 0, 1
8119 ret
8120 +ENDPROC(aesni_enc)
8121
8122 /*
8123 * _aesni_enc1: internal ABI
8124 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8125 AESENC KEY STATE
8126 movaps 0x70(TKEYP), KEY
8127 AESENCLAST KEY STATE
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8133 AESENCLAST KEY STATE2
8134 AESENCLAST KEY STATE3
8135 AESENCLAST KEY STATE4
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 /*
8140 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8141 popl KLEN
8142 popl KEYP
8143 #endif
8144 + pax_force_retaddr 0, 1
8145 ret
8146 +ENDPROC(aesni_dec)
8147
8148 /*
8149 * _aesni_dec1: internal ABI
8150 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8151 AESDEC KEY STATE
8152 movaps 0x70(TKEYP), KEY
8153 AESDECLAST KEY STATE
8154 + pax_force_retaddr_bts
8155 ret
8156
8157 /*
8158 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8159 AESDECLAST KEY STATE2
8160 AESDECLAST KEY STATE3
8161 AESDECLAST KEY STATE4
8162 + pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8167 popl KEYP
8168 popl LEN
8169 #endif
8170 + pax_force_retaddr 0, 1
8171 ret
8172 +ENDPROC(aesni_ecb_enc)
8173
8174 /*
8175 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8176 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8177 popl KEYP
8178 popl LEN
8179 #endif
8180 + pax_force_retaddr 0, 1
8181 ret
8182 +ENDPROC(aesni_ecb_dec)
8183
8184 /*
8185 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8186 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8187 popl LEN
8188 popl IVP
8189 #endif
8190 + pax_force_retaddr 0, 1
8191 ret
8192 +ENDPROC(aesni_cbc_enc)
8193
8194 /*
8195 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8196 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8197 popl LEN
8198 popl IVP
8199 #endif
8200 + pax_force_retaddr 0, 1
8201 ret
8202 +ENDPROC(aesni_cbc_dec)
8203
8204 #ifdef __x86_64__
8205 .align 16
8206 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8207 mov $1, TCTR_LOW
8208 MOVQ_R64_XMM TCTR_LOW INC
8209 MOVQ_R64_XMM CTR TCTR_LOW
8210 + pax_force_retaddr_bts
8211 ret
8212
8213 /*
8214 @@ -2554,6 +2582,7 @@ _aesni_inc:
8215 .Linc_low:
8216 movaps CTR, IV
8217 PSHUFB_XMM BSWAP_MASK IV
8218 + pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8223 .Lctr_enc_ret:
8224 movups IV, (IVP)
8225 .Lctr_enc_just_ret:
8226 + pax_force_retaddr 0, 1
8227 ret
8228 +ENDPROC(aesni_ctr_enc)
8229 #endif
8230 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8231 index 391d245..67f35c2 100644
8232 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8233 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8234 @@ -20,6 +20,8 @@
8235 *
8236 */
8237
8238 +#include <asm/alternative-asm.h>
8239 +
8240 .file "blowfish-x86_64-asm.S"
8241 .text
8242
8243 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8244 jnz __enc_xor;
8245
8246 write_block();
8247 + pax_force_retaddr 0, 1
8248 ret;
8249 __enc_xor:
8250 xor_block();
8251 + pax_force_retaddr 0, 1
8252 ret;
8253
8254 .align 8
8255 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8256
8257 movq %r11, %rbp;
8258
8259 + pax_force_retaddr 0, 1
8260 ret;
8261
8262 /**********************************************************************
8263 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8264
8265 popq %rbx;
8266 popq %rbp;
8267 + pax_force_retaddr 0, 1
8268 ret;
8269
8270 __enc_xor4:
8271 @@ -349,6 +355,7 @@ __enc_xor4:
8272
8273 popq %rbx;
8274 popq %rbp;
8275 + pax_force_retaddr 0, 1
8276 ret;
8277
8278 .align 8
8279 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8280 popq %rbx;
8281 popq %rbp;
8282
8283 + pax_force_retaddr 0, 1
8284 ret;
8285
8286 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8287 index 0b33743..7a56206 100644
8288 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8289 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8290 @@ -20,6 +20,8 @@
8291 *
8292 */
8293
8294 +#include <asm/alternative-asm.h>
8295 +
8296 .file "camellia-x86_64-asm_64.S"
8297 .text
8298
8299 @@ -229,12 +231,14 @@ __enc_done:
8300 enc_outunpack(mov, RT1);
8301
8302 movq RRBP, %rbp;
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 __enc_xor:
8307 enc_outunpack(xor, RT1);
8308
8309 movq RRBP, %rbp;
8310 + pax_force_retaddr 0, 1
8311 ret;
8312
8313 .global camellia_dec_blk;
8314 @@ -275,6 +279,7 @@ __dec_rounds16:
8315 dec_outunpack();
8316
8317 movq RRBP, %rbp;
8318 + pax_force_retaddr 0, 1
8319 ret;
8320
8321 /**********************************************************************
8322 @@ -468,6 +473,7 @@ __enc2_done:
8323
8324 movq RRBP, %rbp;
8325 popq %rbx;
8326 + pax_force_retaddr 0, 1
8327 ret;
8328
8329 __enc2_xor:
8330 @@ -475,6 +481,7 @@ __enc2_xor:
8331
8332 movq RRBP, %rbp;
8333 popq %rbx;
8334 + pax_force_retaddr 0, 1
8335 ret;
8336
8337 .global camellia_dec_blk_2way;
8338 @@ -517,4 +524,5 @@ __dec2_rounds16:
8339
8340 movq RRBP, %rbp;
8341 movq RXOR, %rbx;
8342 + pax_force_retaddr 0, 1
8343 ret;
8344 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8345 index 6214a9b..1f4fc9a 100644
8346 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8347 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8348 @@ -1,3 +1,5 @@
8349 +#include <asm/alternative-asm.h>
8350 +
8351 # enter ECRYPT_encrypt_bytes
8352 .text
8353 .p2align 5
8354 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8355 add %r11,%rsp
8356 mov %rdi,%rax
8357 mov %rsi,%rdx
8358 + pax_force_retaddr 0, 1
8359 ret
8360 # bytesatleast65:
8361 ._bytesatleast65:
8362 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8363 add %r11,%rsp
8364 mov %rdi,%rax
8365 mov %rsi,%rdx
8366 + pax_force_retaddr
8367 ret
8368 # enter ECRYPT_ivsetup
8369 .text
8370 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8371 add %r11,%rsp
8372 mov %rdi,%rax
8373 mov %rsi,%rdx
8374 + pax_force_retaddr
8375 ret
8376 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8377 index 504106b..4e50951 100644
8378 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8379 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8380 @@ -24,6 +24,8 @@
8381 *
8382 */
8383
8384 +#include <asm/alternative-asm.h>
8385 +
8386 .file "serpent-avx-x86_64-asm_64.S"
8387 .text
8388
8389 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8390 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8391 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8392
8393 + pax_force_retaddr
8394 ret;
8395
8396 __enc_xor8:
8397 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8398 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8399
8400 + pax_force_retaddr
8401 ret;
8402
8403 .align 8
8404 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8405 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8406 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8407
8408 + pax_force_retaddr
8409 ret;
8410 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8411 index 3ee1ff0..cbc568b 100644
8412 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8413 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8414 @@ -24,6 +24,8 @@
8415 *
8416 */
8417
8418 +#include <asm/alternative-asm.h>
8419 +
8420 .file "serpent-sse2-x86_64-asm_64.S"
8421 .text
8422
8423 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8424 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8425 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8426
8427 + pax_force_retaddr
8428 ret;
8429
8430 __enc_xor8:
8431 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8432 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8433
8434 + pax_force_retaddr
8435 ret;
8436
8437 .align 8
8438 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8439 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8440 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8441
8442 + pax_force_retaddr
8443 ret;
8444 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8445 index 49d6987..df66bd4 100644
8446 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8447 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8448 @@ -28,6 +28,8 @@
8449 * (at your option) any later version.
8450 */
8451
8452 +#include <asm/alternative-asm.h>
8453 +
8454 #define CTX %rdi // arg1
8455 #define BUF %rsi // arg2
8456 #define CNT %rdx // arg3
8457 @@ -104,6 +106,7 @@
8458 pop %r12
8459 pop %rbp
8460 pop %rbx
8461 + pax_force_retaddr 0, 1
8462 ret
8463
8464 .size \name, .-\name
8465 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8466 index 35f4557..16b379f 100644
8467 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8468 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8469 @@ -21,6 +21,8 @@
8470 *
8471 */
8472
8473 +#include <asm/alternative-asm.h>
8474 +
8475 .file "twofish-avx-x86_64-asm_64.S"
8476 .text
8477
8478 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8479 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8480 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8481
8482 + pax_force_retaddr
8483 ret;
8484
8485 __enc_xor8:
8486 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8487 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8488
8489 + pax_force_retaddr
8490 ret;
8491
8492 .align 8
8493 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8494 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8495 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8496
8497 + pax_force_retaddr
8498 ret;
8499 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8500 index 5b012a2..36d5364 100644
8501 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8502 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8503 @@ -20,6 +20,8 @@
8504 *
8505 */
8506
8507 +#include <asm/alternative-asm.h>
8508 +
8509 .file "twofish-x86_64-asm-3way.S"
8510 .text
8511
8512 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8513 popq %r13;
8514 popq %r14;
8515 popq %r15;
8516 + pax_force_retaddr 0, 1
8517 ret;
8518
8519 __enc_xor3:
8520 @@ -271,6 +274,7 @@ __enc_xor3:
8521 popq %r13;
8522 popq %r14;
8523 popq %r15;
8524 + pax_force_retaddr 0, 1
8525 ret;
8526
8527 .global twofish_dec_blk_3way
8528 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8529 popq %r13;
8530 popq %r14;
8531 popq %r15;
8532 + pax_force_retaddr 0, 1
8533 ret;
8534
8535 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8536 index 7bcf3fc..f53832f 100644
8537 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8538 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8539 @@ -21,6 +21,7 @@
8540 .text
8541
8542 #include <asm/asm-offsets.h>
8543 +#include <asm/alternative-asm.h>
8544
8545 #define a_offset 0
8546 #define b_offset 4
8547 @@ -268,6 +269,7 @@ twofish_enc_blk:
8548
8549 popq R1
8550 movq $1,%rax
8551 + pax_force_retaddr 0, 1
8552 ret
8553
8554 twofish_dec_blk:
8555 @@ -319,4 +321,5 @@ twofish_dec_blk:
8556
8557 popq R1
8558 movq $1,%rax
8559 + pax_force_retaddr 0, 1
8560 ret
8561 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8562 index 07b3a68..bd2a388 100644
8563 --- a/arch/x86/ia32/ia32_aout.c
8564 +++ b/arch/x86/ia32/ia32_aout.c
8565 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8566 unsigned long dump_start, dump_size;
8567 struct user32 dump;
8568
8569 + memset(&dump, 0, sizeof(dump));
8570 +
8571 fs = get_fs();
8572 set_fs(KERNEL_DS);
8573 has_dumped = 1;
8574 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8575 index 673ac9b..7a8c5df 100644
8576 --- a/arch/x86/ia32/ia32_signal.c
8577 +++ b/arch/x86/ia32/ia32_signal.c
8578 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8579 }
8580 seg = get_fs();
8581 set_fs(KERNEL_DS);
8582 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8583 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8584 set_fs(seg);
8585 if (ret >= 0 && uoss_ptr) {
8586 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8587 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8588 */
8589 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8590 size_t frame_size,
8591 - void **fpstate)
8592 + void __user **fpstate)
8593 {
8594 unsigned long sp;
8595
8596 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8597
8598 if (used_math()) {
8599 sp = sp - sig_xstate_ia32_size;
8600 - *fpstate = (struct _fpstate_ia32 *) sp;
8601 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8602 if (save_i387_xstate_ia32(*fpstate) < 0)
8603 return (void __user *) -1L;
8604 }
8605 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8606 sp -= frame_size;
8607 /* Align the stack pointer according to the i386 ABI,
8608 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8609 - sp = ((sp + 4) & -16ul) - 4;
8610 + sp = ((sp - 12) & -16ul) - 4;
8611 return (void __user *) sp;
8612 }
8613
8614 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8615 * These are actually not used anymore, but left because some
8616 * gdb versions depend on them as a marker.
8617 */
8618 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8619 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8620 } put_user_catch(err);
8621
8622 if (err)
8623 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8624 0xb8,
8625 __NR_ia32_rt_sigreturn,
8626 0x80cd,
8627 - 0,
8628 + 0
8629 };
8630
8631 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8632 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8633
8634 if (ka->sa.sa_flags & SA_RESTORER)
8635 restorer = ka->sa.sa_restorer;
8636 + else if (current->mm->context.vdso)
8637 + /* Return stub is in 32bit vsyscall page */
8638 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8639 else
8640 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8641 - rt_sigreturn);
8642 + restorer = &frame->retcode;
8643 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8644
8645 /*
8646 * Not actually used anymore, but left because some gdb
8647 * versions need it.
8648 */
8649 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8650 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8651 } put_user_catch(err);
8652
8653 if (err)
8654 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8655 index 20e5f7b..f33c779 100644
8656 --- a/arch/x86/ia32/ia32entry.S
8657 +++ b/arch/x86/ia32/ia32entry.S
8658 @@ -14,8 +14,10 @@
8659 #include <asm/segment.h>
8660 #include <asm/irqflags.h>
8661 #include <asm/asm.h>
8662 +#include <asm/pgtable.h>
8663 #include <linux/linkage.h>
8664 #include <linux/err.h>
8665 +#include <asm/alternative-asm.h>
8666
8667 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8668 #include <linux/elf-em.h>
8669 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8670 ENDPROC(native_irq_enable_sysexit)
8671 #endif
8672
8673 + .macro pax_enter_kernel_user
8674 + pax_set_fptr_mask
8675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8676 + call pax_enter_kernel_user
8677 +#endif
8678 + .endm
8679 +
8680 + .macro pax_exit_kernel_user
8681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8682 + call pax_exit_kernel_user
8683 +#endif
8684 +#ifdef CONFIG_PAX_RANDKSTACK
8685 + pushq %rax
8686 + pushq %r11
8687 + call pax_randomize_kstack
8688 + popq %r11
8689 + popq %rax
8690 +#endif
8691 + .endm
8692 +
8693 +.macro pax_erase_kstack
8694 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8695 + call pax_erase_kstack
8696 +#endif
8697 +.endm
8698 +
8699 /*
8700 * 32bit SYSENTER instruction entry.
8701 *
8702 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8703 CFI_REGISTER rsp,rbp
8704 SWAPGS_UNSAFE_STACK
8705 movq PER_CPU_VAR(kernel_stack), %rsp
8706 - addq $(KERNEL_STACK_OFFSET),%rsp
8707 - /*
8708 - * No need to follow this irqs on/off section: the syscall
8709 - * disabled irqs, here we enable it straight after entry:
8710 - */
8711 - ENABLE_INTERRUPTS(CLBR_NONE)
8712 movl %ebp,%ebp /* zero extension */
8713 pushq_cfi $__USER32_DS
8714 /*CFI_REL_OFFSET ss,0*/
8715 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8716 CFI_REL_OFFSET rsp,0
8717 pushfq_cfi
8718 /*CFI_REL_OFFSET rflags,0*/
8719 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8720 - CFI_REGISTER rip,r10
8721 + orl $X86_EFLAGS_IF,(%rsp)
8722 + GET_THREAD_INFO(%r11)
8723 + movl TI_sysenter_return(%r11), %r11d
8724 + CFI_REGISTER rip,r11
8725 pushq_cfi $__USER32_CS
8726 /*CFI_REL_OFFSET cs,0*/
8727 movl %eax, %eax
8728 - pushq_cfi %r10
8729 + pushq_cfi %r11
8730 CFI_REL_OFFSET rip,0
8731 pushq_cfi %rax
8732 cld
8733 SAVE_ARGS 0,1,0
8734 + pax_enter_kernel_user
8735 +
8736 +#ifdef CONFIG_PAX_RANDKSTACK
8737 + pax_erase_kstack
8738 +#endif
8739 +
8740 + /*
8741 + * No need to follow this irqs on/off section: the syscall
8742 + * disabled irqs, here we enable it straight after entry:
8743 + */
8744 + ENABLE_INTERRUPTS(CLBR_NONE)
8745 /* no need to do an access_ok check here because rbp has been
8746 32bit zero extended */
8747 +
8748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8749 + mov $PAX_USER_SHADOW_BASE,%r11
8750 + add %r11,%rbp
8751 +#endif
8752 +
8753 1: movl (%rbp),%ebp
8754 _ASM_EXTABLE(1b,ia32_badarg)
8755 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8756 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8757 + GET_THREAD_INFO(%r11)
8758 + orl $TS_COMPAT,TI_status(%r11)
8759 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8760 CFI_REMEMBER_STATE
8761 jnz sysenter_tracesys
8762 cmpq $(IA32_NR_syscalls-1),%rax
8763 @@ -159,12 +201,15 @@ sysenter_do_call:
8764 sysenter_dispatch:
8765 call *ia32_sys_call_table(,%rax,8)
8766 movq %rax,RAX-ARGOFFSET(%rsp)
8767 + GET_THREAD_INFO(%r11)
8768 DISABLE_INTERRUPTS(CLBR_NONE)
8769 TRACE_IRQS_OFF
8770 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8771 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8772 jnz sysexit_audit
8773 sysexit_from_sys_call:
8774 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8775 + pax_exit_kernel_user
8776 + pax_erase_kstack
8777 + andl $~TS_COMPAT,TI_status(%r11)
8778 /* clear IF, that popfq doesn't enable interrupts early */
8779 andl $~0x200,EFLAGS-R11(%rsp)
8780 movl RIP-R11(%rsp),%edx /* User %eip */
8781 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8782 movl %eax,%esi /* 2nd arg: syscall number */
8783 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8784 call __audit_syscall_entry
8785 +
8786 + pax_erase_kstack
8787 +
8788 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8789 cmpq $(IA32_NR_syscalls-1),%rax
8790 ja ia32_badsys
8791 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8792 .endm
8793
8794 .macro auditsys_exit exit
8795 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8796 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8797 jnz ia32_ret_from_sys_call
8798 TRACE_IRQS_ON
8799 sti
8800 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8801 1: setbe %al /* 1 if error, 0 if not */
8802 movzbl %al,%edi /* zero-extend that into %edi */
8803 call __audit_syscall_exit
8804 + GET_THREAD_INFO(%r11)
8805 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8806 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8807 cli
8808 TRACE_IRQS_OFF
8809 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8810 + testl %edi,TI_flags(%r11)
8811 jz \exit
8812 CLEAR_RREGS -ARGOFFSET
8813 jmp int_with_check
8814 @@ -234,7 +283,7 @@ sysexit_audit:
8815
8816 sysenter_tracesys:
8817 #ifdef CONFIG_AUDITSYSCALL
8818 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8820 jz sysenter_auditsys
8821 #endif
8822 SAVE_REST
8823 @@ -246,6 +295,9 @@ sysenter_tracesys:
8824 RESTORE_REST
8825 cmpq $(IA32_NR_syscalls-1),%rax
8826 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8827 +
8828 + pax_erase_kstack
8829 +
8830 jmp sysenter_do_call
8831 CFI_ENDPROC
8832 ENDPROC(ia32_sysenter_target)
8833 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8834 ENTRY(ia32_cstar_target)
8835 CFI_STARTPROC32 simple
8836 CFI_SIGNAL_FRAME
8837 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8838 + CFI_DEF_CFA rsp,0
8839 CFI_REGISTER rip,rcx
8840 /*CFI_REGISTER rflags,r11*/
8841 SWAPGS_UNSAFE_STACK
8842 movl %esp,%r8d
8843 CFI_REGISTER rsp,r8
8844 movq PER_CPU_VAR(kernel_stack),%rsp
8845 + SAVE_ARGS 8*6,0,0
8846 + pax_enter_kernel_user
8847 +
8848 +#ifdef CONFIG_PAX_RANDKSTACK
8849 + pax_erase_kstack
8850 +#endif
8851 +
8852 /*
8853 * No need to follow this irqs on/off section: the syscall
8854 * disabled irqs and here we enable it straight after entry:
8855 */
8856 ENABLE_INTERRUPTS(CLBR_NONE)
8857 - SAVE_ARGS 8,0,0
8858 movl %eax,%eax /* zero extension */
8859 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8860 movq %rcx,RIP-ARGOFFSET(%rsp)
8861 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8862 /* no need to do an access_ok check here because r8 has been
8863 32bit zero extended */
8864 /* hardware stack frame is complete now */
8865 +
8866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8867 + mov $PAX_USER_SHADOW_BASE,%r11
8868 + add %r11,%r8
8869 +#endif
8870 +
8871 1: movl (%r8),%r9d
8872 _ASM_EXTABLE(1b,ia32_badarg)
8873 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8874 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8875 + GET_THREAD_INFO(%r11)
8876 + orl $TS_COMPAT,TI_status(%r11)
8877 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8878 CFI_REMEMBER_STATE
8879 jnz cstar_tracesys
8880 cmpq $IA32_NR_syscalls-1,%rax
8881 @@ -314,12 +379,15 @@ cstar_do_call:
8882 cstar_dispatch:
8883 call *ia32_sys_call_table(,%rax,8)
8884 movq %rax,RAX-ARGOFFSET(%rsp)
8885 + GET_THREAD_INFO(%r11)
8886 DISABLE_INTERRUPTS(CLBR_NONE)
8887 TRACE_IRQS_OFF
8888 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8889 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8890 jnz sysretl_audit
8891 sysretl_from_sys_call:
8892 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8893 + pax_exit_kernel_user
8894 + pax_erase_kstack
8895 + andl $~TS_COMPAT,TI_status(%r11)
8896 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8897 movl RIP-ARGOFFSET(%rsp),%ecx
8898 CFI_REGISTER rip,rcx
8899 @@ -347,7 +415,7 @@ sysretl_audit:
8900
8901 cstar_tracesys:
8902 #ifdef CONFIG_AUDITSYSCALL
8903 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8904 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8905 jz cstar_auditsys
8906 #endif
8907 xchgl %r9d,%ebp
8908 @@ -361,6 +429,9 @@ cstar_tracesys:
8909 xchgl %ebp,%r9d
8910 cmpq $(IA32_NR_syscalls-1),%rax
8911 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8912 +
8913 + pax_erase_kstack
8914 +
8915 jmp cstar_do_call
8916 END(ia32_cstar_target)
8917
8918 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8919 CFI_REL_OFFSET rip,RIP-RIP
8920 PARAVIRT_ADJUST_EXCEPTION_FRAME
8921 SWAPGS
8922 - /*
8923 - * No need to follow this irqs on/off section: the syscall
8924 - * disabled irqs and here we enable it straight after entry:
8925 - */
8926 - ENABLE_INTERRUPTS(CLBR_NONE)
8927 movl %eax,%eax
8928 pushq_cfi %rax
8929 cld
8930 /* note the registers are not zero extended to the sf.
8931 this could be a problem. */
8932 SAVE_ARGS 0,1,0
8933 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8934 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8935 + pax_enter_kernel_user
8936 +
8937 +#ifdef CONFIG_PAX_RANDKSTACK
8938 + pax_erase_kstack
8939 +#endif
8940 +
8941 + /*
8942 + * No need to follow this irqs on/off section: the syscall
8943 + * disabled irqs and here we enable it straight after entry:
8944 + */
8945 + ENABLE_INTERRUPTS(CLBR_NONE)
8946 + GET_THREAD_INFO(%r11)
8947 + orl $TS_COMPAT,TI_status(%r11)
8948 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8949 jnz ia32_tracesys
8950 cmpq $(IA32_NR_syscalls-1),%rax
8951 ja ia32_badsys
8952 @@ -436,6 +514,9 @@ ia32_tracesys:
8953 RESTORE_REST
8954 cmpq $(IA32_NR_syscalls-1),%rax
8955 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8956 +
8957 + pax_erase_kstack
8958 +
8959 jmp ia32_do_call
8960 END(ia32_syscall)
8961
8962 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8963 index 4540bec..714d913 100644
8964 --- a/arch/x86/ia32/sys_ia32.c
8965 +++ b/arch/x86/ia32/sys_ia32.c
8966 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8967 */
8968 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8969 {
8970 - typeof(ubuf->st_uid) uid = 0;
8971 - typeof(ubuf->st_gid) gid = 0;
8972 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8973 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8974 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8975 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8976 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8977 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8978 return ret;
8979 }
8980
8981 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8982 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8983 int options)
8984 {
8985 return compat_sys_wait4(pid, stat_addr, options, NULL);
8986 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8987 mm_segment_t old_fs = get_fs();
8988
8989 set_fs(KERNEL_DS);
8990 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8991 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8992 set_fs(old_fs);
8993 if (put_compat_timespec(&t, interval))
8994 return -EFAULT;
8995 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8996 mm_segment_t old_fs = get_fs();
8997
8998 set_fs(KERNEL_DS);
8999 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9000 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9001 set_fs(old_fs);
9002 if (!ret) {
9003 switch (_NSIG_WORDS) {
9004 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9005 if (copy_siginfo_from_user32(&info, uinfo))
9006 return -EFAULT;
9007 set_fs(KERNEL_DS);
9008 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9009 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9010 set_fs(old_fs);
9011 return ret;
9012 }
9013 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9014 return -EFAULT;
9015
9016 set_fs(KERNEL_DS);
9017 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9018 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9019 count);
9020 set_fs(old_fs);
9021
9022 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9023 index 952bd01..7692c6f 100644
9024 --- a/arch/x86/include/asm/alternative-asm.h
9025 +++ b/arch/x86/include/asm/alternative-asm.h
9026 @@ -15,6 +15,45 @@
9027 .endm
9028 #endif
9029
9030 +#ifdef KERNEXEC_PLUGIN
9031 + .macro pax_force_retaddr_bts rip=0
9032 + btsq $63,\rip(%rsp)
9033 + .endm
9034 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9035 + .macro pax_force_retaddr rip=0, reload=0
9036 + btsq $63,\rip(%rsp)
9037 + .endm
9038 + .macro pax_force_fptr ptr
9039 + btsq $63,\ptr
9040 + .endm
9041 + .macro pax_set_fptr_mask
9042 + .endm
9043 +#endif
9044 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9045 + .macro pax_force_retaddr rip=0, reload=0
9046 + .if \reload
9047 + pax_set_fptr_mask
9048 + .endif
9049 + orq %r10,\rip(%rsp)
9050 + .endm
9051 + .macro pax_force_fptr ptr
9052 + orq %r10,\ptr
9053 + .endm
9054 + .macro pax_set_fptr_mask
9055 + movabs $0x8000000000000000,%r10
9056 + .endm
9057 +#endif
9058 +#else
9059 + .macro pax_force_retaddr rip=0, reload=0
9060 + .endm
9061 + .macro pax_force_fptr ptr
9062 + .endm
9063 + .macro pax_force_retaddr_bts rip=0
9064 + .endm
9065 + .macro pax_set_fptr_mask
9066 + .endm
9067 +#endif
9068 +
9069 .macro altinstruction_entry orig alt feature orig_len alt_len
9070 .long \orig - .
9071 .long \alt - .
9072 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9073 index 7078068..f58bcda 100644
9074 --- a/arch/x86/include/asm/alternative.h
9075 +++ b/arch/x86/include/asm/alternative.h
9076 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9077 ".section .discard,\"aw\",@progbits\n" \
9078 DISCARD_ENTRY(1) \
9079 ".previous\n" \
9080 - ".section .altinstr_replacement, \"ax\"\n" \
9081 + ".section .altinstr_replacement, \"a\"\n" \
9082 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9083 ".previous"
9084
9085 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9086 DISCARD_ENTRY(1) \
9087 DISCARD_ENTRY(2) \
9088 ".previous\n" \
9089 - ".section .altinstr_replacement, \"ax\"\n" \
9090 + ".section .altinstr_replacement, \"a\"\n" \
9091 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9092 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9093 ".previous"
9094 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9095 index f342612..b3fe911 100644
9096 --- a/arch/x86/include/asm/apic.h
9097 +++ b/arch/x86/include/asm/apic.h
9098 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9099
9100 #ifdef CONFIG_X86_LOCAL_APIC
9101
9102 -extern unsigned int apic_verbosity;
9103 +extern int apic_verbosity;
9104 extern int local_apic_timer_c2_ok;
9105
9106 extern int disable_apic;
9107 @@ -391,7 +391,7 @@ struct apic {
9108 */
9109 int (*x86_32_numa_cpu_node)(int cpu);
9110 #endif
9111 -};
9112 +} __do_const;
9113
9114 /*
9115 * Pointer to the local APIC driver in use on this system (there's
9116 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9117 index 20370c6..a2eb9b0 100644
9118 --- a/arch/x86/include/asm/apm.h
9119 +++ b/arch/x86/include/asm/apm.h
9120 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9121 __asm__ __volatile__(APM_DO_ZERO_SEGS
9122 "pushl %%edi\n\t"
9123 "pushl %%ebp\n\t"
9124 - "lcall *%%cs:apm_bios_entry\n\t"
9125 + "lcall *%%ss:apm_bios_entry\n\t"
9126 "setc %%al\n\t"
9127 "popl %%ebp\n\t"
9128 "popl %%edi\n\t"
9129 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9130 __asm__ __volatile__(APM_DO_ZERO_SEGS
9131 "pushl %%edi\n\t"
9132 "pushl %%ebp\n\t"
9133 - "lcall *%%cs:apm_bios_entry\n\t"
9134 + "lcall *%%ss:apm_bios_entry\n\t"
9135 "setc %%bl\n\t"
9136 "popl %%ebp\n\t"
9137 "popl %%edi\n\t"
9138 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9139 index 58cb6d4..a4b806c 100644
9140 --- a/arch/x86/include/asm/atomic.h
9141 +++ b/arch/x86/include/asm/atomic.h
9142 @@ -22,7 +22,18 @@
9143 */
9144 static inline int atomic_read(const atomic_t *v)
9145 {
9146 - return (*(volatile int *)&(v)->counter);
9147 + return (*(volatile const int *)&(v)->counter);
9148 +}
9149 +
9150 +/**
9151 + * atomic_read_unchecked - read atomic variable
9152 + * @v: pointer of type atomic_unchecked_t
9153 + *
9154 + * Atomically reads the value of @v.
9155 + */
9156 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9157 +{
9158 + return (*(volatile const int *)&(v)->counter);
9159 }
9160
9161 /**
9162 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9163 }
9164
9165 /**
9166 + * atomic_set_unchecked - set atomic variable
9167 + * @v: pointer of type atomic_unchecked_t
9168 + * @i: required value
9169 + *
9170 + * Atomically sets the value of @v to @i.
9171 + */
9172 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9173 +{
9174 + v->counter = i;
9175 +}
9176 +
9177 +/**
9178 * atomic_add - add integer to atomic variable
9179 * @i: integer value to add
9180 * @v: pointer of type atomic_t
9181 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9182 */
9183 static inline void atomic_add(int i, atomic_t *v)
9184 {
9185 - asm volatile(LOCK_PREFIX "addl %1,%0"
9186 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9187 +
9188 +#ifdef CONFIG_PAX_REFCOUNT
9189 + "jno 0f\n"
9190 + LOCK_PREFIX "subl %1,%0\n"
9191 + "int $4\n0:\n"
9192 + _ASM_EXTABLE(0b, 0b)
9193 +#endif
9194 +
9195 + : "+m" (v->counter)
9196 + : "ir" (i));
9197 +}
9198 +
9199 +/**
9200 + * atomic_add_unchecked - add integer to atomic variable
9201 + * @i: integer value to add
9202 + * @v: pointer of type atomic_unchecked_t
9203 + *
9204 + * Atomically adds @i to @v.
9205 + */
9206 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9207 +{
9208 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9209 : "+m" (v->counter)
9210 : "ir" (i));
9211 }
9212 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9213 */
9214 static inline void atomic_sub(int i, atomic_t *v)
9215 {
9216 - asm volatile(LOCK_PREFIX "subl %1,%0"
9217 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9218 +
9219 +#ifdef CONFIG_PAX_REFCOUNT
9220 + "jno 0f\n"
9221 + LOCK_PREFIX "addl %1,%0\n"
9222 + "int $4\n0:\n"
9223 + _ASM_EXTABLE(0b, 0b)
9224 +#endif
9225 +
9226 + : "+m" (v->counter)
9227 + : "ir" (i));
9228 +}
9229 +
9230 +/**
9231 + * atomic_sub_unchecked - subtract integer from atomic variable
9232 + * @i: integer value to subtract
9233 + * @v: pointer of type atomic_unchecked_t
9234 + *
9235 + * Atomically subtracts @i from @v.
9236 + */
9237 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9238 +{
9239 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9240 : "+m" (v->counter)
9241 : "ir" (i));
9242 }
9243 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9244 {
9245 unsigned char c;
9246
9247 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9248 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9249 +
9250 +#ifdef CONFIG_PAX_REFCOUNT
9251 + "jno 0f\n"
9252 + LOCK_PREFIX "addl %2,%0\n"
9253 + "int $4\n0:\n"
9254 + _ASM_EXTABLE(0b, 0b)
9255 +#endif
9256 +
9257 + "sete %1\n"
9258 : "+m" (v->counter), "=qm" (c)
9259 : "ir" (i) : "memory");
9260 return c;
9261 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9262 */
9263 static inline void atomic_inc(atomic_t *v)
9264 {
9265 - asm volatile(LOCK_PREFIX "incl %0"
9266 + asm volatile(LOCK_PREFIX "incl %0\n"
9267 +
9268 +#ifdef CONFIG_PAX_REFCOUNT
9269 + "jno 0f\n"
9270 + LOCK_PREFIX "decl %0\n"
9271 + "int $4\n0:\n"
9272 + _ASM_EXTABLE(0b, 0b)
9273 +#endif
9274 +
9275 + : "+m" (v->counter));
9276 +}
9277 +
9278 +/**
9279 + * atomic_inc_unchecked - increment atomic variable
9280 + * @v: pointer of type atomic_unchecked_t
9281 + *
9282 + * Atomically increments @v by 1.
9283 + */
9284 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9285 +{
9286 + asm volatile(LOCK_PREFIX "incl %0\n"
9287 : "+m" (v->counter));
9288 }
9289
9290 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9291 */
9292 static inline void atomic_dec(atomic_t *v)
9293 {
9294 - asm volatile(LOCK_PREFIX "decl %0"
9295 + asm volatile(LOCK_PREFIX "decl %0\n"
9296 +
9297 +#ifdef CONFIG_PAX_REFCOUNT
9298 + "jno 0f\n"
9299 + LOCK_PREFIX "incl %0\n"
9300 + "int $4\n0:\n"
9301 + _ASM_EXTABLE(0b, 0b)
9302 +#endif
9303 +
9304 + : "+m" (v->counter));
9305 +}
9306 +
9307 +/**
9308 + * atomic_dec_unchecked - decrement atomic variable
9309 + * @v: pointer of type atomic_unchecked_t
9310 + *
9311 + * Atomically decrements @v by 1.
9312 + */
9313 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9314 +{
9315 + asm volatile(LOCK_PREFIX "decl %0\n"
9316 : "+m" (v->counter));
9317 }
9318
9319 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9320 {
9321 unsigned char c;
9322
9323 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9324 + asm volatile(LOCK_PREFIX "decl %0\n"
9325 +
9326 +#ifdef CONFIG_PAX_REFCOUNT
9327 + "jno 0f\n"
9328 + LOCK_PREFIX "incl %0\n"
9329 + "int $4\n0:\n"
9330 + _ASM_EXTABLE(0b, 0b)
9331 +#endif
9332 +
9333 + "sete %1\n"
9334 : "+m" (v->counter), "=qm" (c)
9335 : : "memory");
9336 return c != 0;
9337 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9338 {
9339 unsigned char c;
9340
9341 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9342 + asm volatile(LOCK_PREFIX "incl %0\n"
9343 +
9344 +#ifdef CONFIG_PAX_REFCOUNT
9345 + "jno 0f\n"
9346 + LOCK_PREFIX "decl %0\n"
9347 + "int $4\n0:\n"
9348 + _ASM_EXTABLE(0b, 0b)
9349 +#endif
9350 +
9351 + "sete %1\n"
9352 + : "+m" (v->counter), "=qm" (c)
9353 + : : "memory");
9354 + return c != 0;
9355 +}
9356 +
9357 +/**
9358 + * atomic_inc_and_test_unchecked - increment and test
9359 + * @v: pointer of type atomic_unchecked_t
9360 + *
9361 + * Atomically increments @v by 1
9362 + * and returns true if the result is zero, or false for all
9363 + * other cases.
9364 + */
9365 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9366 +{
9367 + unsigned char c;
9368 +
9369 + asm volatile(LOCK_PREFIX "incl %0\n"
9370 + "sete %1\n"
9371 : "+m" (v->counter), "=qm" (c)
9372 : : "memory");
9373 return c != 0;
9374 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9375 {
9376 unsigned char c;
9377
9378 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9379 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9380 +
9381 +#ifdef CONFIG_PAX_REFCOUNT
9382 + "jno 0f\n"
9383 + LOCK_PREFIX "subl %2,%0\n"
9384 + "int $4\n0:\n"
9385 + _ASM_EXTABLE(0b, 0b)
9386 +#endif
9387 +
9388 + "sets %1\n"
9389 : "+m" (v->counter), "=qm" (c)
9390 : "ir" (i) : "memory");
9391 return c;
9392 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9393 goto no_xadd;
9394 #endif
9395 /* Modern 486+ processor */
9396 - return i + xadd(&v->counter, i);
9397 + return i + xadd_check_overflow(&v->counter, i);
9398
9399 #ifdef CONFIG_M386
9400 no_xadd: /* Legacy 386 processor */
9401 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9402 }
9403
9404 /**
9405 + * atomic_add_return_unchecked - add integer and return
9406 + * @i: integer value to add
9407 + * @v: pointer of type atomic_unchecked_t
9408 + *
9409 + * Atomically adds @i to @v and returns @i + @v
9410 + */
9411 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9412 +{
9413 +#ifdef CONFIG_M386
9414 + int __i;
9415 + unsigned long flags;
9416 + if (unlikely(boot_cpu_data.x86 <= 3))
9417 + goto no_xadd;
9418 +#endif
9419 + /* Modern 486+ processor */
9420 + return i + xadd(&v->counter, i);
9421 +
9422 +#ifdef CONFIG_M386
9423 +no_xadd: /* Legacy 386 processor */
9424 + raw_local_irq_save(flags);
9425 + __i = atomic_read_unchecked(v);
9426 + atomic_set_unchecked(v, i + __i);
9427 + raw_local_irq_restore(flags);
9428 + return i + __i;
9429 +#endif
9430 +}
9431 +
9432 +/**
9433 * atomic_sub_return - subtract integer and return
9434 * @v: pointer of type atomic_t
9435 * @i: integer value to subtract
9436 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9437 }
9438
9439 #define atomic_inc_return(v) (atomic_add_return(1, v))
9440 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9441 +{
9442 + return atomic_add_return_unchecked(1, v);
9443 +}
9444 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9445
9446 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9447 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9448 return cmpxchg(&v->counter, old, new);
9449 }
9450
9451 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9452 +{
9453 + return cmpxchg(&v->counter, old, new);
9454 +}
9455 +
9456 static inline int atomic_xchg(atomic_t *v, int new)
9457 {
9458 return xchg(&v->counter, new);
9459 }
9460
9461 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9462 +{
9463 + return xchg(&v->counter, new);
9464 +}
9465 +
9466 /**
9467 * __atomic_add_unless - add unless the number is already a given value
9468 * @v: pointer of type atomic_t
9469 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9470 */
9471 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9472 {
9473 - int c, old;
9474 + int c, old, new;
9475 c = atomic_read(v);
9476 for (;;) {
9477 - if (unlikely(c == (u)))
9478 + if (unlikely(c == u))
9479 break;
9480 - old = atomic_cmpxchg((v), c, c + (a));
9481 +
9482 + asm volatile("addl %2,%0\n"
9483 +
9484 +#ifdef CONFIG_PAX_REFCOUNT
9485 + "jno 0f\n"
9486 + "subl %2,%0\n"
9487 + "int $4\n0:\n"
9488 + _ASM_EXTABLE(0b, 0b)
9489 +#endif
9490 +
9491 + : "=r" (new)
9492 + : "0" (c), "ir" (a));
9493 +
9494 + old = atomic_cmpxchg(v, c, new);
9495 if (likely(old == c))
9496 break;
9497 c = old;
9498 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9499 return c;
9500 }
9501
9502 +/**
9503 + * atomic_inc_not_zero_hint - increment if not null
9504 + * @v: pointer of type atomic_t
9505 + * @hint: probable value of the atomic before the increment
9506 + *
9507 + * This version of atomic_inc_not_zero() gives a hint of probable
9508 + * value of the atomic. This helps processor to not read the memory
9509 + * before doing the atomic read/modify/write cycle, lowering
9510 + * number of bus transactions on some arches.
9511 + *
9512 + * Returns: 0 if increment was not done, 1 otherwise.
9513 + */
9514 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9515 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9516 +{
9517 + int val, c = hint, new;
9518 +
9519 + /* sanity test, should be removed by compiler if hint is a constant */
9520 + if (!hint)
9521 + return __atomic_add_unless(v, 1, 0);
9522 +
9523 + do {
9524 + asm volatile("incl %0\n"
9525 +
9526 +#ifdef CONFIG_PAX_REFCOUNT
9527 + "jno 0f\n"
9528 + "decl %0\n"
9529 + "int $4\n0:\n"
9530 + _ASM_EXTABLE(0b, 0b)
9531 +#endif
9532 +
9533 + : "=r" (new)
9534 + : "0" (c));
9535 +
9536 + val = atomic_cmpxchg(v, c, new);
9537 + if (val == c)
9538 + return 1;
9539 + c = val;
9540 + } while (c);
9541 +
9542 + return 0;
9543 +}
9544
9545 /*
9546 * atomic_dec_if_positive - decrement by 1 if old value positive
9547 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9548 #endif
9549
9550 /* These are x86-specific, used by some header files */
9551 -#define atomic_clear_mask(mask, addr) \
9552 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9553 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9554 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9555 +{
9556 + asm volatile(LOCK_PREFIX "andl %1,%0"
9557 + : "+m" (v->counter)
9558 + : "r" (~(mask))
9559 + : "memory");
9560 +}
9561
9562 -#define atomic_set_mask(mask, addr) \
9563 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9564 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9565 - : "memory")
9566 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9567 +{
9568 + asm volatile(LOCK_PREFIX "andl %1,%0"
9569 + : "+m" (v->counter)
9570 + : "r" (~(mask))
9571 + : "memory");
9572 +}
9573 +
9574 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9575 +{
9576 + asm volatile(LOCK_PREFIX "orl %1,%0"
9577 + : "+m" (v->counter)
9578 + : "r" (mask)
9579 + : "memory");
9580 +}
9581 +
9582 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9583 +{
9584 + asm volatile(LOCK_PREFIX "orl %1,%0"
9585 + : "+m" (v->counter)
9586 + : "r" (mask)
9587 + : "memory");
9588 +}
9589
9590 /* Atomic operations are already serializing on x86 */
9591 #define smp_mb__before_atomic_dec() barrier()
9592 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9593 index b154de7..aadebd8 100644
9594 --- a/arch/x86/include/asm/atomic64_32.h
9595 +++ b/arch/x86/include/asm/atomic64_32.h
9596 @@ -12,6 +12,14 @@ typedef struct {
9597 u64 __aligned(8) counter;
9598 } atomic64_t;
9599
9600 +#ifdef CONFIG_PAX_REFCOUNT
9601 +typedef struct {
9602 + u64 __aligned(8) counter;
9603 +} atomic64_unchecked_t;
9604 +#else
9605 +typedef atomic64_t atomic64_unchecked_t;
9606 +#endif
9607 +
9608 #define ATOMIC64_INIT(val) { (val) }
9609
9610 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9611 @@ -37,21 +45,31 @@ typedef struct {
9612 ATOMIC64_DECL_ONE(sym##_386)
9613
9614 ATOMIC64_DECL_ONE(add_386);
9615 +ATOMIC64_DECL_ONE(add_unchecked_386);
9616 ATOMIC64_DECL_ONE(sub_386);
9617 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9618 ATOMIC64_DECL_ONE(inc_386);
9619 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9620 ATOMIC64_DECL_ONE(dec_386);
9621 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9622 #endif
9623
9624 #define alternative_atomic64(f, out, in...) \
9625 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9626
9627 ATOMIC64_DECL(read);
9628 +ATOMIC64_DECL(read_unchecked);
9629 ATOMIC64_DECL(set);
9630 +ATOMIC64_DECL(set_unchecked);
9631 ATOMIC64_DECL(xchg);
9632 ATOMIC64_DECL(add_return);
9633 +ATOMIC64_DECL(add_return_unchecked);
9634 ATOMIC64_DECL(sub_return);
9635 +ATOMIC64_DECL(sub_return_unchecked);
9636 ATOMIC64_DECL(inc_return);
9637 +ATOMIC64_DECL(inc_return_unchecked);
9638 ATOMIC64_DECL(dec_return);
9639 +ATOMIC64_DECL(dec_return_unchecked);
9640 ATOMIC64_DECL(dec_if_positive);
9641 ATOMIC64_DECL(inc_not_zero);
9642 ATOMIC64_DECL(add_unless);
9643 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9644 }
9645
9646 /**
9647 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9648 + * @p: pointer to type atomic64_unchecked_t
9649 + * @o: expected value
9650 + * @n: new value
9651 + *
9652 + * Atomically sets @v to @n if it was equal to @o and returns
9653 + * the old value.
9654 + */
9655 +
9656 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9657 +{
9658 + return cmpxchg64(&v->counter, o, n);
9659 +}
9660 +
9661 +/**
9662 * atomic64_xchg - xchg atomic64 variable
9663 * @v: pointer to type atomic64_t
9664 * @n: value to assign
9665 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9666 }
9667
9668 /**
9669 + * atomic64_set_unchecked - set atomic64 variable
9670 + * @v: pointer to type atomic64_unchecked_t
9671 + * @n: value to assign
9672 + *
9673 + * Atomically sets the value of @v to @n.
9674 + */
9675 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9676 +{
9677 + unsigned high = (unsigned)(i >> 32);
9678 + unsigned low = (unsigned)i;
9679 + alternative_atomic64(set, /* no output */,
9680 + "S" (v), "b" (low), "c" (high)
9681 + : "eax", "edx", "memory");
9682 +}
9683 +
9684 +/**
9685 * atomic64_read - read atomic64 variable
9686 * @v: pointer to type atomic64_t
9687 *
9688 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9689 }
9690
9691 /**
9692 + * atomic64_read_unchecked - read atomic64 variable
9693 + * @v: pointer to type atomic64_unchecked_t
9694 + *
9695 + * Atomically reads the value of @v and returns it.
9696 + */
9697 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9698 +{
9699 + long long r;
9700 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9701 + return r;
9702 + }
9703 +
9704 +/**
9705 * atomic64_add_return - add and return
9706 * @i: integer value to add
9707 * @v: pointer to type atomic64_t
9708 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9709 return i;
9710 }
9711
9712 +/**
9713 + * atomic64_add_return_unchecked - add and return
9714 + * @i: integer value to add
9715 + * @v: pointer to type atomic64_unchecked_t
9716 + *
9717 + * Atomically adds @i to @v and returns @i + *@v
9718 + */
9719 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9720 +{
9721 + alternative_atomic64(add_return_unchecked,
9722 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9723 + ASM_NO_INPUT_CLOBBER("memory"));
9724 + return i;
9725 +}
9726 +
9727 /*
9728 * Other variants with different arithmetic operators:
9729 */
9730 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9731 return a;
9732 }
9733
9734 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9735 +{
9736 + long long a;
9737 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9738 + "S" (v) : "memory", "ecx");
9739 + return a;
9740 +}
9741 +
9742 static inline long long atomic64_dec_return(atomic64_t *v)
9743 {
9744 long long a;
9745 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9746 }
9747
9748 /**
9749 + * atomic64_add_unchecked - add integer to atomic64 variable
9750 + * @i: integer value to add
9751 + * @v: pointer to type atomic64_unchecked_t
9752 + *
9753 + * Atomically adds @i to @v.
9754 + */
9755 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9756 +{
9757 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9758 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9759 + ASM_NO_INPUT_CLOBBER("memory"));
9760 + return i;
9761 +}
9762 +
9763 +/**
9764 * atomic64_sub - subtract the atomic64 variable
9765 * @i: integer value to subtract
9766 * @v: pointer to type atomic64_t
9767 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9768 index 0e1cbfc..5623683 100644
9769 --- a/arch/x86/include/asm/atomic64_64.h
9770 +++ b/arch/x86/include/asm/atomic64_64.h
9771 @@ -18,7 +18,19 @@
9772 */
9773 static inline long atomic64_read(const atomic64_t *v)
9774 {
9775 - return (*(volatile long *)&(v)->counter);
9776 + return (*(volatile const long *)&(v)->counter);
9777 +}
9778 +
9779 +/**
9780 + * atomic64_read_unchecked - read atomic64 variable
9781 + * @v: pointer of type atomic64_unchecked_t
9782 + *
9783 + * Atomically reads the value of @v.
9784 + * Doesn't imply a read memory barrier.
9785 + */
9786 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9787 +{
9788 + return (*(volatile const long *)&(v)->counter);
9789 }
9790
9791 /**
9792 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9793 }
9794
9795 /**
9796 + * atomic64_set_unchecked - set atomic64 variable
9797 + * @v: pointer to type atomic64_unchecked_t
9798 + * @i: required value
9799 + *
9800 + * Atomically sets the value of @v to @i.
9801 + */
9802 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9803 +{
9804 + v->counter = i;
9805 +}
9806 +
9807 +/**
9808 * atomic64_add - add integer to atomic64 variable
9809 * @i: integer value to add
9810 * @v: pointer to type atomic64_t
9811 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9812 */
9813 static inline void atomic64_add(long i, atomic64_t *v)
9814 {
9815 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9816 +
9817 +#ifdef CONFIG_PAX_REFCOUNT
9818 + "jno 0f\n"
9819 + LOCK_PREFIX "subq %1,%0\n"
9820 + "int $4\n0:\n"
9821 + _ASM_EXTABLE(0b, 0b)
9822 +#endif
9823 +
9824 + : "=m" (v->counter)
9825 + : "er" (i), "m" (v->counter));
9826 +}
9827 +
9828 +/**
9829 + * atomic64_add_unchecked - add integer to atomic64 variable
9830 + * @i: integer value to add
9831 + * @v: pointer to type atomic64_unchecked_t
9832 + *
9833 + * Atomically adds @i to @v.
9834 + */
9835 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9836 +{
9837 asm volatile(LOCK_PREFIX "addq %1,%0"
9838 : "=m" (v->counter)
9839 : "er" (i), "m" (v->counter));
9840 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9841 */
9842 static inline void atomic64_sub(long i, atomic64_t *v)
9843 {
9844 - asm volatile(LOCK_PREFIX "subq %1,%0"
9845 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9846 +
9847 +#ifdef CONFIG_PAX_REFCOUNT
9848 + "jno 0f\n"
9849 + LOCK_PREFIX "addq %1,%0\n"
9850 + "int $4\n0:\n"
9851 + _ASM_EXTABLE(0b, 0b)
9852 +#endif
9853 +
9854 + : "=m" (v->counter)
9855 + : "er" (i), "m" (v->counter));
9856 +}
9857 +
9858 +/**
9859 + * atomic64_sub_unchecked - subtract the atomic64 variable
9860 + * @i: integer value to subtract
9861 + * @v: pointer to type atomic64_unchecked_t
9862 + *
9863 + * Atomically subtracts @i from @v.
9864 + */
9865 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9866 +{
9867 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9868 : "=m" (v->counter)
9869 : "er" (i), "m" (v->counter));
9870 }
9871 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9872 {
9873 unsigned char c;
9874
9875 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9876 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9877 +
9878 +#ifdef CONFIG_PAX_REFCOUNT
9879 + "jno 0f\n"
9880 + LOCK_PREFIX "addq %2,%0\n"
9881 + "int $4\n0:\n"
9882 + _ASM_EXTABLE(0b, 0b)
9883 +#endif
9884 +
9885 + "sete %1\n"
9886 : "=m" (v->counter), "=qm" (c)
9887 : "er" (i), "m" (v->counter) : "memory");
9888 return c;
9889 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9890 */
9891 static inline void atomic64_inc(atomic64_t *v)
9892 {
9893 + asm volatile(LOCK_PREFIX "incq %0\n"
9894 +
9895 +#ifdef CONFIG_PAX_REFCOUNT
9896 + "jno 0f\n"
9897 + LOCK_PREFIX "decq %0\n"
9898 + "int $4\n0:\n"
9899 + _ASM_EXTABLE(0b, 0b)
9900 +#endif
9901 +
9902 + : "=m" (v->counter)
9903 + : "m" (v->counter));
9904 +}
9905 +
9906 +/**
9907 + * atomic64_inc_unchecked - increment atomic64 variable
9908 + * @v: pointer to type atomic64_unchecked_t
9909 + *
9910 + * Atomically increments @v by 1.
9911 + */
9912 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9913 +{
9914 asm volatile(LOCK_PREFIX "incq %0"
9915 : "=m" (v->counter)
9916 : "m" (v->counter));
9917 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9918 */
9919 static inline void atomic64_dec(atomic64_t *v)
9920 {
9921 - asm volatile(LOCK_PREFIX "decq %0"
9922 + asm volatile(LOCK_PREFIX "decq %0\n"
9923 +
9924 +#ifdef CONFIG_PAX_REFCOUNT
9925 + "jno 0f\n"
9926 + LOCK_PREFIX "incq %0\n"
9927 + "int $4\n0:\n"
9928 + _ASM_EXTABLE(0b, 0b)
9929 +#endif
9930 +
9931 + : "=m" (v->counter)
9932 + : "m" (v->counter));
9933 +}
9934 +
9935 +/**
9936 + * atomic64_dec_unchecked - decrement atomic64 variable
9937 + * @v: pointer to type atomic64_t
9938 + *
9939 + * Atomically decrements @v by 1.
9940 + */
9941 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9942 +{
9943 + asm volatile(LOCK_PREFIX "decq %0\n"
9944 : "=m" (v->counter)
9945 : "m" (v->counter));
9946 }
9947 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9948 {
9949 unsigned char c;
9950
9951 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9952 + asm volatile(LOCK_PREFIX "decq %0\n"
9953 +
9954 +#ifdef CONFIG_PAX_REFCOUNT
9955 + "jno 0f\n"
9956 + LOCK_PREFIX "incq %0\n"
9957 + "int $4\n0:\n"
9958 + _ASM_EXTABLE(0b, 0b)
9959 +#endif
9960 +
9961 + "sete %1\n"
9962 : "=m" (v->counter), "=qm" (c)
9963 : "m" (v->counter) : "memory");
9964 return c != 0;
9965 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9966 {
9967 unsigned char c;
9968
9969 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9970 + asm volatile(LOCK_PREFIX "incq %0\n"
9971 +
9972 +#ifdef CONFIG_PAX_REFCOUNT
9973 + "jno 0f\n"
9974 + LOCK_PREFIX "decq %0\n"
9975 + "int $4\n0:\n"
9976 + _ASM_EXTABLE(0b, 0b)
9977 +#endif
9978 +
9979 + "sete %1\n"
9980 : "=m" (v->counter), "=qm" (c)
9981 : "m" (v->counter) : "memory");
9982 return c != 0;
9983 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9984 {
9985 unsigned char c;
9986
9987 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9988 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9989 +
9990 +#ifdef CONFIG_PAX_REFCOUNT
9991 + "jno 0f\n"
9992 + LOCK_PREFIX "subq %2,%0\n"
9993 + "int $4\n0:\n"
9994 + _ASM_EXTABLE(0b, 0b)
9995 +#endif
9996 +
9997 + "sets %1\n"
9998 : "=m" (v->counter), "=qm" (c)
9999 : "er" (i), "m" (v->counter) : "memory");
10000 return c;
10001 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10002 */
10003 static inline long atomic64_add_return(long i, atomic64_t *v)
10004 {
10005 + return i + xadd_check_overflow(&v->counter, i);
10006 +}
10007 +
10008 +/**
10009 + * atomic64_add_return_unchecked - add and return
10010 + * @i: integer value to add
10011 + * @v: pointer to type atomic64_unchecked_t
10012 + *
10013 + * Atomically adds @i to @v and returns @i + @v
10014 + */
10015 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10016 +{
10017 return i + xadd(&v->counter, i);
10018 }
10019
10020 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10021 }
10022
10023 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10024 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10025 +{
10026 + return atomic64_add_return_unchecked(1, v);
10027 +}
10028 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10029
10030 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10031 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10032 return cmpxchg(&v->counter, old, new);
10033 }
10034
10035 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10036 +{
10037 + return cmpxchg(&v->counter, old, new);
10038 +}
10039 +
10040 static inline long atomic64_xchg(atomic64_t *v, long new)
10041 {
10042 return xchg(&v->counter, new);
10043 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10044 */
10045 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10046 {
10047 - long c, old;
10048 + long c, old, new;
10049 c = atomic64_read(v);
10050 for (;;) {
10051 - if (unlikely(c == (u)))
10052 + if (unlikely(c == u))
10053 break;
10054 - old = atomic64_cmpxchg((v), c, c + (a));
10055 +
10056 + asm volatile("add %2,%0\n"
10057 +
10058 +#ifdef CONFIG_PAX_REFCOUNT
10059 + "jno 0f\n"
10060 + "sub %2,%0\n"
10061 + "int $4\n0:\n"
10062 + _ASM_EXTABLE(0b, 0b)
10063 +#endif
10064 +
10065 + : "=r" (new)
10066 + : "0" (c), "ir" (a));
10067 +
10068 + old = atomic64_cmpxchg(v, c, new);
10069 if (likely(old == c))
10070 break;
10071 c = old;
10072 }
10073 - return c != (u);
10074 + return c != u;
10075 }
10076
10077 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10078 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10079 index 72f5009..2f8b9a9 100644
10080 --- a/arch/x86/include/asm/bitops.h
10081 +++ b/arch/x86/include/asm/bitops.h
10082 @@ -40,7 +40,7 @@
10083 * a mask operation on a byte.
10084 */
10085 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10086 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10087 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10088 #define CONST_MASK(nr) (1 << ((nr) & 7))
10089
10090 /**
10091 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10092 index b13fe63..0dab13a 100644
10093 --- a/arch/x86/include/asm/boot.h
10094 +++ b/arch/x86/include/asm/boot.h
10095 @@ -11,10 +11,15 @@
10096 #include <asm/pgtable_types.h>
10097
10098 /* Physical address where kernel should be loaded. */
10099 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10100 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10101 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10102 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10103
10104 +#ifndef __ASSEMBLY__
10105 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10106 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10107 +#endif
10108 +
10109 /* Minimum kernel alignment, as a power of two */
10110 #ifdef CONFIG_X86_64
10111 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10112 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10113 index 48f99f1..d78ebf9 100644
10114 --- a/arch/x86/include/asm/cache.h
10115 +++ b/arch/x86/include/asm/cache.h
10116 @@ -5,12 +5,13 @@
10117
10118 /* L1 cache line size */
10119 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10120 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10121 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10122
10123 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10124 +#define __read_only __attribute__((__section__(".data..read_only")))
10125
10126 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10127 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10128 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10129
10130 #ifdef CONFIG_X86_VSMP
10131 #ifdef CONFIG_SMP
10132 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10133 index 9863ee3..4a1f8e1 100644
10134 --- a/arch/x86/include/asm/cacheflush.h
10135 +++ b/arch/x86/include/asm/cacheflush.h
10136 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10137 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10138
10139 if (pg_flags == _PGMT_DEFAULT)
10140 - return -1;
10141 + return ~0UL;
10142 else if (pg_flags == _PGMT_WC)
10143 return _PAGE_CACHE_WC;
10144 else if (pg_flags == _PGMT_UC_MINUS)
10145 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10146 index 46fc474..b02b0f9 100644
10147 --- a/arch/x86/include/asm/checksum_32.h
10148 +++ b/arch/x86/include/asm/checksum_32.h
10149 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10150 int len, __wsum sum,
10151 int *src_err_ptr, int *dst_err_ptr);
10152
10153 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10154 + int len, __wsum sum,
10155 + int *src_err_ptr, int *dst_err_ptr);
10156 +
10157 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10158 + int len, __wsum sum,
10159 + int *src_err_ptr, int *dst_err_ptr);
10160 +
10161 /*
10162 * Note: when you get a NULL pointer exception here this means someone
10163 * passed in an incorrect kernel address to one of these functions.
10164 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10165 int *err_ptr)
10166 {
10167 might_sleep();
10168 - return csum_partial_copy_generic((__force void *)src, dst,
10169 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10170 len, sum, err_ptr, NULL);
10171 }
10172
10173 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10174 {
10175 might_sleep();
10176 if (access_ok(VERIFY_WRITE, dst, len))
10177 - return csum_partial_copy_generic(src, (__force void *)dst,
10178 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10179 len, sum, NULL, err_ptr);
10180
10181 if (len)
10182 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10183 index 99480e5..d81165b 100644
10184 --- a/arch/x86/include/asm/cmpxchg.h
10185 +++ b/arch/x86/include/asm/cmpxchg.h
10186 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10187 __compiletime_error("Bad argument size for cmpxchg");
10188 extern void __xadd_wrong_size(void)
10189 __compiletime_error("Bad argument size for xadd");
10190 +extern void __xadd_check_overflow_wrong_size(void)
10191 + __compiletime_error("Bad argument size for xadd_check_overflow");
10192 extern void __add_wrong_size(void)
10193 __compiletime_error("Bad argument size for add");
10194 +extern void __add_check_overflow_wrong_size(void)
10195 + __compiletime_error("Bad argument size for add_check_overflow");
10196
10197 /*
10198 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10199 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10200 __ret; \
10201 })
10202
10203 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10204 + ({ \
10205 + __typeof__ (*(ptr)) __ret = (arg); \
10206 + switch (sizeof(*(ptr))) { \
10207 + case __X86_CASE_L: \
10208 + asm volatile (lock #op "l %0, %1\n" \
10209 + "jno 0f\n" \
10210 + "mov %0,%1\n" \
10211 + "int $4\n0:\n" \
10212 + _ASM_EXTABLE(0b, 0b) \
10213 + : "+r" (__ret), "+m" (*(ptr)) \
10214 + : : "memory", "cc"); \
10215 + break; \
10216 + case __X86_CASE_Q: \
10217 + asm volatile (lock #op "q %q0, %1\n" \
10218 + "jno 0f\n" \
10219 + "mov %0,%1\n" \
10220 + "int $4\n0:\n" \
10221 + _ASM_EXTABLE(0b, 0b) \
10222 + : "+r" (__ret), "+m" (*(ptr)) \
10223 + : : "memory", "cc"); \
10224 + break; \
10225 + default: \
10226 + __ ## op ## _check_overflow_wrong_size(); \
10227 + } \
10228 + __ret; \
10229 + })
10230 +
10231 /*
10232 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10233 * Since this is generally used to protect other memory information, we
10234 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10235 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10236 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10237
10238 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10239 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10240 +
10241 #define __add(ptr, inc, lock) \
10242 ({ \
10243 __typeof__ (*(ptr)) __ret = (inc); \
10244 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10245 index 6b7ee5f..9d664b3 100644
10246 --- a/arch/x86/include/asm/cpufeature.h
10247 +++ b/arch/x86/include/asm/cpufeature.h
10248 @@ -202,13 +202,14 @@
10249 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10250 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10251 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10252 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10253 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10254 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10255 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10256 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10257 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10258 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10259 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10260 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10261
10262 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10263
10264 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10265 ".section .discard,\"aw\",@progbits\n"
10266 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10267 ".previous\n"
10268 - ".section .altinstr_replacement,\"ax\"\n"
10269 + ".section .altinstr_replacement,\"a\"\n"
10270 "3: movb $1,%0\n"
10271 "4:\n"
10272 ".previous\n"
10273 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10274 index 8bf1c06..f723dfd 100644
10275 --- a/arch/x86/include/asm/desc.h
10276 +++ b/arch/x86/include/asm/desc.h
10277 @@ -4,6 +4,7 @@
10278 #include <asm/desc_defs.h>
10279 #include <asm/ldt.h>
10280 #include <asm/mmu.h>
10281 +#include <asm/pgtable.h>
10282
10283 #include <linux/smp.h>
10284 #include <linux/percpu.h>
10285 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10286
10287 desc->type = (info->read_exec_only ^ 1) << 1;
10288 desc->type |= info->contents << 2;
10289 + desc->type |= info->seg_not_present ^ 1;
10290
10291 desc->s = 1;
10292 desc->dpl = 0x3;
10293 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10294 }
10295
10296 extern struct desc_ptr idt_descr;
10297 -extern gate_desc idt_table[];
10298 extern struct desc_ptr nmi_idt_descr;
10299 -extern gate_desc nmi_idt_table[];
10300 -
10301 -struct gdt_page {
10302 - struct desc_struct gdt[GDT_ENTRIES];
10303 -} __attribute__((aligned(PAGE_SIZE)));
10304 -
10305 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10306 +extern gate_desc idt_table[256];
10307 +extern gate_desc nmi_idt_table[256];
10308
10309 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10310 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10311 {
10312 - return per_cpu(gdt_page, cpu).gdt;
10313 + return cpu_gdt_table[cpu];
10314 }
10315
10316 #ifdef CONFIG_X86_64
10317 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10318 unsigned long base, unsigned dpl, unsigned flags,
10319 unsigned short seg)
10320 {
10321 - gate->a = (seg << 16) | (base & 0xffff);
10322 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10323 + gate->gate.offset_low = base;
10324 + gate->gate.seg = seg;
10325 + gate->gate.reserved = 0;
10326 + gate->gate.type = type;
10327 + gate->gate.s = 0;
10328 + gate->gate.dpl = dpl;
10329 + gate->gate.p = 1;
10330 + gate->gate.offset_high = base >> 16;
10331 }
10332
10333 #endif
10334 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10335
10336 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10337 {
10338 + pax_open_kernel();
10339 memcpy(&idt[entry], gate, sizeof(*gate));
10340 + pax_close_kernel();
10341 }
10342
10343 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10344 {
10345 + pax_open_kernel();
10346 memcpy(&ldt[entry], desc, 8);
10347 + pax_close_kernel();
10348 }
10349
10350 static inline void
10351 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10352 default: size = sizeof(*gdt); break;
10353 }
10354
10355 + pax_open_kernel();
10356 memcpy(&gdt[entry], desc, size);
10357 + pax_close_kernel();
10358 }
10359
10360 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10361 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10362
10363 static inline void native_load_tr_desc(void)
10364 {
10365 + pax_open_kernel();
10366 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10367 + pax_close_kernel();
10368 }
10369
10370 static inline void native_load_gdt(const struct desc_ptr *dtr)
10371 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10372 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10373 unsigned int i;
10374
10375 + pax_open_kernel();
10376 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10377 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10378 + pax_close_kernel();
10379 }
10380
10381 #define _LDT_empty(info) \
10382 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10383 }
10384
10385 #ifdef CONFIG_X86_64
10386 -static inline void set_nmi_gate(int gate, void *addr)
10387 +static inline void set_nmi_gate(int gate, const void *addr)
10388 {
10389 gate_desc s;
10390
10391 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10392 }
10393 #endif
10394
10395 -static inline void _set_gate(int gate, unsigned type, void *addr,
10396 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10397 unsigned dpl, unsigned ist, unsigned seg)
10398 {
10399 gate_desc s;
10400 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10401 * Pentium F0 0F bugfix can have resulted in the mapped
10402 * IDT being write-protected.
10403 */
10404 -static inline void set_intr_gate(unsigned int n, void *addr)
10405 +static inline void set_intr_gate(unsigned int n, const void *addr)
10406 {
10407 BUG_ON((unsigned)n > 0xFF);
10408 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10409 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10410 /*
10411 * This routine sets up an interrupt gate at directory privilege level 3.
10412 */
10413 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10414 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10415 {
10416 BUG_ON((unsigned)n > 0xFF);
10417 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10418 }
10419
10420 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10421 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10422 {
10423 BUG_ON((unsigned)n > 0xFF);
10424 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10425 }
10426
10427 -static inline void set_trap_gate(unsigned int n, void *addr)
10428 +static inline void set_trap_gate(unsigned int n, const void *addr)
10429 {
10430 BUG_ON((unsigned)n > 0xFF);
10431 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10432 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10433 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10437 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10438 }
10439
10440 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10441 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10442 {
10443 BUG_ON((unsigned)n > 0xFF);
10444 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10445 }
10446
10447 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10448 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10449 {
10450 BUG_ON((unsigned)n > 0xFF);
10451 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10452 }
10453
10454 +#ifdef CONFIG_X86_32
10455 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10456 +{
10457 + struct desc_struct d;
10458 +
10459 + if (likely(limit))
10460 + limit = (limit - 1UL) >> PAGE_SHIFT;
10461 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10462 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10463 +}
10464 +#endif
10465 +
10466 #endif /* _ASM_X86_DESC_H */
10467 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10468 index 278441f..b95a174 100644
10469 --- a/arch/x86/include/asm/desc_defs.h
10470 +++ b/arch/x86/include/asm/desc_defs.h
10471 @@ -31,6 +31,12 @@ struct desc_struct {
10472 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10473 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10474 };
10475 + struct {
10476 + u16 offset_low;
10477 + u16 seg;
10478 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10479 + unsigned offset_high: 16;
10480 + } gate;
10481 };
10482 } __attribute__((packed));
10483
10484 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10485 index 3778256..c5d4fce 100644
10486 --- a/arch/x86/include/asm/e820.h
10487 +++ b/arch/x86/include/asm/e820.h
10488 @@ -69,7 +69,7 @@ struct e820map {
10489 #define ISA_START_ADDRESS 0xa0000
10490 #define ISA_END_ADDRESS 0x100000
10491
10492 -#define BIOS_BEGIN 0x000a0000
10493 +#define BIOS_BEGIN 0x000c0000
10494 #define BIOS_END 0x00100000
10495
10496 #define BIOS_ROM_BASE 0xffe00000
10497 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10498 index 5939f44..f8845f6 100644
10499 --- a/arch/x86/include/asm/elf.h
10500 +++ b/arch/x86/include/asm/elf.h
10501 @@ -243,7 +243,25 @@ extern int force_personality32;
10502 the loader. We need to make sure that it is out of the way of the program
10503 that it will "exec", and that there is sufficient room for the brk. */
10504
10505 +#ifdef CONFIG_PAX_SEGMEXEC
10506 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10507 +#else
10508 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10509 +#endif
10510 +
10511 +#ifdef CONFIG_PAX_ASLR
10512 +#ifdef CONFIG_X86_32
10513 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10514 +
10515 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10516 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10517 +#else
10518 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10519 +
10520 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10521 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10522 +#endif
10523 +#endif
10524
10525 /* This yields a mask that user programs can use to figure out what
10526 instruction set this CPU supports. This could be done in user space,
10527 @@ -296,16 +314,12 @@ do { \
10528
10529 #define ARCH_DLINFO \
10530 do { \
10531 - if (vdso_enabled) \
10532 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10533 - (unsigned long)current->mm->context.vdso); \
10534 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10535 } while (0)
10536
10537 #define ARCH_DLINFO_X32 \
10538 do { \
10539 - if (vdso_enabled) \
10540 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10541 - (unsigned long)current->mm->context.vdso); \
10542 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10543 } while (0)
10544
10545 #define AT_SYSINFO 32
10546 @@ -320,7 +334,7 @@ else \
10547
10548 #endif /* !CONFIG_X86_32 */
10549
10550 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10551 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10552
10553 #define VDSO_ENTRY \
10554 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10555 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10556 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10557 #define compat_arch_setup_additional_pages syscall32_setup_pages
10558
10559 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10560 -#define arch_randomize_brk arch_randomize_brk
10561 -
10562 /*
10563 * True on X86_32 or when emulating IA32 on X86_64
10564 */
10565 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10566 index 75ce3f4..882e801 100644
10567 --- a/arch/x86/include/asm/emergency-restart.h
10568 +++ b/arch/x86/include/asm/emergency-restart.h
10569 @@ -13,6 +13,6 @@ enum reboot_type {
10570
10571 extern enum reboot_type reboot_type;
10572
10573 -extern void machine_emergency_restart(void);
10574 +extern void machine_emergency_restart(void) __noreturn;
10575
10576 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10577 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10578 index 75f4c6d..ee3eb8f 100644
10579 --- a/arch/x86/include/asm/fpu-internal.h
10580 +++ b/arch/x86/include/asm/fpu-internal.h
10581 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10582 {
10583 int err;
10584
10585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10586 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10587 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10588 +#endif
10589 +
10590 /* See comment in fxsave() below. */
10591 #ifdef CONFIG_AS_FXSAVEQ
10592 asm volatile("1: fxrstorq %[fx]\n\t"
10593 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10594 {
10595 int err;
10596
10597 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10598 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10599 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10600 +#endif
10601 +
10602 /*
10603 * Clear the bytes not touched by the fxsave and reserved
10604 * for the SW usage.
10605 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10606 "emms\n\t" /* clear stack tags */
10607 "fildl %P[addr]", /* set F?P to defined value */
10608 X86_FEATURE_FXSAVE_LEAK,
10609 - [addr] "m" (tsk->thread.fpu.has_fpu));
10610 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10611
10612 return fpu_restore_checking(&tsk->thread.fpu);
10613 }
10614 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10615 index 71ecbcb..bac10b7 100644
10616 --- a/arch/x86/include/asm/futex.h
10617 +++ b/arch/x86/include/asm/futex.h
10618 @@ -11,16 +11,18 @@
10619 #include <asm/processor.h>
10620
10621 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10622 + typecheck(u32 __user *, uaddr); \
10623 asm volatile("1:\t" insn "\n" \
10624 "2:\t.section .fixup,\"ax\"\n" \
10625 "3:\tmov\t%3, %1\n" \
10626 "\tjmp\t2b\n" \
10627 "\t.previous\n" \
10628 _ASM_EXTABLE(1b, 3b) \
10629 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10630 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10631 : "i" (-EFAULT), "0" (oparg), "1" (0))
10632
10633 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10634 + typecheck(u32 __user *, uaddr); \
10635 asm volatile("1:\tmovl %2, %0\n" \
10636 "\tmovl\t%0, %3\n" \
10637 "\t" insn "\n" \
10638 @@ -33,7 +35,7 @@
10639 _ASM_EXTABLE(1b, 4b) \
10640 _ASM_EXTABLE(2b, 4b) \
10641 : "=&a" (oldval), "=&r" (ret), \
10642 - "+m" (*uaddr), "=&r" (tem) \
10643 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10644 : "r" (oparg), "i" (-EFAULT), "1" (0))
10645
10646 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10647 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10648
10649 switch (op) {
10650 case FUTEX_OP_SET:
10651 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10652 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10653 break;
10654 case FUTEX_OP_ADD:
10655 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10656 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10657 uaddr, oparg);
10658 break;
10659 case FUTEX_OP_OR:
10660 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10661 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10662 return -EFAULT;
10663
10664 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10665 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10666 "2:\t.section .fixup, \"ax\"\n"
10667 "3:\tmov %3, %0\n"
10668 "\tjmp 2b\n"
10669 "\t.previous\n"
10670 _ASM_EXTABLE(1b, 3b)
10671 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10672 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10673 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10674 : "memory"
10675 );
10676 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10677 index eb92a6e..b98b2f4 100644
10678 --- a/arch/x86/include/asm/hw_irq.h
10679 +++ b/arch/x86/include/asm/hw_irq.h
10680 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10681 extern void enable_IO_APIC(void);
10682
10683 /* Statistics */
10684 -extern atomic_t irq_err_count;
10685 -extern atomic_t irq_mis_count;
10686 +extern atomic_unchecked_t irq_err_count;
10687 +extern atomic_unchecked_t irq_mis_count;
10688
10689 /* EISA */
10690 extern void eisa_set_level_irq(unsigned int irq);
10691 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10692 index d8e8eef..99f81ae 100644
10693 --- a/arch/x86/include/asm/io.h
10694 +++ b/arch/x86/include/asm/io.h
10695 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10696
10697 #include <linux/vmalloc.h>
10698
10699 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10700 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10701 +{
10702 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10703 +}
10704 +
10705 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10706 +{
10707 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10708 +}
10709 +
10710 /*
10711 * Convert a virtual cached pointer to an uncached pointer
10712 */
10713 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10714 index bba3cf8..06bc8da 100644
10715 --- a/arch/x86/include/asm/irqflags.h
10716 +++ b/arch/x86/include/asm/irqflags.h
10717 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10718 sti; \
10719 sysexit
10720
10721 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10722 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10723 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10724 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10725 +
10726 #else
10727 #define INTERRUPT_RETURN iret
10728 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10729 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10730 index 5478825..839e88c 100644
10731 --- a/arch/x86/include/asm/kprobes.h
10732 +++ b/arch/x86/include/asm/kprobes.h
10733 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10734 #define RELATIVEJUMP_SIZE 5
10735 #define RELATIVECALL_OPCODE 0xe8
10736 #define RELATIVE_ADDR_SIZE 4
10737 -#define MAX_STACK_SIZE 64
10738 -#define MIN_STACK_SIZE(ADDR) \
10739 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10740 - THREAD_SIZE - (unsigned long)(ADDR))) \
10741 - ? (MAX_STACK_SIZE) \
10742 - : (((unsigned long)current_thread_info()) + \
10743 - THREAD_SIZE - (unsigned long)(ADDR)))
10744 +#define MAX_STACK_SIZE 64UL
10745 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10746
10747 #define flush_insn_slot(p) do { } while (0)
10748
10749 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10750 index 09155d6..d2e6df9 100644
10751 --- a/arch/x86/include/asm/kvm_host.h
10752 +++ b/arch/x86/include/asm/kvm_host.h
10753 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10754 int (*check_intercept)(struct kvm_vcpu *vcpu,
10755 struct x86_instruction_info *info,
10756 enum x86_intercept_stage stage);
10757 -};
10758 +} __do_const;
10759
10760 struct kvm_arch_async_pf {
10761 u32 token;
10762 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10763 index c8bed0d..e5721fa 100644
10764 --- a/arch/x86/include/asm/local.h
10765 +++ b/arch/x86/include/asm/local.h
10766 @@ -17,26 +17,58 @@ typedef struct {
10767
10768 static inline void local_inc(local_t *l)
10769 {
10770 - asm volatile(_ASM_INC "%0"
10771 + asm volatile(_ASM_INC "%0\n"
10772 +
10773 +#ifdef CONFIG_PAX_REFCOUNT
10774 + "jno 0f\n"
10775 + _ASM_DEC "%0\n"
10776 + "int $4\n0:\n"
10777 + _ASM_EXTABLE(0b, 0b)
10778 +#endif
10779 +
10780 : "+m" (l->a.counter));
10781 }
10782
10783 static inline void local_dec(local_t *l)
10784 {
10785 - asm volatile(_ASM_DEC "%0"
10786 + asm volatile(_ASM_DEC "%0\n"
10787 +
10788 +#ifdef CONFIG_PAX_REFCOUNT
10789 + "jno 0f\n"
10790 + _ASM_INC "%0\n"
10791 + "int $4\n0:\n"
10792 + _ASM_EXTABLE(0b, 0b)
10793 +#endif
10794 +
10795 : "+m" (l->a.counter));
10796 }
10797
10798 static inline void local_add(long i, local_t *l)
10799 {
10800 - asm volatile(_ASM_ADD "%1,%0"
10801 + asm volatile(_ASM_ADD "%1,%0\n"
10802 +
10803 +#ifdef CONFIG_PAX_REFCOUNT
10804 + "jno 0f\n"
10805 + _ASM_SUB "%1,%0\n"
10806 + "int $4\n0:\n"
10807 + _ASM_EXTABLE(0b, 0b)
10808 +#endif
10809 +
10810 : "+m" (l->a.counter)
10811 : "ir" (i));
10812 }
10813
10814 static inline void local_sub(long i, local_t *l)
10815 {
10816 - asm volatile(_ASM_SUB "%1,%0"
10817 + asm volatile(_ASM_SUB "%1,%0\n"
10818 +
10819 +#ifdef CONFIG_PAX_REFCOUNT
10820 + "jno 0f\n"
10821 + _ASM_ADD "%1,%0\n"
10822 + "int $4\n0:\n"
10823 + _ASM_EXTABLE(0b, 0b)
10824 +#endif
10825 +
10826 : "+m" (l->a.counter)
10827 : "ir" (i));
10828 }
10829 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10830 {
10831 unsigned char c;
10832
10833 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10834 + asm volatile(_ASM_SUB "%2,%0\n"
10835 +
10836 +#ifdef CONFIG_PAX_REFCOUNT
10837 + "jno 0f\n"
10838 + _ASM_ADD "%2,%0\n"
10839 + "int $4\n0:\n"
10840 + _ASM_EXTABLE(0b, 0b)
10841 +#endif
10842 +
10843 + "sete %1\n"
10844 : "+m" (l->a.counter), "=qm" (c)
10845 : "ir" (i) : "memory");
10846 return c;
10847 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10848 {
10849 unsigned char c;
10850
10851 - asm volatile(_ASM_DEC "%0; sete %1"
10852 + asm volatile(_ASM_DEC "%0\n"
10853 +
10854 +#ifdef CONFIG_PAX_REFCOUNT
10855 + "jno 0f\n"
10856 + _ASM_INC "%0\n"
10857 + "int $4\n0:\n"
10858 + _ASM_EXTABLE(0b, 0b)
10859 +#endif
10860 +
10861 + "sete %1\n"
10862 : "+m" (l->a.counter), "=qm" (c)
10863 : : "memory");
10864 return c != 0;
10865 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10866 {
10867 unsigned char c;
10868
10869 - asm volatile(_ASM_INC "%0; sete %1"
10870 + asm volatile(_ASM_INC "%0\n"
10871 +
10872 +#ifdef CONFIG_PAX_REFCOUNT
10873 + "jno 0f\n"
10874 + _ASM_DEC "%0\n"
10875 + "int $4\n0:\n"
10876 + _ASM_EXTABLE(0b, 0b)
10877 +#endif
10878 +
10879 + "sete %1\n"
10880 : "+m" (l->a.counter), "=qm" (c)
10881 : : "memory");
10882 return c != 0;
10883 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10884 {
10885 unsigned char c;
10886
10887 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10888 + asm volatile(_ASM_ADD "%2,%0\n"
10889 +
10890 +#ifdef CONFIG_PAX_REFCOUNT
10891 + "jno 0f\n"
10892 + _ASM_SUB "%2,%0\n"
10893 + "int $4\n0:\n"
10894 + _ASM_EXTABLE(0b, 0b)
10895 +#endif
10896 +
10897 + "sets %1\n"
10898 : "+m" (l->a.counter), "=qm" (c)
10899 : "ir" (i) : "memory");
10900 return c;
10901 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10902 #endif
10903 /* Modern 486+ processor */
10904 __i = i;
10905 - asm volatile(_ASM_XADD "%0, %1;"
10906 + asm volatile(_ASM_XADD "%0, %1\n"
10907 +
10908 +#ifdef CONFIG_PAX_REFCOUNT
10909 + "jno 0f\n"
10910 + _ASM_MOV "%0,%1\n"
10911 + "int $4\n0:\n"
10912 + _ASM_EXTABLE(0b, 0b)
10913 +#endif
10914 +
10915 : "+r" (i), "+m" (l->a.counter)
10916 : : "memory");
10917 return i + __i;
10918 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10919 index 593e51d..fa69c9a 100644
10920 --- a/arch/x86/include/asm/mman.h
10921 +++ b/arch/x86/include/asm/mman.h
10922 @@ -5,4 +5,14 @@
10923
10924 #include <asm-generic/mman.h>
10925
10926 +#ifdef __KERNEL__
10927 +#ifndef __ASSEMBLY__
10928 +#ifdef CONFIG_X86_32
10929 +#define arch_mmap_check i386_mmap_check
10930 +int i386_mmap_check(unsigned long addr, unsigned long len,
10931 + unsigned long flags);
10932 +#endif
10933 +#endif
10934 +#endif
10935 +
10936 #endif /* _ASM_X86_MMAN_H */
10937 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10938 index 5f55e69..e20bfb1 100644
10939 --- a/arch/x86/include/asm/mmu.h
10940 +++ b/arch/x86/include/asm/mmu.h
10941 @@ -9,7 +9,7 @@
10942 * we put the segment information here.
10943 */
10944 typedef struct {
10945 - void *ldt;
10946 + struct desc_struct *ldt;
10947 int size;
10948
10949 #ifdef CONFIG_X86_64
10950 @@ -18,7 +18,19 @@ typedef struct {
10951 #endif
10952
10953 struct mutex lock;
10954 - void *vdso;
10955 + unsigned long vdso;
10956 +
10957 +#ifdef CONFIG_X86_32
10958 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10959 + unsigned long user_cs_base;
10960 + unsigned long user_cs_limit;
10961 +
10962 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10963 + cpumask_t cpu_user_cs_mask;
10964 +#endif
10965 +
10966 +#endif
10967 +#endif
10968 } mm_context_t;
10969
10970 #ifdef CONFIG_SMP
10971 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10972 index cdbf367..adb37ac 100644
10973 --- a/arch/x86/include/asm/mmu_context.h
10974 +++ b/arch/x86/include/asm/mmu_context.h
10975 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10976
10977 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10978 {
10979 +
10980 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10981 + unsigned int i;
10982 + pgd_t *pgd;
10983 +
10984 + pax_open_kernel();
10985 + pgd = get_cpu_pgd(smp_processor_id());
10986 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10987 + set_pgd_batched(pgd+i, native_make_pgd(0));
10988 + pax_close_kernel();
10989 +#endif
10990 +
10991 #ifdef CONFIG_SMP
10992 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10993 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10994 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10995 struct task_struct *tsk)
10996 {
10997 unsigned cpu = smp_processor_id();
10998 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10999 + int tlbstate = TLBSTATE_OK;
11000 +#endif
11001
11002 if (likely(prev != next)) {
11003 #ifdef CONFIG_SMP
11004 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11005 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11006 +#endif
11007 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11008 this_cpu_write(cpu_tlbstate.active_mm, next);
11009 #endif
11010 cpumask_set_cpu(cpu, mm_cpumask(next));
11011
11012 /* Re-load page tables */
11013 +#ifdef CONFIG_PAX_PER_CPU_PGD
11014 + pax_open_kernel();
11015 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11016 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11017 + pax_close_kernel();
11018 + load_cr3(get_cpu_pgd(cpu));
11019 +#else
11020 load_cr3(next->pgd);
11021 +#endif
11022
11023 /* stop flush ipis for the previous mm */
11024 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11025 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11026 */
11027 if (unlikely(prev->context.ldt != next->context.ldt))
11028 load_LDT_nolock(&next->context);
11029 - }
11030 +
11031 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11032 + if (!(__supported_pte_mask & _PAGE_NX)) {
11033 + smp_mb__before_clear_bit();
11034 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11035 + smp_mb__after_clear_bit();
11036 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11037 + }
11038 +#endif
11039 +
11040 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11041 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11042 + prev->context.user_cs_limit != next->context.user_cs_limit))
11043 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11044 #ifdef CONFIG_SMP
11045 + else if (unlikely(tlbstate != TLBSTATE_OK))
11046 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11047 +#endif
11048 +#endif
11049 +
11050 + }
11051 else {
11052 +
11053 +#ifdef CONFIG_PAX_PER_CPU_PGD
11054 + pax_open_kernel();
11055 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11056 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11057 + pax_close_kernel();
11058 + load_cr3(get_cpu_pgd(cpu));
11059 +#endif
11060 +
11061 +#ifdef CONFIG_SMP
11062 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11063 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11064
11065 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11066 * tlb flush IPI delivery. We must reload CR3
11067 * to make sure to use no freed page tables.
11068 */
11069 +
11070 +#ifndef CONFIG_PAX_PER_CPU_PGD
11071 load_cr3(next->pgd);
11072 +#endif
11073 +
11074 load_LDT_nolock(&next->context);
11075 +
11076 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11077 + if (!(__supported_pte_mask & _PAGE_NX))
11078 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11079 +#endif
11080 +
11081 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11082 +#ifdef CONFIG_PAX_PAGEEXEC
11083 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11084 +#endif
11085 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11086 +#endif
11087 +
11088 }
11089 +#endif
11090 }
11091 -#endif
11092 }
11093
11094 #define activate_mm(prev, next) \
11095 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11096 index 9eae775..c914fea 100644
11097 --- a/arch/x86/include/asm/module.h
11098 +++ b/arch/x86/include/asm/module.h
11099 @@ -5,6 +5,7 @@
11100
11101 #ifdef CONFIG_X86_64
11102 /* X86_64 does not define MODULE_PROC_FAMILY */
11103 +#define MODULE_PROC_FAMILY ""
11104 #elif defined CONFIG_M386
11105 #define MODULE_PROC_FAMILY "386 "
11106 #elif defined CONFIG_M486
11107 @@ -59,8 +60,20 @@
11108 #error unknown processor family
11109 #endif
11110
11111 -#ifdef CONFIG_X86_32
11112 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11113 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11114 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11115 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11116 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11117 +#else
11118 +#define MODULE_PAX_KERNEXEC ""
11119 #endif
11120
11121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11122 +#define MODULE_PAX_UDEREF "UDEREF "
11123 +#else
11124 +#define MODULE_PAX_UDEREF ""
11125 +#endif
11126 +
11127 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11128 +
11129 #endif /* _ASM_X86_MODULE_H */
11130 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11131 index 320f7bb..e89f8f8 100644
11132 --- a/arch/x86/include/asm/page_64_types.h
11133 +++ b/arch/x86/include/asm/page_64_types.h
11134 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11135
11136 /* duplicated to the one in bootmem.h */
11137 extern unsigned long max_pfn;
11138 -extern unsigned long phys_base;
11139 +extern const unsigned long phys_base;
11140
11141 extern unsigned long __phys_addr(unsigned long);
11142 #define __phys_reloc_hide(x) (x)
11143 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11144 index a0facf3..c017b15 100644
11145 --- a/arch/x86/include/asm/paravirt.h
11146 +++ b/arch/x86/include/asm/paravirt.h
11147 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11148 val);
11149 }
11150
11151 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11152 +{
11153 + pgdval_t val = native_pgd_val(pgd);
11154 +
11155 + if (sizeof(pgdval_t) > sizeof(long))
11156 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11157 + val, (u64)val >> 32);
11158 + else
11159 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11160 + val);
11161 +}
11162 +
11163 static inline void pgd_clear(pgd_t *pgdp)
11164 {
11165 set_pgd(pgdp, __pgd(0));
11166 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11167 pv_mmu_ops.set_fixmap(idx, phys, flags);
11168 }
11169
11170 +#ifdef CONFIG_PAX_KERNEXEC
11171 +static inline unsigned long pax_open_kernel(void)
11172 +{
11173 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11174 +}
11175 +
11176 +static inline unsigned long pax_close_kernel(void)
11177 +{
11178 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11179 +}
11180 +#else
11181 +static inline unsigned long pax_open_kernel(void) { return 0; }
11182 +static inline unsigned long pax_close_kernel(void) { return 0; }
11183 +#endif
11184 +
11185 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11186
11187 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11188 @@ -929,7 +956,7 @@ extern void default_banner(void);
11189
11190 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11191 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11192 -#define PARA_INDIRECT(addr) *%cs:addr
11193 +#define PARA_INDIRECT(addr) *%ss:addr
11194 #endif
11195
11196 #define INTERRUPT_RETURN \
11197 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11198 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11199 CLBR_NONE, \
11200 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11201 +
11202 +#define GET_CR0_INTO_RDI \
11203 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11204 + mov %rax,%rdi
11205 +
11206 +#define SET_RDI_INTO_CR0 \
11207 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11208 +
11209 +#define GET_CR3_INTO_RDI \
11210 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11211 + mov %rax,%rdi
11212 +
11213 +#define SET_RDI_INTO_CR3 \
11214 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11215 +
11216 #endif /* CONFIG_X86_32 */
11217
11218 #endif /* __ASSEMBLY__ */
11219 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11220 index 142236e..6a6b4a6 100644
11221 --- a/arch/x86/include/asm/paravirt_types.h
11222 +++ b/arch/x86/include/asm/paravirt_types.h
11223 @@ -84,20 +84,20 @@ struct pv_init_ops {
11224 */
11225 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11226 unsigned long addr, unsigned len);
11227 -};
11228 +} __no_const;
11229
11230
11231 struct pv_lazy_ops {
11232 /* Set deferred update mode, used for batching operations. */
11233 void (*enter)(void);
11234 void (*leave)(void);
11235 -};
11236 +} __no_const;
11237
11238 struct pv_time_ops {
11239 unsigned long long (*sched_clock)(void);
11240 unsigned long long (*steal_clock)(int cpu);
11241 unsigned long (*get_tsc_khz)(void);
11242 -};
11243 +} __no_const;
11244
11245 struct pv_cpu_ops {
11246 /* hooks for various privileged instructions */
11247 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11248
11249 void (*start_context_switch)(struct task_struct *prev);
11250 void (*end_context_switch)(struct task_struct *next);
11251 -};
11252 +} __no_const;
11253
11254 struct pv_irq_ops {
11255 /*
11256 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11257 unsigned long start_eip,
11258 unsigned long start_esp);
11259 #endif
11260 -};
11261 +} __no_const;
11262
11263 struct pv_mmu_ops {
11264 unsigned long (*read_cr2)(void);
11265 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11266 struct paravirt_callee_save make_pud;
11267
11268 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11269 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11270 #endif /* PAGETABLE_LEVELS == 4 */
11271 #endif /* PAGETABLE_LEVELS >= 3 */
11272
11273 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11274 an mfn. We can tell which is which from the index. */
11275 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11276 phys_addr_t phys, pgprot_t flags);
11277 +
11278 +#ifdef CONFIG_PAX_KERNEXEC
11279 + unsigned long (*pax_open_kernel)(void);
11280 + unsigned long (*pax_close_kernel)(void);
11281 +#endif
11282 +
11283 };
11284
11285 struct arch_spinlock;
11286 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11287 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11288 int (*spin_trylock)(struct arch_spinlock *lock);
11289 void (*spin_unlock)(struct arch_spinlock *lock);
11290 -};
11291 +} __no_const;
11292
11293 /* This contains all the paravirt structures: we get a convenient
11294 * number for each function using the offset which we use to indicate
11295 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11296 index b4389a4..7024269 100644
11297 --- a/arch/x86/include/asm/pgalloc.h
11298 +++ b/arch/x86/include/asm/pgalloc.h
11299 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11300 pmd_t *pmd, pte_t *pte)
11301 {
11302 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11303 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11304 +}
11305 +
11306 +static inline void pmd_populate_user(struct mm_struct *mm,
11307 + pmd_t *pmd, pte_t *pte)
11308 +{
11309 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11310 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11311 }
11312
11313 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11314
11315 #ifdef CONFIG_X86_PAE
11316 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11317 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11318 +{
11319 + pud_populate(mm, pudp, pmd);
11320 +}
11321 #else /* !CONFIG_X86_PAE */
11322 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11323 {
11324 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11325 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11326 }
11327 +
11328 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11329 +{
11330 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11331 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11332 +}
11333 #endif /* CONFIG_X86_PAE */
11334
11335 #if PAGETABLE_LEVELS > 3
11336 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11337 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11338 }
11339
11340 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11341 +{
11342 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11343 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11344 +}
11345 +
11346 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11347 {
11348 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11349 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11350 index f2b489c..4f7e2e5 100644
11351 --- a/arch/x86/include/asm/pgtable-2level.h
11352 +++ b/arch/x86/include/asm/pgtable-2level.h
11353 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11354
11355 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11356 {
11357 + pax_open_kernel();
11358 *pmdp = pmd;
11359 + pax_close_kernel();
11360 }
11361
11362 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11363 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11364 index 4cc9f2b..5fd9226 100644
11365 --- a/arch/x86/include/asm/pgtable-3level.h
11366 +++ b/arch/x86/include/asm/pgtable-3level.h
11367 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11368
11369 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11370 {
11371 + pax_open_kernel();
11372 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11373 + pax_close_kernel();
11374 }
11375
11376 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11377 {
11378 + pax_open_kernel();
11379 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11380 + pax_close_kernel();
11381 }
11382
11383 /*
11384 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11385 index c3520d7..cf742ef 100644
11386 --- a/arch/x86/include/asm/pgtable.h
11387 +++ b/arch/x86/include/asm/pgtable.h
11388 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11389
11390 #ifndef __PAGETABLE_PUD_FOLDED
11391 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11392 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11393 #define pgd_clear(pgd) native_pgd_clear(pgd)
11394 #endif
11395
11396 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11397
11398 #define arch_end_context_switch(prev) do {} while(0)
11399
11400 +#define pax_open_kernel() native_pax_open_kernel()
11401 +#define pax_close_kernel() native_pax_close_kernel()
11402 #endif /* CONFIG_PARAVIRT */
11403
11404 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11405 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11406 +
11407 +#ifdef CONFIG_PAX_KERNEXEC
11408 +static inline unsigned long native_pax_open_kernel(void)
11409 +{
11410 + unsigned long cr0;
11411 +
11412 + preempt_disable();
11413 + barrier();
11414 + cr0 = read_cr0() ^ X86_CR0_WP;
11415 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11416 + write_cr0(cr0);
11417 + return cr0 ^ X86_CR0_WP;
11418 +}
11419 +
11420 +static inline unsigned long native_pax_close_kernel(void)
11421 +{
11422 + unsigned long cr0;
11423 +
11424 + cr0 = read_cr0() ^ X86_CR0_WP;
11425 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11426 + write_cr0(cr0);
11427 + barrier();
11428 + preempt_enable_no_resched();
11429 + return cr0 ^ X86_CR0_WP;
11430 +}
11431 +#else
11432 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11433 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11434 +#endif
11435 +
11436 /*
11437 * The following only work if pte_present() is true.
11438 * Undefined behaviour if not..
11439 */
11440 +static inline int pte_user(pte_t pte)
11441 +{
11442 + return pte_val(pte) & _PAGE_USER;
11443 +}
11444 +
11445 static inline int pte_dirty(pte_t pte)
11446 {
11447 return pte_flags(pte) & _PAGE_DIRTY;
11448 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11449 return pte_clear_flags(pte, _PAGE_RW);
11450 }
11451
11452 +static inline pte_t pte_mkread(pte_t pte)
11453 +{
11454 + return __pte(pte_val(pte) | _PAGE_USER);
11455 +}
11456 +
11457 static inline pte_t pte_mkexec(pte_t pte)
11458 {
11459 - return pte_clear_flags(pte, _PAGE_NX);
11460 +#ifdef CONFIG_X86_PAE
11461 + if (__supported_pte_mask & _PAGE_NX)
11462 + return pte_clear_flags(pte, _PAGE_NX);
11463 + else
11464 +#endif
11465 + return pte_set_flags(pte, _PAGE_USER);
11466 +}
11467 +
11468 +static inline pte_t pte_exprotect(pte_t pte)
11469 +{
11470 +#ifdef CONFIG_X86_PAE
11471 + if (__supported_pte_mask & _PAGE_NX)
11472 + return pte_set_flags(pte, _PAGE_NX);
11473 + else
11474 +#endif
11475 + return pte_clear_flags(pte, _PAGE_USER);
11476 }
11477
11478 static inline pte_t pte_mkdirty(pte_t pte)
11479 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11480 #endif
11481
11482 #ifndef __ASSEMBLY__
11483 +
11484 +#ifdef CONFIG_PAX_PER_CPU_PGD
11485 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11486 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11487 +{
11488 + return cpu_pgd[cpu];
11489 +}
11490 +#endif
11491 +
11492 #include <linux/mm_types.h>
11493
11494 static inline int pte_none(pte_t pte)
11495 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11496
11497 static inline int pgd_bad(pgd_t pgd)
11498 {
11499 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11500 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11501 }
11502
11503 static inline int pgd_none(pgd_t pgd)
11504 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11505 * pgd_offset() returns a (pgd_t *)
11506 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11507 */
11508 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11509 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11510 +
11511 +#ifdef CONFIG_PAX_PER_CPU_PGD
11512 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11513 +#endif
11514 +
11515 /*
11516 * a shortcut which implies the use of the kernel's pgd, instead
11517 * of a process's
11518 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11519 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11520 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11521
11522 +#ifdef CONFIG_X86_32
11523 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11524 +#else
11525 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11526 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11527 +
11528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11529 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11530 +#else
11531 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11532 +#endif
11533 +
11534 +#endif
11535 +
11536 #ifndef __ASSEMBLY__
11537
11538 extern int direct_gbpages;
11539 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11540 * dst and src can be on the same page, but the range must not overlap,
11541 * and must not cross a page boundary.
11542 */
11543 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11544 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11545 {
11546 - memcpy(dst, src, count * sizeof(pgd_t));
11547 + pax_open_kernel();
11548 + while (count--)
11549 + *dst++ = *src++;
11550 + pax_close_kernel();
11551 }
11552
11553 +#ifdef CONFIG_PAX_PER_CPU_PGD
11554 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11555 +#endif
11556 +
11557 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11558 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11559 +#else
11560 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11561 +#endif
11562
11563 #include <asm-generic/pgtable.h>
11564 #endif /* __ASSEMBLY__ */
11565 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11566 index 0c92113..34a77c6 100644
11567 --- a/arch/x86/include/asm/pgtable_32.h
11568 +++ b/arch/x86/include/asm/pgtable_32.h
11569 @@ -25,9 +25,6 @@
11570 struct mm_struct;
11571 struct vm_area_struct;
11572
11573 -extern pgd_t swapper_pg_dir[1024];
11574 -extern pgd_t initial_page_table[1024];
11575 -
11576 static inline void pgtable_cache_init(void) { }
11577 static inline void check_pgt_cache(void) { }
11578 void paging_init(void);
11579 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11580 # include <asm/pgtable-2level.h>
11581 #endif
11582
11583 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11584 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11585 +#ifdef CONFIG_X86_PAE
11586 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11587 +#endif
11588 +
11589 #if defined(CONFIG_HIGHPTE)
11590 #define pte_offset_map(dir, address) \
11591 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11592 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11593 /* Clear a kernel PTE and flush it from the TLB */
11594 #define kpte_clear_flush(ptep, vaddr) \
11595 do { \
11596 + pax_open_kernel(); \
11597 pte_clear(&init_mm, (vaddr), (ptep)); \
11598 + pax_close_kernel(); \
11599 __flush_tlb_one((vaddr)); \
11600 } while (0)
11601
11602 @@ -74,6 +79,9 @@ do { \
11603
11604 #endif /* !__ASSEMBLY__ */
11605
11606 +#define HAVE_ARCH_UNMAPPED_AREA
11607 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11608 +
11609 /*
11610 * kern_addr_valid() is (1) for FLATMEM and (0) for
11611 * SPARSEMEM and DISCONTIGMEM
11612 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11613 index ed5903b..c7fe163 100644
11614 --- a/arch/x86/include/asm/pgtable_32_types.h
11615 +++ b/arch/x86/include/asm/pgtable_32_types.h
11616 @@ -8,7 +8,7 @@
11617 */
11618 #ifdef CONFIG_X86_PAE
11619 # include <asm/pgtable-3level_types.h>
11620 -# define PMD_SIZE (1UL << PMD_SHIFT)
11621 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11622 # define PMD_MASK (~(PMD_SIZE - 1))
11623 #else
11624 # include <asm/pgtable-2level_types.h>
11625 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11626 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11627 #endif
11628
11629 +#ifdef CONFIG_PAX_KERNEXEC
11630 +#ifndef __ASSEMBLY__
11631 +extern unsigned char MODULES_EXEC_VADDR[];
11632 +extern unsigned char MODULES_EXEC_END[];
11633 +#endif
11634 +#include <asm/boot.h>
11635 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11636 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11637 +#else
11638 +#define ktla_ktva(addr) (addr)
11639 +#define ktva_ktla(addr) (addr)
11640 +#endif
11641 +
11642 #define MODULES_VADDR VMALLOC_START
11643 #define MODULES_END VMALLOC_END
11644 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11645 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11646 index 8251be0..4ea8b46 100644
11647 --- a/arch/x86/include/asm/pgtable_64.h
11648 +++ b/arch/x86/include/asm/pgtable_64.h
11649 @@ -16,10 +16,14 @@
11650
11651 extern pud_t level3_kernel_pgt[512];
11652 extern pud_t level3_ident_pgt[512];
11653 +extern pud_t level3_vmalloc_start_pgt[512];
11654 +extern pud_t level3_vmalloc_end_pgt[512];
11655 +extern pud_t level3_vmemmap_pgt[512];
11656 +extern pud_t level2_vmemmap_pgt[512];
11657 extern pmd_t level2_kernel_pgt[512];
11658 extern pmd_t level2_fixmap_pgt[512];
11659 -extern pmd_t level2_ident_pgt[512];
11660 -extern pgd_t init_level4_pgt[];
11661 +extern pmd_t level2_ident_pgt[512*2];
11662 +extern pgd_t init_level4_pgt[512];
11663
11664 #define swapper_pg_dir init_level4_pgt
11665
11666 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11667
11668 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11669 {
11670 + pax_open_kernel();
11671 *pmdp = pmd;
11672 + pax_close_kernel();
11673 }
11674
11675 static inline void native_pmd_clear(pmd_t *pmd)
11676 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11677
11678 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11679 {
11680 + pax_open_kernel();
11681 *pudp = pud;
11682 + pax_close_kernel();
11683 }
11684
11685 static inline void native_pud_clear(pud_t *pud)
11686 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11687
11688 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11689 {
11690 + pax_open_kernel();
11691 + *pgdp = pgd;
11692 + pax_close_kernel();
11693 +}
11694 +
11695 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11696 +{
11697 *pgdp = pgd;
11698 }
11699
11700 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11701 index 766ea16..5b96cb3 100644
11702 --- a/arch/x86/include/asm/pgtable_64_types.h
11703 +++ b/arch/x86/include/asm/pgtable_64_types.h
11704 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11705 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11706 #define MODULES_END _AC(0xffffffffff000000, UL)
11707 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11708 +#define MODULES_EXEC_VADDR MODULES_VADDR
11709 +#define MODULES_EXEC_END MODULES_END
11710 +
11711 +#define ktla_ktva(addr) (addr)
11712 +#define ktva_ktla(addr) (addr)
11713
11714 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11715 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11716 index 013286a..8b42f4f 100644
11717 --- a/arch/x86/include/asm/pgtable_types.h
11718 +++ b/arch/x86/include/asm/pgtable_types.h
11719 @@ -16,13 +16,12 @@
11720 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11721 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11722 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11723 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11724 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11725 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11726 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11727 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11728 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11729 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11730 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11731 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11732 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11733 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11734
11735 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11736 @@ -40,7 +39,6 @@
11737 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11738 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11739 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11740 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11741 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11742 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11743 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11744 @@ -57,8 +55,10 @@
11745
11746 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11747 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11748 -#else
11749 +#elif defined(CONFIG_KMEMCHECK)
11750 #define _PAGE_NX (_AT(pteval_t, 0))
11751 +#else
11752 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11753 #endif
11754
11755 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11756 @@ -96,6 +96,9 @@
11757 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11758 _PAGE_ACCESSED)
11759
11760 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11761 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11762 +
11763 #define __PAGE_KERNEL_EXEC \
11764 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11765 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11766 @@ -106,7 +109,7 @@
11767 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11768 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11769 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11770 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11771 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11772 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11773 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11774 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11775 @@ -168,8 +171,8 @@
11776 * bits are combined, this will alow user to access the high address mapped
11777 * VDSO in the presence of CONFIG_COMPAT_VDSO
11778 */
11779 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11780 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11781 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11782 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11783 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11784 #endif
11785
11786 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11787 {
11788 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11789 }
11790 +#endif
11791
11792 +#if PAGETABLE_LEVELS == 3
11793 +#include <asm-generic/pgtable-nopud.h>
11794 +#endif
11795 +
11796 +#if PAGETABLE_LEVELS == 2
11797 +#include <asm-generic/pgtable-nopmd.h>
11798 +#endif
11799 +
11800 +#ifndef __ASSEMBLY__
11801 #if PAGETABLE_LEVELS > 3
11802 typedef struct { pudval_t pud; } pud_t;
11803
11804 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11805 return pud.pud;
11806 }
11807 #else
11808 -#include <asm-generic/pgtable-nopud.h>
11809 -
11810 static inline pudval_t native_pud_val(pud_t pud)
11811 {
11812 return native_pgd_val(pud.pgd);
11813 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11814 return pmd.pmd;
11815 }
11816 #else
11817 -#include <asm-generic/pgtable-nopmd.h>
11818 -
11819 static inline pmdval_t native_pmd_val(pmd_t pmd)
11820 {
11821 return native_pgd_val(pmd.pud.pgd);
11822 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11823
11824 extern pteval_t __supported_pte_mask;
11825 extern void set_nx(void);
11826 -extern int nx_enabled;
11827
11828 #define pgprot_writecombine pgprot_writecombine
11829 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11830 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11831 index aea1d1d..680cf09 100644
11832 --- a/arch/x86/include/asm/processor-flags.h
11833 +++ b/arch/x86/include/asm/processor-flags.h
11834 @@ -65,6 +65,7 @@
11835 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11836 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11837 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11838 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11839
11840 /*
11841 * x86-64 Task Priority Register, CR8
11842 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11843 index d048cad..45e350f 100644
11844 --- a/arch/x86/include/asm/processor.h
11845 +++ b/arch/x86/include/asm/processor.h
11846 @@ -289,7 +289,7 @@ struct tss_struct {
11847
11848 } ____cacheline_aligned;
11849
11850 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11851 +extern struct tss_struct init_tss[NR_CPUS];
11852
11853 /*
11854 * Save the original ist values for checking stack pointers during debugging
11855 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11856 */
11857 #define TASK_SIZE PAGE_OFFSET
11858 #define TASK_SIZE_MAX TASK_SIZE
11859 +
11860 +#ifdef CONFIG_PAX_SEGMEXEC
11861 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11862 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11863 +#else
11864 #define STACK_TOP TASK_SIZE
11865 -#define STACK_TOP_MAX STACK_TOP
11866 +#endif
11867 +
11868 +#define STACK_TOP_MAX TASK_SIZE
11869
11870 #define INIT_THREAD { \
11871 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11872 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11873 .vm86_info = NULL, \
11874 .sysenter_cs = __KERNEL_CS, \
11875 .io_bitmap_ptr = NULL, \
11876 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11877 */
11878 #define INIT_TSS { \
11879 .x86_tss = { \
11880 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11881 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11882 .ss0 = __KERNEL_DS, \
11883 .ss1 = __KERNEL_CS, \
11884 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11885 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11886 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11887
11888 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11889 -#define KSTK_TOP(info) \
11890 -({ \
11891 - unsigned long *__ptr = (unsigned long *)(info); \
11892 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11893 -})
11894 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11895
11896 /*
11897 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11898 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11899 #define task_pt_regs(task) \
11900 ({ \
11901 struct pt_regs *__regs__; \
11902 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11903 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11904 __regs__ - 1; \
11905 })
11906
11907 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11908 /*
11909 * User space process size. 47bits minus one guard page.
11910 */
11911 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11912 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11913
11914 /* This decides where the kernel will search for a free chunk of vm
11915 * space during mmap's.
11916 */
11917 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11918 - 0xc0000000 : 0xFFFFe000)
11919 + 0xc0000000 : 0xFFFFf000)
11920
11921 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11922 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11923 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11924 #define STACK_TOP_MAX TASK_SIZE_MAX
11925
11926 #define INIT_THREAD { \
11927 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11928 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11929 }
11930
11931 #define INIT_TSS { \
11932 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11933 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11934 }
11935
11936 /*
11937 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11938 */
11939 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11940
11941 +#ifdef CONFIG_PAX_SEGMEXEC
11942 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11943 +#endif
11944 +
11945 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11946
11947 /* Get/set a process' ability to use the timestamp counter instruction */
11948 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11949 #define cpu_has_amd_erratum(x) (false)
11950 #endif /* CONFIG_CPU_SUP_AMD */
11951
11952 -extern unsigned long arch_align_stack(unsigned long sp);
11953 +#define arch_align_stack(x) ((x) & ~0xfUL)
11954 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11955
11956 void default_idle(void);
11957 bool set_pm_idle_to_default(void);
11958
11959 -void stop_this_cpu(void *dummy);
11960 +void stop_this_cpu(void *dummy) __noreturn;
11961
11962 #endif /* _ASM_X86_PROCESSOR_H */
11963 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11964 index dcfde52..dbfea06 100644
11965 --- a/arch/x86/include/asm/ptrace.h
11966 +++ b/arch/x86/include/asm/ptrace.h
11967 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11968 }
11969
11970 /*
11971 - * user_mode_vm(regs) determines whether a register set came from user mode.
11972 + * user_mode(regs) determines whether a register set came from user mode.
11973 * This is true if V8086 mode was enabled OR if the register set was from
11974 * protected mode with RPL-3 CS value. This tricky test checks that with
11975 * one comparison. Many places in the kernel can bypass this full check
11976 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11977 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11978 + * be used.
11979 */
11980 -static inline int user_mode(struct pt_regs *regs)
11981 +static inline int user_mode_novm(struct pt_regs *regs)
11982 {
11983 #ifdef CONFIG_X86_32
11984 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11985 #else
11986 - return !!(regs->cs & 3);
11987 + return !!(regs->cs & SEGMENT_RPL_MASK);
11988 #endif
11989 }
11990
11991 -static inline int user_mode_vm(struct pt_regs *regs)
11992 +static inline int user_mode(struct pt_regs *regs)
11993 {
11994 #ifdef CONFIG_X86_32
11995 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11996 USER_RPL;
11997 #else
11998 - return user_mode(regs);
11999 + return user_mode_novm(regs);
12000 #endif
12001 }
12002
12003 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12004 #ifdef CONFIG_X86_64
12005 static inline bool user_64bit_mode(struct pt_regs *regs)
12006 {
12007 + unsigned long cs = regs->cs & 0xffff;
12008 #ifndef CONFIG_PARAVIRT
12009 /*
12010 * On non-paravirt systems, this is the only long mode CPL 3
12011 * selector. We do not allow long mode selectors in the LDT.
12012 */
12013 - return regs->cs == __USER_CS;
12014 + return cs == __USER_CS;
12015 #else
12016 /* Headers are too twisted for this to go in paravirt.h. */
12017 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12018 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12019 #endif
12020 }
12021 #endif
12022 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12023 index fe1ec5b..dc5c3fe 100644
12024 --- a/arch/x86/include/asm/realmode.h
12025 +++ b/arch/x86/include/asm/realmode.h
12026 @@ -22,16 +22,14 @@ struct real_mode_header {
12027 #endif
12028 /* APM/BIOS reboot */
12029 u32 machine_real_restart_asm;
12030 -#ifdef CONFIG_X86_64
12031 u32 machine_real_restart_seg;
12032 -#endif
12033 };
12034
12035 /* This must match data at trampoline_32/64.S */
12036 struct trampoline_header {
12037 #ifdef CONFIG_X86_32
12038 u32 start;
12039 - u16 gdt_pad;
12040 + u16 boot_cs;
12041 u16 gdt_limit;
12042 u32 gdt_base;
12043 #else
12044 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12045 index a82c4f1..ac45053 100644
12046 --- a/arch/x86/include/asm/reboot.h
12047 +++ b/arch/x86/include/asm/reboot.h
12048 @@ -6,13 +6,13 @@
12049 struct pt_regs;
12050
12051 struct machine_ops {
12052 - void (*restart)(char *cmd);
12053 - void (*halt)(void);
12054 - void (*power_off)(void);
12055 + void (* __noreturn restart)(char *cmd);
12056 + void (* __noreturn halt)(void);
12057 + void (* __noreturn power_off)(void);
12058 void (*shutdown)(void);
12059 void (*crash_shutdown)(struct pt_regs *);
12060 - void (*emergency_restart)(void);
12061 -};
12062 + void (* __noreturn emergency_restart)(void);
12063 +} __no_const;
12064
12065 extern struct machine_ops machine_ops;
12066
12067 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12068 index 2dbe4a7..ce1db00 100644
12069 --- a/arch/x86/include/asm/rwsem.h
12070 +++ b/arch/x86/include/asm/rwsem.h
12071 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12072 {
12073 asm volatile("# beginning down_read\n\t"
12074 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12075 +
12076 +#ifdef CONFIG_PAX_REFCOUNT
12077 + "jno 0f\n"
12078 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12079 + "int $4\n0:\n"
12080 + _ASM_EXTABLE(0b, 0b)
12081 +#endif
12082 +
12083 /* adds 0x00000001 */
12084 " jns 1f\n"
12085 " call call_rwsem_down_read_failed\n"
12086 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12087 "1:\n\t"
12088 " mov %1,%2\n\t"
12089 " add %3,%2\n\t"
12090 +
12091 +#ifdef CONFIG_PAX_REFCOUNT
12092 + "jno 0f\n"
12093 + "sub %3,%2\n"
12094 + "int $4\n0:\n"
12095 + _ASM_EXTABLE(0b, 0b)
12096 +#endif
12097 +
12098 " jle 2f\n\t"
12099 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12100 " jnz 1b\n\t"
12101 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12102 long tmp;
12103 asm volatile("# beginning down_write\n\t"
12104 LOCK_PREFIX " xadd %1,(%2)\n\t"
12105 +
12106 +#ifdef CONFIG_PAX_REFCOUNT
12107 + "jno 0f\n"
12108 + "mov %1,(%2)\n"
12109 + "int $4\n0:\n"
12110 + _ASM_EXTABLE(0b, 0b)
12111 +#endif
12112 +
12113 /* adds 0xffff0001, returns the old value */
12114 " test %1,%1\n\t"
12115 /* was the count 0 before? */
12116 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12117 long tmp;
12118 asm volatile("# beginning __up_read\n\t"
12119 LOCK_PREFIX " xadd %1,(%2)\n\t"
12120 +
12121 +#ifdef CONFIG_PAX_REFCOUNT
12122 + "jno 0f\n"
12123 + "mov %1,(%2)\n"
12124 + "int $4\n0:\n"
12125 + _ASM_EXTABLE(0b, 0b)
12126 +#endif
12127 +
12128 /* subtracts 1, returns the old value */
12129 " jns 1f\n\t"
12130 " call call_rwsem_wake\n" /* expects old value in %edx */
12131 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12132 long tmp;
12133 asm volatile("# beginning __up_write\n\t"
12134 LOCK_PREFIX " xadd %1,(%2)\n\t"
12135 +
12136 +#ifdef CONFIG_PAX_REFCOUNT
12137 + "jno 0f\n"
12138 + "mov %1,(%2)\n"
12139 + "int $4\n0:\n"
12140 + _ASM_EXTABLE(0b, 0b)
12141 +#endif
12142 +
12143 /* subtracts 0xffff0001, returns the old value */
12144 " jns 1f\n\t"
12145 " call call_rwsem_wake\n" /* expects old value in %edx */
12146 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12147 {
12148 asm volatile("# beginning __downgrade_write\n\t"
12149 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12150 +
12151 +#ifdef CONFIG_PAX_REFCOUNT
12152 + "jno 0f\n"
12153 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12154 + "int $4\n0:\n"
12155 + _ASM_EXTABLE(0b, 0b)
12156 +#endif
12157 +
12158 /*
12159 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12160 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12161 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12162 */
12163 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12164 {
12165 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12166 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12167 +
12168 +#ifdef CONFIG_PAX_REFCOUNT
12169 + "jno 0f\n"
12170 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12171 + "int $4\n0:\n"
12172 + _ASM_EXTABLE(0b, 0b)
12173 +#endif
12174 +
12175 : "+m" (sem->count)
12176 : "er" (delta));
12177 }
12178 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12179 */
12180 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12181 {
12182 - return delta + xadd(&sem->count, delta);
12183 + return delta + xadd_check_overflow(&sem->count, delta);
12184 }
12185
12186 #endif /* __KERNEL__ */
12187 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12188 index c48a950..c6d7468 100644
12189 --- a/arch/x86/include/asm/segment.h
12190 +++ b/arch/x86/include/asm/segment.h
12191 @@ -64,10 +64,15 @@
12192 * 26 - ESPFIX small SS
12193 * 27 - per-cpu [ offset to per-cpu data area ]
12194 * 28 - stack_canary-20 [ for stack protector ]
12195 - * 29 - unused
12196 - * 30 - unused
12197 + * 29 - PCI BIOS CS
12198 + * 30 - PCI BIOS DS
12199 * 31 - TSS for double fault handler
12200 */
12201 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12202 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12203 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12204 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12205 +
12206 #define GDT_ENTRY_TLS_MIN 6
12207 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12208
12209 @@ -79,6 +84,8 @@
12210
12211 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12212
12213 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12214 +
12215 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12216
12217 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12218 @@ -104,6 +111,12 @@
12219 #define __KERNEL_STACK_CANARY 0
12220 #endif
12221
12222 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12223 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12224 +
12225 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12226 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12227 +
12228 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12229
12230 /*
12231 @@ -141,7 +154,7 @@
12232 */
12233
12234 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12235 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12236 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12237
12238
12239 #else
12240 @@ -165,6 +178,8 @@
12241 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12242 #define __USER32_DS __USER_DS
12243
12244 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12245 +
12246 #define GDT_ENTRY_TSS 8 /* needs two entries */
12247 #define GDT_ENTRY_LDT 10 /* needs two entries */
12248 #define GDT_ENTRY_TLS_MIN 12
12249 @@ -185,6 +200,7 @@
12250 #endif
12251
12252 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12253 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12254 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12255 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12256 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12257 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12258 {
12259 unsigned long __limit;
12260 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12261 - return __limit + 1;
12262 + return __limit;
12263 }
12264
12265 #endif /* !__ASSEMBLY__ */
12266 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12267 index 4f19a15..9e14f27 100644
12268 --- a/arch/x86/include/asm/smp.h
12269 +++ b/arch/x86/include/asm/smp.h
12270 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12271 /* cpus sharing the last level cache: */
12272 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12273 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12274 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12275 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12276
12277 static inline struct cpumask *cpu_sibling_mask(int cpu)
12278 {
12279 @@ -79,7 +79,7 @@ struct smp_ops {
12280
12281 void (*send_call_func_ipi)(const struct cpumask *mask);
12282 void (*send_call_func_single_ipi)(int cpu);
12283 -};
12284 +} __no_const;
12285
12286 /* Globals due to paravirt */
12287 extern void set_cpu_sibling_map(int cpu);
12288 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12289 extern int safe_smp_processor_id(void);
12290
12291 #elif defined(CONFIG_X86_64_SMP)
12292 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12293 -
12294 -#define stack_smp_processor_id() \
12295 -({ \
12296 - struct thread_info *ti; \
12297 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12298 - ti->cpu; \
12299 -})
12300 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12301 +#define stack_smp_processor_id() raw_smp_processor_id()
12302 #define safe_smp_processor_id() smp_processor_id()
12303
12304 #endif
12305 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12306 index 33692ea..350a534 100644
12307 --- a/arch/x86/include/asm/spinlock.h
12308 +++ b/arch/x86/include/asm/spinlock.h
12309 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12310 static inline void arch_read_lock(arch_rwlock_t *rw)
12311 {
12312 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12313 +
12314 +#ifdef CONFIG_PAX_REFCOUNT
12315 + "jno 0f\n"
12316 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12317 + "int $4\n0:\n"
12318 + _ASM_EXTABLE(0b, 0b)
12319 +#endif
12320 +
12321 "jns 1f\n"
12322 "call __read_lock_failed\n\t"
12323 "1:\n"
12324 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12325 static inline void arch_write_lock(arch_rwlock_t *rw)
12326 {
12327 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12328 +
12329 +#ifdef CONFIG_PAX_REFCOUNT
12330 + "jno 0f\n"
12331 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12332 + "int $4\n0:\n"
12333 + _ASM_EXTABLE(0b, 0b)
12334 +#endif
12335 +
12336 "jz 1f\n"
12337 "call __write_lock_failed\n\t"
12338 "1:\n"
12339 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12340
12341 static inline void arch_read_unlock(arch_rwlock_t *rw)
12342 {
12343 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12344 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12345 +
12346 +#ifdef CONFIG_PAX_REFCOUNT
12347 + "jno 0f\n"
12348 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12349 + "int $4\n0:\n"
12350 + _ASM_EXTABLE(0b, 0b)
12351 +#endif
12352 +
12353 :"+m" (rw->lock) : : "memory");
12354 }
12355
12356 static inline void arch_write_unlock(arch_rwlock_t *rw)
12357 {
12358 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12359 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12360 +
12361 +#ifdef CONFIG_PAX_REFCOUNT
12362 + "jno 0f\n"
12363 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12364 + "int $4\n0:\n"
12365 + _ASM_EXTABLE(0b, 0b)
12366 +#endif
12367 +
12368 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12369 }
12370
12371 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12372 index 6a99859..03cb807 100644
12373 --- a/arch/x86/include/asm/stackprotector.h
12374 +++ b/arch/x86/include/asm/stackprotector.h
12375 @@ -47,7 +47,7 @@
12376 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12377 */
12378 #define GDT_STACK_CANARY_INIT \
12379 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12380 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12381
12382 /*
12383 * Initialize the stackprotector canary value.
12384 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12385
12386 static inline void load_stack_canary_segment(void)
12387 {
12388 -#ifdef CONFIG_X86_32
12389 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12390 asm volatile ("mov %0, %%gs" : : "r" (0));
12391 #endif
12392 }
12393 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12394 index 70bbe39..4ae2bd4 100644
12395 --- a/arch/x86/include/asm/stacktrace.h
12396 +++ b/arch/x86/include/asm/stacktrace.h
12397 @@ -11,28 +11,20 @@
12398
12399 extern int kstack_depth_to_print;
12400
12401 -struct thread_info;
12402 +struct task_struct;
12403 struct stacktrace_ops;
12404
12405 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12406 - unsigned long *stack,
12407 - unsigned long bp,
12408 - const struct stacktrace_ops *ops,
12409 - void *data,
12410 - unsigned long *end,
12411 - int *graph);
12412 +typedef unsigned long walk_stack_t(struct task_struct *task,
12413 + void *stack_start,
12414 + unsigned long *stack,
12415 + unsigned long bp,
12416 + const struct stacktrace_ops *ops,
12417 + void *data,
12418 + unsigned long *end,
12419 + int *graph);
12420
12421 -extern unsigned long
12422 -print_context_stack(struct thread_info *tinfo,
12423 - unsigned long *stack, unsigned long bp,
12424 - const struct stacktrace_ops *ops, void *data,
12425 - unsigned long *end, int *graph);
12426 -
12427 -extern unsigned long
12428 -print_context_stack_bp(struct thread_info *tinfo,
12429 - unsigned long *stack, unsigned long bp,
12430 - const struct stacktrace_ops *ops, void *data,
12431 - unsigned long *end, int *graph);
12432 +extern walk_stack_t print_context_stack;
12433 +extern walk_stack_t print_context_stack_bp;
12434
12435 /* Generic stack tracer with callbacks */
12436
12437 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12438 void (*address)(void *data, unsigned long address, int reliable);
12439 /* On negative return stop dumping */
12440 int (*stack)(void *data, char *name);
12441 - walk_stack_t walk_stack;
12442 + walk_stack_t *walk_stack;
12443 };
12444
12445 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12446 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12447 index 4ec45b3..a4f0a8a 100644
12448 --- a/arch/x86/include/asm/switch_to.h
12449 +++ b/arch/x86/include/asm/switch_to.h
12450 @@ -108,7 +108,7 @@ do { \
12451 "call __switch_to\n\t" \
12452 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12453 __switch_canary \
12454 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12455 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12456 "movq %%rax,%%rdi\n\t" \
12457 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12458 "jnz ret_from_fork\n\t" \
12459 @@ -119,7 +119,7 @@ do { \
12460 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12461 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12462 [_tif_fork] "i" (_TIF_FORK), \
12463 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12464 + [thread_info] "m" (current_tinfo), \
12465 [current_task] "m" (current_task) \
12466 __switch_canary_iparam \
12467 : "memory", "cc" __EXTRA_CLOBBER)
12468 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12469 index 3fda9db4..4ca1c61 100644
12470 --- a/arch/x86/include/asm/sys_ia32.h
12471 +++ b/arch/x86/include/asm/sys_ia32.h
12472 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12473 struct old_sigaction32 __user *);
12474 asmlinkage long sys32_alarm(unsigned int);
12475
12476 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12477 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12478 asmlinkage long sys32_sysfs(int, u32, u32);
12479
12480 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12481 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12482 index 89f794f..1422765 100644
12483 --- a/arch/x86/include/asm/thread_info.h
12484 +++ b/arch/x86/include/asm/thread_info.h
12485 @@ -10,6 +10,7 @@
12486 #include <linux/compiler.h>
12487 #include <asm/page.h>
12488 #include <asm/types.h>
12489 +#include <asm/percpu.h>
12490
12491 /*
12492 * low level task data that entry.S needs immediate access to
12493 @@ -24,7 +25,6 @@ struct exec_domain;
12494 #include <linux/atomic.h>
12495
12496 struct thread_info {
12497 - struct task_struct *task; /* main task structure */
12498 struct exec_domain *exec_domain; /* execution domain */
12499 __u32 flags; /* low level flags */
12500 __u32 status; /* thread synchronous flags */
12501 @@ -34,19 +34,13 @@ struct thread_info {
12502 mm_segment_t addr_limit;
12503 struct restart_block restart_block;
12504 void __user *sysenter_return;
12505 -#ifdef CONFIG_X86_32
12506 - unsigned long previous_esp; /* ESP of the previous stack in
12507 - case of nested (IRQ) stacks
12508 - */
12509 - __u8 supervisor_stack[0];
12510 -#endif
12511 + unsigned long lowest_stack;
12512 unsigned int sig_on_uaccess_error:1;
12513 unsigned int uaccess_err:1; /* uaccess failed */
12514 };
12515
12516 -#define INIT_THREAD_INFO(tsk) \
12517 +#define INIT_THREAD_INFO \
12518 { \
12519 - .task = &tsk, \
12520 .exec_domain = &default_exec_domain, \
12521 .flags = 0, \
12522 .cpu = 0, \
12523 @@ -57,7 +51,7 @@ struct thread_info {
12524 }, \
12525 }
12526
12527 -#define init_thread_info (init_thread_union.thread_info)
12528 +#define init_thread_info (init_thread_union.stack)
12529 #define init_stack (init_thread_union.stack)
12530
12531 #else /* !__ASSEMBLY__ */
12532 @@ -98,6 +92,7 @@ struct thread_info {
12533 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12534 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12535 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12536 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12537
12538 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12539 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12540 @@ -122,16 +117,18 @@ struct thread_info {
12541 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12542 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12543 #define _TIF_X32 (1 << TIF_X32)
12544 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12545
12546 /* work to do in syscall_trace_enter() */
12547 #define _TIF_WORK_SYSCALL_ENTRY \
12548 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12549 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12550 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12551 + _TIF_GRSEC_SETXID)
12552
12553 /* work to do in syscall_trace_leave() */
12554 #define _TIF_WORK_SYSCALL_EXIT \
12555 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12556 - _TIF_SYSCALL_TRACEPOINT)
12557 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12558
12559 /* work to do on interrupt/exception return */
12560 #define _TIF_WORK_MASK \
12561 @@ -141,7 +138,8 @@ struct thread_info {
12562
12563 /* work to do on any return to user space */
12564 #define _TIF_ALLWORK_MASK \
12565 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12566 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12567 + _TIF_GRSEC_SETXID)
12568
12569 /* Only used for 64 bit */
12570 #define _TIF_DO_NOTIFY_MASK \
12571 @@ -157,45 +155,40 @@ struct thread_info {
12572
12573 #define PREEMPT_ACTIVE 0x10000000
12574
12575 -#ifdef CONFIG_X86_32
12576 -
12577 -#define STACK_WARN (THREAD_SIZE/8)
12578 -/*
12579 - * macros/functions for gaining access to the thread information structure
12580 - *
12581 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12582 - */
12583 -#ifndef __ASSEMBLY__
12584 -
12585 -
12586 -/* how to get the current stack pointer from C */
12587 -register unsigned long current_stack_pointer asm("esp") __used;
12588 -
12589 -/* how to get the thread information struct from C */
12590 -static inline struct thread_info *current_thread_info(void)
12591 -{
12592 - return (struct thread_info *)
12593 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12594 -}
12595 -
12596 -#else /* !__ASSEMBLY__ */
12597 -
12598 +#ifdef __ASSEMBLY__
12599 /* how to get the thread information struct from ASM */
12600 #define GET_THREAD_INFO(reg) \
12601 - movl $-THREAD_SIZE, reg; \
12602 - andl %esp, reg
12603 + mov PER_CPU_VAR(current_tinfo), reg
12604
12605 /* use this one if reg already contains %esp */
12606 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12607 - andl $-THREAD_SIZE, reg
12608 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12609 +#else
12610 +/* how to get the thread information struct from C */
12611 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12612 +
12613 +static __always_inline struct thread_info *current_thread_info(void)
12614 +{
12615 + return this_cpu_read_stable(current_tinfo);
12616 +}
12617 +#endif
12618 +
12619 +#ifdef CONFIG_X86_32
12620 +
12621 +#define STACK_WARN (THREAD_SIZE/8)
12622 +/*
12623 + * macros/functions for gaining access to the thread information structure
12624 + *
12625 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12626 + */
12627 +#ifndef __ASSEMBLY__
12628 +
12629 +/* how to get the current stack pointer from C */
12630 +register unsigned long current_stack_pointer asm("esp") __used;
12631
12632 #endif
12633
12634 #else /* X86_32 */
12635
12636 -#include <asm/percpu.h>
12637 -#define KERNEL_STACK_OFFSET (5*8)
12638 -
12639 /*
12640 * macros/functions for gaining access to the thread information structure
12641 * preempt_count needs to be 1 initially, until the scheduler is functional.
12642 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12643 #ifndef __ASSEMBLY__
12644 DECLARE_PER_CPU(unsigned long, kernel_stack);
12645
12646 -static inline struct thread_info *current_thread_info(void)
12647 -{
12648 - struct thread_info *ti;
12649 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12650 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12651 - return ti;
12652 -}
12653 -
12654 -#else /* !__ASSEMBLY__ */
12655 -
12656 -/* how to get the thread information struct from ASM */
12657 -#define GET_THREAD_INFO(reg) \
12658 - movq PER_CPU_VAR(kernel_stack),reg ; \
12659 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12660 -
12661 -/*
12662 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12663 - * a certain register (to be used in assembler memory operands).
12664 - */
12665 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12666 -
12667 +/* how to get the current stack pointer from C */
12668 +register unsigned long current_stack_pointer asm("rsp") __used;
12669 #endif
12670
12671 #endif /* !X86_32 */
12672 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12673 extern void arch_task_cache_init(void);
12674 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12675 extern void arch_release_task_struct(struct task_struct *tsk);
12676 +
12677 +#define __HAVE_THREAD_FUNCTIONS
12678 +#define task_thread_info(task) (&(task)->tinfo)
12679 +#define task_stack_page(task) ((task)->stack)
12680 +#define setup_thread_stack(p, org) do {} while (0)
12681 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12682 +
12683 #endif
12684 #endif /* _ASM_X86_THREAD_INFO_H */
12685 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12686 index e1f3a17..1ab364d 100644
12687 --- a/arch/x86/include/asm/uaccess.h
12688 +++ b/arch/x86/include/asm/uaccess.h
12689 @@ -7,12 +7,15 @@
12690 #include <linux/compiler.h>
12691 #include <linux/thread_info.h>
12692 #include <linux/string.h>
12693 +#include <linux/sched.h>
12694 #include <asm/asm.h>
12695 #include <asm/page.h>
12696
12697 #define VERIFY_READ 0
12698 #define VERIFY_WRITE 1
12699
12700 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12701 +
12702 /*
12703 * The fs value determines whether argument validity checking should be
12704 * performed or not. If get_fs() == USER_DS, checking is performed, with
12705 @@ -28,7 +31,12 @@
12706
12707 #define get_ds() (KERNEL_DS)
12708 #define get_fs() (current_thread_info()->addr_limit)
12709 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12710 +void __set_fs(mm_segment_t x);
12711 +void set_fs(mm_segment_t x);
12712 +#else
12713 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12714 +#endif
12715
12716 #define segment_eq(a, b) ((a).seg == (b).seg)
12717
12718 @@ -76,8 +84,33 @@
12719 * checks that the pointer is in the user space range - after calling
12720 * this function, memory access functions may still return -EFAULT.
12721 */
12722 -#define access_ok(type, addr, size) \
12723 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12724 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12725 +#define access_ok(type, addr, size) \
12726 +({ \
12727 + long __size = size; \
12728 + unsigned long __addr = (unsigned long)addr; \
12729 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12730 + unsigned long __end_ao = __addr + __size - 1; \
12731 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12732 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12733 + while(__addr_ao <= __end_ao) { \
12734 + char __c_ao; \
12735 + __addr_ao += PAGE_SIZE; \
12736 + if (__size > PAGE_SIZE) \
12737 + cond_resched(); \
12738 + if (__get_user(__c_ao, (char __user *)__addr)) \
12739 + break; \
12740 + if (type != VERIFY_WRITE) { \
12741 + __addr = __addr_ao; \
12742 + continue; \
12743 + } \
12744 + if (__put_user(__c_ao, (char __user *)__addr)) \
12745 + break; \
12746 + __addr = __addr_ao; \
12747 + } \
12748 + } \
12749 + __ret_ao; \
12750 +})
12751
12752 /*
12753 * The exception table consists of pairs of addresses relative to the
12754 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12755 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12756 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12757
12758 -
12759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12760 +#define __copyuser_seg "gs;"
12761 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12762 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12763 +#else
12764 +#define __copyuser_seg
12765 +#define __COPYUSER_SET_ES
12766 +#define __COPYUSER_RESTORE_ES
12767 +#endif
12768
12769 #ifdef CONFIG_X86_32
12770 #define __put_user_asm_u64(x, addr, err, errret) \
12771 - asm volatile("1: movl %%eax,0(%2)\n" \
12772 - "2: movl %%edx,4(%2)\n" \
12773 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12774 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12775 "3:\n" \
12776 ".section .fixup,\"ax\"\n" \
12777 "4: movl %3,%0\n" \
12778 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12779 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12780
12781 #define __put_user_asm_ex_u64(x, addr) \
12782 - asm volatile("1: movl %%eax,0(%1)\n" \
12783 - "2: movl %%edx,4(%1)\n" \
12784 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12785 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12786 "3:\n" \
12787 _ASM_EXTABLE_EX(1b, 2b) \
12788 _ASM_EXTABLE_EX(2b, 3b) \
12789 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12790 __typeof__(*(ptr)) __pu_val; \
12791 __chk_user_ptr(ptr); \
12792 might_fault(); \
12793 - __pu_val = x; \
12794 + __pu_val = (x); \
12795 switch (sizeof(*(ptr))) { \
12796 case 1: \
12797 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12798 @@ -379,7 +420,7 @@ do { \
12799 } while (0)
12800
12801 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12802 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12803 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12804 "2:\n" \
12805 ".section .fixup,\"ax\"\n" \
12806 "3: mov %3,%0\n" \
12807 @@ -387,7 +428,7 @@ do { \
12808 " jmp 2b\n" \
12809 ".previous\n" \
12810 _ASM_EXTABLE(1b, 3b) \
12811 - : "=r" (err), ltype(x) \
12812 + : "=r" (err), ltype (x) \
12813 : "m" (__m(addr)), "i" (errret), "0" (err))
12814
12815 #define __get_user_size_ex(x, ptr, size) \
12816 @@ -412,7 +453,7 @@ do { \
12817 } while (0)
12818
12819 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12820 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12821 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12822 "2:\n" \
12823 _ASM_EXTABLE_EX(1b, 2b) \
12824 : ltype(x) : "m" (__m(addr)))
12825 @@ -429,13 +470,24 @@ do { \
12826 int __gu_err; \
12827 unsigned long __gu_val; \
12828 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12829 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12830 + (x) = (__typeof__(*(ptr)))__gu_val; \
12831 __gu_err; \
12832 })
12833
12834 /* FIXME: this hack is definitely wrong -AK */
12835 struct __large_struct { unsigned long buf[100]; };
12836 -#define __m(x) (*(struct __large_struct __user *)(x))
12837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12838 +#define ____m(x) \
12839 +({ \
12840 + unsigned long ____x = (unsigned long)(x); \
12841 + if (____x < PAX_USER_SHADOW_BASE) \
12842 + ____x += PAX_USER_SHADOW_BASE; \
12843 + (void __user *)____x; \
12844 +})
12845 +#else
12846 +#define ____m(x) (x)
12847 +#endif
12848 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12849
12850 /*
12851 * Tell gcc we read from memory instead of writing: this is because
12852 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12853 * aliasing issues.
12854 */
12855 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12856 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12857 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12858 "2:\n" \
12859 ".section .fixup,\"ax\"\n" \
12860 "3: mov %3,%0\n" \
12861 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12862 ".previous\n" \
12863 _ASM_EXTABLE(1b, 3b) \
12864 : "=r"(err) \
12865 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12866 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12867
12868 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12869 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12870 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12871 "2:\n" \
12872 _ASM_EXTABLE_EX(1b, 2b) \
12873 : : ltype(x), "m" (__m(addr)))
12874 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12875 * On error, the variable @x is set to zero.
12876 */
12877
12878 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12879 +#define __get_user(x, ptr) get_user((x), (ptr))
12880 +#else
12881 #define __get_user(x, ptr) \
12882 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12883 +#endif
12884
12885 /**
12886 * __put_user: - Write a simple value into user space, with less checking.
12887 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12888 * Returns zero on success, or -EFAULT on error.
12889 */
12890
12891 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12892 +#define __put_user(x, ptr) put_user((x), (ptr))
12893 +#else
12894 #define __put_user(x, ptr) \
12895 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12896 +#endif
12897
12898 #define __get_user_unaligned __get_user
12899 #define __put_user_unaligned __put_user
12900 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12901 #define get_user_ex(x, ptr) do { \
12902 unsigned long __gue_val; \
12903 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12904 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12905 + (x) = (__typeof__(*(ptr)))__gue_val; \
12906 } while (0)
12907
12908 #ifdef CONFIG_X86_WP_WORKS_OK
12909 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12910 index 576e39b..ccd0a39 100644
12911 --- a/arch/x86/include/asm/uaccess_32.h
12912 +++ b/arch/x86/include/asm/uaccess_32.h
12913 @@ -11,15 +11,15 @@
12914 #include <asm/page.h>
12915
12916 unsigned long __must_check __copy_to_user_ll
12917 - (void __user *to, const void *from, unsigned long n);
12918 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12919 unsigned long __must_check __copy_from_user_ll
12920 - (void *to, const void __user *from, unsigned long n);
12921 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12922 unsigned long __must_check __copy_from_user_ll_nozero
12923 - (void *to, const void __user *from, unsigned long n);
12924 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12925 unsigned long __must_check __copy_from_user_ll_nocache
12926 - (void *to, const void __user *from, unsigned long n);
12927 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12928 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12929 - (void *to, const void __user *from, unsigned long n);
12930 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12931
12932 /**
12933 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12934 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12935 static __always_inline unsigned long __must_check
12936 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12937 {
12938 + if ((long)n < 0)
12939 + return n;
12940 +
12941 if (__builtin_constant_p(n)) {
12942 unsigned long ret;
12943
12944 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12945 return ret;
12946 }
12947 }
12948 + if (!__builtin_constant_p(n))
12949 + check_object_size(from, n, true);
12950 return __copy_to_user_ll(to, from, n);
12951 }
12952
12953 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12954 __copy_to_user(void __user *to, const void *from, unsigned long n)
12955 {
12956 might_fault();
12957 +
12958 return __copy_to_user_inatomic(to, from, n);
12959 }
12960
12961 static __always_inline unsigned long
12962 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12963 {
12964 + if ((long)n < 0)
12965 + return n;
12966 +
12967 /* Avoid zeroing the tail if the copy fails..
12968 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12969 * but as the zeroing behaviour is only significant when n is not
12970 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12971 __copy_from_user(void *to, const void __user *from, unsigned long n)
12972 {
12973 might_fault();
12974 +
12975 + if ((long)n < 0)
12976 + return n;
12977 +
12978 if (__builtin_constant_p(n)) {
12979 unsigned long ret;
12980
12981 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12982 return ret;
12983 }
12984 }
12985 + if (!__builtin_constant_p(n))
12986 + check_object_size(to, n, false);
12987 return __copy_from_user_ll(to, from, n);
12988 }
12989
12990 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12991 const void __user *from, unsigned long n)
12992 {
12993 might_fault();
12994 +
12995 + if ((long)n < 0)
12996 + return n;
12997 +
12998 if (__builtin_constant_p(n)) {
12999 unsigned long ret;
13000
13001 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13002 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13003 unsigned long n)
13004 {
13005 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13006 + if ((long)n < 0)
13007 + return n;
13008 +
13009 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13010 }
13011
13012 -unsigned long __must_check copy_to_user(void __user *to,
13013 - const void *from, unsigned long n);
13014 -unsigned long __must_check _copy_from_user(void *to,
13015 - const void __user *from,
13016 - unsigned long n);
13017 -
13018 +extern void copy_to_user_overflow(void)
13019 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13020 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13021 +#else
13022 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13023 +#endif
13024 +;
13025
13026 extern void copy_from_user_overflow(void)
13027 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13028 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13029 #endif
13030 ;
13031
13032 -static inline unsigned long __must_check copy_from_user(void *to,
13033 - const void __user *from,
13034 - unsigned long n)
13035 +/**
13036 + * copy_to_user: - Copy a block of data into user space.
13037 + * @to: Destination address, in user space.
13038 + * @from: Source address, in kernel space.
13039 + * @n: Number of bytes to copy.
13040 + *
13041 + * Context: User context only. This function may sleep.
13042 + *
13043 + * Copy data from kernel space to user space.
13044 + *
13045 + * Returns number of bytes that could not be copied.
13046 + * On success, this will be zero.
13047 + */
13048 +static inline unsigned long __must_check
13049 +copy_to_user(void __user *to, const void *from, unsigned long n)
13050 {
13051 - int sz = __compiletime_object_size(to);
13052 + size_t sz = __compiletime_object_size(from);
13053
13054 - if (likely(sz == -1 || sz >= n))
13055 - n = _copy_from_user(to, from, n);
13056 - else
13057 + if (unlikely(sz != (size_t)-1 && sz < n))
13058 + copy_to_user_overflow();
13059 + else if (access_ok(VERIFY_WRITE, to, n))
13060 + n = __copy_to_user(to, from, n);
13061 + return n;
13062 +}
13063 +
13064 +/**
13065 + * copy_from_user: - Copy a block of data from user space.
13066 + * @to: Destination address, in kernel space.
13067 + * @from: Source address, in user space.
13068 + * @n: Number of bytes to copy.
13069 + *
13070 + * Context: User context only. This function may sleep.
13071 + *
13072 + * Copy data from user space to kernel space.
13073 + *
13074 + * Returns number of bytes that could not be copied.
13075 + * On success, this will be zero.
13076 + *
13077 + * If some data could not be copied, this function will pad the copied
13078 + * data to the requested size using zero bytes.
13079 + */
13080 +static inline unsigned long __must_check
13081 +copy_from_user(void *to, const void __user *from, unsigned long n)
13082 +{
13083 + size_t sz = __compiletime_object_size(to);
13084 +
13085 + if (unlikely(sz != (size_t)-1 && sz < n))
13086 copy_from_user_overflow();
13087 -
13088 + else if (access_ok(VERIFY_READ, from, n))
13089 + n = __copy_from_user(to, from, n);
13090 + else if ((long)n > 0) {
13091 + if (!__builtin_constant_p(n))
13092 + check_object_size(to, n, false);
13093 + memset(to, 0, n);
13094 + }
13095 return n;
13096 }
13097
13098 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13099 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13100 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13101 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13102
13103 #endif /* _ASM_X86_UACCESS_32_H */
13104 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13105 index d8def8b..ac7fc15 100644
13106 --- a/arch/x86/include/asm/uaccess_64.h
13107 +++ b/arch/x86/include/asm/uaccess_64.h
13108 @@ -10,6 +10,9 @@
13109 #include <asm/alternative.h>
13110 #include <asm/cpufeature.h>
13111 #include <asm/page.h>
13112 +#include <asm/pgtable.h>
13113 +
13114 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13115
13116 /*
13117 * Copy To/From Userspace
13118 @@ -17,13 +20,13 @@
13119
13120 /* Handles exceptions in both to and from, but doesn't do access_ok */
13121 __must_check unsigned long
13122 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13123 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13124 __must_check unsigned long
13125 -copy_user_generic_string(void *to, const void *from, unsigned len);
13126 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13127 __must_check unsigned long
13128 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13129 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13130
13131 -static __always_inline __must_check unsigned long
13132 +static __always_inline __must_check __size_overflow(3) unsigned long
13133 copy_user_generic(void *to, const void *from, unsigned len)
13134 {
13135 unsigned ret;
13136 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13137 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13138 "=d" (len)),
13139 "1" (to), "2" (from), "3" (len)
13140 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13141 + : "memory", "rcx", "r8", "r9", "r11");
13142 return ret;
13143 }
13144
13145 +static __always_inline __must_check unsigned long
13146 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13147 +static __always_inline __must_check unsigned long
13148 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13149 __must_check unsigned long
13150 -_copy_to_user(void __user *to, const void *from, unsigned len);
13151 -__must_check unsigned long
13152 -_copy_from_user(void *to, const void __user *from, unsigned len);
13153 -__must_check unsigned long
13154 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13155 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13156 +
13157 +extern void copy_to_user_overflow(void)
13158 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13159 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13160 +#else
13161 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13162 +#endif
13163 +;
13164 +
13165 +extern void copy_from_user_overflow(void)
13166 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13167 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13168 +#else
13169 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13170 +#endif
13171 +;
13172
13173 static inline unsigned long __must_check copy_from_user(void *to,
13174 const void __user *from,
13175 unsigned long n)
13176 {
13177 - int sz = __compiletime_object_size(to);
13178 -
13179 might_fault();
13180 - if (likely(sz == -1 || sz >= n))
13181 - n = _copy_from_user(to, from, n);
13182 -#ifdef CONFIG_DEBUG_VM
13183 - else
13184 - WARN(1, "Buffer overflow detected!\n");
13185 -#endif
13186 +
13187 + if (access_ok(VERIFY_READ, from, n))
13188 + n = __copy_from_user(to, from, n);
13189 + else if (n < INT_MAX) {
13190 + if (!__builtin_constant_p(n))
13191 + check_object_size(to, n, false);
13192 + memset(to, 0, n);
13193 + }
13194 return n;
13195 }
13196
13197 static __always_inline __must_check
13198 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13199 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13200 {
13201 might_fault();
13202
13203 - return _copy_to_user(dst, src, size);
13204 + if (access_ok(VERIFY_WRITE, dst, size))
13205 + size = __copy_to_user(dst, src, size);
13206 + return size;
13207 }
13208
13209 static __always_inline __must_check
13210 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13211 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13212 {
13213 - int ret = 0;
13214 + size_t sz = __compiletime_object_size(dst);
13215 + unsigned ret = 0;
13216
13217 might_fault();
13218 - if (!__builtin_constant_p(size))
13219 - return copy_user_generic(dst, (__force void *)src, size);
13220 +
13221 + if (size > INT_MAX)
13222 + return size;
13223 +
13224 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13225 + if (!__access_ok(VERIFY_READ, src, size))
13226 + return size;
13227 +#endif
13228 +
13229 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13230 + copy_from_user_overflow();
13231 + return size;
13232 + }
13233 +
13234 + if (!__builtin_constant_p(size)) {
13235 + check_object_size(dst, size, false);
13236 +
13237 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13238 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13239 + src += PAX_USER_SHADOW_BASE;
13240 +#endif
13241 +
13242 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13243 + }
13244 switch (size) {
13245 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13246 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13247 ret, "b", "b", "=q", 1);
13248 return ret;
13249 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13250 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13251 ret, "w", "w", "=r", 2);
13252 return ret;
13253 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13254 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13255 ret, "l", "k", "=r", 4);
13256 return ret;
13257 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13258 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13259 ret, "q", "", "=r", 8);
13260 return ret;
13261 case 10:
13262 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13263 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13264 ret, "q", "", "=r", 10);
13265 if (unlikely(ret))
13266 return ret;
13267 __get_user_asm(*(u16 *)(8 + (char *)dst),
13268 - (u16 __user *)(8 + (char __user *)src),
13269 + (const u16 __user *)(8 + (const char __user *)src),
13270 ret, "w", "w", "=r", 2);
13271 return ret;
13272 case 16:
13273 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13274 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13275 ret, "q", "", "=r", 16);
13276 if (unlikely(ret))
13277 return ret;
13278 __get_user_asm(*(u64 *)(8 + (char *)dst),
13279 - (u64 __user *)(8 + (char __user *)src),
13280 + (const u64 __user *)(8 + (const char __user *)src),
13281 ret, "q", "", "=r", 8);
13282 return ret;
13283 default:
13284 - return copy_user_generic(dst, (__force void *)src, size);
13285 +
13286 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13287 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13288 + src += PAX_USER_SHADOW_BASE;
13289 +#endif
13290 +
13291 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13292 }
13293 }
13294
13295 static __always_inline __must_check
13296 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13297 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13298 {
13299 - int ret = 0;
13300 + size_t sz = __compiletime_object_size(src);
13301 + unsigned ret = 0;
13302
13303 might_fault();
13304 - if (!__builtin_constant_p(size))
13305 - return copy_user_generic((__force void *)dst, src, size);
13306 +
13307 + if (size > INT_MAX)
13308 + return size;
13309 +
13310 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13311 + if (!__access_ok(VERIFY_WRITE, dst, size))
13312 + return size;
13313 +#endif
13314 +
13315 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13316 + copy_to_user_overflow();
13317 + return size;
13318 + }
13319 +
13320 + if (!__builtin_constant_p(size)) {
13321 + check_object_size(src, size, true);
13322 +
13323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13324 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13325 + dst += PAX_USER_SHADOW_BASE;
13326 +#endif
13327 +
13328 + return copy_user_generic((__force_kernel void *)dst, src, size);
13329 + }
13330 switch (size) {
13331 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13332 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13333 ret, "b", "b", "iq", 1);
13334 return ret;
13335 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13336 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13337 ret, "w", "w", "ir", 2);
13338 return ret;
13339 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13340 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13341 ret, "l", "k", "ir", 4);
13342 return ret;
13343 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13344 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13345 ret, "q", "", "er", 8);
13346 return ret;
13347 case 10:
13348 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13349 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13350 ret, "q", "", "er", 10);
13351 if (unlikely(ret))
13352 return ret;
13353 asm("":::"memory");
13354 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13355 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13356 ret, "w", "w", "ir", 2);
13357 return ret;
13358 case 16:
13359 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13360 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13361 ret, "q", "", "er", 16);
13362 if (unlikely(ret))
13363 return ret;
13364 asm("":::"memory");
13365 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13366 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13367 ret, "q", "", "er", 8);
13368 return ret;
13369 default:
13370 - return copy_user_generic((__force void *)dst, src, size);
13371 +
13372 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13373 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13374 + dst += PAX_USER_SHADOW_BASE;
13375 +#endif
13376 +
13377 + return copy_user_generic((__force_kernel void *)dst, src, size);
13378 }
13379 }
13380
13381 static __always_inline __must_check
13382 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13383 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13384 {
13385 - int ret = 0;
13386 + unsigned ret = 0;
13387
13388 might_fault();
13389 - if (!__builtin_constant_p(size))
13390 - return copy_user_generic((__force void *)dst,
13391 - (__force void *)src, size);
13392 +
13393 + if (size > INT_MAX)
13394 + return size;
13395 +
13396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13397 + if (!__access_ok(VERIFY_READ, src, size))
13398 + return size;
13399 + if (!__access_ok(VERIFY_WRITE, dst, size))
13400 + return size;
13401 +#endif
13402 +
13403 + if (!__builtin_constant_p(size)) {
13404 +
13405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13406 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13407 + src += PAX_USER_SHADOW_BASE;
13408 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13409 + dst += PAX_USER_SHADOW_BASE;
13410 +#endif
13411 +
13412 + return copy_user_generic((__force_kernel void *)dst,
13413 + (__force_kernel const void *)src, size);
13414 + }
13415 switch (size) {
13416 case 1: {
13417 u8 tmp;
13418 - __get_user_asm(tmp, (u8 __user *)src,
13419 + __get_user_asm(tmp, (const u8 __user *)src,
13420 ret, "b", "b", "=q", 1);
13421 if (likely(!ret))
13422 __put_user_asm(tmp, (u8 __user *)dst,
13423 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13424 }
13425 case 2: {
13426 u16 tmp;
13427 - __get_user_asm(tmp, (u16 __user *)src,
13428 + __get_user_asm(tmp, (const u16 __user *)src,
13429 ret, "w", "w", "=r", 2);
13430 if (likely(!ret))
13431 __put_user_asm(tmp, (u16 __user *)dst,
13432 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13433
13434 case 4: {
13435 u32 tmp;
13436 - __get_user_asm(tmp, (u32 __user *)src,
13437 + __get_user_asm(tmp, (const u32 __user *)src,
13438 ret, "l", "k", "=r", 4);
13439 if (likely(!ret))
13440 __put_user_asm(tmp, (u32 __user *)dst,
13441 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13442 }
13443 case 8: {
13444 u64 tmp;
13445 - __get_user_asm(tmp, (u64 __user *)src,
13446 + __get_user_asm(tmp, (const u64 __user *)src,
13447 ret, "q", "", "=r", 8);
13448 if (likely(!ret))
13449 __put_user_asm(tmp, (u64 __user *)dst,
13450 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13451 return ret;
13452 }
13453 default:
13454 - return copy_user_generic((__force void *)dst,
13455 - (__force void *)src, size);
13456 +
13457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13458 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13459 + src += PAX_USER_SHADOW_BASE;
13460 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13461 + dst += PAX_USER_SHADOW_BASE;
13462 +#endif
13463 +
13464 + return copy_user_generic((__force_kernel void *)dst,
13465 + (__force_kernel const void *)src, size);
13466 }
13467 }
13468
13469 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13470 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13471 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13472 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13473
13474 static __must_check __always_inline int
13475 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13476 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13477 {
13478 - return copy_user_generic(dst, (__force const void *)src, size);
13479 + if (size > INT_MAX)
13480 + return size;
13481 +
13482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13483 + if (!__access_ok(VERIFY_READ, src, size))
13484 + return size;
13485 +
13486 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13487 + src += PAX_USER_SHADOW_BASE;
13488 +#endif
13489 +
13490 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13491 }
13492
13493 -static __must_check __always_inline int
13494 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13495 +static __must_check __always_inline unsigned long
13496 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13497 {
13498 - return copy_user_generic((__force void *)dst, src, size);
13499 + if (size > INT_MAX)
13500 + return size;
13501 +
13502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13503 + if (!__access_ok(VERIFY_WRITE, dst, size))
13504 + return size;
13505 +
13506 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13507 + dst += PAX_USER_SHADOW_BASE;
13508 +#endif
13509 +
13510 + return copy_user_generic((__force_kernel void *)dst, src, size);
13511 }
13512
13513 -extern long __copy_user_nocache(void *dst, const void __user *src,
13514 - unsigned size, int zerorest);
13515 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13516 + unsigned long size, int zerorest) __size_overflow(3);
13517
13518 -static inline int
13519 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13520 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13521 {
13522 might_sleep();
13523 +
13524 + if (size > INT_MAX)
13525 + return size;
13526 +
13527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13528 + if (!__access_ok(VERIFY_READ, src, size))
13529 + return size;
13530 +#endif
13531 +
13532 return __copy_user_nocache(dst, src, size, 1);
13533 }
13534
13535 -static inline int
13536 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13537 - unsigned size)
13538 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13539 + unsigned long size)
13540 {
13541 + if (size > INT_MAX)
13542 + return size;
13543 +
13544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13545 + if (!__access_ok(VERIFY_READ, src, size))
13546 + return size;
13547 +#endif
13548 +
13549 return __copy_user_nocache(dst, src, size, 0);
13550 }
13551
13552 -unsigned long
13553 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13554 +extern unsigned long
13555 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13556
13557 #endif /* _ASM_X86_UACCESS_64_H */
13558 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13559 index bb05228..d763d5b 100644
13560 --- a/arch/x86/include/asm/vdso.h
13561 +++ b/arch/x86/include/asm/vdso.h
13562 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13563 #define VDSO32_SYMBOL(base, name) \
13564 ({ \
13565 extern const char VDSO32_##name[]; \
13566 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13567 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13568 })
13569 #endif
13570
13571 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13572 index 5b238981..77fdd78 100644
13573 --- a/arch/x86/include/asm/word-at-a-time.h
13574 +++ b/arch/x86/include/asm/word-at-a-time.h
13575 @@ -11,7 +11,7 @@
13576 * and shift, for example.
13577 */
13578 struct word_at_a_time {
13579 - const unsigned long one_bits, high_bits;
13580 + unsigned long one_bits, high_bits;
13581 };
13582
13583 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13584 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13585 index 38155f6..e4184ba 100644
13586 --- a/arch/x86/include/asm/x86_init.h
13587 +++ b/arch/x86/include/asm/x86_init.h
13588 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13589 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13590 void (*find_smp_config)(void);
13591 void (*get_smp_config)(unsigned int early);
13592 -};
13593 +} __no_const;
13594
13595 /**
13596 * struct x86_init_resources - platform specific resource related ops
13597 @@ -43,7 +43,7 @@ struct x86_init_resources {
13598 void (*probe_roms)(void);
13599 void (*reserve_resources)(void);
13600 char *(*memory_setup)(void);
13601 -};
13602 +} __no_const;
13603
13604 /**
13605 * struct x86_init_irqs - platform specific interrupt setup
13606 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13607 void (*pre_vector_init)(void);
13608 void (*intr_init)(void);
13609 void (*trap_init)(void);
13610 -};
13611 +} __no_const;
13612
13613 /**
13614 * struct x86_init_oem - oem platform specific customizing functions
13615 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13616 struct x86_init_oem {
13617 void (*arch_setup)(void);
13618 void (*banner)(void);
13619 -};
13620 +} __no_const;
13621
13622 /**
13623 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13624 @@ -77,7 +77,7 @@ struct x86_init_oem {
13625 */
13626 struct x86_init_mapping {
13627 void (*pagetable_reserve)(u64 start, u64 end);
13628 -};
13629 +} __no_const;
13630
13631 /**
13632 * struct x86_init_paging - platform specific paging functions
13633 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13634 struct x86_init_paging {
13635 void (*pagetable_setup_start)(pgd_t *base);
13636 void (*pagetable_setup_done)(pgd_t *base);
13637 -};
13638 +} __no_const;
13639
13640 /**
13641 * struct x86_init_timers - platform specific timer setup
13642 @@ -102,7 +102,7 @@ struct x86_init_timers {
13643 void (*tsc_pre_init)(void);
13644 void (*timer_init)(void);
13645 void (*wallclock_init)(void);
13646 -};
13647 +} __no_const;
13648
13649 /**
13650 * struct x86_init_iommu - platform specific iommu setup
13651 @@ -110,7 +110,7 @@ struct x86_init_timers {
13652 */
13653 struct x86_init_iommu {
13654 int (*iommu_init)(void);
13655 -};
13656 +} __no_const;
13657
13658 /**
13659 * struct x86_init_pci - platform specific pci init functions
13660 @@ -124,7 +124,7 @@ struct x86_init_pci {
13661 int (*init)(void);
13662 void (*init_irq)(void);
13663 void (*fixup_irqs)(void);
13664 -};
13665 +} __no_const;
13666
13667 /**
13668 * struct x86_init_ops - functions for platform specific setup
13669 @@ -140,7 +140,7 @@ struct x86_init_ops {
13670 struct x86_init_timers timers;
13671 struct x86_init_iommu iommu;
13672 struct x86_init_pci pci;
13673 -};
13674 +} __no_const;
13675
13676 /**
13677 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13678 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13679 void (*setup_percpu_clockev)(void);
13680 void (*early_percpu_clock_init)(void);
13681 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13682 -};
13683 +} __no_const;
13684
13685 /**
13686 * struct x86_platform_ops - platform specific runtime functions
13687 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13688 void (*save_sched_clock_state)(void);
13689 void (*restore_sched_clock_state)(void);
13690 void (*apic_post_init)(void);
13691 -};
13692 +} __no_const;
13693
13694 struct pci_dev;
13695
13696 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13697 void (*teardown_msi_irq)(unsigned int irq);
13698 void (*teardown_msi_irqs)(struct pci_dev *dev);
13699 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13700 -};
13701 +} __no_const;
13702
13703 struct x86_io_apic_ops {
13704 void (*init) (void);
13705 unsigned int (*read) (unsigned int apic, unsigned int reg);
13706 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13707 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13708 -};
13709 +} __no_const;
13710
13711 extern struct x86_init_ops x86_init;
13712 extern struct x86_cpuinit_ops x86_cpuinit;
13713 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13714 index 8a1b6f9..a29c4e4 100644
13715 --- a/arch/x86/include/asm/xsave.h
13716 +++ b/arch/x86/include/asm/xsave.h
13717 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13718 {
13719 int err;
13720
13721 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13722 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13723 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13724 +#endif
13725 +
13726 /*
13727 * Clear the xsave header first, so that reserved fields are
13728 * initialized to zero.
13729 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13730 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13731 {
13732 int err;
13733 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13734 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13735 u32 lmask = mask;
13736 u32 hmask = mask >> 32;
13737
13738 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13739 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13740 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13741 +#endif
13742 +
13743 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13744 "2:\n"
13745 ".section .fixup,\"ax\"\n"
13746 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13747 index 1b8e5a0..354fd59 100644
13748 --- a/arch/x86/kernel/acpi/sleep.c
13749 +++ b/arch/x86/kernel/acpi/sleep.c
13750 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13751 #else /* CONFIG_64BIT */
13752 #ifdef CONFIG_SMP
13753 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13754 +
13755 + pax_open_kernel();
13756 early_gdt_descr.address =
13757 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13758 + pax_close_kernel();
13759 +
13760 initial_gs = per_cpu_offset(smp_processor_id());
13761 #endif
13762 initial_code = (unsigned long)wakeup_long64;
13763 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13764 index 13ab720..95d5442 100644
13765 --- a/arch/x86/kernel/acpi/wakeup_32.S
13766 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13767 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13768 # and restore the stack ... but you need gdt for this to work
13769 movl saved_context_esp, %esp
13770
13771 - movl %cs:saved_magic, %eax
13772 - cmpl $0x12345678, %eax
13773 + cmpl $0x12345678, saved_magic
13774 jne bogus_magic
13775
13776 # jump to place where we left off
13777 - movl saved_eip, %eax
13778 - jmp *%eax
13779 + jmp *(saved_eip)
13780
13781 bogus_magic:
13782 jmp bogus_magic
13783 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13784 index ced4534..3e75d69 100644
13785 --- a/arch/x86/kernel/alternative.c
13786 +++ b/arch/x86/kernel/alternative.c
13787 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13788 */
13789 for (a = start; a < end; a++) {
13790 instr = (u8 *)&a->instr_offset + a->instr_offset;
13791 +
13792 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13793 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13794 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13795 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13796 +#endif
13797 +
13798 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13799 BUG_ON(a->replacementlen > a->instrlen);
13800 BUG_ON(a->instrlen > sizeof(insnbuf));
13801 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13802 for (poff = start; poff < end; poff++) {
13803 u8 *ptr = (u8 *)poff + *poff;
13804
13805 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13806 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13807 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13808 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13809 +#endif
13810 +
13811 if (!*poff || ptr < text || ptr >= text_end)
13812 continue;
13813 /* turn DS segment override prefix into lock prefix */
13814 - if (*ptr == 0x3e)
13815 + if (*ktla_ktva(ptr) == 0x3e)
13816 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13817 };
13818 mutex_unlock(&text_mutex);
13819 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13820 for (poff = start; poff < end; poff++) {
13821 u8 *ptr = (u8 *)poff + *poff;
13822
13823 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13824 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13825 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13826 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13827 +#endif
13828 +
13829 if (!*poff || ptr < text || ptr >= text_end)
13830 continue;
13831 /* turn lock prefix into DS segment override prefix */
13832 - if (*ptr == 0xf0)
13833 + if (*ktla_ktva(ptr) == 0xf0)
13834 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13835 };
13836 mutex_unlock(&text_mutex);
13837 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13838
13839 BUG_ON(p->len > MAX_PATCH_LEN);
13840 /* prep the buffer with the original instructions */
13841 - memcpy(insnbuf, p->instr, p->len);
13842 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13843 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13844 (unsigned long)p->instr, p->len);
13845
13846 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13847 if (smp_alt_once)
13848 free_init_pages("SMP alternatives",
13849 (unsigned long)__smp_locks,
13850 - (unsigned long)__smp_locks_end);
13851 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13852
13853 restart_nmi();
13854 }
13855 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13856 * instructions. And on the local CPU you need to be protected again NMI or MCE
13857 * handlers seeing an inconsistent instruction while you patch.
13858 */
13859 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13860 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13861 size_t len)
13862 {
13863 unsigned long flags;
13864 local_irq_save(flags);
13865 - memcpy(addr, opcode, len);
13866 +
13867 + pax_open_kernel();
13868 + memcpy(ktla_ktva(addr), opcode, len);
13869 sync_core();
13870 + pax_close_kernel();
13871 +
13872 local_irq_restore(flags);
13873 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13874 that causes hangs on some VIA CPUs. */
13875 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13876 */
13877 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13878 {
13879 - unsigned long flags;
13880 - char *vaddr;
13881 + unsigned char *vaddr = ktla_ktva(addr);
13882 struct page *pages[2];
13883 - int i;
13884 + size_t i;
13885
13886 if (!core_kernel_text((unsigned long)addr)) {
13887 - pages[0] = vmalloc_to_page(addr);
13888 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13889 + pages[0] = vmalloc_to_page(vaddr);
13890 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13891 } else {
13892 - pages[0] = virt_to_page(addr);
13893 + pages[0] = virt_to_page(vaddr);
13894 WARN_ON(!PageReserved(pages[0]));
13895 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13896 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13897 }
13898 BUG_ON(!pages[0]);
13899 - local_irq_save(flags);
13900 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13901 - if (pages[1])
13902 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13903 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13904 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13905 - clear_fixmap(FIX_TEXT_POKE0);
13906 - if (pages[1])
13907 - clear_fixmap(FIX_TEXT_POKE1);
13908 - local_flush_tlb();
13909 - sync_core();
13910 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13911 - that causes hangs on some VIA CPUs. */
13912 + text_poke_early(addr, opcode, len);
13913 for (i = 0; i < len; i++)
13914 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13915 - local_irq_restore(flags);
13916 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13917 return addr;
13918 }
13919
13920 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13921 index 24deb30..94a3426 100644
13922 --- a/arch/x86/kernel/apic/apic.c
13923 +++ b/arch/x86/kernel/apic/apic.c
13924 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13925 /*
13926 * Debug level, exported for io_apic.c
13927 */
13928 -unsigned int apic_verbosity;
13929 +int apic_verbosity;
13930
13931 int pic_mode;
13932
13933 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13934 apic_write(APIC_ESR, 0);
13935 v1 = apic_read(APIC_ESR);
13936 ack_APIC_irq();
13937 - atomic_inc(&irq_err_count);
13938 + atomic_inc_unchecked(&irq_err_count);
13939
13940 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13941 smp_processor_id(), v0 , v1);
13942 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13943 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13944 /* Should happen once for each apic */
13945 WARN_ON((*drv)->eoi_write == eoi_write);
13946 - (*drv)->eoi_write = eoi_write;
13947 + pax_open_kernel();
13948 + *(void **)&(*drv)->eoi_write = eoi_write;
13949 + pax_close_kernel();
13950 }
13951 }
13952
13953 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13954 index c265593..137c4ac 100644
13955 --- a/arch/x86/kernel/apic/io_apic.c
13956 +++ b/arch/x86/kernel/apic/io_apic.c
13957 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13958 }
13959 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13960
13961 -void lock_vector_lock(void)
13962 +void lock_vector_lock(void) __acquires(vector_lock)
13963 {
13964 /* Used to the online set of cpus does not change
13965 * during assign_irq_vector.
13966 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13967 raw_spin_lock(&vector_lock);
13968 }
13969
13970 -void unlock_vector_lock(void)
13971 +void unlock_vector_lock(void) __releases(vector_lock)
13972 {
13973 raw_spin_unlock(&vector_lock);
13974 }
13975 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13976 ack_APIC_irq();
13977 }
13978
13979 -atomic_t irq_mis_count;
13980 +atomic_unchecked_t irq_mis_count;
13981
13982 #ifdef CONFIG_GENERIC_PENDING_IRQ
13983 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13984 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13985 * at the cpu.
13986 */
13987 if (!(v & (1 << (i & 0x1f)))) {
13988 - atomic_inc(&irq_mis_count);
13989 + atomic_inc_unchecked(&irq_mis_count);
13990
13991 eoi_ioapic_irq(irq, cfg);
13992 }
13993 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13994 index d65464e..1035d31 100644
13995 --- a/arch/x86/kernel/apm_32.c
13996 +++ b/arch/x86/kernel/apm_32.c
13997 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
13998 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13999 * even though they are called in protected mode.
14000 */
14001 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14002 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14003 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14004
14005 static const char driver_version[] = "1.16ac"; /* no spaces */
14006 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14007 BUG_ON(cpu != 0);
14008 gdt = get_cpu_gdt_table(cpu);
14009 save_desc_40 = gdt[0x40 / 8];
14010 +
14011 + pax_open_kernel();
14012 gdt[0x40 / 8] = bad_bios_desc;
14013 + pax_close_kernel();
14014
14015 apm_irq_save(flags);
14016 APM_DO_SAVE_SEGS;
14017 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14018 &call->esi);
14019 APM_DO_RESTORE_SEGS;
14020 apm_irq_restore(flags);
14021 +
14022 + pax_open_kernel();
14023 gdt[0x40 / 8] = save_desc_40;
14024 + pax_close_kernel();
14025 +
14026 put_cpu();
14027
14028 return call->eax & 0xff;
14029 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14030 BUG_ON(cpu != 0);
14031 gdt = get_cpu_gdt_table(cpu);
14032 save_desc_40 = gdt[0x40 / 8];
14033 +
14034 + pax_open_kernel();
14035 gdt[0x40 / 8] = bad_bios_desc;
14036 + pax_close_kernel();
14037
14038 apm_irq_save(flags);
14039 APM_DO_SAVE_SEGS;
14040 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14041 &call->eax);
14042 APM_DO_RESTORE_SEGS;
14043 apm_irq_restore(flags);
14044 +
14045 + pax_open_kernel();
14046 gdt[0x40 / 8] = save_desc_40;
14047 + pax_close_kernel();
14048 +
14049 put_cpu();
14050 return error;
14051 }
14052 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14053 * code to that CPU.
14054 */
14055 gdt = get_cpu_gdt_table(0);
14056 +
14057 + pax_open_kernel();
14058 set_desc_base(&gdt[APM_CS >> 3],
14059 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14060 set_desc_base(&gdt[APM_CS_16 >> 3],
14061 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14062 set_desc_base(&gdt[APM_DS >> 3],
14063 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14064 + pax_close_kernel();
14065
14066 proc_create("apm", 0, NULL, &apm_file_ops);
14067
14068 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14069 index 68de2dc..1f3c720 100644
14070 --- a/arch/x86/kernel/asm-offsets.c
14071 +++ b/arch/x86/kernel/asm-offsets.c
14072 @@ -33,6 +33,8 @@ void common(void) {
14073 OFFSET(TI_status, thread_info, status);
14074 OFFSET(TI_addr_limit, thread_info, addr_limit);
14075 OFFSET(TI_preempt_count, thread_info, preempt_count);
14076 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14077 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14078
14079 BLANK();
14080 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14081 @@ -53,8 +55,26 @@ void common(void) {
14082 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14083 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14084 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14085 +
14086 +#ifdef CONFIG_PAX_KERNEXEC
14087 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14088 #endif
14089
14090 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14091 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14092 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14093 +#ifdef CONFIG_X86_64
14094 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14095 +#endif
14096 +#endif
14097 +
14098 +#endif
14099 +
14100 + BLANK();
14101 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14102 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14103 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14104 +
14105 #ifdef CONFIG_XEN
14106 BLANK();
14107 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14108 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14109 index 1b4754f..fbb4227 100644
14110 --- a/arch/x86/kernel/asm-offsets_64.c
14111 +++ b/arch/x86/kernel/asm-offsets_64.c
14112 @@ -76,6 +76,7 @@ int main(void)
14113 BLANK();
14114 #undef ENTRY
14115
14116 + DEFINE(TSS_size, sizeof(struct tss_struct));
14117 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14118 BLANK();
14119
14120 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14121 index d30a6a9..79becab 100644
14122 --- a/arch/x86/kernel/cpu/Makefile
14123 +++ b/arch/x86/kernel/cpu/Makefile
14124 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14125 CFLAGS_REMOVE_perf_event.o = -pg
14126 endif
14127
14128 -# Make sure load_percpu_segment has no stackprotector
14129 -nostackp := $(call cc-option, -fno-stack-protector)
14130 -CFLAGS_common.o := $(nostackp)
14131 -
14132 obj-y := intel_cacheinfo.o scattered.o topology.o
14133 obj-y += proc.o capflags.o powerflags.o common.o
14134 obj-y += vmware.o hypervisor.o mshyperv.o
14135 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14136 index 9d92e19..49d7d79 100644
14137 --- a/arch/x86/kernel/cpu/amd.c
14138 +++ b/arch/x86/kernel/cpu/amd.c
14139 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14140 unsigned int size)
14141 {
14142 /* AMD errata T13 (order #21922) */
14143 - if ((c->x86 == 6)) {
14144 + if (c->x86 == 6) {
14145 /* Duron Rev A0 */
14146 if (c->x86_model == 3 && c->x86_mask == 0)
14147 size = 64;
14148 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14149 index a5fbc3c..2254849 100644
14150 --- a/arch/x86/kernel/cpu/common.c
14151 +++ b/arch/x86/kernel/cpu/common.c
14152 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14153
14154 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14155
14156 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14157 -#ifdef CONFIG_X86_64
14158 - /*
14159 - * We need valid kernel segments for data and code in long mode too
14160 - * IRET will check the segment types kkeil 2000/10/28
14161 - * Also sysret mandates a special GDT layout
14162 - *
14163 - * TLS descriptors are currently at a different place compared to i386.
14164 - * Hopefully nobody expects them at a fixed place (Wine?)
14165 - */
14166 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14167 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14168 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14169 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14170 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14171 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14172 -#else
14173 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14174 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14175 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14176 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14177 - /*
14178 - * Segments used for calling PnP BIOS have byte granularity.
14179 - * They code segments and data segments have fixed 64k limits,
14180 - * the transfer segment sizes are set at run time.
14181 - */
14182 - /* 32-bit code */
14183 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14184 - /* 16-bit code */
14185 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14186 - /* 16-bit data */
14187 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14188 - /* 16-bit data */
14189 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14190 - /* 16-bit data */
14191 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14192 - /*
14193 - * The APM segments have byte granularity and their bases
14194 - * are set at run time. All have 64k limits.
14195 - */
14196 - /* 32-bit code */
14197 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14198 - /* 16-bit code */
14199 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14200 - /* data */
14201 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14202 -
14203 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14204 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14205 - GDT_STACK_CANARY_INIT
14206 -#endif
14207 -} };
14208 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14209 -
14210 static int __init x86_xsave_setup(char *s)
14211 {
14212 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14213 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14214 {
14215 struct desc_ptr gdt_descr;
14216
14217 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14218 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14219 gdt_descr.size = GDT_SIZE - 1;
14220 load_gdt(&gdt_descr);
14221 /* Reload the per-cpu base */
14222 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14223 /* Filter out anything that depends on CPUID levels we don't have */
14224 filter_cpuid_features(c, true);
14225
14226 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14227 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14228 +#endif
14229 +
14230 /* If the model name is still unset, do table lookup. */
14231 if (!c->x86_model_id[0]) {
14232 const char *p;
14233 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14234 }
14235 __setup("clearcpuid=", setup_disablecpuid);
14236
14237 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14238 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14239 +
14240 #ifdef CONFIG_X86_64
14241 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14242 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14243 - (unsigned long) nmi_idt_table };
14244 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14245
14246 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14247 irq_stack_union) __aligned(PAGE_SIZE);
14248 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14249 EXPORT_PER_CPU_SYMBOL(current_task);
14250
14251 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14252 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14253 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14254 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14255
14256 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14257 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14258 {
14259 memset(regs, 0, sizeof(struct pt_regs));
14260 regs->fs = __KERNEL_PERCPU;
14261 - regs->gs = __KERNEL_STACK_CANARY;
14262 + savesegment(gs, regs->gs);
14263
14264 return regs;
14265 }
14266 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14267 int i;
14268
14269 cpu = stack_smp_processor_id();
14270 - t = &per_cpu(init_tss, cpu);
14271 + t = init_tss + cpu;
14272 oist = &per_cpu(orig_ist, cpu);
14273
14274 #ifdef CONFIG_NUMA
14275 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14276 switch_to_new_gdt(cpu);
14277 loadsegment(fs, 0);
14278
14279 - load_idt((const struct desc_ptr *)&idt_descr);
14280 + load_idt(&idt_descr);
14281
14282 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14283 syscall_init();
14284 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14285 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14286 barrier();
14287
14288 - x86_configure_nx();
14289 if (cpu != 0)
14290 enable_x2apic();
14291
14292 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14293 {
14294 int cpu = smp_processor_id();
14295 struct task_struct *curr = current;
14296 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14297 + struct tss_struct *t = init_tss + cpu;
14298 struct thread_struct *thread = &curr->thread;
14299
14300 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14301 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14302 index 0a4ce29..f211176 100644
14303 --- a/arch/x86/kernel/cpu/intel.c
14304 +++ b/arch/x86/kernel/cpu/intel.c
14305 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14306 * Update the IDT descriptor and reload the IDT so that
14307 * it uses the read-only mapped virtual address.
14308 */
14309 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14310 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14311 load_idt(&idt_descr);
14312 }
14313 #endif
14314 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14315 index 292d025..b520c94 100644
14316 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14317 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14318 @@ -45,6 +45,7 @@
14319 #include <asm/processor.h>
14320 #include <asm/mce.h>
14321 #include <asm/msr.h>
14322 +#include <asm/local.h>
14323
14324 #include "mce-internal.h"
14325
14326 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14327 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14328 m->cs, m->ip);
14329
14330 - if (m->cs == __KERNEL_CS)
14331 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14332 print_symbol("{%s}", m->ip);
14333 pr_cont("\n");
14334 }
14335 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14336
14337 #define PANIC_TIMEOUT 5 /* 5 seconds */
14338
14339 -static atomic_t mce_paniced;
14340 +static atomic_unchecked_t mce_paniced;
14341
14342 static int fake_panic;
14343 -static atomic_t mce_fake_paniced;
14344 +static atomic_unchecked_t mce_fake_paniced;
14345
14346 /* Panic in progress. Enable interrupts and wait for final IPI */
14347 static void wait_for_panic(void)
14348 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14349 /*
14350 * Make sure only one CPU runs in machine check panic
14351 */
14352 - if (atomic_inc_return(&mce_paniced) > 1)
14353 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14354 wait_for_panic();
14355 barrier();
14356
14357 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14358 console_verbose();
14359 } else {
14360 /* Don't log too much for fake panic */
14361 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14362 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14363 return;
14364 }
14365 /* First print corrected ones that are still unlogged */
14366 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14367 * might have been modified by someone else.
14368 */
14369 rmb();
14370 - if (atomic_read(&mce_paniced))
14371 + if (atomic_read_unchecked(&mce_paniced))
14372 wait_for_panic();
14373 if (!monarch_timeout)
14374 goto out;
14375 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14376 }
14377
14378 /* Call the installed machine check handler for this CPU setup. */
14379 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14380 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14381 unexpected_machine_check;
14382
14383 /*
14384 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14385 return;
14386 }
14387
14388 + pax_open_kernel();
14389 machine_check_vector = do_machine_check;
14390 + pax_close_kernel();
14391
14392 __mcheck_cpu_init_generic();
14393 __mcheck_cpu_init_vendor(c);
14394 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14395 */
14396
14397 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14398 -static int mce_chrdev_open_count; /* #times opened */
14399 +static local_t mce_chrdev_open_count; /* #times opened */
14400 static int mce_chrdev_open_exclu; /* already open exclusive? */
14401
14402 static int mce_chrdev_open(struct inode *inode, struct file *file)
14403 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14404 spin_lock(&mce_chrdev_state_lock);
14405
14406 if (mce_chrdev_open_exclu ||
14407 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14408 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14409 spin_unlock(&mce_chrdev_state_lock);
14410
14411 return -EBUSY;
14412 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14413
14414 if (file->f_flags & O_EXCL)
14415 mce_chrdev_open_exclu = 1;
14416 - mce_chrdev_open_count++;
14417 + local_inc(&mce_chrdev_open_count);
14418
14419 spin_unlock(&mce_chrdev_state_lock);
14420
14421 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14422 {
14423 spin_lock(&mce_chrdev_state_lock);
14424
14425 - mce_chrdev_open_count--;
14426 + local_dec(&mce_chrdev_open_count);
14427 mce_chrdev_open_exclu = 0;
14428
14429 spin_unlock(&mce_chrdev_state_lock);
14430 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14431 static void mce_reset(void)
14432 {
14433 cpu_missing = 0;
14434 - atomic_set(&mce_fake_paniced, 0);
14435 + atomic_set_unchecked(&mce_fake_paniced, 0);
14436 atomic_set(&mce_executing, 0);
14437 atomic_set(&mce_callin, 0);
14438 atomic_set(&global_nwo, 0);
14439 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14440 index 2d5454c..51987eb 100644
14441 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14442 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14443 @@ -11,6 +11,7 @@
14444 #include <asm/processor.h>
14445 #include <asm/mce.h>
14446 #include <asm/msr.h>
14447 +#include <asm/pgtable.h>
14448
14449 /* By default disabled */
14450 int mce_p5_enabled __read_mostly;
14451 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14452 if (!cpu_has(c, X86_FEATURE_MCE))
14453 return;
14454
14455 + pax_open_kernel();
14456 machine_check_vector = pentium_machine_check;
14457 + pax_close_kernel();
14458 /* Make sure the vector pointer is visible before we enable MCEs: */
14459 wmb();
14460
14461 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14462 index 2d7998f..17c9de1 100644
14463 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14464 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14465 @@ -10,6 +10,7 @@
14466 #include <asm/processor.h>
14467 #include <asm/mce.h>
14468 #include <asm/msr.h>
14469 +#include <asm/pgtable.h>
14470
14471 /* Machine check handler for WinChip C6: */
14472 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14473 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14474 {
14475 u32 lo, hi;
14476
14477 + pax_open_kernel();
14478 machine_check_vector = winchip_machine_check;
14479 + pax_close_kernel();
14480 /* Make sure the vector pointer is visible before we enable MCEs: */
14481 wmb();
14482
14483 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14484 index 6b96110..0da73eb 100644
14485 --- a/arch/x86/kernel/cpu/mtrr/main.c
14486 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14487 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14488 u64 size_or_mask, size_and_mask;
14489 static bool mtrr_aps_delayed_init;
14490
14491 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14492 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14493
14494 const struct mtrr_ops *mtrr_if;
14495
14496 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14497 index df5e41f..816c719 100644
14498 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14499 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14500 @@ -25,7 +25,7 @@ struct mtrr_ops {
14501 int (*validate_add_page)(unsigned long base, unsigned long size,
14502 unsigned int type);
14503 int (*have_wrcomb)(void);
14504 -};
14505 +} __do_const;
14506
14507 extern int generic_get_free_region(unsigned long base, unsigned long size,
14508 int replace_reg);
14509 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14510 index 915b876..171f845 100644
14511 --- a/arch/x86/kernel/cpu/perf_event.c
14512 +++ b/arch/x86/kernel/cpu/perf_event.c
14513 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14514 if (idx > GDT_ENTRIES)
14515 return 0;
14516
14517 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14518 + desc = get_cpu_gdt_table(smp_processor_id());
14519 }
14520
14521 return get_desc_base(desc + idx);
14522 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14523 break;
14524
14525 perf_callchain_store(entry, frame.return_address);
14526 - fp = frame.next_frame;
14527 + fp = (const void __force_user *)frame.next_frame;
14528 }
14529 }
14530
14531 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14532 index 6bca492..36e4496 100644
14533 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14534 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14535 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14536 * v2 and above have a perf capabilities MSR
14537 */
14538 if (version > 1) {
14539 - u64 capabilities;
14540 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14541
14542 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14543 - x86_pmu.intel_cap.capabilities = capabilities;
14544 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14545 + x86_pmu.intel_cap.capabilities = capabilities;
14546 }
14547
14548 intel_ds_init();
14549 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14550 index 13ad899..f642b9a 100644
14551 --- a/arch/x86/kernel/crash.c
14552 +++ b/arch/x86/kernel/crash.c
14553 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14554 {
14555 #ifdef CONFIG_X86_32
14556 struct pt_regs fixed_regs;
14557 -#endif
14558
14559 -#ifdef CONFIG_X86_32
14560 - if (!user_mode_vm(regs)) {
14561 + if (!user_mode(regs)) {
14562 crash_fixup_ss_esp(&fixed_regs, regs);
14563 regs = &fixed_regs;
14564 }
14565 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14566 index 37250fe..bf2ec74 100644
14567 --- a/arch/x86/kernel/doublefault_32.c
14568 +++ b/arch/x86/kernel/doublefault_32.c
14569 @@ -11,7 +11,7 @@
14570
14571 #define DOUBLEFAULT_STACKSIZE (1024)
14572 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14573 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14574 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14575
14576 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14577
14578 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14579 unsigned long gdt, tss;
14580
14581 store_gdt(&gdt_desc);
14582 - gdt = gdt_desc.address;
14583 + gdt = (unsigned long)gdt_desc.address;
14584
14585 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14586
14587 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14588 /* 0x2 bit is always set */
14589 .flags = X86_EFLAGS_SF | 0x2,
14590 .sp = STACK_START,
14591 - .es = __USER_DS,
14592 + .es = __KERNEL_DS,
14593 .cs = __KERNEL_CS,
14594 .ss = __KERNEL_DS,
14595 - .ds = __USER_DS,
14596 + .ds = __KERNEL_DS,
14597 .fs = __KERNEL_PERCPU,
14598
14599 .__cr3 = __pa_nodebug(swapper_pg_dir),
14600 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14601 index ae42418b..787c16b 100644
14602 --- a/arch/x86/kernel/dumpstack.c
14603 +++ b/arch/x86/kernel/dumpstack.c
14604 @@ -2,6 +2,9 @@
14605 * Copyright (C) 1991, 1992 Linus Torvalds
14606 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14607 */
14608 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14609 +#define __INCLUDED_BY_HIDESYM 1
14610 +#endif
14611 #include <linux/kallsyms.h>
14612 #include <linux/kprobes.h>
14613 #include <linux/uaccess.h>
14614 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14615 static void
14616 print_ftrace_graph_addr(unsigned long addr, void *data,
14617 const struct stacktrace_ops *ops,
14618 - struct thread_info *tinfo, int *graph)
14619 + struct task_struct *task, int *graph)
14620 {
14621 - struct task_struct *task;
14622 unsigned long ret_addr;
14623 int index;
14624
14625 if (addr != (unsigned long)return_to_handler)
14626 return;
14627
14628 - task = tinfo->task;
14629 index = task->curr_ret_stack;
14630
14631 if (!task->ret_stack || index < *graph)
14632 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 static inline void
14634 print_ftrace_graph_addr(unsigned long addr, void *data,
14635 const struct stacktrace_ops *ops,
14636 - struct thread_info *tinfo, int *graph)
14637 + struct task_struct *task, int *graph)
14638 { }
14639 #endif
14640
14641 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14642 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14643 */
14644
14645 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14646 - void *p, unsigned int size, void *end)
14647 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14648 {
14649 - void *t = tinfo;
14650 if (end) {
14651 if (p < end && p >= (end-THREAD_SIZE))
14652 return 1;
14653 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14654 }
14655
14656 unsigned long
14657 -print_context_stack(struct thread_info *tinfo,
14658 +print_context_stack(struct task_struct *task, void *stack_start,
14659 unsigned long *stack, unsigned long bp,
14660 const struct stacktrace_ops *ops, void *data,
14661 unsigned long *end, int *graph)
14662 {
14663 struct stack_frame *frame = (struct stack_frame *)bp;
14664
14665 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14666 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14667 unsigned long addr;
14668
14669 addr = *stack;
14670 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14671 } else {
14672 ops->address(data, addr, 0);
14673 }
14674 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14675 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14676 }
14677 stack++;
14678 }
14679 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14680 EXPORT_SYMBOL_GPL(print_context_stack);
14681
14682 unsigned long
14683 -print_context_stack_bp(struct thread_info *tinfo,
14684 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14685 unsigned long *stack, unsigned long bp,
14686 const struct stacktrace_ops *ops, void *data,
14687 unsigned long *end, int *graph)
14688 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 struct stack_frame *frame = (struct stack_frame *)bp;
14690 unsigned long *ret_addr = &frame->return_address;
14691
14692 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14693 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14694 unsigned long addr = *ret_addr;
14695
14696 if (!__kernel_text_address(addr))
14697 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14698 ops->address(data, addr, 1);
14699 frame = frame->next_frame;
14700 ret_addr = &frame->return_address;
14701 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14702 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14703 }
14704
14705 return (unsigned long)frame;
14706 @@ -189,7 +188,7 @@ void dump_stack(void)
14707
14708 bp = stack_frame(current, NULL);
14709 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14710 - current->pid, current->comm, print_tainted(),
14711 + task_pid_nr(current), current->comm, print_tainted(),
14712 init_utsname()->release,
14713 (int)strcspn(init_utsname()->version, " "),
14714 init_utsname()->version);
14715 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14716 }
14717 EXPORT_SYMBOL_GPL(oops_begin);
14718
14719 +extern void gr_handle_kernel_exploit(void);
14720 +
14721 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14722 {
14723 if (regs && kexec_should_crash(current))
14724 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14725 panic("Fatal exception in interrupt");
14726 if (panic_on_oops)
14727 panic("Fatal exception");
14728 - do_exit(signr);
14729 +
14730 + gr_handle_kernel_exploit();
14731 +
14732 + do_group_exit(signr);
14733 }
14734
14735 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14736 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14737 print_modules();
14738 show_regs(regs);
14739 #ifdef CONFIG_X86_32
14740 - if (user_mode_vm(regs)) {
14741 + if (user_mode(regs)) {
14742 sp = regs->sp;
14743 ss = regs->ss & 0xffff;
14744 } else {
14745 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14746 unsigned long flags = oops_begin();
14747 int sig = SIGSEGV;
14748
14749 - if (!user_mode_vm(regs))
14750 + if (!user_mode(regs))
14751 report_bug(regs->ip, regs);
14752
14753 if (__die(str, regs, err))
14754 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14755 index 1038a41..ac7e5f6 100644
14756 --- a/arch/x86/kernel/dumpstack_32.c
14757 +++ b/arch/x86/kernel/dumpstack_32.c
14758 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14759 bp = stack_frame(task, regs);
14760
14761 for (;;) {
14762 - struct thread_info *context;
14763 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14764
14765 - context = (struct thread_info *)
14766 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14767 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14768 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14769
14770 - stack = (unsigned long *)context->previous_esp;
14771 - if (!stack)
14772 + if (stack_start == task_stack_page(task))
14773 break;
14774 + stack = *(unsigned long **)stack_start;
14775 if (ops->stack(data, "IRQ") < 0)
14776 break;
14777 touch_nmi_watchdog();
14778 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14779 {
14780 int i;
14781
14782 - __show_regs(regs, !user_mode_vm(regs));
14783 + __show_regs(regs, !user_mode(regs));
14784
14785 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14786 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14787 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14788 * When in-kernel, we also print out the stack and code at the
14789 * time of the fault..
14790 */
14791 - if (!user_mode_vm(regs)) {
14792 + if (!user_mode(regs)) {
14793 unsigned int code_prologue = code_bytes * 43 / 64;
14794 unsigned int code_len = code_bytes;
14795 unsigned char c;
14796 u8 *ip;
14797 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14798
14799 pr_emerg("Stack:\n");
14800 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14801
14802 pr_emerg("Code:");
14803
14804 - ip = (u8 *)regs->ip - code_prologue;
14805 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14806 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14807 /* try starting at IP */
14808 - ip = (u8 *)regs->ip;
14809 + ip = (u8 *)regs->ip + cs_base;
14810 code_len = code_len - code_prologue + 1;
14811 }
14812 for (i = 0; i < code_len; i++, ip++) {
14813 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14814 pr_cont(" Bad EIP value.");
14815 break;
14816 }
14817 - if (ip == (u8 *)regs->ip)
14818 + if (ip == (u8 *)regs->ip + cs_base)
14819 pr_cont(" <%02x>", c);
14820 else
14821 pr_cont(" %02x", c);
14822 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14823 {
14824 unsigned short ud2;
14825
14826 + ip = ktla_ktva(ip);
14827 if (ip < PAGE_OFFSET)
14828 return 0;
14829 if (probe_kernel_address((unsigned short *)ip, ud2))
14830 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14831
14832 return ud2 == 0x0b0f;
14833 }
14834 +
14835 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14836 +void pax_check_alloca(unsigned long size)
14837 +{
14838 + unsigned long sp = (unsigned long)&sp, stack_left;
14839 +
14840 + /* all kernel stacks are of the same size */
14841 + stack_left = sp & (THREAD_SIZE - 1);
14842 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14843 +}
14844 +EXPORT_SYMBOL(pax_check_alloca);
14845 +#endif
14846 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14847 index b653675..33190c0 100644
14848 --- a/arch/x86/kernel/dumpstack_64.c
14849 +++ b/arch/x86/kernel/dumpstack_64.c
14850 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14851 unsigned long *irq_stack_end =
14852 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14853 unsigned used = 0;
14854 - struct thread_info *tinfo;
14855 int graph = 0;
14856 unsigned long dummy;
14857 + void *stack_start;
14858
14859 if (!task)
14860 task = current;
14861 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14862 * current stack address. If the stacks consist of nested
14863 * exceptions
14864 */
14865 - tinfo = task_thread_info(task);
14866 for (;;) {
14867 char *id;
14868 unsigned long *estack_end;
14869 +
14870 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14871 &used, &id);
14872
14873 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 if (ops->stack(data, id) < 0)
14875 break;
14876
14877 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14878 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14879 data, estack_end, &graph);
14880 ops->stack(data, "<EOE>");
14881 /*
14882 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 * second-to-last pointer (index -2 to end) in the
14884 * exception stack:
14885 */
14886 + if ((u16)estack_end[-1] != __KERNEL_DS)
14887 + goto out;
14888 stack = (unsigned long *) estack_end[-2];
14889 continue;
14890 }
14891 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14893 if (ops->stack(data, "IRQ") < 0)
14894 break;
14895 - bp = ops->walk_stack(tinfo, stack, bp,
14896 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14897 ops, data, irq_stack_end, &graph);
14898 /*
14899 * We link to the next stack (which would be
14900 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14901 /*
14902 * This handles the process stack:
14903 */
14904 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14905 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14906 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14907 +out:
14908 put_cpu();
14909 }
14910 EXPORT_SYMBOL(dump_trace);
14911 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14912
14913 return ud2 == 0x0b0f;
14914 }
14915 +
14916 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14917 +void pax_check_alloca(unsigned long size)
14918 +{
14919 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14920 + unsigned cpu, used;
14921 + char *id;
14922 +
14923 + /* check the process stack first */
14924 + stack_start = (unsigned long)task_stack_page(current);
14925 + stack_end = stack_start + THREAD_SIZE;
14926 + if (likely(stack_start <= sp && sp < stack_end)) {
14927 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14928 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14929 + return;
14930 + }
14931 +
14932 + cpu = get_cpu();
14933 +
14934 + /* check the irq stacks */
14935 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14936 + stack_start = stack_end - IRQ_STACK_SIZE;
14937 + if (stack_start <= sp && sp < stack_end) {
14938 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14939 + put_cpu();
14940 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14941 + return;
14942 + }
14943 +
14944 + /* check the exception stacks */
14945 + used = 0;
14946 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14947 + stack_start = stack_end - EXCEPTION_STKSZ;
14948 + if (stack_end && stack_start <= sp && sp < stack_end) {
14949 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14950 + put_cpu();
14951 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14952 + return;
14953 + }
14954 +
14955 + put_cpu();
14956 +
14957 + /* unknown stack */
14958 + BUG();
14959 +}
14960 +EXPORT_SYMBOL(pax_check_alloca);
14961 +#endif
14962 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14963 index 9b9f18b..9fcaa04 100644
14964 --- a/arch/x86/kernel/early_printk.c
14965 +++ b/arch/x86/kernel/early_printk.c
14966 @@ -7,6 +7,7 @@
14967 #include <linux/pci_regs.h>
14968 #include <linux/pci_ids.h>
14969 #include <linux/errno.h>
14970 +#include <linux/sched.h>
14971 #include <asm/io.h>
14972 #include <asm/processor.h>
14973 #include <asm/fcntl.h>
14974 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14975 index 623f288..8bdd78a 100644
14976 --- a/arch/x86/kernel/entry_32.S
14977 +++ b/arch/x86/kernel/entry_32.S
14978 @@ -176,13 +176,153 @@
14979 /*CFI_REL_OFFSET gs, PT_GS*/
14980 .endm
14981 .macro SET_KERNEL_GS reg
14982 +
14983 +#ifdef CONFIG_CC_STACKPROTECTOR
14984 movl $(__KERNEL_STACK_CANARY), \reg
14985 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14986 + movl $(__USER_DS), \reg
14987 +#else
14988 + xorl \reg, \reg
14989 +#endif
14990 +
14991 movl \reg, %gs
14992 .endm
14993
14994 #endif /* CONFIG_X86_32_LAZY_GS */
14995
14996 -.macro SAVE_ALL
14997 +.macro pax_enter_kernel
14998 +#ifdef CONFIG_PAX_KERNEXEC
14999 + call pax_enter_kernel
15000 +#endif
15001 +.endm
15002 +
15003 +.macro pax_exit_kernel
15004 +#ifdef CONFIG_PAX_KERNEXEC
15005 + call pax_exit_kernel
15006 +#endif
15007 +.endm
15008 +
15009 +#ifdef CONFIG_PAX_KERNEXEC
15010 +ENTRY(pax_enter_kernel)
15011 +#ifdef CONFIG_PARAVIRT
15012 + pushl %eax
15013 + pushl %ecx
15014 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15015 + mov %eax, %esi
15016 +#else
15017 + mov %cr0, %esi
15018 +#endif
15019 + bts $16, %esi
15020 + jnc 1f
15021 + mov %cs, %esi
15022 + cmp $__KERNEL_CS, %esi
15023 + jz 3f
15024 + ljmp $__KERNEL_CS, $3f
15025 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15026 +2:
15027 +#ifdef CONFIG_PARAVIRT
15028 + mov %esi, %eax
15029 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15030 +#else
15031 + mov %esi, %cr0
15032 +#endif
15033 +3:
15034 +#ifdef CONFIG_PARAVIRT
15035 + popl %ecx
15036 + popl %eax
15037 +#endif
15038 + ret
15039 +ENDPROC(pax_enter_kernel)
15040 +
15041 +ENTRY(pax_exit_kernel)
15042 +#ifdef CONFIG_PARAVIRT
15043 + pushl %eax
15044 + pushl %ecx
15045 +#endif
15046 + mov %cs, %esi
15047 + cmp $__KERNEXEC_KERNEL_CS, %esi
15048 + jnz 2f
15049 +#ifdef CONFIG_PARAVIRT
15050 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15051 + mov %eax, %esi
15052 +#else
15053 + mov %cr0, %esi
15054 +#endif
15055 + btr $16, %esi
15056 + ljmp $__KERNEL_CS, $1f
15057 +1:
15058 +#ifdef CONFIG_PARAVIRT
15059 + mov %esi, %eax
15060 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15061 +#else
15062 + mov %esi, %cr0
15063 +#endif
15064 +2:
15065 +#ifdef CONFIG_PARAVIRT
15066 + popl %ecx
15067 + popl %eax
15068 +#endif
15069 + ret
15070 +ENDPROC(pax_exit_kernel)
15071 +#endif
15072 +
15073 +.macro pax_erase_kstack
15074 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15075 + call pax_erase_kstack
15076 +#endif
15077 +.endm
15078 +
15079 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15080 +/*
15081 + * ebp: thread_info
15082 + */
15083 +ENTRY(pax_erase_kstack)
15084 + pushl %edi
15085 + pushl %ecx
15086 + pushl %eax
15087 +
15088 + mov TI_lowest_stack(%ebp), %edi
15089 + mov $-0xBEEF, %eax
15090 + std
15091 +
15092 +1: mov %edi, %ecx
15093 + and $THREAD_SIZE_asm - 1, %ecx
15094 + shr $2, %ecx
15095 + repne scasl
15096 + jecxz 2f
15097 +
15098 + cmp $2*16, %ecx
15099 + jc 2f
15100 +
15101 + mov $2*16, %ecx
15102 + repe scasl
15103 + jecxz 2f
15104 + jne 1b
15105 +
15106 +2: cld
15107 + mov %esp, %ecx
15108 + sub %edi, %ecx
15109 +
15110 + cmp $THREAD_SIZE_asm, %ecx
15111 + jb 3f
15112 + ud2
15113 +3:
15114 +
15115 + shr $2, %ecx
15116 + rep stosl
15117 +
15118 + mov TI_task_thread_sp0(%ebp), %edi
15119 + sub $128, %edi
15120 + mov %edi, TI_lowest_stack(%ebp)
15121 +
15122 + popl %eax
15123 + popl %ecx
15124 + popl %edi
15125 + ret
15126 +ENDPROC(pax_erase_kstack)
15127 +#endif
15128 +
15129 +.macro __SAVE_ALL _DS
15130 cld
15131 PUSH_GS
15132 pushl_cfi %fs
15133 @@ -205,7 +345,7 @@
15134 CFI_REL_OFFSET ecx, 0
15135 pushl_cfi %ebx
15136 CFI_REL_OFFSET ebx, 0
15137 - movl $(__USER_DS), %edx
15138 + movl $\_DS, %edx
15139 movl %edx, %ds
15140 movl %edx, %es
15141 movl $(__KERNEL_PERCPU), %edx
15142 @@ -213,6 +353,15 @@
15143 SET_KERNEL_GS %edx
15144 .endm
15145
15146 +.macro SAVE_ALL
15147 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15148 + __SAVE_ALL __KERNEL_DS
15149 + pax_enter_kernel
15150 +#else
15151 + __SAVE_ALL __USER_DS
15152 +#endif
15153 +.endm
15154 +
15155 .macro RESTORE_INT_REGS
15156 popl_cfi %ebx
15157 CFI_RESTORE ebx
15158 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15159 popfl_cfi
15160 jmp syscall_exit
15161 CFI_ENDPROC
15162 -END(ret_from_fork)
15163 +ENDPROC(ret_from_fork)
15164
15165 /*
15166 * Interrupt exit functions should be protected against kprobes
15167 @@ -329,7 +478,15 @@ ret_from_intr:
15168 andl $SEGMENT_RPL_MASK, %eax
15169 #endif
15170 cmpl $USER_RPL, %eax
15171 +
15172 +#ifdef CONFIG_PAX_KERNEXEC
15173 + jae resume_userspace
15174 +
15175 + pax_exit_kernel
15176 + jmp resume_kernel
15177 +#else
15178 jb resume_kernel # not returning to v8086 or userspace
15179 +#endif
15180
15181 ENTRY(resume_userspace)
15182 LOCKDEP_SYS_EXIT
15183 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15184 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15185 # int/exception return?
15186 jne work_pending
15187 - jmp restore_all
15188 -END(ret_from_exception)
15189 + jmp restore_all_pax
15190 +ENDPROC(ret_from_exception)
15191
15192 #ifdef CONFIG_PREEMPT
15193 ENTRY(resume_kernel)
15194 @@ -357,7 +514,7 @@ need_resched:
15195 jz restore_all
15196 call preempt_schedule_irq
15197 jmp need_resched
15198 -END(resume_kernel)
15199 +ENDPROC(resume_kernel)
15200 #endif
15201 CFI_ENDPROC
15202 /*
15203 @@ -391,28 +548,43 @@ sysenter_past_esp:
15204 /*CFI_REL_OFFSET cs, 0*/
15205 /*
15206 * Push current_thread_info()->sysenter_return to the stack.
15207 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15208 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15209 */
15210 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15211 + pushl_cfi $0
15212 CFI_REL_OFFSET eip, 0
15213
15214 pushl_cfi %eax
15215 SAVE_ALL
15216 + GET_THREAD_INFO(%ebp)
15217 + movl TI_sysenter_return(%ebp),%ebp
15218 + movl %ebp,PT_EIP(%esp)
15219 ENABLE_INTERRUPTS(CLBR_NONE)
15220
15221 /*
15222 * Load the potential sixth argument from user stack.
15223 * Careful about security.
15224 */
15225 + movl PT_OLDESP(%esp),%ebp
15226 +
15227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15228 + mov PT_OLDSS(%esp),%ds
15229 +1: movl %ds:(%ebp),%ebp
15230 + push %ss
15231 + pop %ds
15232 +#else
15233 cmpl $__PAGE_OFFSET-3,%ebp
15234 jae syscall_fault
15235 1: movl (%ebp),%ebp
15236 +#endif
15237 +
15238 movl %ebp,PT_EBP(%esp)
15239 _ASM_EXTABLE(1b,syscall_fault)
15240
15241 GET_THREAD_INFO(%ebp)
15242
15243 +#ifdef CONFIG_PAX_RANDKSTACK
15244 + pax_erase_kstack
15245 +#endif
15246 +
15247 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15248 jnz sysenter_audit
15249 sysenter_do_call:
15250 @@ -427,12 +599,24 @@ sysenter_do_call:
15251 testl $_TIF_ALLWORK_MASK, %ecx
15252 jne sysexit_audit
15253 sysenter_exit:
15254 +
15255 +#ifdef CONFIG_PAX_RANDKSTACK
15256 + pushl_cfi %eax
15257 + movl %esp, %eax
15258 + call pax_randomize_kstack
15259 + popl_cfi %eax
15260 +#endif
15261 +
15262 + pax_erase_kstack
15263 +
15264 /* if something modifies registers it must also disable sysexit */
15265 movl PT_EIP(%esp), %edx
15266 movl PT_OLDESP(%esp), %ecx
15267 xorl %ebp,%ebp
15268 TRACE_IRQS_ON
15269 1: mov PT_FS(%esp), %fs
15270 +2: mov PT_DS(%esp), %ds
15271 +3: mov PT_ES(%esp), %es
15272 PTGS_TO_GS
15273 ENABLE_INTERRUPTS_SYSEXIT
15274
15275 @@ -449,6 +633,9 @@ sysenter_audit:
15276 movl %eax,%edx /* 2nd arg: syscall number */
15277 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15278 call __audit_syscall_entry
15279 +
15280 + pax_erase_kstack
15281 +
15282 pushl_cfi %ebx
15283 movl PT_EAX(%esp),%eax /* reload syscall number */
15284 jmp sysenter_do_call
15285 @@ -474,10 +661,16 @@ sysexit_audit:
15286
15287 CFI_ENDPROC
15288 .pushsection .fixup,"ax"
15289 -2: movl $0,PT_FS(%esp)
15290 +4: movl $0,PT_FS(%esp)
15291 + jmp 1b
15292 +5: movl $0,PT_DS(%esp)
15293 + jmp 1b
15294 +6: movl $0,PT_ES(%esp)
15295 jmp 1b
15296 .popsection
15297 - _ASM_EXTABLE(1b,2b)
15298 + _ASM_EXTABLE(1b,4b)
15299 + _ASM_EXTABLE(2b,5b)
15300 + _ASM_EXTABLE(3b,6b)
15301 PTGS_TO_GS_EX
15302 ENDPROC(ia32_sysenter_target)
15303
15304 @@ -491,6 +684,11 @@ ENTRY(system_call)
15305 pushl_cfi %eax # save orig_eax
15306 SAVE_ALL
15307 GET_THREAD_INFO(%ebp)
15308 +
15309 +#ifdef CONFIG_PAX_RANDKSTACK
15310 + pax_erase_kstack
15311 +#endif
15312 +
15313 # system call tracing in operation / emulation
15314 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15315 jnz syscall_trace_entry
15316 @@ -509,6 +707,15 @@ syscall_exit:
15317 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15318 jne syscall_exit_work
15319
15320 +restore_all_pax:
15321 +
15322 +#ifdef CONFIG_PAX_RANDKSTACK
15323 + movl %esp, %eax
15324 + call pax_randomize_kstack
15325 +#endif
15326 +
15327 + pax_erase_kstack
15328 +
15329 restore_all:
15330 TRACE_IRQS_IRET
15331 restore_all_notrace:
15332 @@ -565,14 +772,34 @@ ldt_ss:
15333 * compensating for the offset by changing to the ESPFIX segment with
15334 * a base address that matches for the difference.
15335 */
15336 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15337 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15338 mov %esp, %edx /* load kernel esp */
15339 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15340 mov %dx, %ax /* eax: new kernel esp */
15341 sub %eax, %edx /* offset (low word is 0) */
15342 +#ifdef CONFIG_SMP
15343 + movl PER_CPU_VAR(cpu_number), %ebx
15344 + shll $PAGE_SHIFT_asm, %ebx
15345 + addl $cpu_gdt_table, %ebx
15346 +#else
15347 + movl $cpu_gdt_table, %ebx
15348 +#endif
15349 shr $16, %edx
15350 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15351 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15352 +
15353 +#ifdef CONFIG_PAX_KERNEXEC
15354 + mov %cr0, %esi
15355 + btr $16, %esi
15356 + mov %esi, %cr0
15357 +#endif
15358 +
15359 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15360 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15361 +
15362 +#ifdef CONFIG_PAX_KERNEXEC
15363 + bts $16, %esi
15364 + mov %esi, %cr0
15365 +#endif
15366 +
15367 pushl_cfi $__ESPFIX_SS
15368 pushl_cfi %eax /* new kernel esp */
15369 /* Disable interrupts, but do not irqtrace this section: we
15370 @@ -601,35 +828,23 @@ work_resched:
15371 movl TI_flags(%ebp), %ecx
15372 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15373 # than syscall tracing?
15374 - jz restore_all
15375 + jz restore_all_pax
15376 testb $_TIF_NEED_RESCHED, %cl
15377 jnz work_resched
15378
15379 work_notifysig: # deal with pending signals and
15380 # notify-resume requests
15381 + movl %esp, %eax
15382 #ifdef CONFIG_VM86
15383 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15384 - movl %esp, %eax
15385 - jne work_notifysig_v86 # returning to kernel-space or
15386 + jz 1f # returning to kernel-space or
15387 # vm86-space
15388 - TRACE_IRQS_ON
15389 - ENABLE_INTERRUPTS(CLBR_NONE)
15390 - movb PT_CS(%esp), %bl
15391 - andb $SEGMENT_RPL_MASK, %bl
15392 - cmpb $USER_RPL, %bl
15393 - jb resume_kernel
15394 - xorl %edx, %edx
15395 - call do_notify_resume
15396 - jmp resume_userspace
15397
15398 - ALIGN
15399 -work_notifysig_v86:
15400 pushl_cfi %ecx # save ti_flags for do_notify_resume
15401 call save_v86_state # %eax contains pt_regs pointer
15402 popl_cfi %ecx
15403 movl %eax, %esp
15404 -#else
15405 - movl %esp, %eax
15406 +1:
15407 #endif
15408 TRACE_IRQS_ON
15409 ENABLE_INTERRUPTS(CLBR_NONE)
15410 @@ -640,7 +855,7 @@ work_notifysig_v86:
15411 xorl %edx, %edx
15412 call do_notify_resume
15413 jmp resume_userspace
15414 -END(work_pending)
15415 +ENDPROC(work_pending)
15416
15417 # perform syscall exit tracing
15418 ALIGN
15419 @@ -648,11 +863,14 @@ syscall_trace_entry:
15420 movl $-ENOSYS,PT_EAX(%esp)
15421 movl %esp, %eax
15422 call syscall_trace_enter
15423 +
15424 + pax_erase_kstack
15425 +
15426 /* What it returned is what we'll actually use. */
15427 cmpl $(NR_syscalls), %eax
15428 jnae syscall_call
15429 jmp syscall_exit
15430 -END(syscall_trace_entry)
15431 +ENDPROC(syscall_trace_entry)
15432
15433 # perform syscall exit tracing
15434 ALIGN
15435 @@ -665,20 +883,24 @@ syscall_exit_work:
15436 movl %esp, %eax
15437 call syscall_trace_leave
15438 jmp resume_userspace
15439 -END(syscall_exit_work)
15440 +ENDPROC(syscall_exit_work)
15441 CFI_ENDPROC
15442
15443 RING0_INT_FRAME # can't unwind into user space anyway
15444 syscall_fault:
15445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15446 + push %ss
15447 + pop %ds
15448 +#endif
15449 GET_THREAD_INFO(%ebp)
15450 movl $-EFAULT,PT_EAX(%esp)
15451 jmp resume_userspace
15452 -END(syscall_fault)
15453 +ENDPROC(syscall_fault)
15454
15455 syscall_badsys:
15456 movl $-ENOSYS,PT_EAX(%esp)
15457 jmp resume_userspace
15458 -END(syscall_badsys)
15459 +ENDPROC(syscall_badsys)
15460 CFI_ENDPROC
15461 /*
15462 * End of kprobes section
15463 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15464 CFI_ENDPROC
15465 ENDPROC(ptregs_clone)
15466
15467 + ALIGN;
15468 +ENTRY(kernel_execve)
15469 + CFI_STARTPROC
15470 + pushl_cfi %ebp
15471 + sub $PT_OLDSS+4,%esp
15472 + pushl_cfi %edi
15473 + pushl_cfi %ecx
15474 + pushl_cfi %eax
15475 + lea 3*4(%esp),%edi
15476 + mov $PT_OLDSS/4+1,%ecx
15477 + xorl %eax,%eax
15478 + rep stosl
15479 + popl_cfi %eax
15480 + popl_cfi %ecx
15481 + popl_cfi %edi
15482 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15483 + pushl_cfi %esp
15484 + call sys_execve
15485 + add $4,%esp
15486 + CFI_ADJUST_CFA_OFFSET -4
15487 + GET_THREAD_INFO(%ebp)
15488 + test %eax,%eax
15489 + jz syscall_exit
15490 + add $PT_OLDSS+4,%esp
15491 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15492 + popl_cfi %ebp
15493 + ret
15494 + CFI_ENDPROC
15495 +ENDPROC(kernel_execve)
15496 +
15497 .macro FIXUP_ESPFIX_STACK
15498 /*
15499 * Switch back for ESPFIX stack to the normal zerobased stack
15500 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15501 * normal stack and adjusts ESP with the matching offset.
15502 */
15503 /* fixup the stack */
15504 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15505 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15506 +#ifdef CONFIG_SMP
15507 + movl PER_CPU_VAR(cpu_number), %ebx
15508 + shll $PAGE_SHIFT_asm, %ebx
15509 + addl $cpu_gdt_table, %ebx
15510 +#else
15511 + movl $cpu_gdt_table, %ebx
15512 +#endif
15513 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15514 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15515 shl $16, %eax
15516 addl %esp, %eax /* the adjusted stack pointer */
15517 pushl_cfi $__KERNEL_DS
15518 @@ -813,7 +1072,7 @@ vector=vector+1
15519 .endr
15520 2: jmp common_interrupt
15521 .endr
15522 -END(irq_entries_start)
15523 +ENDPROC(irq_entries_start)
15524
15525 .previous
15526 END(interrupt)
15527 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15528 pushl_cfi $do_coprocessor_error
15529 jmp error_code
15530 CFI_ENDPROC
15531 -END(coprocessor_error)
15532 +ENDPROC(coprocessor_error)
15533
15534 ENTRY(simd_coprocessor_error)
15535 RING0_INT_FRAME
15536 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15537 #endif
15538 jmp error_code
15539 CFI_ENDPROC
15540 -END(simd_coprocessor_error)
15541 +ENDPROC(simd_coprocessor_error)
15542
15543 ENTRY(device_not_available)
15544 RING0_INT_FRAME
15545 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15546 pushl_cfi $do_device_not_available
15547 jmp error_code
15548 CFI_ENDPROC
15549 -END(device_not_available)
15550 +ENDPROC(device_not_available)
15551
15552 #ifdef CONFIG_PARAVIRT
15553 ENTRY(native_iret)
15554 iret
15555 _ASM_EXTABLE(native_iret, iret_exc)
15556 -END(native_iret)
15557 +ENDPROC(native_iret)
15558
15559 ENTRY(native_irq_enable_sysexit)
15560 sti
15561 sysexit
15562 -END(native_irq_enable_sysexit)
15563 +ENDPROC(native_irq_enable_sysexit)
15564 #endif
15565
15566 ENTRY(overflow)
15567 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15568 pushl_cfi $do_overflow
15569 jmp error_code
15570 CFI_ENDPROC
15571 -END(overflow)
15572 +ENDPROC(overflow)
15573
15574 ENTRY(bounds)
15575 RING0_INT_FRAME
15576 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15577 pushl_cfi $do_bounds
15578 jmp error_code
15579 CFI_ENDPROC
15580 -END(bounds)
15581 +ENDPROC(bounds)
15582
15583 ENTRY(invalid_op)
15584 RING0_INT_FRAME
15585 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15586 pushl_cfi $do_invalid_op
15587 jmp error_code
15588 CFI_ENDPROC
15589 -END(invalid_op)
15590 +ENDPROC(invalid_op)
15591
15592 ENTRY(coprocessor_segment_overrun)
15593 RING0_INT_FRAME
15594 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15595 pushl_cfi $do_coprocessor_segment_overrun
15596 jmp error_code
15597 CFI_ENDPROC
15598 -END(coprocessor_segment_overrun)
15599 +ENDPROC(coprocessor_segment_overrun)
15600
15601 ENTRY(invalid_TSS)
15602 RING0_EC_FRAME
15603 pushl_cfi $do_invalid_TSS
15604 jmp error_code
15605 CFI_ENDPROC
15606 -END(invalid_TSS)
15607 +ENDPROC(invalid_TSS)
15608
15609 ENTRY(segment_not_present)
15610 RING0_EC_FRAME
15611 pushl_cfi $do_segment_not_present
15612 jmp error_code
15613 CFI_ENDPROC
15614 -END(segment_not_present)
15615 +ENDPROC(segment_not_present)
15616
15617 ENTRY(stack_segment)
15618 RING0_EC_FRAME
15619 pushl_cfi $do_stack_segment
15620 jmp error_code
15621 CFI_ENDPROC
15622 -END(stack_segment)
15623 +ENDPROC(stack_segment)
15624
15625 ENTRY(alignment_check)
15626 RING0_EC_FRAME
15627 pushl_cfi $do_alignment_check
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(alignment_check)
15631 +ENDPROC(alignment_check)
15632
15633 ENTRY(divide_error)
15634 RING0_INT_FRAME
15635 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15636 pushl_cfi $do_divide_error
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(divide_error)
15640 +ENDPROC(divide_error)
15641
15642 #ifdef CONFIG_X86_MCE
15643 ENTRY(machine_check)
15644 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15645 pushl_cfi machine_check_vector
15646 jmp error_code
15647 CFI_ENDPROC
15648 -END(machine_check)
15649 +ENDPROC(machine_check)
15650 #endif
15651
15652 ENTRY(spurious_interrupt_bug)
15653 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15654 pushl_cfi $do_spurious_interrupt_bug
15655 jmp error_code
15656 CFI_ENDPROC
15657 -END(spurious_interrupt_bug)
15658 +ENDPROC(spurious_interrupt_bug)
15659 /*
15660 * End of kprobes section
15661 */
15662 @@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15663
15664 ENTRY(mcount)
15665 ret
15666 -END(mcount)
15667 +ENDPROC(mcount)
15668
15669 ENTRY(ftrace_caller)
15670 cmpl $0, function_trace_stop
15671 @@ -1129,7 +1388,7 @@ ftrace_graph_call:
15672 .globl ftrace_stub
15673 ftrace_stub:
15674 ret
15675 -END(ftrace_caller)
15676 +ENDPROC(ftrace_caller)
15677
15678 #else /* ! CONFIG_DYNAMIC_FTRACE */
15679
15680 @@ -1165,7 +1424,7 @@ trace:
15681 popl %ecx
15682 popl %eax
15683 jmp ftrace_stub
15684 -END(mcount)
15685 +ENDPROC(mcount)
15686 #endif /* CONFIG_DYNAMIC_FTRACE */
15687 #endif /* CONFIG_FUNCTION_TRACER */
15688
15689 @@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15690 popl %ecx
15691 popl %eax
15692 ret
15693 -END(ftrace_graph_caller)
15694 +ENDPROC(ftrace_graph_caller)
15695
15696 .globl return_to_handler
15697 return_to_handler:
15698 @@ -1241,15 +1500,18 @@ error_code:
15699 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15700 REG_TO_PTGS %ecx
15701 SET_KERNEL_GS %ecx
15702 - movl $(__USER_DS), %ecx
15703 + movl $(__KERNEL_DS), %ecx
15704 movl %ecx, %ds
15705 movl %ecx, %es
15706 +
15707 + pax_enter_kernel
15708 +
15709 TRACE_IRQS_OFF
15710 movl %esp,%eax # pt_regs pointer
15711 call *%edi
15712 jmp ret_from_exception
15713 CFI_ENDPROC
15714 -END(page_fault)
15715 +ENDPROC(page_fault)
15716
15717 /*
15718 * Debug traps and NMI can happen at the one SYSENTER instruction
15719 @@ -1291,7 +1553,7 @@ debug_stack_correct:
15720 call do_debug
15721 jmp ret_from_exception
15722 CFI_ENDPROC
15723 -END(debug)
15724 +ENDPROC(debug)
15725
15726 /*
15727 * NMI is doubly nasty. It can happen _while_ we're handling
15728 @@ -1328,6 +1590,9 @@ nmi_stack_correct:
15729 xorl %edx,%edx # zero error code
15730 movl %esp,%eax # pt_regs pointer
15731 call do_nmi
15732 +
15733 + pax_exit_kernel
15734 +
15735 jmp restore_all_notrace
15736 CFI_ENDPROC
15737
15738 @@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15739 FIXUP_ESPFIX_STACK # %eax == %esp
15740 xorl %edx,%edx # zero error code
15741 call do_nmi
15742 +
15743 + pax_exit_kernel
15744 +
15745 RESTORE_REGS
15746 lss 12+4(%esp), %esp # back to espfix stack
15747 CFI_ADJUST_CFA_OFFSET -24
15748 jmp irq_return
15749 CFI_ENDPROC
15750 -END(nmi)
15751 +ENDPROC(nmi)
15752
15753 ENTRY(int3)
15754 RING0_INT_FRAME
15755 @@ -1381,14 +1649,14 @@ ENTRY(int3)
15756 call do_int3
15757 jmp ret_from_exception
15758 CFI_ENDPROC
15759 -END(int3)
15760 +ENDPROC(int3)
15761
15762 ENTRY(general_protection)
15763 RING0_EC_FRAME
15764 pushl_cfi $do_general_protection
15765 jmp error_code
15766 CFI_ENDPROC
15767 -END(general_protection)
15768 +ENDPROC(general_protection)
15769
15770 #ifdef CONFIG_KVM_GUEST
15771 ENTRY(async_page_fault)
15772 @@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15773 pushl_cfi $do_async_page_fault
15774 jmp error_code
15775 CFI_ENDPROC
15776 -END(async_page_fault)
15777 +ENDPROC(async_page_fault)
15778 #endif
15779
15780 /*
15781 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15782 index 69babd8..4270a51 100644
15783 --- a/arch/x86/kernel/entry_64.S
15784 +++ b/arch/x86/kernel/entry_64.S
15785 @@ -57,6 +57,8 @@
15786 #include <asm/percpu.h>
15787 #include <asm/asm.h>
15788 #include <linux/err.h>
15789 +#include <asm/pgtable.h>
15790 +#include <asm/alternative-asm.h>
15791
15792 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15793 #include <linux/elf-em.h>
15794 @@ -70,8 +72,9 @@
15795 #ifdef CONFIG_FUNCTION_TRACER
15796 #ifdef CONFIG_DYNAMIC_FTRACE
15797 ENTRY(mcount)
15798 + pax_force_retaddr
15799 retq
15800 -END(mcount)
15801 +ENDPROC(mcount)
15802
15803 ENTRY(ftrace_caller)
15804 cmpl $0, function_trace_stop
15805 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15806 #endif
15807
15808 GLOBAL(ftrace_stub)
15809 + pax_force_retaddr
15810 retq
15811 -END(ftrace_caller)
15812 +ENDPROC(ftrace_caller)
15813
15814 #else /* ! CONFIG_DYNAMIC_FTRACE */
15815 ENTRY(mcount)
15816 @@ -114,6 +118,7 @@ ENTRY(mcount)
15817 #endif
15818
15819 GLOBAL(ftrace_stub)
15820 + pax_force_retaddr
15821 retq
15822
15823 trace:
15824 @@ -123,12 +128,13 @@ trace:
15825 movq 8(%rbp), %rsi
15826 subq $MCOUNT_INSN_SIZE, %rdi
15827
15828 + pax_force_fptr ftrace_trace_function
15829 call *ftrace_trace_function
15830
15831 MCOUNT_RESTORE_FRAME
15832
15833 jmp ftrace_stub
15834 -END(mcount)
15835 +ENDPROC(mcount)
15836 #endif /* CONFIG_DYNAMIC_FTRACE */
15837 #endif /* CONFIG_FUNCTION_TRACER */
15838
15839 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15840
15841 MCOUNT_RESTORE_FRAME
15842
15843 + pax_force_retaddr
15844 retq
15845 -END(ftrace_graph_caller)
15846 +ENDPROC(ftrace_graph_caller)
15847
15848 GLOBAL(return_to_handler)
15849 subq $24, %rsp
15850 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15851 movq 8(%rsp), %rdx
15852 movq (%rsp), %rax
15853 addq $24, %rsp
15854 + pax_force_fptr %rdi
15855 jmp *%rdi
15856 #endif
15857
15858 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15859 ENDPROC(native_usergs_sysret64)
15860 #endif /* CONFIG_PARAVIRT */
15861
15862 + .macro ljmpq sel, off
15863 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15864 + .byte 0x48; ljmp *1234f(%rip)
15865 + .pushsection .rodata
15866 + .align 16
15867 + 1234: .quad \off; .word \sel
15868 + .popsection
15869 +#else
15870 + pushq $\sel
15871 + pushq $\off
15872 + lretq
15873 +#endif
15874 + .endm
15875 +
15876 + .macro pax_enter_kernel
15877 + pax_set_fptr_mask
15878 +#ifdef CONFIG_PAX_KERNEXEC
15879 + call pax_enter_kernel
15880 +#endif
15881 + .endm
15882 +
15883 + .macro pax_exit_kernel
15884 +#ifdef CONFIG_PAX_KERNEXEC
15885 + call pax_exit_kernel
15886 +#endif
15887 + .endm
15888 +
15889 +#ifdef CONFIG_PAX_KERNEXEC
15890 +ENTRY(pax_enter_kernel)
15891 + pushq %rdi
15892 +
15893 +#ifdef CONFIG_PARAVIRT
15894 + PV_SAVE_REGS(CLBR_RDI)
15895 +#endif
15896 +
15897 + GET_CR0_INTO_RDI
15898 + bts $16,%rdi
15899 + jnc 3f
15900 + mov %cs,%edi
15901 + cmp $__KERNEL_CS,%edi
15902 + jnz 2f
15903 +1:
15904 +
15905 +#ifdef CONFIG_PARAVIRT
15906 + PV_RESTORE_REGS(CLBR_RDI)
15907 +#endif
15908 +
15909 + popq %rdi
15910 + pax_force_retaddr
15911 + retq
15912 +
15913 +2: ljmpq __KERNEL_CS,1f
15914 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15915 +4: SET_RDI_INTO_CR0
15916 + jmp 1b
15917 +ENDPROC(pax_enter_kernel)
15918 +
15919 +ENTRY(pax_exit_kernel)
15920 + pushq %rdi
15921 +
15922 +#ifdef CONFIG_PARAVIRT
15923 + PV_SAVE_REGS(CLBR_RDI)
15924 +#endif
15925 +
15926 + mov %cs,%rdi
15927 + cmp $__KERNEXEC_KERNEL_CS,%edi
15928 + jz 2f
15929 +1:
15930 +
15931 +#ifdef CONFIG_PARAVIRT
15932 + PV_RESTORE_REGS(CLBR_RDI);
15933 +#endif
15934 +
15935 + popq %rdi
15936 + pax_force_retaddr
15937 + retq
15938 +
15939 +2: GET_CR0_INTO_RDI
15940 + btr $16,%rdi
15941 + ljmpq __KERNEL_CS,3f
15942 +3: SET_RDI_INTO_CR0
15943 + jmp 1b
15944 +#ifdef CONFIG_PARAVIRT
15945 + PV_RESTORE_REGS(CLBR_RDI);
15946 +#endif
15947 +
15948 + popq %rdi
15949 + pax_force_retaddr
15950 + retq
15951 +ENDPROC(pax_exit_kernel)
15952 +#endif
15953 +
15954 + .macro pax_enter_kernel_user
15955 + pax_set_fptr_mask
15956 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15957 + call pax_enter_kernel_user
15958 +#endif
15959 + .endm
15960 +
15961 + .macro pax_exit_kernel_user
15962 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15963 + call pax_exit_kernel_user
15964 +#endif
15965 +#ifdef CONFIG_PAX_RANDKSTACK
15966 + pushq %rax
15967 + call pax_randomize_kstack
15968 + popq %rax
15969 +#endif
15970 + .endm
15971 +
15972 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15973 +ENTRY(pax_enter_kernel_user)
15974 + pushq %rdi
15975 + pushq %rbx
15976 +
15977 +#ifdef CONFIG_PARAVIRT
15978 + PV_SAVE_REGS(CLBR_RDI)
15979 +#endif
15980 +
15981 + GET_CR3_INTO_RDI
15982 + mov %rdi,%rbx
15983 + add $__START_KERNEL_map,%rbx
15984 + sub phys_base(%rip),%rbx
15985 +
15986 +#ifdef CONFIG_PARAVIRT
15987 + pushq %rdi
15988 + cmpl $0, pv_info+PARAVIRT_enabled
15989 + jz 1f
15990 + i = 0
15991 + .rept USER_PGD_PTRS
15992 + mov i*8(%rbx),%rsi
15993 + mov $0,%sil
15994 + lea i*8(%rbx),%rdi
15995 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15996 + i = i + 1
15997 + .endr
15998 + jmp 2f
15999 +1:
16000 +#endif
16001 +
16002 + i = 0
16003 + .rept USER_PGD_PTRS
16004 + movb $0,i*8(%rbx)
16005 + i = i + 1
16006 + .endr
16007 +
16008 +#ifdef CONFIG_PARAVIRT
16009 +2: popq %rdi
16010 +#endif
16011 + SET_RDI_INTO_CR3
16012 +
16013 +#ifdef CONFIG_PAX_KERNEXEC
16014 + GET_CR0_INTO_RDI
16015 + bts $16,%rdi
16016 + SET_RDI_INTO_CR0
16017 +#endif
16018 +
16019 +#ifdef CONFIG_PARAVIRT
16020 + PV_RESTORE_REGS(CLBR_RDI)
16021 +#endif
16022 +
16023 + popq %rbx
16024 + popq %rdi
16025 + pax_force_retaddr
16026 + retq
16027 +ENDPROC(pax_enter_kernel_user)
16028 +
16029 +ENTRY(pax_exit_kernel_user)
16030 + push %rdi
16031 +
16032 +#ifdef CONFIG_PARAVIRT
16033 + pushq %rbx
16034 + PV_SAVE_REGS(CLBR_RDI)
16035 +#endif
16036 +
16037 +#ifdef CONFIG_PAX_KERNEXEC
16038 + GET_CR0_INTO_RDI
16039 + btr $16,%rdi
16040 + SET_RDI_INTO_CR0
16041 +#endif
16042 +
16043 + GET_CR3_INTO_RDI
16044 + add $__START_KERNEL_map,%rdi
16045 + sub phys_base(%rip),%rdi
16046 +
16047 +#ifdef CONFIG_PARAVIRT
16048 + cmpl $0, pv_info+PARAVIRT_enabled
16049 + jz 1f
16050 + mov %rdi,%rbx
16051 + i = 0
16052 + .rept USER_PGD_PTRS
16053 + mov i*8(%rbx),%rsi
16054 + mov $0x67,%sil
16055 + lea i*8(%rbx),%rdi
16056 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16057 + i = i + 1
16058 + .endr
16059 + jmp 2f
16060 +1:
16061 +#endif
16062 +
16063 + i = 0
16064 + .rept USER_PGD_PTRS
16065 + movb $0x67,i*8(%rdi)
16066 + i = i + 1
16067 + .endr
16068 +
16069 +#ifdef CONFIG_PARAVIRT
16070 +2: PV_RESTORE_REGS(CLBR_RDI)
16071 + popq %rbx
16072 +#endif
16073 +
16074 + popq %rdi
16075 + pax_force_retaddr
16076 + retq
16077 +ENDPROC(pax_exit_kernel_user)
16078 +#endif
16079 +
16080 +.macro pax_erase_kstack
16081 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16082 + call pax_erase_kstack
16083 +#endif
16084 +.endm
16085 +
16086 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16087 +ENTRY(pax_erase_kstack)
16088 + pushq %rdi
16089 + pushq %rcx
16090 + pushq %rax
16091 + pushq %r11
16092 +
16093 + GET_THREAD_INFO(%r11)
16094 + mov TI_lowest_stack(%r11), %rdi
16095 + mov $-0xBEEF, %rax
16096 + std
16097 +
16098 +1: mov %edi, %ecx
16099 + and $THREAD_SIZE_asm - 1, %ecx
16100 + shr $3, %ecx
16101 + repne scasq
16102 + jecxz 2f
16103 +
16104 + cmp $2*8, %ecx
16105 + jc 2f
16106 +
16107 + mov $2*8, %ecx
16108 + repe scasq
16109 + jecxz 2f
16110 + jne 1b
16111 +
16112 +2: cld
16113 + mov %esp, %ecx
16114 + sub %edi, %ecx
16115 +
16116 + cmp $THREAD_SIZE_asm, %rcx
16117 + jb 3f
16118 + ud2
16119 +3:
16120 +
16121 + shr $3, %ecx
16122 + rep stosq
16123 +
16124 + mov TI_task_thread_sp0(%r11), %rdi
16125 + sub $256, %rdi
16126 + mov %rdi, TI_lowest_stack(%r11)
16127 +
16128 + popq %r11
16129 + popq %rax
16130 + popq %rcx
16131 + popq %rdi
16132 + pax_force_retaddr
16133 + ret
16134 +ENDPROC(pax_erase_kstack)
16135 +#endif
16136
16137 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16138 #ifdef CONFIG_TRACE_IRQFLAGS
16139 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16140 .endm
16141
16142 .macro UNFAKE_STACK_FRAME
16143 - addq $8*6, %rsp
16144 - CFI_ADJUST_CFA_OFFSET -(6*8)
16145 + addq $8*6 + ARG_SKIP, %rsp
16146 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16147 .endm
16148
16149 /*
16150 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16151 movq %rsp, %rsi
16152
16153 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16154 - testl $3, CS-RBP(%rsi)
16155 + testb $3, CS-RBP(%rsi)
16156 je 1f
16157 SWAPGS
16158 /*
16159 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16160 movq_cfi r15, R15+16
16161 movq %r11, 8(%rsp) /* return address */
16162 FIXUP_TOP_OF_STACK %r11, 16
16163 + pax_force_retaddr
16164 ret
16165 CFI_ENDPROC
16166 -END(save_rest)
16167 +ENDPROC(save_rest)
16168
16169 /* save complete stack frame */
16170 .pushsection .kprobes.text, "ax"
16171 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16172 js 1f /* negative -> in kernel */
16173 SWAPGS
16174 xorl %ebx,%ebx
16175 -1: ret
16176 +1: pax_force_retaddr_bts
16177 + ret
16178 CFI_ENDPROC
16179 -END(save_paranoid)
16180 +ENDPROC(save_paranoid)
16181 .popsection
16182
16183 /*
16184 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16185
16186 RESTORE_REST
16187
16188 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16189 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16190 jz retint_restore_args
16191
16192 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16193 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16194 jmp ret_from_sys_call # go to the SYSRET fastpath
16195
16196 CFI_ENDPROC
16197 -END(ret_from_fork)
16198 +ENDPROC(ret_from_fork)
16199
16200 /*
16201 * System call entry. Up to 6 arguments in registers are supported.
16202 @@ -495,7 +779,7 @@ END(ret_from_fork)
16203 ENTRY(system_call)
16204 CFI_STARTPROC simple
16205 CFI_SIGNAL_FRAME
16206 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16207 + CFI_DEF_CFA rsp,0
16208 CFI_REGISTER rip,rcx
16209 /*CFI_REGISTER rflags,r11*/
16210 SWAPGS_UNSAFE_STACK
16211 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16212
16213 movq %rsp,PER_CPU_VAR(old_rsp)
16214 movq PER_CPU_VAR(kernel_stack),%rsp
16215 + SAVE_ARGS 8*6,0
16216 + pax_enter_kernel_user
16217 +
16218 +#ifdef CONFIG_PAX_RANDKSTACK
16219 + pax_erase_kstack
16220 +#endif
16221 +
16222 /*
16223 * No need to follow this irqs off/on section - it's straight
16224 * and short:
16225 */
16226 ENABLE_INTERRUPTS(CLBR_NONE)
16227 - SAVE_ARGS 8,0
16228 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16229 movq %rcx,RIP-ARGOFFSET(%rsp)
16230 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16231 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16232 + GET_THREAD_INFO(%rcx)
16233 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16234 jnz tracesys
16235 system_call_fastpath:
16236 #if __SYSCALL_MASK == ~0
16237 @@ -527,7 +818,7 @@ system_call_fastpath:
16238 cmpl $__NR_syscall_max,%eax
16239 #endif
16240 ja badsys
16241 - movq %r10,%rcx
16242 + movq R10-ARGOFFSET(%rsp),%rcx
16243 call *sys_call_table(,%rax,8) # XXX: rip relative
16244 movq %rax,RAX-ARGOFFSET(%rsp)
16245 /*
16246 @@ -541,10 +832,13 @@ sysret_check:
16247 LOCKDEP_SYS_EXIT
16248 DISABLE_INTERRUPTS(CLBR_NONE)
16249 TRACE_IRQS_OFF
16250 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16251 + GET_THREAD_INFO(%rcx)
16252 + movl TI_flags(%rcx),%edx
16253 andl %edi,%edx
16254 jnz sysret_careful
16255 CFI_REMEMBER_STATE
16256 + pax_exit_kernel_user
16257 + pax_erase_kstack
16258 /*
16259 * sysretq will re-enable interrupts:
16260 */
16261 @@ -596,14 +890,18 @@ badsys:
16262 * jump back to the normal fast path.
16263 */
16264 auditsys:
16265 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16266 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16267 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16268 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16269 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16270 movq %rax,%rsi /* 2nd arg: syscall number */
16271 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16272 call __audit_syscall_entry
16273 +
16274 + pax_erase_kstack
16275 +
16276 LOAD_ARGS 0 /* reload call-clobbered registers */
16277 + pax_set_fptr_mask
16278 jmp system_call_fastpath
16279
16280 /*
16281 @@ -624,7 +922,7 @@ sysret_audit:
16282 /* Do syscall tracing */
16283 tracesys:
16284 #ifdef CONFIG_AUDITSYSCALL
16285 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16286 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16287 jz auditsys
16288 #endif
16289 SAVE_REST
16290 @@ -632,12 +930,16 @@ tracesys:
16291 FIXUP_TOP_OF_STACK %rdi
16292 movq %rsp,%rdi
16293 call syscall_trace_enter
16294 +
16295 + pax_erase_kstack
16296 +
16297 /*
16298 * Reload arg registers from stack in case ptrace changed them.
16299 * We don't reload %rax because syscall_trace_enter() returned
16300 * the value it wants us to use in the table lookup.
16301 */
16302 LOAD_ARGS ARGOFFSET, 1
16303 + pax_set_fptr_mask
16304 RESTORE_REST
16305 #if __SYSCALL_MASK == ~0
16306 cmpq $__NR_syscall_max,%rax
16307 @@ -646,7 +948,7 @@ tracesys:
16308 cmpl $__NR_syscall_max,%eax
16309 #endif
16310 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16311 - movq %r10,%rcx /* fixup for C */
16312 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16313 call *sys_call_table(,%rax,8)
16314 movq %rax,RAX-ARGOFFSET(%rsp)
16315 /* Use IRET because user could have changed frame */
16316 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16317 andl %edi,%edx
16318 jnz int_careful
16319 andl $~TS_COMPAT,TI_status(%rcx)
16320 - jmp retint_swapgs
16321 + pax_exit_kernel_user
16322 + pax_erase_kstack
16323 + jmp retint_swapgs_pax
16324
16325 /* Either reschedule or signal or syscall exit tracking needed. */
16326 /* First do a reschedule test. */
16327 @@ -713,7 +1017,7 @@ int_restore_rest:
16328 TRACE_IRQS_OFF
16329 jmp int_with_check
16330 CFI_ENDPROC
16331 -END(system_call)
16332 +ENDPROC(system_call)
16333
16334 /*
16335 * Certain special system calls that need to save a complete full stack frame.
16336 @@ -729,7 +1033,7 @@ ENTRY(\label)
16337 call \func
16338 jmp ptregscall_common
16339 CFI_ENDPROC
16340 -END(\label)
16341 +ENDPROC(\label)
16342 .endm
16343
16344 PTREGSCALL stub_clone, sys_clone, %r8
16345 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16346 movq_cfi_restore R12+8, r12
16347 movq_cfi_restore RBP+8, rbp
16348 movq_cfi_restore RBX+8, rbx
16349 + pax_force_retaddr
16350 ret $REST_SKIP /* pop extended registers */
16351 CFI_ENDPROC
16352 -END(ptregscall_common)
16353 +ENDPROC(ptregscall_common)
16354
16355 ENTRY(stub_execve)
16356 CFI_STARTPROC
16357 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16358 RESTORE_REST
16359 jmp int_ret_from_sys_call
16360 CFI_ENDPROC
16361 -END(stub_execve)
16362 +ENDPROC(stub_execve)
16363
16364 /*
16365 * sigreturn is special because it needs to restore all registers on return.
16366 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16367 RESTORE_REST
16368 jmp int_ret_from_sys_call
16369 CFI_ENDPROC
16370 -END(stub_rt_sigreturn)
16371 +ENDPROC(stub_rt_sigreturn)
16372
16373 #ifdef CONFIG_X86_X32_ABI
16374 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16375 @@ -851,7 +1156,7 @@ vector=vector+1
16376 2: jmp common_interrupt
16377 .endr
16378 CFI_ENDPROC
16379 -END(irq_entries_start)
16380 +ENDPROC(irq_entries_start)
16381
16382 .previous
16383 END(interrupt)
16384 @@ -871,6 +1176,16 @@ END(interrupt)
16385 subq $ORIG_RAX-RBP, %rsp
16386 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16387 SAVE_ARGS_IRQ
16388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16389 + testb $3, CS(%rdi)
16390 + jnz 1f
16391 + pax_enter_kernel
16392 + jmp 2f
16393 +1: pax_enter_kernel_user
16394 +2:
16395 +#else
16396 + pax_enter_kernel
16397 +#endif
16398 call \func
16399 .endm
16400
16401 @@ -902,7 +1217,7 @@ ret_from_intr:
16402
16403 exit_intr:
16404 GET_THREAD_INFO(%rcx)
16405 - testl $3,CS-ARGOFFSET(%rsp)
16406 + testb $3,CS-ARGOFFSET(%rsp)
16407 je retint_kernel
16408
16409 /* Interrupt came from user space */
16410 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16411 * The iretq could re-enable interrupts:
16412 */
16413 DISABLE_INTERRUPTS(CLBR_ANY)
16414 + pax_exit_kernel_user
16415 +retint_swapgs_pax:
16416 TRACE_IRQS_IRETQ
16417 SWAPGS
16418 jmp restore_args
16419
16420 retint_restore_args: /* return to kernel space */
16421 DISABLE_INTERRUPTS(CLBR_ANY)
16422 + pax_exit_kernel
16423 + pax_force_retaddr RIP-ARGOFFSET
16424 /*
16425 * The iretq could re-enable interrupts:
16426 */
16427 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16428 #endif
16429
16430 CFI_ENDPROC
16431 -END(common_interrupt)
16432 +ENDPROC(common_interrupt)
16433 /*
16434 * End of kprobes section
16435 */
16436 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16437 interrupt \do_sym
16438 jmp ret_from_intr
16439 CFI_ENDPROC
16440 -END(\sym)
16441 +ENDPROC(\sym)
16442 .endm
16443
16444 #ifdef CONFIG_SMP
16445 @@ -1084,12 +1403,22 @@ ENTRY(\sym)
16446 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16447 call error_entry
16448 DEFAULT_FRAME 0
16449 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16450 + testb $3, CS(%rsp)
16451 + jnz 1f
16452 + pax_enter_kernel
16453 + jmp 2f
16454 +1: pax_enter_kernel_user
16455 +2:
16456 +#else
16457 + pax_enter_kernel
16458 +#endif
16459 movq %rsp,%rdi /* pt_regs pointer */
16460 xorl %esi,%esi /* no error code */
16461 call \do_sym
16462 jmp error_exit /* %ebx: no swapgs flag */
16463 CFI_ENDPROC
16464 -END(\sym)
16465 +ENDPROC(\sym)
16466 .endm
16467
16468 .macro paranoidzeroentry sym do_sym
16469 @@ -1101,15 +1430,25 @@ ENTRY(\sym)
16470 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16471 call save_paranoid
16472 TRACE_IRQS_OFF
16473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16474 + testb $3, CS(%rsp)
16475 + jnz 1f
16476 + pax_enter_kernel
16477 + jmp 2f
16478 +1: pax_enter_kernel_user
16479 +2:
16480 +#else
16481 + pax_enter_kernel
16482 +#endif
16483 movq %rsp,%rdi /* pt_regs pointer */
16484 xorl %esi,%esi /* no error code */
16485 call \do_sym
16486 jmp paranoid_exit /* %ebx: no swapgs flag */
16487 CFI_ENDPROC
16488 -END(\sym)
16489 +ENDPROC(\sym)
16490 .endm
16491
16492 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16493 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16494 .macro paranoidzeroentry_ist sym do_sym ist
16495 ENTRY(\sym)
16496 INTR_FRAME
16497 @@ -1119,14 +1458,30 @@ ENTRY(\sym)
16498 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16499 call save_paranoid
16500 TRACE_IRQS_OFF_DEBUG
16501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16502 + testb $3, CS(%rsp)
16503 + jnz 1f
16504 + pax_enter_kernel
16505 + jmp 2f
16506 +1: pax_enter_kernel_user
16507 +2:
16508 +#else
16509 + pax_enter_kernel
16510 +#endif
16511 movq %rsp,%rdi /* pt_regs pointer */
16512 xorl %esi,%esi /* no error code */
16513 +#ifdef CONFIG_SMP
16514 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16515 + lea init_tss(%r12), %r12
16516 +#else
16517 + lea init_tss(%rip), %r12
16518 +#endif
16519 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16520 call \do_sym
16521 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16522 jmp paranoid_exit /* %ebx: no swapgs flag */
16523 CFI_ENDPROC
16524 -END(\sym)
16525 +ENDPROC(\sym)
16526 .endm
16527
16528 .macro errorentry sym do_sym
16529 @@ -1137,13 +1492,23 @@ ENTRY(\sym)
16530 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16531 call error_entry
16532 DEFAULT_FRAME 0
16533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16534 + testb $3, CS(%rsp)
16535 + jnz 1f
16536 + pax_enter_kernel
16537 + jmp 2f
16538 +1: pax_enter_kernel_user
16539 +2:
16540 +#else
16541 + pax_enter_kernel
16542 +#endif
16543 movq %rsp,%rdi /* pt_regs pointer */
16544 movq ORIG_RAX(%rsp),%rsi /* get error code */
16545 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16546 call \do_sym
16547 jmp error_exit /* %ebx: no swapgs flag */
16548 CFI_ENDPROC
16549 -END(\sym)
16550 +ENDPROC(\sym)
16551 .endm
16552
16553 /* error code is on the stack already */
16554 @@ -1156,13 +1521,23 @@ ENTRY(\sym)
16555 call save_paranoid
16556 DEFAULT_FRAME 0
16557 TRACE_IRQS_OFF
16558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16559 + testb $3, CS(%rsp)
16560 + jnz 1f
16561 + pax_enter_kernel
16562 + jmp 2f
16563 +1: pax_enter_kernel_user
16564 +2:
16565 +#else
16566 + pax_enter_kernel
16567 +#endif
16568 movq %rsp,%rdi /* pt_regs pointer */
16569 movq ORIG_RAX(%rsp),%rsi /* get error code */
16570 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16571 call \do_sym
16572 jmp paranoid_exit /* %ebx: no swapgs flag */
16573 CFI_ENDPROC
16574 -END(\sym)
16575 +ENDPROC(\sym)
16576 .endm
16577
16578 zeroentry divide_error do_divide_error
16579 @@ -1192,9 +1567,10 @@ gs_change:
16580 2: mfence /* workaround */
16581 SWAPGS
16582 popfq_cfi
16583 + pax_force_retaddr
16584 ret
16585 CFI_ENDPROC
16586 -END(native_load_gs_index)
16587 +ENDPROC(native_load_gs_index)
16588
16589 _ASM_EXTABLE(gs_change,bad_gs)
16590 .section .fixup,"ax"
16591 @@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16592 * Here we are in the child and the registers are set as they were
16593 * at kernel_thread() invocation in the parent.
16594 */
16595 + pax_force_fptr %rsi
16596 call *%rsi
16597 # exit
16598 mov %eax, %edi
16599 call do_exit
16600 ud2 # padding for call trace
16601 CFI_ENDPROC
16602 -END(kernel_thread_helper)
16603 +ENDPROC(kernel_thread_helper)
16604
16605 /*
16606 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16607 @@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16608 RESTORE_REST
16609 testq %rax,%rax
16610 je int_ret_from_sys_call
16611 - RESTORE_ARGS
16612 UNFAKE_STACK_FRAME
16613 + pax_force_retaddr
16614 ret
16615 CFI_ENDPROC
16616 -END(kernel_execve)
16617 +ENDPROC(kernel_execve)
16618
16619 /* Call softirq on interrupt stack. Interrupts are off. */
16620 ENTRY(call_softirq)
16621 @@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16622 CFI_DEF_CFA_REGISTER rsp
16623 CFI_ADJUST_CFA_OFFSET -8
16624 decl PER_CPU_VAR(irq_count)
16625 + pax_force_retaddr
16626 ret
16627 CFI_ENDPROC
16628 -END(call_softirq)
16629 +ENDPROC(call_softirq)
16630
16631 #ifdef CONFIG_XEN
16632 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16633 @@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16634 decl PER_CPU_VAR(irq_count)
16635 jmp error_exit
16636 CFI_ENDPROC
16637 -END(xen_do_hypervisor_callback)
16638 +ENDPROC(xen_do_hypervisor_callback)
16639
16640 /*
16641 * Hypervisor uses this for application faults while it executes.
16642 @@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16643 SAVE_ALL
16644 jmp error_exit
16645 CFI_ENDPROC
16646 -END(xen_failsafe_callback)
16647 +ENDPROC(xen_failsafe_callback)
16648
16649 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16650 xen_hvm_callback_vector xen_evtchn_do_upcall
16651 @@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16652 TRACE_IRQS_OFF_DEBUG
16653 testl %ebx,%ebx /* swapgs needed? */
16654 jnz paranoid_restore
16655 - testl $3,CS(%rsp)
16656 + testb $3,CS(%rsp)
16657 jnz paranoid_userspace
16658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16659 + pax_exit_kernel
16660 + TRACE_IRQS_IRETQ 0
16661 + SWAPGS_UNSAFE_STACK
16662 + RESTORE_ALL 8
16663 + pax_force_retaddr_bts
16664 + jmp irq_return
16665 +#endif
16666 paranoid_swapgs:
16667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16668 + pax_exit_kernel_user
16669 +#else
16670 + pax_exit_kernel
16671 +#endif
16672 TRACE_IRQS_IRETQ 0
16673 SWAPGS_UNSAFE_STACK
16674 RESTORE_ALL 8
16675 jmp irq_return
16676 paranoid_restore:
16677 + pax_exit_kernel
16678 TRACE_IRQS_IRETQ_DEBUG 0
16679 RESTORE_ALL 8
16680 + pax_force_retaddr_bts
16681 jmp irq_return
16682 paranoid_userspace:
16683 GET_THREAD_INFO(%rcx)
16684 @@ -1454,7 +1847,7 @@ paranoid_schedule:
16685 TRACE_IRQS_OFF
16686 jmp paranoid_userspace
16687 CFI_ENDPROC
16688 -END(paranoid_exit)
16689 +ENDPROC(paranoid_exit)
16690
16691 /*
16692 * Exception entry point. This expects an error code/orig_rax on the stack.
16693 @@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16694 movq_cfi r14, R14+8
16695 movq_cfi r15, R15+8
16696 xorl %ebx,%ebx
16697 - testl $3,CS+8(%rsp)
16698 + testb $3,CS+8(%rsp)
16699 je error_kernelspace
16700 error_swapgs:
16701 SWAPGS
16702 error_sti:
16703 TRACE_IRQS_OFF
16704 + pax_force_retaddr_bts
16705 ret
16706
16707 /*
16708 @@ -1513,7 +1907,7 @@ bstep_iret:
16709 movq %rcx,RIP+8(%rsp)
16710 jmp error_swapgs
16711 CFI_ENDPROC
16712 -END(error_entry)
16713 +ENDPROC(error_entry)
16714
16715
16716 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16717 @@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16718 jnz retint_careful
16719 jmp retint_swapgs
16720 CFI_ENDPROC
16721 -END(error_exit)
16722 +ENDPROC(error_exit)
16723
16724 /*
16725 * Test if a given stack is an NMI stack or not.
16726 @@ -1591,9 +1985,11 @@ ENTRY(nmi)
16727 * If %cs was not the kernel segment, then the NMI triggered in user
16728 * space, which means it is definitely not nested.
16729 */
16730 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16731 + je 1f
16732 cmpl $__KERNEL_CS, 16(%rsp)
16733 jne first_nmi
16734 -
16735 +1:
16736 /*
16737 * Check the special variable on the stack to see if NMIs are
16738 * executing.
16739 @@ -1752,6 +2148,17 @@ end_repeat_nmi:
16740 */
16741 movq %cr2, %r12
16742
16743 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16744 + testb $3, CS(%rsp)
16745 + jnz 1f
16746 + pax_enter_kernel
16747 + jmp 2f
16748 +1: pax_enter_kernel_user
16749 +2:
16750 +#else
16751 + pax_enter_kernel
16752 +#endif
16753 +
16754 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16755 movq %rsp,%rdi
16756 movq $-1,%rsi
16757 @@ -1767,21 +2174,32 @@ end_repeat_nmi:
16758 testl %ebx,%ebx /* swapgs needed? */
16759 jnz nmi_restore
16760 nmi_swapgs:
16761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16762 + pax_exit_kernel_user
16763 +#else
16764 + pax_exit_kernel
16765 +#endif
16766 SWAPGS_UNSAFE_STACK
16767 + RESTORE_ALL 8
16768 + /* Clear the NMI executing stack variable */
16769 + movq $0, 10*8(%rsp)
16770 + jmp irq_return
16771 nmi_restore:
16772 + pax_exit_kernel
16773 RESTORE_ALL 8
16774 + pax_force_retaddr_bts
16775 /* Clear the NMI executing stack variable */
16776 movq $0, 10*8(%rsp)
16777 jmp irq_return
16778 CFI_ENDPROC
16779 -END(nmi)
16780 +ENDPROC(nmi)
16781
16782 ENTRY(ignore_sysret)
16783 CFI_STARTPROC
16784 mov $-ENOSYS,%eax
16785 sysret
16786 CFI_ENDPROC
16787 -END(ignore_sysret)
16788 +ENDPROC(ignore_sysret)
16789
16790 /*
16791 * End of kprobes section
16792 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16793 index c3a7cb4..3ad00dc 100644
16794 --- a/arch/x86/kernel/ftrace.c
16795 +++ b/arch/x86/kernel/ftrace.c
16796 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16797 {
16798 unsigned char replaced[MCOUNT_INSN_SIZE];
16799
16800 + ip = ktla_ktva(ip);
16801 +
16802 /*
16803 * Note: Due to modules and __init, code can
16804 * disappear and change, we need to protect against faulting
16805 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16806 unsigned char old[MCOUNT_INSN_SIZE], *new;
16807 int ret;
16808
16809 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16810 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16811 new = ftrace_call_replace(ip, (unsigned long)func);
16812
16813 /* See comment above by declaration of modifying_ftrace_code */
16814 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16815 {
16816 unsigned char code[MCOUNT_INSN_SIZE];
16817
16818 + ip = ktla_ktva(ip);
16819 +
16820 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16821 return -EFAULT;
16822
16823 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16824 index c18f59d..9c0c9f6 100644
16825 --- a/arch/x86/kernel/head32.c
16826 +++ b/arch/x86/kernel/head32.c
16827 @@ -18,6 +18,7 @@
16828 #include <asm/io_apic.h>
16829 #include <asm/bios_ebda.h>
16830 #include <asm/tlbflush.h>
16831 +#include <asm/boot.h>
16832
16833 static void __init i386_default_early_setup(void)
16834 {
16835 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16836
16837 void __init i386_start_kernel(void)
16838 {
16839 - memblock_reserve(__pa_symbol(&_text),
16840 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16841 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16842
16843 #ifdef CONFIG_BLK_DEV_INITRD
16844 /* Reserve INITRD */
16845 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16846 index d42ab17..cb1b997 100644
16847 --- a/arch/x86/kernel/head_32.S
16848 +++ b/arch/x86/kernel/head_32.S
16849 @@ -26,6 +26,12 @@
16850 /* Physical address */
16851 #define pa(X) ((X) - __PAGE_OFFSET)
16852
16853 +#ifdef CONFIG_PAX_KERNEXEC
16854 +#define ta(X) (X)
16855 +#else
16856 +#define ta(X) ((X) - __PAGE_OFFSET)
16857 +#endif
16858 +
16859 /*
16860 * References to members of the new_cpu_data structure.
16861 */
16862 @@ -55,11 +61,7 @@
16863 * and small than max_low_pfn, otherwise will waste some page table entries
16864 */
16865
16866 -#if PTRS_PER_PMD > 1
16867 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16868 -#else
16869 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16870 -#endif
16871 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16872
16873 /* Number of possible pages in the lowmem region */
16874 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16875 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16876 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16877
16878 /*
16879 + * Real beginning of normal "text" segment
16880 + */
16881 +ENTRY(stext)
16882 +ENTRY(_stext)
16883 +
16884 +/*
16885 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16886 * %esi points to the real-mode code as a 32-bit pointer.
16887 * CS and DS must be 4 GB flat segments, but we don't depend on
16888 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16889 * can.
16890 */
16891 __HEAD
16892 +
16893 +#ifdef CONFIG_PAX_KERNEXEC
16894 + jmp startup_32
16895 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16896 +.fill PAGE_SIZE-5,1,0xcc
16897 +#endif
16898 +
16899 ENTRY(startup_32)
16900 movl pa(stack_start),%ecx
16901
16902 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16903 2:
16904 leal -__PAGE_OFFSET(%ecx),%esp
16905
16906 +#ifdef CONFIG_SMP
16907 + movl $pa(cpu_gdt_table),%edi
16908 + movl $__per_cpu_load,%eax
16909 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16910 + rorl $16,%eax
16911 + movb %al,__KERNEL_PERCPU + 4(%edi)
16912 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16913 + movl $__per_cpu_end - 1,%eax
16914 + subl $__per_cpu_start,%eax
16915 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16916 +#endif
16917 +
16918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16919 + movl $NR_CPUS,%ecx
16920 + movl $pa(cpu_gdt_table),%edi
16921 +1:
16922 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16923 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16924 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16925 + addl $PAGE_SIZE_asm,%edi
16926 + loop 1b
16927 +#endif
16928 +
16929 +#ifdef CONFIG_PAX_KERNEXEC
16930 + movl $pa(boot_gdt),%edi
16931 + movl $__LOAD_PHYSICAL_ADDR,%eax
16932 + movw %ax,__BOOT_CS + 2(%edi)
16933 + rorl $16,%eax
16934 + movb %al,__BOOT_CS + 4(%edi)
16935 + movb %ah,__BOOT_CS + 7(%edi)
16936 + rorl $16,%eax
16937 +
16938 + ljmp $(__BOOT_CS),$1f
16939 +1:
16940 +
16941 + movl $NR_CPUS,%ecx
16942 + movl $pa(cpu_gdt_table),%edi
16943 + addl $__PAGE_OFFSET,%eax
16944 +1:
16945 + movw %ax,__KERNEL_CS + 2(%edi)
16946 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16947 + rorl $16,%eax
16948 + movb %al,__KERNEL_CS + 4(%edi)
16949 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16950 + movb %ah,__KERNEL_CS + 7(%edi)
16951 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16952 + rorl $16,%eax
16953 + addl $PAGE_SIZE_asm,%edi
16954 + loop 1b
16955 +#endif
16956 +
16957 /*
16958 * Clear BSS first so that there are no surprises...
16959 */
16960 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16961 movl %eax, pa(max_pfn_mapped)
16962
16963 /* Do early initialization of the fixmap area */
16964 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16965 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16966 +#ifdef CONFIG_COMPAT_VDSO
16967 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16968 +#else
16969 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16970 +#endif
16971 #else /* Not PAE */
16972
16973 page_pde_offset = (__PAGE_OFFSET >> 20);
16974 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16975 movl %eax, pa(max_pfn_mapped)
16976
16977 /* Do early initialization of the fixmap area */
16978 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16979 - movl %eax,pa(initial_page_table+0xffc)
16980 +#ifdef CONFIG_COMPAT_VDSO
16981 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16982 +#else
16983 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16984 +#endif
16985 #endif
16986
16987 #ifdef CONFIG_PARAVIRT
16988 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16989 cmpl $num_subarch_entries, %eax
16990 jae bad_subarch
16991
16992 - movl pa(subarch_entries)(,%eax,4), %eax
16993 - subl $__PAGE_OFFSET, %eax
16994 - jmp *%eax
16995 + jmp *pa(subarch_entries)(,%eax,4)
16996
16997 bad_subarch:
16998 WEAK(lguest_entry)
16999 @@ -256,10 +326,10 @@ WEAK(xen_entry)
17000 __INITDATA
17001
17002 subarch_entries:
17003 - .long default_entry /* normal x86/PC */
17004 - .long lguest_entry /* lguest hypervisor */
17005 - .long xen_entry /* Xen hypervisor */
17006 - .long default_entry /* Moorestown MID */
17007 + .long ta(default_entry) /* normal x86/PC */
17008 + .long ta(lguest_entry) /* lguest hypervisor */
17009 + .long ta(xen_entry) /* Xen hypervisor */
17010 + .long ta(default_entry) /* Moorestown MID */
17011 num_subarch_entries = (. - subarch_entries) / 4
17012 .previous
17013 #else
17014 @@ -310,6 +380,7 @@ default_entry:
17015 orl %edx,%eax
17016 movl %eax,%cr4
17017
17018 +#ifdef CONFIG_X86_PAE
17019 testb $X86_CR4_PAE, %al # check if PAE is enabled
17020 jz 6f
17021
17022 @@ -338,6 +409,9 @@ default_entry:
17023 /* Make changes effective */
17024 wrmsr
17025
17026 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17027 +#endif
17028 +
17029 6:
17030
17031 /*
17032 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
17033 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17034 movl %eax,%ss # after changing gdt.
17035
17036 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17037 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17038 movl %eax,%ds
17039 movl %eax,%es
17040
17041 movl $(__KERNEL_PERCPU), %eax
17042 movl %eax,%fs # set this cpu's percpu
17043
17044 +#ifdef CONFIG_CC_STACKPROTECTOR
17045 movl $(__KERNEL_STACK_CANARY),%eax
17046 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17047 + movl $(__USER_DS),%eax
17048 +#else
17049 + xorl %eax,%eax
17050 +#endif
17051 movl %eax,%gs
17052
17053 xorl %eax,%eax # Clear LDT
17054 @@ -520,8 +600,11 @@ setup_once:
17055 * relocation. Manually set base address in stack canary
17056 * segment descriptor.
17057 */
17058 - movl $gdt_page,%eax
17059 + movl $cpu_gdt_table,%eax
17060 movl $stack_canary,%ecx
17061 +#ifdef CONFIG_SMP
17062 + addl $__per_cpu_load,%ecx
17063 +#endif
17064 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17065 shrl $16, %ecx
17066 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17067 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
17068 /* This is global to keep gas from relaxing the jumps */
17069 ENTRY(early_idt_handler)
17070 cld
17071 - cmpl $2,%ss:early_recursion_flag
17072 + cmpl $1,%ss:early_recursion_flag
17073 je hlt_loop
17074 incl %ss:early_recursion_flag
17075
17076 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
17077 pushl (20+6*4)(%esp) /* trapno */
17078 pushl $fault_msg
17079 call printk
17080 -#endif
17081 call dump_stack
17082 +#endif
17083 hlt_loop:
17084 hlt
17085 jmp hlt_loop
17086 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
17087 /* This is the default interrupt "handler" :-) */
17088 ALIGN
17089 ignore_int:
17090 - cld
17091 #ifdef CONFIG_PRINTK
17092 + cmpl $2,%ss:early_recursion_flag
17093 + je hlt_loop
17094 + incl %ss:early_recursion_flag
17095 + cld
17096 pushl %eax
17097 pushl %ecx
17098 pushl %edx
17099 @@ -620,9 +706,6 @@ ignore_int:
17100 movl $(__KERNEL_DS),%eax
17101 movl %eax,%ds
17102 movl %eax,%es
17103 - cmpl $2,early_recursion_flag
17104 - je hlt_loop
17105 - incl early_recursion_flag
17106 pushl 16(%esp)
17107 pushl 24(%esp)
17108 pushl 32(%esp)
17109 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17110 /*
17111 * BSS section
17112 */
17113 -__PAGE_ALIGNED_BSS
17114 - .align PAGE_SIZE
17115 #ifdef CONFIG_X86_PAE
17116 +.section .initial_pg_pmd,"a",@progbits
17117 initial_pg_pmd:
17118 .fill 1024*KPMDS,4,0
17119 #else
17120 +.section .initial_page_table,"a",@progbits
17121 ENTRY(initial_page_table)
17122 .fill 1024,4,0
17123 #endif
17124 +.section .initial_pg_fixmap,"a",@progbits
17125 initial_pg_fixmap:
17126 .fill 1024,4,0
17127 +.section .empty_zero_page,"a",@progbits
17128 ENTRY(empty_zero_page)
17129 .fill 4096,1,0
17130 +.section .swapper_pg_dir,"a",@progbits
17131 ENTRY(swapper_pg_dir)
17132 +#ifdef CONFIG_X86_PAE
17133 + .fill 4,8,0
17134 +#else
17135 .fill 1024,4,0
17136 +#endif
17137 +
17138 +/*
17139 + * The IDT has to be page-aligned to simplify the Pentium
17140 + * F0 0F bug workaround.. We have a special link segment
17141 + * for this.
17142 + */
17143 +.section .idt,"a",@progbits
17144 +ENTRY(idt_table)
17145 + .fill 256,8,0
17146
17147 /*
17148 * This starts the data section.
17149 */
17150 #ifdef CONFIG_X86_PAE
17151 -__PAGE_ALIGNED_DATA
17152 - /* Page-aligned for the benefit of paravirt? */
17153 - .align PAGE_SIZE
17154 +.section .initial_page_table,"a",@progbits
17155 ENTRY(initial_page_table)
17156 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17157 # if KPMDS == 3
17158 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17159 # error "Kernel PMDs should be 1, 2 or 3"
17160 # endif
17161 .align PAGE_SIZE /* needs to be page-sized too */
17162 +
17163 +#ifdef CONFIG_PAX_PER_CPU_PGD
17164 +ENTRY(cpu_pgd)
17165 + .rept NR_CPUS
17166 + .fill 4,8,0
17167 + .endr
17168 +#endif
17169 +
17170 #endif
17171
17172 .data
17173 .balign 4
17174 ENTRY(stack_start)
17175 - .long init_thread_union+THREAD_SIZE
17176 + .long init_thread_union+THREAD_SIZE-8
17177
17178 __INITRODATA
17179 int_msg:
17180 @@ -730,7 +835,7 @@ fault_msg:
17181 * segment size, and 32-bit linear address value:
17182 */
17183
17184 - .data
17185 +.section .rodata,"a",@progbits
17186 .globl boot_gdt_descr
17187 .globl idt_descr
17188
17189 @@ -739,7 +844,7 @@ fault_msg:
17190 .word 0 # 32 bit align gdt_desc.address
17191 boot_gdt_descr:
17192 .word __BOOT_DS+7
17193 - .long boot_gdt - __PAGE_OFFSET
17194 + .long pa(boot_gdt)
17195
17196 .word 0 # 32-bit align idt_desc.address
17197 idt_descr:
17198 @@ -750,7 +855,7 @@ idt_descr:
17199 .word 0 # 32 bit align gdt_desc.address
17200 ENTRY(early_gdt_descr)
17201 .word GDT_ENTRIES*8-1
17202 - .long gdt_page /* Overwritten for secondary CPUs */
17203 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17204
17205 /*
17206 * The boot_gdt must mirror the equivalent in setup.S and is
17207 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17208 .align L1_CACHE_BYTES
17209 ENTRY(boot_gdt)
17210 .fill GDT_ENTRY_BOOT_CS,8,0
17211 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17212 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17213 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17214 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17215 +
17216 + .align PAGE_SIZE_asm
17217 +ENTRY(cpu_gdt_table)
17218 + .rept NR_CPUS
17219 + .quad 0x0000000000000000 /* NULL descriptor */
17220 + .quad 0x0000000000000000 /* 0x0b reserved */
17221 + .quad 0x0000000000000000 /* 0x13 reserved */
17222 + .quad 0x0000000000000000 /* 0x1b reserved */
17223 +
17224 +#ifdef CONFIG_PAX_KERNEXEC
17225 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17226 +#else
17227 + .quad 0x0000000000000000 /* 0x20 unused */
17228 +#endif
17229 +
17230 + .quad 0x0000000000000000 /* 0x28 unused */
17231 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17232 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17233 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17234 + .quad 0x0000000000000000 /* 0x4b reserved */
17235 + .quad 0x0000000000000000 /* 0x53 reserved */
17236 + .quad 0x0000000000000000 /* 0x5b reserved */
17237 +
17238 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17239 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17240 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17241 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17242 +
17243 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17244 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17245 +
17246 + /*
17247 + * Segments used for calling PnP BIOS have byte granularity.
17248 + * The code segments and data segments have fixed 64k limits,
17249 + * the transfer segment sizes are set at run time.
17250 + */
17251 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17252 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17253 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17254 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17255 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17256 +
17257 + /*
17258 + * The APM segments have byte granularity and their bases
17259 + * are set at run time. All have 64k limits.
17260 + */
17261 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17262 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17263 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17264 +
17265 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17266 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17267 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17268 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17269 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17270 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17271 +
17272 + /* Be sure this is zeroed to avoid false validations in Xen */
17273 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17274 + .endr
17275 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17276 index 94bf9cc..400455a 100644
17277 --- a/arch/x86/kernel/head_64.S
17278 +++ b/arch/x86/kernel/head_64.S
17279 @@ -20,6 +20,8 @@
17280 #include <asm/processor-flags.h>
17281 #include <asm/percpu.h>
17282 #include <asm/nops.h>
17283 +#include <asm/cpufeature.h>
17284 +#include <asm/alternative-asm.h>
17285
17286 #ifdef CONFIG_PARAVIRT
17287 #include <asm/asm-offsets.h>
17288 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17289 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17290 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17291 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17292 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17293 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17294 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17295 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17296 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17297 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17298
17299 .text
17300 __HEAD
17301 @@ -88,35 +96,23 @@ startup_64:
17302 */
17303 addq %rbp, init_level4_pgt + 0(%rip)
17304 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17305 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17306 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17307 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17308 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17309
17310 addq %rbp, level3_ident_pgt + 0(%rip)
17311 +#ifndef CONFIG_XEN
17312 + addq %rbp, level3_ident_pgt + 8(%rip)
17313 +#endif
17314
17315 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17316 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17317 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17318 +
17319 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17320 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17321
17322 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17323 -
17324 - /* Add an Identity mapping if I am above 1G */
17325 - leaq _text(%rip), %rdi
17326 - andq $PMD_PAGE_MASK, %rdi
17327 -
17328 - movq %rdi, %rax
17329 - shrq $PUD_SHIFT, %rax
17330 - andq $(PTRS_PER_PUD - 1), %rax
17331 - jz ident_complete
17332 -
17333 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17334 - leaq level3_ident_pgt(%rip), %rbx
17335 - movq %rdx, 0(%rbx, %rax, 8)
17336 -
17337 - movq %rdi, %rax
17338 - shrq $PMD_SHIFT, %rax
17339 - andq $(PTRS_PER_PMD - 1), %rax
17340 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17341 - leaq level2_spare_pgt(%rip), %rbx
17342 - movq %rdx, 0(%rbx, %rax, 8)
17343 -ident_complete:
17344 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17345
17346 /*
17347 * Fixup the kernel text+data virtual addresses. Note that
17348 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17349 * after the boot processor executes this code.
17350 */
17351
17352 - /* Enable PAE mode and PGE */
17353 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17354 + /* Enable PAE mode and PSE/PGE */
17355 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17356 movq %rax, %cr4
17357
17358 /* Setup early boot stage 4 level pagetables. */
17359 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17360 movl $MSR_EFER, %ecx
17361 rdmsr
17362 btsl $_EFER_SCE, %eax /* Enable System Call */
17363 - btl $20,%edi /* No Execute supported? */
17364 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17365 jnc 1f
17366 btsl $_EFER_NX, %eax
17367 + leaq init_level4_pgt(%rip), %rdi
17368 +#ifndef CONFIG_EFI
17369 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17370 +#endif
17371 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17372 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17373 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17374 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17375 1: wrmsr /* Make changes effective */
17376
17377 /* Setup cr0 */
17378 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17379 * jump. In addition we need to ensure %cs is set so we make this
17380 * a far return.
17381 */
17382 + pax_set_fptr_mask
17383 movq initial_code(%rip),%rax
17384 pushq $0 # fake return address to stop unwinder
17385 pushq $__KERNEL_CS # set correct cs
17386 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17387 bad_address:
17388 jmp bad_address
17389
17390 - .section ".init.text","ax"
17391 + __INIT
17392 .globl early_idt_handlers
17393 early_idt_handlers:
17394 # 104(%rsp) %rflags
17395 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17396 addq $16,%rsp # drop vector number and error code
17397 decl early_recursion_flag(%rip)
17398 INTERRUPT_RETURN
17399 + .previous
17400
17401 + __INITDATA
17402 .balign 4
17403 early_recursion_flag:
17404 .long 0
17405 + .previous
17406
17407 + .section .rodata,"a",@progbits
17408 #ifdef CONFIG_EARLY_PRINTK
17409 early_idt_msg:
17410 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17411 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17412 #endif /* CONFIG_EARLY_PRINTK */
17413 .previous
17414
17415 + .section .rodata,"a",@progbits
17416 #define NEXT_PAGE(name) \
17417 .balign PAGE_SIZE; \
17418 ENTRY(name)
17419 @@ -372,7 +382,6 @@ ENTRY(name)
17420 i = i + 1 ; \
17421 .endr
17422
17423 - .data
17424 /*
17425 * This default setting generates an ident mapping at address 0x100000
17426 * and a mapping for the kernel that precisely maps virtual address
17427 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17428 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17429 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17430 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17431 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17432 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17433 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17434 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17435 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17436 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17437 .org init_level4_pgt + L4_START_KERNEL*8, 0
17438 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17439 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17440
17441 +#ifdef CONFIG_PAX_PER_CPU_PGD
17442 +NEXT_PAGE(cpu_pgd)
17443 + .rept NR_CPUS
17444 + .fill 512,8,0
17445 + .endr
17446 +#endif
17447 +
17448 NEXT_PAGE(level3_ident_pgt)
17449 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17450 +#ifdef CONFIG_XEN
17451 .fill 511,8,0
17452 +#else
17453 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17454 + .fill 510,8,0
17455 +#endif
17456 +
17457 +NEXT_PAGE(level3_vmalloc_start_pgt)
17458 + .fill 512,8,0
17459 +
17460 +NEXT_PAGE(level3_vmalloc_end_pgt)
17461 + .fill 512,8,0
17462 +
17463 +NEXT_PAGE(level3_vmemmap_pgt)
17464 + .fill L3_VMEMMAP_START,8,0
17465 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17466
17467 NEXT_PAGE(level3_kernel_pgt)
17468 .fill L3_START_KERNEL,8,0
17469 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17470 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17471 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17472
17473 +NEXT_PAGE(level2_vmemmap_pgt)
17474 + .fill 512,8,0
17475 +
17476 NEXT_PAGE(level2_fixmap_pgt)
17477 - .fill 506,8,0
17478 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17479 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17480 - .fill 5,8,0
17481 + .fill 507,8,0
17482 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17483 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17484 + .fill 4,8,0
17485
17486 -NEXT_PAGE(level1_fixmap_pgt)
17487 +NEXT_PAGE(level1_vsyscall_pgt)
17488 .fill 512,8,0
17489
17490 -NEXT_PAGE(level2_ident_pgt)
17491 - /* Since I easily can, map the first 1G.
17492 + /* Since I easily can, map the first 2G.
17493 * Don't set NX because code runs from these pages.
17494 */
17495 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17496 +NEXT_PAGE(level2_ident_pgt)
17497 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17498
17499 NEXT_PAGE(level2_kernel_pgt)
17500 /*
17501 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17502 * If you want to increase this then increase MODULES_VADDR
17503 * too.)
17504 */
17505 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17506 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17507 -
17508 -NEXT_PAGE(level2_spare_pgt)
17509 - .fill 512, 8, 0
17510 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17511
17512 #undef PMDS
17513 #undef NEXT_PAGE
17514
17515 - .data
17516 + .align PAGE_SIZE
17517 +ENTRY(cpu_gdt_table)
17518 + .rept NR_CPUS
17519 + .quad 0x0000000000000000 /* NULL descriptor */
17520 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17521 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17522 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17523 + .quad 0x00cffb000000ffff /* __USER32_CS */
17524 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17525 + .quad 0x00affb000000ffff /* __USER_CS */
17526 +
17527 +#ifdef CONFIG_PAX_KERNEXEC
17528 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17529 +#else
17530 + .quad 0x0 /* unused */
17531 +#endif
17532 +
17533 + .quad 0,0 /* TSS */
17534 + .quad 0,0 /* LDT */
17535 + .quad 0,0,0 /* three TLS descriptors */
17536 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17537 + /* asm/segment.h:GDT_ENTRIES must match this */
17538 +
17539 + /* zero the remaining page */
17540 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17541 + .endr
17542 +
17543 .align 16
17544 .globl early_gdt_descr
17545 early_gdt_descr:
17546 .word GDT_ENTRIES*8-1
17547 early_gdt_descr_base:
17548 - .quad INIT_PER_CPU_VAR(gdt_page)
17549 + .quad cpu_gdt_table
17550
17551 ENTRY(phys_base)
17552 /* This must match the first entry in level2_kernel_pgt */
17553 .quad 0x0000000000000000
17554
17555 #include "../../x86/xen/xen-head.S"
17556 -
17557 - .section .bss, "aw", @nobits
17558 +
17559 + .section .rodata,"a",@progbits
17560 .align L1_CACHE_BYTES
17561 ENTRY(idt_table)
17562 - .skip IDT_ENTRIES * 16
17563 + .fill 512,8,0
17564
17565 .align L1_CACHE_BYTES
17566 ENTRY(nmi_idt_table)
17567 - .skip IDT_ENTRIES * 16
17568 + .fill 512,8,0
17569
17570 __PAGE_ALIGNED_BSS
17571 .align PAGE_SIZE
17572 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17573 index 9c3bd4a..e1d9b35 100644
17574 --- a/arch/x86/kernel/i386_ksyms_32.c
17575 +++ b/arch/x86/kernel/i386_ksyms_32.c
17576 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17577 EXPORT_SYMBOL(cmpxchg8b_emu);
17578 #endif
17579
17580 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17581 +
17582 /* Networking helper routines. */
17583 EXPORT_SYMBOL(csum_partial_copy_generic);
17584 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17585 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17586
17587 EXPORT_SYMBOL(__get_user_1);
17588 EXPORT_SYMBOL(__get_user_2);
17589 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17590
17591 EXPORT_SYMBOL(csum_partial);
17592 EXPORT_SYMBOL(empty_zero_page);
17593 +
17594 +#ifdef CONFIG_PAX_KERNEXEC
17595 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17596 +#endif
17597 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17598 index f250431..54097e7 100644
17599 --- a/arch/x86/kernel/i387.c
17600 +++ b/arch/x86/kernel/i387.c
17601 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17602 static inline bool interrupted_user_mode(void)
17603 {
17604 struct pt_regs *regs = get_irq_regs();
17605 - return regs && user_mode_vm(regs);
17606 + return regs && user_mode(regs);
17607 }
17608
17609 /*
17610 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17611 index 36d1853..bf25736 100644
17612 --- a/arch/x86/kernel/i8259.c
17613 +++ b/arch/x86/kernel/i8259.c
17614 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17615 "spurious 8259A interrupt: IRQ%d.\n", irq);
17616 spurious_irq_mask |= irqmask;
17617 }
17618 - atomic_inc(&irq_err_count);
17619 + atomic_inc_unchecked(&irq_err_count);
17620 /*
17621 * Theoretically we do not have to handle this IRQ,
17622 * but in Linux this does not cause problems and is
17623 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17624 index 8c96897..be66bfa 100644
17625 --- a/arch/x86/kernel/ioport.c
17626 +++ b/arch/x86/kernel/ioport.c
17627 @@ -6,6 +6,7 @@
17628 #include <linux/sched.h>
17629 #include <linux/kernel.h>
17630 #include <linux/capability.h>
17631 +#include <linux/security.h>
17632 #include <linux/errno.h>
17633 #include <linux/types.h>
17634 #include <linux/ioport.h>
17635 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17636
17637 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17638 return -EINVAL;
17639 +#ifdef CONFIG_GRKERNSEC_IO
17640 + if (turn_on && grsec_disable_privio) {
17641 + gr_handle_ioperm();
17642 + return -EPERM;
17643 + }
17644 +#endif
17645 if (turn_on && !capable(CAP_SYS_RAWIO))
17646 return -EPERM;
17647
17648 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17649 * because the ->io_bitmap_max value must match the bitmap
17650 * contents:
17651 */
17652 - tss = &per_cpu(init_tss, get_cpu());
17653 + tss = init_tss + get_cpu();
17654
17655 if (turn_on)
17656 bitmap_clear(t->io_bitmap_ptr, from, num);
17657 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17658 return -EINVAL;
17659 /* Trying to gain more privileges? */
17660 if (level > old) {
17661 +#ifdef CONFIG_GRKERNSEC_IO
17662 + if (grsec_disable_privio) {
17663 + gr_handle_iopl();
17664 + return -EPERM;
17665 + }
17666 +#endif
17667 if (!capable(CAP_SYS_RAWIO))
17668 return -EPERM;
17669 }
17670 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17671 index d44f782..31ab01e 100644
17672 --- a/arch/x86/kernel/irq.c
17673 +++ b/arch/x86/kernel/irq.c
17674 @@ -18,7 +18,7 @@
17675 #include <asm/mce.h>
17676 #include <asm/hw_irq.h>
17677
17678 -atomic_t irq_err_count;
17679 +atomic_unchecked_t irq_err_count;
17680
17681 /* Function pointer for generic interrupt vector handling */
17682 void (*x86_platform_ipi_callback)(void) = NULL;
17683 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17684 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17685 seq_printf(p, " Machine check polls\n");
17686 #endif
17687 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17688 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17689 #if defined(CONFIG_X86_IO_APIC)
17690 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17691 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17692 #endif
17693 return 0;
17694 }
17695 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17696
17697 u64 arch_irq_stat(void)
17698 {
17699 - u64 sum = atomic_read(&irq_err_count);
17700 + u64 sum = atomic_read_unchecked(&irq_err_count);
17701
17702 #ifdef CONFIG_X86_IO_APIC
17703 - sum += atomic_read(&irq_mis_count);
17704 + sum += atomic_read_unchecked(&irq_mis_count);
17705 #endif
17706 return sum;
17707 }
17708 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17709 index 344faf8..355f60d 100644
17710 --- a/arch/x86/kernel/irq_32.c
17711 +++ b/arch/x86/kernel/irq_32.c
17712 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17713 __asm__ __volatile__("andl %%esp,%0" :
17714 "=r" (sp) : "0" (THREAD_SIZE - 1));
17715
17716 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17717 + return sp < STACK_WARN;
17718 }
17719
17720 static void print_stack_overflow(void)
17721 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17722 * per-CPU IRQ handling contexts (thread information and stack)
17723 */
17724 union irq_ctx {
17725 - struct thread_info tinfo;
17726 - u32 stack[THREAD_SIZE/sizeof(u32)];
17727 + unsigned long previous_esp;
17728 + u32 stack[THREAD_SIZE/sizeof(u32)];
17729 } __attribute__((aligned(THREAD_SIZE)));
17730
17731 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17732 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17733 static inline int
17734 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17735 {
17736 - union irq_ctx *curctx, *irqctx;
17737 + union irq_ctx *irqctx;
17738 u32 *isp, arg1, arg2;
17739
17740 - curctx = (union irq_ctx *) current_thread_info();
17741 irqctx = __this_cpu_read(hardirq_ctx);
17742
17743 /*
17744 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17745 * handler) we can't do that and just have to keep using the
17746 * current stack (which is the irq stack already after all)
17747 */
17748 - if (unlikely(curctx == irqctx))
17749 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17750 return 0;
17751
17752 /* build the stack frame on the IRQ stack */
17753 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17754 - irqctx->tinfo.task = curctx->tinfo.task;
17755 - irqctx->tinfo.previous_esp = current_stack_pointer;
17756 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17757 + irqctx->previous_esp = current_stack_pointer;
17758
17759 - /* Copy the preempt_count so that the [soft]irq checks work. */
17760 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17762 + __set_fs(MAKE_MM_SEG(0));
17763 +#endif
17764
17765 if (unlikely(overflow))
17766 call_on_stack(print_stack_overflow, isp);
17767 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17768 : "0" (irq), "1" (desc), "2" (isp),
17769 "D" (desc->handle_irq)
17770 : "memory", "cc", "ecx");
17771 +
17772 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17773 + __set_fs(current_thread_info()->addr_limit);
17774 +#endif
17775 +
17776 return 1;
17777 }
17778
17779 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17780 */
17781 void __cpuinit irq_ctx_init(int cpu)
17782 {
17783 - union irq_ctx *irqctx;
17784 -
17785 if (per_cpu(hardirq_ctx, cpu))
17786 return;
17787
17788 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17789 - THREADINFO_GFP,
17790 - THREAD_SIZE_ORDER));
17791 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17792 - irqctx->tinfo.cpu = cpu;
17793 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17794 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17795 -
17796 - per_cpu(hardirq_ctx, cpu) = irqctx;
17797 -
17798 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17799 - THREADINFO_GFP,
17800 - THREAD_SIZE_ORDER));
17801 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17802 - irqctx->tinfo.cpu = cpu;
17803 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17804 -
17805 - per_cpu(softirq_ctx, cpu) = irqctx;
17806 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17807 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17808 +
17809 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17810 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17811
17812 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17813 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17814 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17815 asmlinkage void do_softirq(void)
17816 {
17817 unsigned long flags;
17818 - struct thread_info *curctx;
17819 union irq_ctx *irqctx;
17820 u32 *isp;
17821
17822 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17823 local_irq_save(flags);
17824
17825 if (local_softirq_pending()) {
17826 - curctx = current_thread_info();
17827 irqctx = __this_cpu_read(softirq_ctx);
17828 - irqctx->tinfo.task = curctx->task;
17829 - irqctx->tinfo.previous_esp = current_stack_pointer;
17830 + irqctx->previous_esp = current_stack_pointer;
17831
17832 /* build the stack frame on the softirq stack */
17833 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17834 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17835 +
17836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17837 + __set_fs(MAKE_MM_SEG(0));
17838 +#endif
17839
17840 call_on_stack(__do_softirq, isp);
17841 +
17842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17843 + __set_fs(current_thread_info()->addr_limit);
17844 +#endif
17845 +
17846 /*
17847 * Shouldn't happen, we returned above if in_interrupt():
17848 */
17849 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17850 if (unlikely(!desc))
17851 return false;
17852
17853 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17854 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17855 if (unlikely(overflow))
17856 print_stack_overflow();
17857 desc->handle_irq(irq, desc);
17858 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17859 index d04d3ec..ea4b374 100644
17860 --- a/arch/x86/kernel/irq_64.c
17861 +++ b/arch/x86/kernel/irq_64.c
17862 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17863 u64 estack_top, estack_bottom;
17864 u64 curbase = (u64)task_stack_page(current);
17865
17866 - if (user_mode_vm(regs))
17867 + if (user_mode(regs))
17868 return;
17869
17870 if (regs->sp >= curbase + sizeof(struct thread_info) +
17871 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17872 index dc1404b..bbc43e7 100644
17873 --- a/arch/x86/kernel/kdebugfs.c
17874 +++ b/arch/x86/kernel/kdebugfs.c
17875 @@ -27,7 +27,7 @@ struct setup_data_node {
17876 u32 len;
17877 };
17878
17879 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17880 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17881 size_t count, loff_t *ppos)
17882 {
17883 struct setup_data_node *node = file->private_data;
17884 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17885 index 3f61904..873cea9 100644
17886 --- a/arch/x86/kernel/kgdb.c
17887 +++ b/arch/x86/kernel/kgdb.c
17888 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17889 #ifdef CONFIG_X86_32
17890 switch (regno) {
17891 case GDB_SS:
17892 - if (!user_mode_vm(regs))
17893 + if (!user_mode(regs))
17894 *(unsigned long *)mem = __KERNEL_DS;
17895 break;
17896 case GDB_SP:
17897 - if (!user_mode_vm(regs))
17898 + if (!user_mode(regs))
17899 *(unsigned long *)mem = kernel_stack_pointer(regs);
17900 break;
17901 case GDB_GS:
17902 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17903 case 'k':
17904 /* clear the trace bit */
17905 linux_regs->flags &= ~X86_EFLAGS_TF;
17906 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17907 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17908
17909 /* set the trace bit if we're stepping */
17910 if (remcomInBuffer[0] == 's') {
17911 linux_regs->flags |= X86_EFLAGS_TF;
17912 - atomic_set(&kgdb_cpu_doing_single_step,
17913 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17914 raw_smp_processor_id());
17915 }
17916
17917 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17918
17919 switch (cmd) {
17920 case DIE_DEBUG:
17921 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17922 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17923 if (user_mode(regs))
17924 return single_step_cont(regs, args);
17925 break;
17926 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17927 index c5e410e..da6aaf9 100644
17928 --- a/arch/x86/kernel/kprobes-opt.c
17929 +++ b/arch/x86/kernel/kprobes-opt.c
17930 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17931 * Verify if the address gap is in 2GB range, because this uses
17932 * a relative jump.
17933 */
17934 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17935 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17936 if (abs(rel) > 0x7fffffff)
17937 return -ERANGE;
17938
17939 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17940 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17941
17942 /* Set probe function call */
17943 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17944 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17945
17946 /* Set returning jmp instruction at the tail of out-of-line buffer */
17947 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17948 - (u8 *)op->kp.addr + op->optinsn.size);
17949 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17950
17951 flush_icache_range((unsigned long) buf,
17952 (unsigned long) buf + TMPL_END_IDX +
17953 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17954 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17955
17956 /* Backup instructions which will be replaced by jump address */
17957 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17958 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17959 RELATIVE_ADDR_SIZE);
17960
17961 insn_buf[0] = RELATIVEJUMP_OPCODE;
17962 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17963 index e2f751e..dffa2a0 100644
17964 --- a/arch/x86/kernel/kprobes.c
17965 +++ b/arch/x86/kernel/kprobes.c
17966 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17967 } __attribute__((packed)) *insn;
17968
17969 insn = (struct __arch_relative_insn *)from;
17970 +
17971 + pax_open_kernel();
17972 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17973 insn->op = op;
17974 + pax_close_kernel();
17975 }
17976
17977 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17978 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17979 kprobe_opcode_t opcode;
17980 kprobe_opcode_t *orig_opcodes = opcodes;
17981
17982 - if (search_exception_tables((unsigned long)opcodes))
17983 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17984 return 0; /* Page fault may occur on this address. */
17985
17986 retry:
17987 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17988 /* Another subsystem puts a breakpoint, failed to recover */
17989 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17990 return 0;
17991 + pax_open_kernel();
17992 memcpy(dest, insn.kaddr, insn.length);
17993 + pax_close_kernel();
17994
17995 #ifdef CONFIG_X86_64
17996 if (insn_rip_relative(&insn)) {
17997 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17998 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17999 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18000 disp = (u8 *) dest + insn_offset_displacement(&insn);
18001 + pax_open_kernel();
18002 *(s32 *) disp = (s32) newdisp;
18003 + pax_close_kernel();
18004 }
18005 #endif
18006 return insn.length;
18007 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18008 * nor set current_kprobe, because it doesn't use single
18009 * stepping.
18010 */
18011 - regs->ip = (unsigned long)p->ainsn.insn;
18012 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18013 preempt_enable_no_resched();
18014 return;
18015 }
18016 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18017 if (p->opcode == BREAKPOINT_INSTRUCTION)
18018 regs->ip = (unsigned long)p->addr;
18019 else
18020 - regs->ip = (unsigned long)p->ainsn.insn;
18021 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18022 }
18023
18024 /*
18025 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18026 setup_singlestep(p, regs, kcb, 0);
18027 return 1;
18028 }
18029 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18030 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18031 /*
18032 * The breakpoint instruction was removed right
18033 * after we hit it. Another cpu has removed
18034 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18035 " movq %rax, 152(%rsp)\n"
18036 RESTORE_REGS_STRING
18037 " popfq\n"
18038 +#ifdef KERNEXEC_PLUGIN
18039 + " btsq $63,(%rsp)\n"
18040 +#endif
18041 #else
18042 " pushf\n"
18043 SAVE_REGS_STRING
18044 @@ -765,7 +775,7 @@ static void __kprobes
18045 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18046 {
18047 unsigned long *tos = stack_addr(regs);
18048 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18049 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18050 unsigned long orig_ip = (unsigned long)p->addr;
18051 kprobe_opcode_t *insn = p->ainsn.insn;
18052
18053 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18054 struct die_args *args = data;
18055 int ret = NOTIFY_DONE;
18056
18057 - if (args->regs && user_mode_vm(args->regs))
18058 + if (args->regs && user_mode(args->regs))
18059 return ret;
18060
18061 switch (val) {
18062 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18063 index ebc9873..1b9724b 100644
18064 --- a/arch/x86/kernel/ldt.c
18065 +++ b/arch/x86/kernel/ldt.c
18066 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18067 if (reload) {
18068 #ifdef CONFIG_SMP
18069 preempt_disable();
18070 - load_LDT(pc);
18071 + load_LDT_nolock(pc);
18072 if (!cpumask_equal(mm_cpumask(current->mm),
18073 cpumask_of(smp_processor_id())))
18074 smp_call_function(flush_ldt, current->mm, 1);
18075 preempt_enable();
18076 #else
18077 - load_LDT(pc);
18078 + load_LDT_nolock(pc);
18079 #endif
18080 }
18081 if (oldsize) {
18082 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18083 return err;
18084
18085 for (i = 0; i < old->size; i++)
18086 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18087 + write_ldt_entry(new->ldt, i, old->ldt + i);
18088 return 0;
18089 }
18090
18091 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18092 retval = copy_ldt(&mm->context, &old_mm->context);
18093 mutex_unlock(&old_mm->context.lock);
18094 }
18095 +
18096 + if (tsk == current) {
18097 + mm->context.vdso = 0;
18098 +
18099 +#ifdef CONFIG_X86_32
18100 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18101 + mm->context.user_cs_base = 0UL;
18102 + mm->context.user_cs_limit = ~0UL;
18103 +
18104 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18105 + cpus_clear(mm->context.cpu_user_cs_mask);
18106 +#endif
18107 +
18108 +#endif
18109 +#endif
18110 +
18111 + }
18112 +
18113 return retval;
18114 }
18115
18116 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18117 }
18118 }
18119
18120 +#ifdef CONFIG_PAX_SEGMEXEC
18121 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18122 + error = -EINVAL;
18123 + goto out_unlock;
18124 + }
18125 +#endif
18126 +
18127 fill_ldt(&ldt, &ldt_info);
18128 if (oldmode)
18129 ldt.avl = 0;
18130 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18131 index 5b19e4d..6476a76 100644
18132 --- a/arch/x86/kernel/machine_kexec_32.c
18133 +++ b/arch/x86/kernel/machine_kexec_32.c
18134 @@ -26,7 +26,7 @@
18135 #include <asm/cacheflush.h>
18136 #include <asm/debugreg.h>
18137
18138 -static void set_idt(void *newidt, __u16 limit)
18139 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18140 {
18141 struct desc_ptr curidt;
18142
18143 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18144 }
18145
18146
18147 -static void set_gdt(void *newgdt, __u16 limit)
18148 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18149 {
18150 struct desc_ptr curgdt;
18151
18152 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18153 }
18154
18155 control_page = page_address(image->control_code_page);
18156 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18157 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18158
18159 relocate_kernel_ptr = control_page;
18160 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18161 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18162 index 0327e2b..e43737b 100644
18163 --- a/arch/x86/kernel/microcode_intel.c
18164 +++ b/arch/x86/kernel/microcode_intel.c
18165 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18166
18167 static int get_ucode_user(void *to, const void *from, size_t n)
18168 {
18169 - return copy_from_user(to, from, n);
18170 + return copy_from_user(to, (const void __force_user *)from, n);
18171 }
18172
18173 static enum ucode_state
18174 request_microcode_user(int cpu, const void __user *buf, size_t size)
18175 {
18176 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18177 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18178 }
18179
18180 static void microcode_fini_cpu(int cpu)
18181 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18182 index 216a4d7..b328f09 100644
18183 --- a/arch/x86/kernel/module.c
18184 +++ b/arch/x86/kernel/module.c
18185 @@ -43,15 +43,60 @@ do { \
18186 } while (0)
18187 #endif
18188
18189 -void *module_alloc(unsigned long size)
18190 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18191 {
18192 - if (PAGE_ALIGN(size) > MODULES_LEN)
18193 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18194 return NULL;
18195 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18196 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18197 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18198 -1, __builtin_return_address(0));
18199 }
18200
18201 +void *module_alloc(unsigned long size)
18202 +{
18203 +
18204 +#ifdef CONFIG_PAX_KERNEXEC
18205 + return __module_alloc(size, PAGE_KERNEL);
18206 +#else
18207 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18208 +#endif
18209 +
18210 +}
18211 +
18212 +#ifdef CONFIG_PAX_KERNEXEC
18213 +#ifdef CONFIG_X86_32
18214 +void *module_alloc_exec(unsigned long size)
18215 +{
18216 + struct vm_struct *area;
18217 +
18218 + if (size == 0)
18219 + return NULL;
18220 +
18221 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18222 + return area ? area->addr : NULL;
18223 +}
18224 +EXPORT_SYMBOL(module_alloc_exec);
18225 +
18226 +void module_free_exec(struct module *mod, void *module_region)
18227 +{
18228 + vunmap(module_region);
18229 +}
18230 +EXPORT_SYMBOL(module_free_exec);
18231 +#else
18232 +void module_free_exec(struct module *mod, void *module_region)
18233 +{
18234 + module_free(mod, module_region);
18235 +}
18236 +EXPORT_SYMBOL(module_free_exec);
18237 +
18238 +void *module_alloc_exec(unsigned long size)
18239 +{
18240 + return __module_alloc(size, PAGE_KERNEL_RX);
18241 +}
18242 +EXPORT_SYMBOL(module_alloc_exec);
18243 +#endif
18244 +#endif
18245 +
18246 #ifdef CONFIG_X86_32
18247 int apply_relocate(Elf32_Shdr *sechdrs,
18248 const char *strtab,
18249 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18250 unsigned int i;
18251 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18252 Elf32_Sym *sym;
18253 - uint32_t *location;
18254 + uint32_t *plocation, location;
18255
18256 DEBUGP("Applying relocate section %u to %u\n",
18257 relsec, sechdrs[relsec].sh_info);
18258 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18259 /* This is where to make the change */
18260 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18261 - + rel[i].r_offset;
18262 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18263 + location = (uint32_t)plocation;
18264 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18265 + plocation = ktla_ktva((void *)plocation);
18266 /* This is the symbol it is referring to. Note that all
18267 undefined symbols have been resolved. */
18268 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18269 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18270 switch (ELF32_R_TYPE(rel[i].r_info)) {
18271 case R_386_32:
18272 /* We add the value into the location given */
18273 - *location += sym->st_value;
18274 + pax_open_kernel();
18275 + *plocation += sym->st_value;
18276 + pax_close_kernel();
18277 break;
18278 case R_386_PC32:
18279 /* Add the value, subtract its position */
18280 - *location += sym->st_value - (uint32_t)location;
18281 + pax_open_kernel();
18282 + *plocation += sym->st_value - location;
18283 + pax_close_kernel();
18284 break;
18285 default:
18286 pr_err("%s: Unknown relocation: %u\n",
18287 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18288 case R_X86_64_NONE:
18289 break;
18290 case R_X86_64_64:
18291 + pax_open_kernel();
18292 *(u64 *)loc = val;
18293 + pax_close_kernel();
18294 break;
18295 case R_X86_64_32:
18296 + pax_open_kernel();
18297 *(u32 *)loc = val;
18298 + pax_close_kernel();
18299 if (val != *(u32 *)loc)
18300 goto overflow;
18301 break;
18302 case R_X86_64_32S:
18303 + pax_open_kernel();
18304 *(s32 *)loc = val;
18305 + pax_close_kernel();
18306 if ((s64)val != *(s32 *)loc)
18307 goto overflow;
18308 break;
18309 case R_X86_64_PC32:
18310 val -= (u64)loc;
18311 + pax_open_kernel();
18312 *(u32 *)loc = val;
18313 + pax_close_kernel();
18314 +
18315 #if 0
18316 if ((s64)val != *(s32 *)loc)
18317 goto overflow;
18318 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18319 index f84f5c5..e27e54b 100644
18320 --- a/arch/x86/kernel/nmi.c
18321 +++ b/arch/x86/kernel/nmi.c
18322 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18323 dotraplinkage notrace __kprobes void
18324 do_nmi(struct pt_regs *regs, long error_code)
18325 {
18326 +
18327 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18328 + if (!user_mode(regs)) {
18329 + unsigned long cs = regs->cs & 0xFFFF;
18330 + unsigned long ip = ktva_ktla(regs->ip);
18331 +
18332 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18333 + regs->ip = ip;
18334 + }
18335 +#endif
18336 +
18337 nmi_nesting_preprocess(regs);
18338
18339 nmi_enter();
18340 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18341 index 676b8c7..870ba04 100644
18342 --- a/arch/x86/kernel/paravirt-spinlocks.c
18343 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18344 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18345 arch_spin_lock(lock);
18346 }
18347
18348 -struct pv_lock_ops pv_lock_ops = {
18349 +struct pv_lock_ops pv_lock_ops __read_only = {
18350 #ifdef CONFIG_SMP
18351 .spin_is_locked = __ticket_spin_is_locked,
18352 .spin_is_contended = __ticket_spin_is_contended,
18353 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18354 index 17fff18..7bb2088 100644
18355 --- a/arch/x86/kernel/paravirt.c
18356 +++ b/arch/x86/kernel/paravirt.c
18357 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18358 {
18359 return x;
18360 }
18361 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18362 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18363 +#endif
18364
18365 void __init default_banner(void)
18366 {
18367 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18368 if (opfunc == NULL)
18369 /* If there's no function, patch it with a ud2a (BUG) */
18370 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18371 - else if (opfunc == _paravirt_nop)
18372 + else if (opfunc == (void *)_paravirt_nop)
18373 /* If the operation is a nop, then nop the callsite */
18374 ret = paravirt_patch_nop();
18375
18376 /* identity functions just return their single argument */
18377 - else if (opfunc == _paravirt_ident_32)
18378 + else if (opfunc == (void *)_paravirt_ident_32)
18379 ret = paravirt_patch_ident_32(insnbuf, len);
18380 - else if (opfunc == _paravirt_ident_64)
18381 + else if (opfunc == (void *)_paravirt_ident_64)
18382 ret = paravirt_patch_ident_64(insnbuf, len);
18383 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18384 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18385 + ret = paravirt_patch_ident_64(insnbuf, len);
18386 +#endif
18387
18388 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18389 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18390 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18391 if (insn_len > len || start == NULL)
18392 insn_len = len;
18393 else
18394 - memcpy(insnbuf, start, insn_len);
18395 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18396
18397 return insn_len;
18398 }
18399 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18400 preempt_enable();
18401 }
18402
18403 -struct pv_info pv_info = {
18404 +struct pv_info pv_info __read_only = {
18405 .name = "bare hardware",
18406 .paravirt_enabled = 0,
18407 .kernel_rpl = 0,
18408 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18409 #endif
18410 };
18411
18412 -struct pv_init_ops pv_init_ops = {
18413 +struct pv_init_ops pv_init_ops __read_only = {
18414 .patch = native_patch,
18415 };
18416
18417 -struct pv_time_ops pv_time_ops = {
18418 +struct pv_time_ops pv_time_ops __read_only = {
18419 .sched_clock = native_sched_clock,
18420 .steal_clock = native_steal_clock,
18421 };
18422
18423 -struct pv_irq_ops pv_irq_ops = {
18424 +struct pv_irq_ops pv_irq_ops __read_only = {
18425 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18426 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18427 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18428 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18429 #endif
18430 };
18431
18432 -struct pv_cpu_ops pv_cpu_ops = {
18433 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18434 .cpuid = native_cpuid,
18435 .get_debugreg = native_get_debugreg,
18436 .set_debugreg = native_set_debugreg,
18437 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18438 .end_context_switch = paravirt_nop,
18439 };
18440
18441 -struct pv_apic_ops pv_apic_ops = {
18442 +struct pv_apic_ops pv_apic_ops __read_only = {
18443 #ifdef CONFIG_X86_LOCAL_APIC
18444 .startup_ipi_hook = paravirt_nop,
18445 #endif
18446 };
18447
18448 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18449 +#ifdef CONFIG_X86_32
18450 +#ifdef CONFIG_X86_PAE
18451 +/* 64-bit pagetable entries */
18452 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18453 +#else
18454 /* 32-bit pagetable entries */
18455 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18456 +#endif
18457 #else
18458 /* 64-bit pagetable entries */
18459 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18460 #endif
18461
18462 -struct pv_mmu_ops pv_mmu_ops = {
18463 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18464
18465 .read_cr2 = native_read_cr2,
18466 .write_cr2 = native_write_cr2,
18467 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18468 .make_pud = PTE_IDENT,
18469
18470 .set_pgd = native_set_pgd,
18471 + .set_pgd_batched = native_set_pgd_batched,
18472 #endif
18473 #endif /* PAGETABLE_LEVELS >= 3 */
18474
18475 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18476 },
18477
18478 .set_fixmap = native_set_fixmap,
18479 +
18480 +#ifdef CONFIG_PAX_KERNEXEC
18481 + .pax_open_kernel = native_pax_open_kernel,
18482 + .pax_close_kernel = native_pax_close_kernel,
18483 +#endif
18484 +
18485 };
18486
18487 EXPORT_SYMBOL_GPL(pv_time_ops);
18488 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18489 index 35ccf75..7a15747 100644
18490 --- a/arch/x86/kernel/pci-iommu_table.c
18491 +++ b/arch/x86/kernel/pci-iommu_table.c
18492 @@ -2,7 +2,7 @@
18493 #include <asm/iommu_table.h>
18494 #include <linux/string.h>
18495 #include <linux/kallsyms.h>
18496 -
18497 +#include <linux/sched.h>
18498
18499 #define DEBUG 1
18500
18501 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18502 index ef6a845..8028ed3 100644
18503 --- a/arch/x86/kernel/process.c
18504 +++ b/arch/x86/kernel/process.c
18505 @@ -36,7 +36,8 @@
18506 * section. Since TSS's are completely CPU-local, we want them
18507 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18508 */
18509 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18510 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18511 +EXPORT_SYMBOL(init_tss);
18512
18513 #ifdef CONFIG_X86_64
18514 static DEFINE_PER_CPU(unsigned char, is_idle);
18515 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18516 task_xstate_cachep =
18517 kmem_cache_create("task_xstate", xstate_size,
18518 __alignof__(union thread_xstate),
18519 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18520 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18521 }
18522
18523 static inline void drop_fpu(struct task_struct *tsk)
18524 @@ -117,7 +118,7 @@ void exit_thread(void)
18525 unsigned long *bp = t->io_bitmap_ptr;
18526
18527 if (bp) {
18528 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18529 + struct tss_struct *tss = init_tss + get_cpu();
18530
18531 t->io_bitmap_ptr = NULL;
18532 clear_thread_flag(TIF_IO_BITMAP);
18533 @@ -148,7 +149,7 @@ void show_regs_common(void)
18534 board = dmi_get_system_info(DMI_BOARD_NAME);
18535
18536 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18537 - current->pid, current->comm, print_tainted(),
18538 + task_pid_nr(current), current->comm, print_tainted(),
18539 init_utsname()->release,
18540 (int)strcspn(init_utsname()->version, " "),
18541 init_utsname()->version,
18542 @@ -161,6 +162,9 @@ void flush_thread(void)
18543 {
18544 struct task_struct *tsk = current;
18545
18546 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18547 + loadsegment(gs, 0);
18548 +#endif
18549 flush_ptrace_hw_breakpoint(tsk);
18550 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18551 drop_fpu(tsk);
18552 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18553 regs.di = (unsigned long) arg;
18554
18555 #ifdef CONFIG_X86_32
18556 - regs.ds = __USER_DS;
18557 - regs.es = __USER_DS;
18558 + regs.ds = __KERNEL_DS;
18559 + regs.es = __KERNEL_DS;
18560 regs.fs = __KERNEL_PERCPU;
18561 - regs.gs = __KERNEL_STACK_CANARY;
18562 + savesegment(gs, regs.gs);
18563 #else
18564 regs.ss = __KERNEL_DS;
18565 #endif
18566 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18567 void exit_idle(void)
18568 {
18569 /* idle loop has pid 0 */
18570 - if (current->pid)
18571 + if (task_pid_nr(current))
18572 return;
18573 __exit_idle();
18574 }
18575 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18576
18577 return ret;
18578 }
18579 -void stop_this_cpu(void *dummy)
18580 +__noreturn void stop_this_cpu(void *dummy)
18581 {
18582 local_irq_disable();
18583 /*
18584 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18585 }
18586 early_param("idle", idle_setup);
18587
18588 -unsigned long arch_align_stack(unsigned long sp)
18589 +#ifdef CONFIG_PAX_RANDKSTACK
18590 +void pax_randomize_kstack(struct pt_regs *regs)
18591 {
18592 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18593 - sp -= get_random_int() % 8192;
18594 - return sp & ~0xf;
18595 -}
18596 + struct thread_struct *thread = &current->thread;
18597 + unsigned long time;
18598
18599 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18600 -{
18601 - unsigned long range_end = mm->brk + 0x02000000;
18602 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18603 -}
18604 + if (!randomize_va_space)
18605 + return;
18606 +
18607 + if (v8086_mode(regs))
18608 + return;
18609
18610 + rdtscl(time);
18611 +
18612 + /* P4 seems to return a 0 LSB, ignore it */
18613 +#ifdef CONFIG_MPENTIUM4
18614 + time &= 0x3EUL;
18615 + time <<= 2;
18616 +#elif defined(CONFIG_X86_64)
18617 + time &= 0xFUL;
18618 + time <<= 4;
18619 +#else
18620 + time &= 0x1FUL;
18621 + time <<= 3;
18622 +#endif
18623 +
18624 + thread->sp0 ^= time;
18625 + load_sp0(init_tss + smp_processor_id(), thread);
18626 +
18627 +#ifdef CONFIG_X86_64
18628 + this_cpu_write(kernel_stack, thread->sp0);
18629 +#endif
18630 +}
18631 +#endif
18632 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18633 index 516fa18..80bd9e6 100644
18634 --- a/arch/x86/kernel/process_32.c
18635 +++ b/arch/x86/kernel/process_32.c
18636 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18637 unsigned long thread_saved_pc(struct task_struct *tsk)
18638 {
18639 return ((unsigned long *)tsk->thread.sp)[3];
18640 +//XXX return tsk->thread.eip;
18641 }
18642
18643 void __show_regs(struct pt_regs *regs, int all)
18644 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18645 unsigned long sp;
18646 unsigned short ss, gs;
18647
18648 - if (user_mode_vm(regs)) {
18649 + if (user_mode(regs)) {
18650 sp = regs->sp;
18651 ss = regs->ss & 0xffff;
18652 - gs = get_user_gs(regs);
18653 } else {
18654 sp = kernel_stack_pointer(regs);
18655 savesegment(ss, ss);
18656 - savesegment(gs, gs);
18657 }
18658 + gs = get_user_gs(regs);
18659
18660 show_regs_common();
18661
18662 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18663 struct task_struct *tsk;
18664 int err;
18665
18666 - childregs = task_pt_regs(p);
18667 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18668 *childregs = *regs;
18669 childregs->ax = 0;
18670 childregs->sp = sp;
18671
18672 p->thread.sp = (unsigned long) childregs;
18673 p->thread.sp0 = (unsigned long) (childregs+1);
18674 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18675
18676 p->thread.ip = (unsigned long) ret_from_fork;
18677
18678 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18679 struct thread_struct *prev = &prev_p->thread,
18680 *next = &next_p->thread;
18681 int cpu = smp_processor_id();
18682 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18683 + struct tss_struct *tss = init_tss + cpu;
18684 fpu_switch_t fpu;
18685
18686 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18687 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 */
18689 lazy_save_gs(prev->gs);
18690
18691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18692 + __set_fs(task_thread_info(next_p)->addr_limit);
18693 +#endif
18694 +
18695 /*
18696 * Load the per-thread Thread-Local Storage descriptor.
18697 */
18698 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18699 */
18700 arch_end_context_switch(next_p);
18701
18702 + this_cpu_write(current_task, next_p);
18703 + this_cpu_write(current_tinfo, &next_p->tinfo);
18704 +
18705 /*
18706 * Restore %gs if needed (which is common)
18707 */
18708 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18709
18710 switch_fpu_finish(next_p, fpu);
18711
18712 - this_cpu_write(current_task, next_p);
18713 -
18714 return prev_p;
18715 }
18716
18717 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18718 } while (count++ < 16);
18719 return 0;
18720 }
18721 -
18722 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18723 index 0a980c9..1d0e689 100644
18724 --- a/arch/x86/kernel/process_64.c
18725 +++ b/arch/x86/kernel/process_64.c
18726 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18727 struct pt_regs *childregs;
18728 struct task_struct *me = current;
18729
18730 - childregs = ((struct pt_regs *)
18731 - (THREAD_SIZE + task_stack_page(p))) - 1;
18732 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18733 *childregs = *regs;
18734
18735 childregs->ax = 0;
18736 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18737 p->thread.sp = (unsigned long) childregs;
18738 p->thread.sp0 = (unsigned long) (childregs+1);
18739 p->thread.usersp = me->thread.usersp;
18740 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18741
18742 set_tsk_thread_flag(p, TIF_FORK);
18743
18744 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18745 struct thread_struct *prev = &prev_p->thread;
18746 struct thread_struct *next = &next_p->thread;
18747 int cpu = smp_processor_id();
18748 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18749 + struct tss_struct *tss = init_tss + cpu;
18750 unsigned fsindex, gsindex;
18751 fpu_switch_t fpu;
18752
18753 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18754 prev->usersp = this_cpu_read(old_rsp);
18755 this_cpu_write(old_rsp, next->usersp);
18756 this_cpu_write(current_task, next_p);
18757 + this_cpu_write(current_tinfo, &next_p->tinfo);
18758
18759 - this_cpu_write(kernel_stack,
18760 - (unsigned long)task_stack_page(next_p) +
18761 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18762 + this_cpu_write(kernel_stack, next->sp0);
18763
18764 /*
18765 * Now maybe reload the debug registers and handle I/O bitmaps
18766 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18767 if (!p || p == current || p->state == TASK_RUNNING)
18768 return 0;
18769 stack = (unsigned long)task_stack_page(p);
18770 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18771 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18772 return 0;
18773 fp = *(u64 *)(p->thread.sp);
18774 do {
18775 - if (fp < (unsigned long)stack ||
18776 - fp >= (unsigned long)stack+THREAD_SIZE)
18777 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18778 return 0;
18779 ip = *(u64 *)(fp+8);
18780 if (!in_sched_functions(ip))
18781 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18782 index c4c6a5c..905f440 100644
18783 --- a/arch/x86/kernel/ptrace.c
18784 +++ b/arch/x86/kernel/ptrace.c
18785 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18786 unsigned long addr, unsigned long data)
18787 {
18788 int ret;
18789 - unsigned long __user *datap = (unsigned long __user *)data;
18790 + unsigned long __user *datap = (__force unsigned long __user *)data;
18791
18792 switch (request) {
18793 /* read the word at location addr in the USER area. */
18794 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18795 if ((int) addr < 0)
18796 return -EIO;
18797 ret = do_get_thread_area(child, addr,
18798 - (struct user_desc __user *)data);
18799 + (__force struct user_desc __user *) data);
18800 break;
18801
18802 case PTRACE_SET_THREAD_AREA:
18803 if ((int) addr < 0)
18804 return -EIO;
18805 ret = do_set_thread_area(child, addr,
18806 - (struct user_desc __user *)data, 0);
18807 + (__force struct user_desc __user *) data, 0);
18808 break;
18809 #endif
18810
18811 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18812 memset(info, 0, sizeof(*info));
18813 info->si_signo = SIGTRAP;
18814 info->si_code = si_code;
18815 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18816 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18817 }
18818
18819 void user_single_step_siginfo(struct task_struct *tsk,
18820 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18821 # define IS_IA32 0
18822 #endif
18823
18824 +#ifdef CONFIG_GRKERNSEC_SETXID
18825 +extern void gr_delayed_cred_worker(void);
18826 +#endif
18827 +
18828 /*
18829 * We must return the syscall number to actually look up in the table.
18830 * This can be -1L to skip running any syscall at all.
18831 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18832 {
18833 long ret = 0;
18834
18835 +#ifdef CONFIG_GRKERNSEC_SETXID
18836 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18837 + gr_delayed_cred_worker();
18838 +#endif
18839 +
18840 /*
18841 * If we stepped into a sysenter/syscall insn, it trapped in
18842 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18843 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18844 {
18845 bool step;
18846
18847 +#ifdef CONFIG_GRKERNSEC_SETXID
18848 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18849 + gr_delayed_cred_worker();
18850 +#endif
18851 +
18852 audit_syscall_exit(regs);
18853
18854 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18855 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18856 index 42eb330..139955c 100644
18857 --- a/arch/x86/kernel/pvclock.c
18858 +++ b/arch/x86/kernel/pvclock.c
18859 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18860 return pv_tsc_khz;
18861 }
18862
18863 -static atomic64_t last_value = ATOMIC64_INIT(0);
18864 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18865
18866 void pvclock_resume(void)
18867 {
18868 - atomic64_set(&last_value, 0);
18869 + atomic64_set_unchecked(&last_value, 0);
18870 }
18871
18872 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18873 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18874 * updating at the same time, and one of them could be slightly behind,
18875 * making the assumption that last_value always go forward fail to hold.
18876 */
18877 - last = atomic64_read(&last_value);
18878 + last = atomic64_read_unchecked(&last_value);
18879 do {
18880 if (ret < last)
18881 return last;
18882 - last = atomic64_cmpxchg(&last_value, last, ret);
18883 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18884 } while (unlikely(last != ret));
18885
18886 return ret;
18887 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18888 index 52190a9..8074389 100644
18889 --- a/arch/x86/kernel/reboot.c
18890 +++ b/arch/x86/kernel/reboot.c
18891 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18892 EXPORT_SYMBOL(pm_power_off);
18893
18894 static const struct desc_ptr no_idt = {};
18895 -static int reboot_mode;
18896 +static unsigned short reboot_mode;
18897 enum reboot_type reboot_type = BOOT_ACPI;
18898 int reboot_force;
18899
18900 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18901
18902 void __noreturn machine_real_restart(unsigned int type)
18903 {
18904 +
18905 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18906 + struct desc_struct *gdt;
18907 +#endif
18908 +
18909 local_irq_disable();
18910
18911 /*
18912 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18913
18914 /* Jump to the identity-mapped low memory code */
18915 #ifdef CONFIG_X86_32
18916 - asm volatile("jmpl *%0" : :
18917 +
18918 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18919 + gdt = get_cpu_gdt_table(smp_processor_id());
18920 + pax_open_kernel();
18921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18922 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18923 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18924 + loadsegment(ds, __KERNEL_DS);
18925 + loadsegment(es, __KERNEL_DS);
18926 + loadsegment(ss, __KERNEL_DS);
18927 +#endif
18928 +#ifdef CONFIG_PAX_KERNEXEC
18929 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18930 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18931 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18932 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18933 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18934 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18935 +#endif
18936 + pax_close_kernel();
18937 +#endif
18938 +
18939 + asm volatile("ljmpl *%0" : :
18940 "rm" (real_mode_header->machine_real_restart_asm),
18941 "a" (type));
18942 #else
18943 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18944 * try to force a triple fault and then cycle between hitting the keyboard
18945 * controller and doing that
18946 */
18947 -static void native_machine_emergency_restart(void)
18948 +static void __noreturn native_machine_emergency_restart(void)
18949 {
18950 int i;
18951 int attempt = 0;
18952 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18953 #endif
18954 }
18955
18956 -static void __machine_emergency_restart(int emergency)
18957 +static void __noreturn __machine_emergency_restart(int emergency)
18958 {
18959 reboot_emergency = emergency;
18960 machine_ops.emergency_restart();
18961 }
18962
18963 -static void native_machine_restart(char *__unused)
18964 +static void __noreturn native_machine_restart(char *__unused)
18965 {
18966 pr_notice("machine restart\n");
18967
18968 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18969 __machine_emergency_restart(0);
18970 }
18971
18972 -static void native_machine_halt(void)
18973 +static void __noreturn native_machine_halt(void)
18974 {
18975 /* Stop other cpus and apics */
18976 machine_shutdown();
18977 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
18978 stop_this_cpu(NULL);
18979 }
18980
18981 -static void native_machine_power_off(void)
18982 +static void __noreturn native_machine_power_off(void)
18983 {
18984 if (pm_power_off) {
18985 if (!reboot_force)
18986 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18987 }
18988 /* A fallback in case there is no PM info available */
18989 tboot_shutdown(TB_SHUTDOWN_HALT);
18990 + unreachable();
18991 }
18992
18993 struct machine_ops machine_ops = {
18994 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18995 index 7a6f3b3..bed145d7 100644
18996 --- a/arch/x86/kernel/relocate_kernel_64.S
18997 +++ b/arch/x86/kernel/relocate_kernel_64.S
18998 @@ -11,6 +11,7 @@
18999 #include <asm/kexec.h>
19000 #include <asm/processor-flags.h>
19001 #include <asm/pgtable_types.h>
19002 +#include <asm/alternative-asm.h>
19003
19004 /*
19005 * Must be relocatable PIC code callable as a C function
19006 @@ -160,13 +161,14 @@ identity_mapped:
19007 xorq %rbp, %rbp
19008 xorq %r8, %r8
19009 xorq %r9, %r9
19010 - xorq %r10, %r9
19011 + xorq %r10, %r10
19012 xorq %r11, %r11
19013 xorq %r12, %r12
19014 xorq %r13, %r13
19015 xorq %r14, %r14
19016 xorq %r15, %r15
19017
19018 + pax_force_retaddr 0, 1
19019 ret
19020
19021 1:
19022 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19023 index f4b9b80..0d05de1 100644
19024 --- a/arch/x86/kernel/setup.c
19025 +++ b/arch/x86/kernel/setup.c
19026 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19027
19028 switch (data->type) {
19029 case SETUP_E820_EXT:
19030 - parse_e820_ext(data);
19031 + parse_e820_ext((struct setup_data __force_kernel *)data);
19032 break;
19033 case SETUP_DTB:
19034 add_dtb(pa_data);
19035 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19036 * area (640->1Mb) as ram even though it is not.
19037 * take them out.
19038 */
19039 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19040 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19041 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19042 }
19043
19044 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19045
19046 if (!boot_params.hdr.root_flags)
19047 root_mountflags &= ~MS_RDONLY;
19048 - init_mm.start_code = (unsigned long) _text;
19049 - init_mm.end_code = (unsigned long) _etext;
19050 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19051 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19052 init_mm.end_data = (unsigned long) _edata;
19053 init_mm.brk = _brk_end;
19054
19055 - code_resource.start = virt_to_phys(_text);
19056 - code_resource.end = virt_to_phys(_etext)-1;
19057 - data_resource.start = virt_to_phys(_etext);
19058 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19059 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19060 + data_resource.start = virt_to_phys(_sdata);
19061 data_resource.end = virt_to_phys(_edata)-1;
19062 bss_resource.start = virt_to_phys(&__bss_start);
19063 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19064 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19065 index 5cdff03..5810740 100644
19066 --- a/arch/x86/kernel/setup_percpu.c
19067 +++ b/arch/x86/kernel/setup_percpu.c
19068 @@ -21,19 +21,17 @@
19069 #include <asm/cpu.h>
19070 #include <asm/stackprotector.h>
19071
19072 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19073 +#ifdef CONFIG_SMP
19074 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19075 EXPORT_PER_CPU_SYMBOL(cpu_number);
19076 +#endif
19077
19078 -#ifdef CONFIG_X86_64
19079 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19080 -#else
19081 -#define BOOT_PERCPU_OFFSET 0
19082 -#endif
19083
19084 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19085 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19086
19087 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19088 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19089 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19090 };
19091 EXPORT_SYMBOL(__per_cpu_offset);
19092 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19093 {
19094 #ifdef CONFIG_X86_32
19095 struct desc_struct gdt;
19096 + unsigned long base = per_cpu_offset(cpu);
19097
19098 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19099 - 0x2 | DESCTYPE_S, 0x8);
19100 - gdt.s = 1;
19101 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19102 + 0x83 | DESCTYPE_S, 0xC);
19103 write_gdt_entry(get_cpu_gdt_table(cpu),
19104 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19105 #endif
19106 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19107 /* alrighty, percpu areas up and running */
19108 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19109 for_each_possible_cpu(cpu) {
19110 +#ifdef CONFIG_CC_STACKPROTECTOR
19111 +#ifdef CONFIG_X86_32
19112 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19113 +#endif
19114 +#endif
19115 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19116 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19117 per_cpu(cpu_number, cpu) = cpu;
19118 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19119 */
19120 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19121 #endif
19122 +#ifdef CONFIG_CC_STACKPROTECTOR
19123 +#ifdef CONFIG_X86_32
19124 + if (!cpu)
19125 + per_cpu(stack_canary.canary, cpu) = canary;
19126 +#endif
19127 +#endif
19128 /*
19129 * Up to this point, the boot CPU has been using .init.data
19130 * area. Reload any changed state for the boot CPU.
19131 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19132 index b280908..6de349e 100644
19133 --- a/arch/x86/kernel/signal.c
19134 +++ b/arch/x86/kernel/signal.c
19135 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19136 * Align the stack pointer according to the i386 ABI,
19137 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19138 */
19139 - sp = ((sp + 4) & -16ul) - 4;
19140 + sp = ((sp - 12) & -16ul) - 4;
19141 #else /* !CONFIG_X86_32 */
19142 sp = round_down(sp, 16) - 8;
19143 #endif
19144 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19145 * Return an always-bogus address instead so we will die with SIGSEGV.
19146 */
19147 if (onsigstack && !likely(on_sig_stack(sp)))
19148 - return (void __user *)-1L;
19149 + return (__force void __user *)-1L;
19150
19151 /* save i387 state */
19152 if (used_math() && save_i387_xstate(*fpstate) < 0)
19153 - return (void __user *)-1L;
19154 + return (__force void __user *)-1L;
19155
19156 return (void __user *)sp;
19157 }
19158 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19159 }
19160
19161 if (current->mm->context.vdso)
19162 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19163 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19164 else
19165 - restorer = &frame->retcode;
19166 + restorer = (void __user *)&frame->retcode;
19167 if (ka->sa.sa_flags & SA_RESTORER)
19168 restorer = ka->sa.sa_restorer;
19169
19170 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19171 * reasons and because gdb uses it as a signature to notice
19172 * signal handler stack frames.
19173 */
19174 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19175 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19176
19177 if (err)
19178 return -EFAULT;
19179 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19180 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19181
19182 /* Set up to return from userspace. */
19183 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19184 + if (current->mm->context.vdso)
19185 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19186 + else
19187 + restorer = (void __user *)&frame->retcode;
19188 if (ka->sa.sa_flags & SA_RESTORER)
19189 restorer = ka->sa.sa_restorer;
19190 put_user_ex(restorer, &frame->pretcode);
19191 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19192 * reasons and because gdb uses it as a signature to notice
19193 * signal handler stack frames.
19194 */
19195 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19196 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19197 } put_user_catch(err);
19198
19199 if (err)
19200 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19201 index 7c5a8c3..88d422f 100644
19202 --- a/arch/x86/kernel/smpboot.c
19203 +++ b/arch/x86/kernel/smpboot.c
19204 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19205 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19206 (THREAD_SIZE + task_stack_page(idle))) - 1);
19207 per_cpu(current_task, cpu) = idle;
19208 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19209
19210 #ifdef CONFIG_X86_32
19211 /* Stack for startup_32 can be just as for start_secondary onwards */
19212 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19213 #else
19214 clear_tsk_thread_flag(idle, TIF_FORK);
19215 initial_gs = per_cpu_offset(cpu);
19216 - per_cpu(kernel_stack, cpu) =
19217 - (unsigned long)task_stack_page(idle) -
19218 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19219 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19220 #endif
19221 +
19222 + pax_open_kernel();
19223 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19224 + pax_close_kernel();
19225 +
19226 initial_code = (unsigned long)start_secondary;
19227 stack_start = idle->thread.sp;
19228
19229 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19230
19231 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19232
19233 +#ifdef CONFIG_PAX_PER_CPU_PGD
19234 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19235 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19236 + KERNEL_PGD_PTRS);
19237 +#endif
19238 +
19239 err = do_boot_cpu(apicid, cpu, tidle);
19240 if (err) {
19241 pr_debug("do_boot_cpu failed %d\n", err);
19242 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19243 index c346d11..d43b163 100644
19244 --- a/arch/x86/kernel/step.c
19245 +++ b/arch/x86/kernel/step.c
19246 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19247 struct desc_struct *desc;
19248 unsigned long base;
19249
19250 - seg &= ~7UL;
19251 + seg >>= 3;
19252
19253 mutex_lock(&child->mm->context.lock);
19254 - if (unlikely((seg >> 3) >= child->mm->context.size))
19255 + if (unlikely(seg >= child->mm->context.size))
19256 addr = -1L; /* bogus selector, access would fault */
19257 else {
19258 desc = child->mm->context.ldt + seg;
19259 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19260 addr += base;
19261 }
19262 mutex_unlock(&child->mm->context.lock);
19263 - }
19264 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19265 + addr = ktla_ktva(addr);
19266
19267 return addr;
19268 }
19269 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19270 unsigned char opcode[15];
19271 unsigned long addr = convert_ip_to_linear(child, regs);
19272
19273 + if (addr == -EINVAL)
19274 + return 0;
19275 +
19276 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19277 for (i = 0; i < copied; i++) {
19278 switch (opcode[i]) {
19279 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19280 index 0b0cb5f..db6b9ed 100644
19281 --- a/arch/x86/kernel/sys_i386_32.c
19282 +++ b/arch/x86/kernel/sys_i386_32.c
19283 @@ -24,17 +24,224 @@
19284
19285 #include <asm/syscalls.h>
19286
19287 -/*
19288 - * Do a system call from kernel instead of calling sys_execve so we
19289 - * end up with proper pt_regs.
19290 - */
19291 -int kernel_execve(const char *filename,
19292 - const char *const argv[],
19293 - const char *const envp[])
19294 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19295 {
19296 - long __res;
19297 - asm volatile ("int $0x80"
19298 - : "=a" (__res)
19299 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19300 - return __res;
19301 + unsigned long pax_task_size = TASK_SIZE;
19302 +
19303 +#ifdef CONFIG_PAX_SEGMEXEC
19304 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19305 + pax_task_size = SEGMEXEC_TASK_SIZE;
19306 +#endif
19307 +
19308 + if (len > pax_task_size || addr > pax_task_size - len)
19309 + return -EINVAL;
19310 +
19311 + return 0;
19312 +}
19313 +
19314 +unsigned long
19315 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19316 + unsigned long len, unsigned long pgoff, unsigned long flags)
19317 +{
19318 + struct mm_struct *mm = current->mm;
19319 + struct vm_area_struct *vma;
19320 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19321 +
19322 +#ifdef CONFIG_PAX_SEGMEXEC
19323 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19324 + pax_task_size = SEGMEXEC_TASK_SIZE;
19325 +#endif
19326 +
19327 + pax_task_size -= PAGE_SIZE;
19328 +
19329 + if (len > pax_task_size)
19330 + return -ENOMEM;
19331 +
19332 + if (flags & MAP_FIXED)
19333 + return addr;
19334 +
19335 +#ifdef CONFIG_PAX_RANDMMAP
19336 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19337 +#endif
19338 +
19339 + if (addr) {
19340 + addr = PAGE_ALIGN(addr);
19341 + if (pax_task_size - len >= addr) {
19342 + vma = find_vma(mm, addr);
19343 + if (check_heap_stack_gap(vma, addr, len))
19344 + return addr;
19345 + }
19346 + }
19347 + if (len > mm->cached_hole_size) {
19348 + start_addr = addr = mm->free_area_cache;
19349 + } else {
19350 + start_addr = addr = mm->mmap_base;
19351 + mm->cached_hole_size = 0;
19352 + }
19353 +
19354 +#ifdef CONFIG_PAX_PAGEEXEC
19355 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19356 + start_addr = 0x00110000UL;
19357 +
19358 +#ifdef CONFIG_PAX_RANDMMAP
19359 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19360 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19361 +#endif
19362 +
19363 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19364 + start_addr = addr = mm->mmap_base;
19365 + else
19366 + addr = start_addr;
19367 + }
19368 +#endif
19369 +
19370 +full_search:
19371 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19372 + /* At this point: (!vma || addr < vma->vm_end). */
19373 + if (pax_task_size - len < addr) {
19374 + /*
19375 + * Start a new search - just in case we missed
19376 + * some holes.
19377 + */
19378 + if (start_addr != mm->mmap_base) {
19379 + start_addr = addr = mm->mmap_base;
19380 + mm->cached_hole_size = 0;
19381 + goto full_search;
19382 + }
19383 + return -ENOMEM;
19384 + }
19385 + if (check_heap_stack_gap(vma, addr, len))
19386 + break;
19387 + if (addr + mm->cached_hole_size < vma->vm_start)
19388 + mm->cached_hole_size = vma->vm_start - addr;
19389 + addr = vma->vm_end;
19390 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19391 + start_addr = addr = mm->mmap_base;
19392 + mm->cached_hole_size = 0;
19393 + goto full_search;
19394 + }
19395 + }
19396 +
19397 + /*
19398 + * Remember the place where we stopped the search:
19399 + */
19400 + mm->free_area_cache = addr + len;
19401 + return addr;
19402 +}
19403 +
19404 +unsigned long
19405 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19406 + const unsigned long len, const unsigned long pgoff,
19407 + const unsigned long flags)
19408 +{
19409 + struct vm_area_struct *vma;
19410 + struct mm_struct *mm = current->mm;
19411 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19412 +
19413 +#ifdef CONFIG_PAX_SEGMEXEC
19414 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19415 + pax_task_size = SEGMEXEC_TASK_SIZE;
19416 +#endif
19417 +
19418 + pax_task_size -= PAGE_SIZE;
19419 +
19420 + /* requested length too big for entire address space */
19421 + if (len > pax_task_size)
19422 + return -ENOMEM;
19423 +
19424 + if (flags & MAP_FIXED)
19425 + return addr;
19426 +
19427 +#ifdef CONFIG_PAX_PAGEEXEC
19428 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19429 + goto bottomup;
19430 +#endif
19431 +
19432 +#ifdef CONFIG_PAX_RANDMMAP
19433 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19434 +#endif
19435 +
19436 + /* requesting a specific address */
19437 + if (addr) {
19438 + addr = PAGE_ALIGN(addr);
19439 + if (pax_task_size - len >= addr) {
19440 + vma = find_vma(mm, addr);
19441 + if (check_heap_stack_gap(vma, addr, len))
19442 + return addr;
19443 + }
19444 + }
19445 +
19446 + /* check if free_area_cache is useful for us */
19447 + if (len <= mm->cached_hole_size) {
19448 + mm->cached_hole_size = 0;
19449 + mm->free_area_cache = mm->mmap_base;
19450 + }
19451 +
19452 + /* either no address requested or can't fit in requested address hole */
19453 + addr = mm->free_area_cache;
19454 +
19455 + /* make sure it can fit in the remaining address space */
19456 + if (addr > len) {
19457 + vma = find_vma(mm, addr-len);
19458 + if (check_heap_stack_gap(vma, addr - len, len))
19459 + /* remember the address as a hint for next time */
19460 + return (mm->free_area_cache = addr-len);
19461 + }
19462 +
19463 + if (mm->mmap_base < len)
19464 + goto bottomup;
19465 +
19466 + addr = mm->mmap_base-len;
19467 +
19468 + do {
19469 + /*
19470 + * Lookup failure means no vma is above this address,
19471 + * else if new region fits below vma->vm_start,
19472 + * return with success:
19473 + */
19474 + vma = find_vma(mm, addr);
19475 + if (check_heap_stack_gap(vma, addr, len))
19476 + /* remember the address as a hint for next time */
19477 + return (mm->free_area_cache = addr);
19478 +
19479 + /* remember the largest hole we saw so far */
19480 + if (addr + mm->cached_hole_size < vma->vm_start)
19481 + mm->cached_hole_size = vma->vm_start - addr;
19482 +
19483 + /* try just below the current vma->vm_start */
19484 + addr = skip_heap_stack_gap(vma, len);
19485 + } while (!IS_ERR_VALUE(addr));
19486 +
19487 +bottomup:
19488 + /*
19489 + * A failed mmap() very likely causes application failure,
19490 + * so fall back to the bottom-up function here. This scenario
19491 + * can happen with large stack limits and large mmap()
19492 + * allocations.
19493 + */
19494 +
19495 +#ifdef CONFIG_PAX_SEGMEXEC
19496 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19497 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19498 + else
19499 +#endif
19500 +
19501 + mm->mmap_base = TASK_UNMAPPED_BASE;
19502 +
19503 +#ifdef CONFIG_PAX_RANDMMAP
19504 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19505 + mm->mmap_base += mm->delta_mmap;
19506 +#endif
19507 +
19508 + mm->free_area_cache = mm->mmap_base;
19509 + mm->cached_hole_size = ~0UL;
19510 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19511 + /*
19512 + * Restore the topdown base:
19513 + */
19514 + mm->mmap_base = base;
19515 + mm->free_area_cache = base;
19516 + mm->cached_hole_size = ~0UL;
19517 +
19518 + return addr;
19519 }
19520 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19521 index b4d3c39..82bb73b 100644
19522 --- a/arch/x86/kernel/sys_x86_64.c
19523 +++ b/arch/x86/kernel/sys_x86_64.c
19524 @@ -95,8 +95,8 @@ out:
19525 return error;
19526 }
19527
19528 -static void find_start_end(unsigned long flags, unsigned long *begin,
19529 - unsigned long *end)
19530 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19531 + unsigned long *begin, unsigned long *end)
19532 {
19533 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19534 unsigned long new_begin;
19535 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19536 *begin = new_begin;
19537 }
19538 } else {
19539 - *begin = TASK_UNMAPPED_BASE;
19540 + *begin = mm->mmap_base;
19541 *end = TASK_SIZE;
19542 }
19543 }
19544 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19545 if (flags & MAP_FIXED)
19546 return addr;
19547
19548 - find_start_end(flags, &begin, &end);
19549 + find_start_end(mm, flags, &begin, &end);
19550
19551 if (len > end)
19552 return -ENOMEM;
19553
19554 +#ifdef CONFIG_PAX_RANDMMAP
19555 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19556 +#endif
19557 +
19558 if (addr) {
19559 addr = PAGE_ALIGN(addr);
19560 vma = find_vma(mm, addr);
19561 - if (end - len >= addr &&
19562 - (!vma || addr + len <= vma->vm_start))
19563 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19564 return addr;
19565 }
19566 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19567 @@ -172,7 +175,7 @@ full_search:
19568 }
19569 return -ENOMEM;
19570 }
19571 - if (!vma || addr + len <= vma->vm_start) {
19572 + if (check_heap_stack_gap(vma, addr, len)) {
19573 /*
19574 * Remember the place where we stopped the search:
19575 */
19576 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19577 {
19578 struct vm_area_struct *vma;
19579 struct mm_struct *mm = current->mm;
19580 - unsigned long addr = addr0, start_addr;
19581 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19582
19583 /* requested length too big for entire address space */
19584 if (len > TASK_SIZE)
19585 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19586 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19587 goto bottomup;
19588
19589 +#ifdef CONFIG_PAX_RANDMMAP
19590 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19591 +#endif
19592 +
19593 /* requesting a specific address */
19594 if (addr) {
19595 addr = PAGE_ALIGN(addr);
19596 - vma = find_vma(mm, addr);
19597 - if (TASK_SIZE - len >= addr &&
19598 - (!vma || addr + len <= vma->vm_start))
19599 - return addr;
19600 + if (TASK_SIZE - len >= addr) {
19601 + vma = find_vma(mm, addr);
19602 + if (check_heap_stack_gap(vma, addr, len))
19603 + return addr;
19604 + }
19605 }
19606
19607 /* check if free_area_cache is useful for us */
19608 @@ -240,7 +248,7 @@ try_again:
19609 * return with success:
19610 */
19611 vma = find_vma(mm, addr);
19612 - if (!vma || addr+len <= vma->vm_start)
19613 + if (check_heap_stack_gap(vma, addr, len))
19614 /* remember the address as a hint for next time */
19615 return mm->free_area_cache = addr;
19616
19617 @@ -249,8 +257,8 @@ try_again:
19618 mm->cached_hole_size = vma->vm_start - addr;
19619
19620 /* try just below the current vma->vm_start */
19621 - addr = vma->vm_start-len;
19622 - } while (len < vma->vm_start);
19623 + addr = skip_heap_stack_gap(vma, len);
19624 + } while (!IS_ERR_VALUE(addr));
19625
19626 fail:
19627 /*
19628 @@ -270,13 +278,21 @@ bottomup:
19629 * can happen with large stack limits and large mmap()
19630 * allocations.
19631 */
19632 + mm->mmap_base = TASK_UNMAPPED_BASE;
19633 +
19634 +#ifdef CONFIG_PAX_RANDMMAP
19635 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19636 + mm->mmap_base += mm->delta_mmap;
19637 +#endif
19638 +
19639 + mm->free_area_cache = mm->mmap_base;
19640 mm->cached_hole_size = ~0UL;
19641 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19642 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19643 /*
19644 * Restore the topdown base:
19645 */
19646 - mm->free_area_cache = mm->mmap_base;
19647 + mm->mmap_base = base;
19648 + mm->free_area_cache = base;
19649 mm->cached_hole_size = ~0UL;
19650
19651 return addr;
19652 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19653 index f84fe00..93fe08f 100644
19654 --- a/arch/x86/kernel/tboot.c
19655 +++ b/arch/x86/kernel/tboot.c
19656 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19657
19658 void tboot_shutdown(u32 shutdown_type)
19659 {
19660 - void (*shutdown)(void);
19661 + void (* __noreturn shutdown)(void);
19662
19663 if (!tboot_enabled())
19664 return;
19665 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19666
19667 switch_to_tboot_pt();
19668
19669 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19670 + shutdown = (void *)tboot->shutdown_entry;
19671 shutdown();
19672
19673 /* should not reach here */
19674 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19675 return 0;
19676 }
19677
19678 -static atomic_t ap_wfs_count;
19679 +static atomic_unchecked_t ap_wfs_count;
19680
19681 static int tboot_wait_for_aps(int num_aps)
19682 {
19683 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19684 {
19685 switch (action) {
19686 case CPU_DYING:
19687 - atomic_inc(&ap_wfs_count);
19688 + atomic_inc_unchecked(&ap_wfs_count);
19689 if (num_online_cpus() == 1)
19690 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19691 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19692 return NOTIFY_BAD;
19693 break;
19694 }
19695 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19696
19697 tboot_create_trampoline();
19698
19699 - atomic_set(&ap_wfs_count, 0);
19700 + atomic_set_unchecked(&ap_wfs_count, 0);
19701 register_hotcpu_notifier(&tboot_cpu_notifier);
19702
19703 acpi_os_set_prepare_sleep(&tboot_sleep);
19704 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19705 index 24d3c91..d06b473 100644
19706 --- a/arch/x86/kernel/time.c
19707 +++ b/arch/x86/kernel/time.c
19708 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19709 {
19710 unsigned long pc = instruction_pointer(regs);
19711
19712 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19713 + if (!user_mode(regs) && in_lock_functions(pc)) {
19714 #ifdef CONFIG_FRAME_POINTER
19715 - return *(unsigned long *)(regs->bp + sizeof(long));
19716 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19717 #else
19718 unsigned long *sp =
19719 (unsigned long *)kernel_stack_pointer(regs);
19720 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19721 * or above a saved flags. Eflags has bits 22-31 zero,
19722 * kernel addresses don't.
19723 */
19724 +
19725 +#ifdef CONFIG_PAX_KERNEXEC
19726 + return ktla_ktva(sp[0]);
19727 +#else
19728 if (sp[0] >> 22)
19729 return sp[0];
19730 if (sp[1] >> 22)
19731 return sp[1];
19732 #endif
19733 +
19734 +#endif
19735 }
19736 return pc;
19737 }
19738 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19739 index 9d9d2f9..cad418a 100644
19740 --- a/arch/x86/kernel/tls.c
19741 +++ b/arch/x86/kernel/tls.c
19742 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19743 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19744 return -EINVAL;
19745
19746 +#ifdef CONFIG_PAX_SEGMEXEC
19747 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19748 + return -EINVAL;
19749 +#endif
19750 +
19751 set_tls_desc(p, idx, &info, 1);
19752
19753 return 0;
19754 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19755
19756 if (kbuf)
19757 info = kbuf;
19758 - else if (__copy_from_user(infobuf, ubuf, count))
19759 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19760 return -EFAULT;
19761 else
19762 info = infobuf;
19763 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19764 index b481341..5918bbe 100644
19765 --- a/arch/x86/kernel/traps.c
19766 +++ b/arch/x86/kernel/traps.c
19767 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19768
19769 /* Do we ignore FPU interrupts ? */
19770 char ignore_fpu_irq;
19771 -
19772 -/*
19773 - * The IDT has to be page-aligned to simplify the Pentium
19774 - * F0 0F bug workaround.
19775 - */
19776 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19777 #endif
19778
19779 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19780 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19781 }
19782
19783 static void __kprobes
19784 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19785 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19786 long error_code, siginfo_t *info)
19787 {
19788 struct task_struct *tsk = current;
19789
19790 #ifdef CONFIG_X86_32
19791 - if (regs->flags & X86_VM_MASK) {
19792 + if (v8086_mode(regs)) {
19793 /*
19794 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19795 * On nmi (interrupt 2), do_trap should not be called.
19796 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19797 }
19798 #endif
19799
19800 - if (!user_mode(regs))
19801 + if (!user_mode_novm(regs))
19802 goto kernel_trap;
19803
19804 #ifdef CONFIG_X86_32
19805 @@ -147,7 +141,7 @@ trap_signal:
19806 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19807 printk_ratelimit()) {
19808 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19809 - tsk->comm, tsk->pid, str,
19810 + tsk->comm, task_pid_nr(tsk), str,
19811 regs->ip, regs->sp, error_code);
19812 print_vma_addr(" in ", regs->ip);
19813 pr_cont("\n");
19814 @@ -164,8 +158,20 @@ kernel_trap:
19815 if (!fixup_exception(regs)) {
19816 tsk->thread.error_code = error_code;
19817 tsk->thread.trap_nr = trapnr;
19818 +
19819 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19820 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19821 + str = "PAX: suspicious stack segment fault";
19822 +#endif
19823 +
19824 die(str, regs, error_code);
19825 }
19826 +
19827 +#ifdef CONFIG_PAX_REFCOUNT
19828 + if (trapnr == 4)
19829 + pax_report_refcount_overflow(regs);
19830 +#endif
19831 +
19832 return;
19833
19834 #ifdef CONFIG_X86_32
19835 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19836 conditional_sti(regs);
19837
19838 #ifdef CONFIG_X86_32
19839 - if (regs->flags & X86_VM_MASK)
19840 + if (v8086_mode(regs))
19841 goto gp_in_vm86;
19842 #endif
19843
19844 tsk = current;
19845 - if (!user_mode(regs))
19846 + if (!user_mode_novm(regs))
19847 goto gp_in_kernel;
19848
19849 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19850 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19851 + struct mm_struct *mm = tsk->mm;
19852 + unsigned long limit;
19853 +
19854 + down_write(&mm->mmap_sem);
19855 + limit = mm->context.user_cs_limit;
19856 + if (limit < TASK_SIZE) {
19857 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19858 + up_write(&mm->mmap_sem);
19859 + return;
19860 + }
19861 + up_write(&mm->mmap_sem);
19862 + }
19863 +#endif
19864 +
19865 tsk->thread.error_code = error_code;
19866 tsk->thread.trap_nr = X86_TRAP_GP;
19867
19868 @@ -297,6 +319,13 @@ gp_in_kernel:
19869 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19870 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19871 return;
19872 +
19873 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19874 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19875 + die("PAX: suspicious general protection fault", regs, error_code);
19876 + else
19877 +#endif
19878 +
19879 die("general protection fault", regs, error_code);
19880 }
19881
19882 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19883 /* It's safe to allow irq's after DR6 has been saved */
19884 preempt_conditional_sti(regs);
19885
19886 - if (regs->flags & X86_VM_MASK) {
19887 + if (v8086_mode(regs)) {
19888 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19889 X86_TRAP_DB);
19890 preempt_conditional_cli(regs);
19891 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19892 * We already checked v86 mode above, so we can check for kernel mode
19893 * by just checking the CPL of CS.
19894 */
19895 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19896 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19897 tsk->thread.debugreg6 &= ~DR_STEP;
19898 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19899 regs->flags &= ~X86_EFLAGS_TF;
19900 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19901 return;
19902 conditional_sti(regs);
19903
19904 - if (!user_mode_vm(regs))
19905 + if (!user_mode(regs))
19906 {
19907 if (!fixup_exception(regs)) {
19908 task->thread.error_code = error_code;
19909 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19910 index 36fd420..7e5892d 100644
19911 --- a/arch/x86/kernel/uprobes.c
19912 +++ b/arch/x86/kernel/uprobes.c
19913 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19914 int ret = NOTIFY_DONE;
19915
19916 /* We are only interested in userspace traps */
19917 - if (regs && !user_mode_vm(regs))
19918 + if (regs && !user_mode(regs))
19919 return NOTIFY_DONE;
19920
19921 switch (val) {
19922 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19923 index b9242ba..50c5edd 100644
19924 --- a/arch/x86/kernel/verify_cpu.S
19925 +++ b/arch/x86/kernel/verify_cpu.S
19926 @@ -20,6 +20,7 @@
19927 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19928 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19929 * arch/x86/kernel/head_32.S: processor startup
19930 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19931 *
19932 * verify_cpu, returns the status of longmode and SSE in register %eax.
19933 * 0: Success 1: Failure
19934 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19935 index 54abcc0..eb6c848 100644
19936 --- a/arch/x86/kernel/vm86_32.c
19937 +++ b/arch/x86/kernel/vm86_32.c
19938 @@ -43,6 +43,7 @@
19939 #include <linux/ptrace.h>
19940 #include <linux/audit.h>
19941 #include <linux/stddef.h>
19942 +#include <linux/grsecurity.h>
19943
19944 #include <asm/uaccess.h>
19945 #include <asm/io.h>
19946 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19947 do_exit(SIGSEGV);
19948 }
19949
19950 - tss = &per_cpu(init_tss, get_cpu());
19951 + tss = init_tss + get_cpu();
19952 current->thread.sp0 = current->thread.saved_sp0;
19953 current->thread.sysenter_cs = __KERNEL_CS;
19954 load_sp0(tss, &current->thread);
19955 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19956 struct task_struct *tsk;
19957 int tmp, ret = -EPERM;
19958
19959 +#ifdef CONFIG_GRKERNSEC_VM86
19960 + if (!capable(CAP_SYS_RAWIO)) {
19961 + gr_handle_vm86();
19962 + goto out;
19963 + }
19964 +#endif
19965 +
19966 tsk = current;
19967 if (tsk->thread.saved_sp0)
19968 goto out;
19969 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19970 int tmp, ret;
19971 struct vm86plus_struct __user *v86;
19972
19973 +#ifdef CONFIG_GRKERNSEC_VM86
19974 + if (!capable(CAP_SYS_RAWIO)) {
19975 + gr_handle_vm86();
19976 + ret = -EPERM;
19977 + goto out;
19978 + }
19979 +#endif
19980 +
19981 tsk = current;
19982 switch (cmd) {
19983 case VM86_REQUEST_IRQ:
19984 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19985 tsk->thread.saved_fs = info->regs32->fs;
19986 tsk->thread.saved_gs = get_user_gs(info->regs32);
19987
19988 - tss = &per_cpu(init_tss, get_cpu());
19989 + tss = init_tss + get_cpu();
19990 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19991 if (cpu_has_sep)
19992 tsk->thread.sysenter_cs = 0;
19993 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19994 goto cannot_handle;
19995 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19996 goto cannot_handle;
19997 - intr_ptr = (unsigned long __user *) (i << 2);
19998 + intr_ptr = (__force unsigned long __user *) (i << 2);
19999 if (get_user(segoffs, intr_ptr))
20000 goto cannot_handle;
20001 if ((segoffs >> 16) == BIOSSEG)
20002 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20003 index 22a1530..8fbaaad 100644
20004 --- a/arch/x86/kernel/vmlinux.lds.S
20005 +++ b/arch/x86/kernel/vmlinux.lds.S
20006 @@ -26,6 +26,13 @@
20007 #include <asm/page_types.h>
20008 #include <asm/cache.h>
20009 #include <asm/boot.h>
20010 +#include <asm/segment.h>
20011 +
20012 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20013 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20014 +#else
20015 +#define __KERNEL_TEXT_OFFSET 0
20016 +#endif
20017
20018 #undef i386 /* in case the preprocessor is a 32bit one */
20019
20020 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20021
20022 PHDRS {
20023 text PT_LOAD FLAGS(5); /* R_E */
20024 +#ifdef CONFIG_X86_32
20025 + module PT_LOAD FLAGS(5); /* R_E */
20026 +#endif
20027 +#ifdef CONFIG_XEN
20028 + rodata PT_LOAD FLAGS(5); /* R_E */
20029 +#else
20030 + rodata PT_LOAD FLAGS(4); /* R__ */
20031 +#endif
20032 data PT_LOAD FLAGS(6); /* RW_ */
20033 -#ifdef CONFIG_X86_64
20034 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20035 #ifdef CONFIG_SMP
20036 percpu PT_LOAD FLAGS(6); /* RW_ */
20037 #endif
20038 + text.init PT_LOAD FLAGS(5); /* R_E */
20039 + text.exit PT_LOAD FLAGS(5); /* R_E */
20040 init PT_LOAD FLAGS(7); /* RWE */
20041 -#endif
20042 note PT_NOTE FLAGS(0); /* ___ */
20043 }
20044
20045 SECTIONS
20046 {
20047 #ifdef CONFIG_X86_32
20048 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20049 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20050 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20051 #else
20052 - . = __START_KERNEL;
20053 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20054 + . = __START_KERNEL;
20055 #endif
20056
20057 /* Text and read-only data */
20058 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20059 - _text = .;
20060 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20061 /* bootstrapping code */
20062 +#ifdef CONFIG_X86_32
20063 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20064 +#else
20065 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20066 +#endif
20067 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20068 + _text = .;
20069 HEAD_TEXT
20070 #ifdef CONFIG_X86_32
20071 . = ALIGN(PAGE_SIZE);
20072 @@ -108,13 +128,48 @@ SECTIONS
20073 IRQENTRY_TEXT
20074 *(.fixup)
20075 *(.gnu.warning)
20076 - /* End of text section */
20077 - _etext = .;
20078 } :text = 0x9090
20079
20080 - NOTES :text :note
20081 + . += __KERNEL_TEXT_OFFSET;
20082
20083 - EXCEPTION_TABLE(16) :text = 0x9090
20084 +#ifdef CONFIG_X86_32
20085 + . = ALIGN(PAGE_SIZE);
20086 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20087 +
20088 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20089 + MODULES_EXEC_VADDR = .;
20090 + BYTE(0)
20091 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20092 + . = ALIGN(HPAGE_SIZE) - 1;
20093 + MODULES_EXEC_END = .;
20094 +#endif
20095 +
20096 + } :module
20097 +#endif
20098 +
20099 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20100 + /* End of text section */
20101 + BYTE(0)
20102 + _etext = . - __KERNEL_TEXT_OFFSET;
20103 + }
20104 +
20105 +#ifdef CONFIG_X86_32
20106 + . = ALIGN(PAGE_SIZE);
20107 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20108 + *(.idt)
20109 + . = ALIGN(PAGE_SIZE);
20110 + *(.empty_zero_page)
20111 + *(.initial_pg_fixmap)
20112 + *(.initial_pg_pmd)
20113 + *(.initial_page_table)
20114 + *(.swapper_pg_dir)
20115 + } :rodata
20116 +#endif
20117 +
20118 + . = ALIGN(PAGE_SIZE);
20119 + NOTES :rodata :note
20120 +
20121 + EXCEPTION_TABLE(16) :rodata
20122
20123 #if defined(CONFIG_DEBUG_RODATA)
20124 /* .text should occupy whole number of pages */
20125 @@ -126,16 +181,20 @@ SECTIONS
20126
20127 /* Data */
20128 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20129 +
20130 +#ifdef CONFIG_PAX_KERNEXEC
20131 + . = ALIGN(HPAGE_SIZE);
20132 +#else
20133 + . = ALIGN(PAGE_SIZE);
20134 +#endif
20135 +
20136 /* Start of data section */
20137 _sdata = .;
20138
20139 /* init_task */
20140 INIT_TASK_DATA(THREAD_SIZE)
20141
20142 -#ifdef CONFIG_X86_32
20143 - /* 32 bit has nosave before _edata */
20144 NOSAVE_DATA
20145 -#endif
20146
20147 PAGE_ALIGNED_DATA(PAGE_SIZE)
20148
20149 @@ -176,12 +235,19 @@ SECTIONS
20150 #endif /* CONFIG_X86_64 */
20151
20152 /* Init code and data - will be freed after init */
20153 - . = ALIGN(PAGE_SIZE);
20154 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20155 + BYTE(0)
20156 +
20157 +#ifdef CONFIG_PAX_KERNEXEC
20158 + . = ALIGN(HPAGE_SIZE);
20159 +#else
20160 + . = ALIGN(PAGE_SIZE);
20161 +#endif
20162 +
20163 __init_begin = .; /* paired with __init_end */
20164 - }
20165 + } :init.begin
20166
20167 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20168 +#ifdef CONFIG_SMP
20169 /*
20170 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20171 * output PHDR, so the next output section - .init.text - should
20172 @@ -190,12 +256,27 @@ SECTIONS
20173 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20174 #endif
20175
20176 - INIT_TEXT_SECTION(PAGE_SIZE)
20177 -#ifdef CONFIG_X86_64
20178 - :init
20179 -#endif
20180 + . = ALIGN(PAGE_SIZE);
20181 + init_begin = .;
20182 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20183 + VMLINUX_SYMBOL(_sinittext) = .;
20184 + INIT_TEXT
20185 + VMLINUX_SYMBOL(_einittext) = .;
20186 + . = ALIGN(PAGE_SIZE);
20187 + } :text.init
20188
20189 - INIT_DATA_SECTION(16)
20190 + /*
20191 + * .exit.text is discard at runtime, not link time, to deal with
20192 + * references from .altinstructions and .eh_frame
20193 + */
20194 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20195 + EXIT_TEXT
20196 + . = ALIGN(16);
20197 + } :text.exit
20198 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20199 +
20200 + . = ALIGN(PAGE_SIZE);
20201 + INIT_DATA_SECTION(16) :init
20202
20203 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20204 __x86_cpu_dev_start = .;
20205 @@ -257,19 +338,12 @@ SECTIONS
20206 }
20207
20208 . = ALIGN(8);
20209 - /*
20210 - * .exit.text is discard at runtime, not link time, to deal with
20211 - * references from .altinstructions and .eh_frame
20212 - */
20213 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20214 - EXIT_TEXT
20215 - }
20216
20217 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20218 EXIT_DATA
20219 }
20220
20221 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20222 +#ifndef CONFIG_SMP
20223 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20224 #endif
20225
20226 @@ -288,16 +362,10 @@ SECTIONS
20227 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20228 __smp_locks = .;
20229 *(.smp_locks)
20230 - . = ALIGN(PAGE_SIZE);
20231 __smp_locks_end = .;
20232 + . = ALIGN(PAGE_SIZE);
20233 }
20234
20235 -#ifdef CONFIG_X86_64
20236 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20237 - NOSAVE_DATA
20238 - }
20239 -#endif
20240 -
20241 /* BSS */
20242 . = ALIGN(PAGE_SIZE);
20243 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20244 @@ -313,6 +381,7 @@ SECTIONS
20245 __brk_base = .;
20246 . += 64 * 1024; /* 64k alignment slop space */
20247 *(.brk_reservation) /* areas brk users have reserved */
20248 + . = ALIGN(HPAGE_SIZE);
20249 __brk_limit = .;
20250 }
20251
20252 @@ -339,13 +408,12 @@ SECTIONS
20253 * for the boot processor.
20254 */
20255 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20256 -INIT_PER_CPU(gdt_page);
20257 INIT_PER_CPU(irq_stack_union);
20258
20259 /*
20260 * Build-time check on the image size:
20261 */
20262 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20263 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20264 "kernel image bigger than KERNEL_IMAGE_SIZE");
20265
20266 #ifdef CONFIG_SMP
20267 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20268 index 992f890..fc38904 100644
20269 --- a/arch/x86/kernel/vsmp_64.c
20270 +++ b/arch/x86/kernel/vsmp_64.c
20271 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20272 static void vsmp_apic_post_init(void)
20273 {
20274 /* need to update phys_pkg_id */
20275 - apic->phys_pkg_id = apicid_phys_pkg_id;
20276 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20277 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20278 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20279 }
20280
20281 void __init vsmp_init(void)
20282 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20283 index 8d141b3..40a0fe4 100644
20284 --- a/arch/x86/kernel/vsyscall_64.c
20285 +++ b/arch/x86/kernel/vsyscall_64.c
20286 @@ -56,15 +56,13 @@
20287 DEFINE_VVAR(int, vgetcpu_mode);
20288 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20289
20290 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20291 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20292
20293 static int __init vsyscall_setup(char *str)
20294 {
20295 if (str) {
20296 if (!strcmp("emulate", str))
20297 vsyscall_mode = EMULATE;
20298 - else if (!strcmp("native", str))
20299 - vsyscall_mode = NATIVE;
20300 else if (!strcmp("none", str))
20301 vsyscall_mode = NONE;
20302 else
20303 @@ -306,8 +304,7 @@ done:
20304 return true;
20305
20306 sigsegv:
20307 - force_sig(SIGSEGV, current);
20308 - return true;
20309 + do_group_exit(SIGKILL);
20310 }
20311
20312 /*
20313 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20314 extern char __vvar_page;
20315 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20316
20317 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20318 - vsyscall_mode == NATIVE
20319 - ? PAGE_KERNEL_VSYSCALL
20320 - : PAGE_KERNEL_VVAR);
20321 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20322 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20323 (unsigned long)VSYSCALL_START);
20324
20325 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20326 index 6020f6f..bedd6e3 100644
20327 --- a/arch/x86/kernel/x8664_ksyms_64.c
20328 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20329 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20330 EXPORT_SYMBOL(copy_user_generic_unrolled);
20331 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20332 EXPORT_SYMBOL(__copy_user_nocache);
20333 -EXPORT_SYMBOL(_copy_from_user);
20334 -EXPORT_SYMBOL(_copy_to_user);
20335
20336 EXPORT_SYMBOL(copy_page);
20337 EXPORT_SYMBOL(clear_page);
20338 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20339 index 3d3e207..1a73ab2 100644
20340 --- a/arch/x86/kernel/xsave.c
20341 +++ b/arch/x86/kernel/xsave.c
20342 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20343 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20344 return -EINVAL;
20345
20346 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20347 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20348 fx_sw_user->extended_size -
20349 FP_XSTATE_MAGIC2_SIZE));
20350 if (err)
20351 @@ -268,7 +268,7 @@ fx_only:
20352 * the other extended state.
20353 */
20354 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20355 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20356 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20357 }
20358
20359 /*
20360 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20361 if (use_xsave())
20362 err = restore_user_xstate(buf);
20363 else
20364 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20365 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20366 buf);
20367 if (unlikely(err)) {
20368 /*
20369 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20370 index 0595f13..b544fa3 100644
20371 --- a/arch/x86/kvm/cpuid.c
20372 +++ b/arch/x86/kvm/cpuid.c
20373 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20374 struct kvm_cpuid2 *cpuid,
20375 struct kvm_cpuid_entry2 __user *entries)
20376 {
20377 - int r;
20378 + int r, i;
20379
20380 r = -E2BIG;
20381 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20382 goto out;
20383 r = -EFAULT;
20384 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20385 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20386 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20387 goto out;
20388 + for (i = 0; i < cpuid->nent; ++i) {
20389 + struct kvm_cpuid_entry2 cpuid_entry;
20390 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20391 + goto out;
20392 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20393 + }
20394 vcpu->arch.cpuid_nent = cpuid->nent;
20395 kvm_apic_set_version(vcpu);
20396 kvm_x86_ops->cpuid_update(vcpu);
20397 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20398 struct kvm_cpuid2 *cpuid,
20399 struct kvm_cpuid_entry2 __user *entries)
20400 {
20401 - int r;
20402 + int r, i;
20403
20404 r = -E2BIG;
20405 if (cpuid->nent < vcpu->arch.cpuid_nent)
20406 goto out;
20407 r = -EFAULT;
20408 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20409 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20410 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20411 goto out;
20412 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20413 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20414 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20415 + goto out;
20416 + }
20417 return 0;
20418
20419 out:
20420 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20421 index a3b57a2..ebbe732 100644
20422 --- a/arch/x86/kvm/emulate.c
20423 +++ b/arch/x86/kvm/emulate.c
20424 @@ -256,6 +256,7 @@ struct gprefix {
20425
20426 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20427 do { \
20428 + unsigned long _tmp; \
20429 __asm__ __volatile__ ( \
20430 _PRE_EFLAGS("0", "4", "2") \
20431 _op _suffix " %"_x"3,%1; " \
20432 @@ -270,8 +271,6 @@ struct gprefix {
20433 /* Raw emulation: instruction has two explicit operands. */
20434 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20435 do { \
20436 - unsigned long _tmp; \
20437 - \
20438 switch ((ctxt)->dst.bytes) { \
20439 case 2: \
20440 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20441 @@ -287,7 +286,6 @@ struct gprefix {
20442
20443 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20444 do { \
20445 - unsigned long _tmp; \
20446 switch ((ctxt)->dst.bytes) { \
20447 case 1: \
20448 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20449 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20450 index ce87878..ab48aa3 100644
20451 --- a/arch/x86/kvm/lapic.c
20452 +++ b/arch/x86/kvm/lapic.c
20453 @@ -54,7 +54,7 @@
20454 #define APIC_BUS_CYCLE_NS 1
20455
20456 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20457 -#define apic_debug(fmt, arg...)
20458 +#define apic_debug(fmt, arg...) do {} while (0)
20459
20460 #define APIC_LVT_NUM 6
20461 /* 14 is the version for Xeon and Pentium 8.4.8*/
20462 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20463 index bb7cf01..0348a05 100644
20464 --- a/arch/x86/kvm/paging_tmpl.h
20465 +++ b/arch/x86/kvm/paging_tmpl.h
20466 @@ -196,7 +196,7 @@ retry_walk:
20467 if (unlikely(kvm_is_error_hva(host_addr)))
20468 goto error;
20469
20470 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20471 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20472 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20473 goto error;
20474
20475 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20476 index baead95..90feeb4 100644
20477 --- a/arch/x86/kvm/svm.c
20478 +++ b/arch/x86/kvm/svm.c
20479 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20480 int cpu = raw_smp_processor_id();
20481
20482 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20483 +
20484 + pax_open_kernel();
20485 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20486 + pax_close_kernel();
20487 +
20488 load_TR_desc();
20489 }
20490
20491 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20492 #endif
20493 #endif
20494
20495 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20496 + __set_fs(current_thread_info()->addr_limit);
20497 +#endif
20498 +
20499 reload_tss(vcpu);
20500
20501 local_irq_disable();
20502 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20503 index b1eb202..254e292 100644
20504 --- a/arch/x86/kvm/vmx.c
20505 +++ b/arch/x86/kvm/vmx.c
20506 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20507 struct desc_struct *descs;
20508
20509 descs = (void *)gdt->address;
20510 +
20511 + pax_open_kernel();
20512 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20513 + pax_close_kernel();
20514 +
20515 load_TR_desc();
20516 }
20517
20518 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20519 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20520 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20521
20522 +#ifdef CONFIG_PAX_PER_CPU_PGD
20523 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20524 +#endif
20525 +
20526 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20527 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20528 vmx->loaded_vmcs->cpu = cpu;
20529 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20530 if (!cpu_has_vmx_flexpriority())
20531 flexpriority_enabled = 0;
20532
20533 - if (!cpu_has_vmx_tpr_shadow())
20534 - kvm_x86_ops->update_cr8_intercept = NULL;
20535 + if (!cpu_has_vmx_tpr_shadow()) {
20536 + pax_open_kernel();
20537 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20538 + pax_close_kernel();
20539 + }
20540
20541 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20542 kvm_disable_largepages();
20543 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20544
20545 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20546 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20547 +
20548 +#ifndef CONFIG_PAX_PER_CPU_PGD
20549 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20550 +#endif
20551
20552 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20553 #ifdef CONFIG_X86_64
20554 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20555 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20556
20557 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20558 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20559 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20560
20561 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20562 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20563 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20564 "jmp .Lkvm_vmx_return \n\t"
20565 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20566 ".Lkvm_vmx_return: "
20567 +
20568 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20569 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20570 + ".Lkvm_vmx_return2: "
20571 +#endif
20572 +
20573 /* Save guest registers, load host registers, keep flags */
20574 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20575 "pop %0 \n\t"
20576 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20577 #endif
20578 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20579 [wordsize]"i"(sizeof(ulong))
20580 +
20581 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20582 + ,[cs]"i"(__KERNEL_CS)
20583 +#endif
20584 +
20585 : "cc", "memory"
20586 , R"ax", R"bx", R"di", R"si"
20587 #ifdef CONFIG_X86_64
20588 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20589 #endif
20590 );
20591
20592 -#ifndef CONFIG_X86_64
20593 +#ifdef CONFIG_X86_32
20594 /*
20595 * The sysexit path does not restore ds/es, so we must set them to
20596 * a reasonable value ourselves.
20597 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20598 * may be executed in interrupt context, which saves and restore segments
20599 * around it, nullifying its effect.
20600 */
20601 - loadsegment(ds, __USER_DS);
20602 - loadsegment(es, __USER_DS);
20603 + loadsegment(ds, __KERNEL_DS);
20604 + loadsegment(es, __KERNEL_DS);
20605 + loadsegment(ss, __KERNEL_DS);
20606 +
20607 +#ifdef CONFIG_PAX_KERNEXEC
20608 + loadsegment(fs, __KERNEL_PERCPU);
20609 +#endif
20610 +
20611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20612 + __set_fs(current_thread_info()->addr_limit);
20613 +#endif
20614 +
20615 #endif
20616
20617 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20618 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20619 index 2966c84..207d0cb 100644
20620 --- a/arch/x86/kvm/x86.c
20621 +++ b/arch/x86/kvm/x86.c
20622 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20623 {
20624 struct kvm *kvm = vcpu->kvm;
20625 int lm = is_long_mode(vcpu);
20626 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20627 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20628 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20629 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20630 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20631 : kvm->arch.xen_hvm_config.blob_size_32;
20632 u32 page_num = data & ~PAGE_MASK;
20633 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20634 if (n < msr_list.nmsrs)
20635 goto out;
20636 r = -EFAULT;
20637 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20638 + goto out;
20639 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20640 num_msrs_to_save * sizeof(u32)))
20641 goto out;
20642 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20643 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20644 struct kvm_interrupt *irq)
20645 {
20646 - if (irq->irq < 0 || irq->irq >= 256)
20647 + if (irq->irq >= 256)
20648 return -EINVAL;
20649 if (irqchip_in_kernel(vcpu->kvm))
20650 return -ENXIO;
20651 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20652 kvm_mmu_set_mmio_spte_mask(mask);
20653 }
20654
20655 -int kvm_arch_init(void *opaque)
20656 +int kvm_arch_init(const void *opaque)
20657 {
20658 int r;
20659 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20660 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20661 index 642d880..cc9ebac 100644
20662 --- a/arch/x86/lguest/boot.c
20663 +++ b/arch/x86/lguest/boot.c
20664 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20665
20666 static void set_lguest_basic_apic_ops(void)
20667 {
20668 - apic->read = lguest_apic_read;
20669 - apic->write = lguest_apic_write;
20670 - apic->icr_read = lguest_apic_icr_read;
20671 - apic->icr_write = lguest_apic_icr_write;
20672 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20673 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20674 + *(void **)&apic->read = lguest_apic_read;
20675 + *(void **)&apic->write = lguest_apic_write;
20676 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20677 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20678 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20679 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20680 };
20681 #endif
20682
20683 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20684 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20685 * Launcher to reboot us.
20686 */
20687 -static void lguest_restart(char *reason)
20688 +static __noreturn void lguest_restart(char *reason)
20689 {
20690 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20691 + BUG();
20692 }
20693
20694 /*G:050
20695 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20696 index 00933d5..3a64af9 100644
20697 --- a/arch/x86/lib/atomic64_386_32.S
20698 +++ b/arch/x86/lib/atomic64_386_32.S
20699 @@ -48,6 +48,10 @@ BEGIN(read)
20700 movl (v), %eax
20701 movl 4(v), %edx
20702 RET_ENDP
20703 +BEGIN(read_unchecked)
20704 + movl (v), %eax
20705 + movl 4(v), %edx
20706 +RET_ENDP
20707 #undef v
20708
20709 #define v %esi
20710 @@ -55,6 +59,10 @@ BEGIN(set)
20711 movl %ebx, (v)
20712 movl %ecx, 4(v)
20713 RET_ENDP
20714 +BEGIN(set_unchecked)
20715 + movl %ebx, (v)
20716 + movl %ecx, 4(v)
20717 +RET_ENDP
20718 #undef v
20719
20720 #define v %esi
20721 @@ -70,6 +78,20 @@ RET_ENDP
20722 BEGIN(add)
20723 addl %eax, (v)
20724 adcl %edx, 4(v)
20725 +
20726 +#ifdef CONFIG_PAX_REFCOUNT
20727 + jno 0f
20728 + subl %eax, (v)
20729 + sbbl %edx, 4(v)
20730 + int $4
20731 +0:
20732 + _ASM_EXTABLE(0b, 0b)
20733 +#endif
20734 +
20735 +RET_ENDP
20736 +BEGIN(add_unchecked)
20737 + addl %eax, (v)
20738 + adcl %edx, 4(v)
20739 RET_ENDP
20740 #undef v
20741
20742 @@ -77,6 +99,24 @@ RET_ENDP
20743 BEGIN(add_return)
20744 addl (v), %eax
20745 adcl 4(v), %edx
20746 +
20747 +#ifdef CONFIG_PAX_REFCOUNT
20748 + into
20749 +1234:
20750 + _ASM_EXTABLE(1234b, 2f)
20751 +#endif
20752 +
20753 + movl %eax, (v)
20754 + movl %edx, 4(v)
20755 +
20756 +#ifdef CONFIG_PAX_REFCOUNT
20757 +2:
20758 +#endif
20759 +
20760 +RET_ENDP
20761 +BEGIN(add_return_unchecked)
20762 + addl (v), %eax
20763 + adcl 4(v), %edx
20764 movl %eax, (v)
20765 movl %edx, 4(v)
20766 RET_ENDP
20767 @@ -86,6 +126,20 @@ RET_ENDP
20768 BEGIN(sub)
20769 subl %eax, (v)
20770 sbbl %edx, 4(v)
20771 +
20772 +#ifdef CONFIG_PAX_REFCOUNT
20773 + jno 0f
20774 + addl %eax, (v)
20775 + adcl %edx, 4(v)
20776 + int $4
20777 +0:
20778 + _ASM_EXTABLE(0b, 0b)
20779 +#endif
20780 +
20781 +RET_ENDP
20782 +BEGIN(sub_unchecked)
20783 + subl %eax, (v)
20784 + sbbl %edx, 4(v)
20785 RET_ENDP
20786 #undef v
20787
20788 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20789 sbbl $0, %edx
20790 addl (v), %eax
20791 adcl 4(v), %edx
20792 +
20793 +#ifdef CONFIG_PAX_REFCOUNT
20794 + into
20795 +1234:
20796 + _ASM_EXTABLE(1234b, 2f)
20797 +#endif
20798 +
20799 + movl %eax, (v)
20800 + movl %edx, 4(v)
20801 +
20802 +#ifdef CONFIG_PAX_REFCOUNT
20803 +2:
20804 +#endif
20805 +
20806 +RET_ENDP
20807 +BEGIN(sub_return_unchecked)
20808 + negl %edx
20809 + negl %eax
20810 + sbbl $0, %edx
20811 + addl (v), %eax
20812 + adcl 4(v), %edx
20813 movl %eax, (v)
20814 movl %edx, 4(v)
20815 RET_ENDP
20816 @@ -105,6 +180,20 @@ RET_ENDP
20817 BEGIN(inc)
20818 addl $1, (v)
20819 adcl $0, 4(v)
20820 +
20821 +#ifdef CONFIG_PAX_REFCOUNT
20822 + jno 0f
20823 + subl $1, (v)
20824 + sbbl $0, 4(v)
20825 + int $4
20826 +0:
20827 + _ASM_EXTABLE(0b, 0b)
20828 +#endif
20829 +
20830 +RET_ENDP
20831 +BEGIN(inc_unchecked)
20832 + addl $1, (v)
20833 + adcl $0, 4(v)
20834 RET_ENDP
20835 #undef v
20836
20837 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20838 movl 4(v), %edx
20839 addl $1, %eax
20840 adcl $0, %edx
20841 +
20842 +#ifdef CONFIG_PAX_REFCOUNT
20843 + into
20844 +1234:
20845 + _ASM_EXTABLE(1234b, 2f)
20846 +#endif
20847 +
20848 + movl %eax, (v)
20849 + movl %edx, 4(v)
20850 +
20851 +#ifdef CONFIG_PAX_REFCOUNT
20852 +2:
20853 +#endif
20854 +
20855 +RET_ENDP
20856 +BEGIN(inc_return_unchecked)
20857 + movl (v), %eax
20858 + movl 4(v), %edx
20859 + addl $1, %eax
20860 + adcl $0, %edx
20861 movl %eax, (v)
20862 movl %edx, 4(v)
20863 RET_ENDP
20864 @@ -123,6 +232,20 @@ RET_ENDP
20865 BEGIN(dec)
20866 subl $1, (v)
20867 sbbl $0, 4(v)
20868 +
20869 +#ifdef CONFIG_PAX_REFCOUNT
20870 + jno 0f
20871 + addl $1, (v)
20872 + adcl $0, 4(v)
20873 + int $4
20874 +0:
20875 + _ASM_EXTABLE(0b, 0b)
20876 +#endif
20877 +
20878 +RET_ENDP
20879 +BEGIN(dec_unchecked)
20880 + subl $1, (v)
20881 + sbbl $0, 4(v)
20882 RET_ENDP
20883 #undef v
20884
20885 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20886 movl 4(v), %edx
20887 subl $1, %eax
20888 sbbl $0, %edx
20889 +
20890 +#ifdef CONFIG_PAX_REFCOUNT
20891 + into
20892 +1234:
20893 + _ASM_EXTABLE(1234b, 2f)
20894 +#endif
20895 +
20896 + movl %eax, (v)
20897 + movl %edx, 4(v)
20898 +
20899 +#ifdef CONFIG_PAX_REFCOUNT
20900 +2:
20901 +#endif
20902 +
20903 +RET_ENDP
20904 +BEGIN(dec_return_unchecked)
20905 + movl (v), %eax
20906 + movl 4(v), %edx
20907 + subl $1, %eax
20908 + sbbl $0, %edx
20909 movl %eax, (v)
20910 movl %edx, 4(v)
20911 RET_ENDP
20912 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20913 adcl %edx, %edi
20914 addl (v), %eax
20915 adcl 4(v), %edx
20916 +
20917 +#ifdef CONFIG_PAX_REFCOUNT
20918 + into
20919 +1234:
20920 + _ASM_EXTABLE(1234b, 2f)
20921 +#endif
20922 +
20923 cmpl %eax, %ecx
20924 je 3f
20925 1:
20926 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20927 1:
20928 addl $1, %eax
20929 adcl $0, %edx
20930 +
20931 +#ifdef CONFIG_PAX_REFCOUNT
20932 + into
20933 +1234:
20934 + _ASM_EXTABLE(1234b, 2f)
20935 +#endif
20936 +
20937 movl %eax, (v)
20938 movl %edx, 4(v)
20939 movl $1, %eax
20940 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20941 movl 4(v), %edx
20942 subl $1, %eax
20943 sbbl $0, %edx
20944 +
20945 +#ifdef CONFIG_PAX_REFCOUNT
20946 + into
20947 +1234:
20948 + _ASM_EXTABLE(1234b, 1f)
20949 +#endif
20950 +
20951 js 1f
20952 movl %eax, (v)
20953 movl %edx, 4(v)
20954 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20955 index f5cc9eb..51fa319 100644
20956 --- a/arch/x86/lib/atomic64_cx8_32.S
20957 +++ b/arch/x86/lib/atomic64_cx8_32.S
20958 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20959 CFI_STARTPROC
20960
20961 read64 %ecx
20962 + pax_force_retaddr
20963 ret
20964 CFI_ENDPROC
20965 ENDPROC(atomic64_read_cx8)
20966
20967 +ENTRY(atomic64_read_unchecked_cx8)
20968 + CFI_STARTPROC
20969 +
20970 + read64 %ecx
20971 + pax_force_retaddr
20972 + ret
20973 + CFI_ENDPROC
20974 +ENDPROC(atomic64_read_unchecked_cx8)
20975 +
20976 ENTRY(atomic64_set_cx8)
20977 CFI_STARTPROC
20978
20979 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20980 cmpxchg8b (%esi)
20981 jne 1b
20982
20983 + pax_force_retaddr
20984 ret
20985 CFI_ENDPROC
20986 ENDPROC(atomic64_set_cx8)
20987
20988 +ENTRY(atomic64_set_unchecked_cx8)
20989 + CFI_STARTPROC
20990 +
20991 +1:
20992 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20993 + * are atomic on 586 and newer */
20994 + cmpxchg8b (%esi)
20995 + jne 1b
20996 +
20997 + pax_force_retaddr
20998 + ret
20999 + CFI_ENDPROC
21000 +ENDPROC(atomic64_set_unchecked_cx8)
21001 +
21002 ENTRY(atomic64_xchg_cx8)
21003 CFI_STARTPROC
21004
21005 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21006 cmpxchg8b (%esi)
21007 jne 1b
21008
21009 + pax_force_retaddr
21010 ret
21011 CFI_ENDPROC
21012 ENDPROC(atomic64_xchg_cx8)
21013
21014 -.macro addsub_return func ins insc
21015 -ENTRY(atomic64_\func\()_return_cx8)
21016 +.macro addsub_return func ins insc unchecked=""
21017 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21018 CFI_STARTPROC
21019 SAVE ebp
21020 SAVE ebx
21021 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21022 movl %edx, %ecx
21023 \ins\()l %esi, %ebx
21024 \insc\()l %edi, %ecx
21025 +
21026 +.ifb \unchecked
21027 +#ifdef CONFIG_PAX_REFCOUNT
21028 + into
21029 +2:
21030 + _ASM_EXTABLE(2b, 3f)
21031 +#endif
21032 +.endif
21033 +
21034 LOCK_PREFIX
21035 cmpxchg8b (%ebp)
21036 jne 1b
21037 -
21038 -10:
21039 movl %ebx, %eax
21040 movl %ecx, %edx
21041 +
21042 +.ifb \unchecked
21043 +#ifdef CONFIG_PAX_REFCOUNT
21044 +3:
21045 +#endif
21046 +.endif
21047 +
21048 RESTORE edi
21049 RESTORE esi
21050 RESTORE ebx
21051 RESTORE ebp
21052 + pax_force_retaddr
21053 ret
21054 CFI_ENDPROC
21055 -ENDPROC(atomic64_\func\()_return_cx8)
21056 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21057 .endm
21058
21059 addsub_return add add adc
21060 addsub_return sub sub sbb
21061 +addsub_return add add adc _unchecked
21062 +addsub_return sub sub sbb _unchecked
21063
21064 -.macro incdec_return func ins insc
21065 -ENTRY(atomic64_\func\()_return_cx8)
21066 +.macro incdec_return func ins insc unchecked=""
21067 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21068 CFI_STARTPROC
21069 SAVE ebx
21070
21071 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21072 movl %edx, %ecx
21073 \ins\()l $1, %ebx
21074 \insc\()l $0, %ecx
21075 +
21076 +.ifb \unchecked
21077 +#ifdef CONFIG_PAX_REFCOUNT
21078 + into
21079 +2:
21080 + _ASM_EXTABLE(2b, 3f)
21081 +#endif
21082 +.endif
21083 +
21084 LOCK_PREFIX
21085 cmpxchg8b (%esi)
21086 jne 1b
21087
21088 -10:
21089 movl %ebx, %eax
21090 movl %ecx, %edx
21091 +
21092 +.ifb \unchecked
21093 +#ifdef CONFIG_PAX_REFCOUNT
21094 +3:
21095 +#endif
21096 +.endif
21097 +
21098 RESTORE ebx
21099 + pax_force_retaddr
21100 ret
21101 CFI_ENDPROC
21102 -ENDPROC(atomic64_\func\()_return_cx8)
21103 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21104 .endm
21105
21106 incdec_return inc add adc
21107 incdec_return dec sub sbb
21108 +incdec_return inc add adc _unchecked
21109 +incdec_return dec sub sbb _unchecked
21110
21111 ENTRY(atomic64_dec_if_positive_cx8)
21112 CFI_STARTPROC
21113 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21114 movl %edx, %ecx
21115 subl $1, %ebx
21116 sbb $0, %ecx
21117 +
21118 +#ifdef CONFIG_PAX_REFCOUNT
21119 + into
21120 +1234:
21121 + _ASM_EXTABLE(1234b, 2f)
21122 +#endif
21123 +
21124 js 2f
21125 LOCK_PREFIX
21126 cmpxchg8b (%esi)
21127 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21128 movl %ebx, %eax
21129 movl %ecx, %edx
21130 RESTORE ebx
21131 + pax_force_retaddr
21132 ret
21133 CFI_ENDPROC
21134 ENDPROC(atomic64_dec_if_positive_cx8)
21135 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21136 movl %edx, %ecx
21137 addl %ebp, %ebx
21138 adcl %edi, %ecx
21139 +
21140 +#ifdef CONFIG_PAX_REFCOUNT
21141 + into
21142 +1234:
21143 + _ASM_EXTABLE(1234b, 3f)
21144 +#endif
21145 +
21146 LOCK_PREFIX
21147 cmpxchg8b (%esi)
21148 jne 1b
21149 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21150 CFI_ADJUST_CFA_OFFSET -8
21151 RESTORE ebx
21152 RESTORE ebp
21153 + pax_force_retaddr
21154 ret
21155 4:
21156 cmpl %edx, 4(%esp)
21157 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21158 xorl %ecx, %ecx
21159 addl $1, %ebx
21160 adcl %edx, %ecx
21161 +
21162 +#ifdef CONFIG_PAX_REFCOUNT
21163 + into
21164 +1234:
21165 + _ASM_EXTABLE(1234b, 3f)
21166 +#endif
21167 +
21168 LOCK_PREFIX
21169 cmpxchg8b (%esi)
21170 jne 1b
21171 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21172 movl $1, %eax
21173 3:
21174 RESTORE ebx
21175 + pax_force_retaddr
21176 ret
21177 CFI_ENDPROC
21178 ENDPROC(atomic64_inc_not_zero_cx8)
21179 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21180 index 2af5df3..62b1a5a 100644
21181 --- a/arch/x86/lib/checksum_32.S
21182 +++ b/arch/x86/lib/checksum_32.S
21183 @@ -29,7 +29,8 @@
21184 #include <asm/dwarf2.h>
21185 #include <asm/errno.h>
21186 #include <asm/asm.h>
21187 -
21188 +#include <asm/segment.h>
21189 +
21190 /*
21191 * computes a partial checksum, e.g. for TCP/UDP fragments
21192 */
21193 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21194
21195 #define ARGBASE 16
21196 #define FP 12
21197 -
21198 -ENTRY(csum_partial_copy_generic)
21199 +
21200 +ENTRY(csum_partial_copy_generic_to_user)
21201 CFI_STARTPROC
21202 +
21203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21204 + pushl_cfi %gs
21205 + popl_cfi %es
21206 + jmp csum_partial_copy_generic
21207 +#endif
21208 +
21209 +ENTRY(csum_partial_copy_generic_from_user)
21210 +
21211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21212 + pushl_cfi %gs
21213 + popl_cfi %ds
21214 +#endif
21215 +
21216 +ENTRY(csum_partial_copy_generic)
21217 subl $4,%esp
21218 CFI_ADJUST_CFA_OFFSET 4
21219 pushl_cfi %edi
21220 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21221 jmp 4f
21222 SRC(1: movw (%esi), %bx )
21223 addl $2, %esi
21224 -DST( movw %bx, (%edi) )
21225 +DST( movw %bx, %es:(%edi) )
21226 addl $2, %edi
21227 addw %bx, %ax
21228 adcl $0, %eax
21229 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21230 SRC(1: movl (%esi), %ebx )
21231 SRC( movl 4(%esi), %edx )
21232 adcl %ebx, %eax
21233 -DST( movl %ebx, (%edi) )
21234 +DST( movl %ebx, %es:(%edi) )
21235 adcl %edx, %eax
21236 -DST( movl %edx, 4(%edi) )
21237 +DST( movl %edx, %es:4(%edi) )
21238
21239 SRC( movl 8(%esi), %ebx )
21240 SRC( movl 12(%esi), %edx )
21241 adcl %ebx, %eax
21242 -DST( movl %ebx, 8(%edi) )
21243 +DST( movl %ebx, %es:8(%edi) )
21244 adcl %edx, %eax
21245 -DST( movl %edx, 12(%edi) )
21246 +DST( movl %edx, %es:12(%edi) )
21247
21248 SRC( movl 16(%esi), %ebx )
21249 SRC( movl 20(%esi), %edx )
21250 adcl %ebx, %eax
21251 -DST( movl %ebx, 16(%edi) )
21252 +DST( movl %ebx, %es:16(%edi) )
21253 adcl %edx, %eax
21254 -DST( movl %edx, 20(%edi) )
21255 +DST( movl %edx, %es:20(%edi) )
21256
21257 SRC( movl 24(%esi), %ebx )
21258 SRC( movl 28(%esi), %edx )
21259 adcl %ebx, %eax
21260 -DST( movl %ebx, 24(%edi) )
21261 +DST( movl %ebx, %es:24(%edi) )
21262 adcl %edx, %eax
21263 -DST( movl %edx, 28(%edi) )
21264 +DST( movl %edx, %es:28(%edi) )
21265
21266 lea 32(%esi), %esi
21267 lea 32(%edi), %edi
21268 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21269 shrl $2, %edx # This clears CF
21270 SRC(3: movl (%esi), %ebx )
21271 adcl %ebx, %eax
21272 -DST( movl %ebx, (%edi) )
21273 +DST( movl %ebx, %es:(%edi) )
21274 lea 4(%esi), %esi
21275 lea 4(%edi), %edi
21276 dec %edx
21277 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21278 jb 5f
21279 SRC( movw (%esi), %cx )
21280 leal 2(%esi), %esi
21281 -DST( movw %cx, (%edi) )
21282 +DST( movw %cx, %es:(%edi) )
21283 leal 2(%edi), %edi
21284 je 6f
21285 shll $16,%ecx
21286 SRC(5: movb (%esi), %cl )
21287 -DST( movb %cl, (%edi) )
21288 +DST( movb %cl, %es:(%edi) )
21289 6: addl %ecx, %eax
21290 adcl $0, %eax
21291 7:
21292 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21293
21294 6001:
21295 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21296 - movl $-EFAULT, (%ebx)
21297 + movl $-EFAULT, %ss:(%ebx)
21298
21299 # zero the complete destination - computing the rest
21300 # is too much work
21301 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21302
21303 6002:
21304 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21305 - movl $-EFAULT,(%ebx)
21306 + movl $-EFAULT,%ss:(%ebx)
21307 jmp 5000b
21308
21309 .previous
21310
21311 + pushl_cfi %ss
21312 + popl_cfi %ds
21313 + pushl_cfi %ss
21314 + popl_cfi %es
21315 popl_cfi %ebx
21316 CFI_RESTORE ebx
21317 popl_cfi %esi
21318 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21319 popl_cfi %ecx # equivalent to addl $4,%esp
21320 ret
21321 CFI_ENDPROC
21322 -ENDPROC(csum_partial_copy_generic)
21323 +ENDPROC(csum_partial_copy_generic_to_user)
21324
21325 #else
21326
21327 /* Version for PentiumII/PPro */
21328
21329 #define ROUND1(x) \
21330 + nop; nop; nop; \
21331 SRC(movl x(%esi), %ebx ) ; \
21332 addl %ebx, %eax ; \
21333 - DST(movl %ebx, x(%edi) ) ;
21334 + DST(movl %ebx, %es:x(%edi)) ;
21335
21336 #define ROUND(x) \
21337 + nop; nop; nop; \
21338 SRC(movl x(%esi), %ebx ) ; \
21339 adcl %ebx, %eax ; \
21340 - DST(movl %ebx, x(%edi) ) ;
21341 + DST(movl %ebx, %es:x(%edi)) ;
21342
21343 #define ARGBASE 12
21344 -
21345 -ENTRY(csum_partial_copy_generic)
21346 +
21347 +ENTRY(csum_partial_copy_generic_to_user)
21348 CFI_STARTPROC
21349 +
21350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21351 + pushl_cfi %gs
21352 + popl_cfi %es
21353 + jmp csum_partial_copy_generic
21354 +#endif
21355 +
21356 +ENTRY(csum_partial_copy_generic_from_user)
21357 +
21358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21359 + pushl_cfi %gs
21360 + popl_cfi %ds
21361 +#endif
21362 +
21363 +ENTRY(csum_partial_copy_generic)
21364 pushl_cfi %ebx
21365 CFI_REL_OFFSET ebx, 0
21366 pushl_cfi %edi
21367 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21368 subl %ebx, %edi
21369 lea -1(%esi),%edx
21370 andl $-32,%edx
21371 - lea 3f(%ebx,%ebx), %ebx
21372 + lea 3f(%ebx,%ebx,2), %ebx
21373 testl %esi, %esi
21374 jmp *%ebx
21375 1: addl $64,%esi
21376 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21377 jb 5f
21378 SRC( movw (%esi), %dx )
21379 leal 2(%esi), %esi
21380 -DST( movw %dx, (%edi) )
21381 +DST( movw %dx, %es:(%edi) )
21382 leal 2(%edi), %edi
21383 je 6f
21384 shll $16,%edx
21385 5:
21386 SRC( movb (%esi), %dl )
21387 -DST( movb %dl, (%edi) )
21388 +DST( movb %dl, %es:(%edi) )
21389 6: addl %edx, %eax
21390 adcl $0, %eax
21391 7:
21392 .section .fixup, "ax"
21393 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21394 - movl $-EFAULT, (%ebx)
21395 + movl $-EFAULT, %ss:(%ebx)
21396 # zero the complete destination (computing the rest is too much work)
21397 movl ARGBASE+8(%esp),%edi # dst
21398 movl ARGBASE+12(%esp),%ecx # len
21399 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21400 rep; stosb
21401 jmp 7b
21402 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21403 - movl $-EFAULT, (%ebx)
21404 + movl $-EFAULT, %ss:(%ebx)
21405 jmp 7b
21406 .previous
21407
21408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21409 + pushl_cfi %ss
21410 + popl_cfi %ds
21411 + pushl_cfi %ss
21412 + popl_cfi %es
21413 +#endif
21414 +
21415 popl_cfi %esi
21416 CFI_RESTORE esi
21417 popl_cfi %edi
21418 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21419 CFI_RESTORE ebx
21420 ret
21421 CFI_ENDPROC
21422 -ENDPROC(csum_partial_copy_generic)
21423 +ENDPROC(csum_partial_copy_generic_to_user)
21424
21425 #undef ROUND
21426 #undef ROUND1
21427 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21428 index f2145cf..cea889d 100644
21429 --- a/arch/x86/lib/clear_page_64.S
21430 +++ b/arch/x86/lib/clear_page_64.S
21431 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21432 movl $4096/8,%ecx
21433 xorl %eax,%eax
21434 rep stosq
21435 + pax_force_retaddr
21436 ret
21437 CFI_ENDPROC
21438 ENDPROC(clear_page_c)
21439 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21440 movl $4096,%ecx
21441 xorl %eax,%eax
21442 rep stosb
21443 + pax_force_retaddr
21444 ret
21445 CFI_ENDPROC
21446 ENDPROC(clear_page_c_e)
21447 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21448 leaq 64(%rdi),%rdi
21449 jnz .Lloop
21450 nop
21451 + pax_force_retaddr
21452 ret
21453 CFI_ENDPROC
21454 .Lclear_page_end:
21455 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21456
21457 #include <asm/cpufeature.h>
21458
21459 - .section .altinstr_replacement,"ax"
21460 + .section .altinstr_replacement,"a"
21461 1: .byte 0xeb /* jmp <disp8> */
21462 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21463 2: .byte 0xeb /* jmp <disp8> */
21464 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21465 index 1e572c5..2a162cd 100644
21466 --- a/arch/x86/lib/cmpxchg16b_emu.S
21467 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21468 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21469
21470 popf
21471 mov $1, %al
21472 + pax_force_retaddr
21473 ret
21474
21475 not_same:
21476 popf
21477 xor %al,%al
21478 + pax_force_retaddr
21479 ret
21480
21481 CFI_ENDPROC
21482 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21483 index 6b34d04..dccb07f 100644
21484 --- a/arch/x86/lib/copy_page_64.S
21485 +++ b/arch/x86/lib/copy_page_64.S
21486 @@ -9,6 +9,7 @@ copy_page_c:
21487 CFI_STARTPROC
21488 movl $4096/8,%ecx
21489 rep movsq
21490 + pax_force_retaddr
21491 ret
21492 CFI_ENDPROC
21493 ENDPROC(copy_page_c)
21494 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21495
21496 ENTRY(copy_page)
21497 CFI_STARTPROC
21498 - subq $2*8,%rsp
21499 - CFI_ADJUST_CFA_OFFSET 2*8
21500 + subq $3*8,%rsp
21501 + CFI_ADJUST_CFA_OFFSET 3*8
21502 movq %rbx,(%rsp)
21503 CFI_REL_OFFSET rbx, 0
21504 movq %r12,1*8(%rsp)
21505 CFI_REL_OFFSET r12, 1*8
21506 + movq %r13,2*8(%rsp)
21507 + CFI_REL_OFFSET r13, 2*8
21508
21509 movl $(4096/64)-5,%ecx
21510 .p2align 4
21511 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21512 movq 16 (%rsi), %rdx
21513 movq 24 (%rsi), %r8
21514 movq 32 (%rsi), %r9
21515 - movq 40 (%rsi), %r10
21516 + movq 40 (%rsi), %r13
21517 movq 48 (%rsi), %r11
21518 movq 56 (%rsi), %r12
21519
21520 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21521 movq %rdx, 16 (%rdi)
21522 movq %r8, 24 (%rdi)
21523 movq %r9, 32 (%rdi)
21524 - movq %r10, 40 (%rdi)
21525 + movq %r13, 40 (%rdi)
21526 movq %r11, 48 (%rdi)
21527 movq %r12, 56 (%rdi)
21528
21529 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21530 movq 16 (%rsi), %rdx
21531 movq 24 (%rsi), %r8
21532 movq 32 (%rsi), %r9
21533 - movq 40 (%rsi), %r10
21534 + movq 40 (%rsi), %r13
21535 movq 48 (%rsi), %r11
21536 movq 56 (%rsi), %r12
21537
21538 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21539 movq %rdx, 16 (%rdi)
21540 movq %r8, 24 (%rdi)
21541 movq %r9, 32 (%rdi)
21542 - movq %r10, 40 (%rdi)
21543 + movq %r13, 40 (%rdi)
21544 movq %r11, 48 (%rdi)
21545 movq %r12, 56 (%rdi)
21546
21547 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21548 CFI_RESTORE rbx
21549 movq 1*8(%rsp),%r12
21550 CFI_RESTORE r12
21551 - addq $2*8,%rsp
21552 - CFI_ADJUST_CFA_OFFSET -2*8
21553 + movq 2*8(%rsp),%r13
21554 + CFI_RESTORE r13
21555 + addq $3*8,%rsp
21556 + CFI_ADJUST_CFA_OFFSET -3*8
21557 + pax_force_retaddr
21558 ret
21559 .Lcopy_page_end:
21560 CFI_ENDPROC
21561 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21562
21563 #include <asm/cpufeature.h>
21564
21565 - .section .altinstr_replacement,"ax"
21566 + .section .altinstr_replacement,"a"
21567 1: .byte 0xeb /* jmp <disp8> */
21568 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21569 2:
21570 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21571 index 5b2995f..78e7644 100644
21572 --- a/arch/x86/lib/copy_user_64.S
21573 +++ b/arch/x86/lib/copy_user_64.S
21574 @@ -17,6 +17,7 @@
21575 #include <asm/cpufeature.h>
21576 #include <asm/alternative-asm.h>
21577 #include <asm/asm.h>
21578 +#include <asm/pgtable.h>
21579
21580 /*
21581 * By placing feature2 after feature1 in altinstructions section, we logically
21582 @@ -30,7 +31,7 @@
21583 .byte 0xe9 /* 32bit jump */
21584 .long \orig-1f /* by default jump to orig */
21585 1:
21586 - .section .altinstr_replacement,"ax"
21587 + .section .altinstr_replacement,"a"
21588 2: .byte 0xe9 /* near jump with 32bit immediate */
21589 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21590 3: .byte 0xe9 /* near jump with 32bit immediate */
21591 @@ -69,47 +70,20 @@
21592 #endif
21593 .endm
21594
21595 -/* Standard copy_to_user with segment limit checking */
21596 -ENTRY(_copy_to_user)
21597 - CFI_STARTPROC
21598 - GET_THREAD_INFO(%rax)
21599 - movq %rdi,%rcx
21600 - addq %rdx,%rcx
21601 - jc bad_to_user
21602 - cmpq TI_addr_limit(%rax),%rcx
21603 - ja bad_to_user
21604 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21605 - copy_user_generic_unrolled,copy_user_generic_string, \
21606 - copy_user_enhanced_fast_string
21607 - CFI_ENDPROC
21608 -ENDPROC(_copy_to_user)
21609 -
21610 -/* Standard copy_from_user with segment limit checking */
21611 -ENTRY(_copy_from_user)
21612 - CFI_STARTPROC
21613 - GET_THREAD_INFO(%rax)
21614 - movq %rsi,%rcx
21615 - addq %rdx,%rcx
21616 - jc bad_from_user
21617 - cmpq TI_addr_limit(%rax),%rcx
21618 - ja bad_from_user
21619 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21620 - copy_user_generic_unrolled,copy_user_generic_string, \
21621 - copy_user_enhanced_fast_string
21622 - CFI_ENDPROC
21623 -ENDPROC(_copy_from_user)
21624 -
21625 .section .fixup,"ax"
21626 /* must zero dest */
21627 ENTRY(bad_from_user)
21628 bad_from_user:
21629 CFI_STARTPROC
21630 + testl %edx,%edx
21631 + js bad_to_user
21632 movl %edx,%ecx
21633 xorl %eax,%eax
21634 rep
21635 stosb
21636 bad_to_user:
21637 movl %edx,%eax
21638 + pax_force_retaddr
21639 ret
21640 CFI_ENDPROC
21641 ENDPROC(bad_from_user)
21642 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21643 jz 17f
21644 1: movq (%rsi),%r8
21645 2: movq 1*8(%rsi),%r9
21646 -3: movq 2*8(%rsi),%r10
21647 +3: movq 2*8(%rsi),%rax
21648 4: movq 3*8(%rsi),%r11
21649 5: movq %r8,(%rdi)
21650 6: movq %r9,1*8(%rdi)
21651 -7: movq %r10,2*8(%rdi)
21652 +7: movq %rax,2*8(%rdi)
21653 8: movq %r11,3*8(%rdi)
21654 9: movq 4*8(%rsi),%r8
21655 10: movq 5*8(%rsi),%r9
21656 -11: movq 6*8(%rsi),%r10
21657 +11: movq 6*8(%rsi),%rax
21658 12: movq 7*8(%rsi),%r11
21659 13: movq %r8,4*8(%rdi)
21660 14: movq %r9,5*8(%rdi)
21661 -15: movq %r10,6*8(%rdi)
21662 +15: movq %rax,6*8(%rdi)
21663 16: movq %r11,7*8(%rdi)
21664 leaq 64(%rsi),%rsi
21665 leaq 64(%rdi),%rdi
21666 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21667 decl %ecx
21668 jnz 21b
21669 23: xor %eax,%eax
21670 + pax_force_retaddr
21671 ret
21672
21673 .section .fixup,"ax"
21674 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21675 3: rep
21676 movsb
21677 4: xorl %eax,%eax
21678 + pax_force_retaddr
21679 ret
21680
21681 .section .fixup,"ax"
21682 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21683 1: rep
21684 movsb
21685 2: xorl %eax,%eax
21686 + pax_force_retaddr
21687 ret
21688
21689 .section .fixup,"ax"
21690 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21691 index cacddc7..09d49e4 100644
21692 --- a/arch/x86/lib/copy_user_nocache_64.S
21693 +++ b/arch/x86/lib/copy_user_nocache_64.S
21694 @@ -8,6 +8,7 @@
21695
21696 #include <linux/linkage.h>
21697 #include <asm/dwarf2.h>
21698 +#include <asm/alternative-asm.h>
21699
21700 #define FIX_ALIGNMENT 1
21701
21702 @@ -15,6 +16,7 @@
21703 #include <asm/asm-offsets.h>
21704 #include <asm/thread_info.h>
21705 #include <asm/asm.h>
21706 +#include <asm/pgtable.h>
21707
21708 .macro ALIGN_DESTINATION
21709 #ifdef FIX_ALIGNMENT
21710 @@ -48,6 +50,15 @@
21711 */
21712 ENTRY(__copy_user_nocache)
21713 CFI_STARTPROC
21714 +
21715 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21716 + mov $PAX_USER_SHADOW_BASE,%rcx
21717 + cmp %rcx,%rsi
21718 + jae 1f
21719 + add %rcx,%rsi
21720 +1:
21721 +#endif
21722 +
21723 cmpl $8,%edx
21724 jb 20f /* less then 8 bytes, go to byte copy loop */
21725 ALIGN_DESTINATION
21726 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21727 jz 17f
21728 1: movq (%rsi),%r8
21729 2: movq 1*8(%rsi),%r9
21730 -3: movq 2*8(%rsi),%r10
21731 +3: movq 2*8(%rsi),%rax
21732 4: movq 3*8(%rsi),%r11
21733 5: movnti %r8,(%rdi)
21734 6: movnti %r9,1*8(%rdi)
21735 -7: movnti %r10,2*8(%rdi)
21736 +7: movnti %rax,2*8(%rdi)
21737 8: movnti %r11,3*8(%rdi)
21738 9: movq 4*8(%rsi),%r8
21739 10: movq 5*8(%rsi),%r9
21740 -11: movq 6*8(%rsi),%r10
21741 +11: movq 6*8(%rsi),%rax
21742 12: movq 7*8(%rsi),%r11
21743 13: movnti %r8,4*8(%rdi)
21744 14: movnti %r9,5*8(%rdi)
21745 -15: movnti %r10,6*8(%rdi)
21746 +15: movnti %rax,6*8(%rdi)
21747 16: movnti %r11,7*8(%rdi)
21748 leaq 64(%rsi),%rsi
21749 leaq 64(%rdi),%rdi
21750 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21751 jnz 21b
21752 23: xorl %eax,%eax
21753 sfence
21754 + pax_force_retaddr
21755 ret
21756
21757 .section .fixup,"ax"
21758 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21759 index 2419d5f..953ee51 100644
21760 --- a/arch/x86/lib/csum-copy_64.S
21761 +++ b/arch/x86/lib/csum-copy_64.S
21762 @@ -9,6 +9,7 @@
21763 #include <asm/dwarf2.h>
21764 #include <asm/errno.h>
21765 #include <asm/asm.h>
21766 +#include <asm/alternative-asm.h>
21767
21768 /*
21769 * Checksum copy with exception handling.
21770 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21771 CFI_RESTORE rbp
21772 addq $7*8, %rsp
21773 CFI_ADJUST_CFA_OFFSET -7*8
21774 + pax_force_retaddr 0, 1
21775 ret
21776 CFI_RESTORE_STATE
21777
21778 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21779 index 25b7ae8..3b52ccd 100644
21780 --- a/arch/x86/lib/csum-wrappers_64.c
21781 +++ b/arch/x86/lib/csum-wrappers_64.c
21782 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21783 len -= 2;
21784 }
21785 }
21786 - isum = csum_partial_copy_generic((__force const void *)src,
21787 +
21788 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21789 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21790 + src += PAX_USER_SHADOW_BASE;
21791 +#endif
21792 +
21793 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21794 dst, len, isum, errp, NULL);
21795 if (unlikely(*errp))
21796 goto out_err;
21797 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21798 }
21799
21800 *errp = 0;
21801 - return csum_partial_copy_generic(src, (void __force *)dst,
21802 +
21803 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21804 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21805 + dst += PAX_USER_SHADOW_BASE;
21806 +#endif
21807 +
21808 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21809 len, isum, NULL, errp);
21810 }
21811 EXPORT_SYMBOL(csum_partial_copy_to_user);
21812 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21813 index b33b1fb..219f389 100644
21814 --- a/arch/x86/lib/getuser.S
21815 +++ b/arch/x86/lib/getuser.S
21816 @@ -33,15 +33,38 @@
21817 #include <asm/asm-offsets.h>
21818 #include <asm/thread_info.h>
21819 #include <asm/asm.h>
21820 +#include <asm/segment.h>
21821 +#include <asm/pgtable.h>
21822 +#include <asm/alternative-asm.h>
21823 +
21824 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21825 +#define __copyuser_seg gs;
21826 +#else
21827 +#define __copyuser_seg
21828 +#endif
21829
21830 .text
21831 ENTRY(__get_user_1)
21832 CFI_STARTPROC
21833 +
21834 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21835 GET_THREAD_INFO(%_ASM_DX)
21836 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21837 jae bad_get_user
21838 -1: movzb (%_ASM_AX),%edx
21839 +
21840 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21841 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21842 + cmp %_ASM_DX,%_ASM_AX
21843 + jae 1234f
21844 + add %_ASM_DX,%_ASM_AX
21845 +1234:
21846 +#endif
21847 +
21848 +#endif
21849 +
21850 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21851 xor %eax,%eax
21852 + pax_force_retaddr
21853 ret
21854 CFI_ENDPROC
21855 ENDPROC(__get_user_1)
21856 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21857 ENTRY(__get_user_2)
21858 CFI_STARTPROC
21859 add $1,%_ASM_AX
21860 +
21861 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21862 jc bad_get_user
21863 GET_THREAD_INFO(%_ASM_DX)
21864 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21865 jae bad_get_user
21866 -2: movzwl -1(%_ASM_AX),%edx
21867 +
21868 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21869 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21870 + cmp %_ASM_DX,%_ASM_AX
21871 + jae 1234f
21872 + add %_ASM_DX,%_ASM_AX
21873 +1234:
21874 +#endif
21875 +
21876 +#endif
21877 +
21878 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21879 xor %eax,%eax
21880 + pax_force_retaddr
21881 ret
21882 CFI_ENDPROC
21883 ENDPROC(__get_user_2)
21884 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21885 ENTRY(__get_user_4)
21886 CFI_STARTPROC
21887 add $3,%_ASM_AX
21888 +
21889 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21890 jc bad_get_user
21891 GET_THREAD_INFO(%_ASM_DX)
21892 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21893 jae bad_get_user
21894 -3: mov -3(%_ASM_AX),%edx
21895 +
21896 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21897 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21898 + cmp %_ASM_DX,%_ASM_AX
21899 + jae 1234f
21900 + add %_ASM_DX,%_ASM_AX
21901 +1234:
21902 +#endif
21903 +
21904 +#endif
21905 +
21906 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21907 xor %eax,%eax
21908 + pax_force_retaddr
21909 ret
21910 CFI_ENDPROC
21911 ENDPROC(__get_user_4)
21912 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21913 GET_THREAD_INFO(%_ASM_DX)
21914 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21915 jae bad_get_user
21916 +
21917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21918 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21919 + cmp %_ASM_DX,%_ASM_AX
21920 + jae 1234f
21921 + add %_ASM_DX,%_ASM_AX
21922 +1234:
21923 +#endif
21924 +
21925 4: movq -7(%_ASM_AX),%_ASM_DX
21926 xor %eax,%eax
21927 + pax_force_retaddr
21928 ret
21929 CFI_ENDPROC
21930 ENDPROC(__get_user_8)
21931 @@ -91,6 +152,7 @@ bad_get_user:
21932 CFI_STARTPROC
21933 xor %edx,%edx
21934 mov $(-EFAULT),%_ASM_AX
21935 + pax_force_retaddr
21936 ret
21937 CFI_ENDPROC
21938 END(bad_get_user)
21939 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21940 index b1e6c4b..21ae8fc 100644
21941 --- a/arch/x86/lib/insn.c
21942 +++ b/arch/x86/lib/insn.c
21943 @@ -21,6 +21,11 @@
21944 #include <linux/string.h>
21945 #include <asm/inat.h>
21946 #include <asm/insn.h>
21947 +#ifdef __KERNEL__
21948 +#include <asm/pgtable_types.h>
21949 +#else
21950 +#define ktla_ktva(addr) addr
21951 +#endif
21952
21953 /* Verify next sizeof(t) bytes can be on the same instruction */
21954 #define validate_next(t, insn, n) \
21955 @@ -49,8 +54,8 @@
21956 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21957 {
21958 memset(insn, 0, sizeof(*insn));
21959 - insn->kaddr = kaddr;
21960 - insn->next_byte = kaddr;
21961 + insn->kaddr = ktla_ktva(kaddr);
21962 + insn->next_byte = ktla_ktva(kaddr);
21963 insn->x86_64 = x86_64 ? 1 : 0;
21964 insn->opnd_bytes = 4;
21965 if (x86_64)
21966 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21967 index 05a95e7..326f2fa 100644
21968 --- a/arch/x86/lib/iomap_copy_64.S
21969 +++ b/arch/x86/lib/iomap_copy_64.S
21970 @@ -17,6 +17,7 @@
21971
21972 #include <linux/linkage.h>
21973 #include <asm/dwarf2.h>
21974 +#include <asm/alternative-asm.h>
21975
21976 /*
21977 * override generic version in lib/iomap_copy.c
21978 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21979 CFI_STARTPROC
21980 movl %edx,%ecx
21981 rep movsd
21982 + pax_force_retaddr
21983 ret
21984 CFI_ENDPROC
21985 ENDPROC(__iowrite32_copy)
21986 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21987 index 1c273be..da9cc0e 100644
21988 --- a/arch/x86/lib/memcpy_64.S
21989 +++ b/arch/x86/lib/memcpy_64.S
21990 @@ -33,6 +33,7 @@
21991 rep movsq
21992 movl %edx, %ecx
21993 rep movsb
21994 + pax_force_retaddr
21995 ret
21996 .Lmemcpy_e:
21997 .previous
21998 @@ -49,6 +50,7 @@
21999 movq %rdi, %rax
22000 movq %rdx, %rcx
22001 rep movsb
22002 + pax_force_retaddr
22003 ret
22004 .Lmemcpy_e_e:
22005 .previous
22006 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22007 */
22008 movq 0*8(%rsi), %r8
22009 movq 1*8(%rsi), %r9
22010 - movq 2*8(%rsi), %r10
22011 + movq 2*8(%rsi), %rcx
22012 movq 3*8(%rsi), %r11
22013 leaq 4*8(%rsi), %rsi
22014
22015 movq %r8, 0*8(%rdi)
22016 movq %r9, 1*8(%rdi)
22017 - movq %r10, 2*8(%rdi)
22018 + movq %rcx, 2*8(%rdi)
22019 movq %r11, 3*8(%rdi)
22020 leaq 4*8(%rdi), %rdi
22021 jae .Lcopy_forward_loop
22022 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22023 subq $0x20, %rdx
22024 movq -1*8(%rsi), %r8
22025 movq -2*8(%rsi), %r9
22026 - movq -3*8(%rsi), %r10
22027 + movq -3*8(%rsi), %rcx
22028 movq -4*8(%rsi), %r11
22029 leaq -4*8(%rsi), %rsi
22030 movq %r8, -1*8(%rdi)
22031 movq %r9, -2*8(%rdi)
22032 - movq %r10, -3*8(%rdi)
22033 + movq %rcx, -3*8(%rdi)
22034 movq %r11, -4*8(%rdi)
22035 leaq -4*8(%rdi), %rdi
22036 jae .Lcopy_backward_loop
22037 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22038 */
22039 movq 0*8(%rsi), %r8
22040 movq 1*8(%rsi), %r9
22041 - movq -2*8(%rsi, %rdx), %r10
22042 + movq -2*8(%rsi, %rdx), %rcx
22043 movq -1*8(%rsi, %rdx), %r11
22044 movq %r8, 0*8(%rdi)
22045 movq %r9, 1*8(%rdi)
22046 - movq %r10, -2*8(%rdi, %rdx)
22047 + movq %rcx, -2*8(%rdi, %rdx)
22048 movq %r11, -1*8(%rdi, %rdx)
22049 + pax_force_retaddr
22050 retq
22051 .p2align 4
22052 .Lless_16bytes:
22053 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22054 movq -1*8(%rsi, %rdx), %r9
22055 movq %r8, 0*8(%rdi)
22056 movq %r9, -1*8(%rdi, %rdx)
22057 + pax_force_retaddr
22058 retq
22059 .p2align 4
22060 .Lless_8bytes:
22061 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22062 movl -4(%rsi, %rdx), %r8d
22063 movl %ecx, (%rdi)
22064 movl %r8d, -4(%rdi, %rdx)
22065 + pax_force_retaddr
22066 retq
22067 .p2align 4
22068 .Lless_3bytes:
22069 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22070 movb %cl, (%rdi)
22071
22072 .Lend:
22073 + pax_force_retaddr
22074 retq
22075 CFI_ENDPROC
22076 ENDPROC(memcpy)
22077 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22078 index ee16461..c39c199 100644
22079 --- a/arch/x86/lib/memmove_64.S
22080 +++ b/arch/x86/lib/memmove_64.S
22081 @@ -61,13 +61,13 @@ ENTRY(memmove)
22082 5:
22083 sub $0x20, %rdx
22084 movq 0*8(%rsi), %r11
22085 - movq 1*8(%rsi), %r10
22086 + movq 1*8(%rsi), %rcx
22087 movq 2*8(%rsi), %r9
22088 movq 3*8(%rsi), %r8
22089 leaq 4*8(%rsi), %rsi
22090
22091 movq %r11, 0*8(%rdi)
22092 - movq %r10, 1*8(%rdi)
22093 + movq %rcx, 1*8(%rdi)
22094 movq %r9, 2*8(%rdi)
22095 movq %r8, 3*8(%rdi)
22096 leaq 4*8(%rdi), %rdi
22097 @@ -81,10 +81,10 @@ ENTRY(memmove)
22098 4:
22099 movq %rdx, %rcx
22100 movq -8(%rsi, %rdx), %r11
22101 - lea -8(%rdi, %rdx), %r10
22102 + lea -8(%rdi, %rdx), %r9
22103 shrq $3, %rcx
22104 rep movsq
22105 - movq %r11, (%r10)
22106 + movq %r11, (%r9)
22107 jmp 13f
22108 .Lmemmove_end_forward:
22109
22110 @@ -95,14 +95,14 @@ ENTRY(memmove)
22111 7:
22112 movq %rdx, %rcx
22113 movq (%rsi), %r11
22114 - movq %rdi, %r10
22115 + movq %rdi, %r9
22116 leaq -8(%rsi, %rdx), %rsi
22117 leaq -8(%rdi, %rdx), %rdi
22118 shrq $3, %rcx
22119 std
22120 rep movsq
22121 cld
22122 - movq %r11, (%r10)
22123 + movq %r11, (%r9)
22124 jmp 13f
22125
22126 /*
22127 @@ -127,13 +127,13 @@ ENTRY(memmove)
22128 8:
22129 subq $0x20, %rdx
22130 movq -1*8(%rsi), %r11
22131 - movq -2*8(%rsi), %r10
22132 + movq -2*8(%rsi), %rcx
22133 movq -3*8(%rsi), %r9
22134 movq -4*8(%rsi), %r8
22135 leaq -4*8(%rsi), %rsi
22136
22137 movq %r11, -1*8(%rdi)
22138 - movq %r10, -2*8(%rdi)
22139 + movq %rcx, -2*8(%rdi)
22140 movq %r9, -3*8(%rdi)
22141 movq %r8, -4*8(%rdi)
22142 leaq -4*8(%rdi), %rdi
22143 @@ -151,11 +151,11 @@ ENTRY(memmove)
22144 * Move data from 16 bytes to 31 bytes.
22145 */
22146 movq 0*8(%rsi), %r11
22147 - movq 1*8(%rsi), %r10
22148 + movq 1*8(%rsi), %rcx
22149 movq -2*8(%rsi, %rdx), %r9
22150 movq -1*8(%rsi, %rdx), %r8
22151 movq %r11, 0*8(%rdi)
22152 - movq %r10, 1*8(%rdi)
22153 + movq %rcx, 1*8(%rdi)
22154 movq %r9, -2*8(%rdi, %rdx)
22155 movq %r8, -1*8(%rdi, %rdx)
22156 jmp 13f
22157 @@ -167,9 +167,9 @@ ENTRY(memmove)
22158 * Move data from 8 bytes to 15 bytes.
22159 */
22160 movq 0*8(%rsi), %r11
22161 - movq -1*8(%rsi, %rdx), %r10
22162 + movq -1*8(%rsi, %rdx), %r9
22163 movq %r11, 0*8(%rdi)
22164 - movq %r10, -1*8(%rdi, %rdx)
22165 + movq %r9, -1*8(%rdi, %rdx)
22166 jmp 13f
22167 10:
22168 cmpq $4, %rdx
22169 @@ -178,9 +178,9 @@ ENTRY(memmove)
22170 * Move data from 4 bytes to 7 bytes.
22171 */
22172 movl (%rsi), %r11d
22173 - movl -4(%rsi, %rdx), %r10d
22174 + movl -4(%rsi, %rdx), %r9d
22175 movl %r11d, (%rdi)
22176 - movl %r10d, -4(%rdi, %rdx)
22177 + movl %r9d, -4(%rdi, %rdx)
22178 jmp 13f
22179 11:
22180 cmp $2, %rdx
22181 @@ -189,9 +189,9 @@ ENTRY(memmove)
22182 * Move data from 2 bytes to 3 bytes.
22183 */
22184 movw (%rsi), %r11w
22185 - movw -2(%rsi, %rdx), %r10w
22186 + movw -2(%rsi, %rdx), %r9w
22187 movw %r11w, (%rdi)
22188 - movw %r10w, -2(%rdi, %rdx)
22189 + movw %r9w, -2(%rdi, %rdx)
22190 jmp 13f
22191 12:
22192 cmp $1, %rdx
22193 @@ -202,6 +202,7 @@ ENTRY(memmove)
22194 movb (%rsi), %r11b
22195 movb %r11b, (%rdi)
22196 13:
22197 + pax_force_retaddr
22198 retq
22199 CFI_ENDPROC
22200
22201 @@ -210,6 +211,7 @@ ENTRY(memmove)
22202 /* Forward moving data. */
22203 movq %rdx, %rcx
22204 rep movsb
22205 + pax_force_retaddr
22206 retq
22207 .Lmemmove_end_forward_efs:
22208 .previous
22209 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22210 index 2dcb380..963660a 100644
22211 --- a/arch/x86/lib/memset_64.S
22212 +++ b/arch/x86/lib/memset_64.S
22213 @@ -30,6 +30,7 @@
22214 movl %edx,%ecx
22215 rep stosb
22216 movq %r9,%rax
22217 + pax_force_retaddr
22218 ret
22219 .Lmemset_e:
22220 .previous
22221 @@ -52,6 +53,7 @@
22222 movq %rdx,%rcx
22223 rep stosb
22224 movq %r9,%rax
22225 + pax_force_retaddr
22226 ret
22227 .Lmemset_e_e:
22228 .previous
22229 @@ -59,7 +61,7 @@
22230 ENTRY(memset)
22231 ENTRY(__memset)
22232 CFI_STARTPROC
22233 - movq %rdi,%r10
22234 + movq %rdi,%r11
22235
22236 /* expand byte value */
22237 movzbl %sil,%ecx
22238 @@ -117,7 +119,8 @@ ENTRY(__memset)
22239 jnz .Lloop_1
22240
22241 .Lende:
22242 - movq %r10,%rax
22243 + movq %r11,%rax
22244 + pax_force_retaddr
22245 ret
22246
22247 CFI_RESTORE_STATE
22248 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22249 index c9f2d9b..e7fd2c0 100644
22250 --- a/arch/x86/lib/mmx_32.c
22251 +++ b/arch/x86/lib/mmx_32.c
22252 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22253 {
22254 void *p;
22255 int i;
22256 + unsigned long cr0;
22257
22258 if (unlikely(in_interrupt()))
22259 return __memcpy(to, from, len);
22260 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22261 kernel_fpu_begin();
22262
22263 __asm__ __volatile__ (
22264 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22265 - " prefetch 64(%0)\n"
22266 - " prefetch 128(%0)\n"
22267 - " prefetch 192(%0)\n"
22268 - " prefetch 256(%0)\n"
22269 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22270 + " prefetch 64(%1)\n"
22271 + " prefetch 128(%1)\n"
22272 + " prefetch 192(%1)\n"
22273 + " prefetch 256(%1)\n"
22274 "2: \n"
22275 ".section .fixup, \"ax\"\n"
22276 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22277 + "3: \n"
22278 +
22279 +#ifdef CONFIG_PAX_KERNEXEC
22280 + " movl %%cr0, %0\n"
22281 + " movl %0, %%eax\n"
22282 + " andl $0xFFFEFFFF, %%eax\n"
22283 + " movl %%eax, %%cr0\n"
22284 +#endif
22285 +
22286 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22287 +
22288 +#ifdef CONFIG_PAX_KERNEXEC
22289 + " movl %0, %%cr0\n"
22290 +#endif
22291 +
22292 " jmp 2b\n"
22293 ".previous\n"
22294 _ASM_EXTABLE(1b, 3b)
22295 - : : "r" (from));
22296 + : "=&r" (cr0) : "r" (from) : "ax");
22297
22298 for ( ; i > 5; i--) {
22299 __asm__ __volatile__ (
22300 - "1: prefetch 320(%0)\n"
22301 - "2: movq (%0), %%mm0\n"
22302 - " movq 8(%0), %%mm1\n"
22303 - " movq 16(%0), %%mm2\n"
22304 - " movq 24(%0), %%mm3\n"
22305 - " movq %%mm0, (%1)\n"
22306 - " movq %%mm1, 8(%1)\n"
22307 - " movq %%mm2, 16(%1)\n"
22308 - " movq %%mm3, 24(%1)\n"
22309 - " movq 32(%0), %%mm0\n"
22310 - " movq 40(%0), %%mm1\n"
22311 - " movq 48(%0), %%mm2\n"
22312 - " movq 56(%0), %%mm3\n"
22313 - " movq %%mm0, 32(%1)\n"
22314 - " movq %%mm1, 40(%1)\n"
22315 - " movq %%mm2, 48(%1)\n"
22316 - " movq %%mm3, 56(%1)\n"
22317 + "1: prefetch 320(%1)\n"
22318 + "2: movq (%1), %%mm0\n"
22319 + " movq 8(%1), %%mm1\n"
22320 + " movq 16(%1), %%mm2\n"
22321 + " movq 24(%1), %%mm3\n"
22322 + " movq %%mm0, (%2)\n"
22323 + " movq %%mm1, 8(%2)\n"
22324 + " movq %%mm2, 16(%2)\n"
22325 + " movq %%mm3, 24(%2)\n"
22326 + " movq 32(%1), %%mm0\n"
22327 + " movq 40(%1), %%mm1\n"
22328 + " movq 48(%1), %%mm2\n"
22329 + " movq 56(%1), %%mm3\n"
22330 + " movq %%mm0, 32(%2)\n"
22331 + " movq %%mm1, 40(%2)\n"
22332 + " movq %%mm2, 48(%2)\n"
22333 + " movq %%mm3, 56(%2)\n"
22334 ".section .fixup, \"ax\"\n"
22335 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22336 + "3:\n"
22337 +
22338 +#ifdef CONFIG_PAX_KERNEXEC
22339 + " movl %%cr0, %0\n"
22340 + " movl %0, %%eax\n"
22341 + " andl $0xFFFEFFFF, %%eax\n"
22342 + " movl %%eax, %%cr0\n"
22343 +#endif
22344 +
22345 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22346 +
22347 +#ifdef CONFIG_PAX_KERNEXEC
22348 + " movl %0, %%cr0\n"
22349 +#endif
22350 +
22351 " jmp 2b\n"
22352 ".previous\n"
22353 _ASM_EXTABLE(1b, 3b)
22354 - : : "r" (from), "r" (to) : "memory");
22355 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22356
22357 from += 64;
22358 to += 64;
22359 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22360 static void fast_copy_page(void *to, void *from)
22361 {
22362 int i;
22363 + unsigned long cr0;
22364
22365 kernel_fpu_begin();
22366
22367 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22368 * but that is for later. -AV
22369 */
22370 __asm__ __volatile__(
22371 - "1: prefetch (%0)\n"
22372 - " prefetch 64(%0)\n"
22373 - " prefetch 128(%0)\n"
22374 - " prefetch 192(%0)\n"
22375 - " prefetch 256(%0)\n"
22376 + "1: prefetch (%1)\n"
22377 + " prefetch 64(%1)\n"
22378 + " prefetch 128(%1)\n"
22379 + " prefetch 192(%1)\n"
22380 + " prefetch 256(%1)\n"
22381 "2: \n"
22382 ".section .fixup, \"ax\"\n"
22383 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22384 + "3: \n"
22385 +
22386 +#ifdef CONFIG_PAX_KERNEXEC
22387 + " movl %%cr0, %0\n"
22388 + " movl %0, %%eax\n"
22389 + " andl $0xFFFEFFFF, %%eax\n"
22390 + " movl %%eax, %%cr0\n"
22391 +#endif
22392 +
22393 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22394 +
22395 +#ifdef CONFIG_PAX_KERNEXEC
22396 + " movl %0, %%cr0\n"
22397 +#endif
22398 +
22399 " jmp 2b\n"
22400 ".previous\n"
22401 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22402 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22403
22404 for (i = 0; i < (4096-320)/64; i++) {
22405 __asm__ __volatile__ (
22406 - "1: prefetch 320(%0)\n"
22407 - "2: movq (%0), %%mm0\n"
22408 - " movntq %%mm0, (%1)\n"
22409 - " movq 8(%0), %%mm1\n"
22410 - " movntq %%mm1, 8(%1)\n"
22411 - " movq 16(%0), %%mm2\n"
22412 - " movntq %%mm2, 16(%1)\n"
22413 - " movq 24(%0), %%mm3\n"
22414 - " movntq %%mm3, 24(%1)\n"
22415 - " movq 32(%0), %%mm4\n"
22416 - " movntq %%mm4, 32(%1)\n"
22417 - " movq 40(%0), %%mm5\n"
22418 - " movntq %%mm5, 40(%1)\n"
22419 - " movq 48(%0), %%mm6\n"
22420 - " movntq %%mm6, 48(%1)\n"
22421 - " movq 56(%0), %%mm7\n"
22422 - " movntq %%mm7, 56(%1)\n"
22423 + "1: prefetch 320(%1)\n"
22424 + "2: movq (%1), %%mm0\n"
22425 + " movntq %%mm0, (%2)\n"
22426 + " movq 8(%1), %%mm1\n"
22427 + " movntq %%mm1, 8(%2)\n"
22428 + " movq 16(%1), %%mm2\n"
22429 + " movntq %%mm2, 16(%2)\n"
22430 + " movq 24(%1), %%mm3\n"
22431 + " movntq %%mm3, 24(%2)\n"
22432 + " movq 32(%1), %%mm4\n"
22433 + " movntq %%mm4, 32(%2)\n"
22434 + " movq 40(%1), %%mm5\n"
22435 + " movntq %%mm5, 40(%2)\n"
22436 + " movq 48(%1), %%mm6\n"
22437 + " movntq %%mm6, 48(%2)\n"
22438 + " movq 56(%1), %%mm7\n"
22439 + " movntq %%mm7, 56(%2)\n"
22440 ".section .fixup, \"ax\"\n"
22441 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22442 + "3:\n"
22443 +
22444 +#ifdef CONFIG_PAX_KERNEXEC
22445 + " movl %%cr0, %0\n"
22446 + " movl %0, %%eax\n"
22447 + " andl $0xFFFEFFFF, %%eax\n"
22448 + " movl %%eax, %%cr0\n"
22449 +#endif
22450 +
22451 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22452 +
22453 +#ifdef CONFIG_PAX_KERNEXEC
22454 + " movl %0, %%cr0\n"
22455 +#endif
22456 +
22457 " jmp 2b\n"
22458 ".previous\n"
22459 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22460 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22461
22462 from += 64;
22463 to += 64;
22464 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22465 static void fast_copy_page(void *to, void *from)
22466 {
22467 int i;
22468 + unsigned long cr0;
22469
22470 kernel_fpu_begin();
22471
22472 __asm__ __volatile__ (
22473 - "1: prefetch (%0)\n"
22474 - " prefetch 64(%0)\n"
22475 - " prefetch 128(%0)\n"
22476 - " prefetch 192(%0)\n"
22477 - " prefetch 256(%0)\n"
22478 + "1: prefetch (%1)\n"
22479 + " prefetch 64(%1)\n"
22480 + " prefetch 128(%1)\n"
22481 + " prefetch 192(%1)\n"
22482 + " prefetch 256(%1)\n"
22483 "2: \n"
22484 ".section .fixup, \"ax\"\n"
22485 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22486 + "3: \n"
22487 +
22488 +#ifdef CONFIG_PAX_KERNEXEC
22489 + " movl %%cr0, %0\n"
22490 + " movl %0, %%eax\n"
22491 + " andl $0xFFFEFFFF, %%eax\n"
22492 + " movl %%eax, %%cr0\n"
22493 +#endif
22494 +
22495 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22496 +
22497 +#ifdef CONFIG_PAX_KERNEXEC
22498 + " movl %0, %%cr0\n"
22499 +#endif
22500 +
22501 " jmp 2b\n"
22502 ".previous\n"
22503 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22504 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22505
22506 for (i = 0; i < 4096/64; i++) {
22507 __asm__ __volatile__ (
22508 - "1: prefetch 320(%0)\n"
22509 - "2: movq (%0), %%mm0\n"
22510 - " movq 8(%0), %%mm1\n"
22511 - " movq 16(%0), %%mm2\n"
22512 - " movq 24(%0), %%mm3\n"
22513 - " movq %%mm0, (%1)\n"
22514 - " movq %%mm1, 8(%1)\n"
22515 - " movq %%mm2, 16(%1)\n"
22516 - " movq %%mm3, 24(%1)\n"
22517 - " movq 32(%0), %%mm0\n"
22518 - " movq 40(%0), %%mm1\n"
22519 - " movq 48(%0), %%mm2\n"
22520 - " movq 56(%0), %%mm3\n"
22521 - " movq %%mm0, 32(%1)\n"
22522 - " movq %%mm1, 40(%1)\n"
22523 - " movq %%mm2, 48(%1)\n"
22524 - " movq %%mm3, 56(%1)\n"
22525 + "1: prefetch 320(%1)\n"
22526 + "2: movq (%1), %%mm0\n"
22527 + " movq 8(%1), %%mm1\n"
22528 + " movq 16(%1), %%mm2\n"
22529 + " movq 24(%1), %%mm3\n"
22530 + " movq %%mm0, (%2)\n"
22531 + " movq %%mm1, 8(%2)\n"
22532 + " movq %%mm2, 16(%2)\n"
22533 + " movq %%mm3, 24(%2)\n"
22534 + " movq 32(%1), %%mm0\n"
22535 + " movq 40(%1), %%mm1\n"
22536 + " movq 48(%1), %%mm2\n"
22537 + " movq 56(%1), %%mm3\n"
22538 + " movq %%mm0, 32(%2)\n"
22539 + " movq %%mm1, 40(%2)\n"
22540 + " movq %%mm2, 48(%2)\n"
22541 + " movq %%mm3, 56(%2)\n"
22542 ".section .fixup, \"ax\"\n"
22543 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22544 + "3:\n"
22545 +
22546 +#ifdef CONFIG_PAX_KERNEXEC
22547 + " movl %%cr0, %0\n"
22548 + " movl %0, %%eax\n"
22549 + " andl $0xFFFEFFFF, %%eax\n"
22550 + " movl %%eax, %%cr0\n"
22551 +#endif
22552 +
22553 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22554 +
22555 +#ifdef CONFIG_PAX_KERNEXEC
22556 + " movl %0, %%cr0\n"
22557 +#endif
22558 +
22559 " jmp 2b\n"
22560 ".previous\n"
22561 _ASM_EXTABLE(1b, 3b)
22562 - : : "r" (from), "r" (to) : "memory");
22563 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22564
22565 from += 64;
22566 to += 64;
22567 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22568 index f6d13ee..aca5f0b 100644
22569 --- a/arch/x86/lib/msr-reg.S
22570 +++ b/arch/x86/lib/msr-reg.S
22571 @@ -3,6 +3,7 @@
22572 #include <asm/dwarf2.h>
22573 #include <asm/asm.h>
22574 #include <asm/msr.h>
22575 +#include <asm/alternative-asm.h>
22576
22577 #ifdef CONFIG_X86_64
22578 /*
22579 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22580 CFI_STARTPROC
22581 pushq_cfi %rbx
22582 pushq_cfi %rbp
22583 - movq %rdi, %r10 /* Save pointer */
22584 + movq %rdi, %r9 /* Save pointer */
22585 xorl %r11d, %r11d /* Return value */
22586 movl (%rdi), %eax
22587 movl 4(%rdi), %ecx
22588 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22589 movl 28(%rdi), %edi
22590 CFI_REMEMBER_STATE
22591 1: \op
22592 -2: movl %eax, (%r10)
22593 +2: movl %eax, (%r9)
22594 movl %r11d, %eax /* Return value */
22595 - movl %ecx, 4(%r10)
22596 - movl %edx, 8(%r10)
22597 - movl %ebx, 12(%r10)
22598 - movl %ebp, 20(%r10)
22599 - movl %esi, 24(%r10)
22600 - movl %edi, 28(%r10)
22601 + movl %ecx, 4(%r9)
22602 + movl %edx, 8(%r9)
22603 + movl %ebx, 12(%r9)
22604 + movl %ebp, 20(%r9)
22605 + movl %esi, 24(%r9)
22606 + movl %edi, 28(%r9)
22607 popq_cfi %rbp
22608 popq_cfi %rbx
22609 + pax_force_retaddr
22610 ret
22611 3:
22612 CFI_RESTORE_STATE
22613 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22614 index 7f951c8..ebd573a 100644
22615 --- a/arch/x86/lib/putuser.S
22616 +++ b/arch/x86/lib/putuser.S
22617 @@ -15,7 +15,9 @@
22618 #include <asm/thread_info.h>
22619 #include <asm/errno.h>
22620 #include <asm/asm.h>
22621 -
22622 +#include <asm/segment.h>
22623 +#include <asm/pgtable.h>
22624 +#include <asm/alternative-asm.h>
22625
22626 /*
22627 * __put_user_X
22628 @@ -29,52 +31,119 @@
22629 * as they get called from within inline assembly.
22630 */
22631
22632 -#define ENTER CFI_STARTPROC ; \
22633 - GET_THREAD_INFO(%_ASM_BX)
22634 -#define EXIT ret ; \
22635 +#define ENTER CFI_STARTPROC
22636 +#define EXIT pax_force_retaddr; ret ; \
22637 CFI_ENDPROC
22638
22639 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22640 +#define _DEST %_ASM_CX,%_ASM_BX
22641 +#else
22642 +#define _DEST %_ASM_CX
22643 +#endif
22644 +
22645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22646 +#define __copyuser_seg gs;
22647 +#else
22648 +#define __copyuser_seg
22649 +#endif
22650 +
22651 .text
22652 ENTRY(__put_user_1)
22653 ENTER
22654 +
22655 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22656 + GET_THREAD_INFO(%_ASM_BX)
22657 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22658 jae bad_put_user
22659 -1: movb %al,(%_ASM_CX)
22660 +
22661 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22662 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22663 + cmp %_ASM_BX,%_ASM_CX
22664 + jb 1234f
22665 + xor %ebx,%ebx
22666 +1234:
22667 +#endif
22668 +
22669 +#endif
22670 +
22671 +1: __copyuser_seg movb %al,(_DEST)
22672 xor %eax,%eax
22673 EXIT
22674 ENDPROC(__put_user_1)
22675
22676 ENTRY(__put_user_2)
22677 ENTER
22678 +
22679 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22680 + GET_THREAD_INFO(%_ASM_BX)
22681 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22682 sub $1,%_ASM_BX
22683 cmp %_ASM_BX,%_ASM_CX
22684 jae bad_put_user
22685 -2: movw %ax,(%_ASM_CX)
22686 +
22687 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22688 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22689 + cmp %_ASM_BX,%_ASM_CX
22690 + jb 1234f
22691 + xor %ebx,%ebx
22692 +1234:
22693 +#endif
22694 +
22695 +#endif
22696 +
22697 +2: __copyuser_seg movw %ax,(_DEST)
22698 xor %eax,%eax
22699 EXIT
22700 ENDPROC(__put_user_2)
22701
22702 ENTRY(__put_user_4)
22703 ENTER
22704 +
22705 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22706 + GET_THREAD_INFO(%_ASM_BX)
22707 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22708 sub $3,%_ASM_BX
22709 cmp %_ASM_BX,%_ASM_CX
22710 jae bad_put_user
22711 -3: movl %eax,(%_ASM_CX)
22712 +
22713 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22714 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22715 + cmp %_ASM_BX,%_ASM_CX
22716 + jb 1234f
22717 + xor %ebx,%ebx
22718 +1234:
22719 +#endif
22720 +
22721 +#endif
22722 +
22723 +3: __copyuser_seg movl %eax,(_DEST)
22724 xor %eax,%eax
22725 EXIT
22726 ENDPROC(__put_user_4)
22727
22728 ENTRY(__put_user_8)
22729 ENTER
22730 +
22731 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22732 + GET_THREAD_INFO(%_ASM_BX)
22733 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22734 sub $7,%_ASM_BX
22735 cmp %_ASM_BX,%_ASM_CX
22736 jae bad_put_user
22737 -4: mov %_ASM_AX,(%_ASM_CX)
22738 +
22739 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22740 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22741 + cmp %_ASM_BX,%_ASM_CX
22742 + jb 1234f
22743 + xor %ebx,%ebx
22744 +1234:
22745 +#endif
22746 +
22747 +#endif
22748 +
22749 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22750 #ifdef CONFIG_X86_32
22751 -5: movl %edx,4(%_ASM_CX)
22752 +5: __copyuser_seg movl %edx,4(_DEST)
22753 #endif
22754 xor %eax,%eax
22755 EXIT
22756 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22757 index 1cad221..de671ee 100644
22758 --- a/arch/x86/lib/rwlock.S
22759 +++ b/arch/x86/lib/rwlock.S
22760 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22761 FRAME
22762 0: LOCK_PREFIX
22763 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22764 +
22765 +#ifdef CONFIG_PAX_REFCOUNT
22766 + jno 1234f
22767 + LOCK_PREFIX
22768 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22769 + int $4
22770 +1234:
22771 + _ASM_EXTABLE(1234b, 1234b)
22772 +#endif
22773 +
22774 1: rep; nop
22775 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22776 jne 1b
22777 LOCK_PREFIX
22778 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22779 +
22780 +#ifdef CONFIG_PAX_REFCOUNT
22781 + jno 1234f
22782 + LOCK_PREFIX
22783 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22784 + int $4
22785 +1234:
22786 + _ASM_EXTABLE(1234b, 1234b)
22787 +#endif
22788 +
22789 jnz 0b
22790 ENDFRAME
22791 + pax_force_retaddr
22792 ret
22793 CFI_ENDPROC
22794 END(__write_lock_failed)
22795 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22796 FRAME
22797 0: LOCK_PREFIX
22798 READ_LOCK_SIZE(inc) (%__lock_ptr)
22799 +
22800 +#ifdef CONFIG_PAX_REFCOUNT
22801 + jno 1234f
22802 + LOCK_PREFIX
22803 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22804 + int $4
22805 +1234:
22806 + _ASM_EXTABLE(1234b, 1234b)
22807 +#endif
22808 +
22809 1: rep; nop
22810 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22811 js 1b
22812 LOCK_PREFIX
22813 READ_LOCK_SIZE(dec) (%__lock_ptr)
22814 +
22815 +#ifdef CONFIG_PAX_REFCOUNT
22816 + jno 1234f
22817 + LOCK_PREFIX
22818 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22819 + int $4
22820 +1234:
22821 + _ASM_EXTABLE(1234b, 1234b)
22822 +#endif
22823 +
22824 js 0b
22825 ENDFRAME
22826 + pax_force_retaddr
22827 ret
22828 CFI_ENDPROC
22829 END(__read_lock_failed)
22830 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22831 index 5dff5f0..cadebf4 100644
22832 --- a/arch/x86/lib/rwsem.S
22833 +++ b/arch/x86/lib/rwsem.S
22834 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22835 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22836 CFI_RESTORE __ASM_REG(dx)
22837 restore_common_regs
22838 + pax_force_retaddr
22839 ret
22840 CFI_ENDPROC
22841 ENDPROC(call_rwsem_down_read_failed)
22842 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22843 movq %rax,%rdi
22844 call rwsem_down_write_failed
22845 restore_common_regs
22846 + pax_force_retaddr
22847 ret
22848 CFI_ENDPROC
22849 ENDPROC(call_rwsem_down_write_failed)
22850 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22851 movq %rax,%rdi
22852 call rwsem_wake
22853 restore_common_regs
22854 -1: ret
22855 +1: pax_force_retaddr
22856 + ret
22857 CFI_ENDPROC
22858 ENDPROC(call_rwsem_wake)
22859
22860 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22861 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22862 CFI_RESTORE __ASM_REG(dx)
22863 restore_common_regs
22864 + pax_force_retaddr
22865 ret
22866 CFI_ENDPROC
22867 ENDPROC(call_rwsem_downgrade_wake)
22868 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22869 index a63efd6..ccecad8 100644
22870 --- a/arch/x86/lib/thunk_64.S
22871 +++ b/arch/x86/lib/thunk_64.S
22872 @@ -8,6 +8,7 @@
22873 #include <linux/linkage.h>
22874 #include <asm/dwarf2.h>
22875 #include <asm/calling.h>
22876 +#include <asm/alternative-asm.h>
22877
22878 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22879 .macro THUNK name, func, put_ret_addr_in_rdi=0
22880 @@ -41,5 +42,6 @@
22881 SAVE_ARGS
22882 restore:
22883 RESTORE_ARGS
22884 + pax_force_retaddr
22885 ret
22886 CFI_ENDPROC
22887 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22888 index 1781b2f..90368dd 100644
22889 --- a/arch/x86/lib/usercopy_32.c
22890 +++ b/arch/x86/lib/usercopy_32.c
22891 @@ -42,10 +42,12 @@ do { \
22892 int __d0; \
22893 might_fault(); \
22894 __asm__ __volatile__( \
22895 + __COPYUSER_SET_ES \
22896 "0: rep; stosl\n" \
22897 " movl %2,%0\n" \
22898 "1: rep; stosb\n" \
22899 "2:\n" \
22900 + __COPYUSER_RESTORE_ES \
22901 ".section .fixup,\"ax\"\n" \
22902 "3: lea 0(%2,%0,4),%0\n" \
22903 " jmp 2b\n" \
22904 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22905
22906 #ifdef CONFIG_X86_INTEL_USERCOPY
22907 static unsigned long
22908 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22909 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22910 {
22911 int d0, d1;
22912 __asm__ __volatile__(
22913 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22914 " .align 2,0x90\n"
22915 "3: movl 0(%4), %%eax\n"
22916 "4: movl 4(%4), %%edx\n"
22917 - "5: movl %%eax, 0(%3)\n"
22918 - "6: movl %%edx, 4(%3)\n"
22919 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22920 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22921 "7: movl 8(%4), %%eax\n"
22922 "8: movl 12(%4),%%edx\n"
22923 - "9: movl %%eax, 8(%3)\n"
22924 - "10: movl %%edx, 12(%3)\n"
22925 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22926 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22927 "11: movl 16(%4), %%eax\n"
22928 "12: movl 20(%4), %%edx\n"
22929 - "13: movl %%eax, 16(%3)\n"
22930 - "14: movl %%edx, 20(%3)\n"
22931 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22932 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22933 "15: movl 24(%4), %%eax\n"
22934 "16: movl 28(%4), %%edx\n"
22935 - "17: movl %%eax, 24(%3)\n"
22936 - "18: movl %%edx, 28(%3)\n"
22937 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22938 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22939 "19: movl 32(%4), %%eax\n"
22940 "20: movl 36(%4), %%edx\n"
22941 - "21: movl %%eax, 32(%3)\n"
22942 - "22: movl %%edx, 36(%3)\n"
22943 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22944 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22945 "23: movl 40(%4), %%eax\n"
22946 "24: movl 44(%4), %%edx\n"
22947 - "25: movl %%eax, 40(%3)\n"
22948 - "26: movl %%edx, 44(%3)\n"
22949 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22950 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22951 "27: movl 48(%4), %%eax\n"
22952 "28: movl 52(%4), %%edx\n"
22953 - "29: movl %%eax, 48(%3)\n"
22954 - "30: movl %%edx, 52(%3)\n"
22955 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22956 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22957 "31: movl 56(%4), %%eax\n"
22958 "32: movl 60(%4), %%edx\n"
22959 - "33: movl %%eax, 56(%3)\n"
22960 - "34: movl %%edx, 60(%3)\n"
22961 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22962 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22963 " addl $-64, %0\n"
22964 " addl $64, %4\n"
22965 " addl $64, %3\n"
22966 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22967 " shrl $2, %0\n"
22968 " andl $3, %%eax\n"
22969 " cld\n"
22970 + __COPYUSER_SET_ES
22971 "99: rep; movsl\n"
22972 "36: movl %%eax, %0\n"
22973 "37: rep; movsb\n"
22974 "100:\n"
22975 + __COPYUSER_RESTORE_ES
22976 ".section .fixup,\"ax\"\n"
22977 "101: lea 0(%%eax,%0,4),%0\n"
22978 " jmp 100b\n"
22979 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22980 }
22981
22982 static unsigned long
22983 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22984 +{
22985 + int d0, d1;
22986 + __asm__ __volatile__(
22987 + " .align 2,0x90\n"
22988 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22989 + " cmpl $67, %0\n"
22990 + " jbe 3f\n"
22991 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22992 + " .align 2,0x90\n"
22993 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22994 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22995 + "5: movl %%eax, 0(%3)\n"
22996 + "6: movl %%edx, 4(%3)\n"
22997 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22998 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22999 + "9: movl %%eax, 8(%3)\n"
23000 + "10: movl %%edx, 12(%3)\n"
23001 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23002 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23003 + "13: movl %%eax, 16(%3)\n"
23004 + "14: movl %%edx, 20(%3)\n"
23005 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23006 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23007 + "17: movl %%eax, 24(%3)\n"
23008 + "18: movl %%edx, 28(%3)\n"
23009 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23010 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23011 + "21: movl %%eax, 32(%3)\n"
23012 + "22: movl %%edx, 36(%3)\n"
23013 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23014 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23015 + "25: movl %%eax, 40(%3)\n"
23016 + "26: movl %%edx, 44(%3)\n"
23017 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23018 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23019 + "29: movl %%eax, 48(%3)\n"
23020 + "30: movl %%edx, 52(%3)\n"
23021 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23022 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23023 + "33: movl %%eax, 56(%3)\n"
23024 + "34: movl %%edx, 60(%3)\n"
23025 + " addl $-64, %0\n"
23026 + " addl $64, %4\n"
23027 + " addl $64, %3\n"
23028 + " cmpl $63, %0\n"
23029 + " ja 1b\n"
23030 + "35: movl %0, %%eax\n"
23031 + " shrl $2, %0\n"
23032 + " andl $3, %%eax\n"
23033 + " cld\n"
23034 + "99: rep; "__copyuser_seg" movsl\n"
23035 + "36: movl %%eax, %0\n"
23036 + "37: rep; "__copyuser_seg" movsb\n"
23037 + "100:\n"
23038 + ".section .fixup,\"ax\"\n"
23039 + "101: lea 0(%%eax,%0,4),%0\n"
23040 + " jmp 100b\n"
23041 + ".previous\n"
23042 + _ASM_EXTABLE(1b,100b)
23043 + _ASM_EXTABLE(2b,100b)
23044 + _ASM_EXTABLE(3b,100b)
23045 + _ASM_EXTABLE(4b,100b)
23046 + _ASM_EXTABLE(5b,100b)
23047 + _ASM_EXTABLE(6b,100b)
23048 + _ASM_EXTABLE(7b,100b)
23049 + _ASM_EXTABLE(8b,100b)
23050 + _ASM_EXTABLE(9b,100b)
23051 + _ASM_EXTABLE(10b,100b)
23052 + _ASM_EXTABLE(11b,100b)
23053 + _ASM_EXTABLE(12b,100b)
23054 + _ASM_EXTABLE(13b,100b)
23055 + _ASM_EXTABLE(14b,100b)
23056 + _ASM_EXTABLE(15b,100b)
23057 + _ASM_EXTABLE(16b,100b)
23058 + _ASM_EXTABLE(17b,100b)
23059 + _ASM_EXTABLE(18b,100b)
23060 + _ASM_EXTABLE(19b,100b)
23061 + _ASM_EXTABLE(20b,100b)
23062 + _ASM_EXTABLE(21b,100b)
23063 + _ASM_EXTABLE(22b,100b)
23064 + _ASM_EXTABLE(23b,100b)
23065 + _ASM_EXTABLE(24b,100b)
23066 + _ASM_EXTABLE(25b,100b)
23067 + _ASM_EXTABLE(26b,100b)
23068 + _ASM_EXTABLE(27b,100b)
23069 + _ASM_EXTABLE(28b,100b)
23070 + _ASM_EXTABLE(29b,100b)
23071 + _ASM_EXTABLE(30b,100b)
23072 + _ASM_EXTABLE(31b,100b)
23073 + _ASM_EXTABLE(32b,100b)
23074 + _ASM_EXTABLE(33b,100b)
23075 + _ASM_EXTABLE(34b,100b)
23076 + _ASM_EXTABLE(35b,100b)
23077 + _ASM_EXTABLE(36b,100b)
23078 + _ASM_EXTABLE(37b,100b)
23079 + _ASM_EXTABLE(99b,101b)
23080 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23081 + : "1"(to), "2"(from), "0"(size)
23082 + : "eax", "edx", "memory");
23083 + return size;
23084 +}
23085 +
23086 +static unsigned long __size_overflow(3)
23087 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23088 {
23089 int d0, d1;
23090 __asm__ __volatile__(
23091 " .align 2,0x90\n"
23092 - "0: movl 32(%4), %%eax\n"
23093 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23094 " cmpl $67, %0\n"
23095 " jbe 2f\n"
23096 - "1: movl 64(%4), %%eax\n"
23097 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23098 " .align 2,0x90\n"
23099 - "2: movl 0(%4), %%eax\n"
23100 - "21: movl 4(%4), %%edx\n"
23101 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23102 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23103 " movl %%eax, 0(%3)\n"
23104 " movl %%edx, 4(%3)\n"
23105 - "3: movl 8(%4), %%eax\n"
23106 - "31: movl 12(%4),%%edx\n"
23107 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23108 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23109 " movl %%eax, 8(%3)\n"
23110 " movl %%edx, 12(%3)\n"
23111 - "4: movl 16(%4), %%eax\n"
23112 - "41: movl 20(%4), %%edx\n"
23113 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23114 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23115 " movl %%eax, 16(%3)\n"
23116 " movl %%edx, 20(%3)\n"
23117 - "10: movl 24(%4), %%eax\n"
23118 - "51: movl 28(%4), %%edx\n"
23119 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23120 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23121 " movl %%eax, 24(%3)\n"
23122 " movl %%edx, 28(%3)\n"
23123 - "11: movl 32(%4), %%eax\n"
23124 - "61: movl 36(%4), %%edx\n"
23125 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23126 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23127 " movl %%eax, 32(%3)\n"
23128 " movl %%edx, 36(%3)\n"
23129 - "12: movl 40(%4), %%eax\n"
23130 - "71: movl 44(%4), %%edx\n"
23131 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23132 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23133 " movl %%eax, 40(%3)\n"
23134 " movl %%edx, 44(%3)\n"
23135 - "13: movl 48(%4), %%eax\n"
23136 - "81: movl 52(%4), %%edx\n"
23137 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23138 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23139 " movl %%eax, 48(%3)\n"
23140 " movl %%edx, 52(%3)\n"
23141 - "14: movl 56(%4), %%eax\n"
23142 - "91: movl 60(%4), %%edx\n"
23143 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23144 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23145 " movl %%eax, 56(%3)\n"
23146 " movl %%edx, 60(%3)\n"
23147 " addl $-64, %0\n"
23148 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23149 " shrl $2, %0\n"
23150 " andl $3, %%eax\n"
23151 " cld\n"
23152 - "6: rep; movsl\n"
23153 + "6: rep; "__copyuser_seg" movsl\n"
23154 " movl %%eax,%0\n"
23155 - "7: rep; movsb\n"
23156 + "7: rep; "__copyuser_seg" movsb\n"
23157 "8:\n"
23158 ".section .fixup,\"ax\"\n"
23159 "9: lea 0(%%eax,%0,4),%0\n"
23160 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23161 * hyoshiok@miraclelinux.com
23162 */
23163
23164 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23165 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23166 const void __user *from, unsigned long size)
23167 {
23168 int d0, d1;
23169
23170 __asm__ __volatile__(
23171 " .align 2,0x90\n"
23172 - "0: movl 32(%4), %%eax\n"
23173 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23174 " cmpl $67, %0\n"
23175 " jbe 2f\n"
23176 - "1: movl 64(%4), %%eax\n"
23177 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23178 " .align 2,0x90\n"
23179 - "2: movl 0(%4), %%eax\n"
23180 - "21: movl 4(%4), %%edx\n"
23181 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23182 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23183 " movnti %%eax, 0(%3)\n"
23184 " movnti %%edx, 4(%3)\n"
23185 - "3: movl 8(%4), %%eax\n"
23186 - "31: movl 12(%4),%%edx\n"
23187 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23188 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23189 " movnti %%eax, 8(%3)\n"
23190 " movnti %%edx, 12(%3)\n"
23191 - "4: movl 16(%4), %%eax\n"
23192 - "41: movl 20(%4), %%edx\n"
23193 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23194 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23195 " movnti %%eax, 16(%3)\n"
23196 " movnti %%edx, 20(%3)\n"
23197 - "10: movl 24(%4), %%eax\n"
23198 - "51: movl 28(%4), %%edx\n"
23199 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23200 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23201 " movnti %%eax, 24(%3)\n"
23202 " movnti %%edx, 28(%3)\n"
23203 - "11: movl 32(%4), %%eax\n"
23204 - "61: movl 36(%4), %%edx\n"
23205 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23206 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23207 " movnti %%eax, 32(%3)\n"
23208 " movnti %%edx, 36(%3)\n"
23209 - "12: movl 40(%4), %%eax\n"
23210 - "71: movl 44(%4), %%edx\n"
23211 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23212 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23213 " movnti %%eax, 40(%3)\n"
23214 " movnti %%edx, 44(%3)\n"
23215 - "13: movl 48(%4), %%eax\n"
23216 - "81: movl 52(%4), %%edx\n"
23217 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23218 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23219 " movnti %%eax, 48(%3)\n"
23220 " movnti %%edx, 52(%3)\n"
23221 - "14: movl 56(%4), %%eax\n"
23222 - "91: movl 60(%4), %%edx\n"
23223 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23224 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23225 " movnti %%eax, 56(%3)\n"
23226 " movnti %%edx, 60(%3)\n"
23227 " addl $-64, %0\n"
23228 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23229 " shrl $2, %0\n"
23230 " andl $3, %%eax\n"
23231 " cld\n"
23232 - "6: rep; movsl\n"
23233 + "6: rep; "__copyuser_seg" movsl\n"
23234 " movl %%eax,%0\n"
23235 - "7: rep; movsb\n"
23236 + "7: rep; "__copyuser_seg" movsb\n"
23237 "8:\n"
23238 ".section .fixup,\"ax\"\n"
23239 "9: lea 0(%%eax,%0,4),%0\n"
23240 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23241 return size;
23242 }
23243
23244 -static unsigned long __copy_user_intel_nocache(void *to,
23245 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23246 const void __user *from, unsigned long size)
23247 {
23248 int d0, d1;
23249
23250 __asm__ __volatile__(
23251 " .align 2,0x90\n"
23252 - "0: movl 32(%4), %%eax\n"
23253 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23254 " cmpl $67, %0\n"
23255 " jbe 2f\n"
23256 - "1: movl 64(%4), %%eax\n"
23257 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23258 " .align 2,0x90\n"
23259 - "2: movl 0(%4), %%eax\n"
23260 - "21: movl 4(%4), %%edx\n"
23261 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23262 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23263 " movnti %%eax, 0(%3)\n"
23264 " movnti %%edx, 4(%3)\n"
23265 - "3: movl 8(%4), %%eax\n"
23266 - "31: movl 12(%4),%%edx\n"
23267 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23268 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23269 " movnti %%eax, 8(%3)\n"
23270 " movnti %%edx, 12(%3)\n"
23271 - "4: movl 16(%4), %%eax\n"
23272 - "41: movl 20(%4), %%edx\n"
23273 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23274 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23275 " movnti %%eax, 16(%3)\n"
23276 " movnti %%edx, 20(%3)\n"
23277 - "10: movl 24(%4), %%eax\n"
23278 - "51: movl 28(%4), %%edx\n"
23279 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23280 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23281 " movnti %%eax, 24(%3)\n"
23282 " movnti %%edx, 28(%3)\n"
23283 - "11: movl 32(%4), %%eax\n"
23284 - "61: movl 36(%4), %%edx\n"
23285 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23286 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23287 " movnti %%eax, 32(%3)\n"
23288 " movnti %%edx, 36(%3)\n"
23289 - "12: movl 40(%4), %%eax\n"
23290 - "71: movl 44(%4), %%edx\n"
23291 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23292 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23293 " movnti %%eax, 40(%3)\n"
23294 " movnti %%edx, 44(%3)\n"
23295 - "13: movl 48(%4), %%eax\n"
23296 - "81: movl 52(%4), %%edx\n"
23297 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23298 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23299 " movnti %%eax, 48(%3)\n"
23300 " movnti %%edx, 52(%3)\n"
23301 - "14: movl 56(%4), %%eax\n"
23302 - "91: movl 60(%4), %%edx\n"
23303 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23304 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23305 " movnti %%eax, 56(%3)\n"
23306 " movnti %%edx, 60(%3)\n"
23307 " addl $-64, %0\n"
23308 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23309 " shrl $2, %0\n"
23310 " andl $3, %%eax\n"
23311 " cld\n"
23312 - "6: rep; movsl\n"
23313 + "6: rep; "__copyuser_seg" movsl\n"
23314 " movl %%eax,%0\n"
23315 - "7: rep; movsb\n"
23316 + "7: rep; "__copyuser_seg" movsb\n"
23317 "8:\n"
23318 ".section .fixup,\"ax\"\n"
23319 "9: lea 0(%%eax,%0,4),%0\n"
23320 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23321 */
23322 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23323 unsigned long size);
23324 -unsigned long __copy_user_intel(void __user *to, const void *from,
23325 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23326 + unsigned long size);
23327 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23328 unsigned long size);
23329 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23330 const void __user *from, unsigned long size);
23331 #endif /* CONFIG_X86_INTEL_USERCOPY */
23332
23333 /* Generic arbitrary sized copy. */
23334 -#define __copy_user(to, from, size) \
23335 +#define __copy_user(to, from, size, prefix, set, restore) \
23336 do { \
23337 int __d0, __d1, __d2; \
23338 __asm__ __volatile__( \
23339 + set \
23340 " cmp $7,%0\n" \
23341 " jbe 1f\n" \
23342 " movl %1,%0\n" \
23343 " negl %0\n" \
23344 " andl $7,%0\n" \
23345 " subl %0,%3\n" \
23346 - "4: rep; movsb\n" \
23347 + "4: rep; "prefix"movsb\n" \
23348 " movl %3,%0\n" \
23349 " shrl $2,%0\n" \
23350 " andl $3,%3\n" \
23351 " .align 2,0x90\n" \
23352 - "0: rep; movsl\n" \
23353 + "0: rep; "prefix"movsl\n" \
23354 " movl %3,%0\n" \
23355 - "1: rep; movsb\n" \
23356 + "1: rep; "prefix"movsb\n" \
23357 "2:\n" \
23358 + restore \
23359 ".section .fixup,\"ax\"\n" \
23360 "5: addl %3,%0\n" \
23361 " jmp 2b\n" \
23362 @@ -537,14 +649,14 @@ do { \
23363 " negl %0\n" \
23364 " andl $7,%0\n" \
23365 " subl %0,%3\n" \
23366 - "4: rep; movsb\n" \
23367 + "4: rep; "__copyuser_seg"movsb\n" \
23368 " movl %3,%0\n" \
23369 " shrl $2,%0\n" \
23370 " andl $3,%3\n" \
23371 " .align 2,0x90\n" \
23372 - "0: rep; movsl\n" \
23373 + "0: rep; "__copyuser_seg"movsl\n" \
23374 " movl %3,%0\n" \
23375 - "1: rep; movsb\n" \
23376 + "1: rep; "__copyuser_seg"movsb\n" \
23377 "2:\n" \
23378 ".section .fixup,\"ax\"\n" \
23379 "5: addl %3,%0\n" \
23380 @@ -627,9 +739,9 @@ survive:
23381 }
23382 #endif
23383 if (movsl_is_ok(to, from, n))
23384 - __copy_user(to, from, n);
23385 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23386 else
23387 - n = __copy_user_intel(to, from, n);
23388 + n = __generic_copy_to_user_intel(to, from, n);
23389 return n;
23390 }
23391 EXPORT_SYMBOL(__copy_to_user_ll);
23392 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23393 unsigned long n)
23394 {
23395 if (movsl_is_ok(to, from, n))
23396 - __copy_user(to, from, n);
23397 + __copy_user(to, from, n, __copyuser_seg, "", "");
23398 else
23399 - n = __copy_user_intel((void __user *)to,
23400 - (const void *)from, n);
23401 + n = __generic_copy_from_user_intel(to, from, n);
23402 return n;
23403 }
23404 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23405 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23406 if (n > 64 && cpu_has_xmm2)
23407 n = __copy_user_intel_nocache(to, from, n);
23408 else
23409 - __copy_user(to, from, n);
23410 + __copy_user(to, from, n, __copyuser_seg, "", "");
23411 #else
23412 - __copy_user(to, from, n);
23413 + __copy_user(to, from, n, __copyuser_seg, "", "");
23414 #endif
23415 return n;
23416 }
23417 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23418
23419 -/**
23420 - * copy_to_user: - Copy a block of data into user space.
23421 - * @to: Destination address, in user space.
23422 - * @from: Source address, in kernel space.
23423 - * @n: Number of bytes to copy.
23424 - *
23425 - * Context: User context only. This function may sleep.
23426 - *
23427 - * Copy data from kernel space to user space.
23428 - *
23429 - * Returns number of bytes that could not be copied.
23430 - * On success, this will be zero.
23431 - */
23432 -unsigned long
23433 -copy_to_user(void __user *to, const void *from, unsigned long n)
23434 -{
23435 - if (access_ok(VERIFY_WRITE, to, n))
23436 - n = __copy_to_user(to, from, n);
23437 - return n;
23438 -}
23439 -EXPORT_SYMBOL(copy_to_user);
23440 -
23441 -/**
23442 - * copy_from_user: - Copy a block of data from user space.
23443 - * @to: Destination address, in kernel space.
23444 - * @from: Source address, in user space.
23445 - * @n: Number of bytes to copy.
23446 - *
23447 - * Context: User context only. This function may sleep.
23448 - *
23449 - * Copy data from user space to kernel space.
23450 - *
23451 - * Returns number of bytes that could not be copied.
23452 - * On success, this will be zero.
23453 - *
23454 - * If some data could not be copied, this function will pad the copied
23455 - * data to the requested size using zero bytes.
23456 - */
23457 -unsigned long
23458 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23459 -{
23460 - if (access_ok(VERIFY_READ, from, n))
23461 - n = __copy_from_user(to, from, n);
23462 - else
23463 - memset(to, 0, n);
23464 - return n;
23465 -}
23466 -EXPORT_SYMBOL(_copy_from_user);
23467 -
23468 void copy_from_user_overflow(void)
23469 {
23470 WARN(1, "Buffer overflow detected!\n");
23471 }
23472 EXPORT_SYMBOL(copy_from_user_overflow);
23473 +
23474 +void copy_to_user_overflow(void)
23475 +{
23476 + WARN(1, "Buffer overflow detected!\n");
23477 +}
23478 +EXPORT_SYMBOL(copy_to_user_overflow);
23479 +
23480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23481 +void __set_fs(mm_segment_t x)
23482 +{
23483 + switch (x.seg) {
23484 + case 0:
23485 + loadsegment(gs, 0);
23486 + break;
23487 + case TASK_SIZE_MAX:
23488 + loadsegment(gs, __USER_DS);
23489 + break;
23490 + case -1UL:
23491 + loadsegment(gs, __KERNEL_DS);
23492 + break;
23493 + default:
23494 + BUG();
23495 + }
23496 + return;
23497 +}
23498 +EXPORT_SYMBOL(__set_fs);
23499 +
23500 +void set_fs(mm_segment_t x)
23501 +{
23502 + current_thread_info()->addr_limit = x;
23503 + __set_fs(x);
23504 +}
23505 +EXPORT_SYMBOL(set_fs);
23506 +#endif
23507 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23508 index e5b130b..6690d31 100644
23509 --- a/arch/x86/lib/usercopy_64.c
23510 +++ b/arch/x86/lib/usercopy_64.c
23511 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23512 {
23513 long __d0;
23514 might_fault();
23515 +
23516 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23517 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23518 + addr += PAX_USER_SHADOW_BASE;
23519 +#endif
23520 +
23521 /* no memory constraint because it doesn't change any memory gcc knows
23522 about */
23523 asm volatile(
23524 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23525 }
23526 EXPORT_SYMBOL(clear_user);
23527
23528 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23529 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23530 {
23531 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23532 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23533 - }
23534 - return len;
23535 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23536 +
23537 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23538 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23539 + to += PAX_USER_SHADOW_BASE;
23540 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23541 + from += PAX_USER_SHADOW_BASE;
23542 +#endif
23543 +
23544 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23545 + }
23546 + return len;
23547 }
23548 EXPORT_SYMBOL(copy_in_user);
23549
23550 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23551 * it is not necessary to optimize tail handling.
23552 */
23553 unsigned long
23554 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23555 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23556 {
23557 char c;
23558 unsigned zero_len;
23559 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23560 break;
23561 return len;
23562 }
23563 +
23564 +void copy_from_user_overflow(void)
23565 +{
23566 + WARN(1, "Buffer overflow detected!\n");
23567 +}
23568 +EXPORT_SYMBOL(copy_from_user_overflow);
23569 +
23570 +void copy_to_user_overflow(void)
23571 +{
23572 + WARN(1, "Buffer overflow detected!\n");
23573 +}
23574 +EXPORT_SYMBOL(copy_to_user_overflow);
23575 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23576 index 903ec1e..c4166b2 100644
23577 --- a/arch/x86/mm/extable.c
23578 +++ b/arch/x86/mm/extable.c
23579 @@ -6,12 +6,24 @@
23580 static inline unsigned long
23581 ex_insn_addr(const struct exception_table_entry *x)
23582 {
23583 - return (unsigned long)&x->insn + x->insn;
23584 + unsigned long reloc = 0;
23585 +
23586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23587 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23588 +#endif
23589 +
23590 + return (unsigned long)&x->insn + x->insn + reloc;
23591 }
23592 static inline unsigned long
23593 ex_fixup_addr(const struct exception_table_entry *x)
23594 {
23595 - return (unsigned long)&x->fixup + x->fixup;
23596 + unsigned long reloc = 0;
23597 +
23598 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23599 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23600 +#endif
23601 +
23602 + return (unsigned long)&x->fixup + x->fixup + reloc;
23603 }
23604
23605 int fixup_exception(struct pt_regs *regs)
23606 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23607 unsigned long new_ip;
23608
23609 #ifdef CONFIG_PNPBIOS
23610 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23611 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23612 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23613 extern u32 pnp_bios_is_utter_crap;
23614 pnp_bios_is_utter_crap = 1;
23615 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23616 i += 4;
23617 p->fixup -= i;
23618 i += 4;
23619 +
23620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23621 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23622 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23623 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23624 +#endif
23625 +
23626 }
23627 }
23628
23629 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23630 index 76dcd9d..e9dffde 100644
23631 --- a/arch/x86/mm/fault.c
23632 +++ b/arch/x86/mm/fault.c
23633 @@ -13,11 +13,18 @@
23634 #include <linux/perf_event.h> /* perf_sw_event */
23635 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23636 #include <linux/prefetch.h> /* prefetchw */
23637 +#include <linux/unistd.h>
23638 +#include <linux/compiler.h>
23639
23640 #include <asm/traps.h> /* dotraplinkage, ... */
23641 #include <asm/pgalloc.h> /* pgd_*(), ... */
23642 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23643 #include <asm/fixmap.h> /* VSYSCALL_START */
23644 +#include <asm/tlbflush.h>
23645 +
23646 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23647 +#include <asm/stacktrace.h>
23648 +#endif
23649
23650 /*
23651 * Page fault error code bits:
23652 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23653 int ret = 0;
23654
23655 /* kprobe_running() needs smp_processor_id() */
23656 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23657 + if (kprobes_built_in() && !user_mode(regs)) {
23658 preempt_disable();
23659 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23660 ret = 1;
23661 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23662 return !instr_lo || (instr_lo>>1) == 1;
23663 case 0x00:
23664 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23665 - if (probe_kernel_address(instr, opcode))
23666 + if (user_mode(regs)) {
23667 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23668 + return 0;
23669 + } else if (probe_kernel_address(instr, opcode))
23670 return 0;
23671
23672 *prefetch = (instr_lo == 0xF) &&
23673 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23674 while (instr < max_instr) {
23675 unsigned char opcode;
23676
23677 - if (probe_kernel_address(instr, opcode))
23678 + if (user_mode(regs)) {
23679 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23680 + break;
23681 + } else if (probe_kernel_address(instr, opcode))
23682 break;
23683
23684 instr++;
23685 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23686 force_sig_info(si_signo, &info, tsk);
23687 }
23688
23689 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23690 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23691 +#endif
23692 +
23693 +#ifdef CONFIG_PAX_EMUTRAMP
23694 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23695 +#endif
23696 +
23697 +#ifdef CONFIG_PAX_PAGEEXEC
23698 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23699 +{
23700 + pgd_t *pgd;
23701 + pud_t *pud;
23702 + pmd_t *pmd;
23703 +
23704 + pgd = pgd_offset(mm, address);
23705 + if (!pgd_present(*pgd))
23706 + return NULL;
23707 + pud = pud_offset(pgd, address);
23708 + if (!pud_present(*pud))
23709 + return NULL;
23710 + pmd = pmd_offset(pud, address);
23711 + if (!pmd_present(*pmd))
23712 + return NULL;
23713 + return pmd;
23714 +}
23715 +#endif
23716 +
23717 DEFINE_SPINLOCK(pgd_lock);
23718 LIST_HEAD(pgd_list);
23719
23720 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23721 for (address = VMALLOC_START & PMD_MASK;
23722 address >= TASK_SIZE && address < FIXADDR_TOP;
23723 address += PMD_SIZE) {
23724 +
23725 +#ifdef CONFIG_PAX_PER_CPU_PGD
23726 + unsigned long cpu;
23727 +#else
23728 struct page *page;
23729 +#endif
23730
23731 spin_lock(&pgd_lock);
23732 +
23733 +#ifdef CONFIG_PAX_PER_CPU_PGD
23734 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23735 + pgd_t *pgd = get_cpu_pgd(cpu);
23736 + pmd_t *ret;
23737 +#else
23738 list_for_each_entry(page, &pgd_list, lru) {
23739 + pgd_t *pgd = page_address(page);
23740 spinlock_t *pgt_lock;
23741 pmd_t *ret;
23742
23743 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23744 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23745
23746 spin_lock(pgt_lock);
23747 - ret = vmalloc_sync_one(page_address(page), address);
23748 +#endif
23749 +
23750 + ret = vmalloc_sync_one(pgd, address);
23751 +
23752 +#ifndef CONFIG_PAX_PER_CPU_PGD
23753 spin_unlock(pgt_lock);
23754 +#endif
23755
23756 if (!ret)
23757 break;
23758 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23759 * an interrupt in the middle of a task switch..
23760 */
23761 pgd_paddr = read_cr3();
23762 +
23763 +#ifdef CONFIG_PAX_PER_CPU_PGD
23764 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23765 +#endif
23766 +
23767 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23768 if (!pmd_k)
23769 return -1;
23770 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23771 * happen within a race in page table update. In the later
23772 * case just flush:
23773 */
23774 +
23775 +#ifdef CONFIG_PAX_PER_CPU_PGD
23776 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23777 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23778 +#else
23779 pgd = pgd_offset(current->active_mm, address);
23780 +#endif
23781 +
23782 pgd_ref = pgd_offset_k(address);
23783 if (pgd_none(*pgd_ref))
23784 return -1;
23785 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23786 static int is_errata100(struct pt_regs *regs, unsigned long address)
23787 {
23788 #ifdef CONFIG_X86_64
23789 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23790 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23791 return 1;
23792 #endif
23793 return 0;
23794 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23795 }
23796
23797 static const char nx_warning[] = KERN_CRIT
23798 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23799 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23800
23801 static void
23802 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23803 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23804 if (!oops_may_print())
23805 return;
23806
23807 - if (error_code & PF_INSTR) {
23808 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23809 unsigned int level;
23810
23811 pte_t *pte = lookup_address(address, &level);
23812
23813 if (pte && pte_present(*pte) && !pte_exec(*pte))
23814 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23815 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23816 }
23817
23818 +#ifdef CONFIG_PAX_KERNEXEC
23819 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23820 + if (current->signal->curr_ip)
23821 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23822 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23823 + else
23824 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23825 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23826 + }
23827 +#endif
23828 +
23829 printk(KERN_ALERT "BUG: unable to handle kernel ");
23830 if (address < PAGE_SIZE)
23831 printk(KERN_CONT "NULL pointer dereference");
23832 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23833 }
23834 #endif
23835
23836 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23837 + if (pax_is_fetch_fault(regs, error_code, address)) {
23838 +
23839 +#ifdef CONFIG_PAX_EMUTRAMP
23840 + switch (pax_handle_fetch_fault(regs)) {
23841 + case 2:
23842 + return;
23843 + }
23844 +#endif
23845 +
23846 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23847 + do_group_exit(SIGKILL);
23848 + }
23849 +#endif
23850 +
23851 if (unlikely(show_unhandled_signals))
23852 show_signal_msg(regs, error_code, address, tsk);
23853
23854 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23855 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23856 printk(KERN_ERR
23857 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23858 - tsk->comm, tsk->pid, address);
23859 + tsk->comm, task_pid_nr(tsk), address);
23860 code = BUS_MCEERR_AR;
23861 }
23862 #endif
23863 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23864 return 1;
23865 }
23866
23867 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23868 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23869 +{
23870 + pte_t *pte;
23871 + pmd_t *pmd;
23872 + spinlock_t *ptl;
23873 + unsigned char pte_mask;
23874 +
23875 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23876 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23877 + return 0;
23878 +
23879 + /* PaX: it's our fault, let's handle it if we can */
23880 +
23881 + /* PaX: take a look at read faults before acquiring any locks */
23882 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23883 + /* instruction fetch attempt from a protected page in user mode */
23884 + up_read(&mm->mmap_sem);
23885 +
23886 +#ifdef CONFIG_PAX_EMUTRAMP
23887 + switch (pax_handle_fetch_fault(regs)) {
23888 + case 2:
23889 + return 1;
23890 + }
23891 +#endif
23892 +
23893 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23894 + do_group_exit(SIGKILL);
23895 + }
23896 +
23897 + pmd = pax_get_pmd(mm, address);
23898 + if (unlikely(!pmd))
23899 + return 0;
23900 +
23901 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23902 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23903 + pte_unmap_unlock(pte, ptl);
23904 + return 0;
23905 + }
23906 +
23907 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23908 + /* write attempt to a protected page in user mode */
23909 + pte_unmap_unlock(pte, ptl);
23910 + return 0;
23911 + }
23912 +
23913 +#ifdef CONFIG_SMP
23914 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23915 +#else
23916 + if (likely(address > get_limit(regs->cs)))
23917 +#endif
23918 + {
23919 + set_pte(pte, pte_mkread(*pte));
23920 + __flush_tlb_one(address);
23921 + pte_unmap_unlock(pte, ptl);
23922 + up_read(&mm->mmap_sem);
23923 + return 1;
23924 + }
23925 +
23926 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23927 +
23928 + /*
23929 + * PaX: fill DTLB with user rights and retry
23930 + */
23931 + __asm__ __volatile__ (
23932 + "orb %2,(%1)\n"
23933 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23934 +/*
23935 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23936 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23937 + * page fault when examined during a TLB load attempt. this is true not only
23938 + * for PTEs holding a non-present entry but also present entries that will
23939 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23940 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23941 + * for our target pages since their PTEs are simply not in the TLBs at all.
23942 +
23943 + * the best thing in omitting it is that we gain around 15-20% speed in the
23944 + * fast path of the page fault handler and can get rid of tracing since we
23945 + * can no longer flush unintended entries.
23946 + */
23947 + "invlpg (%0)\n"
23948 +#endif
23949 + __copyuser_seg"testb $0,(%0)\n"
23950 + "xorb %3,(%1)\n"
23951 + :
23952 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23953 + : "memory", "cc");
23954 + pte_unmap_unlock(pte, ptl);
23955 + up_read(&mm->mmap_sem);
23956 + return 1;
23957 +}
23958 +#endif
23959 +
23960 /*
23961 * Handle a spurious fault caused by a stale TLB entry.
23962 *
23963 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23964 static inline int
23965 access_error(unsigned long error_code, struct vm_area_struct *vma)
23966 {
23967 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23968 + return 1;
23969 +
23970 if (error_code & PF_WRITE) {
23971 /* write, present and write, not present: */
23972 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23973 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23974 {
23975 struct vm_area_struct *vma;
23976 struct task_struct *tsk;
23977 - unsigned long address;
23978 struct mm_struct *mm;
23979 int fault;
23980 int write = error_code & PF_WRITE;
23981 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23982 (write ? FAULT_FLAG_WRITE : 0);
23983
23984 - tsk = current;
23985 - mm = tsk->mm;
23986 -
23987 /* Get the faulting address: */
23988 - address = read_cr2();
23989 + unsigned long address = read_cr2();
23990 +
23991 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23992 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23993 + if (!search_exception_tables(regs->ip)) {
23994 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23995 + bad_area_nosemaphore(regs, error_code, address);
23996 + return;
23997 + }
23998 + if (address < PAX_USER_SHADOW_BASE) {
23999 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24000 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24001 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24002 + } else
24003 + address -= PAX_USER_SHADOW_BASE;
24004 + }
24005 +#endif
24006 +
24007 + tsk = current;
24008 + mm = tsk->mm;
24009
24010 /*
24011 * Detect and handle instructions that would cause a page fault for
24012 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24013 * User-mode registers count as a user access even for any
24014 * potential system fault or CPU buglet:
24015 */
24016 - if (user_mode_vm(regs)) {
24017 + if (user_mode(regs)) {
24018 local_irq_enable();
24019 error_code |= PF_USER;
24020 } else {
24021 @@ -1132,6 +1339,11 @@ retry:
24022 might_sleep();
24023 }
24024
24025 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24026 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24027 + return;
24028 +#endif
24029 +
24030 vma = find_vma(mm, address);
24031 if (unlikely(!vma)) {
24032 bad_area(regs, error_code, address);
24033 @@ -1143,18 +1355,24 @@ retry:
24034 bad_area(regs, error_code, address);
24035 return;
24036 }
24037 - if (error_code & PF_USER) {
24038 - /*
24039 - * Accessing the stack below %sp is always a bug.
24040 - * The large cushion allows instructions like enter
24041 - * and pusha to work. ("enter $65535, $31" pushes
24042 - * 32 pointers and then decrements %sp by 65535.)
24043 - */
24044 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24045 - bad_area(regs, error_code, address);
24046 - return;
24047 - }
24048 + /*
24049 + * Accessing the stack below %sp is always a bug.
24050 + * The large cushion allows instructions like enter
24051 + * and pusha to work. ("enter $65535, $31" pushes
24052 + * 32 pointers and then decrements %sp by 65535.)
24053 + */
24054 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24055 + bad_area(regs, error_code, address);
24056 + return;
24057 }
24058 +
24059 +#ifdef CONFIG_PAX_SEGMEXEC
24060 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24061 + bad_area(regs, error_code, address);
24062 + return;
24063 + }
24064 +#endif
24065 +
24066 if (unlikely(expand_stack(vma, address))) {
24067 bad_area(regs, error_code, address);
24068 return;
24069 @@ -1209,3 +1427,292 @@ good_area:
24070
24071 up_read(&mm->mmap_sem);
24072 }
24073 +
24074 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24075 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24076 +{
24077 + struct mm_struct *mm = current->mm;
24078 + unsigned long ip = regs->ip;
24079 +
24080 + if (v8086_mode(regs))
24081 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24082 +
24083 +#ifdef CONFIG_PAX_PAGEEXEC
24084 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24085 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24086 + return true;
24087 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24088 + return true;
24089 + return false;
24090 + }
24091 +#endif
24092 +
24093 +#ifdef CONFIG_PAX_SEGMEXEC
24094 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24095 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24096 + return true;
24097 + return false;
24098 + }
24099 +#endif
24100 +
24101 + return false;
24102 +}
24103 +#endif
24104 +
24105 +#ifdef CONFIG_PAX_EMUTRAMP
24106 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24107 +{
24108 + int err;
24109 +
24110 + do { /* PaX: libffi trampoline emulation */
24111 + unsigned char mov, jmp;
24112 + unsigned int addr1, addr2;
24113 +
24114 +#ifdef CONFIG_X86_64
24115 + if ((regs->ip + 9) >> 32)
24116 + break;
24117 +#endif
24118 +
24119 + err = get_user(mov, (unsigned char __user *)regs->ip);
24120 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24121 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24122 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24123 +
24124 + if (err)
24125 + break;
24126 +
24127 + if (mov == 0xB8 && jmp == 0xE9) {
24128 + regs->ax = addr1;
24129 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24130 + return 2;
24131 + }
24132 + } while (0);
24133 +
24134 + do { /* PaX: gcc trampoline emulation #1 */
24135 + unsigned char mov1, mov2;
24136 + unsigned short jmp;
24137 + unsigned int addr1, addr2;
24138 +
24139 +#ifdef CONFIG_X86_64
24140 + if ((regs->ip + 11) >> 32)
24141 + break;
24142 +#endif
24143 +
24144 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24145 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24146 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24147 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24148 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24149 +
24150 + if (err)
24151 + break;
24152 +
24153 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24154 + regs->cx = addr1;
24155 + regs->ax = addr2;
24156 + regs->ip = addr2;
24157 + return 2;
24158 + }
24159 + } while (0);
24160 +
24161 + do { /* PaX: gcc trampoline emulation #2 */
24162 + unsigned char mov, jmp;
24163 + unsigned int addr1, addr2;
24164 +
24165 +#ifdef CONFIG_X86_64
24166 + if ((regs->ip + 9) >> 32)
24167 + break;
24168 +#endif
24169 +
24170 + err = get_user(mov, (unsigned char __user *)regs->ip);
24171 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24172 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24173 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24174 +
24175 + if (err)
24176 + break;
24177 +
24178 + if (mov == 0xB9 && jmp == 0xE9) {
24179 + regs->cx = addr1;
24180 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24181 + return 2;
24182 + }
24183 + } while (0);
24184 +
24185 + return 1; /* PaX in action */
24186 +}
24187 +
24188 +#ifdef CONFIG_X86_64
24189 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24190 +{
24191 + int err;
24192 +
24193 + do { /* PaX: libffi trampoline emulation */
24194 + unsigned short mov1, mov2, jmp1;
24195 + unsigned char stcclc, jmp2;
24196 + unsigned long addr1, addr2;
24197 +
24198 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24199 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24200 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24201 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24202 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24203 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24204 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24205 +
24206 + if (err)
24207 + break;
24208 +
24209 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24210 + regs->r11 = addr1;
24211 + regs->r10 = addr2;
24212 + if (stcclc == 0xF8)
24213 + regs->flags &= ~X86_EFLAGS_CF;
24214 + else
24215 + regs->flags |= X86_EFLAGS_CF;
24216 + regs->ip = addr1;
24217 + return 2;
24218 + }
24219 + } while (0);
24220 +
24221 + do { /* PaX: gcc trampoline emulation #1 */
24222 + unsigned short mov1, mov2, jmp1;
24223 + unsigned char jmp2;
24224 + unsigned int addr1;
24225 + unsigned long addr2;
24226 +
24227 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24228 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24229 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24230 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24231 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24232 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24233 +
24234 + if (err)
24235 + break;
24236 +
24237 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24238 + regs->r11 = addr1;
24239 + regs->r10 = addr2;
24240 + regs->ip = addr1;
24241 + return 2;
24242 + }
24243 + } while (0);
24244 +
24245 + do { /* PaX: gcc trampoline emulation #2 */
24246 + unsigned short mov1, mov2, jmp1;
24247 + unsigned char jmp2;
24248 + unsigned long addr1, addr2;
24249 +
24250 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24251 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24252 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24253 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24254 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24255 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24256 +
24257 + if (err)
24258 + break;
24259 +
24260 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24261 + regs->r11 = addr1;
24262 + regs->r10 = addr2;
24263 + regs->ip = addr1;
24264 + return 2;
24265 + }
24266 + } while (0);
24267 +
24268 + return 1; /* PaX in action */
24269 +}
24270 +#endif
24271 +
24272 +/*
24273 + * PaX: decide what to do with offenders (regs->ip = fault address)
24274 + *
24275 + * returns 1 when task should be killed
24276 + * 2 when gcc trampoline was detected
24277 + */
24278 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24279 +{
24280 + if (v8086_mode(regs))
24281 + return 1;
24282 +
24283 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24284 + return 1;
24285 +
24286 +#ifdef CONFIG_X86_32
24287 + return pax_handle_fetch_fault_32(regs);
24288 +#else
24289 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24290 + return pax_handle_fetch_fault_32(regs);
24291 + else
24292 + return pax_handle_fetch_fault_64(regs);
24293 +#endif
24294 +}
24295 +#endif
24296 +
24297 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24298 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24299 +{
24300 + long i;
24301 +
24302 + printk(KERN_ERR "PAX: bytes at PC: ");
24303 + for (i = 0; i < 20; i++) {
24304 + unsigned char c;
24305 + if (get_user(c, (unsigned char __force_user *)pc+i))
24306 + printk(KERN_CONT "?? ");
24307 + else
24308 + printk(KERN_CONT "%02x ", c);
24309 + }
24310 + printk("\n");
24311 +
24312 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24313 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24314 + unsigned long c;
24315 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24316 +#ifdef CONFIG_X86_32
24317 + printk(KERN_CONT "???????? ");
24318 +#else
24319 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24320 + printk(KERN_CONT "???????? ???????? ");
24321 + else
24322 + printk(KERN_CONT "???????????????? ");
24323 +#endif
24324 + } else {
24325 +#ifdef CONFIG_X86_64
24326 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24327 + printk(KERN_CONT "%08x ", (unsigned int)c);
24328 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24329 + } else
24330 +#endif
24331 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24332 + }
24333 + }
24334 + printk("\n");
24335 +}
24336 +#endif
24337 +
24338 +/**
24339 + * probe_kernel_write(): safely attempt to write to a location
24340 + * @dst: address to write to
24341 + * @src: pointer to the data that shall be written
24342 + * @size: size of the data chunk
24343 + *
24344 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24345 + * happens, handle that and return -EFAULT.
24346 + */
24347 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24348 +{
24349 + long ret;
24350 + mm_segment_t old_fs = get_fs();
24351 +
24352 + set_fs(KERNEL_DS);
24353 + pagefault_disable();
24354 + pax_open_kernel();
24355 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24356 + pax_close_kernel();
24357 + pagefault_enable();
24358 + set_fs(old_fs);
24359 +
24360 + return ret ? -EFAULT : 0;
24361 +}
24362 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24363 index dd74e46..7d26398 100644
24364 --- a/arch/x86/mm/gup.c
24365 +++ b/arch/x86/mm/gup.c
24366 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24367 addr = start;
24368 len = (unsigned long) nr_pages << PAGE_SHIFT;
24369 end = start + len;
24370 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24371 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24372 (void __user *)start, len)))
24373 return 0;
24374
24375 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24376 index 6f31ee5..8ee4164 100644
24377 --- a/arch/x86/mm/highmem_32.c
24378 +++ b/arch/x86/mm/highmem_32.c
24379 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24380 idx = type + KM_TYPE_NR*smp_processor_id();
24381 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24382 BUG_ON(!pte_none(*(kmap_pte-idx)));
24383 +
24384 + pax_open_kernel();
24385 set_pte(kmap_pte-idx, mk_pte(page, prot));
24386 + pax_close_kernel();
24387 +
24388 arch_flush_lazy_mmu_mode();
24389
24390 return (void *)vaddr;
24391 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24392 index b91e485..d00e7c9 100644
24393 --- a/arch/x86/mm/hugetlbpage.c
24394 +++ b/arch/x86/mm/hugetlbpage.c
24395 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24396 struct hstate *h = hstate_file(file);
24397 struct mm_struct *mm = current->mm;
24398 struct vm_area_struct *vma;
24399 - unsigned long start_addr;
24400 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24401 +
24402 +#ifdef CONFIG_PAX_SEGMEXEC
24403 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24404 + pax_task_size = SEGMEXEC_TASK_SIZE;
24405 +#endif
24406 +
24407 + pax_task_size -= PAGE_SIZE;
24408
24409 if (len > mm->cached_hole_size) {
24410 - start_addr = mm->free_area_cache;
24411 + start_addr = mm->free_area_cache;
24412 } else {
24413 - start_addr = TASK_UNMAPPED_BASE;
24414 - mm->cached_hole_size = 0;
24415 + start_addr = mm->mmap_base;
24416 + mm->cached_hole_size = 0;
24417 }
24418
24419 full_search:
24420 @@ -291,26 +298,27 @@ full_search:
24421
24422 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24423 /* At this point: (!vma || addr < vma->vm_end). */
24424 - if (TASK_SIZE - len < addr) {
24425 + if (pax_task_size - len < addr) {
24426 /*
24427 * Start a new search - just in case we missed
24428 * some holes.
24429 */
24430 - if (start_addr != TASK_UNMAPPED_BASE) {
24431 - start_addr = TASK_UNMAPPED_BASE;
24432 + if (start_addr != mm->mmap_base) {
24433 + start_addr = mm->mmap_base;
24434 mm->cached_hole_size = 0;
24435 goto full_search;
24436 }
24437 return -ENOMEM;
24438 }
24439 - if (!vma || addr + len <= vma->vm_start) {
24440 - mm->free_area_cache = addr + len;
24441 - return addr;
24442 - }
24443 + if (check_heap_stack_gap(vma, addr, len))
24444 + break;
24445 if (addr + mm->cached_hole_size < vma->vm_start)
24446 mm->cached_hole_size = vma->vm_start - addr;
24447 addr = ALIGN(vma->vm_end, huge_page_size(h));
24448 }
24449 +
24450 + mm->free_area_cache = addr + len;
24451 + return addr;
24452 }
24453
24454 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24455 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24456 struct mm_struct *mm = current->mm;
24457 struct vm_area_struct *vma;
24458 unsigned long base = mm->mmap_base;
24459 - unsigned long addr = addr0;
24460 + unsigned long addr;
24461 unsigned long largest_hole = mm->cached_hole_size;
24462 - unsigned long start_addr;
24463
24464 /* don't allow allocations above current base */
24465 if (mm->free_area_cache > base)
24466 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24467 largest_hole = 0;
24468 mm->free_area_cache = base;
24469 }
24470 -try_again:
24471 - start_addr = mm->free_area_cache;
24472
24473 /* make sure it can fit in the remaining address space */
24474 if (mm->free_area_cache < len)
24475 goto fail;
24476
24477 /* either no address requested or can't fit in requested address hole */
24478 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24479 + addr = mm->free_area_cache - len;
24480 do {
24481 + addr &= huge_page_mask(h);
24482 /*
24483 * Lookup failure means no vma is above this address,
24484 * i.e. return with success:
24485 @@ -351,10 +357,10 @@ try_again:
24486 if (!vma)
24487 return addr;
24488
24489 - if (addr + len <= vma->vm_start) {
24490 + if (check_heap_stack_gap(vma, addr, len)) {
24491 /* remember the address as a hint for next time */
24492 - mm->cached_hole_size = largest_hole;
24493 - return (mm->free_area_cache = addr);
24494 + mm->cached_hole_size = largest_hole;
24495 + return (mm->free_area_cache = addr);
24496 } else if (mm->free_area_cache == vma->vm_end) {
24497 /* pull free_area_cache down to the first hole */
24498 mm->free_area_cache = vma->vm_start;
24499 @@ -363,29 +369,34 @@ try_again:
24500
24501 /* remember the largest hole we saw so far */
24502 if (addr + largest_hole < vma->vm_start)
24503 - largest_hole = vma->vm_start - addr;
24504 + largest_hole = vma->vm_start - addr;
24505
24506 /* try just below the current vma->vm_start */
24507 - addr = (vma->vm_start - len) & huge_page_mask(h);
24508 - } while (len <= vma->vm_start);
24509 + addr = skip_heap_stack_gap(vma, len);
24510 + } while (!IS_ERR_VALUE(addr));
24511
24512 fail:
24513 /*
24514 - * if hint left us with no space for the requested
24515 - * mapping then try again:
24516 - */
24517 - if (start_addr != base) {
24518 - mm->free_area_cache = base;
24519 - largest_hole = 0;
24520 - goto try_again;
24521 - }
24522 - /*
24523 * A failed mmap() very likely causes application failure,
24524 * so fall back to the bottom-up function here. This scenario
24525 * can happen with large stack limits and large mmap()
24526 * allocations.
24527 */
24528 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24529 +
24530 +#ifdef CONFIG_PAX_SEGMEXEC
24531 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24532 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24533 + else
24534 +#endif
24535 +
24536 + mm->mmap_base = TASK_UNMAPPED_BASE;
24537 +
24538 +#ifdef CONFIG_PAX_RANDMMAP
24539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24540 + mm->mmap_base += mm->delta_mmap;
24541 +#endif
24542 +
24543 + mm->free_area_cache = mm->mmap_base;
24544 mm->cached_hole_size = ~0UL;
24545 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24546 len, pgoff, flags);
24547 @@ -393,6 +404,7 @@ fail:
24548 /*
24549 * Restore the topdown base:
24550 */
24551 + mm->mmap_base = base;
24552 mm->free_area_cache = base;
24553 mm->cached_hole_size = ~0UL;
24554
24555 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24556 struct hstate *h = hstate_file(file);
24557 struct mm_struct *mm = current->mm;
24558 struct vm_area_struct *vma;
24559 + unsigned long pax_task_size = TASK_SIZE;
24560
24561 if (len & ~huge_page_mask(h))
24562 return -EINVAL;
24563 - if (len > TASK_SIZE)
24564 +
24565 +#ifdef CONFIG_PAX_SEGMEXEC
24566 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24567 + pax_task_size = SEGMEXEC_TASK_SIZE;
24568 +#endif
24569 +
24570 + pax_task_size -= PAGE_SIZE;
24571 +
24572 + if (len > pax_task_size)
24573 return -ENOMEM;
24574
24575 if (flags & MAP_FIXED) {
24576 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24577 if (addr) {
24578 addr = ALIGN(addr, huge_page_size(h));
24579 vma = find_vma(mm, addr);
24580 - if (TASK_SIZE - len >= addr &&
24581 - (!vma || addr + len <= vma->vm_start))
24582 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24583 return addr;
24584 }
24585 if (mm->get_unmapped_area == arch_get_unmapped_area)
24586 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24587 index ab1f6a9..e16d764 100644
24588 --- a/arch/x86/mm/init.c
24589 +++ b/arch/x86/mm/init.c
24590 @@ -16,6 +16,8 @@
24591 #include <asm/tlb.h>
24592 #include <asm/proto.h>
24593 #include <asm/dma.h> /* for MAX_DMA_PFN */
24594 +#include <asm/desc.h>
24595 +#include <asm/bios_ebda.h>
24596
24597 unsigned long __initdata pgt_buf_start;
24598 unsigned long __meminitdata pgt_buf_end;
24599 @@ -38,7 +40,7 @@ struct map_range {
24600 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24601 int use_pse, int use_gbpages)
24602 {
24603 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24604 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24605 phys_addr_t base;
24606
24607 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24608 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24609 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24610 * mmio resources as well as potential bios/acpi data regions.
24611 */
24612 +
24613 +#ifdef CONFIG_GRKERNSEC_KMEM
24614 +static unsigned int ebda_start __read_only;
24615 +static unsigned int ebda_end __read_only;
24616 +#endif
24617 +
24618 int devmem_is_allowed(unsigned long pagenr)
24619 {
24620 - if (pagenr < 256)
24621 +#ifdef CONFIG_GRKERNSEC_KMEM
24622 + /* allow BDA */
24623 + if (!pagenr)
24624 return 1;
24625 + /* allow EBDA */
24626 + if (pagenr >= ebda_start && pagenr < ebda_end)
24627 + return 1;
24628 +#else
24629 + if (!pagenr)
24630 + return 1;
24631 +#ifdef CONFIG_VM86
24632 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24633 + return 1;
24634 +#endif
24635 +#endif
24636 +
24637 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24638 + return 1;
24639 +#ifdef CONFIG_GRKERNSEC_KMEM
24640 + /* throw out everything else below 1MB */
24641 + if (pagenr <= 256)
24642 + return 0;
24643 +#endif
24644 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24645 return 0;
24646 if (!page_is_ram(pagenr))
24647 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24648 #endif
24649 }
24650
24651 +#ifdef CONFIG_GRKERNSEC_KMEM
24652 +static inline void gr_init_ebda(void)
24653 +{
24654 + unsigned int ebda_addr;
24655 + unsigned int ebda_size = 0;
24656 +
24657 + ebda_addr = get_bios_ebda();
24658 + if (ebda_addr) {
24659 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24660 + ebda_size <<= 10;
24661 + }
24662 + if (ebda_addr && ebda_size) {
24663 + ebda_start = ebda_addr >> PAGE_SHIFT;
24664 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24665 + } else {
24666 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24667 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24668 + }
24669 +}
24670 +#else
24671 +static inline void gr_init_ebda(void) { }
24672 +#endif
24673 +
24674 void free_initmem(void)
24675 {
24676 +#ifdef CONFIG_PAX_KERNEXEC
24677 +#ifdef CONFIG_X86_32
24678 + /* PaX: limit KERNEL_CS to actual size */
24679 + unsigned long addr, limit;
24680 + struct desc_struct d;
24681 + int cpu;
24682 +#else
24683 + pgd_t *pgd;
24684 + pud_t *pud;
24685 + pmd_t *pmd;
24686 + unsigned long addr, end;
24687 +#endif
24688 +#endif
24689 +
24690 + gr_init_ebda();
24691 +
24692 +#ifdef CONFIG_PAX_KERNEXEC
24693 +#ifdef CONFIG_X86_32
24694 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24695 + limit = (limit - 1UL) >> PAGE_SHIFT;
24696 +
24697 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24698 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24699 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24700 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24701 + }
24702 +
24703 + /* PaX: make KERNEL_CS read-only */
24704 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24705 + if (!paravirt_enabled())
24706 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24707 +/*
24708 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24709 + pgd = pgd_offset_k(addr);
24710 + pud = pud_offset(pgd, addr);
24711 + pmd = pmd_offset(pud, addr);
24712 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24713 + }
24714 +*/
24715 +#ifdef CONFIG_X86_PAE
24716 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24717 +/*
24718 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24719 + pgd = pgd_offset_k(addr);
24720 + pud = pud_offset(pgd, addr);
24721 + pmd = pmd_offset(pud, addr);
24722 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24723 + }
24724 +*/
24725 +#endif
24726 +
24727 +#ifdef CONFIG_MODULES
24728 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24729 +#endif
24730 +
24731 +#else
24732 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24733 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24734 + pgd = pgd_offset_k(addr);
24735 + pud = pud_offset(pgd, addr);
24736 + pmd = pmd_offset(pud, addr);
24737 + if (!pmd_present(*pmd))
24738 + continue;
24739 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24740 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24741 + else
24742 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24743 + }
24744 +
24745 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24746 + end = addr + KERNEL_IMAGE_SIZE;
24747 + for (; addr < end; addr += PMD_SIZE) {
24748 + pgd = pgd_offset_k(addr);
24749 + pud = pud_offset(pgd, addr);
24750 + pmd = pmd_offset(pud, addr);
24751 + if (!pmd_present(*pmd))
24752 + continue;
24753 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24754 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24755 + }
24756 +#endif
24757 +
24758 + flush_tlb_all();
24759 +#endif
24760 +
24761 free_init_pages("unused kernel memory",
24762 (unsigned long)(&__init_begin),
24763 (unsigned long)(&__init_end));
24764 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24765 index 575d86f..4987469 100644
24766 --- a/arch/x86/mm/init_32.c
24767 +++ b/arch/x86/mm/init_32.c
24768 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24769 }
24770
24771 /*
24772 - * Creates a middle page table and puts a pointer to it in the
24773 - * given global directory entry. This only returns the gd entry
24774 - * in non-PAE compilation mode, since the middle layer is folded.
24775 - */
24776 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24777 -{
24778 - pud_t *pud;
24779 - pmd_t *pmd_table;
24780 -
24781 -#ifdef CONFIG_X86_PAE
24782 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24783 - if (after_bootmem)
24784 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24785 - else
24786 - pmd_table = (pmd_t *)alloc_low_page();
24787 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24788 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24789 - pud = pud_offset(pgd, 0);
24790 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24791 -
24792 - return pmd_table;
24793 - }
24794 -#endif
24795 - pud = pud_offset(pgd, 0);
24796 - pmd_table = pmd_offset(pud, 0);
24797 -
24798 - return pmd_table;
24799 -}
24800 -
24801 -/*
24802 * Create a page table and place a pointer to it in a middle page
24803 * directory entry:
24804 */
24805 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24806 page_table = (pte_t *)alloc_low_page();
24807
24808 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24809 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24810 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24811 +#else
24812 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24813 +#endif
24814 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24815 }
24816
24817 return pte_offset_kernel(pmd, 0);
24818 }
24819
24820 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24821 +{
24822 + pud_t *pud;
24823 + pmd_t *pmd_table;
24824 +
24825 + pud = pud_offset(pgd, 0);
24826 + pmd_table = pmd_offset(pud, 0);
24827 +
24828 + return pmd_table;
24829 +}
24830 +
24831 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24832 {
24833 int pgd_idx = pgd_index(vaddr);
24834 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24835 int pgd_idx, pmd_idx;
24836 unsigned long vaddr;
24837 pgd_t *pgd;
24838 + pud_t *pud;
24839 pmd_t *pmd;
24840 pte_t *pte = NULL;
24841
24842 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24843 pgd = pgd_base + pgd_idx;
24844
24845 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24846 - pmd = one_md_table_init(pgd);
24847 - pmd = pmd + pmd_index(vaddr);
24848 + pud = pud_offset(pgd, vaddr);
24849 + pmd = pmd_offset(pud, vaddr);
24850 +
24851 +#ifdef CONFIG_X86_PAE
24852 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24853 +#endif
24854 +
24855 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24856 pmd++, pmd_idx++) {
24857 pte = page_table_kmap_check(one_page_table_init(pmd),
24858 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24859 }
24860 }
24861
24862 -static inline int is_kernel_text(unsigned long addr)
24863 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24864 {
24865 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24866 - return 1;
24867 - return 0;
24868 + if ((start > ktla_ktva((unsigned long)_etext) ||
24869 + end <= ktla_ktva((unsigned long)_stext)) &&
24870 + (start > ktla_ktva((unsigned long)_einittext) ||
24871 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24872 +
24873 +#ifdef CONFIG_ACPI_SLEEP
24874 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24875 +#endif
24876 +
24877 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24878 + return 0;
24879 + return 1;
24880 }
24881
24882 /*
24883 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24884 unsigned long last_map_addr = end;
24885 unsigned long start_pfn, end_pfn;
24886 pgd_t *pgd_base = swapper_pg_dir;
24887 - int pgd_idx, pmd_idx, pte_ofs;
24888 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24889 unsigned long pfn;
24890 pgd_t *pgd;
24891 + pud_t *pud;
24892 pmd_t *pmd;
24893 pte_t *pte;
24894 unsigned pages_2m, pages_4k;
24895 @@ -280,8 +281,13 @@ repeat:
24896 pfn = start_pfn;
24897 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24898 pgd = pgd_base + pgd_idx;
24899 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24900 - pmd = one_md_table_init(pgd);
24901 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24902 + pud = pud_offset(pgd, 0);
24903 + pmd = pmd_offset(pud, 0);
24904 +
24905 +#ifdef CONFIG_X86_PAE
24906 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24907 +#endif
24908
24909 if (pfn >= end_pfn)
24910 continue;
24911 @@ -293,14 +299,13 @@ repeat:
24912 #endif
24913 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24914 pmd++, pmd_idx++) {
24915 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24916 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24917
24918 /*
24919 * Map with big pages if possible, otherwise
24920 * create normal page tables:
24921 */
24922 if (use_pse) {
24923 - unsigned int addr2;
24924 pgprot_t prot = PAGE_KERNEL_LARGE;
24925 /*
24926 * first pass will use the same initial
24927 @@ -310,11 +315,7 @@ repeat:
24928 __pgprot(PTE_IDENT_ATTR |
24929 _PAGE_PSE);
24930
24931 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24932 - PAGE_OFFSET + PAGE_SIZE-1;
24933 -
24934 - if (is_kernel_text(addr) ||
24935 - is_kernel_text(addr2))
24936 + if (is_kernel_text(address, address + PMD_SIZE))
24937 prot = PAGE_KERNEL_LARGE_EXEC;
24938
24939 pages_2m++;
24940 @@ -331,7 +332,7 @@ repeat:
24941 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24942 pte += pte_ofs;
24943 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24944 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24945 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24946 pgprot_t prot = PAGE_KERNEL;
24947 /*
24948 * first pass will use the same initial
24949 @@ -339,7 +340,7 @@ repeat:
24950 */
24951 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24952
24953 - if (is_kernel_text(addr))
24954 + if (is_kernel_text(address, address + PAGE_SIZE))
24955 prot = PAGE_KERNEL_EXEC;
24956
24957 pages_4k++;
24958 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24959
24960 pud = pud_offset(pgd, va);
24961 pmd = pmd_offset(pud, va);
24962 - if (!pmd_present(*pmd))
24963 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24964 break;
24965
24966 pte = pte_offset_kernel(pmd, va);
24967 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24968
24969 static void __init pagetable_init(void)
24970 {
24971 - pgd_t *pgd_base = swapper_pg_dir;
24972 -
24973 - permanent_kmaps_init(pgd_base);
24974 + permanent_kmaps_init(swapper_pg_dir);
24975 }
24976
24977 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24978 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24979 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24980
24981 /* user-defined highmem size */
24982 @@ -734,6 +733,12 @@ void __init mem_init(void)
24983
24984 pci_iommu_alloc();
24985
24986 +#ifdef CONFIG_PAX_PER_CPU_PGD
24987 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24988 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24989 + KERNEL_PGD_PTRS);
24990 +#endif
24991 +
24992 #ifdef CONFIG_FLATMEM
24993 BUG_ON(!mem_map);
24994 #endif
24995 @@ -760,7 +765,7 @@ void __init mem_init(void)
24996 reservedpages++;
24997
24998 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24999 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25000 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25001 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25002
25003 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25004 @@ -801,10 +806,10 @@ void __init mem_init(void)
25005 ((unsigned long)&__init_end -
25006 (unsigned long)&__init_begin) >> 10,
25007
25008 - (unsigned long)&_etext, (unsigned long)&_edata,
25009 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25010 + (unsigned long)&_sdata, (unsigned long)&_edata,
25011 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25012
25013 - (unsigned long)&_text, (unsigned long)&_etext,
25014 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25015 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25016
25017 /*
25018 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25019 if (!kernel_set_to_readonly)
25020 return;
25021
25022 + start = ktla_ktva(start);
25023 pr_debug("Set kernel text: %lx - %lx for read write\n",
25024 start, start+size);
25025
25026 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25027 if (!kernel_set_to_readonly)
25028 return;
25029
25030 + start = ktla_ktva(start);
25031 pr_debug("Set kernel text: %lx - %lx for read only\n",
25032 start, start+size);
25033
25034 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25035 unsigned long start = PFN_ALIGN(_text);
25036 unsigned long size = PFN_ALIGN(_etext) - start;
25037
25038 + start = ktla_ktva(start);
25039 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25040 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25041 size >> 10);
25042 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25043 index 2b6b4a3..c17210d 100644
25044 --- a/arch/x86/mm/init_64.c
25045 +++ b/arch/x86/mm/init_64.c
25046 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25047 * around without checking the pgd every time.
25048 */
25049
25050 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25051 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25052 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25053
25054 int force_personality32;
25055 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25056
25057 for (address = start; address <= end; address += PGDIR_SIZE) {
25058 const pgd_t *pgd_ref = pgd_offset_k(address);
25059 +
25060 +#ifdef CONFIG_PAX_PER_CPU_PGD
25061 + unsigned long cpu;
25062 +#else
25063 struct page *page;
25064 +#endif
25065
25066 if (pgd_none(*pgd_ref))
25067 continue;
25068
25069 spin_lock(&pgd_lock);
25070 +
25071 +#ifdef CONFIG_PAX_PER_CPU_PGD
25072 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25073 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25074 +#else
25075 list_for_each_entry(page, &pgd_list, lru) {
25076 pgd_t *pgd;
25077 spinlock_t *pgt_lock;
25078 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25079 /* the pgt_lock only for Xen */
25080 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25081 spin_lock(pgt_lock);
25082 +#endif
25083
25084 if (pgd_none(*pgd))
25085 set_pgd(pgd, *pgd_ref);
25086 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25087 BUG_ON(pgd_page_vaddr(*pgd)
25088 != pgd_page_vaddr(*pgd_ref));
25089
25090 +#ifndef CONFIG_PAX_PER_CPU_PGD
25091 spin_unlock(pgt_lock);
25092 +#endif
25093 +
25094 }
25095 spin_unlock(&pgd_lock);
25096 }
25097 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25098 {
25099 if (pgd_none(*pgd)) {
25100 pud_t *pud = (pud_t *)spp_getpage();
25101 - pgd_populate(&init_mm, pgd, pud);
25102 + pgd_populate_kernel(&init_mm, pgd, pud);
25103 if (pud != pud_offset(pgd, 0))
25104 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25105 pud, pud_offset(pgd, 0));
25106 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25107 {
25108 if (pud_none(*pud)) {
25109 pmd_t *pmd = (pmd_t *) spp_getpage();
25110 - pud_populate(&init_mm, pud, pmd);
25111 + pud_populate_kernel(&init_mm, pud, pmd);
25112 if (pmd != pmd_offset(pud, 0))
25113 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25114 pmd, pmd_offset(pud, 0));
25115 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25116 pmd = fill_pmd(pud, vaddr);
25117 pte = fill_pte(pmd, vaddr);
25118
25119 + pax_open_kernel();
25120 set_pte(pte, new_pte);
25121 + pax_close_kernel();
25122
25123 /*
25124 * It's enough to flush this one mapping.
25125 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25126 pgd = pgd_offset_k((unsigned long)__va(phys));
25127 if (pgd_none(*pgd)) {
25128 pud = (pud_t *) spp_getpage();
25129 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25130 - _PAGE_USER));
25131 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25132 }
25133 pud = pud_offset(pgd, (unsigned long)__va(phys));
25134 if (pud_none(*pud)) {
25135 pmd = (pmd_t *) spp_getpage();
25136 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25137 - _PAGE_USER));
25138 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25139 }
25140 pmd = pmd_offset(pud, phys);
25141 BUG_ON(!pmd_none(*pmd));
25142 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25143 if (pfn >= pgt_buf_top)
25144 panic("alloc_low_page: ran out of memory");
25145
25146 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25147 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25148 clear_page(adr);
25149 *phys = pfn * PAGE_SIZE;
25150 return adr;
25151 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25152
25153 phys = __pa(virt);
25154 left = phys & (PAGE_SIZE - 1);
25155 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25156 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25157 adr = (void *)(((unsigned long)adr) | left);
25158
25159 return adr;
25160 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25161 unmap_low_page(pmd);
25162
25163 spin_lock(&init_mm.page_table_lock);
25164 - pud_populate(&init_mm, pud, __va(pmd_phys));
25165 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25166 spin_unlock(&init_mm.page_table_lock);
25167 }
25168 __flush_tlb_all();
25169 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25170 unmap_low_page(pud);
25171
25172 spin_lock(&init_mm.page_table_lock);
25173 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25174 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25175 spin_unlock(&init_mm.page_table_lock);
25176 pgd_changed = true;
25177 }
25178 @@ -686,6 +700,12 @@ void __init mem_init(void)
25179
25180 pci_iommu_alloc();
25181
25182 +#ifdef CONFIG_PAX_PER_CPU_PGD
25183 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25184 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25185 + KERNEL_PGD_PTRS);
25186 +#endif
25187 +
25188 /* clear_bss() already clear the empty_zero_page */
25189
25190 reservedpages = 0;
25191 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25192 static struct vm_area_struct gate_vma = {
25193 .vm_start = VSYSCALL_START,
25194 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25195 - .vm_page_prot = PAGE_READONLY_EXEC,
25196 - .vm_flags = VM_READ | VM_EXEC
25197 + .vm_page_prot = PAGE_READONLY,
25198 + .vm_flags = VM_READ
25199 };
25200
25201 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25202 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25203
25204 const char *arch_vma_name(struct vm_area_struct *vma)
25205 {
25206 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25207 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25208 return "[vdso]";
25209 if (vma == &gate_vma)
25210 return "[vsyscall]";
25211 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25212 index 7b179b4..6bd1777 100644
25213 --- a/arch/x86/mm/iomap_32.c
25214 +++ b/arch/x86/mm/iomap_32.c
25215 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25216 type = kmap_atomic_idx_push();
25217 idx = type + KM_TYPE_NR * smp_processor_id();
25218 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25219 +
25220 + pax_open_kernel();
25221 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25222 + pax_close_kernel();
25223 +
25224 arch_flush_lazy_mmu_mode();
25225
25226 return (void *)vaddr;
25227 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25228 index 78fe3f1..8293b6f 100644
25229 --- a/arch/x86/mm/ioremap.c
25230 +++ b/arch/x86/mm/ioremap.c
25231 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25232 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25233 int is_ram = page_is_ram(pfn);
25234
25235 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25236 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25237 return NULL;
25238 WARN_ON_ONCE(is_ram);
25239 }
25240 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25241
25242 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25243 if (page_is_ram(start >> PAGE_SHIFT))
25244 +#ifdef CONFIG_HIGHMEM
25245 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25246 +#endif
25247 return __va(phys);
25248
25249 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25250 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25251 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25252
25253 static __initdata int after_paging_init;
25254 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25255 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25256
25257 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25258 {
25259 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25260 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25261
25262 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25263 - memset(bm_pte, 0, sizeof(bm_pte));
25264 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25265 + pmd_populate_user(&init_mm, pmd, bm_pte);
25266
25267 /*
25268 * The boot-ioremap range spans multiple pmds, for which
25269 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25270 index d87dd6d..bf3fa66 100644
25271 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25272 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25273 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25274 * memory (e.g. tracked pages)? For now, we need this to avoid
25275 * invoking kmemcheck for PnP BIOS calls.
25276 */
25277 - if (regs->flags & X86_VM_MASK)
25278 + if (v8086_mode(regs))
25279 return false;
25280 - if (regs->cs != __KERNEL_CS)
25281 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25282 return false;
25283
25284 pte = kmemcheck_pte_lookup(address);
25285 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25286 index 845df68..1d8d29f 100644
25287 --- a/arch/x86/mm/mmap.c
25288 +++ b/arch/x86/mm/mmap.c
25289 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25290 * Leave an at least ~128 MB hole with possible stack randomization.
25291 */
25292 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25293 -#define MAX_GAP (TASK_SIZE/6*5)
25294 +#define MAX_GAP (pax_task_size/6*5)
25295
25296 static int mmap_is_legacy(void)
25297 {
25298 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25299 return rnd << PAGE_SHIFT;
25300 }
25301
25302 -static unsigned long mmap_base(void)
25303 +static unsigned long mmap_base(struct mm_struct *mm)
25304 {
25305 unsigned long gap = rlimit(RLIMIT_STACK);
25306 + unsigned long pax_task_size = TASK_SIZE;
25307 +
25308 +#ifdef CONFIG_PAX_SEGMEXEC
25309 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25310 + pax_task_size = SEGMEXEC_TASK_SIZE;
25311 +#endif
25312
25313 if (gap < MIN_GAP)
25314 gap = MIN_GAP;
25315 else if (gap > MAX_GAP)
25316 gap = MAX_GAP;
25317
25318 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25319 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25320 }
25321
25322 /*
25323 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25324 * does, but not when emulating X86_32
25325 */
25326 -static unsigned long mmap_legacy_base(void)
25327 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25328 {
25329 - if (mmap_is_ia32())
25330 + if (mmap_is_ia32()) {
25331 +
25332 +#ifdef CONFIG_PAX_SEGMEXEC
25333 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25334 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25335 + else
25336 +#endif
25337 +
25338 return TASK_UNMAPPED_BASE;
25339 - else
25340 + } else
25341 return TASK_UNMAPPED_BASE + mmap_rnd();
25342 }
25343
25344 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25345 void arch_pick_mmap_layout(struct mm_struct *mm)
25346 {
25347 if (mmap_is_legacy()) {
25348 - mm->mmap_base = mmap_legacy_base();
25349 + mm->mmap_base = mmap_legacy_base(mm);
25350 +
25351 +#ifdef CONFIG_PAX_RANDMMAP
25352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25353 + mm->mmap_base += mm->delta_mmap;
25354 +#endif
25355 +
25356 mm->get_unmapped_area = arch_get_unmapped_area;
25357 mm->unmap_area = arch_unmap_area;
25358 } else {
25359 - mm->mmap_base = mmap_base();
25360 + mm->mmap_base = mmap_base(mm);
25361 +
25362 +#ifdef CONFIG_PAX_RANDMMAP
25363 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25364 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25365 +#endif
25366 +
25367 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25368 mm->unmap_area = arch_unmap_area_topdown;
25369 }
25370 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25371 index dc0b727..dc9d71a 100644
25372 --- a/arch/x86/mm/mmio-mod.c
25373 +++ b/arch/x86/mm/mmio-mod.c
25374 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25375 break;
25376 default:
25377 {
25378 - unsigned char *ip = (unsigned char *)instptr;
25379 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25380 my_trace->opcode = MMIO_UNKNOWN_OP;
25381 my_trace->width = 0;
25382 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25383 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25384 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25385 void __iomem *addr)
25386 {
25387 - static atomic_t next_id;
25388 + static atomic_unchecked_t next_id;
25389 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25390 /* These are page-unaligned. */
25391 struct mmiotrace_map map = {
25392 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25393 .private = trace
25394 },
25395 .phys = offset,
25396 - .id = atomic_inc_return(&next_id)
25397 + .id = atomic_inc_return_unchecked(&next_id)
25398 };
25399 map.map_id = trace->id;
25400
25401 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25402 index b008656..773eac2 100644
25403 --- a/arch/x86/mm/pageattr-test.c
25404 +++ b/arch/x86/mm/pageattr-test.c
25405 @@ -36,7 +36,7 @@ enum {
25406
25407 static int pte_testbit(pte_t pte)
25408 {
25409 - return pte_flags(pte) & _PAGE_UNUSED1;
25410 + return pte_flags(pte) & _PAGE_CPA_TEST;
25411 }
25412
25413 struct split_state {
25414 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25415 index a718e0d..45efc32 100644
25416 --- a/arch/x86/mm/pageattr.c
25417 +++ b/arch/x86/mm/pageattr.c
25418 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25419 */
25420 #ifdef CONFIG_PCI_BIOS
25421 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25422 - pgprot_val(forbidden) |= _PAGE_NX;
25423 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25424 #endif
25425
25426 /*
25427 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25428 * Does not cover __inittext since that is gone later on. On
25429 * 64bit we do not enforce !NX on the low mapping
25430 */
25431 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25432 - pgprot_val(forbidden) |= _PAGE_NX;
25433 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25434 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25435
25436 +#ifdef CONFIG_DEBUG_RODATA
25437 /*
25438 * The .rodata section needs to be read-only. Using the pfn
25439 * catches all aliases.
25440 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25441 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25442 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25443 pgprot_val(forbidden) |= _PAGE_RW;
25444 +#endif
25445
25446 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25447 /*
25448 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25449 }
25450 #endif
25451
25452 +#ifdef CONFIG_PAX_KERNEXEC
25453 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25454 + pgprot_val(forbidden) |= _PAGE_RW;
25455 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25456 + }
25457 +#endif
25458 +
25459 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25460
25461 return prot;
25462 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25463 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25464 {
25465 /* change init_mm */
25466 + pax_open_kernel();
25467 set_pte_atomic(kpte, pte);
25468 +
25469 #ifdef CONFIG_X86_32
25470 if (!SHARED_KERNEL_PMD) {
25471 +
25472 +#ifdef CONFIG_PAX_PER_CPU_PGD
25473 + unsigned long cpu;
25474 +#else
25475 struct page *page;
25476 +#endif
25477
25478 +#ifdef CONFIG_PAX_PER_CPU_PGD
25479 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25480 + pgd_t *pgd = get_cpu_pgd(cpu);
25481 +#else
25482 list_for_each_entry(page, &pgd_list, lru) {
25483 - pgd_t *pgd;
25484 + pgd_t *pgd = (pgd_t *)page_address(page);
25485 +#endif
25486 +
25487 pud_t *pud;
25488 pmd_t *pmd;
25489
25490 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25491 + pgd += pgd_index(address);
25492 pud = pud_offset(pgd, address);
25493 pmd = pmd_offset(pud, address);
25494 set_pte_atomic((pte_t *)pmd, pte);
25495 }
25496 }
25497 #endif
25498 + pax_close_kernel();
25499 }
25500
25501 static int
25502 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25503 index 3d68ef6..7f69136 100644
25504 --- a/arch/x86/mm/pat.c
25505 +++ b/arch/x86/mm/pat.c
25506 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25507
25508 if (!entry) {
25509 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25510 - current->comm, current->pid, start, end - 1);
25511 + current->comm, task_pid_nr(current), start, end - 1);
25512 return -EINVAL;
25513 }
25514
25515 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25516
25517 while (cursor < to) {
25518 if (!devmem_is_allowed(pfn)) {
25519 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25520 - current->comm, from, to - 1);
25521 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25522 + current->comm, from, to - 1, cursor);
25523 return 0;
25524 }
25525 cursor += PAGE_SIZE;
25526 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25527 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25528 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25529 "for [mem %#010Lx-%#010Lx]\n",
25530 - current->comm, current->pid,
25531 + current->comm, task_pid_nr(current),
25532 cattr_name(flags),
25533 base, (unsigned long long)(base + size-1));
25534 return -EINVAL;
25535 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25536 flags = lookup_memtype(paddr);
25537 if (want_flags != flags) {
25538 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25539 - current->comm, current->pid,
25540 + current->comm, task_pid_nr(current),
25541 cattr_name(want_flags),
25542 (unsigned long long)paddr,
25543 (unsigned long long)(paddr + size - 1),
25544 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25545 free_memtype(paddr, paddr + size);
25546 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25547 " for [mem %#010Lx-%#010Lx], got %s\n",
25548 - current->comm, current->pid,
25549 + current->comm, task_pid_nr(current),
25550 cattr_name(want_flags),
25551 (unsigned long long)paddr,
25552 (unsigned long long)(paddr + size - 1),
25553 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25554 index 9f0614d..92ae64a 100644
25555 --- a/arch/x86/mm/pf_in.c
25556 +++ b/arch/x86/mm/pf_in.c
25557 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25558 int i;
25559 enum reason_type rv = OTHERS;
25560
25561 - p = (unsigned char *)ins_addr;
25562 + p = (unsigned char *)ktla_ktva(ins_addr);
25563 p += skip_prefix(p, &prf);
25564 p += get_opcode(p, &opcode);
25565
25566 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25567 struct prefix_bits prf;
25568 int i;
25569
25570 - p = (unsigned char *)ins_addr;
25571 + p = (unsigned char *)ktla_ktva(ins_addr);
25572 p += skip_prefix(p, &prf);
25573 p += get_opcode(p, &opcode);
25574
25575 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25576 struct prefix_bits prf;
25577 int i;
25578
25579 - p = (unsigned char *)ins_addr;
25580 + p = (unsigned char *)ktla_ktva(ins_addr);
25581 p += skip_prefix(p, &prf);
25582 p += get_opcode(p, &opcode);
25583
25584 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25585 struct prefix_bits prf;
25586 int i;
25587
25588 - p = (unsigned char *)ins_addr;
25589 + p = (unsigned char *)ktla_ktva(ins_addr);
25590 p += skip_prefix(p, &prf);
25591 p += get_opcode(p, &opcode);
25592 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25593 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25594 struct prefix_bits prf;
25595 int i;
25596
25597 - p = (unsigned char *)ins_addr;
25598 + p = (unsigned char *)ktla_ktva(ins_addr);
25599 p += skip_prefix(p, &prf);
25600 p += get_opcode(p, &opcode);
25601 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25602 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25603 index 8573b83..4f3ed7e 100644
25604 --- a/arch/x86/mm/pgtable.c
25605 +++ b/arch/x86/mm/pgtable.c
25606 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25607 list_del(&page->lru);
25608 }
25609
25610 -#define UNSHARED_PTRS_PER_PGD \
25611 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25612 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25613 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25614
25615 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25616 +{
25617 + unsigned int count = USER_PGD_PTRS;
25618
25619 + while (count--)
25620 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25621 +}
25622 +#endif
25623 +
25624 +#ifdef CONFIG_PAX_PER_CPU_PGD
25625 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25626 +{
25627 + unsigned int count = USER_PGD_PTRS;
25628 +
25629 + while (count--) {
25630 + pgd_t pgd;
25631 +
25632 +#ifdef CONFIG_X86_64
25633 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25634 +#else
25635 + pgd = *src++;
25636 +#endif
25637 +
25638 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25639 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25640 +#endif
25641 +
25642 + *dst++ = pgd;
25643 + }
25644 +
25645 +}
25646 +#endif
25647 +
25648 +#ifdef CONFIG_X86_64
25649 +#define pxd_t pud_t
25650 +#define pyd_t pgd_t
25651 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25652 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25653 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25654 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25655 +#define PYD_SIZE PGDIR_SIZE
25656 +#else
25657 +#define pxd_t pmd_t
25658 +#define pyd_t pud_t
25659 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25660 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25661 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25662 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25663 +#define PYD_SIZE PUD_SIZE
25664 +#endif
25665 +
25666 +#ifdef CONFIG_PAX_PER_CPU_PGD
25667 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25668 +static inline void pgd_dtor(pgd_t *pgd) {}
25669 +#else
25670 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25671 {
25672 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25673 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25674 pgd_list_del(pgd);
25675 spin_unlock(&pgd_lock);
25676 }
25677 +#endif
25678
25679 /*
25680 * List of all pgd's needed for non-PAE so it can invalidate entries
25681 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25682 * -- wli
25683 */
25684
25685 -#ifdef CONFIG_X86_PAE
25686 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25687 /*
25688 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25689 * updating the top-level pagetable entries to guarantee the
25690 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25691 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25692 * and initialize the kernel pmds here.
25693 */
25694 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25695 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25696
25697 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25698 {
25699 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25700 */
25701 flush_tlb_mm(mm);
25702 }
25703 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25704 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25705 #else /* !CONFIG_X86_PAE */
25706
25707 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25708 -#define PREALLOCATED_PMDS 0
25709 +#define PREALLOCATED_PXDS 0
25710
25711 #endif /* CONFIG_X86_PAE */
25712
25713 -static void free_pmds(pmd_t *pmds[])
25714 +static void free_pxds(pxd_t *pxds[])
25715 {
25716 int i;
25717
25718 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25719 - if (pmds[i])
25720 - free_page((unsigned long)pmds[i]);
25721 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25722 + if (pxds[i])
25723 + free_page((unsigned long)pxds[i]);
25724 }
25725
25726 -static int preallocate_pmds(pmd_t *pmds[])
25727 +static int preallocate_pxds(pxd_t *pxds[])
25728 {
25729 int i;
25730 bool failed = false;
25731
25732 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25733 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25734 - if (pmd == NULL)
25735 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25736 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25737 + if (pxd == NULL)
25738 failed = true;
25739 - pmds[i] = pmd;
25740 + pxds[i] = pxd;
25741 }
25742
25743 if (failed) {
25744 - free_pmds(pmds);
25745 + free_pxds(pxds);
25746 return -ENOMEM;
25747 }
25748
25749 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25750 * preallocate which never got a corresponding vma will need to be
25751 * freed manually.
25752 */
25753 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25754 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25755 {
25756 int i;
25757
25758 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25759 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25760 pgd_t pgd = pgdp[i];
25761
25762 if (pgd_val(pgd) != 0) {
25763 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25764 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25765
25766 - pgdp[i] = native_make_pgd(0);
25767 + set_pgd(pgdp + i, native_make_pgd(0));
25768
25769 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25770 - pmd_free(mm, pmd);
25771 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25772 + pxd_free(mm, pxd);
25773 }
25774 }
25775 }
25776
25777 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25778 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25779 {
25780 - pud_t *pud;
25781 + pyd_t *pyd;
25782 unsigned long addr;
25783 int i;
25784
25785 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25786 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25787 return;
25788
25789 - pud = pud_offset(pgd, 0);
25790 +#ifdef CONFIG_X86_64
25791 + pyd = pyd_offset(mm, 0L);
25792 +#else
25793 + pyd = pyd_offset(pgd, 0L);
25794 +#endif
25795
25796 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25797 - i++, pud++, addr += PUD_SIZE) {
25798 - pmd_t *pmd = pmds[i];
25799 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25800 + i++, pyd++, addr += PYD_SIZE) {
25801 + pxd_t *pxd = pxds[i];
25802
25803 if (i >= KERNEL_PGD_BOUNDARY)
25804 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25805 - sizeof(pmd_t) * PTRS_PER_PMD);
25806 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25807 + sizeof(pxd_t) * PTRS_PER_PMD);
25808
25809 - pud_populate(mm, pud, pmd);
25810 + pyd_populate(mm, pyd, pxd);
25811 }
25812 }
25813
25814 pgd_t *pgd_alloc(struct mm_struct *mm)
25815 {
25816 pgd_t *pgd;
25817 - pmd_t *pmds[PREALLOCATED_PMDS];
25818 + pxd_t *pxds[PREALLOCATED_PXDS];
25819
25820 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25821
25822 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25823
25824 mm->pgd = pgd;
25825
25826 - if (preallocate_pmds(pmds) != 0)
25827 + if (preallocate_pxds(pxds) != 0)
25828 goto out_free_pgd;
25829
25830 if (paravirt_pgd_alloc(mm) != 0)
25831 - goto out_free_pmds;
25832 + goto out_free_pxds;
25833
25834 /*
25835 * Make sure that pre-populating the pmds is atomic with
25836 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25837 spin_lock(&pgd_lock);
25838
25839 pgd_ctor(mm, pgd);
25840 - pgd_prepopulate_pmd(mm, pgd, pmds);
25841 + pgd_prepopulate_pxd(mm, pgd, pxds);
25842
25843 spin_unlock(&pgd_lock);
25844
25845 return pgd;
25846
25847 -out_free_pmds:
25848 - free_pmds(pmds);
25849 +out_free_pxds:
25850 + free_pxds(pxds);
25851 out_free_pgd:
25852 free_page((unsigned long)pgd);
25853 out:
25854 @@ -295,7 +356,7 @@ out:
25855
25856 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25857 {
25858 - pgd_mop_up_pmds(mm, pgd);
25859 + pgd_mop_up_pxds(mm, pgd);
25860 pgd_dtor(pgd);
25861 paravirt_pgd_free(mm, pgd);
25862 free_page((unsigned long)pgd);
25863 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25864 index a69bcb8..19068ab 100644
25865 --- a/arch/x86/mm/pgtable_32.c
25866 +++ b/arch/x86/mm/pgtable_32.c
25867 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25868 return;
25869 }
25870 pte = pte_offset_kernel(pmd, vaddr);
25871 +
25872 + pax_open_kernel();
25873 if (pte_val(pteval))
25874 set_pte_at(&init_mm, vaddr, pte, pteval);
25875 else
25876 pte_clear(&init_mm, vaddr, pte);
25877 + pax_close_kernel();
25878
25879 /*
25880 * It's enough to flush this one mapping.
25881 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25882 index 410531d..0f16030 100644
25883 --- a/arch/x86/mm/setup_nx.c
25884 +++ b/arch/x86/mm/setup_nx.c
25885 @@ -5,8 +5,10 @@
25886 #include <asm/pgtable.h>
25887 #include <asm/proto.h>
25888
25889 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25890 static int disable_nx __cpuinitdata;
25891
25892 +#ifndef CONFIG_PAX_PAGEEXEC
25893 /*
25894 * noexec = on|off
25895 *
25896 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25897 return 0;
25898 }
25899 early_param("noexec", noexec_setup);
25900 +#endif
25901 +
25902 +#endif
25903
25904 void __cpuinit x86_configure_nx(void)
25905 {
25906 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25907 if (cpu_has_nx && !disable_nx)
25908 __supported_pte_mask |= _PAGE_NX;
25909 else
25910 +#endif
25911 __supported_pte_mask &= ~_PAGE_NX;
25912 }
25913
25914 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25915 index 613cd83..3a21f1c 100644
25916 --- a/arch/x86/mm/tlb.c
25917 +++ b/arch/x86/mm/tlb.c
25918 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25919 BUG();
25920 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25921 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25922 +
25923 +#ifndef CONFIG_PAX_PER_CPU_PGD
25924 load_cr3(swapper_pg_dir);
25925 +#endif
25926 +
25927 }
25928 }
25929 EXPORT_SYMBOL_GPL(leave_mm);
25930 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25931 index 877b9a1..a8ecf42 100644
25932 --- a/arch/x86/net/bpf_jit.S
25933 +++ b/arch/x86/net/bpf_jit.S
25934 @@ -9,6 +9,7 @@
25935 */
25936 #include <linux/linkage.h>
25937 #include <asm/dwarf2.h>
25938 +#include <asm/alternative-asm.h>
25939
25940 /*
25941 * Calling convention :
25942 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25943 jle bpf_slow_path_word
25944 mov (SKBDATA,%rsi),%eax
25945 bswap %eax /* ntohl() */
25946 + pax_force_retaddr
25947 ret
25948
25949 sk_load_half:
25950 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25951 jle bpf_slow_path_half
25952 movzwl (SKBDATA,%rsi),%eax
25953 rol $8,%ax # ntohs()
25954 + pax_force_retaddr
25955 ret
25956
25957 sk_load_byte:
25958 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25959 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25960 jle bpf_slow_path_byte
25961 movzbl (SKBDATA,%rsi),%eax
25962 + pax_force_retaddr
25963 ret
25964
25965 /**
25966 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25967 movzbl (SKBDATA,%rsi),%ebx
25968 and $15,%bl
25969 shl $2,%bl
25970 + pax_force_retaddr
25971 ret
25972
25973 /* rsi contains offset and can be scratched */
25974 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25975 js bpf_error
25976 mov -12(%rbp),%eax
25977 bswap %eax
25978 + pax_force_retaddr
25979 ret
25980
25981 bpf_slow_path_half:
25982 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25983 mov -12(%rbp),%ax
25984 rol $8,%ax
25985 movzwl %ax,%eax
25986 + pax_force_retaddr
25987 ret
25988
25989 bpf_slow_path_byte:
25990 bpf_slow_path_common(1)
25991 js bpf_error
25992 movzbl -12(%rbp),%eax
25993 + pax_force_retaddr
25994 ret
25995
25996 bpf_slow_path_byte_msh:
25997 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25998 and $15,%al
25999 shl $2,%al
26000 xchg %eax,%ebx
26001 + pax_force_retaddr
26002 ret
26003
26004 #define sk_negative_common(SIZE) \
26005 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26006 sk_negative_common(4)
26007 mov (%rax), %eax
26008 bswap %eax
26009 + pax_force_retaddr
26010 ret
26011
26012 bpf_slow_path_half_neg:
26013 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26014 mov (%rax),%ax
26015 rol $8,%ax
26016 movzwl %ax,%eax
26017 + pax_force_retaddr
26018 ret
26019
26020 bpf_slow_path_byte_neg:
26021 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26022 .globl sk_load_byte_negative_offset
26023 sk_negative_common(1)
26024 movzbl (%rax), %eax
26025 + pax_force_retaddr
26026 ret
26027
26028 bpf_slow_path_byte_msh_neg:
26029 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26030 and $15,%al
26031 shl $2,%al
26032 xchg %eax,%ebx
26033 + pax_force_retaddr
26034 ret
26035
26036 bpf_error:
26037 @@ -197,4 +210,5 @@ bpf_error:
26038 xor %eax,%eax
26039 mov -8(%rbp),%rbx
26040 leaveq
26041 + pax_force_retaddr
26042 ret
26043 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26044 index 33643a8..8e44870 100644
26045 --- a/arch/x86/net/bpf_jit_comp.c
26046 +++ b/arch/x86/net/bpf_jit_comp.c
26047 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26048 set_fs(old_fs);
26049 }
26050
26051 +struct bpf_jit_work {
26052 + struct work_struct work;
26053 + void *image;
26054 +};
26055 +
26056 #define CHOOSE_LOAD_FUNC(K, func) \
26057 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26058
26059 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26060 if (addrs == NULL)
26061 return;
26062
26063 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26064 + if (!fp->work)
26065 + goto out;
26066 +
26067 /* Before first pass, make a rough estimation of addrs[]
26068 * each bpf instruction is translated to less than 64 bytes
26069 */
26070 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26071 break;
26072 default:
26073 /* hmm, too complex filter, give up with jit compiler */
26074 - goto out;
26075 + goto error;
26076 }
26077 ilen = prog - temp;
26078 if (image) {
26079 if (unlikely(proglen + ilen > oldproglen)) {
26080 pr_err("bpb_jit_compile fatal error\n");
26081 - kfree(addrs);
26082 - module_free(NULL, image);
26083 - return;
26084 + module_free_exec(NULL, image);
26085 + goto error;
26086 }
26087 + pax_open_kernel();
26088 memcpy(image + proglen, temp, ilen);
26089 + pax_close_kernel();
26090 }
26091 proglen += ilen;
26092 addrs[i] = proglen;
26093 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26094 break;
26095 }
26096 if (proglen == oldproglen) {
26097 - image = module_alloc(max_t(unsigned int,
26098 - proglen,
26099 - sizeof(struct work_struct)));
26100 + image = module_alloc_exec(proglen);
26101 if (!image)
26102 - goto out;
26103 + goto error;
26104 }
26105 oldproglen = proglen;
26106 }
26107 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26108 bpf_flush_icache(image, image + proglen);
26109
26110 fp->bpf_func = (void *)image;
26111 - }
26112 + } else
26113 +error:
26114 + kfree(fp->work);
26115 +
26116 out:
26117 kfree(addrs);
26118 return;
26119 @@ -652,18 +663,20 @@ out:
26120
26121 static void jit_free_defer(struct work_struct *arg)
26122 {
26123 - module_free(NULL, arg);
26124 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26125 + kfree(arg);
26126 }
26127
26128 /* run from softirq, we must use a work_struct to call
26129 - * module_free() from process context
26130 + * module_free_exec() from process context
26131 */
26132 void bpf_jit_free(struct sk_filter *fp)
26133 {
26134 if (fp->bpf_func != sk_run_filter) {
26135 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26136 + struct work_struct *work = &fp->work->work;
26137
26138 INIT_WORK(work, jit_free_defer);
26139 + fp->work->image = fp->bpf_func;
26140 schedule_work(work);
26141 }
26142 }
26143 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26144 index d6aa6e8..266395a 100644
26145 --- a/arch/x86/oprofile/backtrace.c
26146 +++ b/arch/x86/oprofile/backtrace.c
26147 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26148 struct stack_frame_ia32 *fp;
26149 unsigned long bytes;
26150
26151 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26152 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26153 if (bytes != sizeof(bufhead))
26154 return NULL;
26155
26156 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26157 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26158
26159 oprofile_add_trace(bufhead[0].return_address);
26160
26161 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26162 struct stack_frame bufhead[2];
26163 unsigned long bytes;
26164
26165 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26166 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26167 if (bytes != sizeof(bufhead))
26168 return NULL;
26169
26170 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26171 {
26172 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26173
26174 - if (!user_mode_vm(regs)) {
26175 + if (!user_mode(regs)) {
26176 unsigned long stack = kernel_stack_pointer(regs);
26177 if (depth)
26178 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26179 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26180 index e14a2ff..3fd6b58 100644
26181 --- a/arch/x86/pci/mrst.c
26182 +++ b/arch/x86/pci/mrst.c
26183 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26184 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26185 pci_mmcfg_late_init();
26186 pcibios_enable_irq = mrst_pci_irq_enable;
26187 - pci_root_ops = pci_mrst_ops;
26188 + pax_open_kernel();
26189 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26190 + pax_close_kernel();
26191 pci_soc_mode = 1;
26192 /* Continue with standard init */
26193 return 1;
26194 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26195 index da8fe05..7ee6704 100644
26196 --- a/arch/x86/pci/pcbios.c
26197 +++ b/arch/x86/pci/pcbios.c
26198 @@ -79,50 +79,93 @@ union bios32 {
26199 static struct {
26200 unsigned long address;
26201 unsigned short segment;
26202 -} bios32_indirect = { 0, __KERNEL_CS };
26203 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26204
26205 /*
26206 * Returns the entry point for the given service, NULL on error
26207 */
26208
26209 -static unsigned long bios32_service(unsigned long service)
26210 +static unsigned long __devinit bios32_service(unsigned long service)
26211 {
26212 unsigned char return_code; /* %al */
26213 unsigned long address; /* %ebx */
26214 unsigned long length; /* %ecx */
26215 unsigned long entry; /* %edx */
26216 unsigned long flags;
26217 + struct desc_struct d, *gdt;
26218
26219 local_irq_save(flags);
26220 - __asm__("lcall *(%%edi); cld"
26221 +
26222 + gdt = get_cpu_gdt_table(smp_processor_id());
26223 +
26224 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26225 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26226 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26227 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26228 +
26229 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26230 : "=a" (return_code),
26231 "=b" (address),
26232 "=c" (length),
26233 "=d" (entry)
26234 : "0" (service),
26235 "1" (0),
26236 - "D" (&bios32_indirect));
26237 + "D" (&bios32_indirect),
26238 + "r"(__PCIBIOS_DS)
26239 + : "memory");
26240 +
26241 + pax_open_kernel();
26242 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26243 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26244 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26245 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26246 + pax_close_kernel();
26247 +
26248 local_irq_restore(flags);
26249
26250 switch (return_code) {
26251 - case 0:
26252 - return address + entry;
26253 - case 0x80: /* Not present */
26254 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26255 - return 0;
26256 - default: /* Shouldn't happen */
26257 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26258 - service, return_code);
26259 + case 0: {
26260 + int cpu;
26261 + unsigned char flags;
26262 +
26263 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26264 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26265 + printk(KERN_WARNING "bios32_service: not valid\n");
26266 return 0;
26267 + }
26268 + address = address + PAGE_OFFSET;
26269 + length += 16UL; /* some BIOSs underreport this... */
26270 + flags = 4;
26271 + if (length >= 64*1024*1024) {
26272 + length >>= PAGE_SHIFT;
26273 + flags |= 8;
26274 + }
26275 +
26276 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26277 + gdt = get_cpu_gdt_table(cpu);
26278 + pack_descriptor(&d, address, length, 0x9b, flags);
26279 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26280 + pack_descriptor(&d, address, length, 0x93, flags);
26281 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26282 + }
26283 + return entry;
26284 + }
26285 + case 0x80: /* Not present */
26286 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26287 + return 0;
26288 + default: /* Shouldn't happen */
26289 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26290 + service, return_code);
26291 + return 0;
26292 }
26293 }
26294
26295 static struct {
26296 unsigned long address;
26297 unsigned short segment;
26298 -} pci_indirect = { 0, __KERNEL_CS };
26299 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26300
26301 -static int pci_bios_present;
26302 +static int pci_bios_present __read_only;
26303
26304 static int __devinit check_pcibios(void)
26305 {
26306 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26307 unsigned long flags, pcibios_entry;
26308
26309 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26310 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26311 + pci_indirect.address = pcibios_entry;
26312
26313 local_irq_save(flags);
26314 - __asm__(
26315 - "lcall *(%%edi); cld\n\t"
26316 + __asm__("movw %w6, %%ds\n\t"
26317 + "lcall *%%ss:(%%edi); cld\n\t"
26318 + "push %%ss\n\t"
26319 + "pop %%ds\n\t"
26320 "jc 1f\n\t"
26321 "xor %%ah, %%ah\n"
26322 "1:"
26323 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26324 "=b" (ebx),
26325 "=c" (ecx)
26326 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26327 - "D" (&pci_indirect)
26328 + "D" (&pci_indirect),
26329 + "r" (__PCIBIOS_DS)
26330 : "memory");
26331 local_irq_restore(flags);
26332
26333 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26334
26335 switch (len) {
26336 case 1:
26337 - __asm__("lcall *(%%esi); cld\n\t"
26338 + __asm__("movw %w6, %%ds\n\t"
26339 + "lcall *%%ss:(%%esi); cld\n\t"
26340 + "push %%ss\n\t"
26341 + "pop %%ds\n\t"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26346 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26347 "b" (bx),
26348 "D" ((long)reg),
26349 - "S" (&pci_indirect));
26350 + "S" (&pci_indirect),
26351 + "r" (__PCIBIOS_DS));
26352 /*
26353 * Zero-extend the result beyond 8 bits, do not trust the
26354 * BIOS having done it:
26355 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26356 *value &= 0xff;
26357 break;
26358 case 2:
26359 - __asm__("lcall *(%%esi); cld\n\t"
26360 + __asm__("movw %w6, %%ds\n\t"
26361 + "lcall *%%ss:(%%esi); cld\n\t"
26362 + "push %%ss\n\t"
26363 + "pop %%ds\n\t"
26364 "jc 1f\n\t"
26365 "xor %%ah, %%ah\n"
26366 "1:"
26367 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26368 : "1" (PCIBIOS_READ_CONFIG_WORD),
26369 "b" (bx),
26370 "D" ((long)reg),
26371 - "S" (&pci_indirect));
26372 + "S" (&pci_indirect),
26373 + "r" (__PCIBIOS_DS));
26374 /*
26375 * Zero-extend the result beyond 16 bits, do not trust the
26376 * BIOS having done it:
26377 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26378 *value &= 0xffff;
26379 break;
26380 case 4:
26381 - __asm__("lcall *(%%esi); cld\n\t"
26382 + __asm__("movw %w6, %%ds\n\t"
26383 + "lcall *%%ss:(%%esi); cld\n\t"
26384 + "push %%ss\n\t"
26385 + "pop %%ds\n\t"
26386 "jc 1f\n\t"
26387 "xor %%ah, %%ah\n"
26388 "1:"
26389 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26390 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26391 "b" (bx),
26392 "D" ((long)reg),
26393 - "S" (&pci_indirect));
26394 + "S" (&pci_indirect),
26395 + "r" (__PCIBIOS_DS));
26396 break;
26397 }
26398
26399 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26400
26401 switch (len) {
26402 case 1:
26403 - __asm__("lcall *(%%esi); cld\n\t"
26404 + __asm__("movw %w6, %%ds\n\t"
26405 + "lcall *%%ss:(%%esi); cld\n\t"
26406 + "push %%ss\n\t"
26407 + "pop %%ds\n\t"
26408 "jc 1f\n\t"
26409 "xor %%ah, %%ah\n"
26410 "1:"
26411 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26412 "c" (value),
26413 "b" (bx),
26414 "D" ((long)reg),
26415 - "S" (&pci_indirect));
26416 + "S" (&pci_indirect),
26417 + "r" (__PCIBIOS_DS));
26418 break;
26419 case 2:
26420 - __asm__("lcall *(%%esi); cld\n\t"
26421 + __asm__("movw %w6, %%ds\n\t"
26422 + "lcall *%%ss:(%%esi); cld\n\t"
26423 + "push %%ss\n\t"
26424 + "pop %%ds\n\t"
26425 "jc 1f\n\t"
26426 "xor %%ah, %%ah\n"
26427 "1:"
26428 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26429 "c" (value),
26430 "b" (bx),
26431 "D" ((long)reg),
26432 - "S" (&pci_indirect));
26433 + "S" (&pci_indirect),
26434 + "r" (__PCIBIOS_DS));
26435 break;
26436 case 4:
26437 - __asm__("lcall *(%%esi); cld\n\t"
26438 + __asm__("movw %w6, %%ds\n\t"
26439 + "lcall *%%ss:(%%esi); cld\n\t"
26440 + "push %%ss\n\t"
26441 + "pop %%ds\n\t"
26442 "jc 1f\n\t"
26443 "xor %%ah, %%ah\n"
26444 "1:"
26445 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26446 "c" (value),
26447 "b" (bx),
26448 "D" ((long)reg),
26449 - "S" (&pci_indirect));
26450 + "S" (&pci_indirect),
26451 + "r" (__PCIBIOS_DS));
26452 break;
26453 }
26454
26455 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26456
26457 DBG("PCI: Fetching IRQ routing table... ");
26458 __asm__("push %%es\n\t"
26459 + "movw %w8, %%ds\n\t"
26460 "push %%ds\n\t"
26461 "pop %%es\n\t"
26462 - "lcall *(%%esi); cld\n\t"
26463 + "lcall *%%ss:(%%esi); cld\n\t"
26464 "pop %%es\n\t"
26465 + "push %%ss\n\t"
26466 + "pop %%ds\n"
26467 "jc 1f\n\t"
26468 "xor %%ah, %%ah\n"
26469 "1:"
26470 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26471 "1" (0),
26472 "D" ((long) &opt),
26473 "S" (&pci_indirect),
26474 - "m" (opt)
26475 + "m" (opt),
26476 + "r" (__PCIBIOS_DS)
26477 : "memory");
26478 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26479 if (ret & 0xff00)
26480 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26481 {
26482 int ret;
26483
26484 - __asm__("lcall *(%%esi); cld\n\t"
26485 + __asm__("movw %w5, %%ds\n\t"
26486 + "lcall *%%ss:(%%esi); cld\n\t"
26487 + "push %%ss\n\t"
26488 + "pop %%ds\n"
26489 "jc 1f\n\t"
26490 "xor %%ah, %%ah\n"
26491 "1:"
26492 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26493 : "0" (PCIBIOS_SET_PCI_HW_INT),
26494 "b" ((dev->bus->number << 8) | dev->devfn),
26495 "c" ((irq << 8) | (pin + 10)),
26496 - "S" (&pci_indirect));
26497 + "S" (&pci_indirect),
26498 + "r" (__PCIBIOS_DS));
26499 return !(ret & 0xff00);
26500 }
26501 EXPORT_SYMBOL(pcibios_set_irq_routing);
26502 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26503 index 40e4469..1ab536e 100644
26504 --- a/arch/x86/platform/efi/efi_32.c
26505 +++ b/arch/x86/platform/efi/efi_32.c
26506 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26507 {
26508 struct desc_ptr gdt_descr;
26509
26510 +#ifdef CONFIG_PAX_KERNEXEC
26511 + struct desc_struct d;
26512 +#endif
26513 +
26514 local_irq_save(efi_rt_eflags);
26515
26516 load_cr3(initial_page_table);
26517 __flush_tlb_all();
26518
26519 +#ifdef CONFIG_PAX_KERNEXEC
26520 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26521 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26522 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26523 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26524 +#endif
26525 +
26526 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26527 gdt_descr.size = GDT_SIZE - 1;
26528 load_gdt(&gdt_descr);
26529 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26530 {
26531 struct desc_ptr gdt_descr;
26532
26533 +#ifdef CONFIG_PAX_KERNEXEC
26534 + struct desc_struct d;
26535 +
26536 + memset(&d, 0, sizeof d);
26537 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26538 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26539 +#endif
26540 +
26541 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26542 gdt_descr.size = GDT_SIZE - 1;
26543 load_gdt(&gdt_descr);
26544 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26545 index fbe66e6..eae5e38 100644
26546 --- a/arch/x86/platform/efi/efi_stub_32.S
26547 +++ b/arch/x86/platform/efi/efi_stub_32.S
26548 @@ -6,7 +6,9 @@
26549 */
26550
26551 #include <linux/linkage.h>
26552 +#include <linux/init.h>
26553 #include <asm/page_types.h>
26554 +#include <asm/segment.h>
26555
26556 /*
26557 * efi_call_phys(void *, ...) is a function with variable parameters.
26558 @@ -20,7 +22,7 @@
26559 * service functions will comply with gcc calling convention, too.
26560 */
26561
26562 -.text
26563 +__INIT
26564 ENTRY(efi_call_phys)
26565 /*
26566 * 0. The function can only be called in Linux kernel. So CS has been
26567 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26568 * The mapping of lower virtual memory has been created in prelog and
26569 * epilog.
26570 */
26571 - movl $1f, %edx
26572 - subl $__PAGE_OFFSET, %edx
26573 - jmp *%edx
26574 +#ifdef CONFIG_PAX_KERNEXEC
26575 + movl $(__KERNEXEC_EFI_DS), %edx
26576 + mov %edx, %ds
26577 + mov %edx, %es
26578 + mov %edx, %ss
26579 + addl $2f,(1f)
26580 + ljmp *(1f)
26581 +
26582 +__INITDATA
26583 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26584 +.previous
26585 +
26586 +2:
26587 + subl $2b,(1b)
26588 +#else
26589 + jmp 1f-__PAGE_OFFSET
26590 1:
26591 +#endif
26592
26593 /*
26594 * 2. Now on the top of stack is the return
26595 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26596 * parameter 2, ..., param n. To make things easy, we save the return
26597 * address of efi_call_phys in a global variable.
26598 */
26599 - popl %edx
26600 - movl %edx, saved_return_addr
26601 - /* get the function pointer into ECX*/
26602 - popl %ecx
26603 - movl %ecx, efi_rt_function_ptr
26604 - movl $2f, %edx
26605 - subl $__PAGE_OFFSET, %edx
26606 - pushl %edx
26607 + popl (saved_return_addr)
26608 + popl (efi_rt_function_ptr)
26609
26610 /*
26611 * 3. Clear PG bit in %CR0.
26612 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26613 /*
26614 * 5. Call the physical function.
26615 */
26616 - jmp *%ecx
26617 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26618
26619 -2:
26620 /*
26621 * 6. After EFI runtime service returns, control will return to
26622 * following instruction. We'd better readjust stack pointer first.
26623 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26624 movl %cr0, %edx
26625 orl $0x80000000, %edx
26626 movl %edx, %cr0
26627 - jmp 1f
26628 -1:
26629 +
26630 /*
26631 * 8. Now restore the virtual mode from flat mode by
26632 * adding EIP with PAGE_OFFSET.
26633 */
26634 - movl $1f, %edx
26635 - jmp *%edx
26636 +#ifdef CONFIG_PAX_KERNEXEC
26637 + movl $(__KERNEL_DS), %edx
26638 + mov %edx, %ds
26639 + mov %edx, %es
26640 + mov %edx, %ss
26641 + ljmp $(__KERNEL_CS),$1f
26642 +#else
26643 + jmp 1f+__PAGE_OFFSET
26644 +#endif
26645 1:
26646
26647 /*
26648 * 9. Balance the stack. And because EAX contain the return value,
26649 * we'd better not clobber it.
26650 */
26651 - leal efi_rt_function_ptr, %edx
26652 - movl (%edx), %ecx
26653 - pushl %ecx
26654 + pushl (efi_rt_function_ptr)
26655
26656 /*
26657 - * 10. Push the saved return address onto the stack and return.
26658 + * 10. Return to the saved return address.
26659 */
26660 - leal saved_return_addr, %edx
26661 - movl (%edx), %ecx
26662 - pushl %ecx
26663 - ret
26664 + jmpl *(saved_return_addr)
26665 ENDPROC(efi_call_phys)
26666 .previous
26667
26668 -.data
26669 +__INITDATA
26670 saved_return_addr:
26671 .long 0
26672 efi_rt_function_ptr:
26673 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26674 index 4c07cca..2c8427d 100644
26675 --- a/arch/x86/platform/efi/efi_stub_64.S
26676 +++ b/arch/x86/platform/efi/efi_stub_64.S
26677 @@ -7,6 +7,7 @@
26678 */
26679
26680 #include <linux/linkage.h>
26681 +#include <asm/alternative-asm.h>
26682
26683 #define SAVE_XMM \
26684 mov %rsp, %rax; \
26685 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26686 call *%rdi
26687 addq $32, %rsp
26688 RESTORE_XMM
26689 + pax_force_retaddr 0, 1
26690 ret
26691 ENDPROC(efi_call0)
26692
26693 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26694 call *%rdi
26695 addq $32, %rsp
26696 RESTORE_XMM
26697 + pax_force_retaddr 0, 1
26698 ret
26699 ENDPROC(efi_call1)
26700
26701 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26702 call *%rdi
26703 addq $32, %rsp
26704 RESTORE_XMM
26705 + pax_force_retaddr 0, 1
26706 ret
26707 ENDPROC(efi_call2)
26708
26709 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26710 call *%rdi
26711 addq $32, %rsp
26712 RESTORE_XMM
26713 + pax_force_retaddr 0, 1
26714 ret
26715 ENDPROC(efi_call3)
26716
26717 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26718 call *%rdi
26719 addq $32, %rsp
26720 RESTORE_XMM
26721 + pax_force_retaddr 0, 1
26722 ret
26723 ENDPROC(efi_call4)
26724
26725 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26726 call *%rdi
26727 addq $48, %rsp
26728 RESTORE_XMM
26729 + pax_force_retaddr 0, 1
26730 ret
26731 ENDPROC(efi_call5)
26732
26733 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26734 call *%rdi
26735 addq $48, %rsp
26736 RESTORE_XMM
26737 + pax_force_retaddr 0, 1
26738 ret
26739 ENDPROC(efi_call6)
26740 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26741 index fd41a92..9c33628 100644
26742 --- a/arch/x86/platform/mrst/mrst.c
26743 +++ b/arch/x86/platform/mrst/mrst.c
26744 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26745 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26746 int sfi_mrtc_num;
26747
26748 -static void mrst_power_off(void)
26749 +static __noreturn void mrst_power_off(void)
26750 {
26751 + BUG();
26752 }
26753
26754 -static void mrst_reboot(void)
26755 +static __noreturn void mrst_reboot(void)
26756 {
26757 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26758 + BUG();
26759 }
26760
26761 /* parse all the mtimer info to a static mtimer array */
26762 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26763 index 218cdb1..fd55c08 100644
26764 --- a/arch/x86/power/cpu.c
26765 +++ b/arch/x86/power/cpu.c
26766 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26767 static void fix_processor_context(void)
26768 {
26769 int cpu = smp_processor_id();
26770 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26771 + struct tss_struct *t = init_tss + cpu;
26772
26773 set_tss_desc(cpu, t); /*
26774 * This just modifies memory; should not be
26775 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26776 */
26777
26778 #ifdef CONFIG_X86_64
26779 + pax_open_kernel();
26780 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26781 + pax_close_kernel();
26782
26783 syscall_init(); /* This sets MSR_*STAR and related */
26784 #endif
26785 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26786 index cbca565..bae7133 100644
26787 --- a/arch/x86/realmode/init.c
26788 +++ b/arch/x86/realmode/init.c
26789 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26790 __va(real_mode_header->trampoline_header);
26791
26792 #ifdef CONFIG_X86_32
26793 - trampoline_header->start = __pa(startup_32_smp);
26794 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26795 +
26796 +#ifdef CONFIG_PAX_KERNEXEC
26797 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26798 +#endif
26799 +
26800 + trampoline_header->boot_cs = __BOOT_CS;
26801 trampoline_header->gdt_limit = __BOOT_DS + 7;
26802 trampoline_header->gdt_base = __pa(boot_gdt);
26803 #else
26804 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26805 index 8869287..d577672 100644
26806 --- a/arch/x86/realmode/rm/Makefile
26807 +++ b/arch/x86/realmode/rm/Makefile
26808 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26809 $(call cc-option, -fno-unit-at-a-time)) \
26810 $(call cc-option, -fno-stack-protector) \
26811 $(call cc-option, -mpreferred-stack-boundary=2)
26812 +ifdef CONSTIFY_PLUGIN
26813 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26814 +endif
26815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26816 GCOV_PROFILE := n
26817 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26818 index a28221d..93c40f1 100644
26819 --- a/arch/x86/realmode/rm/header.S
26820 +++ b/arch/x86/realmode/rm/header.S
26821 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26822 #endif
26823 /* APM/BIOS reboot */
26824 .long pa_machine_real_restart_asm
26825 -#ifdef CONFIG_X86_64
26826 +#ifdef CONFIG_X86_32
26827 + .long __KERNEL_CS
26828 +#else
26829 .long __KERNEL32_CS
26830 #endif
26831 END(real_mode_header)
26832 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26833 index c1b2791..f9e31c7 100644
26834 --- a/arch/x86/realmode/rm/trampoline_32.S
26835 +++ b/arch/x86/realmode/rm/trampoline_32.S
26836 @@ -25,6 +25,12 @@
26837 #include <asm/page_types.h>
26838 #include "realmode.h"
26839
26840 +#ifdef CONFIG_PAX_KERNEXEC
26841 +#define ta(X) (X)
26842 +#else
26843 +#define ta(X) (pa_ ## X)
26844 +#endif
26845 +
26846 .text
26847 .code16
26848
26849 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26850
26851 cli # We should be safe anyway
26852
26853 - movl tr_start, %eax # where we need to go
26854 -
26855 movl $0xA5A5A5A5, trampoline_status
26856 # write marker for master knows we're running
26857
26858 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26859 movw $1, %dx # protected mode (PE) bit
26860 lmsw %dx # into protected mode
26861
26862 - ljmpl $__BOOT_CS, $pa_startup_32
26863 + ljmpl *(trampoline_header)
26864
26865 .section ".text32","ax"
26866 .code32
26867 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26868 .balign 8
26869 GLOBAL(trampoline_header)
26870 tr_start: .space 4
26871 - tr_gdt_pad: .space 2
26872 + tr_boot_cs: .space 2
26873 tr_gdt: .space 6
26874 END(trampoline_header)
26875
26876 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26877 index bb360dc..3e5945f 100644
26878 --- a/arch/x86/realmode/rm/trampoline_64.S
26879 +++ b/arch/x86/realmode/rm/trampoline_64.S
26880 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26881 wrmsr
26882
26883 # Enable paging and in turn activate Long Mode
26884 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26885 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26886 movl %eax, %cr0
26887
26888 /*
26889 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26890 index 5a1847d..deccb30 100644
26891 --- a/arch/x86/tools/relocs.c
26892 +++ b/arch/x86/tools/relocs.c
26893 @@ -12,10 +12,13 @@
26894 #include <regex.h>
26895 #include <tools/le_byteshift.h>
26896
26897 +#include "../../../include/generated/autoconf.h"
26898 +
26899 static void die(char *fmt, ...);
26900
26901 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26902 static Elf32_Ehdr ehdr;
26903 +static Elf32_Phdr *phdr;
26904 static unsigned long reloc_count, reloc_idx;
26905 static unsigned long *relocs;
26906 static unsigned long reloc16_count, reloc16_idx;
26907 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26908 }
26909 }
26910
26911 +static void read_phdrs(FILE *fp)
26912 +{
26913 + unsigned int i;
26914 +
26915 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26916 + if (!phdr) {
26917 + die("Unable to allocate %d program headers\n",
26918 + ehdr.e_phnum);
26919 + }
26920 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26921 + die("Seek to %d failed: %s\n",
26922 + ehdr.e_phoff, strerror(errno));
26923 + }
26924 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26925 + die("Cannot read ELF program headers: %s\n",
26926 + strerror(errno));
26927 + }
26928 + for(i = 0; i < ehdr.e_phnum; i++) {
26929 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26930 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26931 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26932 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26933 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26934 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26935 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26936 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26937 + }
26938 +
26939 +}
26940 +
26941 static void read_shdrs(FILE *fp)
26942 {
26943 - int i;
26944 + unsigned int i;
26945 Elf32_Shdr shdr;
26946
26947 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26948 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26949
26950 static void read_strtabs(FILE *fp)
26951 {
26952 - int i;
26953 + unsigned int i;
26954 for (i = 0; i < ehdr.e_shnum; i++) {
26955 struct section *sec = &secs[i];
26956 if (sec->shdr.sh_type != SHT_STRTAB) {
26957 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26958
26959 static void read_symtabs(FILE *fp)
26960 {
26961 - int i,j;
26962 + unsigned int i,j;
26963 for (i = 0; i < ehdr.e_shnum; i++) {
26964 struct section *sec = &secs[i];
26965 if (sec->shdr.sh_type != SHT_SYMTAB) {
26966 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26967 }
26968
26969
26970 -static void read_relocs(FILE *fp)
26971 +static void read_relocs(FILE *fp, int use_real_mode)
26972 {
26973 - int i,j;
26974 + unsigned int i,j;
26975 + uint32_t base;
26976 +
26977 for (i = 0; i < ehdr.e_shnum; i++) {
26978 struct section *sec = &secs[i];
26979 if (sec->shdr.sh_type != SHT_REL) {
26980 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26981 die("Cannot read symbol table: %s\n",
26982 strerror(errno));
26983 }
26984 + base = 0;
26985 +
26986 +#ifdef CONFIG_X86_32
26987 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26988 + if (phdr[j].p_type != PT_LOAD )
26989 + continue;
26990 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
26991 + continue;
26992 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26993 + break;
26994 + }
26995 +#endif
26996 +
26997 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26998 Elf32_Rel *rel = &sec->reltab[j];
26999 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27000 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27001 rel->r_info = elf32_to_cpu(rel->r_info);
27002 }
27003 }
27004 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27005
27006 static void print_absolute_symbols(void)
27007 {
27008 - int i;
27009 + unsigned int i;
27010 printf("Absolute symbols\n");
27011 printf(" Num: Value Size Type Bind Visibility Name\n");
27012 for (i = 0; i < ehdr.e_shnum; i++) {
27013 struct section *sec = &secs[i];
27014 char *sym_strtab;
27015 - int j;
27016 + unsigned int j;
27017
27018 if (sec->shdr.sh_type != SHT_SYMTAB) {
27019 continue;
27020 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27021
27022 static void print_absolute_relocs(void)
27023 {
27024 - int i, printed = 0;
27025 + unsigned int i, printed = 0;
27026
27027 for (i = 0; i < ehdr.e_shnum; i++) {
27028 struct section *sec = &secs[i];
27029 struct section *sec_applies, *sec_symtab;
27030 char *sym_strtab;
27031 Elf32_Sym *sh_symtab;
27032 - int j;
27033 + unsigned int j;
27034 if (sec->shdr.sh_type != SHT_REL) {
27035 continue;
27036 }
27037 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27038 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27039 int use_real_mode)
27040 {
27041 - int i;
27042 + unsigned int i;
27043 /* Walk through the relocations */
27044 for (i = 0; i < ehdr.e_shnum; i++) {
27045 char *sym_strtab;
27046 Elf32_Sym *sh_symtab;
27047 struct section *sec_applies, *sec_symtab;
27048 - int j;
27049 + unsigned int j;
27050 struct section *sec = &secs[i];
27051
27052 if (sec->shdr.sh_type != SHT_REL) {
27053 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27054 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27055 r_type = ELF32_R_TYPE(rel->r_info);
27056
27057 + if (!use_real_mode) {
27058 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27059 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27060 + continue;
27061 +
27062 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27063 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27064 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27065 + continue;
27066 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27067 + continue;
27068 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27069 + continue;
27070 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27071 + continue;
27072 +#endif
27073 + }
27074 +
27075 shn_abs = sym->st_shndx == SHN_ABS;
27076
27077 switch (r_type) {
27078 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27079
27080 static void emit_relocs(int as_text, int use_real_mode)
27081 {
27082 - int i;
27083 + unsigned int i;
27084 /* Count how many relocations I have and allocate space for them. */
27085 reloc_count = 0;
27086 walk_relocs(count_reloc, use_real_mode);
27087 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27088 fname, strerror(errno));
27089 }
27090 read_ehdr(fp);
27091 + read_phdrs(fp);
27092 read_shdrs(fp);
27093 read_strtabs(fp);
27094 read_symtabs(fp);
27095 - read_relocs(fp);
27096 + read_relocs(fp, use_real_mode);
27097 if (show_absolute_syms) {
27098 print_absolute_symbols();
27099 return 0;
27100 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27101 index fd14be1..e3c79c0 100644
27102 --- a/arch/x86/vdso/Makefile
27103 +++ b/arch/x86/vdso/Makefile
27104 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27105 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27106 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27107
27108 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27109 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27110 GCOV_PROFILE := n
27111
27112 #
27113 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27114 index 0faad64..39ef157 100644
27115 --- a/arch/x86/vdso/vdso32-setup.c
27116 +++ b/arch/x86/vdso/vdso32-setup.c
27117 @@ -25,6 +25,7 @@
27118 #include <asm/tlbflush.h>
27119 #include <asm/vdso.h>
27120 #include <asm/proto.h>
27121 +#include <asm/mman.h>
27122
27123 enum {
27124 VDSO_DISABLED = 0,
27125 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27126 void enable_sep_cpu(void)
27127 {
27128 int cpu = get_cpu();
27129 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27130 + struct tss_struct *tss = init_tss + cpu;
27131
27132 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27133 put_cpu();
27134 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27135 gate_vma.vm_start = FIXADDR_USER_START;
27136 gate_vma.vm_end = FIXADDR_USER_END;
27137 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27138 - gate_vma.vm_page_prot = __P101;
27139 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27140
27141 return 0;
27142 }
27143 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27144 if (compat)
27145 addr = VDSO_HIGH_BASE;
27146 else {
27147 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27148 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27149 if (IS_ERR_VALUE(addr)) {
27150 ret = addr;
27151 goto up_fail;
27152 }
27153 }
27154
27155 - current->mm->context.vdso = (void *)addr;
27156 + current->mm->context.vdso = addr;
27157
27158 if (compat_uses_vma || !compat) {
27159 /*
27160 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27161 }
27162
27163 current_thread_info()->sysenter_return =
27164 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27165 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27166
27167 up_fail:
27168 if (ret)
27169 - current->mm->context.vdso = NULL;
27170 + current->mm->context.vdso = 0;
27171
27172 up_write(&mm->mmap_sem);
27173
27174 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27175
27176 const char *arch_vma_name(struct vm_area_struct *vma)
27177 {
27178 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27179 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27180 return "[vdso]";
27181 +
27182 +#ifdef CONFIG_PAX_SEGMEXEC
27183 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27184 + return "[vdso]";
27185 +#endif
27186 +
27187 return NULL;
27188 }
27189
27190 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27191 * Check to see if the corresponding task was created in compat vdso
27192 * mode.
27193 */
27194 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27195 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27196 return &gate_vma;
27197 return NULL;
27198 }
27199 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27200 index 00aaf04..4a26505 100644
27201 --- a/arch/x86/vdso/vma.c
27202 +++ b/arch/x86/vdso/vma.c
27203 @@ -16,8 +16,6 @@
27204 #include <asm/vdso.h>
27205 #include <asm/page.h>
27206
27207 -unsigned int __read_mostly vdso_enabled = 1;
27208 -
27209 extern char vdso_start[], vdso_end[];
27210 extern unsigned short vdso_sync_cpuid;
27211
27212 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27213 * unaligned here as a result of stack start randomization.
27214 */
27215 addr = PAGE_ALIGN(addr);
27216 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27217
27218 return addr;
27219 }
27220 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27221 unsigned size)
27222 {
27223 struct mm_struct *mm = current->mm;
27224 - unsigned long addr;
27225 + unsigned long addr = 0;
27226 int ret;
27227
27228 - if (!vdso_enabled)
27229 - return 0;
27230 -
27231 down_write(&mm->mmap_sem);
27232 +
27233 +#ifdef CONFIG_PAX_RANDMMAP
27234 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27235 +#endif
27236 +
27237 addr = vdso_addr(mm->start_stack, size);
27238 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27239 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27240 if (IS_ERR_VALUE(addr)) {
27241 ret = addr;
27242 goto up_fail;
27243 }
27244
27245 - current->mm->context.vdso = (void *)addr;
27246 + mm->context.vdso = addr;
27247
27248 ret = install_special_mapping(mm, addr, size,
27249 VM_READ|VM_EXEC|
27250 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27251 pages);
27252 - if (ret) {
27253 - current->mm->context.vdso = NULL;
27254 - goto up_fail;
27255 - }
27256 + if (ret)
27257 + mm->context.vdso = 0;
27258
27259 up_fail:
27260 up_write(&mm->mmap_sem);
27261 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27262 vdsox32_size);
27263 }
27264 #endif
27265 -
27266 -static __init int vdso_setup(char *s)
27267 -{
27268 - vdso_enabled = simple_strtoul(s, NULL, 0);
27269 - return 0;
27270 -}
27271 -__setup("vdso=", vdso_setup);
27272 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27273 index c1461de..355f120 100644
27274 --- a/arch/x86/xen/enlighten.c
27275 +++ b/arch/x86/xen/enlighten.c
27276 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27277
27278 struct shared_info xen_dummy_shared_info;
27279
27280 -void *xen_initial_gdt;
27281 -
27282 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27283 __read_mostly int xen_have_vector_callback;
27284 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27285 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27286
27287 static void set_xen_basic_apic_ops(void)
27288 {
27289 - apic->read = xen_apic_read;
27290 - apic->write = xen_apic_write;
27291 - apic->icr_read = xen_apic_icr_read;
27292 - apic->icr_write = xen_apic_icr_write;
27293 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27294 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27295 - apic->set_apic_id = xen_set_apic_id;
27296 - apic->get_apic_id = xen_get_apic_id;
27297 + *(void **)&apic->read = xen_apic_read;
27298 + *(void **)&apic->write = xen_apic_write;
27299 + *(void **)&apic->icr_read = xen_apic_icr_read;
27300 + *(void **)&apic->icr_write = xen_apic_icr_write;
27301 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27302 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27303 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27304 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27305
27306 #ifdef CONFIG_SMP
27307 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27308 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27309 - apic->send_IPI_mask = xen_send_IPI_mask;
27310 - apic->send_IPI_all = xen_send_IPI_all;
27311 - apic->send_IPI_self = xen_send_IPI_self;
27312 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27313 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27314 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27315 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27316 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27317 #endif
27318 }
27319
27320 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27321 #endif
27322 };
27323
27324 -static void xen_reboot(int reason)
27325 +static __noreturn void xen_reboot(int reason)
27326 {
27327 struct sched_shutdown r = { .reason = reason };
27328
27329 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27330 - BUG();
27331 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27332 + BUG();
27333 }
27334
27335 -static void xen_restart(char *msg)
27336 +static __noreturn void xen_restart(char *msg)
27337 {
27338 xen_reboot(SHUTDOWN_reboot);
27339 }
27340
27341 -static void xen_emergency_restart(void)
27342 +static __noreturn void xen_emergency_restart(void)
27343 {
27344 xen_reboot(SHUTDOWN_reboot);
27345 }
27346
27347 -static void xen_machine_halt(void)
27348 +static __noreturn void xen_machine_halt(void)
27349 {
27350 xen_reboot(SHUTDOWN_poweroff);
27351 }
27352
27353 -static void xen_machine_power_off(void)
27354 +static __noreturn void xen_machine_power_off(void)
27355 {
27356 if (pm_power_off)
27357 pm_power_off();
27358 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27359 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27360
27361 /* Work out if we support NX */
27362 - x86_configure_nx();
27363 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27364 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27365 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27366 + unsigned l, h;
27367 +
27368 + __supported_pte_mask |= _PAGE_NX;
27369 + rdmsr(MSR_EFER, l, h);
27370 + l |= EFER_NX;
27371 + wrmsr(MSR_EFER, l, h);
27372 + }
27373 +#endif
27374
27375 xen_setup_features();
27376
27377 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27378
27379 machine_ops = xen_machine_ops;
27380
27381 - /*
27382 - * The only reliable way to retain the initial address of the
27383 - * percpu gdt_page is to remember it here, so we can go and
27384 - * mark it RW later, when the initial percpu area is freed.
27385 - */
27386 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27387 -
27388 xen_smp_init();
27389
27390 #ifdef CONFIG_ACPI_NUMA
27391 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27392 index 5141d80..6c9fb41 100644
27393 --- a/arch/x86/xen/mmu.c
27394 +++ b/arch/x86/xen/mmu.c
27395 @@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27396 convert_pfn_mfn(init_level4_pgt);
27397 convert_pfn_mfn(level3_ident_pgt);
27398 convert_pfn_mfn(level3_kernel_pgt);
27399 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27400 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27401 + convert_pfn_mfn(level3_vmemmap_pgt);
27402
27403 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27404 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27405 @@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27406 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27407 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27408 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27409 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27410 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27411 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27412 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27413 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27414 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27415 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27416
27417 @@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27418 pv_mmu_ops.set_pud = xen_set_pud;
27419 #if PAGETABLE_LEVELS == 4
27420 pv_mmu_ops.set_pgd = xen_set_pgd;
27421 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27422 #endif
27423
27424 /* This will work as long as patching hasn't happened yet
27425 @@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27426 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27427 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27428 .set_pgd = xen_set_pgd_hyper,
27429 + .set_pgd_batched = xen_set_pgd_hyper,
27430
27431 .alloc_pud = xen_alloc_pmd_init,
27432 .release_pud = xen_release_pmd_init,
27433 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27434 index f58dca7..ad21f52 100644
27435 --- a/arch/x86/xen/smp.c
27436 +++ b/arch/x86/xen/smp.c
27437 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27438 {
27439 BUG_ON(smp_processor_id() != 0);
27440 native_smp_prepare_boot_cpu();
27441 -
27442 - /* We've switched to the "real" per-cpu gdt, so make sure the
27443 - old memory can be recycled */
27444 - make_lowmem_page_readwrite(xen_initial_gdt);
27445 -
27446 xen_filter_cpu_maps();
27447 xen_setup_vcpu_info_placement();
27448 }
27449 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27450 gdt = get_cpu_gdt_table(cpu);
27451
27452 ctxt->flags = VGCF_IN_KERNEL;
27453 - ctxt->user_regs.ds = __USER_DS;
27454 - ctxt->user_regs.es = __USER_DS;
27455 + ctxt->user_regs.ds = __KERNEL_DS;
27456 + ctxt->user_regs.es = __KERNEL_DS;
27457 ctxt->user_regs.ss = __KERNEL_DS;
27458 #ifdef CONFIG_X86_32
27459 ctxt->user_regs.fs = __KERNEL_PERCPU;
27460 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27461 + savesegment(gs, ctxt->user_regs.gs);
27462 #else
27463 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27464 #endif
27465 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27466 int rc;
27467
27468 per_cpu(current_task, cpu) = idle;
27469 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27470 #ifdef CONFIG_X86_32
27471 irq_ctx_init(cpu);
27472 #else
27473 clear_tsk_thread_flag(idle, TIF_FORK);
27474 - per_cpu(kernel_stack, cpu) =
27475 - (unsigned long)task_stack_page(idle) -
27476 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27477 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27478 #endif
27479 xen_setup_runstate_info(cpu);
27480 xen_setup_timer(cpu);
27481 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27482 index f9643fc..602e8af 100644
27483 --- a/arch/x86/xen/xen-asm_32.S
27484 +++ b/arch/x86/xen/xen-asm_32.S
27485 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27486 ESP_OFFSET=4 # bytes pushed onto stack
27487
27488 /*
27489 - * Store vcpu_info pointer for easy access. Do it this way to
27490 - * avoid having to reload %fs
27491 + * Store vcpu_info pointer for easy access.
27492 */
27493 #ifdef CONFIG_SMP
27494 - GET_THREAD_INFO(%eax)
27495 - movl TI_cpu(%eax), %eax
27496 - movl __per_cpu_offset(,%eax,4), %eax
27497 - mov xen_vcpu(%eax), %eax
27498 + push %fs
27499 + mov $(__KERNEL_PERCPU), %eax
27500 + mov %eax, %fs
27501 + mov PER_CPU_VAR(xen_vcpu), %eax
27502 + pop %fs
27503 #else
27504 movl xen_vcpu, %eax
27505 #endif
27506 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27507 index aaa7291..3f77960 100644
27508 --- a/arch/x86/xen/xen-head.S
27509 +++ b/arch/x86/xen/xen-head.S
27510 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27511 #ifdef CONFIG_X86_32
27512 mov %esi,xen_start_info
27513 mov $init_thread_union+THREAD_SIZE,%esp
27514 +#ifdef CONFIG_SMP
27515 + movl $cpu_gdt_table,%edi
27516 + movl $__per_cpu_load,%eax
27517 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27518 + rorl $16,%eax
27519 + movb %al,__KERNEL_PERCPU + 4(%edi)
27520 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27521 + movl $__per_cpu_end - 1,%eax
27522 + subl $__per_cpu_start,%eax
27523 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27524 +#endif
27525 #else
27526 mov %rsi,xen_start_info
27527 mov $init_thread_union+THREAD_SIZE,%rsp
27528 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27529 index 202d4c1..99b072a 100644
27530 --- a/arch/x86/xen/xen-ops.h
27531 +++ b/arch/x86/xen/xen-ops.h
27532 @@ -10,8 +10,6 @@
27533 extern const char xen_hypervisor_callback[];
27534 extern const char xen_failsafe_callback[];
27535
27536 -extern void *xen_initial_gdt;
27537 -
27538 struct trap_info;
27539 void xen_copy_trap_info(struct trap_info *traps);
27540
27541 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27542 index 525bd3d..ef888b1 100644
27543 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27544 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27545 @@ -119,9 +119,9 @@
27546 ----------------------------------------------------------------------*/
27547
27548 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27549 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27550 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27551 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27552 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27553
27554 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27555 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27556 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27557 index 2f33760..835e50a 100644
27558 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27559 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27560 @@ -11,6 +11,7 @@
27561 #ifndef _XTENSA_CORE_H
27562 #define _XTENSA_CORE_H
27563
27564 +#include <linux/const.h>
27565
27566 /****************************************************************************
27567 Parameters Useful for Any Code, USER or PRIVILEGED
27568 @@ -112,9 +113,9 @@
27569 ----------------------------------------------------------------------*/
27570
27571 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27572 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27573 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27574 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27575 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27576
27577 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27578 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27579 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27580 index af00795..2bb8105 100644
27581 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27582 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27583 @@ -11,6 +11,7 @@
27584 #ifndef _XTENSA_CORE_CONFIGURATION_H
27585 #define _XTENSA_CORE_CONFIGURATION_H
27586
27587 +#include <linux/const.h>
27588
27589 /****************************************************************************
27590 Parameters Useful for Any Code, USER or PRIVILEGED
27591 @@ -118,9 +119,9 @@
27592 ----------------------------------------------------------------------*/
27593
27594 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27595 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27596 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27597 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27598 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27599
27600 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27601 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27602 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27603 index 58916af..9cb880b 100644
27604 --- a/block/blk-iopoll.c
27605 +++ b/block/blk-iopoll.c
27606 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27607 }
27608 EXPORT_SYMBOL(blk_iopoll_complete);
27609
27610 -static void blk_iopoll_softirq(struct softirq_action *h)
27611 +static void blk_iopoll_softirq(void)
27612 {
27613 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27614 int rearm = 0, budget = blk_iopoll_budget;
27615 diff --git a/block/blk-map.c b/block/blk-map.c
27616 index 623e1cd..ca1e109 100644
27617 --- a/block/blk-map.c
27618 +++ b/block/blk-map.c
27619 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27620 if (!len || !kbuf)
27621 return -EINVAL;
27622
27623 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27624 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27625 if (do_copy)
27626 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27627 else
27628 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27629 index 467c8de..4bddc6d 100644
27630 --- a/block/blk-softirq.c
27631 +++ b/block/blk-softirq.c
27632 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27633 * Softirq action handler - move entries to local list and loop over them
27634 * while passing them to the queue registered handler.
27635 */
27636 -static void blk_done_softirq(struct softirq_action *h)
27637 +static void blk_done_softirq(void)
27638 {
27639 struct list_head *cpu_list, local_list;
27640
27641 diff --git a/block/bsg.c b/block/bsg.c
27642 index ff64ae3..593560c 100644
27643 --- a/block/bsg.c
27644 +++ b/block/bsg.c
27645 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27646 struct sg_io_v4 *hdr, struct bsg_device *bd,
27647 fmode_t has_write_perm)
27648 {
27649 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27650 + unsigned char *cmdptr;
27651 +
27652 if (hdr->request_len > BLK_MAX_CDB) {
27653 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27654 if (!rq->cmd)
27655 return -ENOMEM;
27656 - }
27657 + cmdptr = rq->cmd;
27658 + } else
27659 + cmdptr = tmpcmd;
27660
27661 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27662 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27663 hdr->request_len))
27664 return -EFAULT;
27665
27666 + if (cmdptr != rq->cmd)
27667 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27668 +
27669 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27670 if (blk_verify_command(rq->cmd, has_write_perm))
27671 return -EPERM;
27672 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27673 index 7c668c8..db3521c 100644
27674 --- a/block/compat_ioctl.c
27675 +++ b/block/compat_ioctl.c
27676 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27677 err |= __get_user(f->spec1, &uf->spec1);
27678 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27679 err |= __get_user(name, &uf->name);
27680 - f->name = compat_ptr(name);
27681 + f->name = (void __force_kernel *)compat_ptr(name);
27682 if (err) {
27683 err = -EFAULT;
27684 goto out;
27685 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27686 index 6296b40..417c00f 100644
27687 --- a/block/partitions/efi.c
27688 +++ b/block/partitions/efi.c
27689 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27690 if (!gpt)
27691 return NULL;
27692
27693 + if (!le32_to_cpu(gpt->num_partition_entries))
27694 + return NULL;
27695 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27696 + if (!pte)
27697 + return NULL;
27698 +
27699 count = le32_to_cpu(gpt->num_partition_entries) *
27700 le32_to_cpu(gpt->sizeof_partition_entry);
27701 - if (!count)
27702 - return NULL;
27703 - pte = kzalloc(count, GFP_KERNEL);
27704 - if (!pte)
27705 - return NULL;
27706 -
27707 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27708 (u8 *) pte,
27709 count) < count) {
27710 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27711 index 9a87daa..fb17486 100644
27712 --- a/block/scsi_ioctl.c
27713 +++ b/block/scsi_ioctl.c
27714 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27715 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27716 struct sg_io_hdr *hdr, fmode_t mode)
27717 {
27718 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27719 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27720 + unsigned char *cmdptr;
27721 +
27722 + if (rq->cmd != rq->__cmd)
27723 + cmdptr = rq->cmd;
27724 + else
27725 + cmdptr = tmpcmd;
27726 +
27727 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27728 return -EFAULT;
27729 +
27730 + if (cmdptr != rq->cmd)
27731 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27732 +
27733 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27734 return -EPERM;
27735
27736 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27737 int err;
27738 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27739 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27740 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27741 + unsigned char *cmdptr;
27742
27743 if (!sic)
27744 return -EINVAL;
27745 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27746 */
27747 err = -EFAULT;
27748 rq->cmd_len = cmdlen;
27749 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27750 +
27751 + if (rq->cmd != rq->__cmd)
27752 + cmdptr = rq->cmd;
27753 + else
27754 + cmdptr = tmpcmd;
27755 +
27756 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27757 goto error;
27758
27759 + if (rq->cmd != cmdptr)
27760 + memcpy(rq->cmd, cmdptr, cmdlen);
27761 +
27762 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27763 goto error;
27764
27765 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27766 index 671d4d6..5f24030 100644
27767 --- a/crypto/cryptd.c
27768 +++ b/crypto/cryptd.c
27769 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27770
27771 struct cryptd_blkcipher_request_ctx {
27772 crypto_completion_t complete;
27773 -};
27774 +} __no_const;
27775
27776 struct cryptd_hash_ctx {
27777 struct crypto_shash *child;
27778 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27779
27780 struct cryptd_aead_request_ctx {
27781 crypto_completion_t complete;
27782 -};
27783 +} __no_const;
27784
27785 static void cryptd_queue_worker(struct work_struct *work);
27786
27787 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27788 index e6defd8..c26a225 100644
27789 --- a/drivers/acpi/apei/cper.c
27790 +++ b/drivers/acpi/apei/cper.c
27791 @@ -38,12 +38,12 @@
27792 */
27793 u64 cper_next_record_id(void)
27794 {
27795 - static atomic64_t seq;
27796 + static atomic64_unchecked_t seq;
27797
27798 - if (!atomic64_read(&seq))
27799 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27800 + if (!atomic64_read_unchecked(&seq))
27801 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27802
27803 - return atomic64_inc_return(&seq);
27804 + return atomic64_inc_return_unchecked(&seq);
27805 }
27806 EXPORT_SYMBOL_GPL(cper_next_record_id);
27807
27808 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27809 index 7586544..636a2f0 100644
27810 --- a/drivers/acpi/ec_sys.c
27811 +++ b/drivers/acpi/ec_sys.c
27812 @@ -12,6 +12,7 @@
27813 #include <linux/acpi.h>
27814 #include <linux/debugfs.h>
27815 #include <linux/module.h>
27816 +#include <linux/uaccess.h>
27817 #include "internal.h"
27818
27819 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27820 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27821 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27822 */
27823 unsigned int size = EC_SPACE_SIZE;
27824 - u8 *data = (u8 *) buf;
27825 + u8 data;
27826 loff_t init_off = *off;
27827 int err = 0;
27828
27829 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27830 size = count;
27831
27832 while (size) {
27833 - err = ec_read(*off, &data[*off - init_off]);
27834 + err = ec_read(*off, &data);
27835 if (err)
27836 return err;
27837 + if (put_user(data, &buf[*off - init_off]))
27838 + return -EFAULT;
27839 *off += 1;
27840 size--;
27841 }
27842 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27843
27844 unsigned int size = count;
27845 loff_t init_off = *off;
27846 - u8 *data = (u8 *) buf;
27847 int err = 0;
27848
27849 if (*off >= EC_SPACE_SIZE)
27850 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27851 }
27852
27853 while (size) {
27854 - u8 byte_write = data[*off - init_off];
27855 + u8 byte_write;
27856 + if (get_user(byte_write, &buf[*off - init_off]))
27857 + return -EFAULT;
27858 err = ec_write(*off, byte_write);
27859 if (err)
27860 return err;
27861 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27862 index 251c7b62..000462d 100644
27863 --- a/drivers/acpi/proc.c
27864 +++ b/drivers/acpi/proc.c
27865 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27866 size_t count, loff_t * ppos)
27867 {
27868 struct list_head *node, *next;
27869 - char strbuf[5];
27870 - char str[5] = "";
27871 - unsigned int len = count;
27872 + char strbuf[5] = {0};
27873
27874 - if (len > 4)
27875 - len = 4;
27876 - if (len < 0)
27877 + if (count > 4)
27878 + count = 4;
27879 + if (copy_from_user(strbuf, buffer, count))
27880 return -EFAULT;
27881 -
27882 - if (copy_from_user(strbuf, buffer, len))
27883 - return -EFAULT;
27884 - strbuf[len] = '\0';
27885 - sscanf(strbuf, "%s", str);
27886 + strbuf[count] = '\0';
27887
27888 mutex_lock(&acpi_device_lock);
27889 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27890 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27891 if (!dev->wakeup.flags.valid)
27892 continue;
27893
27894 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27895 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27896 if (device_can_wakeup(&dev->dev)) {
27897 bool enable = !device_may_wakeup(&dev->dev);
27898 device_set_wakeup_enable(&dev->dev, enable);
27899 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27900 index bfc31cb..8213ce1 100644
27901 --- a/drivers/acpi/processor_driver.c
27902 +++ b/drivers/acpi/processor_driver.c
27903 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27904 return 0;
27905 #endif
27906
27907 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27908 + BUG_ON(pr->id >= nr_cpu_ids);
27909
27910 /*
27911 * Buggy BIOS check
27912 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27913 index 8e1039c..ea9cbd4 100644
27914 --- a/drivers/ata/libata-core.c
27915 +++ b/drivers/ata/libata-core.c
27916 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27917 struct ata_port *ap;
27918 unsigned int tag;
27919
27920 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27921 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27922 ap = qc->ap;
27923
27924 qc->flags = 0;
27925 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27926 struct ata_port *ap;
27927 struct ata_link *link;
27928
27929 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27930 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27931 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27932 ap = qc->ap;
27933 link = qc->dev->link;
27934 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27935 return;
27936
27937 spin_lock(&lock);
27938 + pax_open_kernel();
27939
27940 for (cur = ops->inherits; cur; cur = cur->inherits) {
27941 void **inherit = (void **)cur;
27942 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27943 if (IS_ERR(*pp))
27944 *pp = NULL;
27945
27946 - ops->inherits = NULL;
27947 + *(struct ata_port_operations **)&ops->inherits = NULL;
27948
27949 + pax_close_kernel();
27950 spin_unlock(&lock);
27951 }
27952
27953 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27954 index bfaa5cb..3ba1cc3 100644
27955 --- a/drivers/ata/pata_arasan_cf.c
27956 +++ b/drivers/ata/pata_arasan_cf.c
27957 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27958 /* Handle platform specific quirks */
27959 if (pdata->quirk) {
27960 if (pdata->quirk & CF_BROKEN_PIO) {
27961 - ap->ops->set_piomode = NULL;
27962 + pax_open_kernel();
27963 + *(void **)&ap->ops->set_piomode = NULL;
27964 + pax_close_kernel();
27965 ap->pio_mask = 0;
27966 }
27967 if (pdata->quirk & CF_BROKEN_MWDMA)
27968 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27969 index f9b983a..887b9d8 100644
27970 --- a/drivers/atm/adummy.c
27971 +++ b/drivers/atm/adummy.c
27972 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27973 vcc->pop(vcc, skb);
27974 else
27975 dev_kfree_skb_any(skb);
27976 - atomic_inc(&vcc->stats->tx);
27977 + atomic_inc_unchecked(&vcc->stats->tx);
27978
27979 return 0;
27980 }
27981 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27982 index 89b30f3..7964211 100644
27983 --- a/drivers/atm/ambassador.c
27984 +++ b/drivers/atm/ambassador.c
27985 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27986 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27987
27988 // VC layer stats
27989 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27990 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27991
27992 // free the descriptor
27993 kfree (tx_descr);
27994 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27995 dump_skb ("<<<", vc, skb);
27996
27997 // VC layer stats
27998 - atomic_inc(&atm_vcc->stats->rx);
27999 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28000 __net_timestamp(skb);
28001 // end of our responsibility
28002 atm_vcc->push (atm_vcc, skb);
28003 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28004 } else {
28005 PRINTK (KERN_INFO, "dropped over-size frame");
28006 // should we count this?
28007 - atomic_inc(&atm_vcc->stats->rx_drop);
28008 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28009 }
28010
28011 } else {
28012 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28013 }
28014
28015 if (check_area (skb->data, skb->len)) {
28016 - atomic_inc(&atm_vcc->stats->tx_err);
28017 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28018 return -ENOMEM; // ?
28019 }
28020
28021 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28022 index b22d71c..d6e1049 100644
28023 --- a/drivers/atm/atmtcp.c
28024 +++ b/drivers/atm/atmtcp.c
28025 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28026 if (vcc->pop) vcc->pop(vcc,skb);
28027 else dev_kfree_skb(skb);
28028 if (dev_data) return 0;
28029 - atomic_inc(&vcc->stats->tx_err);
28030 + atomic_inc_unchecked(&vcc->stats->tx_err);
28031 return -ENOLINK;
28032 }
28033 size = skb->len+sizeof(struct atmtcp_hdr);
28034 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28035 if (!new_skb) {
28036 if (vcc->pop) vcc->pop(vcc,skb);
28037 else dev_kfree_skb(skb);
28038 - atomic_inc(&vcc->stats->tx_err);
28039 + atomic_inc_unchecked(&vcc->stats->tx_err);
28040 return -ENOBUFS;
28041 }
28042 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28043 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28044 if (vcc->pop) vcc->pop(vcc,skb);
28045 else dev_kfree_skb(skb);
28046 out_vcc->push(out_vcc,new_skb);
28047 - atomic_inc(&vcc->stats->tx);
28048 - atomic_inc(&out_vcc->stats->rx);
28049 + atomic_inc_unchecked(&vcc->stats->tx);
28050 + atomic_inc_unchecked(&out_vcc->stats->rx);
28051 return 0;
28052 }
28053
28054 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28055 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28056 read_unlock(&vcc_sklist_lock);
28057 if (!out_vcc) {
28058 - atomic_inc(&vcc->stats->tx_err);
28059 + atomic_inc_unchecked(&vcc->stats->tx_err);
28060 goto done;
28061 }
28062 skb_pull(skb,sizeof(struct atmtcp_hdr));
28063 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28064 __net_timestamp(new_skb);
28065 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28066 out_vcc->push(out_vcc,new_skb);
28067 - atomic_inc(&vcc->stats->tx);
28068 - atomic_inc(&out_vcc->stats->rx);
28069 + atomic_inc_unchecked(&vcc->stats->tx);
28070 + atomic_inc_unchecked(&out_vcc->stats->rx);
28071 done:
28072 if (vcc->pop) vcc->pop(vcc,skb);
28073 else dev_kfree_skb(skb);
28074 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28075 index 2059ee4..faf51c7 100644
28076 --- a/drivers/atm/eni.c
28077 +++ b/drivers/atm/eni.c
28078 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28079 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28080 vcc->dev->number);
28081 length = 0;
28082 - atomic_inc(&vcc->stats->rx_err);
28083 + atomic_inc_unchecked(&vcc->stats->rx_err);
28084 }
28085 else {
28086 length = ATM_CELL_SIZE-1; /* no HEC */
28087 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28088 size);
28089 }
28090 eff = length = 0;
28091 - atomic_inc(&vcc->stats->rx_err);
28092 + atomic_inc_unchecked(&vcc->stats->rx_err);
28093 }
28094 else {
28095 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28096 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28097 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28098 vcc->dev->number,vcc->vci,length,size << 2,descr);
28099 length = eff = 0;
28100 - atomic_inc(&vcc->stats->rx_err);
28101 + atomic_inc_unchecked(&vcc->stats->rx_err);
28102 }
28103 }
28104 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28105 @@ -767,7 +767,7 @@ rx_dequeued++;
28106 vcc->push(vcc,skb);
28107 pushed++;
28108 }
28109 - atomic_inc(&vcc->stats->rx);
28110 + atomic_inc_unchecked(&vcc->stats->rx);
28111 }
28112 wake_up(&eni_dev->rx_wait);
28113 }
28114 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28115 PCI_DMA_TODEVICE);
28116 if (vcc->pop) vcc->pop(vcc,skb);
28117 else dev_kfree_skb_irq(skb);
28118 - atomic_inc(&vcc->stats->tx);
28119 + atomic_inc_unchecked(&vcc->stats->tx);
28120 wake_up(&eni_dev->tx_wait);
28121 dma_complete++;
28122 }
28123 @@ -1567,7 +1567,7 @@ tx_complete++;
28124 /*--------------------------------- entries ---------------------------------*/
28125
28126
28127 -static const char *media_name[] __devinitdata = {
28128 +static const char *media_name[] __devinitconst = {
28129 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28130 "UTP", "05?", "06?", "07?", /* 4- 7 */
28131 "TAXI","09?", "10?", "11?", /* 8-11 */
28132 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28133 index 86fed1b..6dc4721 100644
28134 --- a/drivers/atm/firestream.c
28135 +++ b/drivers/atm/firestream.c
28136 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28137 }
28138 }
28139
28140 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28141 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28142
28143 fs_dprintk (FS_DEBUG_TXMEM, "i");
28144 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28145 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28146 #endif
28147 skb_put (skb, qe->p1 & 0xffff);
28148 ATM_SKB(skb)->vcc = atm_vcc;
28149 - atomic_inc(&atm_vcc->stats->rx);
28150 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28151 __net_timestamp(skb);
28152 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28153 atm_vcc->push (atm_vcc, skb);
28154 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28155 kfree (pe);
28156 }
28157 if (atm_vcc)
28158 - atomic_inc(&atm_vcc->stats->rx_drop);
28159 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28160 break;
28161 case 0x1f: /* Reassembly abort: no buffers. */
28162 /* Silently increment error counter. */
28163 if (atm_vcc)
28164 - atomic_inc(&atm_vcc->stats->rx_drop);
28165 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28166 break;
28167 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28168 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28169 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28170 index 361f5ae..7fc552d 100644
28171 --- a/drivers/atm/fore200e.c
28172 +++ b/drivers/atm/fore200e.c
28173 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28174 #endif
28175 /* check error condition */
28176 if (*entry->status & STATUS_ERROR)
28177 - atomic_inc(&vcc->stats->tx_err);
28178 + atomic_inc_unchecked(&vcc->stats->tx_err);
28179 else
28180 - atomic_inc(&vcc->stats->tx);
28181 + atomic_inc_unchecked(&vcc->stats->tx);
28182 }
28183 }
28184
28185 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28186 if (skb == NULL) {
28187 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28188
28189 - atomic_inc(&vcc->stats->rx_drop);
28190 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28191 return -ENOMEM;
28192 }
28193
28194 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28195
28196 dev_kfree_skb_any(skb);
28197
28198 - atomic_inc(&vcc->stats->rx_drop);
28199 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28200 return -ENOMEM;
28201 }
28202
28203 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28204
28205 vcc->push(vcc, skb);
28206 - atomic_inc(&vcc->stats->rx);
28207 + atomic_inc_unchecked(&vcc->stats->rx);
28208
28209 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28210
28211 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28212 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28213 fore200e->atm_dev->number,
28214 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28215 - atomic_inc(&vcc->stats->rx_err);
28216 + atomic_inc_unchecked(&vcc->stats->rx_err);
28217 }
28218 }
28219
28220 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28221 goto retry_here;
28222 }
28223
28224 - atomic_inc(&vcc->stats->tx_err);
28225 + atomic_inc_unchecked(&vcc->stats->tx_err);
28226
28227 fore200e->tx_sat++;
28228 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28229 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28230 index b182c2f..1c6fa8a 100644
28231 --- a/drivers/atm/he.c
28232 +++ b/drivers/atm/he.c
28233 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28234
28235 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28236 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28237 - atomic_inc(&vcc->stats->rx_drop);
28238 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28239 goto return_host_buffers;
28240 }
28241
28242 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28243 RBRQ_LEN_ERR(he_dev->rbrq_head)
28244 ? "LEN_ERR" : "",
28245 vcc->vpi, vcc->vci);
28246 - atomic_inc(&vcc->stats->rx_err);
28247 + atomic_inc_unchecked(&vcc->stats->rx_err);
28248 goto return_host_buffers;
28249 }
28250
28251 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28252 vcc->push(vcc, skb);
28253 spin_lock(&he_dev->global_lock);
28254
28255 - atomic_inc(&vcc->stats->rx);
28256 + atomic_inc_unchecked(&vcc->stats->rx);
28257
28258 return_host_buffers:
28259 ++pdus_assembled;
28260 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28261 tpd->vcc->pop(tpd->vcc, tpd->skb);
28262 else
28263 dev_kfree_skb_any(tpd->skb);
28264 - atomic_inc(&tpd->vcc->stats->tx_err);
28265 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28266 }
28267 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28268 return;
28269 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28270 vcc->pop(vcc, skb);
28271 else
28272 dev_kfree_skb_any(skb);
28273 - atomic_inc(&vcc->stats->tx_err);
28274 + atomic_inc_unchecked(&vcc->stats->tx_err);
28275 return -EINVAL;
28276 }
28277
28278 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28279 vcc->pop(vcc, skb);
28280 else
28281 dev_kfree_skb_any(skb);
28282 - atomic_inc(&vcc->stats->tx_err);
28283 + atomic_inc_unchecked(&vcc->stats->tx_err);
28284 return -EINVAL;
28285 }
28286 #endif
28287 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28288 vcc->pop(vcc, skb);
28289 else
28290 dev_kfree_skb_any(skb);
28291 - atomic_inc(&vcc->stats->tx_err);
28292 + atomic_inc_unchecked(&vcc->stats->tx_err);
28293 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28294 return -ENOMEM;
28295 }
28296 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28297 vcc->pop(vcc, skb);
28298 else
28299 dev_kfree_skb_any(skb);
28300 - atomic_inc(&vcc->stats->tx_err);
28301 + atomic_inc_unchecked(&vcc->stats->tx_err);
28302 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28303 return -ENOMEM;
28304 }
28305 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28306 __enqueue_tpd(he_dev, tpd, cid);
28307 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28308
28309 - atomic_inc(&vcc->stats->tx);
28310 + atomic_inc_unchecked(&vcc->stats->tx);
28311
28312 return 0;
28313 }
28314 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28315 index 7d01c2a..4e3ac01 100644
28316 --- a/drivers/atm/horizon.c
28317 +++ b/drivers/atm/horizon.c
28318 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28319 {
28320 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28321 // VC layer stats
28322 - atomic_inc(&vcc->stats->rx);
28323 + atomic_inc_unchecked(&vcc->stats->rx);
28324 __net_timestamp(skb);
28325 // end of our responsibility
28326 vcc->push (vcc, skb);
28327 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28328 dev->tx_iovec = NULL;
28329
28330 // VC layer stats
28331 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28332 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28333
28334 // free the skb
28335 hrz_kfree_skb (skb);
28336 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28337 index 8974bd2..b856f85 100644
28338 --- a/drivers/atm/idt77252.c
28339 +++ b/drivers/atm/idt77252.c
28340 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28341 else
28342 dev_kfree_skb(skb);
28343
28344 - atomic_inc(&vcc->stats->tx);
28345 + atomic_inc_unchecked(&vcc->stats->tx);
28346 }
28347
28348 atomic_dec(&scq->used);
28349 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28350 if ((sb = dev_alloc_skb(64)) == NULL) {
28351 printk("%s: Can't allocate buffers for aal0.\n",
28352 card->name);
28353 - atomic_add(i, &vcc->stats->rx_drop);
28354 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28355 break;
28356 }
28357 if (!atm_charge(vcc, sb->truesize)) {
28358 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28359 card->name);
28360 - atomic_add(i - 1, &vcc->stats->rx_drop);
28361 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28362 dev_kfree_skb(sb);
28363 break;
28364 }
28365 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28366 ATM_SKB(sb)->vcc = vcc;
28367 __net_timestamp(sb);
28368 vcc->push(vcc, sb);
28369 - atomic_inc(&vcc->stats->rx);
28370 + atomic_inc_unchecked(&vcc->stats->rx);
28371
28372 cell += ATM_CELL_PAYLOAD;
28373 }
28374 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28375 "(CDC: %08x)\n",
28376 card->name, len, rpp->len, readl(SAR_REG_CDC));
28377 recycle_rx_pool_skb(card, rpp);
28378 - atomic_inc(&vcc->stats->rx_err);
28379 + atomic_inc_unchecked(&vcc->stats->rx_err);
28380 return;
28381 }
28382 if (stat & SAR_RSQE_CRC) {
28383 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28384 recycle_rx_pool_skb(card, rpp);
28385 - atomic_inc(&vcc->stats->rx_err);
28386 + atomic_inc_unchecked(&vcc->stats->rx_err);
28387 return;
28388 }
28389 if (skb_queue_len(&rpp->queue) > 1) {
28390 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28391 RXPRINTK("%s: Can't alloc RX skb.\n",
28392 card->name);
28393 recycle_rx_pool_skb(card, rpp);
28394 - atomic_inc(&vcc->stats->rx_err);
28395 + atomic_inc_unchecked(&vcc->stats->rx_err);
28396 return;
28397 }
28398 if (!atm_charge(vcc, skb->truesize)) {
28399 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28400 __net_timestamp(skb);
28401
28402 vcc->push(vcc, skb);
28403 - atomic_inc(&vcc->stats->rx);
28404 + atomic_inc_unchecked(&vcc->stats->rx);
28405
28406 return;
28407 }
28408 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28409 __net_timestamp(skb);
28410
28411 vcc->push(vcc, skb);
28412 - atomic_inc(&vcc->stats->rx);
28413 + atomic_inc_unchecked(&vcc->stats->rx);
28414
28415 if (skb->truesize > SAR_FB_SIZE_3)
28416 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28417 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28418 if (vcc->qos.aal != ATM_AAL0) {
28419 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28420 card->name, vpi, vci);
28421 - atomic_inc(&vcc->stats->rx_drop);
28422 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28423 goto drop;
28424 }
28425
28426 if ((sb = dev_alloc_skb(64)) == NULL) {
28427 printk("%s: Can't allocate buffers for AAL0.\n",
28428 card->name);
28429 - atomic_inc(&vcc->stats->rx_err);
28430 + atomic_inc_unchecked(&vcc->stats->rx_err);
28431 goto drop;
28432 }
28433
28434 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28435 ATM_SKB(sb)->vcc = vcc;
28436 __net_timestamp(sb);
28437 vcc->push(vcc, sb);
28438 - atomic_inc(&vcc->stats->rx);
28439 + atomic_inc_unchecked(&vcc->stats->rx);
28440
28441 drop:
28442 skb_pull(queue, 64);
28443 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28444
28445 if (vc == NULL) {
28446 printk("%s: NULL connection in send().\n", card->name);
28447 - atomic_inc(&vcc->stats->tx_err);
28448 + atomic_inc_unchecked(&vcc->stats->tx_err);
28449 dev_kfree_skb(skb);
28450 return -EINVAL;
28451 }
28452 if (!test_bit(VCF_TX, &vc->flags)) {
28453 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28454 - atomic_inc(&vcc->stats->tx_err);
28455 + atomic_inc_unchecked(&vcc->stats->tx_err);
28456 dev_kfree_skb(skb);
28457 return -EINVAL;
28458 }
28459 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28460 break;
28461 default:
28462 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28463 - atomic_inc(&vcc->stats->tx_err);
28464 + atomic_inc_unchecked(&vcc->stats->tx_err);
28465 dev_kfree_skb(skb);
28466 return -EINVAL;
28467 }
28468
28469 if (skb_shinfo(skb)->nr_frags != 0) {
28470 printk("%s: No scatter-gather yet.\n", card->name);
28471 - atomic_inc(&vcc->stats->tx_err);
28472 + atomic_inc_unchecked(&vcc->stats->tx_err);
28473 dev_kfree_skb(skb);
28474 return -EINVAL;
28475 }
28476 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28477
28478 err = queue_skb(card, vc, skb, oam);
28479 if (err) {
28480 - atomic_inc(&vcc->stats->tx_err);
28481 + atomic_inc_unchecked(&vcc->stats->tx_err);
28482 dev_kfree_skb(skb);
28483 return err;
28484 }
28485 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28486 skb = dev_alloc_skb(64);
28487 if (!skb) {
28488 printk("%s: Out of memory in send_oam().\n", card->name);
28489 - atomic_inc(&vcc->stats->tx_err);
28490 + atomic_inc_unchecked(&vcc->stats->tx_err);
28491 return -ENOMEM;
28492 }
28493 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28494 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28495 index 96cce6d..62c3ec5 100644
28496 --- a/drivers/atm/iphase.c
28497 +++ b/drivers/atm/iphase.c
28498 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28499 status = (u_short) (buf_desc_ptr->desc_mode);
28500 if (status & (RX_CER | RX_PTE | RX_OFL))
28501 {
28502 - atomic_inc(&vcc->stats->rx_err);
28503 + atomic_inc_unchecked(&vcc->stats->rx_err);
28504 IF_ERR(printk("IA: bad packet, dropping it");)
28505 if (status & RX_CER) {
28506 IF_ERR(printk(" cause: packet CRC error\n");)
28507 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28508 len = dma_addr - buf_addr;
28509 if (len > iadev->rx_buf_sz) {
28510 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28511 - atomic_inc(&vcc->stats->rx_err);
28512 + atomic_inc_unchecked(&vcc->stats->rx_err);
28513 goto out_free_desc;
28514 }
28515
28516 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28517 ia_vcc = INPH_IA_VCC(vcc);
28518 if (ia_vcc == NULL)
28519 {
28520 - atomic_inc(&vcc->stats->rx_err);
28521 + atomic_inc_unchecked(&vcc->stats->rx_err);
28522 atm_return(vcc, skb->truesize);
28523 dev_kfree_skb_any(skb);
28524 goto INCR_DLE;
28525 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28526 if ((length > iadev->rx_buf_sz) || (length >
28527 (skb->len - sizeof(struct cpcs_trailer))))
28528 {
28529 - atomic_inc(&vcc->stats->rx_err);
28530 + atomic_inc_unchecked(&vcc->stats->rx_err);
28531 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28532 length, skb->len);)
28533 atm_return(vcc, skb->truesize);
28534 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28535
28536 IF_RX(printk("rx_dle_intr: skb push");)
28537 vcc->push(vcc,skb);
28538 - atomic_inc(&vcc->stats->rx);
28539 + atomic_inc_unchecked(&vcc->stats->rx);
28540 iadev->rx_pkt_cnt++;
28541 }
28542 INCR_DLE:
28543 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28544 {
28545 struct k_sonet_stats *stats;
28546 stats = &PRIV(_ia_dev[board])->sonet_stats;
28547 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28548 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28549 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28550 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28551 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28552 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28553 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28554 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28555 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28556 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28557 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28558 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28559 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28560 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28561 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28562 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28563 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28564 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28565 }
28566 ia_cmds.status = 0;
28567 break;
28568 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28569 if ((desc == 0) || (desc > iadev->num_tx_desc))
28570 {
28571 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28572 - atomic_inc(&vcc->stats->tx);
28573 + atomic_inc_unchecked(&vcc->stats->tx);
28574 if (vcc->pop)
28575 vcc->pop(vcc, skb);
28576 else
28577 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28578 ATM_DESC(skb) = vcc->vci;
28579 skb_queue_tail(&iadev->tx_dma_q, skb);
28580
28581 - atomic_inc(&vcc->stats->tx);
28582 + atomic_inc_unchecked(&vcc->stats->tx);
28583 iadev->tx_pkt_cnt++;
28584 /* Increment transaction counter */
28585 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28586
28587 #if 0
28588 /* add flow control logic */
28589 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28590 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28591 if (iavcc->vc_desc_cnt > 10) {
28592 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28593 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28594 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28595 index 68c7588..7036683 100644
28596 --- a/drivers/atm/lanai.c
28597 +++ b/drivers/atm/lanai.c
28598 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28599 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28600 lanai_endtx(lanai, lvcc);
28601 lanai_free_skb(lvcc->tx.atmvcc, skb);
28602 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28603 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28604 }
28605
28606 /* Try to fill the buffer - don't call unless there is backlog */
28607 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28608 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28609 __net_timestamp(skb);
28610 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28611 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28612 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28613 out:
28614 lvcc->rx.buf.ptr = end;
28615 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28616 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28617 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28618 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28619 lanai->stats.service_rxnotaal5++;
28620 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28621 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28622 return 0;
28623 }
28624 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28625 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28626 int bytes;
28627 read_unlock(&vcc_sklist_lock);
28628 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28629 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28630 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28631 lvcc->stats.x.aal5.service_trash++;
28632 bytes = (SERVICE_GET_END(s) * 16) -
28633 (((unsigned long) lvcc->rx.buf.ptr) -
28634 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28635 }
28636 if (s & SERVICE_STREAM) {
28637 read_unlock(&vcc_sklist_lock);
28638 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28639 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28640 lvcc->stats.x.aal5.service_stream++;
28641 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28642 "PDU on VCI %d!\n", lanai->number, vci);
28643 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28644 return 0;
28645 }
28646 DPRINTK("got rx crc error on vci %d\n", vci);
28647 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28648 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28649 lvcc->stats.x.aal5.service_rxcrc++;
28650 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28651 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28652 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28653 index 1c70c45..300718d 100644
28654 --- a/drivers/atm/nicstar.c
28655 +++ b/drivers/atm/nicstar.c
28656 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28657 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28658 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28659 card->index);
28660 - atomic_inc(&vcc->stats->tx_err);
28661 + atomic_inc_unchecked(&vcc->stats->tx_err);
28662 dev_kfree_skb_any(skb);
28663 return -EINVAL;
28664 }
28665 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28666 if (!vc->tx) {
28667 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28668 card->index);
28669 - atomic_inc(&vcc->stats->tx_err);
28670 + atomic_inc_unchecked(&vcc->stats->tx_err);
28671 dev_kfree_skb_any(skb);
28672 return -EINVAL;
28673 }
28674 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28675 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28676 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28677 card->index);
28678 - atomic_inc(&vcc->stats->tx_err);
28679 + atomic_inc_unchecked(&vcc->stats->tx_err);
28680 dev_kfree_skb_any(skb);
28681 return -EINVAL;
28682 }
28683
28684 if (skb_shinfo(skb)->nr_frags != 0) {
28685 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28686 - atomic_inc(&vcc->stats->tx_err);
28687 + atomic_inc_unchecked(&vcc->stats->tx_err);
28688 dev_kfree_skb_any(skb);
28689 return -EINVAL;
28690 }
28691 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28692 }
28693
28694 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28695 - atomic_inc(&vcc->stats->tx_err);
28696 + atomic_inc_unchecked(&vcc->stats->tx_err);
28697 dev_kfree_skb_any(skb);
28698 return -EIO;
28699 }
28700 - atomic_inc(&vcc->stats->tx);
28701 + atomic_inc_unchecked(&vcc->stats->tx);
28702
28703 return 0;
28704 }
28705 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28706 printk
28707 ("nicstar%d: Can't allocate buffers for aal0.\n",
28708 card->index);
28709 - atomic_add(i, &vcc->stats->rx_drop);
28710 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28711 break;
28712 }
28713 if (!atm_charge(vcc, sb->truesize)) {
28714 RXPRINTK
28715 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28716 card->index);
28717 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28718 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28719 dev_kfree_skb_any(sb);
28720 break;
28721 }
28722 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28723 ATM_SKB(sb)->vcc = vcc;
28724 __net_timestamp(sb);
28725 vcc->push(vcc, sb);
28726 - atomic_inc(&vcc->stats->rx);
28727 + atomic_inc_unchecked(&vcc->stats->rx);
28728 cell += ATM_CELL_PAYLOAD;
28729 }
28730
28731 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28732 if (iovb == NULL) {
28733 printk("nicstar%d: Out of iovec buffers.\n",
28734 card->index);
28735 - atomic_inc(&vcc->stats->rx_drop);
28736 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28737 recycle_rx_buf(card, skb);
28738 return;
28739 }
28740 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28741 small or large buffer itself. */
28742 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28743 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28744 - atomic_inc(&vcc->stats->rx_err);
28745 + atomic_inc_unchecked(&vcc->stats->rx_err);
28746 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28747 NS_MAX_IOVECS);
28748 NS_PRV_IOVCNT(iovb) = 0;
28749 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28750 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28751 card->index);
28752 which_list(card, skb);
28753 - atomic_inc(&vcc->stats->rx_err);
28754 + atomic_inc_unchecked(&vcc->stats->rx_err);
28755 recycle_rx_buf(card, skb);
28756 vc->rx_iov = NULL;
28757 recycle_iov_buf(card, iovb);
28758 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28759 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28760 card->index);
28761 which_list(card, skb);
28762 - atomic_inc(&vcc->stats->rx_err);
28763 + atomic_inc_unchecked(&vcc->stats->rx_err);
28764 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28765 NS_PRV_IOVCNT(iovb));
28766 vc->rx_iov = NULL;
28767 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28768 printk(" - PDU size mismatch.\n");
28769 else
28770 printk(".\n");
28771 - atomic_inc(&vcc->stats->rx_err);
28772 + atomic_inc_unchecked(&vcc->stats->rx_err);
28773 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28774 NS_PRV_IOVCNT(iovb));
28775 vc->rx_iov = NULL;
28776 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28777 /* skb points to a small buffer */
28778 if (!atm_charge(vcc, skb->truesize)) {
28779 push_rxbufs(card, skb);
28780 - atomic_inc(&vcc->stats->rx_drop);
28781 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28782 } else {
28783 skb_put(skb, len);
28784 dequeue_sm_buf(card, skb);
28785 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28786 ATM_SKB(skb)->vcc = vcc;
28787 __net_timestamp(skb);
28788 vcc->push(vcc, skb);
28789 - atomic_inc(&vcc->stats->rx);
28790 + atomic_inc_unchecked(&vcc->stats->rx);
28791 }
28792 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28793 struct sk_buff *sb;
28794 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28795 if (len <= NS_SMBUFSIZE) {
28796 if (!atm_charge(vcc, sb->truesize)) {
28797 push_rxbufs(card, sb);
28798 - atomic_inc(&vcc->stats->rx_drop);
28799 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28800 } else {
28801 skb_put(sb, len);
28802 dequeue_sm_buf(card, sb);
28803 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28804 ATM_SKB(sb)->vcc = vcc;
28805 __net_timestamp(sb);
28806 vcc->push(vcc, sb);
28807 - atomic_inc(&vcc->stats->rx);
28808 + atomic_inc_unchecked(&vcc->stats->rx);
28809 }
28810
28811 push_rxbufs(card, skb);
28812 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28813
28814 if (!atm_charge(vcc, skb->truesize)) {
28815 push_rxbufs(card, skb);
28816 - atomic_inc(&vcc->stats->rx_drop);
28817 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28818 } else {
28819 dequeue_lg_buf(card, skb);
28820 #ifdef NS_USE_DESTRUCTORS
28821 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28822 ATM_SKB(skb)->vcc = vcc;
28823 __net_timestamp(skb);
28824 vcc->push(vcc, skb);
28825 - atomic_inc(&vcc->stats->rx);
28826 + atomic_inc_unchecked(&vcc->stats->rx);
28827 }
28828
28829 push_rxbufs(card, sb);
28830 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28831 printk
28832 ("nicstar%d: Out of huge buffers.\n",
28833 card->index);
28834 - atomic_inc(&vcc->stats->rx_drop);
28835 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28836 recycle_iovec_rx_bufs(card,
28837 (struct iovec *)
28838 iovb->data,
28839 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28840 card->hbpool.count++;
28841 } else
28842 dev_kfree_skb_any(hb);
28843 - atomic_inc(&vcc->stats->rx_drop);
28844 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28845 } else {
28846 /* Copy the small buffer to the huge buffer */
28847 sb = (struct sk_buff *)iov->iov_base;
28848 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28849 #endif /* NS_USE_DESTRUCTORS */
28850 __net_timestamp(hb);
28851 vcc->push(vcc, hb);
28852 - atomic_inc(&vcc->stats->rx);
28853 + atomic_inc_unchecked(&vcc->stats->rx);
28854 }
28855 }
28856
28857 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28858 index 9851093..adb2b1e 100644
28859 --- a/drivers/atm/solos-pci.c
28860 +++ b/drivers/atm/solos-pci.c
28861 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28862 }
28863 atm_charge(vcc, skb->truesize);
28864 vcc->push(vcc, skb);
28865 - atomic_inc(&vcc->stats->rx);
28866 + atomic_inc_unchecked(&vcc->stats->rx);
28867 break;
28868
28869 case PKT_STATUS:
28870 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28871 vcc = SKB_CB(oldskb)->vcc;
28872
28873 if (vcc) {
28874 - atomic_inc(&vcc->stats->tx);
28875 + atomic_inc_unchecked(&vcc->stats->tx);
28876 solos_pop(vcc, oldskb);
28877 } else
28878 dev_kfree_skb_irq(oldskb);
28879 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28880 index 0215934..ce9f5b1 100644
28881 --- a/drivers/atm/suni.c
28882 +++ b/drivers/atm/suni.c
28883 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28884
28885
28886 #define ADD_LIMITED(s,v) \
28887 - atomic_add((v),&stats->s); \
28888 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28889 + atomic_add_unchecked((v),&stats->s); \
28890 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28891
28892
28893 static void suni_hz(unsigned long from_timer)
28894 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28895 index 5120a96..e2572bd 100644
28896 --- a/drivers/atm/uPD98402.c
28897 +++ b/drivers/atm/uPD98402.c
28898 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28899 struct sonet_stats tmp;
28900 int error = 0;
28901
28902 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28903 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28904 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28905 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28906 if (zero && !error) {
28907 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28908
28909
28910 #define ADD_LIMITED(s,v) \
28911 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28912 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28913 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28914 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28915 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28916 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28917
28918
28919 static void stat_event(struct atm_dev *dev)
28920 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28921 if (reason & uPD98402_INT_PFM) stat_event(dev);
28922 if (reason & uPD98402_INT_PCO) {
28923 (void) GET(PCOCR); /* clear interrupt cause */
28924 - atomic_add(GET(HECCT),
28925 + atomic_add_unchecked(GET(HECCT),
28926 &PRIV(dev)->sonet_stats.uncorr_hcs);
28927 }
28928 if ((reason & uPD98402_INT_RFO) &&
28929 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28930 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28931 uPD98402_INT_LOS),PIMR); /* enable them */
28932 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28933 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28934 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28935 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28936 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28937 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28938 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28939 return 0;
28940 }
28941
28942 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28943 index abe4e20..83c4727 100644
28944 --- a/drivers/atm/zatm.c
28945 +++ b/drivers/atm/zatm.c
28946 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28947 }
28948 if (!size) {
28949 dev_kfree_skb_irq(skb);
28950 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28951 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28952 continue;
28953 }
28954 if (!atm_charge(vcc,skb->truesize)) {
28955 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28956 skb->len = size;
28957 ATM_SKB(skb)->vcc = vcc;
28958 vcc->push(vcc,skb);
28959 - atomic_inc(&vcc->stats->rx);
28960 + atomic_inc_unchecked(&vcc->stats->rx);
28961 }
28962 zout(pos & 0xffff,MTA(mbx));
28963 #if 0 /* probably a stupid idea */
28964 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28965 skb_queue_head(&zatm_vcc->backlog,skb);
28966 break;
28967 }
28968 - atomic_inc(&vcc->stats->tx);
28969 + atomic_inc_unchecked(&vcc->stats->tx);
28970 wake_up(&zatm_vcc->tx_wait);
28971 }
28972
28973 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28974 index deb4a45..211eff2 100644
28975 --- a/drivers/base/devtmpfs.c
28976 +++ b/drivers/base/devtmpfs.c
28977 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28978 if (!thread)
28979 return 0;
28980
28981 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28982 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28983 if (err)
28984 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28985 else
28986 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28987 index cbb463b..babe2cf 100644
28988 --- a/drivers/base/power/wakeup.c
28989 +++ b/drivers/base/power/wakeup.c
28990 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28991 * They need to be modified together atomically, so it's better to use one
28992 * atomic variable to hold them both.
28993 */
28994 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28995 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28996
28997 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28998 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28999
29000 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29001 {
29002 - unsigned int comb = atomic_read(&combined_event_count);
29003 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29004
29005 *cnt = (comb >> IN_PROGRESS_BITS);
29006 *inpr = comb & MAX_IN_PROGRESS;
29007 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29008 ws->start_prevent_time = ws->last_time;
29009
29010 /* Increment the counter of events in progress. */
29011 - cec = atomic_inc_return(&combined_event_count);
29012 + cec = atomic_inc_return_unchecked(&combined_event_count);
29013
29014 trace_wakeup_source_activate(ws->name, cec);
29015 }
29016 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29017 * Increment the counter of registered wakeup events and decrement the
29018 * couter of wakeup events in progress simultaneously.
29019 */
29020 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29021 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29022 trace_wakeup_source_deactivate(ws->name, cec);
29023
29024 split_counters(&cnt, &inpr);
29025 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29026 index b0f553b..77b928b 100644
29027 --- a/drivers/block/cciss.c
29028 +++ b/drivers/block/cciss.c
29029 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29030 int err;
29031 u32 cp;
29032
29033 + memset(&arg64, 0, sizeof(arg64));
29034 +
29035 err = 0;
29036 err |=
29037 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29038 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29039 while (!list_empty(&h->reqQ)) {
29040 c = list_entry(h->reqQ.next, CommandList_struct, list);
29041 /* can't do anything if fifo is full */
29042 - if ((h->access.fifo_full(h))) {
29043 + if ((h->access->fifo_full(h))) {
29044 dev_warn(&h->pdev->dev, "fifo full\n");
29045 break;
29046 }
29047 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29048 h->Qdepth--;
29049
29050 /* Tell the controller execute command */
29051 - h->access.submit_command(h, c);
29052 + h->access->submit_command(h, c);
29053
29054 /* Put job onto the completed Q */
29055 addQ(&h->cmpQ, c);
29056 @@ -3443,17 +3445,17 @@ startio:
29057
29058 static inline unsigned long get_next_completion(ctlr_info_t *h)
29059 {
29060 - return h->access.command_completed(h);
29061 + return h->access->command_completed(h);
29062 }
29063
29064 static inline int interrupt_pending(ctlr_info_t *h)
29065 {
29066 - return h->access.intr_pending(h);
29067 + return h->access->intr_pending(h);
29068 }
29069
29070 static inline long interrupt_not_for_us(ctlr_info_t *h)
29071 {
29072 - return ((h->access.intr_pending(h) == 0) ||
29073 + return ((h->access->intr_pending(h) == 0) ||
29074 (h->interrupts_enabled == 0));
29075 }
29076
29077 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29078 u32 a;
29079
29080 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29081 - return h->access.command_completed(h);
29082 + return h->access->command_completed(h);
29083
29084 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29085 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29086 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29087 trans_support & CFGTBL_Trans_use_short_tags);
29088
29089 /* Change the access methods to the performant access methods */
29090 - h->access = SA5_performant_access;
29091 + h->access = &SA5_performant_access;
29092 h->transMethod = CFGTBL_Trans_Performant;
29093
29094 return;
29095 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29096 if (prod_index < 0)
29097 return -ENODEV;
29098 h->product_name = products[prod_index].product_name;
29099 - h->access = *(products[prod_index].access);
29100 + h->access = products[prod_index].access;
29101
29102 if (cciss_board_disabled(h)) {
29103 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29104 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29105 }
29106
29107 /* make sure the board interrupts are off */
29108 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29109 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29110 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29111 if (rc)
29112 goto clean2;
29113 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29114 * fake ones to scoop up any residual completions.
29115 */
29116 spin_lock_irqsave(&h->lock, flags);
29117 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29118 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29119 spin_unlock_irqrestore(&h->lock, flags);
29120 free_irq(h->intr[h->intr_mode], h);
29121 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29122 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29123 dev_info(&h->pdev->dev, "Board READY.\n");
29124 dev_info(&h->pdev->dev,
29125 "Waiting for stale completions to drain.\n");
29126 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29127 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29128 msleep(10000);
29129 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29130 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29131
29132 rc = controller_reset_failed(h->cfgtable);
29133 if (rc)
29134 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29135 cciss_scsi_setup(h);
29136
29137 /* Turn the interrupts on so we can service requests */
29138 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29139 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29140
29141 /* Get the firmware version */
29142 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29143 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29144 kfree(flush_buf);
29145 if (return_code != IO_OK)
29146 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29147 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29148 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29149 free_irq(h->intr[h->intr_mode], h);
29150 }
29151
29152 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29153 index 7fda30e..eb5dfe0 100644
29154 --- a/drivers/block/cciss.h
29155 +++ b/drivers/block/cciss.h
29156 @@ -101,7 +101,7 @@ struct ctlr_info
29157 /* information about each logical volume */
29158 drive_info_struct *drv[CISS_MAX_LUN];
29159
29160 - struct access_method access;
29161 + struct access_method *access;
29162
29163 /* queue and queue Info */
29164 struct list_head reqQ;
29165 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29166 index 9125bbe..eede5c8 100644
29167 --- a/drivers/block/cpqarray.c
29168 +++ b/drivers/block/cpqarray.c
29169 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29170 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29171 goto Enomem4;
29172 }
29173 - hba[i]->access.set_intr_mask(hba[i], 0);
29174 + hba[i]->access->set_intr_mask(hba[i], 0);
29175 if (request_irq(hba[i]->intr, do_ida_intr,
29176 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29177 {
29178 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29179 add_timer(&hba[i]->timer);
29180
29181 /* Enable IRQ now that spinlock and rate limit timer are set up */
29182 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29183 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29184
29185 for(j=0; j<NWD; j++) {
29186 struct gendisk *disk = ida_gendisk[i][j];
29187 @@ -694,7 +694,7 @@ DBGINFO(
29188 for(i=0; i<NR_PRODUCTS; i++) {
29189 if (board_id == products[i].board_id) {
29190 c->product_name = products[i].product_name;
29191 - c->access = *(products[i].access);
29192 + c->access = products[i].access;
29193 break;
29194 }
29195 }
29196 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29197 hba[ctlr]->intr = intr;
29198 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29199 hba[ctlr]->product_name = products[j].product_name;
29200 - hba[ctlr]->access = *(products[j].access);
29201 + hba[ctlr]->access = products[j].access;
29202 hba[ctlr]->ctlr = ctlr;
29203 hba[ctlr]->board_id = board_id;
29204 hba[ctlr]->pci_dev = NULL; /* not PCI */
29205 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29206
29207 while((c = h->reqQ) != NULL) {
29208 /* Can't do anything if we're busy */
29209 - if (h->access.fifo_full(h) == 0)
29210 + if (h->access->fifo_full(h) == 0)
29211 return;
29212
29213 /* Get the first entry from the request Q */
29214 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29215 h->Qdepth--;
29216
29217 /* Tell the controller to do our bidding */
29218 - h->access.submit_command(h, c);
29219 + h->access->submit_command(h, c);
29220
29221 /* Get onto the completion Q */
29222 addQ(&h->cmpQ, c);
29223 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29224 unsigned long flags;
29225 __u32 a,a1;
29226
29227 - istat = h->access.intr_pending(h);
29228 + istat = h->access->intr_pending(h);
29229 /* Is this interrupt for us? */
29230 if (istat == 0)
29231 return IRQ_NONE;
29232 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29233 */
29234 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29235 if (istat & FIFO_NOT_EMPTY) {
29236 - while((a = h->access.command_completed(h))) {
29237 + while((a = h->access->command_completed(h))) {
29238 a1 = a; a &= ~3;
29239 if ((c = h->cmpQ) == NULL)
29240 {
29241 @@ -1449,11 +1449,11 @@ static int sendcmd(
29242 /*
29243 * Disable interrupt
29244 */
29245 - info_p->access.set_intr_mask(info_p, 0);
29246 + info_p->access->set_intr_mask(info_p, 0);
29247 /* Make sure there is room in the command FIFO */
29248 /* Actually it should be completely empty at this time. */
29249 for (i = 200000; i > 0; i--) {
29250 - temp = info_p->access.fifo_full(info_p);
29251 + temp = info_p->access->fifo_full(info_p);
29252 if (temp != 0) {
29253 break;
29254 }
29255 @@ -1466,7 +1466,7 @@ DBG(
29256 /*
29257 * Send the cmd
29258 */
29259 - info_p->access.submit_command(info_p, c);
29260 + info_p->access->submit_command(info_p, c);
29261 complete = pollcomplete(ctlr);
29262
29263 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29264 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29265 * we check the new geometry. Then turn interrupts back on when
29266 * we're done.
29267 */
29268 - host->access.set_intr_mask(host, 0);
29269 + host->access->set_intr_mask(host, 0);
29270 getgeometry(ctlr);
29271 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29272 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29273
29274 for(i=0; i<NWD; i++) {
29275 struct gendisk *disk = ida_gendisk[ctlr][i];
29276 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29277 /* Wait (up to 2 seconds) for a command to complete */
29278
29279 for (i = 200000; i > 0; i--) {
29280 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29281 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29282 if (done == 0) {
29283 udelay(10); /* a short fixed delay */
29284 } else
29285 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29286 index be73e9d..7fbf140 100644
29287 --- a/drivers/block/cpqarray.h
29288 +++ b/drivers/block/cpqarray.h
29289 @@ -99,7 +99,7 @@ struct ctlr_info {
29290 drv_info_t drv[NWD];
29291 struct proc_dir_entry *proc;
29292
29293 - struct access_method access;
29294 + struct access_method *access;
29295
29296 cmdlist_t *reqQ;
29297 cmdlist_t *cmpQ;
29298 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29299 index b953cc7..e3dc580 100644
29300 --- a/drivers/block/drbd/drbd_int.h
29301 +++ b/drivers/block/drbd/drbd_int.h
29302 @@ -735,7 +735,7 @@ struct drbd_request;
29303 struct drbd_epoch {
29304 struct list_head list;
29305 unsigned int barrier_nr;
29306 - atomic_t epoch_size; /* increased on every request added. */
29307 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29308 atomic_t active; /* increased on every req. added, and dec on every finished. */
29309 unsigned long flags;
29310 };
29311 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29312 void *int_dig_in;
29313 void *int_dig_vv;
29314 wait_queue_head_t seq_wait;
29315 - atomic_t packet_seq;
29316 + atomic_unchecked_t packet_seq;
29317 unsigned int peer_seq;
29318 spinlock_t peer_seq_lock;
29319 unsigned int minor;
29320 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29321
29322 static inline void drbd_tcp_cork(struct socket *sock)
29323 {
29324 - int __user val = 1;
29325 + int val = 1;
29326 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29327 - (char __user *)&val, sizeof(val));
29328 + (char __force_user *)&val, sizeof(val));
29329 }
29330
29331 static inline void drbd_tcp_uncork(struct socket *sock)
29332 {
29333 - int __user val = 0;
29334 + int val = 0;
29335 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29336 - (char __user *)&val, sizeof(val));
29337 + (char __force_user *)&val, sizeof(val));
29338 }
29339
29340 static inline void drbd_tcp_nodelay(struct socket *sock)
29341 {
29342 - int __user val = 1;
29343 + int val = 1;
29344 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29345 - (char __user *)&val, sizeof(val));
29346 + (char __force_user *)&val, sizeof(val));
29347 }
29348
29349 static inline void drbd_tcp_quickack(struct socket *sock)
29350 {
29351 - int __user val = 2;
29352 + int val = 2;
29353 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29354 - (char __user *)&val, sizeof(val));
29355 + (char __force_user *)&val, sizeof(val));
29356 }
29357
29358 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29359 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29360 index f93a032..71c87bf 100644
29361 --- a/drivers/block/drbd/drbd_main.c
29362 +++ b/drivers/block/drbd/drbd_main.c
29363 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29364 p.sector = sector;
29365 p.block_id = block_id;
29366 p.blksize = blksize;
29367 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29368 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29369
29370 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29371 return false;
29372 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29373
29374 p.sector = cpu_to_be64(req->sector);
29375 p.block_id = (unsigned long)req;
29376 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29377 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29378
29379 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29380
29381 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29382 atomic_set(&mdev->unacked_cnt, 0);
29383 atomic_set(&mdev->local_cnt, 0);
29384 atomic_set(&mdev->net_cnt, 0);
29385 - atomic_set(&mdev->packet_seq, 0);
29386 + atomic_set_unchecked(&mdev->packet_seq, 0);
29387 atomic_set(&mdev->pp_in_use, 0);
29388 atomic_set(&mdev->pp_in_use_by_net, 0);
29389 atomic_set(&mdev->rs_sect_in, 0);
29390 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29391 mdev->receiver.t_state);
29392
29393 /* no need to lock it, I'm the only thread alive */
29394 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29395 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29396 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29397 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29398 mdev->al_writ_cnt =
29399 mdev->bm_writ_cnt =
29400 mdev->read_cnt =
29401 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29402 index edb490a..ecd69da 100644
29403 --- a/drivers/block/drbd/drbd_nl.c
29404 +++ b/drivers/block/drbd/drbd_nl.c
29405 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29406 module_put(THIS_MODULE);
29407 }
29408
29409 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29410 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29411
29412 static unsigned short *
29413 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29414 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29415 cn_reply->id.idx = CN_IDX_DRBD;
29416 cn_reply->id.val = CN_VAL_DRBD;
29417
29418 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29419 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29420 cn_reply->ack = 0; /* not used here. */
29421 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29422 (int)((char *)tl - (char *)reply->tag_list);
29423 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29424 cn_reply->id.idx = CN_IDX_DRBD;
29425 cn_reply->id.val = CN_VAL_DRBD;
29426
29427 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29428 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29429 cn_reply->ack = 0; /* not used here. */
29430 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29431 (int)((char *)tl - (char *)reply->tag_list);
29432 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29433 cn_reply->id.idx = CN_IDX_DRBD;
29434 cn_reply->id.val = CN_VAL_DRBD;
29435
29436 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29437 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29438 cn_reply->ack = 0; // not used here.
29439 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29440 (int)((char*)tl - (char*)reply->tag_list);
29441 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29442 cn_reply->id.idx = CN_IDX_DRBD;
29443 cn_reply->id.val = CN_VAL_DRBD;
29444
29445 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29446 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29447 cn_reply->ack = 0; /* not used here. */
29448 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29449 (int)((char *)tl - (char *)reply->tag_list);
29450 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29451 index c74ca2d..860c819 100644
29452 --- a/drivers/block/drbd/drbd_receiver.c
29453 +++ b/drivers/block/drbd/drbd_receiver.c
29454 @@ -898,7 +898,7 @@ retry:
29455 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29456 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29457
29458 - atomic_set(&mdev->packet_seq, 0);
29459 + atomic_set_unchecked(&mdev->packet_seq, 0);
29460 mdev->peer_seq = 0;
29461
29462 if (drbd_send_protocol(mdev) == -1)
29463 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29464 do {
29465 next_epoch = NULL;
29466
29467 - epoch_size = atomic_read(&epoch->epoch_size);
29468 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29469
29470 switch (ev & ~EV_CLEANUP) {
29471 case EV_PUT:
29472 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29473 rv = FE_DESTROYED;
29474 } else {
29475 epoch->flags = 0;
29476 - atomic_set(&epoch->epoch_size, 0);
29477 + atomic_set_unchecked(&epoch->epoch_size, 0);
29478 /* atomic_set(&epoch->active, 0); is already zero */
29479 if (rv == FE_STILL_LIVE)
29480 rv = FE_RECYCLED;
29481 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29482 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29483 drbd_flush(mdev);
29484
29485 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29486 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29487 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29488 if (epoch)
29489 break;
29490 }
29491
29492 epoch = mdev->current_epoch;
29493 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29494 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29495
29496 D_ASSERT(atomic_read(&epoch->active) == 0);
29497 D_ASSERT(epoch->flags == 0);
29498 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29499 }
29500
29501 epoch->flags = 0;
29502 - atomic_set(&epoch->epoch_size, 0);
29503 + atomic_set_unchecked(&epoch->epoch_size, 0);
29504 atomic_set(&epoch->active, 0);
29505
29506 spin_lock(&mdev->epoch_lock);
29507 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29508 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29509 list_add(&epoch->list, &mdev->current_epoch->list);
29510 mdev->current_epoch = epoch;
29511 mdev->epochs++;
29512 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29513 spin_unlock(&mdev->peer_seq_lock);
29514
29515 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29516 - atomic_inc(&mdev->current_epoch->epoch_size);
29517 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29518 return drbd_drain_block(mdev, data_size);
29519 }
29520
29521 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29522
29523 spin_lock(&mdev->epoch_lock);
29524 e->epoch = mdev->current_epoch;
29525 - atomic_inc(&e->epoch->epoch_size);
29526 + atomic_inc_unchecked(&e->epoch->epoch_size);
29527 atomic_inc(&e->epoch->active);
29528 spin_unlock(&mdev->epoch_lock);
29529
29530 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29531 D_ASSERT(list_empty(&mdev->done_ee));
29532
29533 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29534 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29535 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29536 D_ASSERT(list_empty(&mdev->current_epoch->list));
29537 }
29538
29539 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29540 index 3bba655..6151b66 100644
29541 --- a/drivers/block/loop.c
29542 +++ b/drivers/block/loop.c
29543 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29544 mm_segment_t old_fs = get_fs();
29545
29546 set_fs(get_ds());
29547 - bw = file->f_op->write(file, buf, len, &pos);
29548 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29549 set_fs(old_fs);
29550 if (likely(bw == len))
29551 return 0;
29552 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29553 index ea6f632..eafb192 100644
29554 --- a/drivers/char/Kconfig
29555 +++ b/drivers/char/Kconfig
29556 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29557
29558 config DEVKMEM
29559 bool "/dev/kmem virtual device support"
29560 - default y
29561 + default n
29562 + depends on !GRKERNSEC_KMEM
29563 help
29564 Say Y here if you want to support the /dev/kmem device. The
29565 /dev/kmem device is rarely used, but can be used for certain
29566 @@ -581,6 +582,7 @@ config DEVPORT
29567 bool
29568 depends on !M68K
29569 depends on ISA || PCI
29570 + depends on !GRKERNSEC_KMEM
29571 default y
29572
29573 source "drivers/s390/char/Kconfig"
29574 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29575 index 2e04433..22afc64 100644
29576 --- a/drivers/char/agp/frontend.c
29577 +++ b/drivers/char/agp/frontend.c
29578 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29579 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29580 return -EFAULT;
29581
29582 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29583 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29584 return -EFAULT;
29585
29586 client = agp_find_client_by_pid(reserve.pid);
29587 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29588 index 21cb980..f15107c 100644
29589 --- a/drivers/char/genrtc.c
29590 +++ b/drivers/char/genrtc.c
29591 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29592 switch (cmd) {
29593
29594 case RTC_PLL_GET:
29595 + memset(&pll, 0, sizeof(pll));
29596 if (get_rtc_pll(&pll))
29597 return -EINVAL;
29598 else
29599 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29600 index dfd7876..c0b0885 100644
29601 --- a/drivers/char/hpet.c
29602 +++ b/drivers/char/hpet.c
29603 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29604 }
29605
29606 static int
29607 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29608 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29609 struct hpet_info *info)
29610 {
29611 struct hpet_timer __iomem *timer;
29612 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29613 index 2c29942..604c5ba 100644
29614 --- a/drivers/char/ipmi/ipmi_msghandler.c
29615 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29616 @@ -420,7 +420,7 @@ struct ipmi_smi {
29617 struct proc_dir_entry *proc_dir;
29618 char proc_dir_name[10];
29619
29620 - atomic_t stats[IPMI_NUM_STATS];
29621 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29622
29623 /*
29624 * run_to_completion duplicate of smb_info, smi_info
29625 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29626
29627
29628 #define ipmi_inc_stat(intf, stat) \
29629 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29630 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29631 #define ipmi_get_stat(intf, stat) \
29632 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29633 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29634
29635 static int is_lan_addr(struct ipmi_addr *addr)
29636 {
29637 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29638 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29639 init_waitqueue_head(&intf->waitq);
29640 for (i = 0; i < IPMI_NUM_STATS; i++)
29641 - atomic_set(&intf->stats[i], 0);
29642 + atomic_set_unchecked(&intf->stats[i], 0);
29643
29644 intf->proc_dir = NULL;
29645
29646 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29647 index 83f85cf..279e63f 100644
29648 --- a/drivers/char/ipmi/ipmi_si_intf.c
29649 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29650 @@ -275,7 +275,7 @@ struct smi_info {
29651 unsigned char slave_addr;
29652
29653 /* Counters and things for the proc filesystem. */
29654 - atomic_t stats[SI_NUM_STATS];
29655 + atomic_unchecked_t stats[SI_NUM_STATS];
29656
29657 struct task_struct *thread;
29658
29659 @@ -284,9 +284,9 @@ struct smi_info {
29660 };
29661
29662 #define smi_inc_stat(smi, stat) \
29663 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29664 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29665 #define smi_get_stat(smi, stat) \
29666 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29667 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29668
29669 #define SI_MAX_PARMS 4
29670
29671 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29672 atomic_set(&new_smi->req_events, 0);
29673 new_smi->run_to_completion = 0;
29674 for (i = 0; i < SI_NUM_STATS; i++)
29675 - atomic_set(&new_smi->stats[i], 0);
29676 + atomic_set_unchecked(&new_smi->stats[i], 0);
29677
29678 new_smi->interrupt_disabled = 1;
29679 atomic_set(&new_smi->stop_operation, 0);
29680 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29681 index 47ff7e4..0c7d340 100644
29682 --- a/drivers/char/mbcs.c
29683 +++ b/drivers/char/mbcs.c
29684 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29685 return 0;
29686 }
29687
29688 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29689 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29690 {
29691 .part_num = MBCS_PART_NUM,
29692 .mfg_num = MBCS_MFG_NUM,
29693 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29694 index e5eedfa..fcab50ea 100644
29695 --- a/drivers/char/mem.c
29696 +++ b/drivers/char/mem.c
29697 @@ -18,6 +18,7 @@
29698 #include <linux/raw.h>
29699 #include <linux/tty.h>
29700 #include <linux/capability.h>
29701 +#include <linux/security.h>
29702 #include <linux/ptrace.h>
29703 #include <linux/device.h>
29704 #include <linux/highmem.h>
29705 @@ -37,6 +38,10 @@
29706
29707 #define DEVPORT_MINOR 4
29708
29709 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29710 +extern const struct file_operations grsec_fops;
29711 +#endif
29712 +
29713 static inline unsigned long size_inside_page(unsigned long start,
29714 unsigned long size)
29715 {
29716 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29717
29718 while (cursor < to) {
29719 if (!devmem_is_allowed(pfn)) {
29720 +#ifdef CONFIG_GRKERNSEC_KMEM
29721 + gr_handle_mem_readwrite(from, to);
29722 +#else
29723 printk(KERN_INFO
29724 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29725 current->comm, from, to);
29726 +#endif
29727 return 0;
29728 }
29729 cursor += PAGE_SIZE;
29730 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29731 }
29732 return 1;
29733 }
29734 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29735 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29736 +{
29737 + return 0;
29738 +}
29739 #else
29740 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29741 {
29742 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29743
29744 while (count > 0) {
29745 unsigned long remaining;
29746 + char *temp;
29747
29748 sz = size_inside_page(p, count);
29749
29750 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29751 if (!ptr)
29752 return -EFAULT;
29753
29754 - remaining = copy_to_user(buf, ptr, sz);
29755 +#ifdef CONFIG_PAX_USERCOPY
29756 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29757 + if (!temp) {
29758 + unxlate_dev_mem_ptr(p, ptr);
29759 + return -ENOMEM;
29760 + }
29761 + memcpy(temp, ptr, sz);
29762 +#else
29763 + temp = ptr;
29764 +#endif
29765 +
29766 + remaining = copy_to_user(buf, temp, sz);
29767 +
29768 +#ifdef CONFIG_PAX_USERCOPY
29769 + kfree(temp);
29770 +#endif
29771 +
29772 unxlate_dev_mem_ptr(p, ptr);
29773 if (remaining)
29774 return -EFAULT;
29775 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29776 size_t count, loff_t *ppos)
29777 {
29778 unsigned long p = *ppos;
29779 - ssize_t low_count, read, sz;
29780 + ssize_t low_count, read, sz, err = 0;
29781 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29782 - int err = 0;
29783
29784 read = 0;
29785 if (p < (unsigned long) high_memory) {
29786 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29787 }
29788 #endif
29789 while (low_count > 0) {
29790 + char *temp;
29791 +
29792 sz = size_inside_page(p, low_count);
29793
29794 /*
29795 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29796 */
29797 kbuf = xlate_dev_kmem_ptr((char *)p);
29798
29799 - if (copy_to_user(buf, kbuf, sz))
29800 +#ifdef CONFIG_PAX_USERCOPY
29801 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29802 + if (!temp)
29803 + return -ENOMEM;
29804 + memcpy(temp, kbuf, sz);
29805 +#else
29806 + temp = kbuf;
29807 +#endif
29808 +
29809 + err = copy_to_user(buf, temp, sz);
29810 +
29811 +#ifdef CONFIG_PAX_USERCOPY
29812 + kfree(temp);
29813 +#endif
29814 +
29815 + if (err)
29816 return -EFAULT;
29817 buf += sz;
29818 p += sz;
29819 @@ -833,6 +880,9 @@ static const struct memdev {
29820 #ifdef CONFIG_CRASH_DUMP
29821 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29822 #endif
29823 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29824 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29825 +#endif
29826 };
29827
29828 static int memory_open(struct inode *inode, struct file *filp)
29829 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29830 index 9df78e2..01ba9ae 100644
29831 --- a/drivers/char/nvram.c
29832 +++ b/drivers/char/nvram.c
29833 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29834
29835 spin_unlock_irq(&rtc_lock);
29836
29837 - if (copy_to_user(buf, contents, tmp - contents))
29838 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29839 return -EFAULT;
29840
29841 *ppos = i;
29842 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29843 index 0a484b4..f48ccd1 100644
29844 --- a/drivers/char/pcmcia/synclink_cs.c
29845 +++ b/drivers/char/pcmcia/synclink_cs.c
29846 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29847
29848 if (debug_level >= DEBUG_LEVEL_INFO)
29849 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29850 - __FILE__,__LINE__, info->device_name, port->count);
29851 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29852
29853 - WARN_ON(!port->count);
29854 + WARN_ON(!atomic_read(&port->count));
29855
29856 if (tty_port_close_start(port, tty, filp) == 0)
29857 goto cleanup;
29858 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29859 cleanup:
29860 if (debug_level >= DEBUG_LEVEL_INFO)
29861 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29862 - tty->driver->name, port->count);
29863 + tty->driver->name, atomic_read(&port->count));
29864 }
29865
29866 /* Wait until the transmitter is empty.
29867 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29868
29869 if (debug_level >= DEBUG_LEVEL_INFO)
29870 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29871 - __FILE__,__LINE__,tty->driver->name, port->count);
29872 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29873
29874 /* If port is closing, signal caller to try again */
29875 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29876 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29877 goto cleanup;
29878 }
29879 spin_lock(&port->lock);
29880 - port->count++;
29881 + atomic_inc(&port->count);
29882 spin_unlock(&port->lock);
29883 spin_unlock_irqrestore(&info->netlock, flags);
29884
29885 - if (port->count == 1) {
29886 + if (atomic_read(&port->count) == 1) {
29887 /* 1st open on this device, init hardware */
29888 retval = startup(info, tty);
29889 if (retval < 0)
29890 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29891 unsigned short new_crctype;
29892
29893 /* return error if TTY interface open */
29894 - if (info->port.count)
29895 + if (atomic_read(&info->port.count))
29896 return -EBUSY;
29897
29898 switch (encoding)
29899 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29900
29901 /* arbitrate between network and tty opens */
29902 spin_lock_irqsave(&info->netlock, flags);
29903 - if (info->port.count != 0 || info->netcount != 0) {
29904 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29905 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29906 spin_unlock_irqrestore(&info->netlock, flags);
29907 return -EBUSY;
29908 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29909 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29910
29911 /* return error if TTY interface open */
29912 - if (info->port.count)
29913 + if (atomic_read(&info->port.count))
29914 return -EBUSY;
29915
29916 if (cmd != SIOCWANDEV)
29917 diff --git a/drivers/char/random.c b/drivers/char/random.c
29918 index b86eae9..4192a7a 100644
29919 --- a/drivers/char/random.c
29920 +++ b/drivers/char/random.c
29921 @@ -272,8 +272,13 @@
29922 /*
29923 * Configuration information
29924 */
29925 +#ifdef CONFIG_GRKERNSEC_RANDNET
29926 +#define INPUT_POOL_WORDS 512
29927 +#define OUTPUT_POOL_WORDS 128
29928 +#else
29929 #define INPUT_POOL_WORDS 128
29930 #define OUTPUT_POOL_WORDS 32
29931 +#endif
29932 #define SEC_XFER_SIZE 512
29933 #define EXTRACT_SIZE 10
29934
29935 @@ -313,10 +318,17 @@ static struct poolinfo {
29936 int poolwords;
29937 int tap1, tap2, tap3, tap4, tap5;
29938 } poolinfo_table[] = {
29939 +#ifdef CONFIG_GRKERNSEC_RANDNET
29940 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29941 + { 512, 411, 308, 208, 104, 1 },
29942 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29943 + { 128, 103, 76, 51, 25, 1 },
29944 +#else
29945 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29946 { 128, 103, 76, 51, 25, 1 },
29947 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29948 { 32, 26, 20, 14, 7, 1 },
29949 +#endif
29950 #if 0
29951 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29952 { 2048, 1638, 1231, 819, 411, 1 },
29953 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29954 input_rotate += i ? 7 : 14;
29955 }
29956
29957 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29958 - ACCESS_ONCE(r->add_ptr) = i;
29959 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29960 + ACCESS_ONCE_RW(r->add_ptr) = i;
29961 smp_wmb();
29962
29963 if (out)
29964 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29965 }
29966 #endif
29967
29968 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29969 +u64 latent_entropy;
29970 +
29971 +__init void transfer_latent_entropy(void)
29972 +{
29973 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29974 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29975 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29976 +}
29977 +#endif
29978 +
29979 /*********************************************************************
29980 *
29981 * Entropy extraction routines
29982 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29983
29984 extract_buf(r, tmp);
29985 i = min_t(int, nbytes, EXTRACT_SIZE);
29986 - if (copy_to_user(buf, tmp, i)) {
29987 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29988 ret = -EFAULT;
29989 break;
29990 }
29991 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29992 #include <linux/sysctl.h>
29993
29994 static int min_read_thresh = 8, min_write_thresh;
29995 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29996 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29997 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29998 static char sysctl_bootid[16];
29999
30000 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30001 index f877805..403375a 100644
30002 --- a/drivers/char/sonypi.c
30003 +++ b/drivers/char/sonypi.c
30004 @@ -54,6 +54,7 @@
30005
30006 #include <asm/uaccess.h>
30007 #include <asm/io.h>
30008 +#include <asm/local.h>
30009
30010 #include <linux/sonypi.h>
30011
30012 @@ -490,7 +491,7 @@ static struct sonypi_device {
30013 spinlock_t fifo_lock;
30014 wait_queue_head_t fifo_proc_list;
30015 struct fasync_struct *fifo_async;
30016 - int open_count;
30017 + local_t open_count;
30018 int model;
30019 struct input_dev *input_jog_dev;
30020 struct input_dev *input_key_dev;
30021 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30022 static int sonypi_misc_release(struct inode *inode, struct file *file)
30023 {
30024 mutex_lock(&sonypi_device.lock);
30025 - sonypi_device.open_count--;
30026 + local_dec(&sonypi_device.open_count);
30027 mutex_unlock(&sonypi_device.lock);
30028 return 0;
30029 }
30030 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30031 {
30032 mutex_lock(&sonypi_device.lock);
30033 /* Flush input queue on first open */
30034 - if (!sonypi_device.open_count)
30035 + if (!local_read(&sonypi_device.open_count))
30036 kfifo_reset(&sonypi_device.fifo);
30037 - sonypi_device.open_count++;
30038 + local_inc(&sonypi_device.open_count);
30039 mutex_unlock(&sonypi_device.lock);
30040
30041 return 0;
30042 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30043 index 4dc8024..90108d1 100644
30044 --- a/drivers/char/tpm/tpm.c
30045 +++ b/drivers/char/tpm/tpm.c
30046 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30047 chip->vendor.req_complete_val)
30048 goto out_recv;
30049
30050 - if ((status == chip->vendor.req_canceled)) {
30051 + if (status == chip->vendor.req_canceled) {
30052 dev_err(chip->dev, "Operation Canceled\n");
30053 rc = -ECANCELED;
30054 goto out;
30055 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30056 index 0636520..169c1d0 100644
30057 --- a/drivers/char/tpm/tpm_bios.c
30058 +++ b/drivers/char/tpm/tpm_bios.c
30059 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30060 event = addr;
30061
30062 if ((event->event_type == 0 && event->event_size == 0) ||
30063 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30064 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30065 return NULL;
30066
30067 return addr;
30068 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30069 return NULL;
30070
30071 if ((event->event_type == 0 && event->event_size == 0) ||
30072 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30073 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30074 return NULL;
30075
30076 (*pos)++;
30077 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30078 int i;
30079
30080 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30081 - seq_putc(m, data[i]);
30082 + if (!seq_putc(m, data[i]))
30083 + return -EFAULT;
30084
30085 return 0;
30086 }
30087 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30088 log->bios_event_log_end = log->bios_event_log + len;
30089
30090 virt = acpi_os_map_memory(start, len);
30091 + if (!virt) {
30092 + kfree(log->bios_event_log);
30093 + log->bios_event_log = NULL;
30094 + return -EFAULT;
30095 + }
30096
30097 - memcpy(log->bios_event_log, virt, len);
30098 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30099
30100 acpi_os_unmap_memory(virt, len);
30101 return 0;
30102 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30103 index cdf2f54..e55c197 100644
30104 --- a/drivers/char/virtio_console.c
30105 +++ b/drivers/char/virtio_console.c
30106 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30107 if (to_user) {
30108 ssize_t ret;
30109
30110 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30111 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30112 if (ret)
30113 return -EFAULT;
30114 } else {
30115 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30116 if (!port_has_data(port) && !port->host_connected)
30117 return 0;
30118
30119 - return fill_readbuf(port, ubuf, count, true);
30120 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30121 }
30122
30123 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30124 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30125 index e164c55..3aabb50 100644
30126 --- a/drivers/edac/edac_pci_sysfs.c
30127 +++ b/drivers/edac/edac_pci_sysfs.c
30128 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30129 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30130 static int edac_pci_poll_msec = 1000; /* one second workq period */
30131
30132 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30133 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30134 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30135 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30136
30137 static struct kobject *edac_pci_top_main_kobj;
30138 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30139 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30140 edac_printk(KERN_CRIT, EDAC_PCI,
30141 "Signaled System Error on %s\n",
30142 pci_name(dev));
30143 - atomic_inc(&pci_nonparity_count);
30144 + atomic_inc_unchecked(&pci_nonparity_count);
30145 }
30146
30147 if (status & (PCI_STATUS_PARITY)) {
30148 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30149 "Master Data Parity Error on %s\n",
30150 pci_name(dev));
30151
30152 - atomic_inc(&pci_parity_count);
30153 + atomic_inc_unchecked(&pci_parity_count);
30154 }
30155
30156 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30157 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30158 "Detected Parity Error on %s\n",
30159 pci_name(dev));
30160
30161 - atomic_inc(&pci_parity_count);
30162 + atomic_inc_unchecked(&pci_parity_count);
30163 }
30164 }
30165
30166 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30167 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30168 "Signaled System Error on %s\n",
30169 pci_name(dev));
30170 - atomic_inc(&pci_nonparity_count);
30171 + atomic_inc_unchecked(&pci_nonparity_count);
30172 }
30173
30174 if (status & (PCI_STATUS_PARITY)) {
30175 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30176 "Master Data Parity Error on "
30177 "%s\n", pci_name(dev));
30178
30179 - atomic_inc(&pci_parity_count);
30180 + atomic_inc_unchecked(&pci_parity_count);
30181 }
30182
30183 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30184 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30185 "Detected Parity Error on %s\n",
30186 pci_name(dev));
30187
30188 - atomic_inc(&pci_parity_count);
30189 + atomic_inc_unchecked(&pci_parity_count);
30190 }
30191 }
30192 }
30193 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30194 if (!check_pci_errors)
30195 return;
30196
30197 - before_count = atomic_read(&pci_parity_count);
30198 + before_count = atomic_read_unchecked(&pci_parity_count);
30199
30200 /* scan all PCI devices looking for a Parity Error on devices and
30201 * bridges.
30202 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30203 /* Only if operator has selected panic on PCI Error */
30204 if (edac_pci_get_panic_on_pe()) {
30205 /* If the count is different 'after' from 'before' */
30206 - if (before_count != atomic_read(&pci_parity_count))
30207 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30208 panic("EDAC: PCI Parity Error");
30209 }
30210 }
30211 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30212 index 8c87a5e..a19cbd7 100644
30213 --- a/drivers/edac/mce_amd.h
30214 +++ b/drivers/edac/mce_amd.h
30215 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30216 struct amd_decoder_ops {
30217 bool (*dc_mce)(u16, u8);
30218 bool (*ic_mce)(u16, u8);
30219 -};
30220 +} __no_const;
30221
30222 void amd_report_gart_errors(bool);
30223 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30224 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30225 index 57ea7f4..789e3c3 100644
30226 --- a/drivers/firewire/core-card.c
30227 +++ b/drivers/firewire/core-card.c
30228 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30229
30230 void fw_core_remove_card(struct fw_card *card)
30231 {
30232 - struct fw_card_driver dummy_driver = dummy_driver_template;
30233 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30234
30235 card->driver->update_phy_reg(card, 4,
30236 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30237 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30238 index f8d2287..5aaf4db 100644
30239 --- a/drivers/firewire/core-cdev.c
30240 +++ b/drivers/firewire/core-cdev.c
30241 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30242 int ret;
30243
30244 if ((request->channels == 0 && request->bandwidth == 0) ||
30245 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30246 - request->bandwidth < 0)
30247 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30248 return -EINVAL;
30249
30250 r = kmalloc(sizeof(*r), GFP_KERNEL);
30251 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30252 index 87d6f2d..5bf9d90 100644
30253 --- a/drivers/firewire/core-transaction.c
30254 +++ b/drivers/firewire/core-transaction.c
30255 @@ -37,6 +37,7 @@
30256 #include <linux/timer.h>
30257 #include <linux/types.h>
30258 #include <linux/workqueue.h>
30259 +#include <linux/sched.h>
30260
30261 #include <asm/byteorder.h>
30262
30263 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30264 index 515a42c..5ecf3ba 100644
30265 --- a/drivers/firewire/core.h
30266 +++ b/drivers/firewire/core.h
30267 @@ -111,6 +111,7 @@ struct fw_card_driver {
30268
30269 int (*stop_iso)(struct fw_iso_context *ctx);
30270 };
30271 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30272
30273 void fw_card_initialize(struct fw_card *card,
30274 const struct fw_card_driver *driver, struct device *device);
30275 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30276 index b298158..7ed8432 100644
30277 --- a/drivers/firmware/dmi_scan.c
30278 +++ b/drivers/firmware/dmi_scan.c
30279 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30280 }
30281 }
30282 else {
30283 - /*
30284 - * no iounmap() for that ioremap(); it would be a no-op, but
30285 - * it's so early in setup that sucker gets confused into doing
30286 - * what it shouldn't if we actually call it.
30287 - */
30288 p = dmi_ioremap(0xF0000, 0x10000);
30289 if (p == NULL)
30290 goto error;
30291 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30292 if (buf == NULL)
30293 return -1;
30294
30295 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30296 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30297
30298 iounmap(buf);
30299 return 0;
30300 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30301 index 82d5c20..44a7177 100644
30302 --- a/drivers/gpio/gpio-vr41xx.c
30303 +++ b/drivers/gpio/gpio-vr41xx.c
30304 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30305 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30306 maskl, pendl, maskh, pendh);
30307
30308 - atomic_inc(&irq_err_count);
30309 + atomic_inc_unchecked(&irq_err_count);
30310
30311 return -EINVAL;
30312 }
30313 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30314 index 3252e70..b5314ace 100644
30315 --- a/drivers/gpu/drm/drm_crtc_helper.c
30316 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30317 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30318 struct drm_crtc *tmp;
30319 int crtc_mask = 1;
30320
30321 - WARN(!crtc, "checking null crtc?\n");
30322 + BUG_ON(!crtc);
30323
30324 dev = crtc->dev;
30325
30326 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30327 index 9238de4..a27c72a 100644
30328 --- a/drivers/gpu/drm/drm_drv.c
30329 +++ b/drivers/gpu/drm/drm_drv.c
30330 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30331 /**
30332 * Copy and IOCTL return string to user space
30333 */
30334 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30335 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30336 {
30337 int len;
30338
30339 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30340 return -ENODEV;
30341
30342 atomic_inc(&dev->ioctl_count);
30343 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30344 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30345 ++file_priv->ioctl_count;
30346
30347 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30348 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30349 index 5062eec..4e3e51f 100644
30350 --- a/drivers/gpu/drm/drm_fops.c
30351 +++ b/drivers/gpu/drm/drm_fops.c
30352 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30353 }
30354
30355 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30356 - atomic_set(&dev->counts[i], 0);
30357 + atomic_set_unchecked(&dev->counts[i], 0);
30358
30359 dev->sigdata.lock = NULL;
30360
30361 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30362
30363 retcode = drm_open_helper(inode, filp, dev);
30364 if (!retcode) {
30365 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30366 - if (!dev->open_count++)
30367 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30368 + if (local_inc_return(&dev->open_count) == 1)
30369 retcode = drm_setup(dev);
30370 }
30371 if (!retcode) {
30372 @@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30373
30374 mutex_lock(&drm_global_mutex);
30375
30376 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30377 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30378
30379 if (dev->driver->preclose)
30380 dev->driver->preclose(dev, file_priv);
30381 @@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30382 * Begin inline drm_release
30383 */
30384
30385 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30386 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30387 task_pid_nr(current),
30388 (long)old_encode_dev(file_priv->minor->device),
30389 - dev->open_count);
30390 + local_read(&dev->open_count));
30391
30392 /* Release any auth tokens that might point to this file_priv,
30393 (do that under the drm_global_mutex) */
30394 @@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30395 * End inline drm_release
30396 */
30397
30398 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30399 - if (!--dev->open_count) {
30400 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30401 + if (local_dec_and_test(&dev->open_count)) {
30402 if (atomic_read(&dev->ioctl_count)) {
30403 DRM_ERROR("Device busy: %d\n",
30404 atomic_read(&dev->ioctl_count));
30405 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30406 index c87dc96..326055d 100644
30407 --- a/drivers/gpu/drm/drm_global.c
30408 +++ b/drivers/gpu/drm/drm_global.c
30409 @@ -36,7 +36,7 @@
30410 struct drm_global_item {
30411 struct mutex mutex;
30412 void *object;
30413 - int refcount;
30414 + atomic_t refcount;
30415 };
30416
30417 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30418 @@ -49,7 +49,7 @@ void drm_global_init(void)
30419 struct drm_global_item *item = &glob[i];
30420 mutex_init(&item->mutex);
30421 item->object = NULL;
30422 - item->refcount = 0;
30423 + atomic_set(&item->refcount, 0);
30424 }
30425 }
30426
30427 @@ -59,7 +59,7 @@ void drm_global_release(void)
30428 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30429 struct drm_global_item *item = &glob[i];
30430 BUG_ON(item->object != NULL);
30431 - BUG_ON(item->refcount != 0);
30432 + BUG_ON(atomic_read(&item->refcount) != 0);
30433 }
30434 }
30435
30436 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30437 void *object;
30438
30439 mutex_lock(&item->mutex);
30440 - if (item->refcount == 0) {
30441 + if (atomic_read(&item->refcount) == 0) {
30442 item->object = kzalloc(ref->size, GFP_KERNEL);
30443 if (unlikely(item->object == NULL)) {
30444 ret = -ENOMEM;
30445 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30446 goto out_err;
30447
30448 }
30449 - ++item->refcount;
30450 + atomic_inc(&item->refcount);
30451 ref->object = item->object;
30452 object = item->object;
30453 mutex_unlock(&item->mutex);
30454 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30455 struct drm_global_item *item = &glob[ref->global_type];
30456
30457 mutex_lock(&item->mutex);
30458 - BUG_ON(item->refcount == 0);
30459 + BUG_ON(atomic_read(&item->refcount) == 0);
30460 BUG_ON(ref->object != item->object);
30461 - if (--item->refcount == 0) {
30462 + if (atomic_dec_and_test(&item->refcount)) {
30463 ref->release(ref);
30464 item->object = NULL;
30465 }
30466 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30467 index 8928edb..0c79258 100644
30468 --- a/drivers/gpu/drm/drm_info.c
30469 +++ b/drivers/gpu/drm/drm_info.c
30470 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30471 struct drm_local_map *map;
30472 struct drm_map_list *r_list;
30473
30474 - /* Hardcoded from _DRM_FRAME_BUFFER,
30475 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30476 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30477 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30478 + static const char * const types[] = {
30479 + [_DRM_FRAME_BUFFER] = "FB",
30480 + [_DRM_REGISTERS] = "REG",
30481 + [_DRM_SHM] = "SHM",
30482 + [_DRM_AGP] = "AGP",
30483 + [_DRM_SCATTER_GATHER] = "SG",
30484 + [_DRM_CONSISTENT] = "PCI",
30485 + [_DRM_GEM] = "GEM" };
30486 const char *type;
30487 int i;
30488
30489 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30490 map = r_list->map;
30491 if (!map)
30492 continue;
30493 - if (map->type < 0 || map->type > 5)
30494 + if (map->type >= ARRAY_SIZE(types))
30495 type = "??";
30496 else
30497 type = types[map->type];
30498 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30499 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30500 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30501 vma->vm_flags & VM_IO ? 'i' : '-',
30502 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30503 + 0);
30504 +#else
30505 vma->vm_pgoff);
30506 +#endif
30507
30508 #if defined(__i386__)
30509 pgprot = pgprot_val(vma->vm_page_prot);
30510 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30511 index 637fcc3..e890b33 100644
30512 --- a/drivers/gpu/drm/drm_ioc32.c
30513 +++ b/drivers/gpu/drm/drm_ioc32.c
30514 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30515 request = compat_alloc_user_space(nbytes);
30516 if (!access_ok(VERIFY_WRITE, request, nbytes))
30517 return -EFAULT;
30518 - list = (struct drm_buf_desc *) (request + 1);
30519 + list = (struct drm_buf_desc __user *) (request + 1);
30520
30521 if (__put_user(count, &request->count)
30522 || __put_user(list, &request->list))
30523 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30524 request = compat_alloc_user_space(nbytes);
30525 if (!access_ok(VERIFY_WRITE, request, nbytes))
30526 return -EFAULT;
30527 - list = (struct drm_buf_pub *) (request + 1);
30528 + list = (struct drm_buf_pub __user *) (request + 1);
30529
30530 if (__put_user(count, &request->count)
30531 || __put_user(list, &request->list))
30532 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30533 index 64a62c6..ceab35e 100644
30534 --- a/drivers/gpu/drm/drm_ioctl.c
30535 +++ b/drivers/gpu/drm/drm_ioctl.c
30536 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30537 stats->data[i].value =
30538 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30539 else
30540 - stats->data[i].value = atomic_read(&dev->counts[i]);
30541 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30542 stats->data[i].type = dev->types[i];
30543 }
30544
30545 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30546 index 3203955..c8090af 100644
30547 --- a/drivers/gpu/drm/drm_lock.c
30548 +++ b/drivers/gpu/drm/drm_lock.c
30549 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30550 if (drm_lock_take(&master->lock, lock->context)) {
30551 master->lock.file_priv = file_priv;
30552 master->lock.lock_time = jiffies;
30553 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30554 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30555 break; /* Got lock */
30556 }
30557
30558 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30559 return -EINVAL;
30560 }
30561
30562 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30563 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30564
30565 if (drm_lock_free(&master->lock, lock->context)) {
30566 /* FIXME: Should really bail out here. */
30567 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30568 index 21bcd4a..8e074e0 100644
30569 --- a/drivers/gpu/drm/drm_stub.c
30570 +++ b/drivers/gpu/drm/drm_stub.c
30571 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30572
30573 drm_device_set_unplugged(dev);
30574
30575 - if (dev->open_count == 0) {
30576 + if (local_read(&dev->open_count) == 0) {
30577 drm_put_dev(dev);
30578 }
30579 mutex_unlock(&drm_global_mutex);
30580 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30581 index 463ec68..f5bd2b5 100644
30582 --- a/drivers/gpu/drm/i810/i810_dma.c
30583 +++ b/drivers/gpu/drm/i810/i810_dma.c
30584 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30585 dma->buflist[vertex->idx],
30586 vertex->discard, vertex->used);
30587
30588 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30589 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30590 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30591 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30592 sarea_priv->last_enqueue = dev_priv->counter - 1;
30593 sarea_priv->last_dispatch = (int)hw_status[5];
30594
30595 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30596 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30597 mc->last_render);
30598
30599 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30600 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30601 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30602 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30603 sarea_priv->last_enqueue = dev_priv->counter - 1;
30604 sarea_priv->last_dispatch = (int)hw_status[5];
30605
30606 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30607 index 6e0acad..93c8289 100644
30608 --- a/drivers/gpu/drm/i810/i810_drv.h
30609 +++ b/drivers/gpu/drm/i810/i810_drv.h
30610 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30611 int page_flipping;
30612
30613 wait_queue_head_t irq_queue;
30614 - atomic_t irq_received;
30615 - atomic_t irq_emitted;
30616 + atomic_unchecked_t irq_received;
30617 + atomic_unchecked_t irq_emitted;
30618
30619 int front_offset;
30620 } drm_i810_private_t;
30621 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30622 index 359f6e8..ada68fd 100644
30623 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30624 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30625 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30626 I915_READ(GTIMR));
30627 }
30628 seq_printf(m, "Interrupts received: %d\n",
30629 - atomic_read(&dev_priv->irq_received));
30630 + atomic_read_unchecked(&dev_priv->irq_received));
30631 for (i = 0; i < I915_NUM_RINGS; i++) {
30632 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30633 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30634 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30635 index 914c0df..d47d380 100644
30636 --- a/drivers/gpu/drm/i915/i915_dma.c
30637 +++ b/drivers/gpu/drm/i915/i915_dma.c
30638 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30639 bool can_switch;
30640
30641 spin_lock(&dev->count_lock);
30642 - can_switch = (dev->open_count == 0);
30643 + can_switch = (local_read(&dev->open_count) == 0);
30644 spin_unlock(&dev->count_lock);
30645 return can_switch;
30646 }
30647 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30648 index 627fe35..c9a7346 100644
30649 --- a/drivers/gpu/drm/i915/i915_drv.h
30650 +++ b/drivers/gpu/drm/i915/i915_drv.h
30651 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30652 /* render clock increase/decrease */
30653 /* display clock increase/decrease */
30654 /* pll clock increase/decrease */
30655 -};
30656 +} __no_const;
30657
30658 struct drm_i915_gt_funcs {
30659 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30660 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30661 -};
30662 +} __no_const;
30663
30664 struct intel_device_info {
30665 u8 gen;
30666 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30667 int current_page;
30668 int page_flipping;
30669
30670 - atomic_t irq_received;
30671 + atomic_unchecked_t irq_received;
30672
30673 /* protects the irq masks */
30674 spinlock_t irq_lock;
30675 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30676 * will be page flipped away on the next vblank. When it
30677 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30678 */
30679 - atomic_t pending_flip;
30680 + atomic_unchecked_t pending_flip;
30681 };
30682
30683 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30684 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30685 struct drm_i915_private *dev_priv, unsigned port);
30686 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30687 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30688 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30689 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30690 {
30691 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30692 }
30693 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30694 index ff2819e..6b5997b 100644
30695 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30696 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30697 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30698 i915_gem_clflush_object(obj);
30699
30700 if (obj->base.pending_write_domain)
30701 - cd->flips |= atomic_read(&obj->pending_flip);
30702 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30703
30704 /* The actual obj->write_domain will be updated with
30705 * pending_write_domain after we emit the accumulated flush for all
30706 @@ -906,9 +906,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30707
30708 static int
30709 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30710 - int count)
30711 + unsigned int count)
30712 {
30713 - int i;
30714 + unsigned int i;
30715
30716 for (i = 0; i < count; i++) {
30717 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30718 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30719 index 73fa3e1..ab2e9b9 100644
30720 --- a/drivers/gpu/drm/i915/i915_irq.c
30721 +++ b/drivers/gpu/drm/i915/i915_irq.c
30722 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30723 u32 pipe_stats[I915_MAX_PIPES];
30724 bool blc_event;
30725
30726 - atomic_inc(&dev_priv->irq_received);
30727 + atomic_inc_unchecked(&dev_priv->irq_received);
30728
30729 while (true) {
30730 iir = I915_READ(VLV_IIR);
30731 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30732 irqreturn_t ret = IRQ_NONE;
30733 int i;
30734
30735 - atomic_inc(&dev_priv->irq_received);
30736 + atomic_inc_unchecked(&dev_priv->irq_received);
30737
30738 /* disable master interrupt before clearing iir */
30739 de_ier = I915_READ(DEIER);
30740 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30741 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30742 u32 hotplug_mask;
30743
30744 - atomic_inc(&dev_priv->irq_received);
30745 + atomic_inc_unchecked(&dev_priv->irq_received);
30746
30747 /* disable master interrupt before clearing iir */
30748 de_ier = I915_READ(DEIER);
30749 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30750 {
30751 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30752
30753 - atomic_set(&dev_priv->irq_received, 0);
30754 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30755
30756 I915_WRITE(HWSTAM, 0xeffe);
30757
30758 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30759 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30760 int pipe;
30761
30762 - atomic_set(&dev_priv->irq_received, 0);
30763 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30764
30765 /* VLV magic */
30766 I915_WRITE(VLV_IMR, 0);
30767 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30768 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30769 int pipe;
30770
30771 - atomic_set(&dev_priv->irq_received, 0);
30772 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30773
30774 for_each_pipe(pipe)
30775 I915_WRITE(PIPESTAT(pipe), 0);
30776 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30777 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30778 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30779
30780 - atomic_inc(&dev_priv->irq_received);
30781 + atomic_inc_unchecked(&dev_priv->irq_received);
30782
30783 iir = I915_READ16(IIR);
30784 if (iir == 0)
30785 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30786 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30787 int pipe;
30788
30789 - atomic_set(&dev_priv->irq_received, 0);
30790 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30791
30792 if (I915_HAS_HOTPLUG(dev)) {
30793 I915_WRITE(PORT_HOTPLUG_EN, 0);
30794 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30795 };
30796 int pipe, ret = IRQ_NONE;
30797
30798 - atomic_inc(&dev_priv->irq_received);
30799 + atomic_inc_unchecked(&dev_priv->irq_received);
30800
30801 iir = I915_READ(IIR);
30802 do {
30803 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30804 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30805 int pipe;
30806
30807 - atomic_set(&dev_priv->irq_received, 0);
30808 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30809
30810 I915_WRITE(PORT_HOTPLUG_EN, 0);
30811 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30812 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30813 int irq_received;
30814 int ret = IRQ_NONE, pipe;
30815
30816 - atomic_inc(&dev_priv->irq_received);
30817 + atomic_inc_unchecked(&dev_priv->irq_received);
30818
30819 iir = I915_READ(IIR);
30820
30821 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30822 index b634f6f..84bb8ba 100644
30823 --- a/drivers/gpu/drm/i915/intel_display.c
30824 +++ b/drivers/gpu/drm/i915/intel_display.c
30825 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30826
30827 wait_event(dev_priv->pending_flip_queue,
30828 atomic_read(&dev_priv->mm.wedged) ||
30829 - atomic_read(&obj->pending_flip) == 0);
30830 + atomic_read_unchecked(&obj->pending_flip) == 0);
30831
30832 /* Big Hammer, we also need to ensure that any pending
30833 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30834 @@ -6168,7 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30835
30836 obj = work->old_fb_obj;
30837
30838 - atomic_clear_mask(1 << intel_crtc->plane,
30839 + atomic_clear_mask_unchecked(1 << intel_crtc->plane,
30840 &obj->pending_flip.counter);
30841
30842 wake_up(&dev_priv->pending_flip_queue);
30843 @@ -6515,7 +6515,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30844 /* Block clients from rendering to the new back buffer until
30845 * the flip occurs and the object is no longer visible.
30846 */
30847 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30848 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30849
30850 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30851 if (ret)
30852 @@ -6530,7 +6530,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30853 return 0;
30854
30855 cleanup_pending:
30856 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30857 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30858 drm_gem_object_unreference(&work->old_fb_obj->base);
30859 drm_gem_object_unreference(&obj->base);
30860 mutex_unlock(&dev->struct_mutex);
30861 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30862 index 54558a0..2d97005 100644
30863 --- a/drivers/gpu/drm/mga/mga_drv.h
30864 +++ b/drivers/gpu/drm/mga/mga_drv.h
30865 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30866 u32 clear_cmd;
30867 u32 maccess;
30868
30869 - atomic_t vbl_received; /**< Number of vblanks received. */
30870 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30871 wait_queue_head_t fence_queue;
30872 - atomic_t last_fence_retired;
30873 + atomic_unchecked_t last_fence_retired;
30874 u32 next_fence_to_post;
30875
30876 unsigned int fb_cpp;
30877 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30878 index 2581202..f230a8d9 100644
30879 --- a/drivers/gpu/drm/mga/mga_irq.c
30880 +++ b/drivers/gpu/drm/mga/mga_irq.c
30881 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30882 if (crtc != 0)
30883 return 0;
30884
30885 - return atomic_read(&dev_priv->vbl_received);
30886 + return atomic_read_unchecked(&dev_priv->vbl_received);
30887 }
30888
30889
30890 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30891 /* VBLANK interrupt */
30892 if (status & MGA_VLINEPEN) {
30893 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30894 - atomic_inc(&dev_priv->vbl_received);
30895 + atomic_inc_unchecked(&dev_priv->vbl_received);
30896 drm_handle_vblank(dev, 0);
30897 handled = 1;
30898 }
30899 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30900 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30901 MGA_WRITE(MGA_PRIMEND, prim_end);
30902
30903 - atomic_inc(&dev_priv->last_fence_retired);
30904 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30905 DRM_WAKEUP(&dev_priv->fence_queue);
30906 handled = 1;
30907 }
30908 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30909 * using fences.
30910 */
30911 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30912 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30913 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30914 - *sequence) <= (1 << 23)));
30915
30916 *sequence = cur_fence;
30917 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30918 index a0a3fe3..209bf10 100644
30919 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30920 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30921 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30922 struct bit_table {
30923 const char id;
30924 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30925 -};
30926 +} __no_const;
30927
30928 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30929
30930 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30931 index 4f2cc95..9c6c510 100644
30932 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30933 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30934 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30935 u32 handle, u16 class);
30936 void (*set_tile_region)(struct drm_device *dev, int i);
30937 void (*tlb_flush)(struct drm_device *, int engine);
30938 -};
30939 +} __no_const;
30940
30941 struct nouveau_instmem_engine {
30942 void *priv;
30943 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30944 struct nouveau_mc_engine {
30945 int (*init)(struct drm_device *dev);
30946 void (*takedown)(struct drm_device *dev);
30947 -};
30948 +} __no_const;
30949
30950 struct nouveau_timer_engine {
30951 int (*init)(struct drm_device *dev);
30952 void (*takedown)(struct drm_device *dev);
30953 uint64_t (*read)(struct drm_device *dev);
30954 -};
30955 +} __no_const;
30956
30957 struct nouveau_fb_engine {
30958 int num_tiles;
30959 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30960 void (*put)(struct drm_device *, struct nouveau_mem **);
30961
30962 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30963 -};
30964 +} __no_const;
30965
30966 struct nouveau_engine {
30967 struct nouveau_instmem_engine instmem;
30968 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30969 struct drm_global_reference mem_global_ref;
30970 struct ttm_bo_global_ref bo_global_ref;
30971 struct ttm_bo_device bdev;
30972 - atomic_t validate_sequence;
30973 + atomic_unchecked_t validate_sequence;
30974 int (*move)(struct nouveau_channel *,
30975 struct ttm_buffer_object *,
30976 struct ttm_mem_reg *, struct ttm_mem_reg *);
30977 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30978 index af7cfb8..aadc2a3 100644
30979 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30980 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30981 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30982 int trycnt = 0;
30983 int ret, i;
30984
30985 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30986 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30987 retry:
30988 if (++trycnt > 100000) {
30989 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30990 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30991 index c610144..97440e2 100644
30992 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30993 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30994 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30995 bool can_switch;
30996
30997 spin_lock(&dev->count_lock);
30998 - can_switch = (dev->open_count == 0);
30999 + can_switch = (local_read(&dev->open_count) == 0);
31000 spin_unlock(&dev->count_lock);
31001 return can_switch;
31002 }
31003 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31004 index 93240bd..c490f60 100644
31005 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31006 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31007 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31008 }
31009
31010 if (nv_encoder->dcb->type == OUTPUT_DP) {
31011 - struct dp_train_func func = {
31012 + static struct dp_train_func func = {
31013 .link_set = nv50_sor_dp_link_set,
31014 .train_set = nv50_sor_dp_train_set,
31015 .train_adj = nv50_sor_dp_train_adj
31016 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31017 index 8a2fc89..3a5cf40 100644
31018 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31019 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31020 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31021 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31022
31023 if (nv_encoder->dcb->type == OUTPUT_DP) {
31024 - struct dp_train_func func = {
31025 + static struct dp_train_func func = {
31026 .link_set = nvd0_sor_dp_link_set,
31027 .train_set = nvd0_sor_dp_train_set,
31028 .train_adj = nvd0_sor_dp_train_adj
31029 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31030 index bcac90b..53bfc76 100644
31031 --- a/drivers/gpu/drm/r128/r128_cce.c
31032 +++ b/drivers/gpu/drm/r128/r128_cce.c
31033 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31034
31035 /* GH: Simple idle check.
31036 */
31037 - atomic_set(&dev_priv->idle_count, 0);
31038 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31039
31040 /* We don't support anything other than bus-mastering ring mode,
31041 * but the ring can be in either AGP or PCI space for the ring
31042 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31043 index 930c71b..499aded 100644
31044 --- a/drivers/gpu/drm/r128/r128_drv.h
31045 +++ b/drivers/gpu/drm/r128/r128_drv.h
31046 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31047 int is_pci;
31048 unsigned long cce_buffers_offset;
31049
31050 - atomic_t idle_count;
31051 + atomic_unchecked_t idle_count;
31052
31053 int page_flipping;
31054 int current_page;
31055 u32 crtc_offset;
31056 u32 crtc_offset_cntl;
31057
31058 - atomic_t vbl_received;
31059 + atomic_unchecked_t vbl_received;
31060
31061 u32 color_fmt;
31062 unsigned int front_offset;
31063 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31064 index 429d5a0..7e899ed 100644
31065 --- a/drivers/gpu/drm/r128/r128_irq.c
31066 +++ b/drivers/gpu/drm/r128/r128_irq.c
31067 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31068 if (crtc != 0)
31069 return 0;
31070
31071 - return atomic_read(&dev_priv->vbl_received);
31072 + return atomic_read_unchecked(&dev_priv->vbl_received);
31073 }
31074
31075 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31076 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31077 /* VBLANK interrupt */
31078 if (status & R128_CRTC_VBLANK_INT) {
31079 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31080 - atomic_inc(&dev_priv->vbl_received);
31081 + atomic_inc_unchecked(&dev_priv->vbl_received);
31082 drm_handle_vblank(dev, 0);
31083 return IRQ_HANDLED;
31084 }
31085 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31086 index a9e33ce..09edd4b 100644
31087 --- a/drivers/gpu/drm/r128/r128_state.c
31088 +++ b/drivers/gpu/drm/r128/r128_state.c
31089 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31090
31091 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31092 {
31093 - if (atomic_read(&dev_priv->idle_count) == 0)
31094 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31095 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31096 else
31097 - atomic_set(&dev_priv->idle_count, 0);
31098 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31099 }
31100
31101 #endif
31102 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31103 index 5a82b6b..9e69c73 100644
31104 --- a/drivers/gpu/drm/radeon/mkregtable.c
31105 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31106 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31107 regex_t mask_rex;
31108 regmatch_t match[4];
31109 char buf[1024];
31110 - size_t end;
31111 + long end;
31112 int len;
31113 int done = 0;
31114 int r;
31115 unsigned o;
31116 struct offset *offset;
31117 char last_reg_s[10];
31118 - int last_reg;
31119 + unsigned long last_reg;
31120
31121 if (regcomp
31122 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31123 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31124 index 59a1531..3bab49b 100644
31125 --- a/drivers/gpu/drm/radeon/radeon.h
31126 +++ b/drivers/gpu/drm/radeon/radeon.h
31127 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31128 int x2, int y2);
31129 void (*draw_auto)(struct radeon_device *rdev);
31130 void (*set_default_state)(struct radeon_device *rdev);
31131 -};
31132 +} __no_const;
31133
31134 struct r600_blit {
31135 struct radeon_bo *shader_obj;
31136 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31137 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31138 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31139 } pflip;
31140 -};
31141 +} __no_const;
31142
31143 /*
31144 * Asic structures
31145 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31146 index 7a3daeb..5016171 100644
31147 --- a/drivers/gpu/drm/radeon/radeon_device.c
31148 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31149 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31150 bool can_switch;
31151
31152 spin_lock(&dev->count_lock);
31153 - can_switch = (dev->open_count == 0);
31154 + can_switch = (local_read(&dev->open_count) == 0);
31155 spin_unlock(&dev->count_lock);
31156 return can_switch;
31157 }
31158 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31159 index a1b59ca..86f2d44 100644
31160 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31161 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31162 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31163
31164 /* SW interrupt */
31165 wait_queue_head_t swi_queue;
31166 - atomic_t swi_emitted;
31167 + atomic_unchecked_t swi_emitted;
31168 int vblank_crtc;
31169 uint32_t irq_enable_reg;
31170 uint32_t r500_disp_irq_reg;
31171 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31172 index 48b7cea..342236f 100644
31173 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31174 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31175 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31176 request = compat_alloc_user_space(sizeof(*request));
31177 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31178 || __put_user(req32.param, &request->param)
31179 - || __put_user((void __user *)(unsigned long)req32.value,
31180 + || __put_user((unsigned long)req32.value,
31181 &request->value))
31182 return -EFAULT;
31183
31184 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31185 index 00da384..32f972d 100644
31186 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31187 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31188 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31189 unsigned int ret;
31190 RING_LOCALS;
31191
31192 - atomic_inc(&dev_priv->swi_emitted);
31193 - ret = atomic_read(&dev_priv->swi_emitted);
31194 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31195 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31196
31197 BEGIN_RING(4);
31198 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31199 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31200 drm_radeon_private_t *dev_priv =
31201 (drm_radeon_private_t *) dev->dev_private;
31202
31203 - atomic_set(&dev_priv->swi_emitted, 0);
31204 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31205 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31206
31207 dev->max_vblank_count = 0x001fffff;
31208 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31209 index e8422ae..d22d4a8 100644
31210 --- a/drivers/gpu/drm/radeon/radeon_state.c
31211 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31212 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31213 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31214 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31215
31216 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31217 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31218 sarea_priv->nbox * sizeof(depth_boxes[0])))
31219 return -EFAULT;
31220
31221 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31222 {
31223 drm_radeon_private_t *dev_priv = dev->dev_private;
31224 drm_radeon_getparam_t *param = data;
31225 - int value;
31226 + int value = 0;
31227
31228 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31229
31230 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31231 index 5b71c71..650f9e4 100644
31232 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31233 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31234 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31235 }
31236 if (unlikely(ttm_vm_ops == NULL)) {
31237 ttm_vm_ops = vma->vm_ops;
31238 - radeon_ttm_vm_ops = *ttm_vm_ops;
31239 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31240 + pax_open_kernel();
31241 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31242 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31243 + pax_close_kernel();
31244 }
31245 vma->vm_ops = &radeon_ttm_vm_ops;
31246 return 0;
31247 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31248 index 3b663fc..57850f4 100644
31249 --- a/drivers/gpu/drm/radeon/rs690.c
31250 +++ b/drivers/gpu/drm/radeon/rs690.c
31251 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31252 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31253 rdev->pm.sideport_bandwidth.full)
31254 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31255 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31256 + read_delay_latency.full = dfixed_const(800 * 1000);
31257 read_delay_latency.full = dfixed_div(read_delay_latency,
31258 rdev->pm.igp_sideport_mclk);
31259 + a.full = dfixed_const(370);
31260 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31261 } else {
31262 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31263 rdev->pm.k8_bandwidth.full)
31264 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31265 index ebc6fac..a8313ed 100644
31266 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31267 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31268 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31269 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31270 struct shrink_control *sc)
31271 {
31272 - static atomic_t start_pool = ATOMIC_INIT(0);
31273 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31274 unsigned i;
31275 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31276 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31277 struct ttm_page_pool *pool;
31278 int shrink_pages = sc->nr_to_scan;
31279
31280 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31281 index 88edacc..1e5412b 100644
31282 --- a/drivers/gpu/drm/via/via_drv.h
31283 +++ b/drivers/gpu/drm/via/via_drv.h
31284 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31285 typedef uint32_t maskarray_t[5];
31286
31287 typedef struct drm_via_irq {
31288 - atomic_t irq_received;
31289 + atomic_unchecked_t irq_received;
31290 uint32_t pending_mask;
31291 uint32_t enable_mask;
31292 wait_queue_head_t irq_queue;
31293 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31294 struct timeval last_vblank;
31295 int last_vblank_valid;
31296 unsigned usec_per_vblank;
31297 - atomic_t vbl_received;
31298 + atomic_unchecked_t vbl_received;
31299 drm_via_state_t hc_state;
31300 char pci_buf[VIA_PCI_BUF_SIZE];
31301 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31302 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31303 index d391f48..10c8ca3 100644
31304 --- a/drivers/gpu/drm/via/via_irq.c
31305 +++ b/drivers/gpu/drm/via/via_irq.c
31306 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31307 if (crtc != 0)
31308 return 0;
31309
31310 - return atomic_read(&dev_priv->vbl_received);
31311 + return atomic_read_unchecked(&dev_priv->vbl_received);
31312 }
31313
31314 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31315 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31316
31317 status = VIA_READ(VIA_REG_INTERRUPT);
31318 if (status & VIA_IRQ_VBLANK_PENDING) {
31319 - atomic_inc(&dev_priv->vbl_received);
31320 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31321 + atomic_inc_unchecked(&dev_priv->vbl_received);
31322 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31323 do_gettimeofday(&cur_vblank);
31324 if (dev_priv->last_vblank_valid) {
31325 dev_priv->usec_per_vblank =
31326 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31327 dev_priv->last_vblank = cur_vblank;
31328 dev_priv->last_vblank_valid = 1;
31329 }
31330 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31331 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31332 DRM_DEBUG("US per vblank is: %u\n",
31333 dev_priv->usec_per_vblank);
31334 }
31335 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31336
31337 for (i = 0; i < dev_priv->num_irqs; ++i) {
31338 if (status & cur_irq->pending_mask) {
31339 - atomic_inc(&cur_irq->irq_received);
31340 + atomic_inc_unchecked(&cur_irq->irq_received);
31341 DRM_WAKEUP(&cur_irq->irq_queue);
31342 handled = 1;
31343 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31344 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31345 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31346 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31347 masks[irq][4]));
31348 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31349 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31350 } else {
31351 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31352 (((cur_irq_sequence =
31353 - atomic_read(&cur_irq->irq_received)) -
31354 + atomic_read_unchecked(&cur_irq->irq_received)) -
31355 *sequence) <= (1 << 23)));
31356 }
31357 *sequence = cur_irq_sequence;
31358 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31359 }
31360
31361 for (i = 0; i < dev_priv->num_irqs; ++i) {
31362 - atomic_set(&cur_irq->irq_received, 0);
31363 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31364 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31365 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31366 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31367 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31368 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31369 case VIA_IRQ_RELATIVE:
31370 irqwait->request.sequence +=
31371 - atomic_read(&cur_irq->irq_received);
31372 + atomic_read_unchecked(&cur_irq->irq_received);
31373 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31374 case VIA_IRQ_ABSOLUTE:
31375 break;
31376 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31377 index 29c984f..4084f1a 100644
31378 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31379 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31380 @@ -263,7 +263,7 @@ struct vmw_private {
31381 * Fencing and IRQs.
31382 */
31383
31384 - atomic_t marker_seq;
31385 + atomic_unchecked_t marker_seq;
31386 wait_queue_head_t fence_queue;
31387 wait_queue_head_t fifo_queue;
31388 int fence_queue_waiters; /* Protected by hw_mutex */
31389 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31390 index a0c2f12..68ae6cb 100644
31391 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31392 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31393 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31394 (unsigned int) min,
31395 (unsigned int) fifo->capabilities);
31396
31397 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31398 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31399 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31400 vmw_marker_queue_init(&fifo->marker_queue);
31401 return vmw_fifo_send_fence(dev_priv, &dummy);
31402 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31403 if (reserveable)
31404 iowrite32(bytes, fifo_mem +
31405 SVGA_FIFO_RESERVED);
31406 - return fifo_mem + (next_cmd >> 2);
31407 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31408 } else {
31409 need_bounce = true;
31410 }
31411 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31412
31413 fm = vmw_fifo_reserve(dev_priv, bytes);
31414 if (unlikely(fm == NULL)) {
31415 - *seqno = atomic_read(&dev_priv->marker_seq);
31416 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31417 ret = -ENOMEM;
31418 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31419 false, 3*HZ);
31420 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31421 }
31422
31423 do {
31424 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31425 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31426 } while (*seqno == 0);
31427
31428 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31429 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31430 index cabc95f..14b3d77 100644
31431 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31432 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31433 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31434 * emitted. Then the fence is stale and signaled.
31435 */
31436
31437 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31438 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31439 > VMW_FENCE_WRAP);
31440
31441 return ret;
31442 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31443
31444 if (fifo_idle)
31445 down_read(&fifo_state->rwsem);
31446 - signal_seq = atomic_read(&dev_priv->marker_seq);
31447 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31448 ret = 0;
31449
31450 for (;;) {
31451 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31452 index 8a8725c..afed796 100644
31453 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31454 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31455 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31456 while (!vmw_lag_lt(queue, us)) {
31457 spin_lock(&queue->lock);
31458 if (list_empty(&queue->head))
31459 - seqno = atomic_read(&dev_priv->marker_seq);
31460 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31461 else {
31462 marker = list_first_entry(&queue->head,
31463 struct vmw_marker, head);
31464 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31465 index 5de3bb3..08e5063 100644
31466 --- a/drivers/hid/hid-core.c
31467 +++ b/drivers/hid/hid-core.c
31468 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31469
31470 int hid_add_device(struct hid_device *hdev)
31471 {
31472 - static atomic_t id = ATOMIC_INIT(0);
31473 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31474 int ret;
31475
31476 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31477 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31478 /* XXX hack, any other cleaner solution after the driver core
31479 * is converted to allow more than 20 bytes as the device name? */
31480 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31481 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31482 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31483
31484 hid_debug_register(hdev, dev_name(&hdev->dev));
31485 ret = device_add(&hdev->dev);
31486 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31487 index eec3291..8ed706b 100644
31488 --- a/drivers/hid/hid-wiimote-debug.c
31489 +++ b/drivers/hid/hid-wiimote-debug.c
31490 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31491 else if (size == 0)
31492 return -EIO;
31493
31494 - if (copy_to_user(u, buf, size))
31495 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31496 return -EFAULT;
31497
31498 *off += size;
31499 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31500 index 14599e2..711c965 100644
31501 --- a/drivers/hid/usbhid/hiddev.c
31502 +++ b/drivers/hid/usbhid/hiddev.c
31503 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31504 break;
31505
31506 case HIDIOCAPPLICATION:
31507 - if (arg < 0 || arg >= hid->maxapplication)
31508 + if (arg >= hid->maxapplication)
31509 break;
31510
31511 for (i = 0; i < hid->maxcollection; i++)
31512 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31513 index 4065374..10ed7dc 100644
31514 --- a/drivers/hv/channel.c
31515 +++ b/drivers/hv/channel.c
31516 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31517 int ret = 0;
31518 int t;
31519
31520 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31521 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31522 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31523 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31524
31525 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31526 if (ret)
31527 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31528 index 86f8885..ab9cb2b 100644
31529 --- a/drivers/hv/hv.c
31530 +++ b/drivers/hv/hv.c
31531 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31532 u64 output_address = (output) ? virt_to_phys(output) : 0;
31533 u32 output_address_hi = output_address >> 32;
31534 u32 output_address_lo = output_address & 0xFFFFFFFF;
31535 - void *hypercall_page = hv_context.hypercall_page;
31536 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31537
31538 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31539 "=a"(hv_status_lo) : "d" (control_hi),
31540 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31541 index 0614ff3..f0b2b5c 100644
31542 --- a/drivers/hv/hyperv_vmbus.h
31543 +++ b/drivers/hv/hyperv_vmbus.h
31544 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31545 struct vmbus_connection {
31546 enum vmbus_connect_state conn_state;
31547
31548 - atomic_t next_gpadl_handle;
31549 + atomic_unchecked_t next_gpadl_handle;
31550
31551 /*
31552 * Represents channel interrupts. Each bit position represents a
31553 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31554 index 4748086..3abf845 100644
31555 --- a/drivers/hv/vmbus_drv.c
31556 +++ b/drivers/hv/vmbus_drv.c
31557 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31558 {
31559 int ret = 0;
31560
31561 - static atomic_t device_num = ATOMIC_INIT(0);
31562 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31563
31564 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31565 - atomic_inc_return(&device_num));
31566 + atomic_inc_return_unchecked(&device_num));
31567
31568 child_device_obj->device.bus = &hv_bus;
31569 child_device_obj->device.parent = &hv_acpi_dev->dev;
31570 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31571 index 8b011d0..3de24a1 100644
31572 --- a/drivers/hwmon/sht15.c
31573 +++ b/drivers/hwmon/sht15.c
31574 @@ -166,7 +166,7 @@ struct sht15_data {
31575 int supply_uV;
31576 bool supply_uV_valid;
31577 struct work_struct update_supply_work;
31578 - atomic_t interrupt_handled;
31579 + atomic_unchecked_t interrupt_handled;
31580 };
31581
31582 /**
31583 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31584 return ret;
31585
31586 gpio_direction_input(data->pdata->gpio_data);
31587 - atomic_set(&data->interrupt_handled, 0);
31588 + atomic_set_unchecked(&data->interrupt_handled, 0);
31589
31590 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31591 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31592 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31593 /* Only relevant if the interrupt hasn't occurred. */
31594 - if (!atomic_read(&data->interrupt_handled))
31595 + if (!atomic_read_unchecked(&data->interrupt_handled))
31596 schedule_work(&data->read_work);
31597 }
31598 ret = wait_event_timeout(data->wait_queue,
31599 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31600
31601 /* First disable the interrupt */
31602 disable_irq_nosync(irq);
31603 - atomic_inc(&data->interrupt_handled);
31604 + atomic_inc_unchecked(&data->interrupt_handled);
31605 /* Then schedule a reading work struct */
31606 if (data->state != SHT15_READING_NOTHING)
31607 schedule_work(&data->read_work);
31608 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31609 * If not, then start the interrupt again - care here as could
31610 * have gone low in meantime so verify it hasn't!
31611 */
31612 - atomic_set(&data->interrupt_handled, 0);
31613 + atomic_set_unchecked(&data->interrupt_handled, 0);
31614 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31615 /* If still not occurred or another handler was scheduled */
31616 if (gpio_get_value(data->pdata->gpio_data)
31617 - || atomic_read(&data->interrupt_handled))
31618 + || atomic_read_unchecked(&data->interrupt_handled))
31619 return;
31620 }
31621
31622 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31623 index 378fcb5..5e91fa8 100644
31624 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31625 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31626 @@ -43,7 +43,7 @@
31627 extern struct i2c_adapter amd756_smbus;
31628
31629 static struct i2c_adapter *s4882_adapter;
31630 -static struct i2c_algorithm *s4882_algo;
31631 +static i2c_algorithm_no_const *s4882_algo;
31632
31633 /* Wrapper access functions for multiplexed SMBus */
31634 static DEFINE_MUTEX(amd756_lock);
31635 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31636 index 29015eb..af2d8e9 100644
31637 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31638 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31639 @@ -41,7 +41,7 @@
31640 extern struct i2c_adapter *nforce2_smbus;
31641
31642 static struct i2c_adapter *s4985_adapter;
31643 -static struct i2c_algorithm *s4985_algo;
31644 +static i2c_algorithm_no_const *s4985_algo;
31645
31646 /* Wrapper access functions for multiplexed SMBus */
31647 static DEFINE_MUTEX(nforce2_lock);
31648 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31649 index 1038c38..eb92f51 100644
31650 --- a/drivers/i2c/i2c-mux.c
31651 +++ b/drivers/i2c/i2c-mux.c
31652 @@ -30,7 +30,7 @@
31653 /* multiplexer per channel data */
31654 struct i2c_mux_priv {
31655 struct i2c_adapter adap;
31656 - struct i2c_algorithm algo;
31657 + i2c_algorithm_no_const algo;
31658
31659 struct i2c_adapter *parent;
31660 void *mux_priv; /* the mux chip/device */
31661 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31662 index 57d00ca..0145194 100644
31663 --- a/drivers/ide/aec62xx.c
31664 +++ b/drivers/ide/aec62xx.c
31665 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31666 .cable_detect = atp86x_cable_detect,
31667 };
31668
31669 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31670 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31671 { /* 0: AEC6210 */
31672 .name = DRV_NAME,
31673 .init_chipset = init_chipset_aec62xx,
31674 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31675 index 2c8016a..911a27c 100644
31676 --- a/drivers/ide/alim15x3.c
31677 +++ b/drivers/ide/alim15x3.c
31678 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31679 .dma_sff_read_status = ide_dma_sff_read_status,
31680 };
31681
31682 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31683 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31684 .name = DRV_NAME,
31685 .init_chipset = init_chipset_ali15x3,
31686 .init_hwif = init_hwif_ali15x3,
31687 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31688 index 3747b25..56fc995 100644
31689 --- a/drivers/ide/amd74xx.c
31690 +++ b/drivers/ide/amd74xx.c
31691 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31692 .udma_mask = udma, \
31693 }
31694
31695 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31696 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31697 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31698 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31699 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31700 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31701 index 15f0ead..cb43480 100644
31702 --- a/drivers/ide/atiixp.c
31703 +++ b/drivers/ide/atiixp.c
31704 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31705 .cable_detect = atiixp_cable_detect,
31706 };
31707
31708 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31709 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31710 { /* 0: IXP200/300/400/700 */
31711 .name = DRV_NAME,
31712 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31713 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31714 index 5f80312..d1fc438 100644
31715 --- a/drivers/ide/cmd64x.c
31716 +++ b/drivers/ide/cmd64x.c
31717 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31718 .dma_sff_read_status = ide_dma_sff_read_status,
31719 };
31720
31721 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31722 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31723 { /* 0: CMD643 */
31724 .name = DRV_NAME,
31725 .init_chipset = init_chipset_cmd64x,
31726 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31727 index 2c1e5f7..1444762 100644
31728 --- a/drivers/ide/cs5520.c
31729 +++ b/drivers/ide/cs5520.c
31730 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31731 .set_dma_mode = cs5520_set_dma_mode,
31732 };
31733
31734 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31735 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31736 .name = DRV_NAME,
31737 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31738 .port_ops = &cs5520_port_ops,
31739 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31740 index 4dc4eb9..49b40ad 100644
31741 --- a/drivers/ide/cs5530.c
31742 +++ b/drivers/ide/cs5530.c
31743 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31744 .udma_filter = cs5530_udma_filter,
31745 };
31746
31747 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31748 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31749 .name = DRV_NAME,
31750 .init_chipset = init_chipset_cs5530,
31751 .init_hwif = init_hwif_cs5530,
31752 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31753 index 5059faf..18d4c85 100644
31754 --- a/drivers/ide/cs5535.c
31755 +++ b/drivers/ide/cs5535.c
31756 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31757 .cable_detect = cs5535_cable_detect,
31758 };
31759
31760 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31761 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31762 .name = DRV_NAME,
31763 .port_ops = &cs5535_port_ops,
31764 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31765 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31766 index 847553f..3ffb49d 100644
31767 --- a/drivers/ide/cy82c693.c
31768 +++ b/drivers/ide/cy82c693.c
31769 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31770 .set_dma_mode = cy82c693_set_dma_mode,
31771 };
31772
31773 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31774 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31775 .name = DRV_NAME,
31776 .init_iops = init_iops_cy82c693,
31777 .port_ops = &cy82c693_port_ops,
31778 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31779 index 58c51cd..4aec3b8 100644
31780 --- a/drivers/ide/hpt366.c
31781 +++ b/drivers/ide/hpt366.c
31782 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31783 }
31784 };
31785
31786 -static const struct hpt_info hpt36x __devinitdata = {
31787 +static const struct hpt_info hpt36x __devinitconst = {
31788 .chip_name = "HPT36x",
31789 .chip_type = HPT36x,
31790 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31791 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31792 .timings = &hpt36x_timings
31793 };
31794
31795 -static const struct hpt_info hpt370 __devinitdata = {
31796 +static const struct hpt_info hpt370 __devinitconst = {
31797 .chip_name = "HPT370",
31798 .chip_type = HPT370,
31799 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31800 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31801 .timings = &hpt37x_timings
31802 };
31803
31804 -static const struct hpt_info hpt370a __devinitdata = {
31805 +static const struct hpt_info hpt370a __devinitconst = {
31806 .chip_name = "HPT370A",
31807 .chip_type = HPT370A,
31808 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31809 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31810 .timings = &hpt37x_timings
31811 };
31812
31813 -static const struct hpt_info hpt374 __devinitdata = {
31814 +static const struct hpt_info hpt374 __devinitconst = {
31815 .chip_name = "HPT374",
31816 .chip_type = HPT374,
31817 .udma_mask = ATA_UDMA5,
31818 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31819 .timings = &hpt37x_timings
31820 };
31821
31822 -static const struct hpt_info hpt372 __devinitdata = {
31823 +static const struct hpt_info hpt372 __devinitconst = {
31824 .chip_name = "HPT372",
31825 .chip_type = HPT372,
31826 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31827 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31828 .timings = &hpt37x_timings
31829 };
31830
31831 -static const struct hpt_info hpt372a __devinitdata = {
31832 +static const struct hpt_info hpt372a __devinitconst = {
31833 .chip_name = "HPT372A",
31834 .chip_type = HPT372A,
31835 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31836 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31837 .timings = &hpt37x_timings
31838 };
31839
31840 -static const struct hpt_info hpt302 __devinitdata = {
31841 +static const struct hpt_info hpt302 __devinitconst = {
31842 .chip_name = "HPT302",
31843 .chip_type = HPT302,
31844 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31845 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31846 .timings = &hpt37x_timings
31847 };
31848
31849 -static const struct hpt_info hpt371 __devinitdata = {
31850 +static const struct hpt_info hpt371 __devinitconst = {
31851 .chip_name = "HPT371",
31852 .chip_type = HPT371,
31853 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31854 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31855 .timings = &hpt37x_timings
31856 };
31857
31858 -static const struct hpt_info hpt372n __devinitdata = {
31859 +static const struct hpt_info hpt372n __devinitconst = {
31860 .chip_name = "HPT372N",
31861 .chip_type = HPT372N,
31862 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31863 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31864 .timings = &hpt37x_timings
31865 };
31866
31867 -static const struct hpt_info hpt302n __devinitdata = {
31868 +static const struct hpt_info hpt302n __devinitconst = {
31869 .chip_name = "HPT302N",
31870 .chip_type = HPT302N,
31871 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31872 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31873 .timings = &hpt37x_timings
31874 };
31875
31876 -static const struct hpt_info hpt371n __devinitdata = {
31877 +static const struct hpt_info hpt371n __devinitconst = {
31878 .chip_name = "HPT371N",
31879 .chip_type = HPT371N,
31880 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31881 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31882 .dma_sff_read_status = ide_dma_sff_read_status,
31883 };
31884
31885 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31886 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31887 { /* 0: HPT36x */
31888 .name = DRV_NAME,
31889 .init_chipset = init_chipset_hpt366,
31890 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31891 index 8126824..55a2798 100644
31892 --- a/drivers/ide/ide-cd.c
31893 +++ b/drivers/ide/ide-cd.c
31894 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31895 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31896 if ((unsigned long)buf & alignment
31897 || blk_rq_bytes(rq) & q->dma_pad_mask
31898 - || object_is_on_stack(buf))
31899 + || object_starts_on_stack(buf))
31900 drive->dma = 0;
31901 }
31902 }
31903 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31904 index 7f56b73..dab5b67 100644
31905 --- a/drivers/ide/ide-pci-generic.c
31906 +++ b/drivers/ide/ide-pci-generic.c
31907 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31908 .udma_mask = ATA_UDMA6, \
31909 }
31910
31911 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31912 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31913 /* 0: Unknown */
31914 DECLARE_GENERIC_PCI_DEV(0),
31915
31916 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31917 index 560e66d..d5dd180 100644
31918 --- a/drivers/ide/it8172.c
31919 +++ b/drivers/ide/it8172.c
31920 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31921 .set_dma_mode = it8172_set_dma_mode,
31922 };
31923
31924 -static const struct ide_port_info it8172_port_info __devinitdata = {
31925 +static const struct ide_port_info it8172_port_info __devinitconst = {
31926 .name = DRV_NAME,
31927 .port_ops = &it8172_port_ops,
31928 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31929 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31930 index 46816ba..1847aeb 100644
31931 --- a/drivers/ide/it8213.c
31932 +++ b/drivers/ide/it8213.c
31933 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31934 .cable_detect = it8213_cable_detect,
31935 };
31936
31937 -static const struct ide_port_info it8213_chipset __devinitdata = {
31938 +static const struct ide_port_info it8213_chipset __devinitconst = {
31939 .name = DRV_NAME,
31940 .enablebits = { {0x41, 0x80, 0x80} },
31941 .port_ops = &it8213_port_ops,
31942 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31943 index 2e3169f..c5611db 100644
31944 --- a/drivers/ide/it821x.c
31945 +++ b/drivers/ide/it821x.c
31946 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31947 .cable_detect = it821x_cable_detect,
31948 };
31949
31950 -static const struct ide_port_info it821x_chipset __devinitdata = {
31951 +static const struct ide_port_info it821x_chipset __devinitconst = {
31952 .name = DRV_NAME,
31953 .init_chipset = init_chipset_it821x,
31954 .init_hwif = init_hwif_it821x,
31955 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31956 index 74c2c4a..efddd7d 100644
31957 --- a/drivers/ide/jmicron.c
31958 +++ b/drivers/ide/jmicron.c
31959 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31960 .cable_detect = jmicron_cable_detect,
31961 };
31962
31963 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31964 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31965 .name = DRV_NAME,
31966 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31967 .port_ops = &jmicron_port_ops,
31968 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31969 index 95327a2..73f78d8 100644
31970 --- a/drivers/ide/ns87415.c
31971 +++ b/drivers/ide/ns87415.c
31972 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31973 .dma_sff_read_status = superio_dma_sff_read_status,
31974 };
31975
31976 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31977 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31978 .name = DRV_NAME,
31979 .init_hwif = init_hwif_ns87415,
31980 .tp_ops = &ns87415_tp_ops,
31981 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31982 index 1a53a4c..39edc66 100644
31983 --- a/drivers/ide/opti621.c
31984 +++ b/drivers/ide/opti621.c
31985 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31986 .set_pio_mode = opti621_set_pio_mode,
31987 };
31988
31989 -static const struct ide_port_info opti621_chipset __devinitdata = {
31990 +static const struct ide_port_info opti621_chipset __devinitconst = {
31991 .name = DRV_NAME,
31992 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31993 .port_ops = &opti621_port_ops,
31994 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31995 index 9546fe2..2e5ceb6 100644
31996 --- a/drivers/ide/pdc202xx_new.c
31997 +++ b/drivers/ide/pdc202xx_new.c
31998 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31999 .udma_mask = udma, \
32000 }
32001
32002 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32003 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32004 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32005 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32006 };
32007 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32008 index 3a35ec6..5634510 100644
32009 --- a/drivers/ide/pdc202xx_old.c
32010 +++ b/drivers/ide/pdc202xx_old.c
32011 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32012 .max_sectors = sectors, \
32013 }
32014
32015 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32016 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32017 { /* 0: PDC20246 */
32018 .name = DRV_NAME,
32019 .init_chipset = init_chipset_pdc202xx,
32020 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32021 index 1892e81..fe0fd60 100644
32022 --- a/drivers/ide/piix.c
32023 +++ b/drivers/ide/piix.c
32024 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32025 .udma_mask = udma, \
32026 }
32027
32028 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32029 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32030 /* 0: MPIIX */
32031 { /*
32032 * MPIIX actually has only a single IDE channel mapped to
32033 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32034 index a6414a8..c04173e 100644
32035 --- a/drivers/ide/rz1000.c
32036 +++ b/drivers/ide/rz1000.c
32037 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32038 }
32039 }
32040
32041 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32042 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32043 .name = DRV_NAME,
32044 .host_flags = IDE_HFLAG_NO_DMA,
32045 };
32046 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32047 index 356b9b5..d4758eb 100644
32048 --- a/drivers/ide/sc1200.c
32049 +++ b/drivers/ide/sc1200.c
32050 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32051 .dma_sff_read_status = ide_dma_sff_read_status,
32052 };
32053
32054 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32055 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32056 .name = DRV_NAME,
32057 .port_ops = &sc1200_port_ops,
32058 .dma_ops = &sc1200_dma_ops,
32059 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32060 index b7f5b0c..9701038 100644
32061 --- a/drivers/ide/scc_pata.c
32062 +++ b/drivers/ide/scc_pata.c
32063 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32064 .dma_sff_read_status = scc_dma_sff_read_status,
32065 };
32066
32067 -static const struct ide_port_info scc_chipset __devinitdata = {
32068 +static const struct ide_port_info scc_chipset __devinitconst = {
32069 .name = "sccIDE",
32070 .init_iops = init_iops_scc,
32071 .init_dma = scc_init_dma,
32072 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32073 index 35fb8da..24d72ef 100644
32074 --- a/drivers/ide/serverworks.c
32075 +++ b/drivers/ide/serverworks.c
32076 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32077 .cable_detect = svwks_cable_detect,
32078 };
32079
32080 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32081 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32082 { /* 0: OSB4 */
32083 .name = DRV_NAME,
32084 .init_chipset = init_chipset_svwks,
32085 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32086 index ddeda44..46f7e30 100644
32087 --- a/drivers/ide/siimage.c
32088 +++ b/drivers/ide/siimage.c
32089 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32090 .udma_mask = ATA_UDMA6, \
32091 }
32092
32093 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32094 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32095 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32096 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32097 };
32098 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32099 index 4a00225..09e61b4 100644
32100 --- a/drivers/ide/sis5513.c
32101 +++ b/drivers/ide/sis5513.c
32102 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32103 .cable_detect = sis_cable_detect,
32104 };
32105
32106 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32107 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32108 .name = DRV_NAME,
32109 .init_chipset = init_chipset_sis5513,
32110 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32111 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32112 index f21dc2a..d051cd2 100644
32113 --- a/drivers/ide/sl82c105.c
32114 +++ b/drivers/ide/sl82c105.c
32115 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32116 .dma_sff_read_status = ide_dma_sff_read_status,
32117 };
32118
32119 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32120 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32121 .name = DRV_NAME,
32122 .init_chipset = init_chipset_sl82c105,
32123 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32124 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32125 index 864ffe0..863a5e9 100644
32126 --- a/drivers/ide/slc90e66.c
32127 +++ b/drivers/ide/slc90e66.c
32128 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32129 .cable_detect = slc90e66_cable_detect,
32130 };
32131
32132 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32133 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32134 .name = DRV_NAME,
32135 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32136 .port_ops = &slc90e66_port_ops,
32137 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32138 index 4799d5c..1794678 100644
32139 --- a/drivers/ide/tc86c001.c
32140 +++ b/drivers/ide/tc86c001.c
32141 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32142 .dma_sff_read_status = ide_dma_sff_read_status,
32143 };
32144
32145 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32146 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32147 .name = DRV_NAME,
32148 .init_hwif = init_hwif_tc86c001,
32149 .port_ops = &tc86c001_port_ops,
32150 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32151 index 281c914..55ce1b8 100644
32152 --- a/drivers/ide/triflex.c
32153 +++ b/drivers/ide/triflex.c
32154 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32155 .set_dma_mode = triflex_set_mode,
32156 };
32157
32158 -static const struct ide_port_info triflex_device __devinitdata = {
32159 +static const struct ide_port_info triflex_device __devinitconst = {
32160 .name = DRV_NAME,
32161 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32162 .port_ops = &triflex_port_ops,
32163 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32164 index 4b42ca0..e494a98 100644
32165 --- a/drivers/ide/trm290.c
32166 +++ b/drivers/ide/trm290.c
32167 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32168 .dma_check = trm290_dma_check,
32169 };
32170
32171 -static const struct ide_port_info trm290_chipset __devinitdata = {
32172 +static const struct ide_port_info trm290_chipset __devinitconst = {
32173 .name = DRV_NAME,
32174 .init_hwif = init_hwif_trm290,
32175 .tp_ops = &trm290_tp_ops,
32176 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32177 index f46f49c..eb77678 100644
32178 --- a/drivers/ide/via82cxxx.c
32179 +++ b/drivers/ide/via82cxxx.c
32180 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32181 .cable_detect = via82cxxx_cable_detect,
32182 };
32183
32184 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32185 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32186 .name = DRV_NAME,
32187 .init_chipset = init_chipset_via82cxxx,
32188 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32189 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32190 index 73d4531..c90cd2d 100644
32191 --- a/drivers/ieee802154/fakehard.c
32192 +++ b/drivers/ieee802154/fakehard.c
32193 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32194 phy->transmit_power = 0xbf;
32195
32196 dev->netdev_ops = &fake_ops;
32197 - dev->ml_priv = &fake_mlme;
32198 + dev->ml_priv = (void *)&fake_mlme;
32199
32200 priv = netdev_priv(dev);
32201 priv->phy = phy;
32202 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32203 index d67999f..4c5d083 100644
32204 --- a/drivers/infiniband/core/cm.c
32205 +++ b/drivers/infiniband/core/cm.c
32206 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32207
32208 struct cm_counter_group {
32209 struct kobject obj;
32210 - atomic_long_t counter[CM_ATTR_COUNT];
32211 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32212 };
32213
32214 struct cm_counter_attribute {
32215 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32216 struct ib_mad_send_buf *msg = NULL;
32217 int ret;
32218
32219 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32220 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32221 counter[CM_REQ_COUNTER]);
32222
32223 /* Quick state check to discard duplicate REQs. */
32224 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32225 if (!cm_id_priv)
32226 return;
32227
32228 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32229 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32230 counter[CM_REP_COUNTER]);
32231 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32232 if (ret)
32233 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32234 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32235 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32236 spin_unlock_irq(&cm_id_priv->lock);
32237 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32238 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32239 counter[CM_RTU_COUNTER]);
32240 goto out;
32241 }
32242 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32243 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32244 dreq_msg->local_comm_id);
32245 if (!cm_id_priv) {
32246 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32247 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32248 counter[CM_DREQ_COUNTER]);
32249 cm_issue_drep(work->port, work->mad_recv_wc);
32250 return -EINVAL;
32251 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32252 case IB_CM_MRA_REP_RCVD:
32253 break;
32254 case IB_CM_TIMEWAIT:
32255 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32256 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32257 counter[CM_DREQ_COUNTER]);
32258 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32259 goto unlock;
32260 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32261 cm_free_msg(msg);
32262 goto deref;
32263 case IB_CM_DREQ_RCVD:
32264 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32265 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32266 counter[CM_DREQ_COUNTER]);
32267 goto unlock;
32268 default:
32269 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32270 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32271 cm_id_priv->msg, timeout)) {
32272 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32273 - atomic_long_inc(&work->port->
32274 + atomic_long_inc_unchecked(&work->port->
32275 counter_group[CM_RECV_DUPLICATES].
32276 counter[CM_MRA_COUNTER]);
32277 goto out;
32278 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32279 break;
32280 case IB_CM_MRA_REQ_RCVD:
32281 case IB_CM_MRA_REP_RCVD:
32282 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32283 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32284 counter[CM_MRA_COUNTER]);
32285 /* fall through */
32286 default:
32287 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32288 case IB_CM_LAP_IDLE:
32289 break;
32290 case IB_CM_MRA_LAP_SENT:
32291 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32292 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32293 counter[CM_LAP_COUNTER]);
32294 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32295 goto unlock;
32296 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32297 cm_free_msg(msg);
32298 goto deref;
32299 case IB_CM_LAP_RCVD:
32300 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32301 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32302 counter[CM_LAP_COUNTER]);
32303 goto unlock;
32304 default:
32305 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32306 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32307 if (cur_cm_id_priv) {
32308 spin_unlock_irq(&cm.lock);
32309 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32310 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32311 counter[CM_SIDR_REQ_COUNTER]);
32312 goto out; /* Duplicate message. */
32313 }
32314 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32315 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32316 msg->retries = 1;
32317
32318 - atomic_long_add(1 + msg->retries,
32319 + atomic_long_add_unchecked(1 + msg->retries,
32320 &port->counter_group[CM_XMIT].counter[attr_index]);
32321 if (msg->retries)
32322 - atomic_long_add(msg->retries,
32323 + atomic_long_add_unchecked(msg->retries,
32324 &port->counter_group[CM_XMIT_RETRIES].
32325 counter[attr_index]);
32326
32327 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32328 }
32329
32330 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32331 - atomic_long_inc(&port->counter_group[CM_RECV].
32332 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32333 counter[attr_id - CM_ATTR_ID_OFFSET]);
32334
32335 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32336 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32337 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32338
32339 return sprintf(buf, "%ld\n",
32340 - atomic_long_read(&group->counter[cm_attr->index]));
32341 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32342 }
32343
32344 static const struct sysfs_ops cm_counter_ops = {
32345 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32346 index 176c8f9..2627b62 100644
32347 --- a/drivers/infiniband/core/fmr_pool.c
32348 +++ b/drivers/infiniband/core/fmr_pool.c
32349 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32350
32351 struct task_struct *thread;
32352
32353 - atomic_t req_ser;
32354 - atomic_t flush_ser;
32355 + atomic_unchecked_t req_ser;
32356 + atomic_unchecked_t flush_ser;
32357
32358 wait_queue_head_t force_wait;
32359 };
32360 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32361 struct ib_fmr_pool *pool = pool_ptr;
32362
32363 do {
32364 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32365 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32366 ib_fmr_batch_release(pool);
32367
32368 - atomic_inc(&pool->flush_ser);
32369 + atomic_inc_unchecked(&pool->flush_ser);
32370 wake_up_interruptible(&pool->force_wait);
32371
32372 if (pool->flush_function)
32373 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32374 }
32375
32376 set_current_state(TASK_INTERRUPTIBLE);
32377 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32378 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32379 !kthread_should_stop())
32380 schedule();
32381 __set_current_state(TASK_RUNNING);
32382 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32383 pool->dirty_watermark = params->dirty_watermark;
32384 pool->dirty_len = 0;
32385 spin_lock_init(&pool->pool_lock);
32386 - atomic_set(&pool->req_ser, 0);
32387 - atomic_set(&pool->flush_ser, 0);
32388 + atomic_set_unchecked(&pool->req_ser, 0);
32389 + atomic_set_unchecked(&pool->flush_ser, 0);
32390 init_waitqueue_head(&pool->force_wait);
32391
32392 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32393 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32394 }
32395 spin_unlock_irq(&pool->pool_lock);
32396
32397 - serial = atomic_inc_return(&pool->req_ser);
32398 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32399 wake_up_process(pool->thread);
32400
32401 if (wait_event_interruptible(pool->force_wait,
32402 - atomic_read(&pool->flush_ser) - serial >= 0))
32403 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32404 return -EINTR;
32405
32406 return 0;
32407 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32408 } else {
32409 list_add_tail(&fmr->list, &pool->dirty_list);
32410 if (++pool->dirty_len >= pool->dirty_watermark) {
32411 - atomic_inc(&pool->req_ser);
32412 + atomic_inc_unchecked(&pool->req_ser);
32413 wake_up_process(pool->thread);
32414 }
32415 }
32416 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32417 index 57e07c6..56d09d4 100644
32418 --- a/drivers/infiniband/hw/cxgb4/mem.c
32419 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32420 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32421 int err;
32422 struct fw_ri_tpte tpt;
32423 u32 stag_idx;
32424 - static atomic_t key;
32425 + static atomic_unchecked_t key;
32426
32427 if (c4iw_fatal_error(rdev))
32428 return -EIO;
32429 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32430 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32431 rdev->stats.stag.max = rdev->stats.stag.cur;
32432 mutex_unlock(&rdev->stats.lock);
32433 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32434 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32435 }
32436 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32437 __func__, stag_state, type, pdid, stag_idx);
32438 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32439 index 79b3dbc..96e5fcc 100644
32440 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32441 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32442 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32443 struct ib_atomic_eth *ateth;
32444 struct ipath_ack_entry *e;
32445 u64 vaddr;
32446 - atomic64_t *maddr;
32447 + atomic64_unchecked_t *maddr;
32448 u64 sdata;
32449 u32 rkey;
32450 u8 next;
32451 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32452 IB_ACCESS_REMOTE_ATOMIC)))
32453 goto nack_acc_unlck;
32454 /* Perform atomic OP and save result. */
32455 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32456 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32457 sdata = be64_to_cpu(ateth->swap_data);
32458 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32459 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32460 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32461 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32462 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32463 be64_to_cpu(ateth->compare_data),
32464 sdata);
32465 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32466 index 1f95bba..9530f87 100644
32467 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32468 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32469 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32470 unsigned long flags;
32471 struct ib_wc wc;
32472 u64 sdata;
32473 - atomic64_t *maddr;
32474 + atomic64_unchecked_t *maddr;
32475 enum ib_wc_status send_status;
32476
32477 /*
32478 @@ -382,11 +382,11 @@ again:
32479 IB_ACCESS_REMOTE_ATOMIC)))
32480 goto acc_err;
32481 /* Perform atomic OP and save result. */
32482 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32483 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32484 sdata = wqe->wr.wr.atomic.compare_add;
32485 *(u64 *) sqp->s_sge.sge.vaddr =
32486 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32487 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32488 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32489 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32490 sdata, wqe->wr.wr.atomic.swap);
32491 goto send_comp;
32492 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32493 index 7140199..da60063 100644
32494 --- a/drivers/infiniband/hw/nes/nes.c
32495 +++ b/drivers/infiniband/hw/nes/nes.c
32496 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32497 LIST_HEAD(nes_adapter_list);
32498 static LIST_HEAD(nes_dev_list);
32499
32500 -atomic_t qps_destroyed;
32501 +atomic_unchecked_t qps_destroyed;
32502
32503 static unsigned int ee_flsh_adapter;
32504 static unsigned int sysfs_nonidx_addr;
32505 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32506 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32507 struct nes_adapter *nesadapter = nesdev->nesadapter;
32508
32509 - atomic_inc(&qps_destroyed);
32510 + atomic_inc_unchecked(&qps_destroyed);
32511
32512 /* Free the control structures */
32513
32514 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32515 index c438e46..ca30356 100644
32516 --- a/drivers/infiniband/hw/nes/nes.h
32517 +++ b/drivers/infiniband/hw/nes/nes.h
32518 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32519 extern unsigned int wqm_quanta;
32520 extern struct list_head nes_adapter_list;
32521
32522 -extern atomic_t cm_connects;
32523 -extern atomic_t cm_accepts;
32524 -extern atomic_t cm_disconnects;
32525 -extern atomic_t cm_closes;
32526 -extern atomic_t cm_connecteds;
32527 -extern atomic_t cm_connect_reqs;
32528 -extern atomic_t cm_rejects;
32529 -extern atomic_t mod_qp_timouts;
32530 -extern atomic_t qps_created;
32531 -extern atomic_t qps_destroyed;
32532 -extern atomic_t sw_qps_destroyed;
32533 +extern atomic_unchecked_t cm_connects;
32534 +extern atomic_unchecked_t cm_accepts;
32535 +extern atomic_unchecked_t cm_disconnects;
32536 +extern atomic_unchecked_t cm_closes;
32537 +extern atomic_unchecked_t cm_connecteds;
32538 +extern atomic_unchecked_t cm_connect_reqs;
32539 +extern atomic_unchecked_t cm_rejects;
32540 +extern atomic_unchecked_t mod_qp_timouts;
32541 +extern atomic_unchecked_t qps_created;
32542 +extern atomic_unchecked_t qps_destroyed;
32543 +extern atomic_unchecked_t sw_qps_destroyed;
32544 extern u32 mh_detected;
32545 extern u32 mh_pauses_sent;
32546 extern u32 cm_packets_sent;
32547 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32548 extern u32 cm_packets_received;
32549 extern u32 cm_packets_dropped;
32550 extern u32 cm_packets_retrans;
32551 -extern atomic_t cm_listens_created;
32552 -extern atomic_t cm_listens_destroyed;
32553 +extern atomic_unchecked_t cm_listens_created;
32554 +extern atomic_unchecked_t cm_listens_destroyed;
32555 extern u32 cm_backlog_drops;
32556 -extern atomic_t cm_loopbacks;
32557 -extern atomic_t cm_nodes_created;
32558 -extern atomic_t cm_nodes_destroyed;
32559 -extern atomic_t cm_accel_dropped_pkts;
32560 -extern atomic_t cm_resets_recvd;
32561 -extern atomic_t pau_qps_created;
32562 -extern atomic_t pau_qps_destroyed;
32563 +extern atomic_unchecked_t cm_loopbacks;
32564 +extern atomic_unchecked_t cm_nodes_created;
32565 +extern atomic_unchecked_t cm_nodes_destroyed;
32566 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32567 +extern atomic_unchecked_t cm_resets_recvd;
32568 +extern atomic_unchecked_t pau_qps_created;
32569 +extern atomic_unchecked_t pau_qps_destroyed;
32570
32571 extern u32 int_mod_timer_init;
32572 extern u32 int_mod_cq_depth_256;
32573 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32574 index 020e95c..fbb3450 100644
32575 --- a/drivers/infiniband/hw/nes/nes_cm.c
32576 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32577 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32578 u32 cm_packets_retrans;
32579 u32 cm_packets_created;
32580 u32 cm_packets_received;
32581 -atomic_t cm_listens_created;
32582 -atomic_t cm_listens_destroyed;
32583 +atomic_unchecked_t cm_listens_created;
32584 +atomic_unchecked_t cm_listens_destroyed;
32585 u32 cm_backlog_drops;
32586 -atomic_t cm_loopbacks;
32587 -atomic_t cm_nodes_created;
32588 -atomic_t cm_nodes_destroyed;
32589 -atomic_t cm_accel_dropped_pkts;
32590 -atomic_t cm_resets_recvd;
32591 +atomic_unchecked_t cm_loopbacks;
32592 +atomic_unchecked_t cm_nodes_created;
32593 +atomic_unchecked_t cm_nodes_destroyed;
32594 +atomic_unchecked_t cm_accel_dropped_pkts;
32595 +atomic_unchecked_t cm_resets_recvd;
32596
32597 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32598 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32599 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32600
32601 static struct nes_cm_core *g_cm_core;
32602
32603 -atomic_t cm_connects;
32604 -atomic_t cm_accepts;
32605 -atomic_t cm_disconnects;
32606 -atomic_t cm_closes;
32607 -atomic_t cm_connecteds;
32608 -atomic_t cm_connect_reqs;
32609 -atomic_t cm_rejects;
32610 +atomic_unchecked_t cm_connects;
32611 +atomic_unchecked_t cm_accepts;
32612 +atomic_unchecked_t cm_disconnects;
32613 +atomic_unchecked_t cm_closes;
32614 +atomic_unchecked_t cm_connecteds;
32615 +atomic_unchecked_t cm_connect_reqs;
32616 +atomic_unchecked_t cm_rejects;
32617
32618 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32619 {
32620 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32621 kfree(listener);
32622 listener = NULL;
32623 ret = 0;
32624 - atomic_inc(&cm_listens_destroyed);
32625 + atomic_inc_unchecked(&cm_listens_destroyed);
32626 } else {
32627 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32628 }
32629 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32630 cm_node->rem_mac);
32631
32632 add_hte_node(cm_core, cm_node);
32633 - atomic_inc(&cm_nodes_created);
32634 + atomic_inc_unchecked(&cm_nodes_created);
32635
32636 return cm_node;
32637 }
32638 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32639 }
32640
32641 atomic_dec(&cm_core->node_cnt);
32642 - atomic_inc(&cm_nodes_destroyed);
32643 + atomic_inc_unchecked(&cm_nodes_destroyed);
32644 nesqp = cm_node->nesqp;
32645 if (nesqp) {
32646 nesqp->cm_node = NULL;
32647 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32648
32649 static void drop_packet(struct sk_buff *skb)
32650 {
32651 - atomic_inc(&cm_accel_dropped_pkts);
32652 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32653 dev_kfree_skb_any(skb);
32654 }
32655
32656 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32657 {
32658
32659 int reset = 0; /* whether to send reset in case of err.. */
32660 - atomic_inc(&cm_resets_recvd);
32661 + atomic_inc_unchecked(&cm_resets_recvd);
32662 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32663 " refcnt=%d\n", cm_node, cm_node->state,
32664 atomic_read(&cm_node->ref_count));
32665 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32666 rem_ref_cm_node(cm_node->cm_core, cm_node);
32667 return NULL;
32668 }
32669 - atomic_inc(&cm_loopbacks);
32670 + atomic_inc_unchecked(&cm_loopbacks);
32671 loopbackremotenode->loopbackpartner = cm_node;
32672 loopbackremotenode->tcp_cntxt.rcv_wscale =
32673 NES_CM_DEFAULT_RCV_WND_SCALE;
32674 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32675 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32676 else {
32677 rem_ref_cm_node(cm_core, cm_node);
32678 - atomic_inc(&cm_accel_dropped_pkts);
32679 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32680 dev_kfree_skb_any(skb);
32681 }
32682 break;
32683 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32684
32685 if ((cm_id) && (cm_id->event_handler)) {
32686 if (issue_disconn) {
32687 - atomic_inc(&cm_disconnects);
32688 + atomic_inc_unchecked(&cm_disconnects);
32689 cm_event.event = IW_CM_EVENT_DISCONNECT;
32690 cm_event.status = disconn_status;
32691 cm_event.local_addr = cm_id->local_addr;
32692 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32693 }
32694
32695 if (issue_close) {
32696 - atomic_inc(&cm_closes);
32697 + atomic_inc_unchecked(&cm_closes);
32698 nes_disconnect(nesqp, 1);
32699
32700 cm_id->provider_data = nesqp;
32701 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32702
32703 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32704 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32705 - atomic_inc(&cm_accepts);
32706 + atomic_inc_unchecked(&cm_accepts);
32707
32708 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32709 netdev_refcnt_read(nesvnic->netdev));
32710 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32711 struct nes_cm_core *cm_core;
32712 u8 *start_buff;
32713
32714 - atomic_inc(&cm_rejects);
32715 + atomic_inc_unchecked(&cm_rejects);
32716 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32717 loopback = cm_node->loopbackpartner;
32718 cm_core = cm_node->cm_core;
32719 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32720 ntohl(cm_id->local_addr.sin_addr.s_addr),
32721 ntohs(cm_id->local_addr.sin_port));
32722
32723 - atomic_inc(&cm_connects);
32724 + atomic_inc_unchecked(&cm_connects);
32725 nesqp->active_conn = 1;
32726
32727 /* cache the cm_id in the qp */
32728 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32729 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32730 return err;
32731 }
32732 - atomic_inc(&cm_listens_created);
32733 + atomic_inc_unchecked(&cm_listens_created);
32734 }
32735
32736 cm_id->add_ref(cm_id);
32737 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32738
32739 if (nesqp->destroyed)
32740 return;
32741 - atomic_inc(&cm_connecteds);
32742 + atomic_inc_unchecked(&cm_connecteds);
32743 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32744 " local port 0x%04X. jiffies = %lu.\n",
32745 nesqp->hwqp.qp_id,
32746 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32747
32748 cm_id->add_ref(cm_id);
32749 ret = cm_id->event_handler(cm_id, &cm_event);
32750 - atomic_inc(&cm_closes);
32751 + atomic_inc_unchecked(&cm_closes);
32752 cm_event.event = IW_CM_EVENT_CLOSE;
32753 cm_event.status = 0;
32754 cm_event.provider_data = cm_id->provider_data;
32755 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32756 return;
32757 cm_id = cm_node->cm_id;
32758
32759 - atomic_inc(&cm_connect_reqs);
32760 + atomic_inc_unchecked(&cm_connect_reqs);
32761 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32762 cm_node, cm_id, jiffies);
32763
32764 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32765 return;
32766 cm_id = cm_node->cm_id;
32767
32768 - atomic_inc(&cm_connect_reqs);
32769 + atomic_inc_unchecked(&cm_connect_reqs);
32770 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32771 cm_node, cm_id, jiffies);
32772
32773 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32774 index 3ba7be3..c81f6ff 100644
32775 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32776 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32777 @@ -40,8 +40,8 @@
32778 #include "nes.h"
32779 #include "nes_mgt.h"
32780
32781 -atomic_t pau_qps_created;
32782 -atomic_t pau_qps_destroyed;
32783 +atomic_unchecked_t pau_qps_created;
32784 +atomic_unchecked_t pau_qps_destroyed;
32785
32786 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32787 {
32788 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32789 {
32790 struct sk_buff *skb;
32791 unsigned long flags;
32792 - atomic_inc(&pau_qps_destroyed);
32793 + atomic_inc_unchecked(&pau_qps_destroyed);
32794
32795 /* Free packets that have not yet been forwarded */
32796 /* Lock is acquired by skb_dequeue when removing the skb */
32797 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32798 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32799 skb_queue_head_init(&nesqp->pau_list);
32800 spin_lock_init(&nesqp->pau_lock);
32801 - atomic_inc(&pau_qps_created);
32802 + atomic_inc_unchecked(&pau_qps_created);
32803 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32804 }
32805
32806 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32807 index f3a3ecf..57d311d 100644
32808 --- a/drivers/infiniband/hw/nes/nes_nic.c
32809 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32810 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32811 target_stat_values[++index] = mh_detected;
32812 target_stat_values[++index] = mh_pauses_sent;
32813 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32814 - target_stat_values[++index] = atomic_read(&cm_connects);
32815 - target_stat_values[++index] = atomic_read(&cm_accepts);
32816 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32817 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32818 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32819 - target_stat_values[++index] = atomic_read(&cm_rejects);
32820 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32821 - target_stat_values[++index] = atomic_read(&qps_created);
32822 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32823 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32824 - target_stat_values[++index] = atomic_read(&cm_closes);
32825 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32826 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32827 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32828 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32829 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32830 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32831 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32832 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32833 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32834 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32835 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32836 target_stat_values[++index] = cm_packets_sent;
32837 target_stat_values[++index] = cm_packets_bounced;
32838 target_stat_values[++index] = cm_packets_created;
32839 target_stat_values[++index] = cm_packets_received;
32840 target_stat_values[++index] = cm_packets_dropped;
32841 target_stat_values[++index] = cm_packets_retrans;
32842 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32843 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32844 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32845 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32846 target_stat_values[++index] = cm_backlog_drops;
32847 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32848 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32849 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32850 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32851 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32852 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32853 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32854 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32855 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32856 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32857 target_stat_values[++index] = nesadapter->free_4kpbl;
32858 target_stat_values[++index] = nesadapter->free_256pbl;
32859 target_stat_values[++index] = int_mod_timer_init;
32860 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32861 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32862 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32863 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32864 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32865 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32866 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32867 }
32868
32869 /**
32870 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32871 index 8b8812d..a5e1133 100644
32872 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32873 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32874 @@ -46,9 +46,9 @@
32875
32876 #include <rdma/ib_umem.h>
32877
32878 -atomic_t mod_qp_timouts;
32879 -atomic_t qps_created;
32880 -atomic_t sw_qps_destroyed;
32881 +atomic_unchecked_t mod_qp_timouts;
32882 +atomic_unchecked_t qps_created;
32883 +atomic_unchecked_t sw_qps_destroyed;
32884
32885 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32886
32887 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32888 if (init_attr->create_flags)
32889 return ERR_PTR(-EINVAL);
32890
32891 - atomic_inc(&qps_created);
32892 + atomic_inc_unchecked(&qps_created);
32893 switch (init_attr->qp_type) {
32894 case IB_QPT_RC:
32895 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32896 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32897 struct iw_cm_event cm_event;
32898 int ret = 0;
32899
32900 - atomic_inc(&sw_qps_destroyed);
32901 + atomic_inc_unchecked(&sw_qps_destroyed);
32902 nesqp->destroyed = 1;
32903
32904 /* Blow away the connection if it exists. */
32905 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32906 index 7b1b8669..4b69f85 100644
32907 --- a/drivers/infiniband/hw/qib/qib.h
32908 +++ b/drivers/infiniband/hw/qib/qib.h
32909 @@ -51,6 +51,7 @@
32910 #include <linux/completion.h>
32911 #include <linux/kref.h>
32912 #include <linux/sched.h>
32913 +#include <linux/slab.h>
32914
32915 #include "qib_common.h"
32916 #include "qib_verbs.h"
32917 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32918 index da739d9..da1c7f4 100644
32919 --- a/drivers/input/gameport/gameport.c
32920 +++ b/drivers/input/gameport/gameport.c
32921 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32922 */
32923 static void gameport_init_port(struct gameport *gameport)
32924 {
32925 - static atomic_t gameport_no = ATOMIC_INIT(0);
32926 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32927
32928 __module_get(THIS_MODULE);
32929
32930 mutex_init(&gameport->drv_mutex);
32931 device_initialize(&gameport->dev);
32932 dev_set_name(&gameport->dev, "gameport%lu",
32933 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32934 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32935 gameport->dev.bus = &gameport_bus;
32936 gameport->dev.release = gameport_release_port;
32937 if (gameport->parent)
32938 diff --git a/drivers/input/input.c b/drivers/input/input.c
32939 index 8921c61..f5cd63d 100644
32940 --- a/drivers/input/input.c
32941 +++ b/drivers/input/input.c
32942 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32943 */
32944 int input_register_device(struct input_dev *dev)
32945 {
32946 - static atomic_t input_no = ATOMIC_INIT(0);
32947 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32948 struct input_handler *handler;
32949 const char *path;
32950 int error;
32951 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32952 dev->setkeycode = input_default_setkeycode;
32953
32954 dev_set_name(&dev->dev, "input%ld",
32955 - (unsigned long) atomic_inc_return(&input_no) - 1);
32956 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32957
32958 error = device_add(&dev->dev);
32959 if (error)
32960 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32961 index 04c69af..5f92d00 100644
32962 --- a/drivers/input/joystick/sidewinder.c
32963 +++ b/drivers/input/joystick/sidewinder.c
32964 @@ -30,6 +30,7 @@
32965 #include <linux/kernel.h>
32966 #include <linux/module.h>
32967 #include <linux/slab.h>
32968 +#include <linux/sched.h>
32969 #include <linux/init.h>
32970 #include <linux/input.h>
32971 #include <linux/gameport.h>
32972 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32973 index 83811e4..0822b90 100644
32974 --- a/drivers/input/joystick/xpad.c
32975 +++ b/drivers/input/joystick/xpad.c
32976 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32977
32978 static int xpad_led_probe(struct usb_xpad *xpad)
32979 {
32980 - static atomic_t led_seq = ATOMIC_INIT(0);
32981 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32982 long led_no;
32983 struct xpad_led *led;
32984 struct led_classdev *led_cdev;
32985 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32986 if (!led)
32987 return -ENOMEM;
32988
32989 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32990 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32991
32992 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32993 led->xpad = xpad;
32994 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32995 index 0110b5a..d3ad144 100644
32996 --- a/drivers/input/mousedev.c
32997 +++ b/drivers/input/mousedev.c
32998 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32999
33000 spin_unlock_irq(&client->packet_lock);
33001
33002 - if (copy_to_user(buffer, data, count))
33003 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33004 return -EFAULT;
33005
33006 return count;
33007 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33008 index d0f7533..fb8215b 100644
33009 --- a/drivers/input/serio/serio.c
33010 +++ b/drivers/input/serio/serio.c
33011 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33012 */
33013 static void serio_init_port(struct serio *serio)
33014 {
33015 - static atomic_t serio_no = ATOMIC_INIT(0);
33016 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33017
33018 __module_get(THIS_MODULE);
33019
33020 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33021 mutex_init(&serio->drv_mutex);
33022 device_initialize(&serio->dev);
33023 dev_set_name(&serio->dev, "serio%ld",
33024 - (long)atomic_inc_return(&serio_no) - 1);
33025 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33026 serio->dev.bus = &serio_bus;
33027 serio->dev.release = serio_release_port;
33028 serio->dev.groups = serio_device_attr_groups;
33029 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33030 index 38c4bd8..58965d9 100644
33031 --- a/drivers/isdn/capi/capi.c
33032 +++ b/drivers/isdn/capi/capi.c
33033 @@ -83,8 +83,8 @@ struct capiminor {
33034
33035 struct capi20_appl *ap;
33036 u32 ncci;
33037 - atomic_t datahandle;
33038 - atomic_t msgid;
33039 + atomic_unchecked_t datahandle;
33040 + atomic_unchecked_t msgid;
33041
33042 struct tty_port port;
33043 int ttyinstop;
33044 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33045 capimsg_setu16(s, 2, mp->ap->applid);
33046 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33047 capimsg_setu8 (s, 5, CAPI_RESP);
33048 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33049 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33050 capimsg_setu32(s, 8, mp->ncci);
33051 capimsg_setu16(s, 12, datahandle);
33052 }
33053 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33054 mp->outbytes -= len;
33055 spin_unlock_bh(&mp->outlock);
33056
33057 - datahandle = atomic_inc_return(&mp->datahandle);
33058 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33059 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33060 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33061 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33062 capimsg_setu16(skb->data, 2, mp->ap->applid);
33063 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33064 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33065 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33066 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33067 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33068 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33069 capimsg_setu16(skb->data, 16, len); /* Data length */
33070 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33071 index a6d9fd2..afdb8a3 100644
33072 --- a/drivers/isdn/gigaset/interface.c
33073 +++ b/drivers/isdn/gigaset/interface.c
33074 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33075 }
33076 tty->driver_data = cs;
33077
33078 - ++cs->port.count;
33079 + atomic_inc(&cs->port.count);
33080
33081 - if (cs->port.count == 1) {
33082 + if (atomic_read(&cs->port.count) == 1) {
33083 tty_port_tty_set(&cs->port, tty);
33084 tty->low_latency = 1;
33085 }
33086 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33087
33088 if (!cs->connected)
33089 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33090 - else if (!cs->port.count)
33091 + else if (!atomic_read(&cs->port.count))
33092 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33093 - else if (!--cs->port.count)
33094 + else if (!atomic_dec_return(&cs->port.count))
33095 tty_port_tty_set(&cs->port, NULL);
33096
33097 mutex_unlock(&cs->mutex);
33098 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33099 index 821f7ac..28d4030 100644
33100 --- a/drivers/isdn/hardware/avm/b1.c
33101 +++ b/drivers/isdn/hardware/avm/b1.c
33102 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33103 }
33104 if (left) {
33105 if (t4file->user) {
33106 - if (copy_from_user(buf, dp, left))
33107 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33108 return -EFAULT;
33109 } else {
33110 memcpy(buf, dp, left);
33111 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33112 }
33113 if (left) {
33114 if (config->user) {
33115 - if (copy_from_user(buf, dp, left))
33116 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33117 return -EFAULT;
33118 } else {
33119 memcpy(buf, dp, left);
33120 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33121 index dd6b53a..19d9ee6 100644
33122 --- a/drivers/isdn/hardware/eicon/divasync.h
33123 +++ b/drivers/isdn/hardware/eicon/divasync.h
33124 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33125 } diva_didd_add_adapter_t;
33126 typedef struct _diva_didd_remove_adapter {
33127 IDI_CALL p_request;
33128 -} diva_didd_remove_adapter_t;
33129 +} __no_const diva_didd_remove_adapter_t;
33130 typedef struct _diva_didd_read_adapter_array {
33131 void *buffer;
33132 dword length;
33133 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33134 index d303e65..28bcb7b 100644
33135 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33136 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33137 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33138 typedef struct _diva_os_idi_adapter_interface {
33139 diva_init_card_proc_t cleanup_adapter_proc;
33140 diva_cmd_card_proc_t cmd_proc;
33141 -} diva_os_idi_adapter_interface_t;
33142 +} __no_const diva_os_idi_adapter_interface_t;
33143
33144 typedef struct _diva_os_xdi_adapter {
33145 struct list_head link;
33146 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33147 index 7bc5067..fd36232 100644
33148 --- a/drivers/isdn/i4l/isdn_tty.c
33149 +++ b/drivers/isdn/i4l/isdn_tty.c
33150 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33151 port = &info->port;
33152 #ifdef ISDN_DEBUG_MODEM_OPEN
33153 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33154 - port->count);
33155 + atomic_read(&port->count))
33156 #endif
33157 - port->count++;
33158 + atomic_inc(&port->count);
33159 tty->driver_data = info;
33160 port->tty = tty;
33161 tty->port = port;
33162 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33163 #endif
33164 return;
33165 }
33166 - if ((tty->count == 1) && (port->count != 1)) {
33167 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33168 /*
33169 * Uh, oh. tty->count is 1, which means that the tty
33170 * structure will be freed. Info->count should always
33171 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33172 * serial port won't be shutdown.
33173 */
33174 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33175 - "info->count is %d\n", port->count);
33176 - port->count = 1;
33177 + "info->count is %d\n", atomic_read(&port->count));
33178 + atomic_set(&port->count, 1);
33179 }
33180 - if (--port->count < 0) {
33181 + if (atomic_dec_return(&port->count) < 0) {
33182 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33183 - info->line, port->count);
33184 - port->count = 0;
33185 + info->line, atomic_read(&port->count));
33186 + atomic_set(&port->count, 0);
33187 }
33188 - if (port->count) {
33189 + if (atomic_read(&port->count)) {
33190 #ifdef ISDN_DEBUG_MODEM_OPEN
33191 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33192 #endif
33193 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33194 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33195 return;
33196 isdn_tty_shutdown(info);
33197 - port->count = 0;
33198 + atomic_set(&port->count, 0);
33199 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33200 port->tty = NULL;
33201 wake_up_interruptible(&port->open_wait);
33202 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33203 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33204 modem_info *info = &dev->mdm.info[i];
33205
33206 - if (info->port.count == 0)
33207 + if (atomic_read(&info->port.count) == 0)
33208 continue;
33209 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33210 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33211 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33212 index e74df7c..03a03ba 100644
33213 --- a/drivers/isdn/icn/icn.c
33214 +++ b/drivers/isdn/icn/icn.c
33215 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33216 if (count > len)
33217 count = len;
33218 if (user) {
33219 - if (copy_from_user(msg, buf, count))
33220 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33221 return -EFAULT;
33222 } else
33223 memcpy(msg, buf, count);
33224 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33225 index b5fdcb7..5b6c59f 100644
33226 --- a/drivers/lguest/core.c
33227 +++ b/drivers/lguest/core.c
33228 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33229 * it's worked so far. The end address needs +1 because __get_vm_area
33230 * allocates an extra guard page, so we need space for that.
33231 */
33232 +
33233 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33234 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33235 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33236 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33237 +#else
33238 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33239 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33240 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33241 +#endif
33242 +
33243 if (!switcher_vma) {
33244 err = -ENOMEM;
33245 printk("lguest: could not map switcher pages high\n");
33246 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33247 * Now the Switcher is mapped at the right address, we can't fail!
33248 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33249 */
33250 - memcpy(switcher_vma->addr, start_switcher_text,
33251 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33252 end_switcher_text - start_switcher_text);
33253
33254 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33255 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33256 index 39809035..ce25c5e 100644
33257 --- a/drivers/lguest/x86/core.c
33258 +++ b/drivers/lguest/x86/core.c
33259 @@ -59,7 +59,7 @@ static struct {
33260 /* Offset from where switcher.S was compiled to where we've copied it */
33261 static unsigned long switcher_offset(void)
33262 {
33263 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33264 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33265 }
33266
33267 /* This cpu's struct lguest_pages. */
33268 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33269 * These copies are pretty cheap, so we do them unconditionally: */
33270 /* Save the current Host top-level page directory.
33271 */
33272 +
33273 +#ifdef CONFIG_PAX_PER_CPU_PGD
33274 + pages->state.host_cr3 = read_cr3();
33275 +#else
33276 pages->state.host_cr3 = __pa(current->mm->pgd);
33277 +#endif
33278 +
33279 /*
33280 * Set up the Guest's page tables to see this CPU's pages (and no
33281 * other CPU's pages).
33282 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33283 * compiled-in switcher code and the high-mapped copy we just made.
33284 */
33285 for (i = 0; i < IDT_ENTRIES; i++)
33286 - default_idt_entries[i] += switcher_offset();
33287 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33288
33289 /*
33290 * Set up the Switcher's per-cpu areas.
33291 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33292 * it will be undisturbed when we switch. To change %cs and jump we
33293 * need this structure to feed to Intel's "lcall" instruction.
33294 */
33295 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33296 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33297 lguest_entry.segment = LGUEST_CS;
33298
33299 /*
33300 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33301 index 40634b0..4f5855e 100644
33302 --- a/drivers/lguest/x86/switcher_32.S
33303 +++ b/drivers/lguest/x86/switcher_32.S
33304 @@ -87,6 +87,7 @@
33305 #include <asm/page.h>
33306 #include <asm/segment.h>
33307 #include <asm/lguest.h>
33308 +#include <asm/processor-flags.h>
33309
33310 // We mark the start of the code to copy
33311 // It's placed in .text tho it's never run here
33312 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33313 // Changes type when we load it: damn Intel!
33314 // For after we switch over our page tables
33315 // That entry will be read-only: we'd crash.
33316 +
33317 +#ifdef CONFIG_PAX_KERNEXEC
33318 + mov %cr0, %edx
33319 + xor $X86_CR0_WP, %edx
33320 + mov %edx, %cr0
33321 +#endif
33322 +
33323 movl $(GDT_ENTRY_TSS*8), %edx
33324 ltr %dx
33325
33326 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33327 // Let's clear it again for our return.
33328 // The GDT descriptor of the Host
33329 // Points to the table after two "size" bytes
33330 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33331 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33332 // Clear "used" from type field (byte 5, bit 2)
33333 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33334 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33335 +
33336 +#ifdef CONFIG_PAX_KERNEXEC
33337 + mov %cr0, %eax
33338 + xor $X86_CR0_WP, %eax
33339 + mov %eax, %cr0
33340 +#endif
33341
33342 // Once our page table's switched, the Guest is live!
33343 // The Host fades as we run this final step.
33344 @@ -295,13 +309,12 @@ deliver_to_host:
33345 // I consulted gcc, and it gave
33346 // These instructions, which I gladly credit:
33347 leal (%edx,%ebx,8), %eax
33348 - movzwl (%eax),%edx
33349 - movl 4(%eax), %eax
33350 - xorw %ax, %ax
33351 - orl %eax, %edx
33352 + movl 4(%eax), %edx
33353 + movw (%eax), %dx
33354 // Now the address of the handler's in %edx
33355 // We call it now: its "iret" drops us home.
33356 - jmp *%edx
33357 + ljmp $__KERNEL_CS, $1f
33358 +1: jmp *%edx
33359
33360 // Every interrupt can come to us here
33361 // But we must truly tell each apart.
33362 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33363 index 20e5c2c..9e849a9 100644
33364 --- a/drivers/macintosh/macio_asic.c
33365 +++ b/drivers/macintosh/macio_asic.c
33366 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33367 * MacIO is matched against any Apple ID, it's probe() function
33368 * will then decide wether it applies or not
33369 */
33370 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33371 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33372 .vendor = PCI_VENDOR_ID_APPLE,
33373 .device = PCI_ANY_ID,
33374 .subvendor = PCI_ANY_ID,
33375 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33376 index 94e7f6b..2f4a0d8 100644
33377 --- a/drivers/md/bitmap.c
33378 +++ b/drivers/md/bitmap.c
33379 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33380 chunk_kb ? "KB" : "B");
33381 if (bitmap->storage.file) {
33382 seq_printf(seq, ", file: ");
33383 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33384 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33385 }
33386
33387 seq_printf(seq, "\n");
33388 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33389 index afd9598..528d8f9 100644
33390 --- a/drivers/md/dm-ioctl.c
33391 +++ b/drivers/md/dm-ioctl.c
33392 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33393 cmd == DM_LIST_VERSIONS_CMD)
33394 return 0;
33395
33396 - if ((cmd == DM_DEV_CREATE_CMD)) {
33397 + if (cmd == DM_DEV_CREATE_CMD) {
33398 if (!*param->name) {
33399 DMWARN("name not supplied when creating device");
33400 return -EINVAL;
33401 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33402 index bc5ddba8..b961159 100644
33403 --- a/drivers/md/dm-raid1.c
33404 +++ b/drivers/md/dm-raid1.c
33405 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33406
33407 struct mirror {
33408 struct mirror_set *ms;
33409 - atomic_t error_count;
33410 + atomic_unchecked_t error_count;
33411 unsigned long error_type;
33412 struct dm_dev *dev;
33413 sector_t offset;
33414 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33415 struct mirror *m;
33416
33417 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33418 - if (!atomic_read(&m->error_count))
33419 + if (!atomic_read_unchecked(&m->error_count))
33420 return m;
33421
33422 return NULL;
33423 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33424 * simple way to tell if a device has encountered
33425 * errors.
33426 */
33427 - atomic_inc(&m->error_count);
33428 + atomic_inc_unchecked(&m->error_count);
33429
33430 if (test_and_set_bit(error_type, &m->error_type))
33431 return;
33432 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33433 struct mirror *m = get_default_mirror(ms);
33434
33435 do {
33436 - if (likely(!atomic_read(&m->error_count)))
33437 + if (likely(!atomic_read_unchecked(&m->error_count)))
33438 return m;
33439
33440 if (m-- == ms->mirror)
33441 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33442 {
33443 struct mirror *default_mirror = get_default_mirror(m->ms);
33444
33445 - return !atomic_read(&default_mirror->error_count);
33446 + return !atomic_read_unchecked(&default_mirror->error_count);
33447 }
33448
33449 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33450 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33451 */
33452 if (likely(region_in_sync(ms, region, 1)))
33453 m = choose_mirror(ms, bio->bi_sector);
33454 - else if (m && atomic_read(&m->error_count))
33455 + else if (m && atomic_read_unchecked(&m->error_count))
33456 m = NULL;
33457
33458 if (likely(m))
33459 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33460 }
33461
33462 ms->mirror[mirror].ms = ms;
33463 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33464 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33465 ms->mirror[mirror].error_type = 0;
33466 ms->mirror[mirror].offset = offset;
33467
33468 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33469 */
33470 static char device_status_char(struct mirror *m)
33471 {
33472 - if (!atomic_read(&(m->error_count)))
33473 + if (!atomic_read_unchecked(&(m->error_count)))
33474 return 'A';
33475
33476 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33477 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33478 index a087bf2..4c94786 100644
33479 --- a/drivers/md/dm-stripe.c
33480 +++ b/drivers/md/dm-stripe.c
33481 @@ -20,7 +20,7 @@ struct stripe {
33482 struct dm_dev *dev;
33483 sector_t physical_start;
33484
33485 - atomic_t error_count;
33486 + atomic_unchecked_t error_count;
33487 };
33488
33489 struct stripe_c {
33490 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33491 kfree(sc);
33492 return r;
33493 }
33494 - atomic_set(&(sc->stripe[i].error_count), 0);
33495 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33496 }
33497
33498 ti->private = sc;
33499 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33500 DMEMIT("%d ", sc->stripes);
33501 for (i = 0; i < sc->stripes; i++) {
33502 DMEMIT("%s ", sc->stripe[i].dev->name);
33503 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33504 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33505 'D' : 'A';
33506 }
33507 buffer[i] = '\0';
33508 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33509 */
33510 for (i = 0; i < sc->stripes; i++)
33511 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33512 - atomic_inc(&(sc->stripe[i].error_count));
33513 - if (atomic_read(&(sc->stripe[i].error_count)) <
33514 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33515 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33516 DM_IO_ERROR_THRESHOLD)
33517 schedule_work(&sc->trigger_event);
33518 }
33519 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33520 index 100368e..64262ce 100644
33521 --- a/drivers/md/dm-table.c
33522 +++ b/drivers/md/dm-table.c
33523 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33524 if (!dev_size)
33525 return 0;
33526
33527 - if ((start >= dev_size) || (start + len > dev_size)) {
33528 + if ((start >= dev_size) || (len > dev_size - start)) {
33529 DMWARN("%s: %s too small for target: "
33530 "start=%llu, len=%llu, dev_size=%llu",
33531 dm_device_name(ti->table->md), bdevname(bdev, b),
33532 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33533 index 693e149..b7e0fde 100644
33534 --- a/drivers/md/dm-thin-metadata.c
33535 +++ b/drivers/md/dm-thin-metadata.c
33536 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33537 {
33538 pmd->info.tm = pmd->tm;
33539 pmd->info.levels = 2;
33540 - pmd->info.value_type.context = pmd->data_sm;
33541 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33542 pmd->info.value_type.size = sizeof(__le64);
33543 pmd->info.value_type.inc = data_block_inc;
33544 pmd->info.value_type.dec = data_block_dec;
33545 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33546
33547 pmd->bl_info.tm = pmd->tm;
33548 pmd->bl_info.levels = 1;
33549 - pmd->bl_info.value_type.context = pmd->data_sm;
33550 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33551 pmd->bl_info.value_type.size = sizeof(__le64);
33552 pmd->bl_info.value_type.inc = data_block_inc;
33553 pmd->bl_info.value_type.dec = data_block_dec;
33554 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33555 index 67ffa39..cb3b1dd 100644
33556 --- a/drivers/md/dm.c
33557 +++ b/drivers/md/dm.c
33558 @@ -176,9 +176,9 @@ struct mapped_device {
33559 /*
33560 * Event handling.
33561 */
33562 - atomic_t event_nr;
33563 + atomic_unchecked_t event_nr;
33564 wait_queue_head_t eventq;
33565 - atomic_t uevent_seq;
33566 + atomic_unchecked_t uevent_seq;
33567 struct list_head uevent_list;
33568 spinlock_t uevent_lock; /* Protect access to uevent_list */
33569
33570 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33571 rwlock_init(&md->map_lock);
33572 atomic_set(&md->holders, 1);
33573 atomic_set(&md->open_count, 0);
33574 - atomic_set(&md->event_nr, 0);
33575 - atomic_set(&md->uevent_seq, 0);
33576 + atomic_set_unchecked(&md->event_nr, 0);
33577 + atomic_set_unchecked(&md->uevent_seq, 0);
33578 INIT_LIST_HEAD(&md->uevent_list);
33579 spin_lock_init(&md->uevent_lock);
33580
33581 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33582
33583 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33584
33585 - atomic_inc(&md->event_nr);
33586 + atomic_inc_unchecked(&md->event_nr);
33587 wake_up(&md->eventq);
33588 }
33589
33590 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33591
33592 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33593 {
33594 - return atomic_add_return(1, &md->uevent_seq);
33595 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33596 }
33597
33598 uint32_t dm_get_event_nr(struct mapped_device *md)
33599 {
33600 - return atomic_read(&md->event_nr);
33601 + return atomic_read_unchecked(&md->event_nr);
33602 }
33603
33604 int dm_wait_event(struct mapped_device *md, int event_nr)
33605 {
33606 return wait_event_interruptible(md->eventq,
33607 - (event_nr != atomic_read(&md->event_nr)));
33608 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33609 }
33610
33611 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33612 diff --git a/drivers/md/md.c b/drivers/md/md.c
33613 index 308e87b..7f365d6 100644
33614 --- a/drivers/md/md.c
33615 +++ b/drivers/md/md.c
33616 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33617 * start build, activate spare
33618 */
33619 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33620 -static atomic_t md_event_count;
33621 +static atomic_unchecked_t md_event_count;
33622 void md_new_event(struct mddev *mddev)
33623 {
33624 - atomic_inc(&md_event_count);
33625 + atomic_inc_unchecked(&md_event_count);
33626 wake_up(&md_event_waiters);
33627 }
33628 EXPORT_SYMBOL_GPL(md_new_event);
33629 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33630 */
33631 static void md_new_event_inintr(struct mddev *mddev)
33632 {
33633 - atomic_inc(&md_event_count);
33634 + atomic_inc_unchecked(&md_event_count);
33635 wake_up(&md_event_waiters);
33636 }
33637
33638 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33639 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33640 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33641 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33642 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33643 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33644
33645 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33646 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33647 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33648 else
33649 sb->resync_offset = cpu_to_le64(0);
33650
33651 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33652 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33653
33654 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33655 sb->size = cpu_to_le64(mddev->dev_sectors);
33656 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33657 static ssize_t
33658 errors_show(struct md_rdev *rdev, char *page)
33659 {
33660 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33661 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33662 }
33663
33664 static ssize_t
33665 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33666 char *e;
33667 unsigned long n = simple_strtoul(buf, &e, 10);
33668 if (*buf && (*e == 0 || *e == '\n')) {
33669 - atomic_set(&rdev->corrected_errors, n);
33670 + atomic_set_unchecked(&rdev->corrected_errors, n);
33671 return len;
33672 }
33673 return -EINVAL;
33674 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33675 rdev->sb_loaded = 0;
33676 rdev->bb_page = NULL;
33677 atomic_set(&rdev->nr_pending, 0);
33678 - atomic_set(&rdev->read_errors, 0);
33679 - atomic_set(&rdev->corrected_errors, 0);
33680 + atomic_set_unchecked(&rdev->read_errors, 0);
33681 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33682
33683 INIT_LIST_HEAD(&rdev->same_set);
33684 init_waitqueue_head(&rdev->blocked_wait);
33685 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33686
33687 spin_unlock(&pers_lock);
33688 seq_printf(seq, "\n");
33689 - seq->poll_event = atomic_read(&md_event_count);
33690 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33691 return 0;
33692 }
33693 if (v == (void*)2) {
33694 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33695 return error;
33696
33697 seq = file->private_data;
33698 - seq->poll_event = atomic_read(&md_event_count);
33699 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33700 return error;
33701 }
33702
33703 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33704 /* always allow read */
33705 mask = POLLIN | POLLRDNORM;
33706
33707 - if (seq->poll_event != atomic_read(&md_event_count))
33708 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33709 mask |= POLLERR | POLLPRI;
33710 return mask;
33711 }
33712 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33713 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33714 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33715 (int)part_stat_read(&disk->part0, sectors[1]) -
33716 - atomic_read(&disk->sync_io);
33717 + atomic_read_unchecked(&disk->sync_io);
33718 /* sync IO will cause sync_io to increase before the disk_stats
33719 * as sync_io is counted when a request starts, and
33720 * disk_stats is counted when it completes.
33721 diff --git a/drivers/md/md.h b/drivers/md/md.h
33722 index f385b03..b600be8 100644
33723 --- a/drivers/md/md.h
33724 +++ b/drivers/md/md.h
33725 @@ -94,13 +94,13 @@ struct md_rdev {
33726 * only maintained for arrays that
33727 * support hot removal
33728 */
33729 - atomic_t read_errors; /* number of consecutive read errors that
33730 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33731 * we have tried to ignore.
33732 */
33733 struct timespec last_read_error; /* monotonic time since our
33734 * last read error
33735 */
33736 - atomic_t corrected_errors; /* number of corrected read errors,
33737 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33738 * for reporting to userspace and storing
33739 * in superblock.
33740 */
33741 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33742
33743 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33744 {
33745 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33746 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33747 }
33748
33749 struct md_personality
33750 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33751 index f6d29e6..7917f5e 100644
33752 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33753 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33754 @@ -22,7 +22,7 @@
33755 * Space map interface.
33756 */
33757 struct sm_disk {
33758 - struct dm_space_map sm;
33759 + dm_space_map_no_const sm;
33760
33761 struct ll_disk ll;
33762 struct ll_disk old_ll;
33763 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33764 index e89ae5e..062e4c2 100644
33765 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33766 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33767 @@ -43,7 +43,7 @@ struct block_op {
33768 };
33769
33770 struct sm_metadata {
33771 - struct dm_space_map sm;
33772 + dm_space_map_no_const sm;
33773
33774 struct ll_disk ll;
33775 struct ll_disk old_ll;
33776 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33777 index 1cbfc6b..56e1dbb 100644
33778 --- a/drivers/md/persistent-data/dm-space-map.h
33779 +++ b/drivers/md/persistent-data/dm-space-map.h
33780 @@ -60,6 +60,7 @@ struct dm_space_map {
33781 int (*root_size)(struct dm_space_map *sm, size_t *result);
33782 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33783 };
33784 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33785
33786 /*----------------------------------------------------------------*/
33787
33788 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33789 index 611b5f7..cee0bfb 100644
33790 --- a/drivers/md/raid1.c
33791 +++ b/drivers/md/raid1.c
33792 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33793 if (r1_sync_page_io(rdev, sect, s,
33794 bio->bi_io_vec[idx].bv_page,
33795 READ) != 0)
33796 - atomic_add(s, &rdev->corrected_errors);
33797 + atomic_add_unchecked(s, &rdev->corrected_errors);
33798 }
33799 sectors -= s;
33800 sect += s;
33801 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33802 test_bit(In_sync, &rdev->flags)) {
33803 if (r1_sync_page_io(rdev, sect, s,
33804 conf->tmppage, READ)) {
33805 - atomic_add(s, &rdev->corrected_errors);
33806 + atomic_add_unchecked(s, &rdev->corrected_errors);
33807 printk(KERN_INFO
33808 "md/raid1:%s: read error corrected "
33809 "(%d sectors at %llu on %s)\n",
33810 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33811 index a48c215..6bda6f4 100644
33812 --- a/drivers/md/raid10.c
33813 +++ b/drivers/md/raid10.c
33814 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33815 /* The write handler will notice the lack of
33816 * R10BIO_Uptodate and record any errors etc
33817 */
33818 - atomic_add(r10_bio->sectors,
33819 + atomic_add_unchecked(r10_bio->sectors,
33820 &conf->mirrors[d].rdev->corrected_errors);
33821
33822 /* for reconstruct, we always reschedule after a read.
33823 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33824 {
33825 struct timespec cur_time_mon;
33826 unsigned long hours_since_last;
33827 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33828 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33829
33830 ktime_get_ts(&cur_time_mon);
33831
33832 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33833 * overflowing the shift of read_errors by hours_since_last.
33834 */
33835 if (hours_since_last >= 8 * sizeof(read_errors))
33836 - atomic_set(&rdev->read_errors, 0);
33837 + atomic_set_unchecked(&rdev->read_errors, 0);
33838 else
33839 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33840 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33841 }
33842
33843 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33844 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33845 return;
33846
33847 check_decay_read_errors(mddev, rdev);
33848 - atomic_inc(&rdev->read_errors);
33849 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33850 + atomic_inc_unchecked(&rdev->read_errors);
33851 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33852 char b[BDEVNAME_SIZE];
33853 bdevname(rdev->bdev, b);
33854
33855 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33856 "md/raid10:%s: %s: Raid device exceeded "
33857 "read_error threshold [cur %d:max %d]\n",
33858 mdname(mddev), b,
33859 - atomic_read(&rdev->read_errors), max_read_errors);
33860 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33861 printk(KERN_NOTICE
33862 "md/raid10:%s: %s: Failing raid device\n",
33863 mdname(mddev), b);
33864 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33865 sect +
33866 choose_data_offset(r10_bio, rdev)),
33867 bdevname(rdev->bdev, b));
33868 - atomic_add(s, &rdev->corrected_errors);
33869 + atomic_add_unchecked(s, &rdev->corrected_errors);
33870 }
33871
33872 rdev_dec_pending(rdev, mddev);
33873 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33874 index 0689173..35df76c 100644
33875 --- a/drivers/md/raid5.c
33876 +++ b/drivers/md/raid5.c
33877 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33878 mdname(conf->mddev), STRIPE_SECTORS,
33879 (unsigned long long)s,
33880 bdevname(rdev->bdev, b));
33881 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33882 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33883 clear_bit(R5_ReadError, &sh->dev[i].flags);
33884 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33885 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33886 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33887
33888 - if (atomic_read(&rdev->read_errors))
33889 - atomic_set(&rdev->read_errors, 0);
33890 + if (atomic_read_unchecked(&rdev->read_errors))
33891 + atomic_set_unchecked(&rdev->read_errors, 0);
33892 } else {
33893 const char *bdn = bdevname(rdev->bdev, b);
33894 int retry = 0;
33895 int set_bad = 0;
33896
33897 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33898 - atomic_inc(&rdev->read_errors);
33899 + atomic_inc_unchecked(&rdev->read_errors);
33900 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33901 printk_ratelimited(
33902 KERN_WARNING
33903 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33904 mdname(conf->mddev),
33905 (unsigned long long)s,
33906 bdn);
33907 - } else if (atomic_read(&rdev->read_errors)
33908 + } else if (atomic_read_unchecked(&rdev->read_errors)
33909 > conf->max_nr_stripes)
33910 printk(KERN_WARNING
33911 "md/raid:%s: Too many read errors, failing device %s.\n",
33912 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33913 index ebf3f05..b1f3e77 100644
33914 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33915 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33916 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33917 .subvendor = _subvend, .subdevice = _subdev, \
33918 .driver_data = (unsigned long)&_driverdata }
33919
33920 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33921 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33922 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33923 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33924 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33925 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33926 index fa7188a..04a045e 100644
33927 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33928 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33929 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33930 union {
33931 dmx_ts_cb ts;
33932 dmx_section_cb sec;
33933 - } cb;
33934 + } __no_const cb;
33935
33936 struct dvb_demux *demux;
33937 void *priv;
33938 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33939 index 39eab73..60033e7 100644
33940 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33941 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33942 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33943 const struct dvb_device *template, void *priv, int type)
33944 {
33945 struct dvb_device *dvbdev;
33946 - struct file_operations *dvbdevfops;
33947 + file_operations_no_const *dvbdevfops;
33948 struct device *clsdev;
33949 int minor;
33950 int id;
33951 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33952 index 3940bb0..fb3952a 100644
33953 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33954 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33955 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33956
33957 struct dib0700_adapter_state {
33958 int (*set_param_save) (struct dvb_frontend *);
33959 -};
33960 +} __no_const;
33961
33962 static int dib7070_set_param_override(struct dvb_frontend *fe)
33963 {
33964 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33965 index 9382895..ac8093c 100644
33966 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33967 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33968 @@ -95,7 +95,7 @@ struct su3000_state {
33969
33970 struct s6x0_state {
33971 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33972 -};
33973 +} __no_const;
33974
33975 /* debug */
33976 static int dvb_usb_dw2102_debug;
33977 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33978 index 404f63a..4796533 100644
33979 --- a/drivers/media/dvb/frontends/dib3000.h
33980 +++ b/drivers/media/dvb/frontends/dib3000.h
33981 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33982 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33983 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33984 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33985 -};
33986 +} __no_const;
33987
33988 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33989 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33990 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33991 index 72ee8de..eae0c80 100644
33992 --- a/drivers/media/dvb/ngene/ngene-cards.c
33993 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33994 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
33995
33996 /****************************************************************************/
33997
33998 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33999 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34000 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34001 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34002 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34003 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34004 index 697a421..16c5a5f 100644
34005 --- a/drivers/media/radio/radio-cadet.c
34006 +++ b/drivers/media/radio/radio-cadet.c
34007 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34008 unsigned char readbuf[RDS_BUFFER];
34009 int i = 0;
34010
34011 + if (count > RDS_BUFFER)
34012 + return -EFAULT;
34013 mutex_lock(&dev->lock);
34014 if (dev->rdsstat == 0)
34015 cadet_start_rds(dev);
34016 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34017 while (i < count && dev->rdsin != dev->rdsout)
34018 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34019
34020 - if (i && copy_to_user(data, readbuf, i))
34021 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34022 i = -EFAULT;
34023 unlock:
34024 mutex_unlock(&dev->lock);
34025 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34026 index 55cbd78..428b0da 100644
34027 --- a/drivers/media/radio/radio-tea5777.h
34028 +++ b/drivers/media/radio/radio-tea5777.h
34029 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34030
34031 struct radio_tea5777 {
34032 struct v4l2_device *v4l2_dev;
34033 - struct v4l2_file_operations fops;
34034 + v4l2_file_operations_no_const fops;
34035 struct video_device vd; /* video device */
34036 bool has_am; /* Device can tune to AM freqs */
34037 bool write_before_read; /* must write before read quirk */
34038 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34039 index 9cde353..8c6a1c3 100644
34040 --- a/drivers/media/video/au0828/au0828.h
34041 +++ b/drivers/media/video/au0828/au0828.h
34042 @@ -191,7 +191,7 @@ struct au0828_dev {
34043
34044 /* I2C */
34045 struct i2c_adapter i2c_adap;
34046 - struct i2c_algorithm i2c_algo;
34047 + i2c_algorithm_no_const i2c_algo;
34048 struct i2c_client i2c_client;
34049 u32 i2c_rc;
34050
34051 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34052 index dfac6e3..c26de31 100644
34053 --- a/drivers/media/video/cx88/cx88-alsa.c
34054 +++ b/drivers/media/video/cx88/cx88-alsa.c
34055 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34056 * Only boards with eeprom and byte 1 at eeprom=1 have it
34057 */
34058
34059 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34060 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34061 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34062 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34063 {0, }
34064 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34065 index 88cf9d9..bbc4b2c 100644
34066 --- a/drivers/media/video/omap/omap_vout.c
34067 +++ b/drivers/media/video/omap/omap_vout.c
34068 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34069 OMAP_VIDEO2,
34070 };
34071
34072 -static struct videobuf_queue_ops video_vbq_ops;
34073 /* Variables configurable through module params*/
34074 static u32 video1_numbuffers = 3;
34075 static u32 video2_numbuffers = 3;
34076 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34077 {
34078 struct videobuf_queue *q;
34079 struct omap_vout_device *vout = NULL;
34080 + static struct videobuf_queue_ops video_vbq_ops = {
34081 + .buf_setup = omap_vout_buffer_setup,
34082 + .buf_prepare = omap_vout_buffer_prepare,
34083 + .buf_release = omap_vout_buffer_release,
34084 + .buf_queue = omap_vout_buffer_queue,
34085 + };
34086
34087 vout = video_drvdata(file);
34088 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34089 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34090 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34091
34092 q = &vout->vbq;
34093 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34094 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34095 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34096 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34097 spin_lock_init(&vout->vbq_lock);
34098
34099 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34100 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34101 index 036952f..80d356d 100644
34102 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34103 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34104 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34105
34106 /* I2C stuff */
34107 struct i2c_adapter i2c_adap;
34108 - struct i2c_algorithm i2c_algo;
34109 + i2c_algorithm_no_const i2c_algo;
34110 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34111 int i2c_cx25840_hack_state;
34112 int i2c_linked;
34113 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34114 index 02194c0..091733b 100644
34115 --- a/drivers/media/video/timblogiw.c
34116 +++ b/drivers/media/video/timblogiw.c
34117 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34118
34119 /* Platform device functions */
34120
34121 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34122 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34123 .vidioc_querycap = timblogiw_querycap,
34124 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34125 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34126 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34127 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34128 };
34129
34130 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34131 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34132 .owner = THIS_MODULE,
34133 .open = timblogiw_open,
34134 .release = timblogiw_close,
34135 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34136 index d99db56..a16b959 100644
34137 --- a/drivers/message/fusion/mptbase.c
34138 +++ b/drivers/message/fusion/mptbase.c
34139 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34140 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34141 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34142
34143 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34144 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34145 +#else
34146 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34147 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34148 +#endif
34149 +
34150 /*
34151 * Rounding UP to nearest 4-kB boundary here...
34152 */
34153 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34154 index 551262e..7551198 100644
34155 --- a/drivers/message/fusion/mptsas.c
34156 +++ b/drivers/message/fusion/mptsas.c
34157 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34158 return 0;
34159 }
34160
34161 +static inline void
34162 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34163 +{
34164 + if (phy_info->port_details) {
34165 + phy_info->port_details->rphy = rphy;
34166 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34167 + ioc->name, rphy));
34168 + }
34169 +
34170 + if (rphy) {
34171 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34172 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34173 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34174 + ioc->name, rphy, rphy->dev.release));
34175 + }
34176 +}
34177 +
34178 /* no mutex */
34179 static void
34180 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34181 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34182 return NULL;
34183 }
34184
34185 -static inline void
34186 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34187 -{
34188 - if (phy_info->port_details) {
34189 - phy_info->port_details->rphy = rphy;
34190 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34191 - ioc->name, rphy));
34192 - }
34193 -
34194 - if (rphy) {
34195 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34196 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34197 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34198 - ioc->name, rphy, rphy->dev.release));
34199 - }
34200 -}
34201 -
34202 static inline struct sas_port *
34203 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34204 {
34205 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34206 index 0c3ced7..1fe34ec 100644
34207 --- a/drivers/message/fusion/mptscsih.c
34208 +++ b/drivers/message/fusion/mptscsih.c
34209 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34210
34211 h = shost_priv(SChost);
34212
34213 - if (h) {
34214 - if (h->info_kbuf == NULL)
34215 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34216 - return h->info_kbuf;
34217 - h->info_kbuf[0] = '\0';
34218 + if (!h)
34219 + return NULL;
34220
34221 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34222 - h->info_kbuf[size-1] = '\0';
34223 - }
34224 + if (h->info_kbuf == NULL)
34225 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34226 + return h->info_kbuf;
34227 + h->info_kbuf[0] = '\0';
34228 +
34229 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34230 + h->info_kbuf[size-1] = '\0';
34231
34232 return h->info_kbuf;
34233 }
34234 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34235 index 8001aa6..b137580 100644
34236 --- a/drivers/message/i2o/i2o_proc.c
34237 +++ b/drivers/message/i2o/i2o_proc.c
34238 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34239 "Array Controller Device"
34240 };
34241
34242 -static char *chtostr(char *tmp, u8 *chars, int n)
34243 -{
34244 - tmp[0] = 0;
34245 - return strncat(tmp, (char *)chars, n);
34246 -}
34247 -
34248 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34249 char *group)
34250 {
34251 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34252 } *result;
34253
34254 i2o_exec_execute_ddm_table ddm_table;
34255 - char tmp[28 + 1];
34256
34257 result = kmalloc(sizeof(*result), GFP_KERNEL);
34258 if (!result)
34259 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34260
34261 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34262 seq_printf(seq, "%-#8x", ddm_table.module_id);
34263 - seq_printf(seq, "%-29s",
34264 - chtostr(tmp, ddm_table.module_name_version, 28));
34265 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34266 seq_printf(seq, "%9d ", ddm_table.data_size);
34267 seq_printf(seq, "%8d", ddm_table.code_size);
34268
34269 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34270
34271 i2o_driver_result_table *result;
34272 i2o_driver_store_table *dst;
34273 - char tmp[28 + 1];
34274
34275 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34276 if (result == NULL)
34277 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34278
34279 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34280 seq_printf(seq, "%-#8x", dst->module_id);
34281 - seq_printf(seq, "%-29s",
34282 - chtostr(tmp, dst->module_name_version, 28));
34283 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34284 + seq_printf(seq, "%-.28s", dst->module_name_version);
34285 + seq_printf(seq, "%-.8s", dst->date);
34286 seq_printf(seq, "%8d ", dst->module_size);
34287 seq_printf(seq, "%8d ", dst->mpb_size);
34288 seq_printf(seq, "0x%04x", dst->module_flags);
34289 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34290 // == (allow) 512d bytes (max)
34291 static u16 *work16 = (u16 *) work32;
34292 int token;
34293 - char tmp[16 + 1];
34294
34295 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34296
34297 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34298 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34299 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34300 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34301 - seq_printf(seq, "Vendor info : %s\n",
34302 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34303 - seq_printf(seq, "Product info : %s\n",
34304 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34305 - seq_printf(seq, "Description : %s\n",
34306 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34307 - seq_printf(seq, "Product rev. : %s\n",
34308 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34309 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34310 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34311 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34312 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34313
34314 seq_printf(seq, "Serial number : ");
34315 print_serial_number(seq, (u8 *) (work32 + 16),
34316 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34317 u8 pad[256]; // allow up to 256 byte (max) serial number
34318 } result;
34319
34320 - char tmp[24 + 1];
34321 -
34322 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34323
34324 if (token < 0) {
34325 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34326 }
34327
34328 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34329 - seq_printf(seq, "Module name : %s\n",
34330 - chtostr(tmp, result.module_name, 24));
34331 - seq_printf(seq, "Module revision : %s\n",
34332 - chtostr(tmp, result.module_rev, 8));
34333 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34334 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34335
34336 seq_printf(seq, "Serial number : ");
34337 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34338 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34339 u8 instance_number[4];
34340 } result;
34341
34342 - char tmp[64 + 1];
34343 -
34344 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34345
34346 if (token < 0) {
34347 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34348 return 0;
34349 }
34350
34351 - seq_printf(seq, "Device name : %s\n",
34352 - chtostr(tmp, result.device_name, 64));
34353 - seq_printf(seq, "Service name : %s\n",
34354 - chtostr(tmp, result.service_name, 64));
34355 - seq_printf(seq, "Physical name : %s\n",
34356 - chtostr(tmp, result.physical_location, 64));
34357 - seq_printf(seq, "Instance number : %s\n",
34358 - chtostr(tmp, result.instance_number, 4));
34359 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34360 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34361 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34362 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34363
34364 return 0;
34365 }
34366 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34367 index a8c08f3..155fe3d 100644
34368 --- a/drivers/message/i2o/iop.c
34369 +++ b/drivers/message/i2o/iop.c
34370 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34371
34372 spin_lock_irqsave(&c->context_list_lock, flags);
34373
34374 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34375 - atomic_inc(&c->context_list_counter);
34376 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34377 + atomic_inc_unchecked(&c->context_list_counter);
34378
34379 - entry->context = atomic_read(&c->context_list_counter);
34380 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34381
34382 list_add(&entry->list, &c->context_list);
34383
34384 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34385
34386 #if BITS_PER_LONG == 64
34387 spin_lock_init(&c->context_list_lock);
34388 - atomic_set(&c->context_list_counter, 0);
34389 + atomic_set_unchecked(&c->context_list_counter, 0);
34390 INIT_LIST_HEAD(&c->context_list);
34391 #endif
34392
34393 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34394 index 7ce65f4..e66e9bc 100644
34395 --- a/drivers/mfd/abx500-core.c
34396 +++ b/drivers/mfd/abx500-core.c
34397 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34398
34399 struct abx500_device_entry {
34400 struct list_head list;
34401 - struct abx500_ops ops;
34402 + abx500_ops_no_const ops;
34403 struct device *dev;
34404 };
34405
34406 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34407 index 965c480..71f2db9 100644
34408 --- a/drivers/mfd/janz-cmodio.c
34409 +++ b/drivers/mfd/janz-cmodio.c
34410 @@ -13,6 +13,7 @@
34411
34412 #include <linux/kernel.h>
34413 #include <linux/module.h>
34414 +#include <linux/slab.h>
34415 #include <linux/init.h>
34416 #include <linux/pci.h>
34417 #include <linux/interrupt.h>
34418 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34419 index a981e2a..5ca0c8b 100644
34420 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34421 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34422 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34423 * the lid is closed. This leads to interrupts as soon as a little move
34424 * is done.
34425 */
34426 - atomic_inc(&lis3->count);
34427 + atomic_inc_unchecked(&lis3->count);
34428
34429 wake_up_interruptible(&lis3->misc_wait);
34430 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34431 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34432 if (lis3->pm_dev)
34433 pm_runtime_get_sync(lis3->pm_dev);
34434
34435 - atomic_set(&lis3->count, 0);
34436 + atomic_set_unchecked(&lis3->count, 0);
34437 return 0;
34438 }
34439
34440 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34441 add_wait_queue(&lis3->misc_wait, &wait);
34442 while (true) {
34443 set_current_state(TASK_INTERRUPTIBLE);
34444 - data = atomic_xchg(&lis3->count, 0);
34445 + data = atomic_xchg_unchecked(&lis3->count, 0);
34446 if (data)
34447 break;
34448
34449 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34450 struct lis3lv02d, miscdev);
34451
34452 poll_wait(file, &lis3->misc_wait, wait);
34453 - if (atomic_read(&lis3->count))
34454 + if (atomic_read_unchecked(&lis3->count))
34455 return POLLIN | POLLRDNORM;
34456 return 0;
34457 }
34458 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34459 index 2b1482a..5d33616 100644
34460 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34461 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34462 @@ -266,7 +266,7 @@ struct lis3lv02d {
34463 struct input_polled_dev *idev; /* input device */
34464 struct platform_device *pdev; /* platform device */
34465 struct regulator_bulk_data regulators[2];
34466 - atomic_t count; /* interrupt count after last read */
34467 + atomic_unchecked_t count; /* interrupt count after last read */
34468 union axis_conversion ac; /* hw -> logical axis */
34469 int mapped_btns[3];
34470
34471 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34472 index 2f30bad..c4c13d0 100644
34473 --- a/drivers/misc/sgi-gru/gruhandles.c
34474 +++ b/drivers/misc/sgi-gru/gruhandles.c
34475 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34476 unsigned long nsec;
34477
34478 nsec = CLKS2NSEC(clks);
34479 - atomic_long_inc(&mcs_op_statistics[op].count);
34480 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34481 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34482 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34483 if (mcs_op_statistics[op].max < nsec)
34484 mcs_op_statistics[op].max = nsec;
34485 }
34486 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34487 index 950dbe9..eeef0f8 100644
34488 --- a/drivers/misc/sgi-gru/gruprocfs.c
34489 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34490 @@ -32,9 +32,9 @@
34491
34492 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34493
34494 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34495 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34496 {
34497 - unsigned long val = atomic_long_read(v);
34498 + unsigned long val = atomic_long_read_unchecked(v);
34499
34500 seq_printf(s, "%16lu %s\n", val, id);
34501 }
34502 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34503
34504 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34505 for (op = 0; op < mcsop_last; op++) {
34506 - count = atomic_long_read(&mcs_op_statistics[op].count);
34507 - total = atomic_long_read(&mcs_op_statistics[op].total);
34508 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34509 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34510 max = mcs_op_statistics[op].max;
34511 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34512 count ? total / count : 0, max);
34513 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34514 index 5c3ce24..4915ccb 100644
34515 --- a/drivers/misc/sgi-gru/grutables.h
34516 +++ b/drivers/misc/sgi-gru/grutables.h
34517 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34518 * GRU statistics.
34519 */
34520 struct gru_stats_s {
34521 - atomic_long_t vdata_alloc;
34522 - atomic_long_t vdata_free;
34523 - atomic_long_t gts_alloc;
34524 - atomic_long_t gts_free;
34525 - atomic_long_t gms_alloc;
34526 - atomic_long_t gms_free;
34527 - atomic_long_t gts_double_allocate;
34528 - atomic_long_t assign_context;
34529 - atomic_long_t assign_context_failed;
34530 - atomic_long_t free_context;
34531 - atomic_long_t load_user_context;
34532 - atomic_long_t load_kernel_context;
34533 - atomic_long_t lock_kernel_context;
34534 - atomic_long_t unlock_kernel_context;
34535 - atomic_long_t steal_user_context;
34536 - atomic_long_t steal_kernel_context;
34537 - atomic_long_t steal_context_failed;
34538 - atomic_long_t nopfn;
34539 - atomic_long_t asid_new;
34540 - atomic_long_t asid_next;
34541 - atomic_long_t asid_wrap;
34542 - atomic_long_t asid_reuse;
34543 - atomic_long_t intr;
34544 - atomic_long_t intr_cbr;
34545 - atomic_long_t intr_tfh;
34546 - atomic_long_t intr_spurious;
34547 - atomic_long_t intr_mm_lock_failed;
34548 - atomic_long_t call_os;
34549 - atomic_long_t call_os_wait_queue;
34550 - atomic_long_t user_flush_tlb;
34551 - atomic_long_t user_unload_context;
34552 - atomic_long_t user_exception;
34553 - atomic_long_t set_context_option;
34554 - atomic_long_t check_context_retarget_intr;
34555 - atomic_long_t check_context_unload;
34556 - atomic_long_t tlb_dropin;
34557 - atomic_long_t tlb_preload_page;
34558 - atomic_long_t tlb_dropin_fail_no_asid;
34559 - atomic_long_t tlb_dropin_fail_upm;
34560 - atomic_long_t tlb_dropin_fail_invalid;
34561 - atomic_long_t tlb_dropin_fail_range_active;
34562 - atomic_long_t tlb_dropin_fail_idle;
34563 - atomic_long_t tlb_dropin_fail_fmm;
34564 - atomic_long_t tlb_dropin_fail_no_exception;
34565 - atomic_long_t tfh_stale_on_fault;
34566 - atomic_long_t mmu_invalidate_range;
34567 - atomic_long_t mmu_invalidate_page;
34568 - atomic_long_t flush_tlb;
34569 - atomic_long_t flush_tlb_gru;
34570 - atomic_long_t flush_tlb_gru_tgh;
34571 - atomic_long_t flush_tlb_gru_zero_asid;
34572 + atomic_long_unchecked_t vdata_alloc;
34573 + atomic_long_unchecked_t vdata_free;
34574 + atomic_long_unchecked_t gts_alloc;
34575 + atomic_long_unchecked_t gts_free;
34576 + atomic_long_unchecked_t gms_alloc;
34577 + atomic_long_unchecked_t gms_free;
34578 + atomic_long_unchecked_t gts_double_allocate;
34579 + atomic_long_unchecked_t assign_context;
34580 + atomic_long_unchecked_t assign_context_failed;
34581 + atomic_long_unchecked_t free_context;
34582 + atomic_long_unchecked_t load_user_context;
34583 + atomic_long_unchecked_t load_kernel_context;
34584 + atomic_long_unchecked_t lock_kernel_context;
34585 + atomic_long_unchecked_t unlock_kernel_context;
34586 + atomic_long_unchecked_t steal_user_context;
34587 + atomic_long_unchecked_t steal_kernel_context;
34588 + atomic_long_unchecked_t steal_context_failed;
34589 + atomic_long_unchecked_t nopfn;
34590 + atomic_long_unchecked_t asid_new;
34591 + atomic_long_unchecked_t asid_next;
34592 + atomic_long_unchecked_t asid_wrap;
34593 + atomic_long_unchecked_t asid_reuse;
34594 + atomic_long_unchecked_t intr;
34595 + atomic_long_unchecked_t intr_cbr;
34596 + atomic_long_unchecked_t intr_tfh;
34597 + atomic_long_unchecked_t intr_spurious;
34598 + atomic_long_unchecked_t intr_mm_lock_failed;
34599 + atomic_long_unchecked_t call_os;
34600 + atomic_long_unchecked_t call_os_wait_queue;
34601 + atomic_long_unchecked_t user_flush_tlb;
34602 + atomic_long_unchecked_t user_unload_context;
34603 + atomic_long_unchecked_t user_exception;
34604 + atomic_long_unchecked_t set_context_option;
34605 + atomic_long_unchecked_t check_context_retarget_intr;
34606 + atomic_long_unchecked_t check_context_unload;
34607 + atomic_long_unchecked_t tlb_dropin;
34608 + atomic_long_unchecked_t tlb_preload_page;
34609 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34610 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34611 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34612 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34613 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34614 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34615 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34616 + atomic_long_unchecked_t tfh_stale_on_fault;
34617 + atomic_long_unchecked_t mmu_invalidate_range;
34618 + atomic_long_unchecked_t mmu_invalidate_page;
34619 + atomic_long_unchecked_t flush_tlb;
34620 + atomic_long_unchecked_t flush_tlb_gru;
34621 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34622 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34623
34624 - atomic_long_t copy_gpa;
34625 - atomic_long_t read_gpa;
34626 + atomic_long_unchecked_t copy_gpa;
34627 + atomic_long_unchecked_t read_gpa;
34628
34629 - atomic_long_t mesq_receive;
34630 - atomic_long_t mesq_receive_none;
34631 - atomic_long_t mesq_send;
34632 - atomic_long_t mesq_send_failed;
34633 - atomic_long_t mesq_noop;
34634 - atomic_long_t mesq_send_unexpected_error;
34635 - atomic_long_t mesq_send_lb_overflow;
34636 - atomic_long_t mesq_send_qlimit_reached;
34637 - atomic_long_t mesq_send_amo_nacked;
34638 - atomic_long_t mesq_send_put_nacked;
34639 - atomic_long_t mesq_page_overflow;
34640 - atomic_long_t mesq_qf_locked;
34641 - atomic_long_t mesq_qf_noop_not_full;
34642 - atomic_long_t mesq_qf_switch_head_failed;
34643 - atomic_long_t mesq_qf_unexpected_error;
34644 - atomic_long_t mesq_noop_unexpected_error;
34645 - atomic_long_t mesq_noop_lb_overflow;
34646 - atomic_long_t mesq_noop_qlimit_reached;
34647 - atomic_long_t mesq_noop_amo_nacked;
34648 - atomic_long_t mesq_noop_put_nacked;
34649 - atomic_long_t mesq_noop_page_overflow;
34650 + atomic_long_unchecked_t mesq_receive;
34651 + atomic_long_unchecked_t mesq_receive_none;
34652 + atomic_long_unchecked_t mesq_send;
34653 + atomic_long_unchecked_t mesq_send_failed;
34654 + atomic_long_unchecked_t mesq_noop;
34655 + atomic_long_unchecked_t mesq_send_unexpected_error;
34656 + atomic_long_unchecked_t mesq_send_lb_overflow;
34657 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34658 + atomic_long_unchecked_t mesq_send_amo_nacked;
34659 + atomic_long_unchecked_t mesq_send_put_nacked;
34660 + atomic_long_unchecked_t mesq_page_overflow;
34661 + atomic_long_unchecked_t mesq_qf_locked;
34662 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34663 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34664 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34665 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34666 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34667 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34668 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34669 + atomic_long_unchecked_t mesq_noop_put_nacked;
34670 + atomic_long_unchecked_t mesq_noop_page_overflow;
34671
34672 };
34673
34674 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34675 tghop_invalidate, mcsop_last};
34676
34677 struct mcs_op_statistic {
34678 - atomic_long_t count;
34679 - atomic_long_t total;
34680 + atomic_long_unchecked_t count;
34681 + atomic_long_unchecked_t total;
34682 unsigned long max;
34683 };
34684
34685 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34686
34687 #define STAT(id) do { \
34688 if (gru_options & OPT_STATS) \
34689 - atomic_long_inc(&gru_stats.id); \
34690 + atomic_long_inc_unchecked(&gru_stats.id); \
34691 } while (0)
34692
34693 #ifdef CONFIG_SGI_GRU_DEBUG
34694 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34695 index c862cd4..0d176fe 100644
34696 --- a/drivers/misc/sgi-xp/xp.h
34697 +++ b/drivers/misc/sgi-xp/xp.h
34698 @@ -288,7 +288,7 @@ struct xpc_interface {
34699 xpc_notify_func, void *);
34700 void (*received) (short, int, void *);
34701 enum xp_retval (*partid_to_nasids) (short, void *);
34702 -};
34703 +} __no_const;
34704
34705 extern struct xpc_interface xpc_interface;
34706
34707 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34708 index b94d5f7..7f494c5 100644
34709 --- a/drivers/misc/sgi-xp/xpc.h
34710 +++ b/drivers/misc/sgi-xp/xpc.h
34711 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34712 void (*received_payload) (struct xpc_channel *, void *);
34713 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34714 };
34715 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34716
34717 /* struct xpc_partition act_state values (for XPC HB) */
34718
34719 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34720 /* found in xpc_main.c */
34721 extern struct device *xpc_part;
34722 extern struct device *xpc_chan;
34723 -extern struct xpc_arch_operations xpc_arch_ops;
34724 +extern xpc_arch_operations_no_const xpc_arch_ops;
34725 extern int xpc_disengage_timelimit;
34726 extern int xpc_disengage_timedout;
34727 extern int xpc_activate_IRQ_rcvd;
34728 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34729 index 8d082b4..aa749ae 100644
34730 --- a/drivers/misc/sgi-xp/xpc_main.c
34731 +++ b/drivers/misc/sgi-xp/xpc_main.c
34732 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34733 .notifier_call = xpc_system_die,
34734 };
34735
34736 -struct xpc_arch_operations xpc_arch_ops;
34737 +xpc_arch_operations_no_const xpc_arch_ops;
34738
34739 /*
34740 * Timer function to enforce the timelimit on the partition disengage.
34741 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34742 index 504da71..9722d43 100644
34743 --- a/drivers/mmc/host/sdhci-pci.c
34744 +++ b/drivers/mmc/host/sdhci-pci.c
34745 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34746 .probe = via_probe,
34747 };
34748
34749 -static const struct pci_device_id pci_ids[] __devinitdata = {
34750 +static const struct pci_device_id pci_ids[] __devinitconst = {
34751 {
34752 .vendor = PCI_VENDOR_ID_RICOH,
34753 .device = PCI_DEVICE_ID_RICOH_R5C822,
34754 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34755 index a4eb8b5..8c0628f 100644
34756 --- a/drivers/mtd/devices/doc2000.c
34757 +++ b/drivers/mtd/devices/doc2000.c
34758 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34759
34760 /* The ECC will not be calculated correctly if less than 512 is written */
34761 /* DBB-
34762 - if (len != 0x200 && eccbuf)
34763 + if (len != 0x200)
34764 printk(KERN_WARNING
34765 "ECC needs a full sector write (adr: %lx size %lx)\n",
34766 (long) to, (long) len);
34767 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34768 index 0650aaf..7718762 100644
34769 --- a/drivers/mtd/nand/denali.c
34770 +++ b/drivers/mtd/nand/denali.c
34771 @@ -26,6 +26,7 @@
34772 #include <linux/pci.h>
34773 #include <linux/mtd/mtd.h>
34774 #include <linux/module.h>
34775 +#include <linux/slab.h>
34776
34777 #include "denali.h"
34778
34779 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34780 index 51b9d6a..52af9a7 100644
34781 --- a/drivers/mtd/nftlmount.c
34782 +++ b/drivers/mtd/nftlmount.c
34783 @@ -24,6 +24,7 @@
34784 #include <asm/errno.h>
34785 #include <linux/delay.h>
34786 #include <linux/slab.h>
34787 +#include <linux/sched.h>
34788 #include <linux/mtd/mtd.h>
34789 #include <linux/mtd/nand.h>
34790 #include <linux/mtd/nftl.h>
34791 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34792 index 57d64b8..623dd86 100644
34793 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34794 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34795 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34796 */
34797
34798 #define ATL2_PARAM(X, desc) \
34799 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34800 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34801 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34802 MODULE_PARM_DESC(X, desc);
34803 #else
34804 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34805 index f83e033..8b4f43a 100644
34806 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34807 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34808 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34809
34810 int (*wait_comp)(struct bnx2x *bp,
34811 struct bnx2x_rx_mode_ramrod_params *p);
34812 -};
34813 +} __no_const;
34814
34815 /********************** Set multicast group ***********************************/
34816
34817 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34818 index 6d52cb2..bc95640 100644
34819 --- a/drivers/net/ethernet/broadcom/tg3.h
34820 +++ b/drivers/net/ethernet/broadcom/tg3.h
34821 @@ -140,6 +140,7 @@
34822 #define CHIPREV_ID_5750_A0 0x4000
34823 #define CHIPREV_ID_5750_A1 0x4001
34824 #define CHIPREV_ID_5750_A3 0x4003
34825 +#define CHIPREV_ID_5750_C1 0x4201
34826 #define CHIPREV_ID_5750_C2 0x4202
34827 #define CHIPREV_ID_5752_A0_HW 0x5000
34828 #define CHIPREV_ID_5752_A0 0x6000
34829 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34830 index 8cffcdf..aadf043 100644
34831 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34832 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34833 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34834 */
34835 struct l2t_skb_cb {
34836 arp_failure_handler_func arp_failure_handler;
34837 -};
34838 +} __no_const;
34839
34840 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34841
34842 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34843 index f879e92..726f20f 100644
34844 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34845 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34846 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34847 for (i=0; i<ETH_ALEN; i++) {
34848 tmp.addr[i] = dev->dev_addr[i];
34849 }
34850 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34851 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34852 break;
34853
34854 case DE4X5_SET_HWADDR: /* Set the hardware address */
34855 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34856 spin_lock_irqsave(&lp->lock, flags);
34857 memcpy(&statbuf, &lp->pktStats, ioc->len);
34858 spin_unlock_irqrestore(&lp->lock, flags);
34859 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34860 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34861 return -EFAULT;
34862 break;
34863 }
34864 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34865 index ed7d1dc..d426748 100644
34866 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34867 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34868 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34869 {NULL}};
34870
34871
34872 -static const char *block_name[] __devinitdata = {
34873 +static const char *block_name[] __devinitconst = {
34874 "21140 non-MII",
34875 "21140 MII PHY",
34876 "21142 Serial PHY",
34877 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34878 index 75d45f8..3d9c55b 100644
34879 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34880 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34881 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34882 struct uli_phy_ops {
34883 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34884 u16 (*read)(struct uli526x_board_info *, u8, u8);
34885 - } phy;
34886 + } __no_const phy;
34887 struct net_device *next_dev; /* next device */
34888 struct pci_dev *pdev; /* PCI device */
34889 spinlock_t lock;
34890 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34891 index 4d1ffca..7c1ec4d 100644
34892 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34893 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34894 @@ -236,7 +236,7 @@ struct pci_id_info {
34895 int drv_flags; /* Driver use, intended as capability flags. */
34896 };
34897
34898 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34899 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34900 { /* Sometime a Level-One switch card. */
34901 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34902 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34903 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34904 index d7bb52a..3b83588 100644
34905 --- a/drivers/net/ethernet/dlink/sundance.c
34906 +++ b/drivers/net/ethernet/dlink/sundance.c
34907 @@ -218,7 +218,7 @@ enum {
34908 struct pci_id_info {
34909 const char *name;
34910 };
34911 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34912 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34913 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34914 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34915 {"D-Link DFE-580TX 4 port Server Adapter"},
34916 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34917 index 78b8aa8..dd6323a 100644
34918 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34919 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34920 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34921
34922 if (wrapped)
34923 newacc += 65536;
34924 - ACCESS_ONCE(*acc) = newacc;
34925 + ACCESS_ONCE_RW(*acc) = newacc;
34926 }
34927
34928 void be_parse_stats(struct be_adapter *adapter)
34929 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34930 index 74d749e..eefb1bd 100644
34931 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34932 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34933 @@ -31,6 +31,8 @@
34934 #include <linux/netdevice.h>
34935 #include <linux/phy.h>
34936 #include <linux/platform_device.h>
34937 +#include <linux/interrupt.h>
34938 +#include <linux/irqreturn.h>
34939 #include <net/ip.h>
34940
34941 #include "ftgmac100.h"
34942 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34943 index b901a01..1ff32ee 100644
34944 --- a/drivers/net/ethernet/faraday/ftmac100.c
34945 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34946 @@ -31,6 +31,8 @@
34947 #include <linux/module.h>
34948 #include <linux/netdevice.h>
34949 #include <linux/platform_device.h>
34950 +#include <linux/interrupt.h>
34951 +#include <linux/irqreturn.h>
34952
34953 #include "ftmac100.h"
34954
34955 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34956 index 9d71c9c..0e4a0ac 100644
34957 --- a/drivers/net/ethernet/fealnx.c
34958 +++ b/drivers/net/ethernet/fealnx.c
34959 @@ -150,7 +150,7 @@ struct chip_info {
34960 int flags;
34961 };
34962
34963 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34964 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34965 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34966 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34967 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34968 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34969 index ed5b409..ec37828 100644
34970 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34971 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34972 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34973 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34974 s32 (*read_mac_addr)(struct e1000_hw *);
34975 };
34976 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34977
34978 /*
34979 * When to use various PHY register access functions:
34980 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34981 void (*power_up)(struct e1000_hw *);
34982 void (*power_down)(struct e1000_hw *);
34983 };
34984 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34985
34986 /* Function pointers for the NVM. */
34987 struct e1000_nvm_operations {
34988 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34989 s32 (*validate)(struct e1000_hw *);
34990 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34991 };
34992 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34993
34994 struct e1000_mac_info {
34995 - struct e1000_mac_operations ops;
34996 + e1000_mac_operations_no_const ops;
34997 u8 addr[ETH_ALEN];
34998 u8 perm_addr[ETH_ALEN];
34999
35000 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35001 };
35002
35003 struct e1000_phy_info {
35004 - struct e1000_phy_operations ops;
35005 + e1000_phy_operations_no_const ops;
35006
35007 enum e1000_phy_type type;
35008
35009 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35010 };
35011
35012 struct e1000_nvm_info {
35013 - struct e1000_nvm_operations ops;
35014 + e1000_nvm_operations_no_const ops;
35015
35016 enum e1000_nvm_type type;
35017 enum e1000_nvm_override override;
35018 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35019 index c2a51dc..c2bd262 100644
35020 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35021 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35022 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35023 void (*release_swfw_sync)(struct e1000_hw *, u16);
35024
35025 };
35026 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35027
35028 struct e1000_phy_operations {
35029 s32 (*acquire)(struct e1000_hw *);
35030 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35031 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35032 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35033 };
35034 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35035
35036 struct e1000_nvm_operations {
35037 s32 (*acquire)(struct e1000_hw *);
35038 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35039 s32 (*validate)(struct e1000_hw *);
35040 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35041 };
35042 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35043
35044 struct e1000_info {
35045 s32 (*get_invariants)(struct e1000_hw *);
35046 @@ -364,7 +367,7 @@ struct e1000_info {
35047 extern const struct e1000_info e1000_82575_info;
35048
35049 struct e1000_mac_info {
35050 - struct e1000_mac_operations ops;
35051 + e1000_mac_operations_no_const ops;
35052
35053 u8 addr[6];
35054 u8 perm_addr[6];
35055 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35056 };
35057
35058 struct e1000_phy_info {
35059 - struct e1000_phy_operations ops;
35060 + e1000_phy_operations_no_const ops;
35061
35062 enum e1000_phy_type type;
35063
35064 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35065 };
35066
35067 struct e1000_nvm_info {
35068 - struct e1000_nvm_operations ops;
35069 + e1000_nvm_operations_no_const ops;
35070 enum e1000_nvm_type type;
35071 enum e1000_nvm_override override;
35072
35073 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35074 s32 (*check_for_ack)(struct e1000_hw *, u16);
35075 s32 (*check_for_rst)(struct e1000_hw *, u16);
35076 };
35077 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35078
35079 struct e1000_mbx_stats {
35080 u32 msgs_tx;
35081 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35082 };
35083
35084 struct e1000_mbx_info {
35085 - struct e1000_mbx_operations ops;
35086 + e1000_mbx_operations_no_const ops;
35087 struct e1000_mbx_stats stats;
35088 u32 timeout;
35089 u32 usec_delay;
35090 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35091 index 57db3c6..aa825fc 100644
35092 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35093 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35094 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35095 s32 (*read_mac_addr)(struct e1000_hw *);
35096 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35097 };
35098 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35099
35100 struct e1000_mac_info {
35101 - struct e1000_mac_operations ops;
35102 + e1000_mac_operations_no_const ops;
35103 u8 addr[6];
35104 u8 perm_addr[6];
35105
35106 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35107 s32 (*check_for_ack)(struct e1000_hw *);
35108 s32 (*check_for_rst)(struct e1000_hw *);
35109 };
35110 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35111
35112 struct e1000_mbx_stats {
35113 u32 msgs_tx;
35114 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35115 };
35116
35117 struct e1000_mbx_info {
35118 - struct e1000_mbx_operations ops;
35119 + e1000_mbx_operations_no_const ops;
35120 struct e1000_mbx_stats stats;
35121 u32 timeout;
35122 u32 usec_delay;
35123 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35124 index 3456d56..b688d81 100644
35125 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35126 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35127 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35128 /* store the new cycle speed */
35129 adapter->cycle_speed = cycle_speed;
35130
35131 - ACCESS_ONCE(adapter->base_incval) = incval;
35132 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35133 smp_mb();
35134
35135 /* grab the ptp lock */
35136 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35137 index 400f86a..7f2e062 100644
35138 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35139 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35140 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35141 s32 (*update_checksum)(struct ixgbe_hw *);
35142 u16 (*calc_checksum)(struct ixgbe_hw *);
35143 };
35144 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35145
35146 struct ixgbe_mac_operations {
35147 s32 (*init_hw)(struct ixgbe_hw *);
35148 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35149 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35150 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35151 };
35152 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35153
35154 struct ixgbe_phy_operations {
35155 s32 (*identify)(struct ixgbe_hw *);
35156 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35157 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35158 s32 (*check_overtemp)(struct ixgbe_hw *);
35159 };
35160 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35161
35162 struct ixgbe_eeprom_info {
35163 - struct ixgbe_eeprom_operations ops;
35164 + ixgbe_eeprom_operations_no_const ops;
35165 enum ixgbe_eeprom_type type;
35166 u32 semaphore_delay;
35167 u16 word_size;
35168 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35169
35170 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35171 struct ixgbe_mac_info {
35172 - struct ixgbe_mac_operations ops;
35173 + ixgbe_mac_operations_no_const ops;
35174 enum ixgbe_mac_type type;
35175 u8 addr[ETH_ALEN];
35176 u8 perm_addr[ETH_ALEN];
35177 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35178 };
35179
35180 struct ixgbe_phy_info {
35181 - struct ixgbe_phy_operations ops;
35182 + ixgbe_phy_operations_no_const ops;
35183 struct mdio_if_info mdio;
35184 enum ixgbe_phy_type type;
35185 u32 id;
35186 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35187 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35188 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35189 };
35190 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35191
35192 struct ixgbe_mbx_stats {
35193 u32 msgs_tx;
35194 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35195 };
35196
35197 struct ixgbe_mbx_info {
35198 - struct ixgbe_mbx_operations ops;
35199 + ixgbe_mbx_operations_no_const ops;
35200 struct ixgbe_mbx_stats stats;
35201 u32 timeout;
35202 u32 usec_delay;
35203 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35204 index 25c951d..cc7cf33 100644
35205 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35206 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35207 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35208 s32 (*clear_vfta)(struct ixgbe_hw *);
35209 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35210 };
35211 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35212
35213 enum ixgbe_mac_type {
35214 ixgbe_mac_unknown = 0,
35215 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35216 };
35217
35218 struct ixgbe_mac_info {
35219 - struct ixgbe_mac_operations ops;
35220 + ixgbe_mac_operations_no_const ops;
35221 u8 addr[6];
35222 u8 perm_addr[6];
35223
35224 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35225 s32 (*check_for_ack)(struct ixgbe_hw *);
35226 s32 (*check_for_rst)(struct ixgbe_hw *);
35227 };
35228 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35229
35230 struct ixgbe_mbx_stats {
35231 u32 msgs_tx;
35232 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35233 };
35234
35235 struct ixgbe_mbx_info {
35236 - struct ixgbe_mbx_operations ops;
35237 + ixgbe_mbx_operations_no_const ops;
35238 struct ixgbe_mbx_stats stats;
35239 u32 timeout;
35240 u32 udelay;
35241 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35242 index 9e0c1ee..8471f77 100644
35243 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35244 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35245 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35246 void (*link_down)(struct __vxge_hw_device *devh);
35247 void (*crit_err)(struct __vxge_hw_device *devh,
35248 enum vxge_hw_event type, u64 ext_data);
35249 -};
35250 +} __no_const;
35251
35252 /*
35253 * struct __vxge_hw_blockpool_entry - Block private data structure
35254 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35255 index 4a518a3..936b334 100644
35256 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35257 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35258 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35259 struct vxge_hw_mempool_dma *dma_object,
35260 u32 index,
35261 u32 is_last);
35262 -};
35263 +} __no_const;
35264
35265 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35266 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35267 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35268 index b47d5b3..273a516 100644
35269 --- a/drivers/net/ethernet/realtek/r8169.c
35270 +++ b/drivers/net/ethernet/realtek/r8169.c
35271 @@ -745,22 +745,22 @@ struct rtl8169_private {
35272 struct mdio_ops {
35273 void (*write)(struct rtl8169_private *, int, int);
35274 int (*read)(struct rtl8169_private *, int);
35275 - } mdio_ops;
35276 + } __no_const mdio_ops;
35277
35278 struct pll_power_ops {
35279 void (*down)(struct rtl8169_private *);
35280 void (*up)(struct rtl8169_private *);
35281 - } pll_power_ops;
35282 + } __no_const pll_power_ops;
35283
35284 struct jumbo_ops {
35285 void (*enable)(struct rtl8169_private *);
35286 void (*disable)(struct rtl8169_private *);
35287 - } jumbo_ops;
35288 + } __no_const jumbo_ops;
35289
35290 struct csi_ops {
35291 void (*write)(struct rtl8169_private *, int, int);
35292 u32 (*read)(struct rtl8169_private *, int);
35293 - } csi_ops;
35294 + } __no_const csi_ops;
35295
35296 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35297 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35298 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35299 index 4613591..d816601 100644
35300 --- a/drivers/net/ethernet/sis/sis190.c
35301 +++ b/drivers/net/ethernet/sis/sis190.c
35302 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35303 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35304 struct net_device *dev)
35305 {
35306 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35307 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35308 struct sis190_private *tp = netdev_priv(dev);
35309 struct pci_dev *isa_bridge;
35310 u8 reg, tmp8;
35311 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35312 index 0c74a70..3bc6f68 100644
35313 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35314 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35315 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35316
35317 writel(value, ioaddr + MMC_CNTRL);
35318
35319 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35320 - MMC_CNTRL, value);
35321 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35322 +// MMC_CNTRL, value);
35323 }
35324
35325 /* To mask all all interrupts.*/
35326 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35327 index 95ceb35..318fc12 100644
35328 --- a/drivers/net/hyperv/hyperv_net.h
35329 +++ b/drivers/net/hyperv/hyperv_net.h
35330 @@ -99,7 +99,7 @@ struct rndis_device {
35331
35332 enum rndis_device_state state;
35333 bool link_state;
35334 - atomic_t new_req_id;
35335 + atomic_unchecked_t new_req_id;
35336
35337 spinlock_t request_lock;
35338 struct list_head req_list;
35339 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35340 index 1e88a10..1b01736 100644
35341 --- a/drivers/net/hyperv/rndis_filter.c
35342 +++ b/drivers/net/hyperv/rndis_filter.c
35343 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35344 * template
35345 */
35346 set = &rndis_msg->msg.set_req;
35347 - set->req_id = atomic_inc_return(&dev->new_req_id);
35348 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35349
35350 /* Add to the request list */
35351 spin_lock_irqsave(&dev->request_lock, flags);
35352 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35353
35354 /* Setup the rndis set */
35355 halt = &request->request_msg.msg.halt_req;
35356 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35357 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35358
35359 /* Ignore return since this msg is optional. */
35360 rndis_filter_send_request(dev, request);
35361 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35362 index 5c05572..389610b 100644
35363 --- a/drivers/net/ppp/ppp_generic.c
35364 +++ b/drivers/net/ppp/ppp_generic.c
35365 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35366 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35367 struct ppp_stats stats;
35368 struct ppp_comp_stats cstats;
35369 - char *vers;
35370
35371 switch (cmd) {
35372 case SIOCGPPPSTATS:
35373 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35374 break;
35375
35376 case SIOCGPPPVER:
35377 - vers = PPP_VERSION;
35378 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35379 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35380 break;
35381 err = 0;
35382 break;
35383 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35384 index 3a16d4f..a311cec 100644
35385 --- a/drivers/net/tun.c
35386 +++ b/drivers/net/tun.c
35387 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35388 }
35389
35390 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35391 - unsigned long arg, int ifreq_len)
35392 + unsigned long arg, size_t ifreq_len)
35393 {
35394 struct tun_file *tfile = file->private_data;
35395 struct tun_struct *tun;
35396 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35397 int vnet_hdr_sz;
35398 int ret;
35399
35400 + if (ifreq_len > sizeof ifr)
35401 + return -EFAULT;
35402 +
35403 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35404 if (copy_from_user(&ifr, argp, ifreq_len))
35405 return -EFAULT;
35406 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35407 index 62f30b4..ff99dfd 100644
35408 --- a/drivers/net/usb/hso.c
35409 +++ b/drivers/net/usb/hso.c
35410 @@ -71,7 +71,7 @@
35411 #include <asm/byteorder.h>
35412 #include <linux/serial_core.h>
35413 #include <linux/serial.h>
35414 -
35415 +#include <asm/local.h>
35416
35417 #define MOD_AUTHOR "Option Wireless"
35418 #define MOD_DESCRIPTION "USB High Speed Option driver"
35419 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35420 struct urb *urb;
35421
35422 urb = serial->rx_urb[0];
35423 - if (serial->port.count > 0) {
35424 + if (atomic_read(&serial->port.count) > 0) {
35425 count = put_rxbuf_data(urb, serial);
35426 if (count == -1)
35427 return;
35428 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35429 DUMP1(urb->transfer_buffer, urb->actual_length);
35430
35431 /* Anyone listening? */
35432 - if (serial->port.count == 0)
35433 + if (atomic_read(&serial->port.count) == 0)
35434 return;
35435
35436 if (status == 0) {
35437 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35438 tty_port_tty_set(&serial->port, tty);
35439
35440 /* check for port already opened, if not set the termios */
35441 - serial->port.count++;
35442 - if (serial->port.count == 1) {
35443 + if (atomic_inc_return(&serial->port.count) == 1) {
35444 serial->rx_state = RX_IDLE;
35445 /* Force default termio settings */
35446 _hso_serial_set_termios(tty, NULL);
35447 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35448 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35449 if (result) {
35450 hso_stop_serial_device(serial->parent);
35451 - serial->port.count--;
35452 + atomic_dec(&serial->port.count);
35453 kref_put(&serial->parent->ref, hso_serial_ref_free);
35454 }
35455 } else {
35456 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35457
35458 /* reset the rts and dtr */
35459 /* do the actual close */
35460 - serial->port.count--;
35461 + atomic_dec(&serial->port.count);
35462
35463 - if (serial->port.count <= 0) {
35464 - serial->port.count = 0;
35465 + if (atomic_read(&serial->port.count) <= 0) {
35466 + atomic_set(&serial->port.count, 0);
35467 tty_port_tty_set(&serial->port, NULL);
35468 if (!usb_gone)
35469 hso_stop_serial_device(serial->parent);
35470 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35471
35472 /* the actual setup */
35473 spin_lock_irqsave(&serial->serial_lock, flags);
35474 - if (serial->port.count)
35475 + if (atomic_read(&serial->port.count))
35476 _hso_serial_set_termios(tty, old);
35477 else
35478 tty->termios = old;
35479 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35480 D1("Pending read interrupt on port %d\n", i);
35481 spin_lock(&serial->serial_lock);
35482 if (serial->rx_state == RX_IDLE &&
35483 - serial->port.count > 0) {
35484 + atomic_read(&serial->port.count) > 0) {
35485 /* Setup and send a ctrl req read on
35486 * port i */
35487 if (!serial->rx_urb_filled[0]) {
35488 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35489 /* Start all serial ports */
35490 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35491 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35492 - if (dev2ser(serial_table[i])->port.count) {
35493 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35494 result =
35495 hso_start_serial_device(serial_table[i], GFP_NOIO);
35496 hso_kick_transmit(dev2ser(serial_table[i]));
35497 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35498 index 6169fbd..40e8422 100644
35499 --- a/drivers/net/wireless/ath/ath.h
35500 +++ b/drivers/net/wireless/ath/ath.h
35501 @@ -119,6 +119,7 @@ struct ath_ops {
35502 void (*write_flush) (void *);
35503 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35504 };
35505 +typedef struct ath_ops __no_const ath_ops_no_const;
35506
35507 struct ath_common;
35508 struct ath_bus_ops;
35509 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35510 index 8d78253..bebbb68 100644
35511 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35512 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35513 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35514 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35515 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35516
35517 - ACCESS_ONCE(ads->ds_link) = i->link;
35518 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35519 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35520 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35521
35522 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35523 ctl6 = SM(i->keytype, AR_EncrType);
35524 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35525
35526 if ((i->is_first || i->is_last) &&
35527 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35528 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35529 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35530 | set11nTries(i->rates, 1)
35531 | set11nTries(i->rates, 2)
35532 | set11nTries(i->rates, 3)
35533 | (i->dur_update ? AR_DurUpdateEna : 0)
35534 | SM(0, AR_BurstDur);
35535
35536 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35537 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35538 | set11nRate(i->rates, 1)
35539 | set11nRate(i->rates, 2)
35540 | set11nRate(i->rates, 3);
35541 } else {
35542 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35543 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35544 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35545 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35546 }
35547
35548 if (!i->is_first) {
35549 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35550 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35551 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35552 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35553 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35554 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35555 return;
35556 }
35557
35558 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35559 break;
35560 }
35561
35562 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35563 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35564 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35565 | SM(i->txpower, AR_XmitPower)
35566 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35567 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35568 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35569 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35570
35571 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35572 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35573 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35574 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35575
35576 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35577 return;
35578
35579 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35580 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35581 | set11nPktDurRTSCTS(i->rates, 1);
35582
35583 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35584 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35585 | set11nPktDurRTSCTS(i->rates, 3);
35586
35587 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35588 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35589 | set11nRateFlags(i->rates, 1)
35590 | set11nRateFlags(i->rates, 2)
35591 | set11nRateFlags(i->rates, 3)
35592 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35593 index 78816b8..1fcdfae 100644
35594 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35595 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35596 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35597 (i->qcu << AR_TxQcuNum_S) | desc_len;
35598
35599 checksum += val;
35600 - ACCESS_ONCE(ads->info) = val;
35601 + ACCESS_ONCE_RW(ads->info) = val;
35602
35603 checksum += i->link;
35604 - ACCESS_ONCE(ads->link) = i->link;
35605 + ACCESS_ONCE_RW(ads->link) = i->link;
35606
35607 checksum += i->buf_addr[0];
35608 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35609 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35610 checksum += i->buf_addr[1];
35611 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35612 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35613 checksum += i->buf_addr[2];
35614 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35615 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35616 checksum += i->buf_addr[3];
35617 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35618 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35619
35620 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35621 - ACCESS_ONCE(ads->ctl3) = val;
35622 + ACCESS_ONCE_RW(ads->ctl3) = val;
35623 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35624 - ACCESS_ONCE(ads->ctl5) = val;
35625 + ACCESS_ONCE_RW(ads->ctl5) = val;
35626 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35627 - ACCESS_ONCE(ads->ctl7) = val;
35628 + ACCESS_ONCE_RW(ads->ctl7) = val;
35629 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35630 - ACCESS_ONCE(ads->ctl9) = val;
35631 + ACCESS_ONCE_RW(ads->ctl9) = val;
35632
35633 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35634 - ACCESS_ONCE(ads->ctl10) = checksum;
35635 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35636
35637 if (i->is_first || i->is_last) {
35638 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35639 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35640 | set11nTries(i->rates, 1)
35641 | set11nTries(i->rates, 2)
35642 | set11nTries(i->rates, 3)
35643 | (i->dur_update ? AR_DurUpdateEna : 0)
35644 | SM(0, AR_BurstDur);
35645
35646 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35647 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35648 | set11nRate(i->rates, 1)
35649 | set11nRate(i->rates, 2)
35650 | set11nRate(i->rates, 3);
35651 } else {
35652 - ACCESS_ONCE(ads->ctl13) = 0;
35653 - ACCESS_ONCE(ads->ctl14) = 0;
35654 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35655 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35656 }
35657
35658 ads->ctl20 = 0;
35659 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35660
35661 ctl17 = SM(i->keytype, AR_EncrType);
35662 if (!i->is_first) {
35663 - ACCESS_ONCE(ads->ctl11) = 0;
35664 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35665 - ACCESS_ONCE(ads->ctl15) = 0;
35666 - ACCESS_ONCE(ads->ctl16) = 0;
35667 - ACCESS_ONCE(ads->ctl17) = ctl17;
35668 - ACCESS_ONCE(ads->ctl18) = 0;
35669 - ACCESS_ONCE(ads->ctl19) = 0;
35670 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35671 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35672 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35673 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35674 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35675 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35676 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35677 return;
35678 }
35679
35680 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35681 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35682 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35683 | SM(i->txpower, AR_XmitPower)
35684 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35685 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35686 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35687 ctl12 |= SM(val, AR_PAPRDChainMask);
35688
35689 - ACCESS_ONCE(ads->ctl12) = ctl12;
35690 - ACCESS_ONCE(ads->ctl17) = ctl17;
35691 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35692 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35693
35694 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35695 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35696 | set11nPktDurRTSCTS(i->rates, 1);
35697
35698 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35699 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35700 | set11nPktDurRTSCTS(i->rates, 3);
35701
35702 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35703 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35704 | set11nRateFlags(i->rates, 1)
35705 | set11nRateFlags(i->rates, 2)
35706 | set11nRateFlags(i->rates, 3)
35707 | SM(i->rtscts_rate, AR_RTSCTSRate);
35708
35709 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35710 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35711 }
35712
35713 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35714 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35715 index de6968f..29ac4c1 100644
35716 --- a/drivers/net/wireless/ath/ath9k/hw.h
35717 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35718 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35719
35720 /* ANI */
35721 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35722 -};
35723 +} __no_const;
35724
35725 /**
35726 * struct ath_hw_ops - callbacks used by hardware code and driver code
35727 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35728 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35729 struct ath_hw_antcomb_conf *antconf);
35730
35731 -};
35732 +} __no_const;
35733
35734 struct ath_nf_limits {
35735 s16 max;
35736 @@ -706,7 +706,7 @@ enum ath_cal_list {
35737 #define AH_FASTCC 0x4
35738
35739 struct ath_hw {
35740 - struct ath_ops reg_ops;
35741 + ath_ops_no_const reg_ops;
35742
35743 struct ieee80211_hw *hw;
35744 struct ath_common common;
35745 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35746 index af00e2c..ab04d34 100644
35747 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35748 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35749 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35750 void (*carrsuppr)(struct brcms_phy *);
35751 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35752 void (*detach)(struct brcms_phy *);
35753 -};
35754 +} __no_const;
35755
35756 struct brcms_phy {
35757 struct brcms_phy_pub pubpi_ro;
35758 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35759 index faec404..a5277f1 100644
35760 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35761 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35762 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35763 */
35764 if (il3945_mod_params.disable_hw_scan) {
35765 D_INFO("Disabling hw_scan\n");
35766 - il3945_mac_ops.hw_scan = NULL;
35767 + pax_open_kernel();
35768 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35769 + pax_close_kernel();
35770 }
35771
35772 D_INFO("*** LOAD DRIVER ***\n");
35773 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35774 index a47b306..297daf2 100644
35775 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35776 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35777 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35778 {
35779 struct iwl_priv *priv = file->private_data;
35780 char buf[64];
35781 - int buf_size;
35782 + size_t buf_size;
35783 u32 offset, len;
35784
35785 memset(buf, 0, sizeof(buf));
35786 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35787 struct iwl_priv *priv = file->private_data;
35788
35789 char buf[8];
35790 - int buf_size;
35791 + size_t buf_size;
35792 u32 reset_flag;
35793
35794 memset(buf, 0, sizeof(buf));
35795 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35796 {
35797 struct iwl_priv *priv = file->private_data;
35798 char buf[8];
35799 - int buf_size;
35800 + size_t buf_size;
35801 int ht40;
35802
35803 memset(buf, 0, sizeof(buf));
35804 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35805 {
35806 struct iwl_priv *priv = file->private_data;
35807 char buf[8];
35808 - int buf_size;
35809 + size_t buf_size;
35810 int value;
35811
35812 memset(buf, 0, sizeof(buf));
35813 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35814 {
35815 struct iwl_priv *priv = file->private_data;
35816 char buf[8];
35817 - int buf_size;
35818 + size_t buf_size;
35819 int clear;
35820
35821 memset(buf, 0, sizeof(buf));
35822 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35823 {
35824 struct iwl_priv *priv = file->private_data;
35825 char buf[8];
35826 - int buf_size;
35827 + size_t buf_size;
35828 int trace;
35829
35830 memset(buf, 0, sizeof(buf));
35831 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35832 {
35833 struct iwl_priv *priv = file->private_data;
35834 char buf[8];
35835 - int buf_size;
35836 + size_t buf_size;
35837 int missed;
35838
35839 memset(buf, 0, sizeof(buf));
35840 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35841
35842 struct iwl_priv *priv = file->private_data;
35843 char buf[8];
35844 - int buf_size;
35845 + size_t buf_size;
35846 int plcp;
35847
35848 memset(buf, 0, sizeof(buf));
35849 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35850
35851 struct iwl_priv *priv = file->private_data;
35852 char buf[8];
35853 - int buf_size;
35854 + size_t buf_size;
35855 int flush;
35856
35857 memset(buf, 0, sizeof(buf));
35858 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35859
35860 struct iwl_priv *priv = file->private_data;
35861 char buf[8];
35862 - int buf_size;
35863 + size_t buf_size;
35864 int rts;
35865
35866 if (!priv->cfg->ht_params)
35867 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35868 {
35869 struct iwl_priv *priv = file->private_data;
35870 char buf[8];
35871 - int buf_size;
35872 + size_t buf_size;
35873
35874 memset(buf, 0, sizeof(buf));
35875 buf_size = min(count, sizeof(buf) - 1);
35876 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35877 struct iwl_priv *priv = file->private_data;
35878 u32 event_log_flag;
35879 char buf[8];
35880 - int buf_size;
35881 + size_t buf_size;
35882
35883 /* check that the interface is up */
35884 if (!iwl_is_ready(priv))
35885 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35886 struct iwl_priv *priv = file->private_data;
35887 char buf[8];
35888 u32 calib_disabled;
35889 - int buf_size;
35890 + size_t buf_size;
35891
35892 memset(buf, 0, sizeof(buf));
35893 buf_size = min(count, sizeof(buf) - 1);
35894 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35895 index dbeebef..b45a152 100644
35896 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35897 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35898 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35899 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35900
35901 char buf[8];
35902 - int buf_size;
35903 + size_t buf_size;
35904 u32 reset_flag;
35905
35906 memset(buf, 0, sizeof(buf));
35907 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35908 {
35909 struct iwl_trans *trans = file->private_data;
35910 char buf[8];
35911 - int buf_size;
35912 + size_t buf_size;
35913 int csr;
35914
35915 memset(buf, 0, sizeof(buf));
35916 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35917 index 0083839..fcb7225 100644
35918 --- a/drivers/net/wireless/mac80211_hwsim.c
35919 +++ b/drivers/net/wireless/mac80211_hwsim.c
35920 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35921 return -EINVAL;
35922
35923 if (fake_hw_scan) {
35924 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35925 - mac80211_hwsim_ops.sw_scan_start = NULL;
35926 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35927 + pax_open_kernel();
35928 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35929 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35930 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35931 + pax_close_kernel();
35932 }
35933
35934 spin_lock_init(&hwsim_radio_lock);
35935 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35936 index e7c2a82..582e228 100644
35937 --- a/drivers/net/wireless/mwifiex/main.h
35938 +++ b/drivers/net/wireless/mwifiex/main.h
35939 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
35940 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35941 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35942 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35943 -};
35944 +} __no_const;
35945
35946 struct mwifiex_adapter {
35947 u8 iface_type;
35948 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35949 index 7a4ae9e..56e00bd 100644
35950 --- a/drivers/net/wireless/rndis_wlan.c
35951 +++ b/drivers/net/wireless/rndis_wlan.c
35952 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35953
35954 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35955
35956 - if (rts_threshold < 0 || rts_threshold > 2347)
35957 + if (rts_threshold > 2347)
35958 rts_threshold = 2347;
35959
35960 tmp = cpu_to_le32(rts_threshold);
35961 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35962 index 8afb546..0c0dc5c 100644
35963 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35964 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35965 @@ -397,7 +397,7 @@ struct rt2x00_intf {
35966 * for hardware which doesn't support hardware
35967 * sequence counting.
35968 */
35969 - atomic_t seqno;
35970 + atomic_unchecked_t seqno;
35971 };
35972
35973 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35974 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35975 index f7e74a0..da71431 100644
35976 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35977 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35978 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35979 * sequence counter given by mac80211.
35980 */
35981 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35982 - seqno = atomic_add_return(0x10, &intf->seqno);
35983 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35984 else
35985 - seqno = atomic_read(&intf->seqno);
35986 + seqno = atomic_read_unchecked(&intf->seqno);
35987
35988 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35989 hdr->seq_ctrl |= cpu_to_le16(seqno);
35990 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35991 index fd02060..74ee481 100644
35992 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35993 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35994 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35995 void (*reset)(struct wl1251 *wl);
35996 void (*enable_irq)(struct wl1251 *wl);
35997 void (*disable_irq)(struct wl1251 *wl);
35998 -};
35999 +} __no_const;
36000
36001 struct wl1251 {
36002 struct ieee80211_hw *hw;
36003 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36004 index 0ce7a8e..56a0ccf 100644
36005 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36006 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36007 @@ -81,7 +81,7 @@ struct wlcore_ops {
36008 struct ieee80211_sta *sta,
36009 struct ieee80211_key_conf *key_conf);
36010 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36011 -};
36012 +} __no_const;
36013
36014 enum wlcore_partitions {
36015 PART_DOWN,
36016 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36017 index f34b5b2..b5abb9f 100644
36018 --- a/drivers/oprofile/buffer_sync.c
36019 +++ b/drivers/oprofile/buffer_sync.c
36020 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36021 if (cookie == NO_COOKIE)
36022 offset = pc;
36023 if (cookie == INVALID_COOKIE) {
36024 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36025 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36026 offset = pc;
36027 }
36028 if (cookie != last_cookie) {
36029 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36030 /* add userspace sample */
36031
36032 if (!mm) {
36033 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36034 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36035 return 0;
36036 }
36037
36038 cookie = lookup_dcookie(mm, s->eip, &offset);
36039
36040 if (cookie == INVALID_COOKIE) {
36041 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36042 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36043 return 0;
36044 }
36045
36046 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36047 /* ignore backtraces if failed to add a sample */
36048 if (state == sb_bt_start) {
36049 state = sb_bt_ignore;
36050 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36051 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36052 }
36053 }
36054 release_mm(mm);
36055 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36056 index c0cc4e7..44d4e54 100644
36057 --- a/drivers/oprofile/event_buffer.c
36058 +++ b/drivers/oprofile/event_buffer.c
36059 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36060 }
36061
36062 if (buffer_pos == buffer_size) {
36063 - atomic_inc(&oprofile_stats.event_lost_overflow);
36064 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36065 return;
36066 }
36067
36068 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36069 index ed2c3ec..deda85a 100644
36070 --- a/drivers/oprofile/oprof.c
36071 +++ b/drivers/oprofile/oprof.c
36072 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36073 if (oprofile_ops.switch_events())
36074 return;
36075
36076 - atomic_inc(&oprofile_stats.multiplex_counter);
36077 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36078 start_switch_worker();
36079 }
36080
36081 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36082 index 917d28e..d62d981 100644
36083 --- a/drivers/oprofile/oprofile_stats.c
36084 +++ b/drivers/oprofile/oprofile_stats.c
36085 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36086 cpu_buf->sample_invalid_eip = 0;
36087 }
36088
36089 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36090 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36091 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36092 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36093 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36094 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36095 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36096 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36097 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36098 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36099 }
36100
36101
36102 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36103 index 38b6fc0..b5cbfce 100644
36104 --- a/drivers/oprofile/oprofile_stats.h
36105 +++ b/drivers/oprofile/oprofile_stats.h
36106 @@ -13,11 +13,11 @@
36107 #include <linux/atomic.h>
36108
36109 struct oprofile_stat_struct {
36110 - atomic_t sample_lost_no_mm;
36111 - atomic_t sample_lost_no_mapping;
36112 - atomic_t bt_lost_no_mapping;
36113 - atomic_t event_lost_overflow;
36114 - atomic_t multiplex_counter;
36115 + atomic_unchecked_t sample_lost_no_mm;
36116 + atomic_unchecked_t sample_lost_no_mapping;
36117 + atomic_unchecked_t bt_lost_no_mapping;
36118 + atomic_unchecked_t event_lost_overflow;
36119 + atomic_unchecked_t multiplex_counter;
36120 };
36121
36122 extern struct oprofile_stat_struct oprofile_stats;
36123 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36124 index 849357c..b83c1e0 100644
36125 --- a/drivers/oprofile/oprofilefs.c
36126 +++ b/drivers/oprofile/oprofilefs.c
36127 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36128
36129
36130 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36131 - char const *name, atomic_t *val)
36132 + char const *name, atomic_unchecked_t *val)
36133 {
36134 return __oprofilefs_create_file(sb, root, name,
36135 &atomic_ro_fops, 0444, val);
36136 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36137 index 3f56bc0..707d642 100644
36138 --- a/drivers/parport/procfs.c
36139 +++ b/drivers/parport/procfs.c
36140 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36141
36142 *ppos += len;
36143
36144 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36145 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36146 }
36147
36148 #ifdef CONFIG_PARPORT_1284
36149 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36150
36151 *ppos += len;
36152
36153 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36154 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36155 }
36156 #endif /* IEEE1284.3 support. */
36157
36158 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36159 index 9fff878..ad0ad53 100644
36160 --- a/drivers/pci/hotplug/cpci_hotplug.h
36161 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36162 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36163 int (*hardware_test) (struct slot* slot, u32 value);
36164 u8 (*get_power) (struct slot* slot);
36165 int (*set_power) (struct slot* slot, int value);
36166 -};
36167 +} __no_const;
36168
36169 struct cpci_hp_controller {
36170 unsigned int irq;
36171 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36172 index 76ba8a1..20ca857 100644
36173 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36174 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36175 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36176
36177 void compaq_nvram_init (void __iomem *rom_start)
36178 {
36179 +
36180 +#ifndef CONFIG_PAX_KERNEXEC
36181 if (rom_start) {
36182 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36183 }
36184 +#endif
36185 +
36186 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36187
36188 /* initialize our int15 lock */
36189 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36190 index b500840..d7159d3 100644
36191 --- a/drivers/pci/pcie/aspm.c
36192 +++ b/drivers/pci/pcie/aspm.c
36193 @@ -27,9 +27,9 @@
36194 #define MODULE_PARAM_PREFIX "pcie_aspm."
36195
36196 /* Note: those are not register definitions */
36197 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36198 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36199 -#define ASPM_STATE_L1 (4) /* L1 state */
36200 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36201 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36202 +#define ASPM_STATE_L1 (4U) /* L1 state */
36203 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36204 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36205
36206 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36207 index 61859d0..124539e 100644
36208 --- a/drivers/pci/probe.c
36209 +++ b/drivers/pci/probe.c
36210 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36211 struct pci_bus_region region;
36212 bool bar_too_big = false, bar_disabled = false;
36213
36214 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36215 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36216
36217 /* No printks while decoding is disabled! */
36218 if (!dev->mmio_always_on) {
36219 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36220 index 27911b5..5b6db88 100644
36221 --- a/drivers/pci/proc.c
36222 +++ b/drivers/pci/proc.c
36223 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36224 static int __init pci_proc_init(void)
36225 {
36226 struct pci_dev *dev = NULL;
36227 +
36228 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36229 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36230 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36231 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36232 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36233 +#endif
36234 +#else
36235 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36236 +#endif
36237 proc_create("devices", 0, proc_bus_pci_dir,
36238 &proc_bus_pci_dev_operations);
36239 proc_initialized = 1;
36240 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36241 index 52daaa8..d6b81eb 100644
36242 --- a/drivers/platform/x86/thinkpad_acpi.c
36243 +++ b/drivers/platform/x86/thinkpad_acpi.c
36244 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36245 return 0;
36246 }
36247
36248 -void static hotkey_mask_warn_incomplete_mask(void)
36249 +static void hotkey_mask_warn_incomplete_mask(void)
36250 {
36251 /* log only what the user can fix... */
36252 const u32 wantedmask = hotkey_driver_mask &
36253 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36254 }
36255 }
36256
36257 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36258 - struct tp_nvram_state *newn,
36259 - const u32 event_mask)
36260 -{
36261 -
36262 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36263 do { \
36264 if ((event_mask & (1 << __scancode)) && \
36265 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36266 tpacpi_hotkey_send_key(__scancode); \
36267 } while (0)
36268
36269 - void issue_volchange(const unsigned int oldvol,
36270 - const unsigned int newvol)
36271 - {
36272 - unsigned int i = oldvol;
36273 +static void issue_volchange(const unsigned int oldvol,
36274 + const unsigned int newvol,
36275 + const u32 event_mask)
36276 +{
36277 + unsigned int i = oldvol;
36278
36279 - while (i > newvol) {
36280 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36281 - i--;
36282 - }
36283 - while (i < newvol) {
36284 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36285 - i++;
36286 - }
36287 + while (i > newvol) {
36288 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36289 + i--;
36290 }
36291 + while (i < newvol) {
36292 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36293 + i++;
36294 + }
36295 +}
36296
36297 - void issue_brightnesschange(const unsigned int oldbrt,
36298 - const unsigned int newbrt)
36299 - {
36300 - unsigned int i = oldbrt;
36301 +static void issue_brightnesschange(const unsigned int oldbrt,
36302 + const unsigned int newbrt,
36303 + const u32 event_mask)
36304 +{
36305 + unsigned int i = oldbrt;
36306
36307 - while (i > newbrt) {
36308 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36309 - i--;
36310 - }
36311 - while (i < newbrt) {
36312 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36313 - i++;
36314 - }
36315 + while (i > newbrt) {
36316 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36317 + i--;
36318 + }
36319 + while (i < newbrt) {
36320 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36321 + i++;
36322 }
36323 +}
36324
36325 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36326 + struct tp_nvram_state *newn,
36327 + const u32 event_mask)
36328 +{
36329 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36330 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36331 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36332 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36333 oldn->volume_level != newn->volume_level) {
36334 /* recently muted, or repeated mute keypress, or
36335 * multiple presses ending in mute */
36336 - issue_volchange(oldn->volume_level, newn->volume_level);
36337 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36338 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36339 }
36340 } else {
36341 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36342 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36343 }
36344 if (oldn->volume_level != newn->volume_level) {
36345 - issue_volchange(oldn->volume_level, newn->volume_level);
36346 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36347 } else if (oldn->volume_toggle != newn->volume_toggle) {
36348 /* repeated vol up/down keypress at end of scale ? */
36349 if (newn->volume_level == 0)
36350 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36351 /* handle brightness */
36352 if (oldn->brightness_level != newn->brightness_level) {
36353 issue_brightnesschange(oldn->brightness_level,
36354 - newn->brightness_level);
36355 + newn->brightness_level,
36356 + event_mask);
36357 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36358 /* repeated key presses that didn't change state */
36359 if (newn->brightness_level == 0)
36360 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36361 && !tp_features.bright_unkfw)
36362 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36363 }
36364 +}
36365
36366 #undef TPACPI_COMPARE_KEY
36367 #undef TPACPI_MAY_SEND_KEY
36368 -}
36369
36370 /*
36371 * Polling driver
36372 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36373 index 769d265..a3a05ca 100644
36374 --- a/drivers/pnp/pnpbios/bioscalls.c
36375 +++ b/drivers/pnp/pnpbios/bioscalls.c
36376 @@ -58,7 +58,7 @@ do { \
36377 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36378 } while(0)
36379
36380 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36381 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36382 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36383
36384 /*
36385 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36386
36387 cpu = get_cpu();
36388 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36389 +
36390 + pax_open_kernel();
36391 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36392 + pax_close_kernel();
36393
36394 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36395 spin_lock_irqsave(&pnp_bios_lock, flags);
36396 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36397 :"memory");
36398 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36399
36400 + pax_open_kernel();
36401 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36402 + pax_close_kernel();
36403 +
36404 put_cpu();
36405
36406 /* If we get here and this is set then the PnP BIOS faulted on us. */
36407 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36408 return status;
36409 }
36410
36411 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36412 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36413 {
36414 int i;
36415
36416 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36417 pnp_bios_callpoint.offset = header->fields.pm16offset;
36418 pnp_bios_callpoint.segment = PNP_CS16;
36419
36420 + pax_open_kernel();
36421 +
36422 for_each_possible_cpu(i) {
36423 struct desc_struct *gdt = get_cpu_gdt_table(i);
36424 if (!gdt)
36425 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36426 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36427 (unsigned long)__va(header->fields.pm16dseg));
36428 }
36429 +
36430 + pax_close_kernel();
36431 }
36432 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36433 index b0ecacb..7c9da2e 100644
36434 --- a/drivers/pnp/resource.c
36435 +++ b/drivers/pnp/resource.c
36436 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36437 return 1;
36438
36439 /* check if the resource is valid */
36440 - if (*irq < 0 || *irq > 15)
36441 + if (*irq > 15)
36442 return 0;
36443
36444 /* check if the resource is reserved */
36445 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36446 return 1;
36447
36448 /* check if the resource is valid */
36449 - if (*dma < 0 || *dma == 4 || *dma > 7)
36450 + if (*dma == 4 || *dma > 7)
36451 return 0;
36452
36453 /* check if the resource is reserved */
36454 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36455 index 181ddec..774b6da 100644
36456 --- a/drivers/power/bq27x00_battery.c
36457 +++ b/drivers/power/bq27x00_battery.c
36458 @@ -80,7 +80,7 @@
36459 struct bq27x00_device_info;
36460 struct bq27x00_access_methods {
36461 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36462 -};
36463 +} __no_const;
36464
36465 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36466
36467 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36468 index 8d53174..04c65de 100644
36469 --- a/drivers/regulator/max8660.c
36470 +++ b/drivers/regulator/max8660.c
36471 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36472 max8660->shadow_regs[MAX8660_OVER1] = 5;
36473 } else {
36474 /* Otherwise devices can be toggled via software */
36475 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36476 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36477 + pax_open_kernel();
36478 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36479 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36480 + pax_close_kernel();
36481 }
36482
36483 /*
36484 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36485 index b388b74..ed82573 100644
36486 --- a/drivers/regulator/mc13892-regulator.c
36487 +++ b/drivers/regulator/mc13892-regulator.c
36488 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36489 }
36490 mc13xxx_unlock(mc13892);
36491
36492 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36493 + pax_open_kernel();
36494 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36495 = mc13892_vcam_set_mode;
36496 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36497 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36498 = mc13892_vcam_get_mode;
36499 + pax_close_kernel();
36500
36501 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36502 ARRAY_SIZE(mc13892_regulators));
36503 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36504 index cace6d3..f623fda 100644
36505 --- a/drivers/rtc/rtc-dev.c
36506 +++ b/drivers/rtc/rtc-dev.c
36507 @@ -14,6 +14,7 @@
36508 #include <linux/module.h>
36509 #include <linux/rtc.h>
36510 #include <linux/sched.h>
36511 +#include <linux/grsecurity.h>
36512 #include "rtc-core.h"
36513
36514 static dev_t rtc_devt;
36515 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36516 if (copy_from_user(&tm, uarg, sizeof(tm)))
36517 return -EFAULT;
36518
36519 + gr_log_timechange();
36520 +
36521 return rtc_set_time(rtc, &tm);
36522
36523 case RTC_PIE_ON:
36524 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36525 index 9e933a8..4f969f7 100644
36526 --- a/drivers/scsi/aacraid/aacraid.h
36527 +++ b/drivers/scsi/aacraid/aacraid.h
36528 @@ -503,7 +503,7 @@ struct adapter_ops
36529 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36530 /* Administrative operations */
36531 int (*adapter_comm)(struct aac_dev * dev, int comm);
36532 -};
36533 +} __no_const;
36534
36535 /*
36536 * Define which interrupt handler needs to be installed
36537 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36538 index 7199534..cb7f158 100644
36539 --- a/drivers/scsi/aacraid/linit.c
36540 +++ b/drivers/scsi/aacraid/linit.c
36541 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36542 #elif defined(__devinitconst)
36543 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36544 #else
36545 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36546 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36547 #endif
36548 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36549 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36550 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36551 index ff80552..1c4120c 100644
36552 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36553 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36554 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36555 .lldd_ata_set_dmamode = asd_set_dmamode,
36556 };
36557
36558 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36559 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36560 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36561 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36562 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36563 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36564 index 4ad7e36..d004679 100644
36565 --- a/drivers/scsi/bfa/bfa.h
36566 +++ b/drivers/scsi/bfa/bfa.h
36567 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36568 u32 *end);
36569 int cpe_vec_q0;
36570 int rme_vec_q0;
36571 -};
36572 +} __no_const;
36573 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36574
36575 struct bfa_faa_cbfn_s {
36576 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36577 index f0f80e2..8ec946b 100644
36578 --- a/drivers/scsi/bfa/bfa_fcpim.c
36579 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36580 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36581
36582 bfa_iotag_attach(fcp);
36583
36584 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36585 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36586 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36587 (fcp->num_itns * sizeof(struct bfa_itn_s));
36588 memset(fcp->itn_arr, 0,
36589 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36590 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36591 {
36592 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36593 - struct bfa_itn_s *itn;
36594 + bfa_itn_s_no_const *itn;
36595
36596 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36597 itn->isr = isr;
36598 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36599 index 36f26da..38a34a8 100644
36600 --- a/drivers/scsi/bfa/bfa_fcpim.h
36601 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36602 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36603 struct bfa_itn_s {
36604 bfa_isr_func_t isr;
36605 };
36606 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36607
36608 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36609 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36610 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36611 struct list_head iotag_tio_free_q; /* free IO resources */
36612 struct list_head iotag_unused_q; /* unused IO resources*/
36613 struct bfa_iotag_s *iotag_arr;
36614 - struct bfa_itn_s *itn_arr;
36615 + bfa_itn_s_no_const *itn_arr;
36616 int num_ioim_reqs;
36617 int num_fwtio_reqs;
36618 int num_itns;
36619 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36620 index 1a99d4b..e85d64b 100644
36621 --- a/drivers/scsi/bfa/bfa_ioc.h
36622 +++ b/drivers/scsi/bfa/bfa_ioc.h
36623 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36624 bfa_ioc_disable_cbfn_t disable_cbfn;
36625 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36626 bfa_ioc_reset_cbfn_t reset_cbfn;
36627 -};
36628 +} __no_const;
36629
36630 /*
36631 * IOC event notification mechanism.
36632 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36633 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36634 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36635 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36636 -};
36637 +} __no_const;
36638
36639 /*
36640 * Queue element to wait for room in request queue. FIFO order is
36641 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36642 index 593085a..47aa999 100644
36643 --- a/drivers/scsi/hosts.c
36644 +++ b/drivers/scsi/hosts.c
36645 @@ -42,7 +42,7 @@
36646 #include "scsi_logging.h"
36647
36648
36649 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36650 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36651
36652
36653 static void scsi_host_cls_release(struct device *dev)
36654 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36655 * subtract one because we increment first then return, but we need to
36656 * know what the next host number was before increment
36657 */
36658 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36659 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36660 shost->dma_channel = 0xff;
36661
36662 /* These three are default values which can be overridden */
36663 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36664 index f9823f2..7bc3e81 100644
36665 --- a/drivers/scsi/hpsa.c
36666 +++ b/drivers/scsi/hpsa.c
36667 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36668 unsigned long flags;
36669
36670 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36671 - return h->access.command_completed(h, q);
36672 + return h->access->command_completed(h, q);
36673
36674 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36675 a = rq->head[rq->current_entry];
36676 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36677 while (!list_empty(&h->reqQ)) {
36678 c = list_entry(h->reqQ.next, struct CommandList, list);
36679 /* can't do anything if fifo is full */
36680 - if ((h->access.fifo_full(h))) {
36681 + if ((h->access->fifo_full(h))) {
36682 dev_warn(&h->pdev->dev, "fifo full\n");
36683 break;
36684 }
36685 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36686
36687 /* Tell the controller execute command */
36688 spin_unlock_irqrestore(&h->lock, flags);
36689 - h->access.submit_command(h, c);
36690 + h->access->submit_command(h, c);
36691 spin_lock_irqsave(&h->lock, flags);
36692 }
36693 spin_unlock_irqrestore(&h->lock, flags);
36694 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36695
36696 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36697 {
36698 - return h->access.command_completed(h, q);
36699 + return h->access->command_completed(h, q);
36700 }
36701
36702 static inline bool interrupt_pending(struct ctlr_info *h)
36703 {
36704 - return h->access.intr_pending(h);
36705 + return h->access->intr_pending(h);
36706 }
36707
36708 static inline long interrupt_not_for_us(struct ctlr_info *h)
36709 {
36710 - return (h->access.intr_pending(h) == 0) ||
36711 + return (h->access->intr_pending(h) == 0) ||
36712 (h->interrupts_enabled == 0);
36713 }
36714
36715 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36716 if (prod_index < 0)
36717 return -ENODEV;
36718 h->product_name = products[prod_index].product_name;
36719 - h->access = *(products[prod_index].access);
36720 + h->access = products[prod_index].access;
36721
36722 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36723 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36724 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36725
36726 assert_spin_locked(&lockup_detector_lock);
36727 remove_ctlr_from_lockup_detector_list(h);
36728 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36729 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36730 spin_lock_irqsave(&h->lock, flags);
36731 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36732 spin_unlock_irqrestore(&h->lock, flags);
36733 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36734 }
36735
36736 /* make sure the board interrupts are off */
36737 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36738 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36739
36740 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36741 goto clean2;
36742 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36743 * fake ones to scoop up any residual completions.
36744 */
36745 spin_lock_irqsave(&h->lock, flags);
36746 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36747 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36748 spin_unlock_irqrestore(&h->lock, flags);
36749 free_irqs(h);
36750 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36751 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36752 dev_info(&h->pdev->dev, "Board READY.\n");
36753 dev_info(&h->pdev->dev,
36754 "Waiting for stale completions to drain.\n");
36755 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36756 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36757 msleep(10000);
36758 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36759 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36760
36761 rc = controller_reset_failed(h->cfgtable);
36762 if (rc)
36763 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36764 }
36765
36766 /* Turn the interrupts on so we can service requests */
36767 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36768 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36769
36770 hpsa_hba_inquiry(h);
36771 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36772 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36773 * To write all data in the battery backed cache to disks
36774 */
36775 hpsa_flush_cache(h);
36776 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36777 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36778 hpsa_free_irqs_and_disable_msix(h);
36779 }
36780
36781 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36782 return;
36783 }
36784 /* Change the access methods to the performant access methods */
36785 - h->access = SA5_performant_access;
36786 + h->access = &SA5_performant_access;
36787 h->transMethod = CFGTBL_Trans_Performant;
36788 }
36789
36790 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36791 index 9816479..c5d4e97 100644
36792 --- a/drivers/scsi/hpsa.h
36793 +++ b/drivers/scsi/hpsa.h
36794 @@ -79,7 +79,7 @@ struct ctlr_info {
36795 unsigned int msix_vector;
36796 unsigned int msi_vector;
36797 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36798 - struct access_method access;
36799 + struct access_method *access;
36800
36801 /* queue and queue Info */
36802 struct list_head reqQ;
36803 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36804 index f2df059..a3a9930 100644
36805 --- a/drivers/scsi/ips.h
36806 +++ b/drivers/scsi/ips.h
36807 @@ -1027,7 +1027,7 @@ typedef struct {
36808 int (*intr)(struct ips_ha *);
36809 void (*enableint)(struct ips_ha *);
36810 uint32_t (*statupd)(struct ips_ha *);
36811 -} ips_hw_func_t;
36812 +} __no_const ips_hw_func_t;
36813
36814 typedef struct ips_ha {
36815 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36816 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36817 index c772d8d..35c362c 100644
36818 --- a/drivers/scsi/libfc/fc_exch.c
36819 +++ b/drivers/scsi/libfc/fc_exch.c
36820 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36821 u16 pool_max_index;
36822
36823 struct {
36824 - atomic_t no_free_exch;
36825 - atomic_t no_free_exch_xid;
36826 - atomic_t xid_not_found;
36827 - atomic_t xid_busy;
36828 - atomic_t seq_not_found;
36829 - atomic_t non_bls_resp;
36830 + atomic_unchecked_t no_free_exch;
36831 + atomic_unchecked_t no_free_exch_xid;
36832 + atomic_unchecked_t xid_not_found;
36833 + atomic_unchecked_t xid_busy;
36834 + atomic_unchecked_t seq_not_found;
36835 + atomic_unchecked_t non_bls_resp;
36836 } stats;
36837 };
36838
36839 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36840 /* allocate memory for exchange */
36841 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36842 if (!ep) {
36843 - atomic_inc(&mp->stats.no_free_exch);
36844 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36845 goto out;
36846 }
36847 memset(ep, 0, sizeof(*ep));
36848 @@ -786,7 +786,7 @@ out:
36849 return ep;
36850 err:
36851 spin_unlock_bh(&pool->lock);
36852 - atomic_inc(&mp->stats.no_free_exch_xid);
36853 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36854 mempool_free(ep, mp->ep_pool);
36855 return NULL;
36856 }
36857 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36858 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36859 ep = fc_exch_find(mp, xid);
36860 if (!ep) {
36861 - atomic_inc(&mp->stats.xid_not_found);
36862 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36863 reject = FC_RJT_OX_ID;
36864 goto out;
36865 }
36866 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36867 ep = fc_exch_find(mp, xid);
36868 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36869 if (ep) {
36870 - atomic_inc(&mp->stats.xid_busy);
36871 + atomic_inc_unchecked(&mp->stats.xid_busy);
36872 reject = FC_RJT_RX_ID;
36873 goto rel;
36874 }
36875 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36876 }
36877 xid = ep->xid; /* get our XID */
36878 } else if (!ep) {
36879 - atomic_inc(&mp->stats.xid_not_found);
36880 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36881 reject = FC_RJT_RX_ID; /* XID not found */
36882 goto out;
36883 }
36884 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36885 } else {
36886 sp = &ep->seq;
36887 if (sp->id != fh->fh_seq_id) {
36888 - atomic_inc(&mp->stats.seq_not_found);
36889 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36890 if (f_ctl & FC_FC_END_SEQ) {
36891 /*
36892 * Update sequence_id based on incoming last
36893 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36894
36895 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36896 if (!ep) {
36897 - atomic_inc(&mp->stats.xid_not_found);
36898 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36899 goto out;
36900 }
36901 if (ep->esb_stat & ESB_ST_COMPLETE) {
36902 - atomic_inc(&mp->stats.xid_not_found);
36903 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36904 goto rel;
36905 }
36906 if (ep->rxid == FC_XID_UNKNOWN)
36907 ep->rxid = ntohs(fh->fh_rx_id);
36908 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36909 - atomic_inc(&mp->stats.xid_not_found);
36910 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36911 goto rel;
36912 }
36913 if (ep->did != ntoh24(fh->fh_s_id) &&
36914 ep->did != FC_FID_FLOGI) {
36915 - atomic_inc(&mp->stats.xid_not_found);
36916 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36917 goto rel;
36918 }
36919 sof = fr_sof(fp);
36920 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36921 sp->ssb_stat |= SSB_ST_RESP;
36922 sp->id = fh->fh_seq_id;
36923 } else if (sp->id != fh->fh_seq_id) {
36924 - atomic_inc(&mp->stats.seq_not_found);
36925 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36926 goto rel;
36927 }
36928
36929 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36930 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36931
36932 if (!sp)
36933 - atomic_inc(&mp->stats.xid_not_found);
36934 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36935 else
36936 - atomic_inc(&mp->stats.non_bls_resp);
36937 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36938
36939 fc_frame_free(fp);
36940 }
36941 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36942
36943 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36944 mp = ema->mp;
36945 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36946 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36947 st->fc_no_free_exch_xid +=
36948 - atomic_read(&mp->stats.no_free_exch_xid);
36949 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36950 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36951 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36952 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36953 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36954 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36955 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36956 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36957 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36958 }
36959 }
36960 EXPORT_SYMBOL(fc_exch_update_stats);
36961 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36962 index a59fcdc..abe55f3 100644
36963 --- a/drivers/scsi/libsas/sas_ata.c
36964 +++ b/drivers/scsi/libsas/sas_ata.c
36965 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36966 .postreset = ata_std_postreset,
36967 .error_handler = ata_std_error_handler,
36968 .post_internal_cmd = sas_ata_post_internal,
36969 - .qc_defer = ata_std_qc_defer,
36970 + .qc_defer = ata_std_qc_defer,
36971 .qc_prep = ata_noop_qc_prep,
36972 .qc_issue = sas_ata_qc_issue,
36973 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36974 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36975 index a65c05a..a39e402 100644
36976 --- a/drivers/scsi/lpfc/lpfc.h
36977 +++ b/drivers/scsi/lpfc/lpfc.h
36978 @@ -420,7 +420,7 @@ struct lpfc_vport {
36979 struct dentry *debug_nodelist;
36980 struct dentry *vport_debugfs_root;
36981 struct lpfc_debugfs_trc *disc_trc;
36982 - atomic_t disc_trc_cnt;
36983 + atomic_unchecked_t disc_trc_cnt;
36984 #endif
36985 uint8_t stat_data_enabled;
36986 uint8_t stat_data_blocked;
36987 @@ -834,8 +834,8 @@ struct lpfc_hba {
36988 struct timer_list fabric_block_timer;
36989 unsigned long bit_flags;
36990 #define FABRIC_COMANDS_BLOCKED 0
36991 - atomic_t num_rsrc_err;
36992 - atomic_t num_cmd_success;
36993 + atomic_unchecked_t num_rsrc_err;
36994 + atomic_unchecked_t num_cmd_success;
36995 unsigned long last_rsrc_error_time;
36996 unsigned long last_ramp_down_time;
36997 unsigned long last_ramp_up_time;
36998 @@ -871,7 +871,7 @@ struct lpfc_hba {
36999
37000 struct dentry *debug_slow_ring_trc;
37001 struct lpfc_debugfs_trc *slow_ring_trc;
37002 - atomic_t slow_ring_trc_cnt;
37003 + atomic_unchecked_t slow_ring_trc_cnt;
37004 /* iDiag debugfs sub-directory */
37005 struct dentry *idiag_root;
37006 struct dentry *idiag_pci_cfg;
37007 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37008 index 3217d63..c417981 100644
37009 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37010 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37011 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37012
37013 #include <linux/debugfs.h>
37014
37015 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37016 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37017 static unsigned long lpfc_debugfs_start_time = 0L;
37018
37019 /* iDiag */
37020 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37021 lpfc_debugfs_enable = 0;
37022
37023 len = 0;
37024 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37025 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37026 (lpfc_debugfs_max_disc_trc - 1);
37027 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37028 dtp = vport->disc_trc + i;
37029 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37030 lpfc_debugfs_enable = 0;
37031
37032 len = 0;
37033 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37034 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37035 (lpfc_debugfs_max_slow_ring_trc - 1);
37036 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37037 dtp = phba->slow_ring_trc + i;
37038 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37039 !vport || !vport->disc_trc)
37040 return;
37041
37042 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37043 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37044 (lpfc_debugfs_max_disc_trc - 1);
37045 dtp = vport->disc_trc + index;
37046 dtp->fmt = fmt;
37047 dtp->data1 = data1;
37048 dtp->data2 = data2;
37049 dtp->data3 = data3;
37050 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37051 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37052 dtp->jif = jiffies;
37053 #endif
37054 return;
37055 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37056 !phba || !phba->slow_ring_trc)
37057 return;
37058
37059 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37060 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37061 (lpfc_debugfs_max_slow_ring_trc - 1);
37062 dtp = phba->slow_ring_trc + index;
37063 dtp->fmt = fmt;
37064 dtp->data1 = data1;
37065 dtp->data2 = data2;
37066 dtp->data3 = data3;
37067 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37068 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37069 dtp->jif = jiffies;
37070 #endif
37071 return;
37072 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37073 "slow_ring buffer\n");
37074 goto debug_failed;
37075 }
37076 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37077 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37078 memset(phba->slow_ring_trc, 0,
37079 (sizeof(struct lpfc_debugfs_trc) *
37080 lpfc_debugfs_max_slow_ring_trc));
37081 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37082 "buffer\n");
37083 goto debug_failed;
37084 }
37085 - atomic_set(&vport->disc_trc_cnt, 0);
37086 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37087
37088 snprintf(name, sizeof(name), "discovery_trace");
37089 vport->debug_disc_trc =
37090 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37091 index 45c1520..35ba744 100644
37092 --- a/drivers/scsi/lpfc/lpfc_init.c
37093 +++ b/drivers/scsi/lpfc/lpfc_init.c
37094 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37095 "misc_register returned with status %d", error);
37096
37097 if (lpfc_enable_npiv) {
37098 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37099 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37100 + pax_open_kernel();
37101 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37102 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37103 + pax_close_kernel();
37104 }
37105 lpfc_transport_template =
37106 fc_attach_transport(&lpfc_transport_functions);
37107 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37108 index 925975d..0f1fc07 100644
37109 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37110 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37111 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37112 uint32_t evt_posted;
37113
37114 spin_lock_irqsave(&phba->hbalock, flags);
37115 - atomic_inc(&phba->num_rsrc_err);
37116 + atomic_inc_unchecked(&phba->num_rsrc_err);
37117 phba->last_rsrc_error_time = jiffies;
37118
37119 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37120 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37121 unsigned long flags;
37122 struct lpfc_hba *phba = vport->phba;
37123 uint32_t evt_posted;
37124 - atomic_inc(&phba->num_cmd_success);
37125 + atomic_inc_unchecked(&phba->num_cmd_success);
37126
37127 if (vport->cfg_lun_queue_depth <= queue_depth)
37128 return;
37129 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37130 unsigned long num_rsrc_err, num_cmd_success;
37131 int i;
37132
37133 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37134 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37135 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37136 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37137
37138 /*
37139 * The error and success command counters are global per
37140 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37141 }
37142 }
37143 lpfc_destroy_vport_work_array(phba, vports);
37144 - atomic_set(&phba->num_rsrc_err, 0);
37145 - atomic_set(&phba->num_cmd_success, 0);
37146 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37147 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37148 }
37149
37150 /**
37151 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37152 }
37153 }
37154 lpfc_destroy_vport_work_array(phba, vports);
37155 - atomic_set(&phba->num_rsrc_err, 0);
37156 - atomic_set(&phba->num_cmd_success, 0);
37157 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37158 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37159 }
37160
37161 /**
37162 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37163 index ea8a0b4..812a124 100644
37164 --- a/drivers/scsi/pmcraid.c
37165 +++ b/drivers/scsi/pmcraid.c
37166 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37167 res->scsi_dev = scsi_dev;
37168 scsi_dev->hostdata = res;
37169 res->change_detected = 0;
37170 - atomic_set(&res->read_failures, 0);
37171 - atomic_set(&res->write_failures, 0);
37172 + atomic_set_unchecked(&res->read_failures, 0);
37173 + atomic_set_unchecked(&res->write_failures, 0);
37174 rc = 0;
37175 }
37176 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37177 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37178
37179 /* If this was a SCSI read/write command keep count of errors */
37180 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37181 - atomic_inc(&res->read_failures);
37182 + atomic_inc_unchecked(&res->read_failures);
37183 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37184 - atomic_inc(&res->write_failures);
37185 + atomic_inc_unchecked(&res->write_failures);
37186
37187 if (!RES_IS_GSCSI(res->cfg_entry) &&
37188 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37189 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37190 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37191 * hrrq_id assigned here in queuecommand
37192 */
37193 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37194 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37195 pinstance->num_hrrq;
37196 cmd->cmd_done = pmcraid_io_done;
37197
37198 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37199 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37200 * hrrq_id assigned here in queuecommand
37201 */
37202 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37203 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37204 pinstance->num_hrrq;
37205
37206 if (request_size) {
37207 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37208
37209 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37210 /* add resources only after host is added into system */
37211 - if (!atomic_read(&pinstance->expose_resources))
37212 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37213 return;
37214
37215 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37216 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37217 init_waitqueue_head(&pinstance->reset_wait_q);
37218
37219 atomic_set(&pinstance->outstanding_cmds, 0);
37220 - atomic_set(&pinstance->last_message_id, 0);
37221 - atomic_set(&pinstance->expose_resources, 0);
37222 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37223 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37224
37225 INIT_LIST_HEAD(&pinstance->free_res_q);
37226 INIT_LIST_HEAD(&pinstance->used_res_q);
37227 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37228 /* Schedule worker thread to handle CCN and take care of adding and
37229 * removing devices to OS
37230 */
37231 - atomic_set(&pinstance->expose_resources, 1);
37232 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37233 schedule_work(&pinstance->worker_q);
37234 return rc;
37235
37236 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37237 index e1d150f..6c6df44 100644
37238 --- a/drivers/scsi/pmcraid.h
37239 +++ b/drivers/scsi/pmcraid.h
37240 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37241 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37242
37243 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37244 - atomic_t last_message_id;
37245 + atomic_unchecked_t last_message_id;
37246
37247 /* configuration table */
37248 struct pmcraid_config_table *cfg_table;
37249 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37250 atomic_t outstanding_cmds;
37251
37252 /* should add/delete resources to mid-layer now ?*/
37253 - atomic_t expose_resources;
37254 + atomic_unchecked_t expose_resources;
37255
37256
37257
37258 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37259 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37260 };
37261 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37262 - atomic_t read_failures; /* count of failed READ commands */
37263 - atomic_t write_failures; /* count of failed WRITE commands */
37264 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37265 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37266
37267 /* To indicate add/delete/modify during CCN */
37268 u8 change_detected;
37269 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37270 index 5ab9530..2dd80f7 100644
37271 --- a/drivers/scsi/qla2xxx/qla_attr.c
37272 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37273 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37274 return 0;
37275 }
37276
37277 -struct fc_function_template qla2xxx_transport_functions = {
37278 +fc_function_template_no_const qla2xxx_transport_functions = {
37279
37280 .show_host_node_name = 1,
37281 .show_host_port_name = 1,
37282 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37283 .bsg_timeout = qla24xx_bsg_timeout,
37284 };
37285
37286 -struct fc_function_template qla2xxx_transport_vport_functions = {
37287 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37288
37289 .show_host_node_name = 1,
37290 .show_host_port_name = 1,
37291 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37292 index 39007f5..7fafc64 100644
37293 --- a/drivers/scsi/qla2xxx/qla_def.h
37294 +++ b/drivers/scsi/qla2xxx/qla_def.h
37295 @@ -2284,7 +2284,7 @@ struct isp_operations {
37296 int (*start_scsi) (srb_t *);
37297 int (*abort_isp) (struct scsi_qla_host *);
37298 int (*iospace_config)(struct qla_hw_data*);
37299 -};
37300 +} __no_const;
37301
37302 /* MSI-X Support *************************************************************/
37303
37304 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37305 index 9eacd2d..d79629c 100644
37306 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37307 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37308 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37309 struct device_attribute;
37310 extern struct device_attribute *qla2x00_host_attrs[];
37311 struct fc_function_template;
37312 -extern struct fc_function_template qla2xxx_transport_functions;
37313 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37314 +extern fc_function_template_no_const qla2xxx_transport_functions;
37315 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37316 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37317 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37318 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37319 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37320 index 7fdba7f..1b4b2c2 100644
37321 --- a/drivers/scsi/qla4xxx/ql4_def.h
37322 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37323 @@ -268,7 +268,7 @@ struct ddb_entry {
37324 * (4000 only) */
37325 atomic_t relogin_timer; /* Max Time to wait for
37326 * relogin to complete */
37327 - atomic_t relogin_retry_count; /* Num of times relogin has been
37328 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37329 * retried */
37330 uint32_t default_time2wait; /* Default Min time between
37331 * relogins (+aens) */
37332 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37333 index 9da4266..377b3b6 100644
37334 --- a/drivers/scsi/qla4xxx/ql4_os.c
37335 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37336 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37337 */
37338 if (!iscsi_is_session_online(cls_sess)) {
37339 /* Reset retry relogin timer */
37340 - atomic_inc(&ddb_entry->relogin_retry_count);
37341 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37342 DEBUG2(ql4_printk(KERN_INFO, ha,
37343 "%s: index[%d] relogin timed out-retrying"
37344 " relogin (%d), retry (%d)\n", __func__,
37345 ddb_entry->fw_ddb_index,
37346 - atomic_read(&ddb_entry->relogin_retry_count),
37347 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37348 ddb_entry->default_time2wait + 4));
37349 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37350 atomic_set(&ddb_entry->retry_relogin_timer,
37351 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37352
37353 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37354 atomic_set(&ddb_entry->relogin_timer, 0);
37355 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37356 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37357 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37358 ddb_entry->default_relogin_timeout =
37359 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37360 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37361 index 2936b44..546ecdb 100644
37362 --- a/drivers/scsi/scsi.c
37363 +++ b/drivers/scsi/scsi.c
37364 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37365 unsigned long timeout;
37366 int rtn = 0;
37367
37368 - atomic_inc(&cmd->device->iorequest_cnt);
37369 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37370
37371 /* check if the device is still usable */
37372 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37373 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37374 index faa790f..7e351ddd 100644
37375 --- a/drivers/scsi/scsi_lib.c
37376 +++ b/drivers/scsi/scsi_lib.c
37377 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37378 shost = sdev->host;
37379 scsi_init_cmd_errh(cmd);
37380 cmd->result = DID_NO_CONNECT << 16;
37381 - atomic_inc(&cmd->device->iorequest_cnt);
37382 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37383
37384 /*
37385 * SCSI request completion path will do scsi_device_unbusy(),
37386 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37387
37388 INIT_LIST_HEAD(&cmd->eh_entry);
37389
37390 - atomic_inc(&cmd->device->iodone_cnt);
37391 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37392 if (cmd->result)
37393 - atomic_inc(&cmd->device->ioerr_cnt);
37394 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37395
37396 disposition = scsi_decide_disposition(cmd);
37397 if (disposition != SUCCESS &&
37398 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37399 index ce5224c..8c6d071 100644
37400 --- a/drivers/scsi/scsi_sysfs.c
37401 +++ b/drivers/scsi/scsi_sysfs.c
37402 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37403 char *buf) \
37404 { \
37405 struct scsi_device *sdev = to_scsi_device(dev); \
37406 - unsigned long long count = atomic_read(&sdev->field); \
37407 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37408 return snprintf(buf, 20, "0x%llx\n", count); \
37409 } \
37410 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37411 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37412 index 84a1fdf..693b0d6 100644
37413 --- a/drivers/scsi/scsi_tgt_lib.c
37414 +++ b/drivers/scsi/scsi_tgt_lib.c
37415 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37416 int err;
37417
37418 dprintk("%lx %u\n", uaddr, len);
37419 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37420 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37421 if (err) {
37422 /*
37423 * TODO: need to fixup sg_tablesize, max_segment_size,
37424 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37425 index e894ca7..de9d7660 100644
37426 --- a/drivers/scsi/scsi_transport_fc.c
37427 +++ b/drivers/scsi/scsi_transport_fc.c
37428 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37429 * Netlink Infrastructure
37430 */
37431
37432 -static atomic_t fc_event_seq;
37433 +static atomic_unchecked_t fc_event_seq;
37434
37435 /**
37436 * fc_get_event_number - Obtain the next sequential FC event number
37437 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37438 u32
37439 fc_get_event_number(void)
37440 {
37441 - return atomic_add_return(1, &fc_event_seq);
37442 + return atomic_add_return_unchecked(1, &fc_event_seq);
37443 }
37444 EXPORT_SYMBOL(fc_get_event_number);
37445
37446 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37447 {
37448 int error;
37449
37450 - atomic_set(&fc_event_seq, 0);
37451 + atomic_set_unchecked(&fc_event_seq, 0);
37452
37453 error = transport_class_register(&fc_host_class);
37454 if (error)
37455 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37456 char *cp;
37457
37458 *val = simple_strtoul(buf, &cp, 0);
37459 - if ((*cp && (*cp != '\n')) || (*val < 0))
37460 + if (*cp && (*cp != '\n'))
37461 return -EINVAL;
37462 /*
37463 * Check for overflow; dev_loss_tmo is u32
37464 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37465 index fa1dfaa..4bb620c 100644
37466 --- a/drivers/scsi/scsi_transport_iscsi.c
37467 +++ b/drivers/scsi/scsi_transport_iscsi.c
37468 @@ -79,7 +79,7 @@ struct iscsi_internal {
37469 struct transport_container session_cont;
37470 };
37471
37472 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37473 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37474 static struct workqueue_struct *iscsi_eh_timer_workq;
37475
37476 static DEFINE_IDA(iscsi_sess_ida);
37477 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37478 int err;
37479
37480 ihost = shost->shost_data;
37481 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37482 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37483
37484 if (target_id == ISCSI_MAX_TARGET) {
37485 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37486 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37487 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37488 ISCSI_TRANSPORT_VERSION);
37489
37490 - atomic_set(&iscsi_session_nr, 0);
37491 + atomic_set_unchecked(&iscsi_session_nr, 0);
37492
37493 err = class_register(&iscsi_transport_class);
37494 if (err)
37495 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37496 index 21a045e..ec89e03 100644
37497 --- a/drivers/scsi/scsi_transport_srp.c
37498 +++ b/drivers/scsi/scsi_transport_srp.c
37499 @@ -33,7 +33,7 @@
37500 #include "scsi_transport_srp_internal.h"
37501
37502 struct srp_host_attrs {
37503 - atomic_t next_port_id;
37504 + atomic_unchecked_t next_port_id;
37505 };
37506 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37507
37508 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37509 struct Scsi_Host *shost = dev_to_shost(dev);
37510 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37511
37512 - atomic_set(&srp_host->next_port_id, 0);
37513 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37514 return 0;
37515 }
37516
37517 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37518 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37519 rport->roles = ids->roles;
37520
37521 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37522 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37523 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37524
37525 transport_setup_device(&rport->dev);
37526 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37527 index 4df73e5..b691c58 100644
37528 --- a/drivers/scsi/sd.c
37529 +++ b/drivers/scsi/sd.c
37530 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37531 sdkp->disk = gd;
37532 sdkp->index = index;
37533 atomic_set(&sdkp->openers, 0);
37534 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37535 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37536
37537 if (!sdp->request_queue->rq_timeout) {
37538 if (sdp->type != TYPE_MOD)
37539 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37540 index 9c5c5f2..8414557 100644
37541 --- a/drivers/scsi/sg.c
37542 +++ b/drivers/scsi/sg.c
37543 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37544 sdp->disk->disk_name,
37545 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37546 NULL,
37547 - (char *)arg);
37548 + (char __user *)arg);
37549 case BLKTRACESTART:
37550 return blk_trace_startstop(sdp->device->request_queue, 1);
37551 case BLKTRACESTOP:
37552 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37553 index 84c2861..ece0a31 100644
37554 --- a/drivers/spi/spi.c
37555 +++ b/drivers/spi/spi.c
37556 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37557 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37558
37559 /* portable code must never pass more than 32 bytes */
37560 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37561 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37562
37563 static u8 *buf;
37564
37565 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37566 index 34afc16..ffe44dd 100644
37567 --- a/drivers/staging/octeon/ethernet-rx.c
37568 +++ b/drivers/staging/octeon/ethernet-rx.c
37569 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37570 /* Increment RX stats for virtual ports */
37571 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37572 #ifdef CONFIG_64BIT
37573 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37574 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37575 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37576 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37577 #else
37578 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37579 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37580 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37581 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37582 #endif
37583 }
37584 netif_receive_skb(skb);
37585 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37586 dev->name);
37587 */
37588 #ifdef CONFIG_64BIT
37589 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37590 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37591 #else
37592 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37593 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37594 #endif
37595 dev_kfree_skb_irq(skb);
37596 }
37597 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37598 index 683bedc..86dba9a 100644
37599 --- a/drivers/staging/octeon/ethernet.c
37600 +++ b/drivers/staging/octeon/ethernet.c
37601 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37602 * since the RX tasklet also increments it.
37603 */
37604 #ifdef CONFIG_64BIT
37605 - atomic64_add(rx_status.dropped_packets,
37606 - (atomic64_t *)&priv->stats.rx_dropped);
37607 + atomic64_add_unchecked(rx_status.dropped_packets,
37608 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37609 #else
37610 - atomic_add(rx_status.dropped_packets,
37611 - (atomic_t *)&priv->stats.rx_dropped);
37612 + atomic_add_unchecked(rx_status.dropped_packets,
37613 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37614 #endif
37615 }
37616
37617 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37618 index dc23395..cf7e9b1 100644
37619 --- a/drivers/staging/rtl8712/rtl871x_io.h
37620 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37621 @@ -108,7 +108,7 @@ struct _io_ops {
37622 u8 *pmem);
37623 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37624 u8 *pmem);
37625 -};
37626 +} __no_const;
37627
37628 struct io_req {
37629 struct list_head list;
37630 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37631 index c7b5e8b..783d6cb 100644
37632 --- a/drivers/staging/sbe-2t3e3/netdev.c
37633 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37634 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37635 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37636
37637 if (rlen)
37638 - if (copy_to_user(data, &resp, rlen))
37639 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37640 return -EFAULT;
37641
37642 return 0;
37643 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37644 index 5d89c0f..9261317 100644
37645 --- a/drivers/staging/usbip/usbip_common.h
37646 +++ b/drivers/staging/usbip/usbip_common.h
37647 @@ -289,7 +289,7 @@ struct usbip_device {
37648 void (*shutdown)(struct usbip_device *);
37649 void (*reset)(struct usbip_device *);
37650 void (*unusable)(struct usbip_device *);
37651 - } eh_ops;
37652 + } __no_const eh_ops;
37653 };
37654
37655 #define kthread_get_run(threadfn, data, namefmt, ...) \
37656 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37657 index c66b8b3..a4a035b 100644
37658 --- a/drivers/staging/usbip/vhci.h
37659 +++ b/drivers/staging/usbip/vhci.h
37660 @@ -83,7 +83,7 @@ struct vhci_hcd {
37661 unsigned resuming:1;
37662 unsigned long re_timeout;
37663
37664 - atomic_t seqnum;
37665 + atomic_unchecked_t seqnum;
37666
37667 /*
37668 * NOTE:
37669 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37670 index 12a9a5f..afd8295 100644
37671 --- a/drivers/staging/usbip/vhci_hcd.c
37672 +++ b/drivers/staging/usbip/vhci_hcd.c
37673 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37674 return;
37675 }
37676
37677 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37678 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37679 if (priv->seqnum == 0xffff)
37680 dev_info(&urb->dev->dev, "seqnum max\n");
37681
37682 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37683 return -ENOMEM;
37684 }
37685
37686 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37687 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37688 if (unlink->seqnum == 0xffff)
37689 pr_info("seqnum max\n");
37690
37691 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37692 vdev->rhport = rhport;
37693 }
37694
37695 - atomic_set(&vhci->seqnum, 0);
37696 + atomic_set_unchecked(&vhci->seqnum, 0);
37697 spin_lock_init(&vhci->lock);
37698
37699 hcd->power_budget = 0; /* no limit */
37700 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37701 index f0eaf04..5a82e06 100644
37702 --- a/drivers/staging/usbip/vhci_rx.c
37703 +++ b/drivers/staging/usbip/vhci_rx.c
37704 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37705 if (!urb) {
37706 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37707 pr_info("max seqnum %d\n",
37708 - atomic_read(&the_controller->seqnum));
37709 + atomic_read_unchecked(&the_controller->seqnum));
37710 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37711 return;
37712 }
37713 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37714 index 6ac6f45..1b208ba 100644
37715 --- a/drivers/staging/vt6655/hostap.c
37716 +++ b/drivers/staging/vt6655/hostap.c
37717 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37718 *
37719 */
37720
37721 +static net_device_ops_no_const apdev_netdev_ops;
37722 +
37723 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37724 {
37725 PSDevice apdev_priv;
37726 struct net_device *dev = pDevice->dev;
37727 int ret;
37728 - const struct net_device_ops apdev_netdev_ops = {
37729 - .ndo_start_xmit = pDevice->tx_80211,
37730 - };
37731
37732 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37733
37734 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37735 *apdev_priv = *pDevice;
37736 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37737
37738 + /* only half broken now */
37739 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37740 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37741
37742 pDevice->apdev->type = ARPHRD_IEEE80211;
37743 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37744 index 682002a..35ed5cf 100644
37745 --- a/drivers/staging/vt6656/hostap.c
37746 +++ b/drivers/staging/vt6656/hostap.c
37747 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37748 *
37749 */
37750
37751 +static net_device_ops_no_const apdev_netdev_ops;
37752 +
37753 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37754 {
37755 PSDevice apdev_priv;
37756 struct net_device *dev = pDevice->dev;
37757 int ret;
37758 - const struct net_device_ops apdev_netdev_ops = {
37759 - .ndo_start_xmit = pDevice->tx_80211,
37760 - };
37761
37762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37763
37764 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37765 *apdev_priv = *pDevice;
37766 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37767
37768 + /* only half broken now */
37769 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37770 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37771
37772 pDevice->apdev->type = ARPHRD_IEEE80211;
37773 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37774 index 7843dfd..3db105f 100644
37775 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37776 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37777 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37778
37779 struct usbctlx_completor {
37780 int (*complete) (struct usbctlx_completor *);
37781 -};
37782 +} __no_const;
37783
37784 static int
37785 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37786 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37787 index eaa9021..43f023b 100644
37788 --- a/drivers/staging/zcache/tmem.c
37789 +++ b/drivers/staging/zcache/tmem.c
37790 @@ -39,7 +39,7 @@
37791 * A tmem host implementation must use this function to register callbacks
37792 * for memory allocation.
37793 */
37794 -static struct tmem_hostops tmem_hostops;
37795 +static tmem_hostops_no_const tmem_hostops;
37796
37797 static void tmem_objnode_tree_init(void);
37798
37799 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37800 * A tmem host implementation must use this function to register
37801 * callbacks for a page-accessible memory (PAM) implementation
37802 */
37803 -static struct tmem_pamops tmem_pamops;
37804 +static tmem_pamops_no_const tmem_pamops;
37805
37806 void tmem_register_pamops(struct tmem_pamops *m)
37807 {
37808 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37809 index 0d4aa82..f7832d4 100644
37810 --- a/drivers/staging/zcache/tmem.h
37811 +++ b/drivers/staging/zcache/tmem.h
37812 @@ -180,6 +180,7 @@ struct tmem_pamops {
37813 void (*new_obj)(struct tmem_obj *);
37814 int (*replace_in_obj)(void *, struct tmem_obj *);
37815 };
37816 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37817 extern void tmem_register_pamops(struct tmem_pamops *m);
37818
37819 /* memory allocation methods provided by the host implementation */
37820 @@ -189,6 +190,7 @@ struct tmem_hostops {
37821 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37822 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37823 };
37824 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37825 extern void tmem_register_hostops(struct tmem_hostops *m);
37826
37827 /* core tmem accessor functions */
37828 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37829 index 269f544..32def0d 100644
37830 --- a/drivers/target/target_core_transport.c
37831 +++ b/drivers/target/target_core_transport.c
37832 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37833 spin_lock_init(&dev->se_port_lock);
37834 spin_lock_init(&dev->se_tmr_lock);
37835 spin_lock_init(&dev->qf_cmd_lock);
37836 - atomic_set(&dev->dev_ordered_id, 0);
37837 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37838
37839 se_dev_set_default_attribs(dev, dev_limits);
37840
37841 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37842 * Used to determine when ORDERED commands should go from
37843 * Dormant to Active status.
37844 */
37845 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37846 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37847 smp_mb__after_atomic_inc();
37848 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37849 cmd->se_ordered_id, cmd->sam_task_attr,
37850 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37851 index e61cabd..7617d26 100644
37852 --- a/drivers/tty/cyclades.c
37853 +++ b/drivers/tty/cyclades.c
37854 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37855 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37856 info->port.count);
37857 #endif
37858 - info->port.count++;
37859 + atomic_inc(&info->port.count);
37860 #ifdef CY_DEBUG_COUNT
37861 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37862 - current->pid, info->port.count);
37863 + current->pid, atomic_read(&info->port.count));
37864 #endif
37865
37866 /*
37867 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37868 for (j = 0; j < cy_card[i].nports; j++) {
37869 info = &cy_card[i].ports[j];
37870
37871 - if (info->port.count) {
37872 + if (atomic_read(&info->port.count)) {
37873 /* XXX is the ldisc num worth this? */
37874 struct tty_struct *tty;
37875 struct tty_ldisc *ld;
37876 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37877 index 2d691eb..be02ebd 100644
37878 --- a/drivers/tty/hvc/hvc_console.c
37879 +++ b/drivers/tty/hvc/hvc_console.c
37880 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37881
37882 spin_lock_irqsave(&hp->port.lock, flags);
37883 /* Check and then increment for fast path open. */
37884 - if (hp->port.count++ > 0) {
37885 + if (atomic_inc_return(&hp->port.count) > 1) {
37886 spin_unlock_irqrestore(&hp->port.lock, flags);
37887 hvc_kick();
37888 return 0;
37889 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37890
37891 spin_lock_irqsave(&hp->port.lock, flags);
37892
37893 - if (--hp->port.count == 0) {
37894 + if (atomic_dec_return(&hp->port.count) == 0) {
37895 spin_unlock_irqrestore(&hp->port.lock, flags);
37896 /* We are done with the tty pointer now. */
37897 tty_port_tty_set(&hp->port, NULL);
37898 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37899 */
37900 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37901 } else {
37902 - if (hp->port.count < 0)
37903 + if (atomic_read(&hp->port.count) < 0)
37904 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37905 - hp->vtermno, hp->port.count);
37906 + hp->vtermno, atomic_read(&hp->port.count));
37907 spin_unlock_irqrestore(&hp->port.lock, flags);
37908 }
37909
37910 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37911 * open->hangup case this can be called after the final close so prevent
37912 * that from happening for now.
37913 */
37914 - if (hp->port.count <= 0) {
37915 + if (atomic_read(&hp->port.count) <= 0) {
37916 spin_unlock_irqrestore(&hp->port.lock, flags);
37917 return;
37918 }
37919
37920 - temp_open_count = hp->port.count;
37921 - hp->port.count = 0;
37922 + temp_open_count = atomic_read(&hp->port.count);
37923 + atomic_set(&hp->port.count, 0);
37924 spin_unlock_irqrestore(&hp->port.lock, flags);
37925 tty_port_tty_set(&hp->port, NULL);
37926
37927 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37928 return -EPIPE;
37929
37930 /* FIXME what's this (unprotected) check for? */
37931 - if (hp->port.count <= 0)
37932 + if (atomic_read(&hp->port.count) <= 0)
37933 return -EIO;
37934
37935 spin_lock_irqsave(&hp->lock, flags);
37936 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37937 index d56788c..12d8f85 100644
37938 --- a/drivers/tty/hvc/hvcs.c
37939 +++ b/drivers/tty/hvc/hvcs.c
37940 @@ -83,6 +83,7 @@
37941 #include <asm/hvcserver.h>
37942 #include <asm/uaccess.h>
37943 #include <asm/vio.h>
37944 +#include <asm/local.h>
37945
37946 /*
37947 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37948 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37949
37950 spin_lock_irqsave(&hvcsd->lock, flags);
37951
37952 - if (hvcsd->port.count > 0) {
37953 + if (atomic_read(&hvcsd->port.count) > 0) {
37954 spin_unlock_irqrestore(&hvcsd->lock, flags);
37955 printk(KERN_INFO "HVCS: vterm state unchanged. "
37956 "The hvcs device node is still in use.\n");
37957 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37958 if ((retval = hvcs_partner_connect(hvcsd)))
37959 goto error_release;
37960
37961 - hvcsd->port.count = 1;
37962 + atomic_set(&hvcsd->port.count, 1);
37963 hvcsd->port.tty = tty;
37964 tty->driver_data = hvcsd;
37965
37966 @@ -1168,7 +1169,7 @@ fast_open:
37967
37968 spin_lock_irqsave(&hvcsd->lock, flags);
37969 tty_port_get(&hvcsd->port);
37970 - hvcsd->port.count++;
37971 + atomic_inc(&hvcsd->port.count);
37972 hvcsd->todo_mask |= HVCS_SCHED_READ;
37973 spin_unlock_irqrestore(&hvcsd->lock, flags);
37974
37975 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37976 hvcsd = tty->driver_data;
37977
37978 spin_lock_irqsave(&hvcsd->lock, flags);
37979 - if (--hvcsd->port.count == 0) {
37980 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37981
37982 vio_disable_interrupts(hvcsd->vdev);
37983
37984 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37985 free_irq(irq, hvcsd);
37986 tty_port_put(&hvcsd->port);
37987 return;
37988 - } else if (hvcsd->port.count < 0) {
37989 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37990 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37991 " is missmanaged.\n",
37992 - hvcsd->vdev->unit_address, hvcsd->port.count);
37993 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37994 }
37995
37996 spin_unlock_irqrestore(&hvcsd->lock, flags);
37997 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37998
37999 spin_lock_irqsave(&hvcsd->lock, flags);
38000 /* Preserve this so that we know how many kref refs to put */
38001 - temp_open_count = hvcsd->port.count;
38002 + temp_open_count = atomic_read(&hvcsd->port.count);
38003
38004 /*
38005 * Don't kref put inside the spinlock because the destruction
38006 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38007 tty->driver_data = NULL;
38008 hvcsd->port.tty = NULL;
38009
38010 - hvcsd->port.count = 0;
38011 + atomic_set(&hvcsd->port.count, 0);
38012
38013 /* This will drop any buffered data on the floor which is OK in a hangup
38014 * scenario. */
38015 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38016 * the middle of a write operation? This is a crummy place to do this
38017 * but we want to keep it all in the spinlock.
38018 */
38019 - if (hvcsd->port.count <= 0) {
38020 + if (atomic_read(&hvcsd->port.count) <= 0) {
38021 spin_unlock_irqrestore(&hvcsd->lock, flags);
38022 return -ENODEV;
38023 }
38024 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38025 {
38026 struct hvcs_struct *hvcsd = tty->driver_data;
38027
38028 - if (!hvcsd || hvcsd->port.count <= 0)
38029 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38030 return 0;
38031
38032 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38033 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38034 index f8b5fa0..4ba9f89 100644
38035 --- a/drivers/tty/ipwireless/tty.c
38036 +++ b/drivers/tty/ipwireless/tty.c
38037 @@ -29,6 +29,7 @@
38038 #include <linux/tty_driver.h>
38039 #include <linux/tty_flip.h>
38040 #include <linux/uaccess.h>
38041 +#include <asm/local.h>
38042
38043 #include "tty.h"
38044 #include "network.h"
38045 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38046 mutex_unlock(&tty->ipw_tty_mutex);
38047 return -ENODEV;
38048 }
38049 - if (tty->port.count == 0)
38050 + if (atomic_read(&tty->port.count) == 0)
38051 tty->tx_bytes_queued = 0;
38052
38053 - tty->port.count++;
38054 + atomic_inc(&tty->port.count);
38055
38056 tty->port.tty = linux_tty;
38057 linux_tty->driver_data = tty;
38058 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38059
38060 static void do_ipw_close(struct ipw_tty *tty)
38061 {
38062 - tty->port.count--;
38063 -
38064 - if (tty->port.count == 0) {
38065 + if (atomic_dec_return(&tty->port.count) == 0) {
38066 struct tty_struct *linux_tty = tty->port.tty;
38067
38068 if (linux_tty != NULL) {
38069 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38070 return;
38071
38072 mutex_lock(&tty->ipw_tty_mutex);
38073 - if (tty->port.count == 0) {
38074 + if (atomic_read(&tty->port.count) == 0) {
38075 mutex_unlock(&tty->ipw_tty_mutex);
38076 return;
38077 }
38078 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38079 return;
38080 }
38081
38082 - if (!tty->port.count) {
38083 + if (!atomic_read(&tty->port.count)) {
38084 mutex_unlock(&tty->ipw_tty_mutex);
38085 return;
38086 }
38087 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38088 return -ENODEV;
38089
38090 mutex_lock(&tty->ipw_tty_mutex);
38091 - if (!tty->port.count) {
38092 + if (!atomic_read(&tty->port.count)) {
38093 mutex_unlock(&tty->ipw_tty_mutex);
38094 return -EINVAL;
38095 }
38096 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38097 if (!tty)
38098 return -ENODEV;
38099
38100 - if (!tty->port.count)
38101 + if (!atomic_read(&tty->port.count))
38102 return -EINVAL;
38103
38104 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38105 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38106 if (!tty)
38107 return 0;
38108
38109 - if (!tty->port.count)
38110 + if (!atomic_read(&tty->port.count))
38111 return 0;
38112
38113 return tty->tx_bytes_queued;
38114 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38115 if (!tty)
38116 return -ENODEV;
38117
38118 - if (!tty->port.count)
38119 + if (!atomic_read(&tty->port.count))
38120 return -EINVAL;
38121
38122 return get_control_lines(tty);
38123 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38124 if (!tty)
38125 return -ENODEV;
38126
38127 - if (!tty->port.count)
38128 + if (!atomic_read(&tty->port.count))
38129 return -EINVAL;
38130
38131 return set_control_lines(tty, set, clear);
38132 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38133 if (!tty)
38134 return -ENODEV;
38135
38136 - if (!tty->port.count)
38137 + if (!atomic_read(&tty->port.count))
38138 return -EINVAL;
38139
38140 /* FIXME: Exactly how is the tty object locked here .. */
38141 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38142 * are gone */
38143 mutex_lock(&ttyj->ipw_tty_mutex);
38144 }
38145 - while (ttyj->port.count)
38146 + while (atomic_read(&ttyj->port.count))
38147 do_ipw_close(ttyj);
38148 ipwireless_disassociate_network_ttys(network,
38149 ttyj->channel_idx);
38150 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38151 index 324467d..504cc25 100644
38152 --- a/drivers/tty/moxa.c
38153 +++ b/drivers/tty/moxa.c
38154 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38155 }
38156
38157 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38158 - ch->port.count++;
38159 + atomic_inc(&ch->port.count);
38160 tty->driver_data = ch;
38161 tty_port_tty_set(&ch->port, tty);
38162 mutex_lock(&ch->port.mutex);
38163 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38164 index 90dff82..08119c3 100644
38165 --- a/drivers/tty/n_gsm.c
38166 +++ b/drivers/tty/n_gsm.c
38167 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38168 kref_init(&dlci->ref);
38169 mutex_init(&dlci->mutex);
38170 dlci->fifo = &dlci->_fifo;
38171 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38172 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38173 kfree(dlci);
38174 return NULL;
38175 }
38176 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38177 if (dlci == NULL)
38178 return -ENOMEM;
38179 port = &dlci->port;
38180 - port->count++;
38181 + atomic_inc(&port->count);
38182 tty->driver_data = dlci;
38183 dlci_get(dlci);
38184 dlci_get(dlci->gsm->dlci[0]);
38185 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38186 index 26f0d0e..b7c4273 100644
38187 --- a/drivers/tty/n_tty.c
38188 +++ b/drivers/tty/n_tty.c
38189 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38190 {
38191 *ops = tty_ldisc_N_TTY;
38192 ops->owner = NULL;
38193 - ops->refcount = ops->flags = 0;
38194 + atomic_set(&ops->refcount, 0);
38195 + ops->flags = 0;
38196 }
38197 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38198 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38199 index 5505ffc..7affff9 100644
38200 --- a/drivers/tty/pty.c
38201 +++ b/drivers/tty/pty.c
38202 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38203 panic("Couldn't register Unix98 pts driver");
38204
38205 /* Now create the /dev/ptmx special device */
38206 + pax_open_kernel();
38207 tty_default_fops(&ptmx_fops);
38208 - ptmx_fops.open = ptmx_open;
38209 + *(void **)&ptmx_fops.open = ptmx_open;
38210 + pax_close_kernel();
38211
38212 cdev_init(&ptmx_cdev, &ptmx_fops);
38213 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38214 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38215 index 777d5f9..56d67ca 100644
38216 --- a/drivers/tty/rocket.c
38217 +++ b/drivers/tty/rocket.c
38218 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38219 tty->driver_data = info;
38220 tty_port_tty_set(port, tty);
38221
38222 - if (port->count++ == 0) {
38223 + if (atomic_inc_return(&port->count) == 1) {
38224 atomic_inc(&rp_num_ports_open);
38225
38226 #ifdef ROCKET_DEBUG_OPEN
38227 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38228 #endif
38229 }
38230 #ifdef ROCKET_DEBUG_OPEN
38231 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38232 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38233 #endif
38234
38235 /*
38236 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38237 spin_unlock_irqrestore(&info->port.lock, flags);
38238 return;
38239 }
38240 - if (info->port.count)
38241 + if (atomic_read(&info->port.count))
38242 atomic_dec(&rp_num_ports_open);
38243 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38244 spin_unlock_irqrestore(&info->port.lock, flags);
38245 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38246 index 2b42a01..32a2ed3 100644
38247 --- a/drivers/tty/serial/kgdboc.c
38248 +++ b/drivers/tty/serial/kgdboc.c
38249 @@ -24,8 +24,9 @@
38250 #define MAX_CONFIG_LEN 40
38251
38252 static struct kgdb_io kgdboc_io_ops;
38253 +static struct kgdb_io kgdboc_io_ops_console;
38254
38255 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38256 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38257 static int configured = -1;
38258
38259 static char config[MAX_CONFIG_LEN];
38260 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38261 kgdboc_unregister_kbd();
38262 if (configured == 1)
38263 kgdb_unregister_io_module(&kgdboc_io_ops);
38264 + else if (configured == 2)
38265 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38266 }
38267
38268 static int configure_kgdboc(void)
38269 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38270 int err;
38271 char *cptr = config;
38272 struct console *cons;
38273 + int is_console = 0;
38274
38275 err = kgdboc_option_setup(config);
38276 if (err || !strlen(config) || isspace(config[0]))
38277 goto noconfig;
38278
38279 err = -ENODEV;
38280 - kgdboc_io_ops.is_console = 0;
38281 kgdb_tty_driver = NULL;
38282
38283 kgdboc_use_kms = 0;
38284 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38285 int idx;
38286 if (cons->device && cons->device(cons, &idx) == p &&
38287 idx == tty_line) {
38288 - kgdboc_io_ops.is_console = 1;
38289 + is_console = 1;
38290 break;
38291 }
38292 cons = cons->next;
38293 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38294 kgdb_tty_line = tty_line;
38295
38296 do_register:
38297 - err = kgdb_register_io_module(&kgdboc_io_ops);
38298 + if (is_console) {
38299 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38300 + configured = 2;
38301 + } else {
38302 + err = kgdb_register_io_module(&kgdboc_io_ops);
38303 + configured = 1;
38304 + }
38305 if (err)
38306 goto noconfig;
38307
38308 - configured = 1;
38309 -
38310 return 0;
38311
38312 noconfig:
38313 @@ -213,7 +220,7 @@ noconfig:
38314 static int __init init_kgdboc(void)
38315 {
38316 /* Already configured? */
38317 - if (configured == 1)
38318 + if (configured >= 1)
38319 return 0;
38320
38321 return configure_kgdboc();
38322 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38323 if (config[len - 1] == '\n')
38324 config[len - 1] = '\0';
38325
38326 - if (configured == 1)
38327 + if (configured >= 1)
38328 cleanup_kgdboc();
38329
38330 /* Go and configure with the new params. */
38331 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38332 .post_exception = kgdboc_post_exp_handler,
38333 };
38334
38335 +static struct kgdb_io kgdboc_io_ops_console = {
38336 + .name = "kgdboc",
38337 + .read_char = kgdboc_get_char,
38338 + .write_char = kgdboc_put_char,
38339 + .pre_exception = kgdboc_pre_exp_handler,
38340 + .post_exception = kgdboc_post_exp_handler,
38341 + .is_console = 1
38342 +};
38343 +
38344 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38345 /* This is only available if kgdboc is a built in for early debugging */
38346 static int __init kgdboc_early_init(char *opt)
38347 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38348 index a21dc8e..fe43e9e 100644
38349 --- a/drivers/tty/serial/serial_core.c
38350 +++ b/drivers/tty/serial/serial_core.c
38351 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38352 uart_flush_buffer(tty);
38353 uart_shutdown(tty, state);
38354 spin_lock_irqsave(&port->lock, flags);
38355 - port->count = 0;
38356 + atomic_set(&port->count, 0);
38357 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38358 spin_unlock_irqrestore(&port->lock, flags);
38359 tty_port_tty_set(port, NULL);
38360 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38361 goto end;
38362 }
38363
38364 - port->count++;
38365 + atomic_inc(&port->count);
38366 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38367 retval = -ENXIO;
38368 goto err_dec_count;
38369 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38370 /*
38371 * Make sure the device is in D0 state.
38372 */
38373 - if (port->count == 1)
38374 + if (atomic_read(&port->count) == 1)
38375 uart_change_pm(state, 0);
38376
38377 /*
38378 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38379 end:
38380 return retval;
38381 err_dec_count:
38382 - port->count--;
38383 + atomic_inc(&port->count);
38384 mutex_unlock(&port->mutex);
38385 goto end;
38386 }
38387 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38388 index 593d40a..bdc61f3 100644
38389 --- a/drivers/tty/synclink.c
38390 +++ b/drivers/tty/synclink.c
38391 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38392
38393 if (debug_level >= DEBUG_LEVEL_INFO)
38394 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38395 - __FILE__,__LINE__, info->device_name, info->port.count);
38396 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38397
38398 if (tty_port_close_start(&info->port, tty, filp) == 0)
38399 goto cleanup;
38400 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38401 cleanup:
38402 if (debug_level >= DEBUG_LEVEL_INFO)
38403 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38404 - tty->driver->name, info->port.count);
38405 + tty->driver->name, atomic_read(&info->port.count));
38406
38407 } /* end of mgsl_close() */
38408
38409 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38410
38411 mgsl_flush_buffer(tty);
38412 shutdown(info);
38413 -
38414 - info->port.count = 0;
38415 +
38416 + atomic_set(&info->port.count, 0);
38417 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38418 info->port.tty = NULL;
38419
38420 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38421
38422 if (debug_level >= DEBUG_LEVEL_INFO)
38423 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38424 - __FILE__,__LINE__, tty->driver->name, port->count );
38425 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38426
38427 spin_lock_irqsave(&info->irq_spinlock, flags);
38428 if (!tty_hung_up_p(filp)) {
38429 extra_count = true;
38430 - port->count--;
38431 + atomic_dec(&port->count);
38432 }
38433 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38434 port->blocked_open++;
38435 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38436
38437 if (debug_level >= DEBUG_LEVEL_INFO)
38438 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38439 - __FILE__,__LINE__, tty->driver->name, port->count );
38440 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38441
38442 tty_unlock();
38443 schedule();
38444 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38445
38446 /* FIXME: Racy on hangup during close wait */
38447 if (extra_count)
38448 - port->count++;
38449 + atomic_inc(&port->count);
38450 port->blocked_open--;
38451
38452 if (debug_level >= DEBUG_LEVEL_INFO)
38453 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38454 - __FILE__,__LINE__, tty->driver->name, port->count );
38455 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38456
38457 if (!retval)
38458 port->flags |= ASYNC_NORMAL_ACTIVE;
38459 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38460
38461 if (debug_level >= DEBUG_LEVEL_INFO)
38462 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38463 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38464 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38465
38466 /* If port is closing, signal caller to try again */
38467 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38468 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38469 spin_unlock_irqrestore(&info->netlock, flags);
38470 goto cleanup;
38471 }
38472 - info->port.count++;
38473 + atomic_inc(&info->port.count);
38474 spin_unlock_irqrestore(&info->netlock, flags);
38475
38476 - if (info->port.count == 1) {
38477 + if (atomic_read(&info->port.count) == 1) {
38478 /* 1st open on this device, init hardware */
38479 retval = startup(info);
38480 if (retval < 0)
38481 @@ -3444,8 +3444,8 @@ cleanup:
38482 if (retval) {
38483 if (tty->count == 1)
38484 info->port.tty = NULL; /* tty layer will release tty struct */
38485 - if(info->port.count)
38486 - info->port.count--;
38487 + if (atomic_read(&info->port.count))
38488 + atomic_dec(&info->port.count);
38489 }
38490
38491 return retval;
38492 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38493 unsigned short new_crctype;
38494
38495 /* return error if TTY interface open */
38496 - if (info->port.count)
38497 + if (atomic_read(&info->port.count))
38498 return -EBUSY;
38499
38500 switch (encoding)
38501 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38502
38503 /* arbitrate between network and tty opens */
38504 spin_lock_irqsave(&info->netlock, flags);
38505 - if (info->port.count != 0 || info->netcount != 0) {
38506 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38507 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38508 spin_unlock_irqrestore(&info->netlock, flags);
38509 return -EBUSY;
38510 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38511 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38512
38513 /* return error if TTY interface open */
38514 - if (info->port.count)
38515 + if (atomic_read(&info->port.count))
38516 return -EBUSY;
38517
38518 if (cmd != SIOCWANDEV)
38519 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38520 index aa1debf..9297a16 100644
38521 --- a/drivers/tty/synclink_gt.c
38522 +++ b/drivers/tty/synclink_gt.c
38523 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38524 tty->driver_data = info;
38525 info->port.tty = tty;
38526
38527 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38528 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38529
38530 /* If port is closing, signal caller to try again */
38531 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38532 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38533 mutex_unlock(&info->port.mutex);
38534 goto cleanup;
38535 }
38536 - info->port.count++;
38537 + atomic_inc(&info->port.count);
38538 spin_unlock_irqrestore(&info->netlock, flags);
38539
38540 - if (info->port.count == 1) {
38541 + if (atomic_read(&info->port.count) == 1) {
38542 /* 1st open on this device, init hardware */
38543 retval = startup(info);
38544 if (retval < 0) {
38545 @@ -716,8 +716,8 @@ cleanup:
38546 if (retval) {
38547 if (tty->count == 1)
38548 info->port.tty = NULL; /* tty layer will release tty struct */
38549 - if(info->port.count)
38550 - info->port.count--;
38551 + if(atomic_read(&info->port.count))
38552 + atomic_dec(&info->port.count);
38553 }
38554
38555 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38556 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38557
38558 if (sanity_check(info, tty->name, "close"))
38559 return;
38560 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38561 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38562
38563 if (tty_port_close_start(&info->port, tty, filp) == 0)
38564 goto cleanup;
38565 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38566 tty_port_close_end(&info->port, tty);
38567 info->port.tty = NULL;
38568 cleanup:
38569 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38570 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38571 }
38572
38573 static void hangup(struct tty_struct *tty)
38574 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38575 shutdown(info);
38576
38577 spin_lock_irqsave(&info->port.lock, flags);
38578 - info->port.count = 0;
38579 + atomic_set(&info->port.count, 0);
38580 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38581 info->port.tty = NULL;
38582 spin_unlock_irqrestore(&info->port.lock, flags);
38583 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38584 unsigned short new_crctype;
38585
38586 /* return error if TTY interface open */
38587 - if (info->port.count)
38588 + if (atomic_read(&info->port.count))
38589 return -EBUSY;
38590
38591 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38592 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38593
38594 /* arbitrate between network and tty opens */
38595 spin_lock_irqsave(&info->netlock, flags);
38596 - if (info->port.count != 0 || info->netcount != 0) {
38597 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38598 DBGINFO(("%s hdlc_open busy\n", dev->name));
38599 spin_unlock_irqrestore(&info->netlock, flags);
38600 return -EBUSY;
38601 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38602 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38603
38604 /* return error if TTY interface open */
38605 - if (info->port.count)
38606 + if (atomic_read(&info->port.count))
38607 return -EBUSY;
38608
38609 if (cmd != SIOCWANDEV)
38610 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38611 if (port == NULL)
38612 continue;
38613 spin_lock(&port->lock);
38614 - if ((port->port.count || port->netcount) &&
38615 + if ((atomic_read(&port->port.count) || port->netcount) &&
38616 port->pending_bh && !port->bh_running &&
38617 !port->bh_requested) {
38618 DBGISR(("%s bh queued\n", port->device_name));
38619 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38620 spin_lock_irqsave(&info->lock, flags);
38621 if (!tty_hung_up_p(filp)) {
38622 extra_count = true;
38623 - port->count--;
38624 + atomic_dec(&port->count);
38625 }
38626 spin_unlock_irqrestore(&info->lock, flags);
38627 port->blocked_open++;
38628 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38629 remove_wait_queue(&port->open_wait, &wait);
38630
38631 if (extra_count)
38632 - port->count++;
38633 + atomic_inc(&port->count);
38634 port->blocked_open--;
38635
38636 if (!retval)
38637 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38638 index a3dddc1..8905ab2 100644
38639 --- a/drivers/tty/synclinkmp.c
38640 +++ b/drivers/tty/synclinkmp.c
38641 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38642
38643 if (debug_level >= DEBUG_LEVEL_INFO)
38644 printk("%s(%d):%s open(), old ref count = %d\n",
38645 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38646 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38647
38648 /* If port is closing, signal caller to try again */
38649 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38650 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38651 spin_unlock_irqrestore(&info->netlock, flags);
38652 goto cleanup;
38653 }
38654 - info->port.count++;
38655 + atomic_inc(&info->port.count);
38656 spin_unlock_irqrestore(&info->netlock, flags);
38657
38658 - if (info->port.count == 1) {
38659 + if (atomic_read(&info->port.count) == 1) {
38660 /* 1st open on this device, init hardware */
38661 retval = startup(info);
38662 if (retval < 0)
38663 @@ -788,8 +788,8 @@ cleanup:
38664 if (retval) {
38665 if (tty->count == 1)
38666 info->port.tty = NULL; /* tty layer will release tty struct */
38667 - if(info->port.count)
38668 - info->port.count--;
38669 + if(atomic_read(&info->port.count))
38670 + atomic_dec(&info->port.count);
38671 }
38672
38673 return retval;
38674 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38675
38676 if (debug_level >= DEBUG_LEVEL_INFO)
38677 printk("%s(%d):%s close() entry, count=%d\n",
38678 - __FILE__,__LINE__, info->device_name, info->port.count);
38679 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38680
38681 if (tty_port_close_start(&info->port, tty, filp) == 0)
38682 goto cleanup;
38683 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38684 cleanup:
38685 if (debug_level >= DEBUG_LEVEL_INFO)
38686 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38687 - tty->driver->name, info->port.count);
38688 + tty->driver->name, atomic_read(&info->port.count));
38689 }
38690
38691 /* Called by tty_hangup() when a hangup is signaled.
38692 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38693 shutdown(info);
38694
38695 spin_lock_irqsave(&info->port.lock, flags);
38696 - info->port.count = 0;
38697 + atomic_set(&info->port.count, 0);
38698 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38699 info->port.tty = NULL;
38700 spin_unlock_irqrestore(&info->port.lock, flags);
38701 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38702 unsigned short new_crctype;
38703
38704 /* return error if TTY interface open */
38705 - if (info->port.count)
38706 + if (atomic_read(&info->port.count))
38707 return -EBUSY;
38708
38709 switch (encoding)
38710 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38711
38712 /* arbitrate between network and tty opens */
38713 spin_lock_irqsave(&info->netlock, flags);
38714 - if (info->port.count != 0 || info->netcount != 0) {
38715 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38716 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38717 spin_unlock_irqrestore(&info->netlock, flags);
38718 return -EBUSY;
38719 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38720 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38721
38722 /* return error if TTY interface open */
38723 - if (info->port.count)
38724 + if (atomic_read(&info->port.count))
38725 return -EBUSY;
38726
38727 if (cmd != SIOCWANDEV)
38728 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38729 * do not request bottom half processing if the
38730 * device is not open in a normal mode.
38731 */
38732 - if ( port && (port->port.count || port->netcount) &&
38733 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38734 port->pending_bh && !port->bh_running &&
38735 !port->bh_requested ) {
38736 if ( debug_level >= DEBUG_LEVEL_ISR )
38737 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38738
38739 if (debug_level >= DEBUG_LEVEL_INFO)
38740 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38741 - __FILE__,__LINE__, tty->driver->name, port->count );
38742 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38743
38744 spin_lock_irqsave(&info->lock, flags);
38745 if (!tty_hung_up_p(filp)) {
38746 extra_count = true;
38747 - port->count--;
38748 + atomic_dec(&port->count);
38749 }
38750 spin_unlock_irqrestore(&info->lock, flags);
38751 port->blocked_open++;
38752 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38753
38754 if (debug_level >= DEBUG_LEVEL_INFO)
38755 printk("%s(%d):%s block_til_ready() count=%d\n",
38756 - __FILE__,__LINE__, tty->driver->name, port->count );
38757 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38758
38759 tty_unlock();
38760 schedule();
38761 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38762 remove_wait_queue(&port->open_wait, &wait);
38763
38764 if (extra_count)
38765 - port->count++;
38766 + atomic_inc(&port->count);
38767 port->blocked_open--;
38768
38769 if (debug_level >= DEBUG_LEVEL_INFO)
38770 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38771 - __FILE__,__LINE__, tty->driver->name, port->count );
38772 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38773
38774 if (!retval)
38775 port->flags |= ASYNC_NORMAL_ACTIVE;
38776 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38777 index 05728894..b9d44c6 100644
38778 --- a/drivers/tty/sysrq.c
38779 +++ b/drivers/tty/sysrq.c
38780 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38781 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38782 size_t count, loff_t *ppos)
38783 {
38784 - if (count) {
38785 + if (count && capable(CAP_SYS_ADMIN)) {
38786 char c;
38787
38788 if (get_user(c, buf))
38789 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38790 index b425c79..08a3f06 100644
38791 --- a/drivers/tty/tty_io.c
38792 +++ b/drivers/tty/tty_io.c
38793 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38794
38795 void tty_default_fops(struct file_operations *fops)
38796 {
38797 - *fops = tty_fops;
38798 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38799 }
38800
38801 /*
38802 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38803 index 6f99c99..8947bc4 100644
38804 --- a/drivers/tty/tty_ldisc.c
38805 +++ b/drivers/tty/tty_ldisc.c
38806 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38807 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38808 struct tty_ldisc_ops *ldo = ld->ops;
38809
38810 - ldo->refcount--;
38811 + atomic_dec(&ldo->refcount);
38812 module_put(ldo->owner);
38813 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38814
38815 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38816 spin_lock_irqsave(&tty_ldisc_lock, flags);
38817 tty_ldiscs[disc] = new_ldisc;
38818 new_ldisc->num = disc;
38819 - new_ldisc->refcount = 0;
38820 + atomic_set(&new_ldisc->refcount, 0);
38821 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38822
38823 return ret;
38824 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38825 return -EINVAL;
38826
38827 spin_lock_irqsave(&tty_ldisc_lock, flags);
38828 - if (tty_ldiscs[disc]->refcount)
38829 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38830 ret = -EBUSY;
38831 else
38832 tty_ldiscs[disc] = NULL;
38833 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38834 if (ldops) {
38835 ret = ERR_PTR(-EAGAIN);
38836 if (try_module_get(ldops->owner)) {
38837 - ldops->refcount++;
38838 + atomic_inc(&ldops->refcount);
38839 ret = ldops;
38840 }
38841 }
38842 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38843 unsigned long flags;
38844
38845 spin_lock_irqsave(&tty_ldisc_lock, flags);
38846 - ldops->refcount--;
38847 + atomic_dec(&ldops->refcount);
38848 module_put(ldops->owner);
38849 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38850 }
38851 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38852 index bf6e238..d401c04 100644
38853 --- a/drivers/tty/tty_port.c
38854 +++ b/drivers/tty/tty_port.c
38855 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38856 unsigned long flags;
38857
38858 spin_lock_irqsave(&port->lock, flags);
38859 - port->count = 0;
38860 + atomic_set(&port->count, 0);
38861 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38862 if (port->tty) {
38863 set_bit(TTY_IO_ERROR, &port->tty->flags);
38864 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38865 /* The port lock protects the port counts */
38866 spin_lock_irqsave(&port->lock, flags);
38867 if (!tty_hung_up_p(filp))
38868 - port->count--;
38869 + atomic_dec(&port->count);
38870 port->blocked_open++;
38871 spin_unlock_irqrestore(&port->lock, flags);
38872
38873 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38874 we must not mess that up further */
38875 spin_lock_irqsave(&port->lock, flags);
38876 if (!tty_hung_up_p(filp))
38877 - port->count++;
38878 + atomic_inc(&port->count);
38879 port->blocked_open--;
38880 if (retval == 0)
38881 port->flags |= ASYNC_NORMAL_ACTIVE;
38882 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38883 return 0;
38884 }
38885
38886 - if (tty->count == 1 && port->count != 1) {
38887 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38888 printk(KERN_WARNING
38889 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38890 - port->count);
38891 - port->count = 1;
38892 + atomic_read(&port->count));
38893 + atomic_set(&port->count, 1);
38894 }
38895 - if (--port->count < 0) {
38896 + if (atomic_dec_return(&port->count) < 0) {
38897 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38898 - port->count);
38899 - port->count = 0;
38900 + atomic_read(&port->count));
38901 + atomic_set(&port->count, 0);
38902 }
38903
38904 - if (port->count) {
38905 + if (atomic_read(&port->count)) {
38906 spin_unlock_irqrestore(&port->lock, flags);
38907 if (port->ops->drop)
38908 port->ops->drop(port);
38909 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38910 {
38911 spin_lock_irq(&port->lock);
38912 if (!tty_hung_up_p(filp))
38913 - ++port->count;
38914 + atomic_inc(&port->count);
38915 spin_unlock_irq(&port->lock);
38916 tty_port_tty_set(port, tty);
38917
38918 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38919 index 770a854..e5d3db3 100644
38920 --- a/drivers/tty/vt/keyboard.c
38921 +++ b/drivers/tty/vt/keyboard.c
38922 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38923 kbd->kbdmode == VC_OFF) &&
38924 value != KVAL(K_SAK))
38925 return; /* SAK is allowed even in raw mode */
38926 +
38927 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38928 + {
38929 + void *func = fn_handler[value];
38930 + if (func == fn_show_state || func == fn_show_ptregs ||
38931 + func == fn_show_mem)
38932 + return;
38933 + }
38934 +#endif
38935 +
38936 fn_handler[value](vc);
38937 }
38938
38939 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38940 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38941 return -EFAULT;
38942
38943 - if (!capable(CAP_SYS_TTY_CONFIG))
38944 - perm = 0;
38945 -
38946 switch (cmd) {
38947 case KDGKBENT:
38948 /* Ensure another thread doesn't free it under us */
38949 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38950 spin_unlock_irqrestore(&kbd_event_lock, flags);
38951 return put_user(val, &user_kbe->kb_value);
38952 case KDSKBENT:
38953 + if (!capable(CAP_SYS_TTY_CONFIG))
38954 + perm = 0;
38955 +
38956 if (!perm)
38957 return -EPERM;
38958 if (!i && v == K_NOSUCHMAP) {
38959 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38960 int i, j, k;
38961 int ret;
38962
38963 - if (!capable(CAP_SYS_TTY_CONFIG))
38964 - perm = 0;
38965 -
38966 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38967 if (!kbs) {
38968 ret = -ENOMEM;
38969 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38970 kfree(kbs);
38971 return ((p && *p) ? -EOVERFLOW : 0);
38972 case KDSKBSENT:
38973 + if (!capable(CAP_SYS_TTY_CONFIG))
38974 + perm = 0;
38975 +
38976 if (!perm) {
38977 ret = -EPERM;
38978 goto reterr;
38979 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38980 index a783d53..cb30d94 100644
38981 --- a/drivers/uio/uio.c
38982 +++ b/drivers/uio/uio.c
38983 @@ -25,6 +25,7 @@
38984 #include <linux/kobject.h>
38985 #include <linux/cdev.h>
38986 #include <linux/uio_driver.h>
38987 +#include <asm/local.h>
38988
38989 #define UIO_MAX_DEVICES (1U << MINORBITS)
38990
38991 @@ -32,10 +33,10 @@ struct uio_device {
38992 struct module *owner;
38993 struct device *dev;
38994 int minor;
38995 - atomic_t event;
38996 + atomic_unchecked_t event;
38997 struct fasync_struct *async_queue;
38998 wait_queue_head_t wait;
38999 - int vma_count;
39000 + local_t vma_count;
39001 struct uio_info *info;
39002 struct kobject *map_dir;
39003 struct kobject *portio_dir;
39004 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39005 struct device_attribute *attr, char *buf)
39006 {
39007 struct uio_device *idev = dev_get_drvdata(dev);
39008 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39009 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39010 }
39011
39012 static struct device_attribute uio_class_attributes[] = {
39013 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39014 {
39015 struct uio_device *idev = info->uio_dev;
39016
39017 - atomic_inc(&idev->event);
39018 + atomic_inc_unchecked(&idev->event);
39019 wake_up_interruptible(&idev->wait);
39020 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39021 }
39022 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39023 }
39024
39025 listener->dev = idev;
39026 - listener->event_count = atomic_read(&idev->event);
39027 + listener->event_count = atomic_read_unchecked(&idev->event);
39028 filep->private_data = listener;
39029
39030 if (idev->info->open) {
39031 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39032 return -EIO;
39033
39034 poll_wait(filep, &idev->wait, wait);
39035 - if (listener->event_count != atomic_read(&idev->event))
39036 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39037 return POLLIN | POLLRDNORM;
39038 return 0;
39039 }
39040 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39041 do {
39042 set_current_state(TASK_INTERRUPTIBLE);
39043
39044 - event_count = atomic_read(&idev->event);
39045 + event_count = atomic_read_unchecked(&idev->event);
39046 if (event_count != listener->event_count) {
39047 if (copy_to_user(buf, &event_count, count))
39048 retval = -EFAULT;
39049 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39050 static void uio_vma_open(struct vm_area_struct *vma)
39051 {
39052 struct uio_device *idev = vma->vm_private_data;
39053 - idev->vma_count++;
39054 + local_inc(&idev->vma_count);
39055 }
39056
39057 static void uio_vma_close(struct vm_area_struct *vma)
39058 {
39059 struct uio_device *idev = vma->vm_private_data;
39060 - idev->vma_count--;
39061 + local_dec(&idev->vma_count);
39062 }
39063
39064 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39065 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39066 idev->owner = owner;
39067 idev->info = info;
39068 init_waitqueue_head(&idev->wait);
39069 - atomic_set(&idev->event, 0);
39070 + atomic_set_unchecked(&idev->event, 0);
39071
39072 ret = uio_get_minor(idev);
39073 if (ret)
39074 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39075 index b7eb86a..36d28af 100644
39076 --- a/drivers/usb/atm/cxacru.c
39077 +++ b/drivers/usb/atm/cxacru.c
39078 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39079 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39080 if (ret < 2)
39081 return -EINVAL;
39082 - if (index < 0 || index > 0x7f)
39083 + if (index > 0x7f)
39084 return -EINVAL;
39085 pos += tmp;
39086
39087 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39088 index ee62b35..b663594 100644
39089 --- a/drivers/usb/atm/usbatm.c
39090 +++ b/drivers/usb/atm/usbatm.c
39091 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39092 if (printk_ratelimit())
39093 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39094 __func__, vpi, vci);
39095 - atomic_inc(&vcc->stats->rx_err);
39096 + atomic_inc_unchecked(&vcc->stats->rx_err);
39097 return;
39098 }
39099
39100 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39101 if (length > ATM_MAX_AAL5_PDU) {
39102 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39103 __func__, length, vcc);
39104 - atomic_inc(&vcc->stats->rx_err);
39105 + atomic_inc_unchecked(&vcc->stats->rx_err);
39106 goto out;
39107 }
39108
39109 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39110 if (sarb->len < pdu_length) {
39111 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39112 __func__, pdu_length, sarb->len, vcc);
39113 - atomic_inc(&vcc->stats->rx_err);
39114 + atomic_inc_unchecked(&vcc->stats->rx_err);
39115 goto out;
39116 }
39117
39118 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39119 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39120 __func__, vcc);
39121 - atomic_inc(&vcc->stats->rx_err);
39122 + atomic_inc_unchecked(&vcc->stats->rx_err);
39123 goto out;
39124 }
39125
39126 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39127 if (printk_ratelimit())
39128 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39129 __func__, length);
39130 - atomic_inc(&vcc->stats->rx_drop);
39131 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39132 goto out;
39133 }
39134
39135 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39136
39137 vcc->push(vcc, skb);
39138
39139 - atomic_inc(&vcc->stats->rx);
39140 + atomic_inc_unchecked(&vcc->stats->rx);
39141 out:
39142 skb_trim(sarb, 0);
39143 }
39144 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39145 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39146
39147 usbatm_pop(vcc, skb);
39148 - atomic_inc(&vcc->stats->tx);
39149 + atomic_inc_unchecked(&vcc->stats->tx);
39150
39151 skb = skb_dequeue(&instance->sndqueue);
39152 }
39153 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39154 if (!left--)
39155 return sprintf(page,
39156 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39157 - atomic_read(&atm_dev->stats.aal5.tx),
39158 - atomic_read(&atm_dev->stats.aal5.tx_err),
39159 - atomic_read(&atm_dev->stats.aal5.rx),
39160 - atomic_read(&atm_dev->stats.aal5.rx_err),
39161 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39162 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39163 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39164 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39165 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39166 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39167
39168 if (!left--) {
39169 if (instance->disconnected)
39170 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39171 index 3440812..2a4ef1f 100644
39172 --- a/drivers/usb/core/devices.c
39173 +++ b/drivers/usb/core/devices.c
39174 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39175 * time it gets called.
39176 */
39177 static struct device_connect_event {
39178 - atomic_t count;
39179 + atomic_unchecked_t count;
39180 wait_queue_head_t wait;
39181 } device_event = {
39182 .count = ATOMIC_INIT(1),
39183 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39184
39185 void usbfs_conn_disc_event(void)
39186 {
39187 - atomic_add(2, &device_event.count);
39188 + atomic_add_unchecked(2, &device_event.count);
39189 wake_up(&device_event.wait);
39190 }
39191
39192 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39193
39194 poll_wait(file, &device_event.wait, wait);
39195
39196 - event_count = atomic_read(&device_event.count);
39197 + event_count = atomic_read_unchecked(&device_event.count);
39198 if (file->f_version != event_count) {
39199 file->f_version = event_count;
39200 return POLLIN | POLLRDNORM;
39201 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39202 index 89dcf15..481800b 100644
39203 --- a/drivers/usb/early/ehci-dbgp.c
39204 +++ b/drivers/usb/early/ehci-dbgp.c
39205 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39206
39207 #ifdef CONFIG_KGDB
39208 static struct kgdb_io kgdbdbgp_io_ops;
39209 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39210 +static struct kgdb_io kgdbdbgp_io_ops_console;
39211 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39212 #else
39213 #define dbgp_kgdb_mode (0)
39214 #endif
39215 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39216 .write_char = kgdbdbgp_write_char,
39217 };
39218
39219 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39220 + .name = "kgdbdbgp",
39221 + .read_char = kgdbdbgp_read_char,
39222 + .write_char = kgdbdbgp_write_char,
39223 + .is_console = 1
39224 +};
39225 +
39226 static int kgdbdbgp_wait_time;
39227
39228 static int __init kgdbdbgp_parse_config(char *str)
39229 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39230 ptr++;
39231 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39232 }
39233 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39234 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39235 + if (early_dbgp_console.index != -1)
39236 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39237 + else
39238 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39239
39240 return 0;
39241 }
39242 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39243 index da6d479..80ed10b 100644
39244 --- a/drivers/usb/gadget/u_serial.c
39245 +++ b/drivers/usb/gadget/u_serial.c
39246 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39247 spin_lock_irq(&port->port_lock);
39248
39249 /* already open? Great. */
39250 - if (port->port.count) {
39251 + if (atomic_read(&port->port.count)) {
39252 status = 0;
39253 - port->port.count++;
39254 + atomic_inc(&port->port.count);
39255
39256 /* currently opening/closing? wait ... */
39257 } else if (port->openclose) {
39258 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39259 tty->driver_data = port;
39260 port->port.tty = tty;
39261
39262 - port->port.count = 1;
39263 + atomic_set(&port->port.count, 1);
39264 port->openclose = false;
39265
39266 /* if connected, start the I/O stream */
39267 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39268
39269 spin_lock_irq(&port->port_lock);
39270
39271 - if (port->port.count != 1) {
39272 - if (port->port.count == 0)
39273 + if (atomic_read(&port->port.count) != 1) {
39274 + if (atomic_read(&port->port.count) == 0)
39275 WARN_ON(1);
39276 else
39277 - --port->port.count;
39278 + atomic_dec(&port->port.count);
39279 goto exit;
39280 }
39281
39282 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39283 * and sleep if necessary
39284 */
39285 port->openclose = true;
39286 - port->port.count = 0;
39287 + atomic_set(&port->port.count, 0);
39288
39289 gser = port->port_usb;
39290 if (gser && gser->disconnect)
39291 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39292 int cond;
39293
39294 spin_lock_irq(&port->port_lock);
39295 - cond = (port->port.count == 0) && !port->openclose;
39296 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39297 spin_unlock_irq(&port->port_lock);
39298 return cond;
39299 }
39300 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39301 /* if it's already open, start I/O ... and notify the serial
39302 * protocol about open/close status (connect/disconnect).
39303 */
39304 - if (port->port.count) {
39305 + if (atomic_read(&port->port.count)) {
39306 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39307 gs_start_io(port);
39308 if (gser->connect)
39309 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39310
39311 port->port_usb = NULL;
39312 gser->ioport = NULL;
39313 - if (port->port.count > 0 || port->openclose) {
39314 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39315 wake_up_interruptible(&port->drain_wait);
39316 if (port->port.tty)
39317 tty_hangup(port->port.tty);
39318 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39319
39320 /* finally, free any unused/unusable I/O buffers */
39321 spin_lock_irqsave(&port->port_lock, flags);
39322 - if (port->port.count == 0 && !port->openclose)
39323 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39324 gs_buf_free(&port->port_write_buf);
39325 gs_free_requests(gser->out, &port->read_pool, NULL);
39326 gs_free_requests(gser->out, &port->read_queue, NULL);
39327 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39328 index b9cca6d..75c75df 100644
39329 --- a/drivers/usb/serial/console.c
39330 +++ b/drivers/usb/serial/console.c
39331 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39332
39333 info->port = port;
39334
39335 - ++port->port.count;
39336 + atomic_inc(&port->port.count);
39337 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39338 if (serial->type->set_termios) {
39339 /*
39340 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39341 }
39342 /* Now that any required fake tty operations are completed restore
39343 * the tty port count */
39344 - --port->port.count;
39345 + atomic_dec(&port->port.count);
39346 /* The console is special in terms of closing the device so
39347 * indicate this port is now acting as a system console. */
39348 port->port.console = 1;
39349 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39350 free_tty:
39351 kfree(tty);
39352 reset_open_count:
39353 - port->port.count = 0;
39354 + atomic_set(&port->port.count, 0);
39355 usb_autopm_put_interface(serial->interface);
39356 error_get_interface:
39357 usb_serial_put(serial);
39358 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39359 index d6bea3e..60b250e 100644
39360 --- a/drivers/usb/wusbcore/wa-hc.h
39361 +++ b/drivers/usb/wusbcore/wa-hc.h
39362 @@ -192,7 +192,7 @@ struct wahc {
39363 struct list_head xfer_delayed_list;
39364 spinlock_t xfer_list_lock;
39365 struct work_struct xfer_work;
39366 - atomic_t xfer_id_count;
39367 + atomic_unchecked_t xfer_id_count;
39368 };
39369
39370
39371 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39372 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39373 spin_lock_init(&wa->xfer_list_lock);
39374 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39375 - atomic_set(&wa->xfer_id_count, 1);
39376 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39377 }
39378
39379 /**
39380 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39381 index 57c01ab..8a05959 100644
39382 --- a/drivers/usb/wusbcore/wa-xfer.c
39383 +++ b/drivers/usb/wusbcore/wa-xfer.c
39384 @@ -296,7 +296,7 @@ out:
39385 */
39386 static void wa_xfer_id_init(struct wa_xfer *xfer)
39387 {
39388 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39389 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39390 }
39391
39392 /*
39393 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39394 index ef82a0d..da8a0b3 100644
39395 --- a/drivers/vhost/vhost.c
39396 +++ b/drivers/vhost/vhost.c
39397 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39398 return 0;
39399 }
39400
39401 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39402 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39403 {
39404 struct file *eventfp, *filep = NULL,
39405 *pollstart = NULL, *pollstop = NULL;
39406 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39407 index 747442d..7c0c434 100644
39408 --- a/drivers/video/aty/aty128fb.c
39409 +++ b/drivers/video/aty/aty128fb.c
39410 @@ -149,7 +149,7 @@ enum {
39411 };
39412
39413 /* Must match above enum */
39414 -static const char *r128_family[] __devinitdata = {
39415 +static const char *r128_family[] __devinitconst = {
39416 "AGP",
39417 "PCI",
39418 "PRO AGP",
39419 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39420 index 5c3960d..15cf8fc 100644
39421 --- a/drivers/video/fbcmap.c
39422 +++ b/drivers/video/fbcmap.c
39423 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39424 rc = -ENODEV;
39425 goto out;
39426 }
39427 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39428 - !info->fbops->fb_setcmap)) {
39429 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39430 rc = -EINVAL;
39431 goto out1;
39432 }
39433 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39434 index 0dff12a..2ef47b3 100644
39435 --- a/drivers/video/fbmem.c
39436 +++ b/drivers/video/fbmem.c
39437 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39438 image->dx += image->width + 8;
39439 }
39440 } else if (rotate == FB_ROTATE_UD) {
39441 - for (x = 0; x < num && image->dx >= 0; x++) {
39442 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39443 info->fbops->fb_imageblit(info, image);
39444 image->dx -= image->width + 8;
39445 }
39446 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39447 image->dy += image->height + 8;
39448 }
39449 } else if (rotate == FB_ROTATE_CCW) {
39450 - for (x = 0; x < num && image->dy >= 0; x++) {
39451 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39452 info->fbops->fb_imageblit(info, image);
39453 image->dy -= image->height + 8;
39454 }
39455 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39456 return -EFAULT;
39457 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39458 return -EINVAL;
39459 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39460 + if (con2fb.framebuffer >= FB_MAX)
39461 return -EINVAL;
39462 if (!registered_fb[con2fb.framebuffer])
39463 request_module("fb%d", con2fb.framebuffer);
39464 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39465 index 5a5d092..265c5ed 100644
39466 --- a/drivers/video/geode/gx1fb_core.c
39467 +++ b/drivers/video/geode/gx1fb_core.c
39468 @@ -29,7 +29,7 @@ static int crt_option = 1;
39469 static char panel_option[32] = "";
39470
39471 /* Modes relevant to the GX1 (taken from modedb.c) */
39472 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39473 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39474 /* 640x480-60 VESA */
39475 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39476 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39477 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39478 index 0fad23f..0e9afa4 100644
39479 --- a/drivers/video/gxt4500.c
39480 +++ b/drivers/video/gxt4500.c
39481 @@ -156,7 +156,7 @@ struct gxt4500_par {
39482 static char *mode_option;
39483
39484 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39485 -static const struct fb_videomode defaultmode __devinitdata = {
39486 +static const struct fb_videomode defaultmode __devinitconst = {
39487 .refresh = 60,
39488 .xres = 1280,
39489 .yres = 1024,
39490 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39491 return 0;
39492 }
39493
39494 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39495 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39496 .id = "IBM GXT4500P",
39497 .type = FB_TYPE_PACKED_PIXELS,
39498 .visual = FB_VISUAL_PSEUDOCOLOR,
39499 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39500 index 7672d2e..b56437f 100644
39501 --- a/drivers/video/i810/i810_accel.c
39502 +++ b/drivers/video/i810/i810_accel.c
39503 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39504 }
39505 }
39506 printk("ringbuffer lockup!!!\n");
39507 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39508 i810_report_error(mmio);
39509 par->dev_flags |= LOCKUP;
39510 info->pixmap.scan_align = 1;
39511 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39512 index b83f361..2b05a91 100644
39513 --- a/drivers/video/i810/i810_main.c
39514 +++ b/drivers/video/i810/i810_main.c
39515 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39516 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39517
39518 /* PCI */
39519 -static const char *i810_pci_list[] __devinitdata = {
39520 +static const char *i810_pci_list[] __devinitconst = {
39521 "Intel(R) 810 Framebuffer Device" ,
39522 "Intel(R) 810-DC100 Framebuffer Device" ,
39523 "Intel(R) 810E Framebuffer Device" ,
39524 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39525 index de36693..3c63fc2 100644
39526 --- a/drivers/video/jz4740_fb.c
39527 +++ b/drivers/video/jz4740_fb.c
39528 @@ -136,7 +136,7 @@ struct jzfb {
39529 uint32_t pseudo_palette[16];
39530 };
39531
39532 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39533 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39534 .id = "JZ4740 FB",
39535 .type = FB_TYPE_PACKED_PIXELS,
39536 .visual = FB_VISUAL_TRUECOLOR,
39537 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39538 index 3c14e43..eafa544 100644
39539 --- a/drivers/video/logo/logo_linux_clut224.ppm
39540 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39541 @@ -1,1604 +1,1123 @@
39542 P3
39543 -# Standard 224-color Linux logo
39544 80 80
39545 255
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 0 0 0
39555 - 6 6 6 6 6 6 10 10 10 10 10 10
39556 - 10 10 10 6 6 6 6 6 6 6 6 6
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 6 6 6 10 10 10 14 14 14
39575 - 22 22 22 26 26 26 30 30 30 34 34 34
39576 - 30 30 30 30 30 30 26 26 26 18 18 18
39577 - 14 14 14 10 10 10 6 6 6 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 0 0 0 0 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 1 0 0 1 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 6 6 6 14 14 14 26 26 26 42 42 42
39595 - 54 54 54 66 66 66 78 78 78 78 78 78
39596 - 78 78 78 74 74 74 66 66 66 54 54 54
39597 - 42 42 42 26 26 26 18 18 18 10 10 10
39598 - 6 6 6 0 0 0 0 0 0 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 1 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 10 10 10
39614 - 22 22 22 42 42 42 66 66 66 86 86 86
39615 - 66 66 66 38 38 38 38 38 38 22 22 22
39616 - 26 26 26 34 34 34 54 54 54 66 66 66
39617 - 86 86 86 70 70 70 46 46 46 26 26 26
39618 - 14 14 14 6 6 6 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 0 0 0 0 0 0 0 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 1 0 0 1 0 0 1 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 10 10 10 26 26 26
39634 - 50 50 50 82 82 82 58 58 58 6 6 6
39635 - 2 2 6 2 2 6 2 2 6 2 2 6
39636 - 2 2 6 2 2 6 2 2 6 2 2 6
39637 - 6 6 6 54 54 54 86 86 86 66 66 66
39638 - 38 38 38 18 18 18 6 6 6 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 6 6 6 22 22 22 50 50 50
39654 - 78 78 78 34 34 34 2 2 6 2 2 6
39655 - 2 2 6 2 2 6 2 2 6 2 2 6
39656 - 2 2 6 2 2 6 2 2 6 2 2 6
39657 - 2 2 6 2 2 6 6 6 6 70 70 70
39658 - 78 78 78 46 46 46 22 22 22 6 6 6
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 1 0 0 1 0 0 1 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 6 6 6 18 18 18 42 42 42 82 82 82
39674 - 26 26 26 2 2 6 2 2 6 2 2 6
39675 - 2 2 6 2 2 6 2 2 6 2 2 6
39676 - 2 2 6 2 2 6 2 2 6 14 14 14
39677 - 46 46 46 34 34 34 6 6 6 2 2 6
39678 - 42 42 42 78 78 78 42 42 42 18 18 18
39679 - 6 6 6 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 1 0 0 0 0 0 1 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 10 10 10 30 30 30 66 66 66 58 58 58
39694 - 2 2 6 2 2 6 2 2 6 2 2 6
39695 - 2 2 6 2 2 6 2 2 6 2 2 6
39696 - 2 2 6 2 2 6 2 2 6 26 26 26
39697 - 86 86 86 101 101 101 46 46 46 10 10 10
39698 - 2 2 6 58 58 58 70 70 70 34 34 34
39699 - 10 10 10 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 1 0 0 1 0 0 1 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 14 14 14 42 42 42 86 86 86 10 10 10
39714 - 2 2 6 2 2 6 2 2 6 2 2 6
39715 - 2 2 6 2 2 6 2 2 6 2 2 6
39716 - 2 2 6 2 2 6 2 2 6 30 30 30
39717 - 94 94 94 94 94 94 58 58 58 26 26 26
39718 - 2 2 6 6 6 6 78 78 78 54 54 54
39719 - 22 22 22 6 6 6 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 6 6 6
39733 - 22 22 22 62 62 62 62 62 62 2 2 6
39734 - 2 2 6 2 2 6 2 2 6 2 2 6
39735 - 2 2 6 2 2 6 2 2 6 2 2 6
39736 - 2 2 6 2 2 6 2 2 6 26 26 26
39737 - 54 54 54 38 38 38 18 18 18 10 10 10
39738 - 2 2 6 2 2 6 34 34 34 82 82 82
39739 - 38 38 38 14 14 14 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 1 0 0 1 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 6 6 6
39753 - 30 30 30 78 78 78 30 30 30 2 2 6
39754 - 2 2 6 2 2 6 2 2 6 2 2 6
39755 - 2 2 6 2 2 6 2 2 6 2 2 6
39756 - 2 2 6 2 2 6 2 2 6 10 10 10
39757 - 10 10 10 2 2 6 2 2 6 2 2 6
39758 - 2 2 6 2 2 6 2 2 6 78 78 78
39759 - 50 50 50 18 18 18 6 6 6 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 1 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 10 10 10
39773 - 38 38 38 86 86 86 14 14 14 2 2 6
39774 - 2 2 6 2 2 6 2 2 6 2 2 6
39775 - 2 2 6 2 2 6 2 2 6 2 2 6
39776 - 2 2 6 2 2 6 2 2 6 2 2 6
39777 - 2 2 6 2 2 6 2 2 6 2 2 6
39778 - 2 2 6 2 2 6 2 2 6 54 54 54
39779 - 66 66 66 26 26 26 6 6 6 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 1 0 0 1 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 14 14 14
39793 - 42 42 42 82 82 82 2 2 6 2 2 6
39794 - 2 2 6 6 6 6 10 10 10 2 2 6
39795 - 2 2 6 2 2 6 2 2 6 2 2 6
39796 - 2 2 6 2 2 6 2 2 6 6 6 6
39797 - 14 14 14 10 10 10 2 2 6 2 2 6
39798 - 2 2 6 2 2 6 2 2 6 18 18 18
39799 - 82 82 82 34 34 34 10 10 10 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 1 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 14 14 14
39813 - 46 46 46 86 86 86 2 2 6 2 2 6
39814 - 6 6 6 6 6 6 22 22 22 34 34 34
39815 - 6 6 6 2 2 6 2 2 6 2 2 6
39816 - 2 2 6 2 2 6 18 18 18 34 34 34
39817 - 10 10 10 50 50 50 22 22 22 2 2 6
39818 - 2 2 6 2 2 6 2 2 6 10 10 10
39819 - 86 86 86 42 42 42 14 14 14 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 1 0 0 1 0 0 1 0 0 0
39828 - 0 0 0 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 14 14 14
39833 - 46 46 46 86 86 86 2 2 6 2 2 6
39834 - 38 38 38 116 116 116 94 94 94 22 22 22
39835 - 22 22 22 2 2 6 2 2 6 2 2 6
39836 - 14 14 14 86 86 86 138 138 138 162 162 162
39837 -154 154 154 38 38 38 26 26 26 6 6 6
39838 - 2 2 6 2 2 6 2 2 6 2 2 6
39839 - 86 86 86 46 46 46 14 14 14 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 14 14 14
39853 - 46 46 46 86 86 86 2 2 6 14 14 14
39854 -134 134 134 198 198 198 195 195 195 116 116 116
39855 - 10 10 10 2 2 6 2 2 6 6 6 6
39856 -101 98 89 187 187 187 210 210 210 218 218 218
39857 -214 214 214 134 134 134 14 14 14 6 6 6
39858 - 2 2 6 2 2 6 2 2 6 2 2 6
39859 - 86 86 86 50 50 50 18 18 18 6 6 6
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 1 0 0 0
39867 - 0 0 1 0 0 1 0 0 1 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 14 14 14
39873 - 46 46 46 86 86 86 2 2 6 54 54 54
39874 -218 218 218 195 195 195 226 226 226 246 246 246
39875 - 58 58 58 2 2 6 2 2 6 30 30 30
39876 -210 210 210 253 253 253 174 174 174 123 123 123
39877 -221 221 221 234 234 234 74 74 74 2 2 6
39878 - 2 2 6 2 2 6 2 2 6 2 2 6
39879 - 70 70 70 58 58 58 22 22 22 6 6 6
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 14 14 14
39893 - 46 46 46 82 82 82 2 2 6 106 106 106
39894 -170 170 170 26 26 26 86 86 86 226 226 226
39895 -123 123 123 10 10 10 14 14 14 46 46 46
39896 -231 231 231 190 190 190 6 6 6 70 70 70
39897 - 90 90 90 238 238 238 158 158 158 2 2 6
39898 - 2 2 6 2 2 6 2 2 6 2 2 6
39899 - 70 70 70 58 58 58 22 22 22 6 6 6
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 1 0 0 0
39907 - 0 0 1 0 0 1 0 0 1 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 14 14 14
39913 - 42 42 42 86 86 86 6 6 6 116 116 116
39914 -106 106 106 6 6 6 70 70 70 149 149 149
39915 -128 128 128 18 18 18 38 38 38 54 54 54
39916 -221 221 221 106 106 106 2 2 6 14 14 14
39917 - 46 46 46 190 190 190 198 198 198 2 2 6
39918 - 2 2 6 2 2 6 2 2 6 2 2 6
39919 - 74 74 74 62 62 62 22 22 22 6 6 6
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 1 0 0 0
39927 - 0 0 1 0 0 0 0 0 1 0 0 0
39928 - 0 0 0 0 0 0 0 0 0 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 14 14 14
39933 - 42 42 42 94 94 94 14 14 14 101 101 101
39934 -128 128 128 2 2 6 18 18 18 116 116 116
39935 -118 98 46 121 92 8 121 92 8 98 78 10
39936 -162 162 162 106 106 106 2 2 6 2 2 6
39937 - 2 2 6 195 195 195 195 195 195 6 6 6
39938 - 2 2 6 2 2 6 2 2 6 2 2 6
39939 - 74 74 74 62 62 62 22 22 22 6 6 6
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 1 0 0 1
39947 - 0 0 1 0 0 0 0 0 1 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 10 10 10
39953 - 38 38 38 90 90 90 14 14 14 58 58 58
39954 -210 210 210 26 26 26 54 38 6 154 114 10
39955 -226 170 11 236 186 11 225 175 15 184 144 12
39956 -215 174 15 175 146 61 37 26 9 2 2 6
39957 - 70 70 70 246 246 246 138 138 138 2 2 6
39958 - 2 2 6 2 2 6 2 2 6 2 2 6
39959 - 70 70 70 66 66 66 26 26 26 6 6 6
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 10 10 10
39973 - 38 38 38 86 86 86 14 14 14 10 10 10
39974 -195 195 195 188 164 115 192 133 9 225 175 15
39975 -239 182 13 234 190 10 232 195 16 232 200 30
39976 -245 207 45 241 208 19 232 195 16 184 144 12
39977 -218 194 134 211 206 186 42 42 42 2 2 6
39978 - 2 2 6 2 2 6 2 2 6 2 2 6
39979 - 50 50 50 74 74 74 30 30 30 6 6 6
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 10 10 10
39993 - 34 34 34 86 86 86 14 14 14 2 2 6
39994 -121 87 25 192 133 9 219 162 10 239 182 13
39995 -236 186 11 232 195 16 241 208 19 244 214 54
39996 -246 218 60 246 218 38 246 215 20 241 208 19
39997 -241 208 19 226 184 13 121 87 25 2 2 6
39998 - 2 2 6 2 2 6 2 2 6 2 2 6
39999 - 50 50 50 82 82 82 34 34 34 10 10 10
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 0 0 0
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 10 10 10
40013 - 34 34 34 82 82 82 30 30 30 61 42 6
40014 -180 123 7 206 145 10 230 174 11 239 182 13
40015 -234 190 10 238 202 15 241 208 19 246 218 74
40016 -246 218 38 246 215 20 246 215 20 246 215 20
40017 -226 184 13 215 174 15 184 144 12 6 6 6
40018 - 2 2 6 2 2 6 2 2 6 2 2 6
40019 - 26 26 26 94 94 94 42 42 42 14 14 14
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 10 10 10
40033 - 30 30 30 78 78 78 50 50 50 104 69 6
40034 -192 133 9 216 158 10 236 178 12 236 186 11
40035 -232 195 16 241 208 19 244 214 54 245 215 43
40036 -246 215 20 246 215 20 241 208 19 198 155 10
40037 -200 144 11 216 158 10 156 118 10 2 2 6
40038 - 2 2 6 2 2 6 2 2 6 2 2 6
40039 - 6 6 6 90 90 90 54 54 54 18 18 18
40040 - 6 6 6 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 10 10 10
40053 - 30 30 30 78 78 78 46 46 46 22 22 22
40054 -137 92 6 210 162 10 239 182 13 238 190 10
40055 -238 202 15 241 208 19 246 215 20 246 215 20
40056 -241 208 19 203 166 17 185 133 11 210 150 10
40057 -216 158 10 210 150 10 102 78 10 2 2 6
40058 - 6 6 6 54 54 54 14 14 14 2 2 6
40059 - 2 2 6 62 62 62 74 74 74 30 30 30
40060 - 10 10 10 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 10 10 10
40073 - 34 34 34 78 78 78 50 50 50 6 6 6
40074 - 94 70 30 139 102 15 190 146 13 226 184 13
40075 -232 200 30 232 195 16 215 174 15 190 146 13
40076 -168 122 10 192 133 9 210 150 10 213 154 11
40077 -202 150 34 182 157 106 101 98 89 2 2 6
40078 - 2 2 6 78 78 78 116 116 116 58 58 58
40079 - 2 2 6 22 22 22 90 90 90 46 46 46
40080 - 18 18 18 6 6 6 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 10 10 10
40093 - 38 38 38 86 86 86 50 50 50 6 6 6
40094 -128 128 128 174 154 114 156 107 11 168 122 10
40095 -198 155 10 184 144 12 197 138 11 200 144 11
40096 -206 145 10 206 145 10 197 138 11 188 164 115
40097 -195 195 195 198 198 198 174 174 174 14 14 14
40098 - 2 2 6 22 22 22 116 116 116 116 116 116
40099 - 22 22 22 2 2 6 74 74 74 70 70 70
40100 - 30 30 30 10 10 10 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 6 6 6 18 18 18
40113 - 50 50 50 101 101 101 26 26 26 10 10 10
40114 -138 138 138 190 190 190 174 154 114 156 107 11
40115 -197 138 11 200 144 11 197 138 11 192 133 9
40116 -180 123 7 190 142 34 190 178 144 187 187 187
40117 -202 202 202 221 221 221 214 214 214 66 66 66
40118 - 2 2 6 2 2 6 50 50 50 62 62 62
40119 - 6 6 6 2 2 6 10 10 10 90 90 90
40120 - 50 50 50 18 18 18 6 6 6 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 10 10 10 34 34 34
40133 - 74 74 74 74 74 74 2 2 6 6 6 6
40134 -144 144 144 198 198 198 190 190 190 178 166 146
40135 -154 121 60 156 107 11 156 107 11 168 124 44
40136 -174 154 114 187 187 187 190 190 190 210 210 210
40137 -246 246 246 253 253 253 253 253 253 182 182 182
40138 - 6 6 6 2 2 6 2 2 6 2 2 6
40139 - 2 2 6 2 2 6 2 2 6 62 62 62
40140 - 74 74 74 34 34 34 14 14 14 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 10 10 10 22 22 22 54 54 54
40153 - 94 94 94 18 18 18 2 2 6 46 46 46
40154 -234 234 234 221 221 221 190 190 190 190 190 190
40155 -190 190 190 187 187 187 187 187 187 190 190 190
40156 -190 190 190 195 195 195 214 214 214 242 242 242
40157 -253 253 253 253 253 253 253 253 253 253 253 253
40158 - 82 82 82 2 2 6 2 2 6 2 2 6
40159 - 2 2 6 2 2 6 2 2 6 14 14 14
40160 - 86 86 86 54 54 54 22 22 22 6 6 6
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 6 6 6 18 18 18 46 46 46 90 90 90
40173 - 46 46 46 18 18 18 6 6 6 182 182 182
40174 -253 253 253 246 246 246 206 206 206 190 190 190
40175 -190 190 190 190 190 190 190 190 190 190 190 190
40176 -206 206 206 231 231 231 250 250 250 253 253 253
40177 -253 253 253 253 253 253 253 253 253 253 253 253
40178 -202 202 202 14 14 14 2 2 6 2 2 6
40179 - 2 2 6 2 2 6 2 2 6 2 2 6
40180 - 42 42 42 86 86 86 42 42 42 18 18 18
40181 - 6 6 6 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 6 6 6
40192 - 14 14 14 38 38 38 74 74 74 66 66 66
40193 - 2 2 6 6 6 6 90 90 90 250 250 250
40194 -253 253 253 253 253 253 238 238 238 198 198 198
40195 -190 190 190 190 190 190 195 195 195 221 221 221
40196 -246 246 246 253 253 253 253 253 253 253 253 253
40197 -253 253 253 253 253 253 253 253 253 253 253 253
40198 -253 253 253 82 82 82 2 2 6 2 2 6
40199 - 2 2 6 2 2 6 2 2 6 2 2 6
40200 - 2 2 6 78 78 78 70 70 70 34 34 34
40201 - 14 14 14 6 6 6 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 14 14 14
40212 - 34 34 34 66 66 66 78 78 78 6 6 6
40213 - 2 2 6 18 18 18 218 218 218 253 253 253
40214 -253 253 253 253 253 253 253 253 253 246 246 246
40215 -226 226 226 231 231 231 246 246 246 253 253 253
40216 -253 253 253 253 253 253 253 253 253 253 253 253
40217 -253 253 253 253 253 253 253 253 253 253 253 253
40218 -253 253 253 178 178 178 2 2 6 2 2 6
40219 - 2 2 6 2 2 6 2 2 6 2 2 6
40220 - 2 2 6 18 18 18 90 90 90 62 62 62
40221 - 30 30 30 10 10 10 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 10 10 10 26 26 26
40232 - 58 58 58 90 90 90 18 18 18 2 2 6
40233 - 2 2 6 110 110 110 253 253 253 253 253 253
40234 -253 253 253 253 253 253 253 253 253 253 253 253
40235 -250 250 250 253 253 253 253 253 253 253 253 253
40236 -253 253 253 253 253 253 253 253 253 253 253 253
40237 -253 253 253 253 253 253 253 253 253 253 253 253
40238 -253 253 253 231 231 231 18 18 18 2 2 6
40239 - 2 2 6 2 2 6 2 2 6 2 2 6
40240 - 2 2 6 2 2 6 18 18 18 94 94 94
40241 - 54 54 54 26 26 26 10 10 10 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 6 6 6 22 22 22 50 50 50
40252 - 90 90 90 26 26 26 2 2 6 2 2 6
40253 - 14 14 14 195 195 195 250 250 250 253 253 253
40254 -253 253 253 253 253 253 253 253 253 253 253 253
40255 -253 253 253 253 253 253 253 253 253 253 253 253
40256 -253 253 253 253 253 253 253 253 253 253 253 253
40257 -253 253 253 253 253 253 253 253 253 253 253 253
40258 -250 250 250 242 242 242 54 54 54 2 2 6
40259 - 2 2 6 2 2 6 2 2 6 2 2 6
40260 - 2 2 6 2 2 6 2 2 6 38 38 38
40261 - 86 86 86 50 50 50 22 22 22 6 6 6
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 6 6 6 14 14 14 38 38 38 82 82 82
40272 - 34 34 34 2 2 6 2 2 6 2 2 6
40273 - 42 42 42 195 195 195 246 246 246 253 253 253
40274 -253 253 253 253 253 253 253 253 253 250 250 250
40275 -242 242 242 242 242 242 250 250 250 253 253 253
40276 -253 253 253 253 253 253 253 253 253 253 253 253
40277 -253 253 253 250 250 250 246 246 246 238 238 238
40278 -226 226 226 231 231 231 101 101 101 6 6 6
40279 - 2 2 6 2 2 6 2 2 6 2 2 6
40280 - 2 2 6 2 2 6 2 2 6 2 2 6
40281 - 38 38 38 82 82 82 42 42 42 14 14 14
40282 - 6 6 6 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 10 10 10 26 26 26 62 62 62 66 66 66
40292 - 2 2 6 2 2 6 2 2 6 6 6 6
40293 - 70 70 70 170 170 170 206 206 206 234 234 234
40294 -246 246 246 250 250 250 250 250 250 238 238 238
40295 -226 226 226 231 231 231 238 238 238 250 250 250
40296 -250 250 250 250 250 250 246 246 246 231 231 231
40297 -214 214 214 206 206 206 202 202 202 202 202 202
40298 -198 198 198 202 202 202 182 182 182 18 18 18
40299 - 2 2 6 2 2 6 2 2 6 2 2 6
40300 - 2 2 6 2 2 6 2 2 6 2 2 6
40301 - 2 2 6 62 62 62 66 66 66 30 30 30
40302 - 10 10 10 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 14 14 14 42 42 42 82 82 82 18 18 18
40312 - 2 2 6 2 2 6 2 2 6 10 10 10
40313 - 94 94 94 182 182 182 218 218 218 242 242 242
40314 -250 250 250 253 253 253 253 253 253 250 250 250
40315 -234 234 234 253 253 253 253 253 253 253 253 253
40316 -253 253 253 253 253 253 253 253 253 246 246 246
40317 -238 238 238 226 226 226 210 210 210 202 202 202
40318 -195 195 195 195 195 195 210 210 210 158 158 158
40319 - 6 6 6 14 14 14 50 50 50 14 14 14
40320 - 2 2 6 2 2 6 2 2 6 2 2 6
40321 - 2 2 6 6 6 6 86 86 86 46 46 46
40322 - 18 18 18 6 6 6 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 0 0 0 0 0 0 0 0 0
40327 - 0 0 0 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 6 6 6
40331 - 22 22 22 54 54 54 70 70 70 2 2 6
40332 - 2 2 6 10 10 10 2 2 6 22 22 22
40333 -166 166 166 231 231 231 250 250 250 253 253 253
40334 -253 253 253 253 253 253 253 253 253 250 250 250
40335 -242 242 242 253 253 253 253 253 253 253 253 253
40336 -253 253 253 253 253 253 253 253 253 253 253 253
40337 -253 253 253 253 253 253 253 253 253 246 246 246
40338 -231 231 231 206 206 206 198 198 198 226 226 226
40339 - 94 94 94 2 2 6 6 6 6 38 38 38
40340 - 30 30 30 2 2 6 2 2 6 2 2 6
40341 - 2 2 6 2 2 6 62 62 62 66 66 66
40342 - 26 26 26 10 10 10 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 0 0 0 0 0 0 0 0 0 0 0 0
40347 - 0 0 0 0 0 0 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 10 10 10
40351 - 30 30 30 74 74 74 50 50 50 2 2 6
40352 - 26 26 26 26 26 26 2 2 6 106 106 106
40353 -238 238 238 253 253 253 253 253 253 253 253 253
40354 -253 253 253 253 253 253 253 253 253 253 253 253
40355 -253 253 253 253 253 253 253 253 253 253 253 253
40356 -253 253 253 253 253 253 253 253 253 253 253 253
40357 -253 253 253 253 253 253 253 253 253 253 253 253
40358 -253 253 253 246 246 246 218 218 218 202 202 202
40359 -210 210 210 14 14 14 2 2 6 2 2 6
40360 - 30 30 30 22 22 22 2 2 6 2 2 6
40361 - 2 2 6 2 2 6 18 18 18 86 86 86
40362 - 42 42 42 14 14 14 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 0 0 0
40366 - 0 0 0 0 0 0 0 0 0 0 0 0
40367 - 0 0 0 0 0 0 0 0 0 0 0 0
40368 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 14 14 14
40371 - 42 42 42 90 90 90 22 22 22 2 2 6
40372 - 42 42 42 2 2 6 18 18 18 218 218 218
40373 -253 253 253 253 253 253 253 253 253 253 253 253
40374 -253 253 253 253 253 253 253 253 253 253 253 253
40375 -253 253 253 253 253 253 253 253 253 253 253 253
40376 -253 253 253 253 253 253 253 253 253 253 253 253
40377 -253 253 253 253 253 253 253 253 253 253 253 253
40378 -253 253 253 253 253 253 250 250 250 221 221 221
40379 -218 218 218 101 101 101 2 2 6 14 14 14
40380 - 18 18 18 38 38 38 10 10 10 2 2 6
40381 - 2 2 6 2 2 6 2 2 6 78 78 78
40382 - 58 58 58 22 22 22 6 6 6 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 0 0 0
40386 - 0 0 0 0 0 0 0 0 0 0 0 0
40387 - 0 0 0 0 0 0 0 0 0 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 6 6 6 18 18 18
40391 - 54 54 54 82 82 82 2 2 6 26 26 26
40392 - 22 22 22 2 2 6 123 123 123 253 253 253
40393 -253 253 253 253 253 253 253 253 253 253 253 253
40394 -253 253 253 253 253 253 253 253 253 253 253 253
40395 -253 253 253 253 253 253 253 253 253 253 253 253
40396 -253 253 253 253 253 253 253 253 253 253 253 253
40397 -253 253 253 253 253 253 253 253 253 253 253 253
40398 -253 253 253 253 253 253 253 253 253 250 250 250
40399 -238 238 238 198 198 198 6 6 6 38 38 38
40400 - 58 58 58 26 26 26 38 38 38 2 2 6
40401 - 2 2 6 2 2 6 2 2 6 46 46 46
40402 - 78 78 78 30 30 30 10 10 10 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 0 0 0 0 0 0 0 0 0 0 0 0
40407 - 0 0 0 0 0 0 0 0 0 0 0 0
40408 - 0 0 0 0 0 0 0 0 0 0 0 0
40409 - 0 0 0 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 10 10 10 30 30 30
40411 - 74 74 74 58 58 58 2 2 6 42 42 42
40412 - 2 2 6 22 22 22 231 231 231 253 253 253
40413 -253 253 253 253 253 253 253 253 253 253 253 253
40414 -253 253 253 253 253 253 253 253 253 250 250 250
40415 -253 253 253 253 253 253 253 253 253 253 253 253
40416 -253 253 253 253 253 253 253 253 253 253 253 253
40417 -253 253 253 253 253 253 253 253 253 253 253 253
40418 -253 253 253 253 253 253 253 253 253 253 253 253
40419 -253 253 253 246 246 246 46 46 46 38 38 38
40420 - 42 42 42 14 14 14 38 38 38 14 14 14
40421 - 2 2 6 2 2 6 2 2 6 6 6 6
40422 - 86 86 86 46 46 46 14 14 14 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 0 0 0
40426 - 0 0 0 0 0 0 0 0 0 0 0 0
40427 - 0 0 0 0 0 0 0 0 0 0 0 0
40428 - 0 0 0 0 0 0 0 0 0 0 0 0
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 6 6 6 14 14 14 42 42 42
40431 - 90 90 90 18 18 18 18 18 18 26 26 26
40432 - 2 2 6 116 116 116 253 253 253 253 253 253
40433 -253 253 253 253 253 253 253 253 253 253 253 253
40434 -253 253 253 253 253 253 250 250 250 238 238 238
40435 -253 253 253 253 253 253 253 253 253 253 253 253
40436 -253 253 253 253 253 253 253 253 253 253 253 253
40437 -253 253 253 253 253 253 253 253 253 253 253 253
40438 -253 253 253 253 253 253 253 253 253 253 253 253
40439 -253 253 253 253 253 253 94 94 94 6 6 6
40440 - 2 2 6 2 2 6 10 10 10 34 34 34
40441 - 2 2 6 2 2 6 2 2 6 2 2 6
40442 - 74 74 74 58 58 58 22 22 22 6 6 6
40443 - 0 0 0 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 0 0 0 0 0 0 0 0 0
40446 - 0 0 0 0 0 0 0 0 0 0 0 0
40447 - 0 0 0 0 0 0 0 0 0 0 0 0
40448 - 0 0 0 0 0 0 0 0 0 0 0 0
40449 - 0 0 0 0 0 0 0 0 0 0 0 0
40450 - 0 0 0 10 10 10 26 26 26 66 66 66
40451 - 82 82 82 2 2 6 38 38 38 6 6 6
40452 - 14 14 14 210 210 210 253 253 253 253 253 253
40453 -253 253 253 253 253 253 253 253 253 253 253 253
40454 -253 253 253 253 253 253 246 246 246 242 242 242
40455 -253 253 253 253 253 253 253 253 253 253 253 253
40456 -253 253 253 253 253 253 253 253 253 253 253 253
40457 -253 253 253 253 253 253 253 253 253 253 253 253
40458 -253 253 253 253 253 253 253 253 253 253 253 253
40459 -253 253 253 253 253 253 144 144 144 2 2 6
40460 - 2 2 6 2 2 6 2 2 6 46 46 46
40461 - 2 2 6 2 2 6 2 2 6 2 2 6
40462 - 42 42 42 74 74 74 30 30 30 10 10 10
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 0 0 0 0 0 0 0 0 0 0 0 0
40465 - 0 0 0 0 0 0 0 0 0 0 0 0
40466 - 0 0 0 0 0 0 0 0 0 0 0 0
40467 - 0 0 0 0 0 0 0 0 0 0 0 0
40468 - 0 0 0 0 0 0 0 0 0 0 0 0
40469 - 0 0 0 0 0 0 0 0 0 0 0 0
40470 - 6 6 6 14 14 14 42 42 42 90 90 90
40471 - 26 26 26 6 6 6 42 42 42 2 2 6
40472 - 74 74 74 250 250 250 253 253 253 253 253 253
40473 -253 253 253 253 253 253 253 253 253 253 253 253
40474 -253 253 253 253 253 253 242 242 242 242 242 242
40475 -253 253 253 253 253 253 253 253 253 253 253 253
40476 -253 253 253 253 253 253 253 253 253 253 253 253
40477 -253 253 253 253 253 253 253 253 253 253 253 253
40478 -253 253 253 253 253 253 253 253 253 253 253 253
40479 -253 253 253 253 253 253 182 182 182 2 2 6
40480 - 2 2 6 2 2 6 2 2 6 46 46 46
40481 - 2 2 6 2 2 6 2 2 6 2 2 6
40482 - 10 10 10 86 86 86 38 38 38 10 10 10
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 0 0 0 0 0 0
40485 - 0 0 0 0 0 0 0 0 0 0 0 0
40486 - 0 0 0 0 0 0 0 0 0 0 0 0
40487 - 0 0 0 0 0 0 0 0 0 0 0 0
40488 - 0 0 0 0 0 0 0 0 0 0 0 0
40489 - 0 0 0 0 0 0 0 0 0 0 0 0
40490 - 10 10 10 26 26 26 66 66 66 82 82 82
40491 - 2 2 6 22 22 22 18 18 18 2 2 6
40492 -149 149 149 253 253 253 253 253 253 253 253 253
40493 -253 253 253 253 253 253 253 253 253 253 253 253
40494 -253 253 253 253 253 253 234 234 234 242 242 242
40495 -253 253 253 253 253 253 253 253 253 253 253 253
40496 -253 253 253 253 253 253 253 253 253 253 253 253
40497 -253 253 253 253 253 253 253 253 253 253 253 253
40498 -253 253 253 253 253 253 253 253 253 253 253 253
40499 -253 253 253 253 253 253 206 206 206 2 2 6
40500 - 2 2 6 2 2 6 2 2 6 38 38 38
40501 - 2 2 6 2 2 6 2 2 6 2 2 6
40502 - 6 6 6 86 86 86 46 46 46 14 14 14
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 0 0 0
40505 - 0 0 0 0 0 0 0 0 0 0 0 0
40506 - 0 0 0 0 0 0 0 0 0 0 0 0
40507 - 0 0 0 0 0 0 0 0 0 0 0 0
40508 - 0 0 0 0 0 0 0 0 0 0 0 0
40509 - 0 0 0 0 0 0 0 0 0 6 6 6
40510 - 18 18 18 46 46 46 86 86 86 18 18 18
40511 - 2 2 6 34 34 34 10 10 10 6 6 6
40512 -210 210 210 253 253 253 253 253 253 253 253 253
40513 -253 253 253 253 253 253 253 253 253 253 253 253
40514 -253 253 253 253 253 253 234 234 234 242 242 242
40515 -253 253 253 253 253 253 253 253 253 253 253 253
40516 -253 253 253 253 253 253 253 253 253 253 253 253
40517 -253 253 253 253 253 253 253 253 253 253 253 253
40518 -253 253 253 253 253 253 253 253 253 253 253 253
40519 -253 253 253 253 253 253 221 221 221 6 6 6
40520 - 2 2 6 2 2 6 6 6 6 30 30 30
40521 - 2 2 6 2 2 6 2 2 6 2 2 6
40522 - 2 2 6 82 82 82 54 54 54 18 18 18
40523 - 6 6 6 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 0 0 0 0 0 0 0 0 0 0 0 0
40526 - 0 0 0 0 0 0 0 0 0 0 0 0
40527 - 0 0 0 0 0 0 0 0 0 0 0 0
40528 - 0 0 0 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 0 0 0 10 10 10
40530 - 26 26 26 66 66 66 62 62 62 2 2 6
40531 - 2 2 6 38 38 38 10 10 10 26 26 26
40532 -238 238 238 253 253 253 253 253 253 253 253 253
40533 -253 253 253 253 253 253 253 253 253 253 253 253
40534 -253 253 253 253 253 253 231 231 231 238 238 238
40535 -253 253 253 253 253 253 253 253 253 253 253 253
40536 -253 253 253 253 253 253 253 253 253 253 253 253
40537 -253 253 253 253 253 253 253 253 253 253 253 253
40538 -253 253 253 253 253 253 253 253 253 253 253 253
40539 -253 253 253 253 253 253 231 231 231 6 6 6
40540 - 2 2 6 2 2 6 10 10 10 30 30 30
40541 - 2 2 6 2 2 6 2 2 6 2 2 6
40542 - 2 2 6 66 66 66 58 58 58 22 22 22
40543 - 6 6 6 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 0 0 0 0 0 0
40546 - 0 0 0 0 0 0 0 0 0 0 0 0
40547 - 0 0 0 0 0 0 0 0 0 0 0 0
40548 - 0 0 0 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 10 10 10
40550 - 38 38 38 78 78 78 6 6 6 2 2 6
40551 - 2 2 6 46 46 46 14 14 14 42 42 42
40552 -246 246 246 253 253 253 253 253 253 253 253 253
40553 -253 253 253 253 253 253 253 253 253 253 253 253
40554 -253 253 253 253 253 253 231 231 231 242 242 242
40555 -253 253 253 253 253 253 253 253 253 253 253 253
40556 -253 253 253 253 253 253 253 253 253 253 253 253
40557 -253 253 253 253 253 253 253 253 253 253 253 253
40558 -253 253 253 253 253 253 253 253 253 253 253 253
40559 -253 253 253 253 253 253 234 234 234 10 10 10
40560 - 2 2 6 2 2 6 22 22 22 14 14 14
40561 - 2 2 6 2 2 6 2 2 6 2 2 6
40562 - 2 2 6 66 66 66 62 62 62 22 22 22
40563 - 6 6 6 0 0 0 0 0 0 0 0 0
40564 - 0 0 0 0 0 0 0 0 0 0 0 0
40565 - 0 0 0 0 0 0 0 0 0 0 0 0
40566 - 0 0 0 0 0 0 0 0 0 0 0 0
40567 - 0 0 0 0 0 0 0 0 0 0 0 0
40568 - 0 0 0 0 0 0 0 0 0 0 0 0
40569 - 0 0 0 0 0 0 6 6 6 18 18 18
40570 - 50 50 50 74 74 74 2 2 6 2 2 6
40571 - 14 14 14 70 70 70 34 34 34 62 62 62
40572 -250 250 250 253 253 253 253 253 253 253 253 253
40573 -253 253 253 253 253 253 253 253 253 253 253 253
40574 -253 253 253 253 253 253 231 231 231 246 246 246
40575 -253 253 253 253 253 253 253 253 253 253 253 253
40576 -253 253 253 253 253 253 253 253 253 253 253 253
40577 -253 253 253 253 253 253 253 253 253 253 253 253
40578 -253 253 253 253 253 253 253 253 253 253 253 253
40579 -253 253 253 253 253 253 234 234 234 14 14 14
40580 - 2 2 6 2 2 6 30 30 30 2 2 6
40581 - 2 2 6 2 2 6 2 2 6 2 2 6
40582 - 2 2 6 66 66 66 62 62 62 22 22 22
40583 - 6 6 6 0 0 0 0 0 0 0 0 0
40584 - 0 0 0 0 0 0 0 0 0 0 0 0
40585 - 0 0 0 0 0 0 0 0 0 0 0 0
40586 - 0 0 0 0 0 0 0 0 0 0 0 0
40587 - 0 0 0 0 0 0 0 0 0 0 0 0
40588 - 0 0 0 0 0 0 0 0 0 0 0 0
40589 - 0 0 0 0 0 0 6 6 6 18 18 18
40590 - 54 54 54 62 62 62 2 2 6 2 2 6
40591 - 2 2 6 30 30 30 46 46 46 70 70 70
40592 -250 250 250 253 253 253 253 253 253 253 253 253
40593 -253 253 253 253 253 253 253 253 253 253 253 253
40594 -253 253 253 253 253 253 231 231 231 246 246 246
40595 -253 253 253 253 253 253 253 253 253 253 253 253
40596 -253 253 253 253 253 253 253 253 253 253 253 253
40597 -253 253 253 253 253 253 253 253 253 253 253 253
40598 -253 253 253 253 253 253 253 253 253 253 253 253
40599 -253 253 253 253 253 253 226 226 226 10 10 10
40600 - 2 2 6 6 6 6 30 30 30 2 2 6
40601 - 2 2 6 2 2 6 2 2 6 2 2 6
40602 - 2 2 6 66 66 66 58 58 58 22 22 22
40603 - 6 6 6 0 0 0 0 0 0 0 0 0
40604 - 0 0 0 0 0 0 0 0 0 0 0 0
40605 - 0 0 0 0 0 0 0 0 0 0 0 0
40606 - 0 0 0 0 0 0 0 0 0 0 0 0
40607 - 0 0 0 0 0 0 0 0 0 0 0 0
40608 - 0 0 0 0 0 0 0 0 0 0 0 0
40609 - 0 0 0 0 0 0 6 6 6 22 22 22
40610 - 58 58 58 62 62 62 2 2 6 2 2 6
40611 - 2 2 6 2 2 6 30 30 30 78 78 78
40612 -250 250 250 253 253 253 253 253 253 253 253 253
40613 -253 253 253 253 253 253 253 253 253 253 253 253
40614 -253 253 253 253 253 253 231 231 231 246 246 246
40615 -253 253 253 253 253 253 253 253 253 253 253 253
40616 -253 253 253 253 253 253 253 253 253 253 253 253
40617 -253 253 253 253 253 253 253 253 253 253 253 253
40618 -253 253 253 253 253 253 253 253 253 253 253 253
40619 -253 253 253 253 253 253 206 206 206 2 2 6
40620 - 22 22 22 34 34 34 18 14 6 22 22 22
40621 - 26 26 26 18 18 18 6 6 6 2 2 6
40622 - 2 2 6 82 82 82 54 54 54 18 18 18
40623 - 6 6 6 0 0 0 0 0 0 0 0 0
40624 - 0 0 0 0 0 0 0 0 0 0 0 0
40625 - 0 0 0 0 0 0 0 0 0 0 0 0
40626 - 0 0 0 0 0 0 0 0 0 0 0 0
40627 - 0 0 0 0 0 0 0 0 0 0 0 0
40628 - 0 0 0 0 0 0 0 0 0 0 0 0
40629 - 0 0 0 0 0 0 6 6 6 26 26 26
40630 - 62 62 62 106 106 106 74 54 14 185 133 11
40631 -210 162 10 121 92 8 6 6 6 62 62 62
40632 -238 238 238 253 253 253 253 253 253 253 253 253
40633 -253 253 253 253 253 253 253 253 253 253 253 253
40634 -253 253 253 253 253 253 231 231 231 246 246 246
40635 -253 253 253 253 253 253 253 253 253 253 253 253
40636 -253 253 253 253 253 253 253 253 253 253 253 253
40637 -253 253 253 253 253 253 253 253 253 253 253 253
40638 -253 253 253 253 253 253 253 253 253 253 253 253
40639 -253 253 253 253 253 253 158 158 158 18 18 18
40640 - 14 14 14 2 2 6 2 2 6 2 2 6
40641 - 6 6 6 18 18 18 66 66 66 38 38 38
40642 - 6 6 6 94 94 94 50 50 50 18 18 18
40643 - 6 6 6 0 0 0 0 0 0 0 0 0
40644 - 0 0 0 0 0 0 0 0 0 0 0 0
40645 - 0 0 0 0 0 0 0 0 0 0 0 0
40646 - 0 0 0 0 0 0 0 0 0 0 0 0
40647 - 0 0 0 0 0 0 0 0 0 0 0 0
40648 - 0 0 0 0 0 0 0 0 0 6 6 6
40649 - 10 10 10 10 10 10 18 18 18 38 38 38
40650 - 78 78 78 142 134 106 216 158 10 242 186 14
40651 -246 190 14 246 190 14 156 118 10 10 10 10
40652 - 90 90 90 238 238 238 253 253 253 253 253 253
40653 -253 253 253 253 253 253 253 253 253 253 253 253
40654 -253 253 253 253 253 253 231 231 231 250 250 250
40655 -253 253 253 253 253 253 253 253 253 253 253 253
40656 -253 253 253 253 253 253 253 253 253 253 253 253
40657 -253 253 253 253 253 253 253 253 253 253 253 253
40658 -253 253 253 253 253 253 253 253 253 246 230 190
40659 -238 204 91 238 204 91 181 142 44 37 26 9
40660 - 2 2 6 2 2 6 2 2 6 2 2 6
40661 - 2 2 6 2 2 6 38 38 38 46 46 46
40662 - 26 26 26 106 106 106 54 54 54 18 18 18
40663 - 6 6 6 0 0 0 0 0 0 0 0 0
40664 - 0 0 0 0 0 0 0 0 0 0 0 0
40665 - 0 0 0 0 0 0 0 0 0 0 0 0
40666 - 0 0 0 0 0 0 0 0 0 0 0 0
40667 - 0 0 0 0 0 0 0 0 0 0 0 0
40668 - 0 0 0 6 6 6 14 14 14 22 22 22
40669 - 30 30 30 38 38 38 50 50 50 70 70 70
40670 -106 106 106 190 142 34 226 170 11 242 186 14
40671 -246 190 14 246 190 14 246 190 14 154 114 10
40672 - 6 6 6 74 74 74 226 226 226 253 253 253
40673 -253 253 253 253 253 253 253 253 253 253 253 253
40674 -253 253 253 253 253 253 231 231 231 250 250 250
40675 -253 253 253 253 253 253 253 253 253 253 253 253
40676 -253 253 253 253 253 253 253 253 253 253 253 253
40677 -253 253 253 253 253 253 253 253 253 253 253 253
40678 -253 253 253 253 253 253 253 253 253 228 184 62
40679 -241 196 14 241 208 19 232 195 16 38 30 10
40680 - 2 2 6 2 2 6 2 2 6 2 2 6
40681 - 2 2 6 6 6 6 30 30 30 26 26 26
40682 -203 166 17 154 142 90 66 66 66 26 26 26
40683 - 6 6 6 0 0 0 0 0 0 0 0 0
40684 - 0 0 0 0 0 0 0 0 0 0 0 0
40685 - 0 0 0 0 0 0 0 0 0 0 0 0
40686 - 0 0 0 0 0 0 0 0 0 0 0 0
40687 - 0 0 0 0 0 0 0 0 0 0 0 0
40688 - 6 6 6 18 18 18 38 38 38 58 58 58
40689 - 78 78 78 86 86 86 101 101 101 123 123 123
40690 -175 146 61 210 150 10 234 174 13 246 186 14
40691 -246 190 14 246 190 14 246 190 14 238 190 10
40692 -102 78 10 2 2 6 46 46 46 198 198 198
40693 -253 253 253 253 253 253 253 253 253 253 253 253
40694 -253 253 253 253 253 253 234 234 234 242 242 242
40695 -253 253 253 253 253 253 253 253 253 253 253 253
40696 -253 253 253 253 253 253 253 253 253 253 253 253
40697 -253 253 253 253 253 253 253 253 253 253 253 253
40698 -253 253 253 253 253 253 253 253 253 224 178 62
40699 -242 186 14 241 196 14 210 166 10 22 18 6
40700 - 2 2 6 2 2 6 2 2 6 2 2 6
40701 - 2 2 6 2 2 6 6 6 6 121 92 8
40702 -238 202 15 232 195 16 82 82 82 34 34 34
40703 - 10 10 10 0 0 0 0 0 0 0 0 0
40704 - 0 0 0 0 0 0 0 0 0 0 0 0
40705 - 0 0 0 0 0 0 0 0 0 0 0 0
40706 - 0 0 0 0 0 0 0 0 0 0 0 0
40707 - 0 0 0 0 0 0 0 0 0 0 0 0
40708 - 14 14 14 38 38 38 70 70 70 154 122 46
40709 -190 142 34 200 144 11 197 138 11 197 138 11
40710 -213 154 11 226 170 11 242 186 14 246 190 14
40711 -246 190 14 246 190 14 246 190 14 246 190 14
40712 -225 175 15 46 32 6 2 2 6 22 22 22
40713 -158 158 158 250 250 250 253 253 253 253 253 253
40714 -253 253 253 253 253 253 253 253 253 253 253 253
40715 -253 253 253 253 253 253 253 253 253 253 253 253
40716 -253 253 253 253 253 253 253 253 253 253 253 253
40717 -253 253 253 253 253 253 253 253 253 253 253 253
40718 -253 253 253 250 250 250 242 242 242 224 178 62
40719 -239 182 13 236 186 11 213 154 11 46 32 6
40720 - 2 2 6 2 2 6 2 2 6 2 2 6
40721 - 2 2 6 2 2 6 61 42 6 225 175 15
40722 -238 190 10 236 186 11 112 100 78 42 42 42
40723 - 14 14 14 0 0 0 0 0 0 0 0 0
40724 - 0 0 0 0 0 0 0 0 0 0 0 0
40725 - 0 0 0 0 0 0 0 0 0 0 0 0
40726 - 0 0 0 0 0 0 0 0 0 0 0 0
40727 - 0 0 0 0 0 0 0 0 0 6 6 6
40728 - 22 22 22 54 54 54 154 122 46 213 154 11
40729 -226 170 11 230 174 11 226 170 11 226 170 11
40730 -236 178 12 242 186 14 246 190 14 246 190 14
40731 -246 190 14 246 190 14 246 190 14 246 190 14
40732 -241 196 14 184 144 12 10 10 10 2 2 6
40733 - 6 6 6 116 116 116 242 242 242 253 253 253
40734 -253 253 253 253 253 253 253 253 253 253 253 253
40735 -253 253 253 253 253 253 253 253 253 253 253 253
40736 -253 253 253 253 253 253 253 253 253 253 253 253
40737 -253 253 253 253 253 253 253 253 253 253 253 253
40738 -253 253 253 231 231 231 198 198 198 214 170 54
40739 -236 178 12 236 178 12 210 150 10 137 92 6
40740 - 18 14 6 2 2 6 2 2 6 2 2 6
40741 - 6 6 6 70 47 6 200 144 11 236 178 12
40742 -239 182 13 239 182 13 124 112 88 58 58 58
40743 - 22 22 22 6 6 6 0 0 0 0 0 0
40744 - 0 0 0 0 0 0 0 0 0 0 0 0
40745 - 0 0 0 0 0 0 0 0 0 0 0 0
40746 - 0 0 0 0 0 0 0 0 0 0 0 0
40747 - 0 0 0 0 0 0 0 0 0 10 10 10
40748 - 30 30 30 70 70 70 180 133 36 226 170 11
40749 -239 182 13 242 186 14 242 186 14 246 186 14
40750 -246 190 14 246 190 14 246 190 14 246 190 14
40751 -246 190 14 246 190 14 246 190 14 246 190 14
40752 -246 190 14 232 195 16 98 70 6 2 2 6
40753 - 2 2 6 2 2 6 66 66 66 221 221 221
40754 -253 253 253 253 253 253 253 253 253 253 253 253
40755 -253 253 253 253 253 253 253 253 253 253 253 253
40756 -253 253 253 253 253 253 253 253 253 253 253 253
40757 -253 253 253 253 253 253 253 253 253 253 253 253
40758 -253 253 253 206 206 206 198 198 198 214 166 58
40759 -230 174 11 230 174 11 216 158 10 192 133 9
40760 -163 110 8 116 81 8 102 78 10 116 81 8
40761 -167 114 7 197 138 11 226 170 11 239 182 13
40762 -242 186 14 242 186 14 162 146 94 78 78 78
40763 - 34 34 34 14 14 14 6 6 6 0 0 0
40764 - 0 0 0 0 0 0 0 0 0 0 0 0
40765 - 0 0 0 0 0 0 0 0 0 0 0 0
40766 - 0 0 0 0 0 0 0 0 0 0 0 0
40767 - 0 0 0 0 0 0 0 0 0 6 6 6
40768 - 30 30 30 78 78 78 190 142 34 226 170 11
40769 -239 182 13 246 190 14 246 190 14 246 190 14
40770 -246 190 14 246 190 14 246 190 14 246 190 14
40771 -246 190 14 246 190 14 246 190 14 246 190 14
40772 -246 190 14 241 196 14 203 166 17 22 18 6
40773 - 2 2 6 2 2 6 2 2 6 38 38 38
40774 -218 218 218 253 253 253 253 253 253 253 253 253
40775 -253 253 253 253 253 253 253 253 253 253 253 253
40776 -253 253 253 253 253 253 253 253 253 253 253 253
40777 -253 253 253 253 253 253 253 253 253 253 253 253
40778 -250 250 250 206 206 206 198 198 198 202 162 69
40779 -226 170 11 236 178 12 224 166 10 210 150 10
40780 -200 144 11 197 138 11 192 133 9 197 138 11
40781 -210 150 10 226 170 11 242 186 14 246 190 14
40782 -246 190 14 246 186 14 225 175 15 124 112 88
40783 - 62 62 62 30 30 30 14 14 14 6 6 6
40784 - 0 0 0 0 0 0 0 0 0 0 0 0
40785 - 0 0 0 0 0 0 0 0 0 0 0 0
40786 - 0 0 0 0 0 0 0 0 0 0 0 0
40787 - 0 0 0 0 0 0 0 0 0 10 10 10
40788 - 30 30 30 78 78 78 174 135 50 224 166 10
40789 -239 182 13 246 190 14 246 190 14 246 190 14
40790 -246 190 14 246 190 14 246 190 14 246 190 14
40791 -246 190 14 246 190 14 246 190 14 246 190 14
40792 -246 190 14 246 190 14 241 196 14 139 102 15
40793 - 2 2 6 2 2 6 2 2 6 2 2 6
40794 - 78 78 78 250 250 250 253 253 253 253 253 253
40795 -253 253 253 253 253 253 253 253 253 253 253 253
40796 -253 253 253 253 253 253 253 253 253 253 253 253
40797 -253 253 253 253 253 253 253 253 253 253 253 253
40798 -250 250 250 214 214 214 198 198 198 190 150 46
40799 -219 162 10 236 178 12 234 174 13 224 166 10
40800 -216 158 10 213 154 11 213 154 11 216 158 10
40801 -226 170 11 239 182 13 246 190 14 246 190 14
40802 -246 190 14 246 190 14 242 186 14 206 162 42
40803 -101 101 101 58 58 58 30 30 30 14 14 14
40804 - 6 6 6 0 0 0 0 0 0 0 0 0
40805 - 0 0 0 0 0 0 0 0 0 0 0 0
40806 - 0 0 0 0 0 0 0 0 0 0 0 0
40807 - 0 0 0 0 0 0 0 0 0 10 10 10
40808 - 30 30 30 74 74 74 174 135 50 216 158 10
40809 -236 178 12 246 190 14 246 190 14 246 190 14
40810 -246 190 14 246 190 14 246 190 14 246 190 14
40811 -246 190 14 246 190 14 246 190 14 246 190 14
40812 -246 190 14 246 190 14 241 196 14 226 184 13
40813 - 61 42 6 2 2 6 2 2 6 2 2 6
40814 - 22 22 22 238 238 238 253 253 253 253 253 253
40815 -253 253 253 253 253 253 253 253 253 253 253 253
40816 -253 253 253 253 253 253 253 253 253 253 253 253
40817 -253 253 253 253 253 253 253 253 253 253 253 253
40818 -253 253 253 226 226 226 187 187 187 180 133 36
40819 -216 158 10 236 178 12 239 182 13 236 178 12
40820 -230 174 11 226 170 11 226 170 11 230 174 11
40821 -236 178 12 242 186 14 246 190 14 246 190 14
40822 -246 190 14 246 190 14 246 186 14 239 182 13
40823 -206 162 42 106 106 106 66 66 66 34 34 34
40824 - 14 14 14 6 6 6 0 0 0 0 0 0
40825 - 0 0 0 0 0 0 0 0 0 0 0 0
40826 - 0 0 0 0 0 0 0 0 0 0 0 0
40827 - 0 0 0 0 0 0 0 0 0 6 6 6
40828 - 26 26 26 70 70 70 163 133 67 213 154 11
40829 -236 178 12 246 190 14 246 190 14 246 190 14
40830 -246 190 14 246 190 14 246 190 14 246 190 14
40831 -246 190 14 246 190 14 246 190 14 246 190 14
40832 -246 190 14 246 190 14 246 190 14 241 196 14
40833 -190 146 13 18 14 6 2 2 6 2 2 6
40834 - 46 46 46 246 246 246 253 253 253 253 253 253
40835 -253 253 253 253 253 253 253 253 253 253 253 253
40836 -253 253 253 253 253 253 253 253 253 253 253 253
40837 -253 253 253 253 253 253 253 253 253 253 253 253
40838 -253 253 253 221 221 221 86 86 86 156 107 11
40839 -216 158 10 236 178 12 242 186 14 246 186 14
40840 -242 186 14 239 182 13 239 182 13 242 186 14
40841 -242 186 14 246 186 14 246 190 14 246 190 14
40842 -246 190 14 246 190 14 246 190 14 246 190 14
40843 -242 186 14 225 175 15 142 122 72 66 66 66
40844 - 30 30 30 10 10 10 0 0 0 0 0 0
40845 - 0 0 0 0 0 0 0 0 0 0 0 0
40846 - 0 0 0 0 0 0 0 0 0 0 0 0
40847 - 0 0 0 0 0 0 0 0 0 6 6 6
40848 - 26 26 26 70 70 70 163 133 67 210 150 10
40849 -236 178 12 246 190 14 246 190 14 246 190 14
40850 -246 190 14 246 190 14 246 190 14 246 190 14
40851 -246 190 14 246 190 14 246 190 14 246 190 14
40852 -246 190 14 246 190 14 246 190 14 246 190 14
40853 -232 195 16 121 92 8 34 34 34 106 106 106
40854 -221 221 221 253 253 253 253 253 253 253 253 253
40855 -253 253 253 253 253 253 253 253 253 253 253 253
40856 -253 253 253 253 253 253 253 253 253 253 253 253
40857 -253 253 253 253 253 253 253 253 253 253 253 253
40858 -242 242 242 82 82 82 18 14 6 163 110 8
40859 -216 158 10 236 178 12 242 186 14 246 190 14
40860 -246 190 14 246 190 14 246 190 14 246 190 14
40861 -246 190 14 246 190 14 246 190 14 246 190 14
40862 -246 190 14 246 190 14 246 190 14 246 190 14
40863 -246 190 14 246 190 14 242 186 14 163 133 67
40864 - 46 46 46 18 18 18 6 6 6 0 0 0
40865 - 0 0 0 0 0 0 0 0 0 0 0 0
40866 - 0 0 0 0 0 0 0 0 0 0 0 0
40867 - 0 0 0 0 0 0 0 0 0 10 10 10
40868 - 30 30 30 78 78 78 163 133 67 210 150 10
40869 -236 178 12 246 186 14 246 190 14 246 190 14
40870 -246 190 14 246 190 14 246 190 14 246 190 14
40871 -246 190 14 246 190 14 246 190 14 246 190 14
40872 -246 190 14 246 190 14 246 190 14 246 190 14
40873 -241 196 14 215 174 15 190 178 144 253 253 253
40874 -253 253 253 253 253 253 253 253 253 253 253 253
40875 -253 253 253 253 253 253 253 253 253 253 253 253
40876 -253 253 253 253 253 253 253 253 253 253 253 253
40877 -253 253 253 253 253 253 253 253 253 218 218 218
40878 - 58 58 58 2 2 6 22 18 6 167 114 7
40879 -216 158 10 236 178 12 246 186 14 246 190 14
40880 -246 190 14 246 190 14 246 190 14 246 190 14
40881 -246 190 14 246 190 14 246 190 14 246 190 14
40882 -246 190 14 246 190 14 246 190 14 246 190 14
40883 -246 190 14 246 186 14 242 186 14 190 150 46
40884 - 54 54 54 22 22 22 6 6 6 0 0 0
40885 - 0 0 0 0 0 0 0 0 0 0 0 0
40886 - 0 0 0 0 0 0 0 0 0 0 0 0
40887 - 0 0 0 0 0 0 0 0 0 14 14 14
40888 - 38 38 38 86 86 86 180 133 36 213 154 11
40889 -236 178 12 246 186 14 246 190 14 246 190 14
40890 -246 190 14 246 190 14 246 190 14 246 190 14
40891 -246 190 14 246 190 14 246 190 14 246 190 14
40892 -246 190 14 246 190 14 246 190 14 246 190 14
40893 -246 190 14 232 195 16 190 146 13 214 214 214
40894 -253 253 253 253 253 253 253 253 253 253 253 253
40895 -253 253 253 253 253 253 253 253 253 253 253 253
40896 -253 253 253 253 253 253 253 253 253 253 253 253
40897 -253 253 253 250 250 250 170 170 170 26 26 26
40898 - 2 2 6 2 2 6 37 26 9 163 110 8
40899 -219 162 10 239 182 13 246 186 14 246 190 14
40900 -246 190 14 246 190 14 246 190 14 246 190 14
40901 -246 190 14 246 190 14 246 190 14 246 190 14
40902 -246 190 14 246 190 14 246 190 14 246 190 14
40903 -246 186 14 236 178 12 224 166 10 142 122 72
40904 - 46 46 46 18 18 18 6 6 6 0 0 0
40905 - 0 0 0 0 0 0 0 0 0 0 0 0
40906 - 0 0 0 0 0 0 0 0 0 0 0 0
40907 - 0 0 0 0 0 0 6 6 6 18 18 18
40908 - 50 50 50 109 106 95 192 133 9 224 166 10
40909 -242 186 14 246 190 14 246 190 14 246 190 14
40910 -246 190 14 246 190 14 246 190 14 246 190 14
40911 -246 190 14 246 190 14 246 190 14 246 190 14
40912 -246 190 14 246 190 14 246 190 14 246 190 14
40913 -242 186 14 226 184 13 210 162 10 142 110 46
40914 -226 226 226 253 253 253 253 253 253 253 253 253
40915 -253 253 253 253 253 253 253 253 253 253 253 253
40916 -253 253 253 253 253 253 253 253 253 253 253 253
40917 -198 198 198 66 66 66 2 2 6 2 2 6
40918 - 2 2 6 2 2 6 50 34 6 156 107 11
40919 -219 162 10 239 182 13 246 186 14 246 190 14
40920 -246 190 14 246 190 14 246 190 14 246 190 14
40921 -246 190 14 246 190 14 246 190 14 246 190 14
40922 -246 190 14 246 190 14 246 190 14 242 186 14
40923 -234 174 13 213 154 11 154 122 46 66 66 66
40924 - 30 30 30 10 10 10 0 0 0 0 0 0
40925 - 0 0 0 0 0 0 0 0 0 0 0 0
40926 - 0 0 0 0 0 0 0 0 0 0 0 0
40927 - 0 0 0 0 0 0 6 6 6 22 22 22
40928 - 58 58 58 154 121 60 206 145 10 234 174 13
40929 -242 186 14 246 186 14 246 190 14 246 190 14
40930 -246 190 14 246 190 14 246 190 14 246 190 14
40931 -246 190 14 246 190 14 246 190 14 246 190 14
40932 -246 190 14 246 190 14 246 190 14 246 190 14
40933 -246 186 14 236 178 12 210 162 10 163 110 8
40934 - 61 42 6 138 138 138 218 218 218 250 250 250
40935 -253 253 253 253 253 253 253 253 253 250 250 250
40936 -242 242 242 210 210 210 144 144 144 66 66 66
40937 - 6 6 6 2 2 6 2 2 6 2 2 6
40938 - 2 2 6 2 2 6 61 42 6 163 110 8
40939 -216 158 10 236 178 12 246 190 14 246 190 14
40940 -246 190 14 246 190 14 246 190 14 246 190 14
40941 -246 190 14 246 190 14 246 190 14 246 190 14
40942 -246 190 14 239 182 13 230 174 11 216 158 10
40943 -190 142 34 124 112 88 70 70 70 38 38 38
40944 - 18 18 18 6 6 6 0 0 0 0 0 0
40945 - 0 0 0 0 0 0 0 0 0 0 0 0
40946 - 0 0 0 0 0 0 0 0 0 0 0 0
40947 - 0 0 0 0 0 0 6 6 6 22 22 22
40948 - 62 62 62 168 124 44 206 145 10 224 166 10
40949 -236 178 12 239 182 13 242 186 14 242 186 14
40950 -246 186 14 246 190 14 246 190 14 246 190 14
40951 -246 190 14 246 190 14 246 190 14 246 190 14
40952 -246 190 14 246 190 14 246 190 14 246 190 14
40953 -246 190 14 236 178 12 216 158 10 175 118 6
40954 - 80 54 7 2 2 6 6 6 6 30 30 30
40955 - 54 54 54 62 62 62 50 50 50 38 38 38
40956 - 14 14 14 2 2 6 2 2 6 2 2 6
40957 - 2 2 6 2 2 6 2 2 6 2 2 6
40958 - 2 2 6 6 6 6 80 54 7 167 114 7
40959 -213 154 11 236 178 12 246 190 14 246 190 14
40960 -246 190 14 246 190 14 246 190 14 246 190 14
40961 -246 190 14 242 186 14 239 182 13 239 182 13
40962 -230 174 11 210 150 10 174 135 50 124 112 88
40963 - 82 82 82 54 54 54 34 34 34 18 18 18
40964 - 6 6 6 0 0 0 0 0 0 0 0 0
40965 - 0 0 0 0 0 0 0 0 0 0 0 0
40966 - 0 0 0 0 0 0 0 0 0 0 0 0
40967 - 0 0 0 0 0 0 6 6 6 18 18 18
40968 - 50 50 50 158 118 36 192 133 9 200 144 11
40969 -216 158 10 219 162 10 224 166 10 226 170 11
40970 -230 174 11 236 178 12 239 182 13 239 182 13
40971 -242 186 14 246 186 14 246 190 14 246 190 14
40972 -246 190 14 246 190 14 246 190 14 246 190 14
40973 -246 186 14 230 174 11 210 150 10 163 110 8
40974 -104 69 6 10 10 10 2 2 6 2 2 6
40975 - 2 2 6 2 2 6 2 2 6 2 2 6
40976 - 2 2 6 2 2 6 2 2 6 2 2 6
40977 - 2 2 6 2 2 6 2 2 6 2 2 6
40978 - 2 2 6 6 6 6 91 60 6 167 114 7
40979 -206 145 10 230 174 11 242 186 14 246 190 14
40980 -246 190 14 246 190 14 246 186 14 242 186 14
40981 -239 182 13 230 174 11 224 166 10 213 154 11
40982 -180 133 36 124 112 88 86 86 86 58 58 58
40983 - 38 38 38 22 22 22 10 10 10 6 6 6
40984 - 0 0 0 0 0 0 0 0 0 0 0 0
40985 - 0 0 0 0 0 0 0 0 0 0 0 0
40986 - 0 0 0 0 0 0 0 0 0 0 0 0
40987 - 0 0 0 0 0 0 0 0 0 14 14 14
40988 - 34 34 34 70 70 70 138 110 50 158 118 36
40989 -167 114 7 180 123 7 192 133 9 197 138 11
40990 -200 144 11 206 145 10 213 154 11 219 162 10
40991 -224 166 10 230 174 11 239 182 13 242 186 14
40992 -246 186 14 246 186 14 246 186 14 246 186 14
40993 -239 182 13 216 158 10 185 133 11 152 99 6
40994 -104 69 6 18 14 6 2 2 6 2 2 6
40995 - 2 2 6 2 2 6 2 2 6 2 2 6
40996 - 2 2 6 2 2 6 2 2 6 2 2 6
40997 - 2 2 6 2 2 6 2 2 6 2 2 6
40998 - 2 2 6 6 6 6 80 54 7 152 99 6
40999 -192 133 9 219 162 10 236 178 12 239 182 13
41000 -246 186 14 242 186 14 239 182 13 236 178 12
41001 -224 166 10 206 145 10 192 133 9 154 121 60
41002 - 94 94 94 62 62 62 42 42 42 22 22 22
41003 - 14 14 14 6 6 6 0 0 0 0 0 0
41004 - 0 0 0 0 0 0 0 0 0 0 0 0
41005 - 0 0 0 0 0 0 0 0 0 0 0 0
41006 - 0 0 0 0 0 0 0 0 0 0 0 0
41007 - 0 0 0 0 0 0 0 0 0 6 6 6
41008 - 18 18 18 34 34 34 58 58 58 78 78 78
41009 -101 98 89 124 112 88 142 110 46 156 107 11
41010 -163 110 8 167 114 7 175 118 6 180 123 7
41011 -185 133 11 197 138 11 210 150 10 219 162 10
41012 -226 170 11 236 178 12 236 178 12 234 174 13
41013 -219 162 10 197 138 11 163 110 8 130 83 6
41014 - 91 60 6 10 10 10 2 2 6 2 2 6
41015 - 18 18 18 38 38 38 38 38 38 38 38 38
41016 - 38 38 38 38 38 38 38 38 38 38 38 38
41017 - 38 38 38 38 38 38 26 26 26 2 2 6
41018 - 2 2 6 6 6 6 70 47 6 137 92 6
41019 -175 118 6 200 144 11 219 162 10 230 174 11
41020 -234 174 13 230 174 11 219 162 10 210 150 10
41021 -192 133 9 163 110 8 124 112 88 82 82 82
41022 - 50 50 50 30 30 30 14 14 14 6 6 6
41023 - 0 0 0 0 0 0 0 0 0 0 0 0
41024 - 0 0 0 0 0 0 0 0 0 0 0 0
41025 - 0 0 0 0 0 0 0 0 0 0 0 0
41026 - 0 0 0 0 0 0 0 0 0 0 0 0
41027 - 0 0 0 0 0 0 0 0 0 0 0 0
41028 - 6 6 6 14 14 14 22 22 22 34 34 34
41029 - 42 42 42 58 58 58 74 74 74 86 86 86
41030 -101 98 89 122 102 70 130 98 46 121 87 25
41031 -137 92 6 152 99 6 163 110 8 180 123 7
41032 -185 133 11 197 138 11 206 145 10 200 144 11
41033 -180 123 7 156 107 11 130 83 6 104 69 6
41034 - 50 34 6 54 54 54 110 110 110 101 98 89
41035 - 86 86 86 82 82 82 78 78 78 78 78 78
41036 - 78 78 78 78 78 78 78 78 78 78 78 78
41037 - 78 78 78 82 82 82 86 86 86 94 94 94
41038 -106 106 106 101 101 101 86 66 34 124 80 6
41039 -156 107 11 180 123 7 192 133 9 200 144 11
41040 -206 145 10 200 144 11 192 133 9 175 118 6
41041 -139 102 15 109 106 95 70 70 70 42 42 42
41042 - 22 22 22 10 10 10 0 0 0 0 0 0
41043 - 0 0 0 0 0 0 0 0 0 0 0 0
41044 - 0 0 0 0 0 0 0 0 0 0 0 0
41045 - 0 0 0 0 0 0 0 0 0 0 0 0
41046 - 0 0 0 0 0 0 0 0 0 0 0 0
41047 - 0 0 0 0 0 0 0 0 0 0 0 0
41048 - 0 0 0 0 0 0 6 6 6 10 10 10
41049 - 14 14 14 22 22 22 30 30 30 38 38 38
41050 - 50 50 50 62 62 62 74 74 74 90 90 90
41051 -101 98 89 112 100 78 121 87 25 124 80 6
41052 -137 92 6 152 99 6 152 99 6 152 99 6
41053 -138 86 6 124 80 6 98 70 6 86 66 30
41054 -101 98 89 82 82 82 58 58 58 46 46 46
41055 - 38 38 38 34 34 34 34 34 34 34 34 34
41056 - 34 34 34 34 34 34 34 34 34 34 34 34
41057 - 34 34 34 34 34 34 38 38 38 42 42 42
41058 - 54 54 54 82 82 82 94 86 76 91 60 6
41059 -134 86 6 156 107 11 167 114 7 175 118 6
41060 -175 118 6 167 114 7 152 99 6 121 87 25
41061 -101 98 89 62 62 62 34 34 34 18 18 18
41062 - 6 6 6 0 0 0 0 0 0 0 0 0
41063 - 0 0 0 0 0 0 0 0 0 0 0 0
41064 - 0 0 0 0 0 0 0 0 0 0 0 0
41065 - 0 0 0 0 0 0 0 0 0 0 0 0
41066 - 0 0 0 0 0 0 0 0 0 0 0 0
41067 - 0 0 0 0 0 0 0 0 0 0 0 0
41068 - 0 0 0 0 0 0 0 0 0 0 0 0
41069 - 0 0 0 6 6 6 6 6 6 10 10 10
41070 - 18 18 18 22 22 22 30 30 30 42 42 42
41071 - 50 50 50 66 66 66 86 86 86 101 98 89
41072 -106 86 58 98 70 6 104 69 6 104 69 6
41073 -104 69 6 91 60 6 82 62 34 90 90 90
41074 - 62 62 62 38 38 38 22 22 22 14 14 14
41075 - 10 10 10 10 10 10 10 10 10 10 10 10
41076 - 10 10 10 10 10 10 6 6 6 10 10 10
41077 - 10 10 10 10 10 10 10 10 10 14 14 14
41078 - 22 22 22 42 42 42 70 70 70 89 81 66
41079 - 80 54 7 104 69 6 124 80 6 137 92 6
41080 -134 86 6 116 81 8 100 82 52 86 86 86
41081 - 58 58 58 30 30 30 14 14 14 6 6 6
41082 - 0 0 0 0 0 0 0 0 0 0 0 0
41083 - 0 0 0 0 0 0 0 0 0 0 0 0
41084 - 0 0 0 0 0 0 0 0 0 0 0 0
41085 - 0 0 0 0 0 0 0 0 0 0 0 0
41086 - 0 0 0 0 0 0 0 0 0 0 0 0
41087 - 0 0 0 0 0 0 0 0 0 0 0 0
41088 - 0 0 0 0 0 0 0 0 0 0 0 0
41089 - 0 0 0 0 0 0 0 0 0 0 0 0
41090 - 0 0 0 6 6 6 10 10 10 14 14 14
41091 - 18 18 18 26 26 26 38 38 38 54 54 54
41092 - 70 70 70 86 86 86 94 86 76 89 81 66
41093 - 89 81 66 86 86 86 74 74 74 50 50 50
41094 - 30 30 30 14 14 14 6 6 6 0 0 0
41095 - 0 0 0 0 0 0 0 0 0 0 0 0
41096 - 0 0 0 0 0 0 0 0 0 0 0 0
41097 - 0 0 0 0 0 0 0 0 0 0 0 0
41098 - 6 6 6 18 18 18 34 34 34 58 58 58
41099 - 82 82 82 89 81 66 89 81 66 89 81 66
41100 - 94 86 66 94 86 76 74 74 74 50 50 50
41101 - 26 26 26 14 14 14 6 6 6 0 0 0
41102 - 0 0 0 0 0 0 0 0 0 0 0 0
41103 - 0 0 0 0 0 0 0 0 0 0 0 0
41104 - 0 0 0 0 0 0 0 0 0 0 0 0
41105 - 0 0 0 0 0 0 0 0 0 0 0 0
41106 - 0 0 0 0 0 0 0 0 0 0 0 0
41107 - 0 0 0 0 0 0 0 0 0 0 0 0
41108 - 0 0 0 0 0 0 0 0 0 0 0 0
41109 - 0 0 0 0 0 0 0 0 0 0 0 0
41110 - 0 0 0 0 0 0 0 0 0 0 0 0
41111 - 6 6 6 6 6 6 14 14 14 18 18 18
41112 - 30 30 30 38 38 38 46 46 46 54 54 54
41113 - 50 50 50 42 42 42 30 30 30 18 18 18
41114 - 10 10 10 0 0 0 0 0 0 0 0 0
41115 - 0 0 0 0 0 0 0 0 0 0 0 0
41116 - 0 0 0 0 0 0 0 0 0 0 0 0
41117 - 0 0 0 0 0 0 0 0 0 0 0 0
41118 - 0 0 0 6 6 6 14 14 14 26 26 26
41119 - 38 38 38 50 50 50 58 58 58 58 58 58
41120 - 54 54 54 42 42 42 30 30 30 18 18 18
41121 - 10 10 10 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 0 0 0 0 0 0
41123 - 0 0 0 0 0 0 0 0 0 0 0 0
41124 - 0 0 0 0 0 0 0 0 0 0 0 0
41125 - 0 0 0 0 0 0 0 0 0 0 0 0
41126 - 0 0 0 0 0 0 0 0 0 0 0 0
41127 - 0 0 0 0 0 0 0 0 0 0 0 0
41128 - 0 0 0 0 0 0 0 0 0 0 0 0
41129 - 0 0 0 0 0 0 0 0 0 0 0 0
41130 - 0 0 0 0 0 0 0 0 0 0 0 0
41131 - 0 0 0 0 0 0 0 0 0 6 6 6
41132 - 6 6 6 10 10 10 14 14 14 18 18 18
41133 - 18 18 18 14 14 14 10 10 10 6 6 6
41134 - 0 0 0 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 0 0 0 0 0 0
41136 - 0 0 0 0 0 0 0 0 0 0 0 0
41137 - 0 0 0 0 0 0 0 0 0 0 0 0
41138 - 0 0 0 0 0 0 0 0 0 6 6 6
41139 - 14 14 14 18 18 18 22 22 22 22 22 22
41140 - 18 18 18 14 14 14 10 10 10 6 6 6
41141 - 0 0 0 0 0 0 0 0 0 0 0 0
41142 - 0 0 0 0 0 0 0 0 0 0 0 0
41143 - 0 0 0 0 0 0 0 0 0 0 0 0
41144 - 0 0 0 0 0 0 0 0 0 0 0 0
41145 - 0 0 0 0 0 0 0 0 0 0 0 0
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41159 +4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173 +4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187 +4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215 +4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229 +4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41235 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41240 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41249 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41250 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41253 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41254 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41255 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41256 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41262 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41263 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41264 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41267 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41268 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41269 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41270 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41275 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41276 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41277 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41278 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41281 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41282 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41283 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41284 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41285 +4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41289 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41290 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41291 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41292 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41293 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41295 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41296 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41297 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41298 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41303 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41304 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41305 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41306 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41307 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41308 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41309 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41310 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41311 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41312 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41313 +4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41317 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41318 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41319 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41320 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41321 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41322 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41323 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41324 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41325 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41326 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41331 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41332 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41333 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41334 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41335 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41336 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41337 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41338 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41339 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41340 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41345 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41346 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41347 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41348 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41349 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41350 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41351 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41352 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41353 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41354 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41359 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41360 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41361 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41362 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41363 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41364 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41365 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41366 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41367 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41368 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41369 +4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41372 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41373 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41374 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41375 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41376 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41377 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41378 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41379 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41380 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41381 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41382 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41383 +4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41386 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41387 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41388 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41389 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41390 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41391 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41392 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41393 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41394 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41395 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41396 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41397 +0 0 0 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41399 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41400 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41401 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41402 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41403 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41404 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41405 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41406 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41407 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41408 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41409 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41410 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41411 +2 0 0 0 0 0
41412 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41413 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41414 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41415 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41416 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41417 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41418 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41419 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41420 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41421 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41422 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41423 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41424 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41425 +37 38 37 0 0 0
41426 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41427 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41428 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41429 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41430 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41431 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41432 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41433 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41434 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41435 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41436 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41437 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41438 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41439 +85 115 134 4 0 0
41440 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41441 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41442 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41443 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41444 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41445 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41446 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41447 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41448 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41449 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41450 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41451 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41452 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41453 +60 73 81 4 0 0
41454 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41455 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41456 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41457 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41458 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41459 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41460 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41461 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41462 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41463 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41464 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41465 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41466 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41467 +16 19 21 4 0 0
41468 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41469 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41470 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41471 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41472 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41473 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41474 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41475 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41476 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41477 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41478 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41479 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41480 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41481 +4 0 0 4 3 3
41482 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41483 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41484 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41486 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41487 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41488 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41489 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41490 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41491 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41492 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41493 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41494 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41495 +3 2 2 4 4 4
41496 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41497 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41498 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41499 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41500 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41501 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41502 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41503 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41504 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41505 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41506 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41507 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41508 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41509 +4 4 4 4 4 4
41510 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41511 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41512 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41513 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41514 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41515 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41516 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41517 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41518 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41519 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41520 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41521 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41522 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41523 +4 4 4 4 4 4
41524 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41525 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41526 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41527 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41528 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41529 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41530 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41531 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41532 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41533 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41534 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41535 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41536 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41537 +5 5 5 5 5 5
41538 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41539 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41540 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41541 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41542 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41543 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41544 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41545 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41546 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41547 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41548 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41549 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41550 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41551 +5 5 5 4 4 4
41552 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41553 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41554 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41555 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41556 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41557 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41558 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41559 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41560 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41561 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41562 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41563 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565 +4 4 4 4 4 4
41566 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41567 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41568 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41569 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41570 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41571 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41572 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41573 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41574 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41575 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41576 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41577 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41579 +4 4 4 4 4 4
41580 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41581 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41582 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41583 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41584 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41585 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41586 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41587 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41588 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41589 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41590 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593 +4 4 4 4 4 4
41594 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41595 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41596 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41597 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41598 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41599 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41600 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41601 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41602 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41603 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41604 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607 +4 4 4 4 4 4
41608 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41609 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41610 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41611 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41612 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41613 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41614 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41615 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41616 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41617 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41618 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621 +4 4 4 4 4 4
41622 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41623 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41624 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41625 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41626 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41627 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41628 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41629 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41630 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41631 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41632 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635 +4 4 4 4 4 4
41636 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41637 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41638 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41639 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41640 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41641 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41642 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41643 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41644 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41645 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41646 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649 +4 4 4 4 4 4
41650 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41651 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41652 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41653 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41654 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41655 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41656 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41657 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41658 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41659 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41660 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663 +4 4 4 4 4 4
41664 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41665 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41666 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41667 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41668 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41669 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41670 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41671 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41672 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41673 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41674 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4
41678 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41679 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41680 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41681 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41682 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41683 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41684 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41685 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41686 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41687 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41688 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691 +4 4 4 4 4 4
41692 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41693 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41694 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41695 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41696 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41697 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41698 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41699 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41700 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41701 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41702 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705 +4 4 4 4 4 4
41706 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41707 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41708 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41709 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41710 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41711 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41712 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41713 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41714 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41715 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41716 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719 +4 4 4 4 4 4
41720 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41721 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41722 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41723 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41724 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41725 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41726 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41727 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41728 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41729 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41730 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733 +4 4 4 4 4 4
41734 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41735 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41736 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41737 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41738 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41739 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41740 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41741 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41742 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41743 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41744 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747 +4 4 4 4 4 4
41748 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41749 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41750 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41751 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41752 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41753 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41754 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41755 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41756 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41757 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41758 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761 +4 4 4 4 4 4
41762 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41763 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41764 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41765 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41766 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41767 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41768 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41769 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41770 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41771 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41772 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 4 4 4
41776 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41777 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41778 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41779 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41780 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41781 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41782 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41783 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41784 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41785 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41786 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 4 4 4
41790 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41791 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41792 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41793 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41794 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41795 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41796 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41797 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41798 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41799 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41800 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803 +4 4 4 4 4 4
41804 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41805 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41806 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41807 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41808 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41809 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41810 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41811 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41812 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41813 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41814 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817 +4 4 4 4 4 4
41818 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41819 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41820 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41821 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41822 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41823 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41824 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41825 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41826 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41827 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41828 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41831 +4 4 4 4 4 4
41832 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41833 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41834 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41835 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41836 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41837 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41838 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41839 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41840 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41841 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41842 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41845 +4 4 4 4 4 4
41846 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41847 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41848 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41849 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41850 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41851 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41852 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41853 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41854 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41855 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41856 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41859 +4 4 4 4 4 4
41860 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41861 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41862 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41863 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41864 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41865 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41866 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41867 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41868 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41869 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41870 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41873 +4 4 4 4 4 4
41874 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41875 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41876 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41877 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41878 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41879 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41880 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41881 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41882 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41883 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41884 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41887 +4 4 4 4 4 4
41888 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41889 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41890 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41891 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41892 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41893 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41894 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41895 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41896 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41897 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41898 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41901 +4 4 4 4 4 4
41902 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41903 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41904 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41905 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41906 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41907 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41908 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41909 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41910 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41911 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41912 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41915 +4 4 4 4 4 4
41916 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41917 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41918 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41919 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41920 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41921 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41922 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41923 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41924 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41925 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41926 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41929 +4 4 4 4 4 4
41930 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41931 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41932 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41933 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41934 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41935 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41936 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41937 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41938 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41939 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41940 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41943 +4 4 4 4 4 4
41944 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41945 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41946 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41947 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41948 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41949 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41950 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41951 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41952 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41953 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41954 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41957 +4 4 4 4 4 4
41958 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41959 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41960 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41961 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41962 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41963 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41964 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41965 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41966 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41967 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41971 +4 4 4 4 4 4
41972 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41973 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41974 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41975 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41976 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41977 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41978 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41979 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41980 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41981 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41985 +4 4 4 4 4 4
41986 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41987 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41988 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41989 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41990 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41991 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41992 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41993 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41994 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41995 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41999 +4 4 4 4 4 4
42000 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42001 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42002 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42003 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42004 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42005 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42006 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42007 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42008 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42009 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42013 +4 4 4 4 4 4
42014 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42015 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42016 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42017 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42018 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42019 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42020 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42021 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42022 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42027 +4 4 4 4 4 4
42028 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42029 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42030 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42031 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42032 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42033 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42034 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42035 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42036 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42041 +4 4 4 4 4 4
42042 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42043 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42044 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42045 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42046 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42047 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42048 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42049 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42050 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42055 +4 4 4 4 4 4
42056 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42057 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42058 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42059 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42060 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42061 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42062 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42063 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42069 +4 4 4 4 4 4
42070 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42071 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42072 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42073 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42074 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42075 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42076 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42077 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42083 +4 4 4 4 4 4
42084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42085 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42086 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42087 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42088 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42089 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42090 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42091 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42097 +4 4 4 4 4 4
42098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42099 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42100 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42101 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42102 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42103 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42104 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42105 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42111 +4 4 4 4 4 4
42112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42113 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42114 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42115 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42116 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42117 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42118 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42119 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42125 +4 4 4 4 4 4
42126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42128 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42129 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42130 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42131 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42132 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42133 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42139 +4 4 4 4 4 4
42140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42143 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42144 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42145 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42146 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42153 +4 4 4 4 4 4
42154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42157 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42158 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42159 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42160 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42167 +4 4 4 4 4 4
42168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42171 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42172 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42173 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42174 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42181 +4 4 4 4 4 4
42182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42185 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42186 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42187 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42188 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42195 +4 4 4 4 4 4
42196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42200 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42201 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42202 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42209 +4 4 4 4 4 4
42210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42215 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42216 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42223 +4 4 4 4 4 4
42224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42229 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42230 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42237 +4 4 4 4 4 4
42238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42243 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251 +4 4 4 4 4 4
42252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42257 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42265 +4 4 4 4 4 4
42266 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42267 index 38fcfff..0072dcd 100644
42268 --- a/drivers/video/udlfb.c
42269 +++ b/drivers/video/udlfb.c
42270 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42271 dlfb_urb_completion(urb);
42272
42273 error:
42274 - atomic_add(bytes_sent, &dev->bytes_sent);
42275 - atomic_add(bytes_identical, &dev->bytes_identical);
42276 - atomic_add(width*height*2, &dev->bytes_rendered);
42277 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42278 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42279 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42280 end_cycles = get_cycles();
42281 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42282 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42283 >> 10)), /* Kcycles */
42284 &dev->cpu_kcycles_used);
42285
42286 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42287 dlfb_urb_completion(urb);
42288
42289 error:
42290 - atomic_add(bytes_sent, &dev->bytes_sent);
42291 - atomic_add(bytes_identical, &dev->bytes_identical);
42292 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42293 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42294 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42295 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42296 end_cycles = get_cycles();
42297 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42298 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42299 >> 10)), /* Kcycles */
42300 &dev->cpu_kcycles_used);
42301 }
42302 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42303 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42304 struct dlfb_data *dev = fb_info->par;
42305 return snprintf(buf, PAGE_SIZE, "%u\n",
42306 - atomic_read(&dev->bytes_rendered));
42307 + atomic_read_unchecked(&dev->bytes_rendered));
42308 }
42309
42310 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42311 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42312 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42313 struct dlfb_data *dev = fb_info->par;
42314 return snprintf(buf, PAGE_SIZE, "%u\n",
42315 - atomic_read(&dev->bytes_identical));
42316 + atomic_read_unchecked(&dev->bytes_identical));
42317 }
42318
42319 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42320 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42321 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42322 struct dlfb_data *dev = fb_info->par;
42323 return snprintf(buf, PAGE_SIZE, "%u\n",
42324 - atomic_read(&dev->bytes_sent));
42325 + atomic_read_unchecked(&dev->bytes_sent));
42326 }
42327
42328 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42329 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42330 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42331 struct dlfb_data *dev = fb_info->par;
42332 return snprintf(buf, PAGE_SIZE, "%u\n",
42333 - atomic_read(&dev->cpu_kcycles_used));
42334 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42335 }
42336
42337 static ssize_t edid_show(
42338 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42339 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42340 struct dlfb_data *dev = fb_info->par;
42341
42342 - atomic_set(&dev->bytes_rendered, 0);
42343 - atomic_set(&dev->bytes_identical, 0);
42344 - atomic_set(&dev->bytes_sent, 0);
42345 - atomic_set(&dev->cpu_kcycles_used, 0);
42346 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42347 + atomic_set_unchecked(&dev->bytes_identical, 0);
42348 + atomic_set_unchecked(&dev->bytes_sent, 0);
42349 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42350
42351 return count;
42352 }
42353 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42354 index b0e2a42..e2df3ad 100644
42355 --- a/drivers/video/uvesafb.c
42356 +++ b/drivers/video/uvesafb.c
42357 @@ -19,6 +19,7 @@
42358 #include <linux/io.h>
42359 #include <linux/mutex.h>
42360 #include <linux/slab.h>
42361 +#include <linux/moduleloader.h>
42362 #include <video/edid.h>
42363 #include <video/uvesafb.h>
42364 #ifdef CONFIG_X86
42365 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42366 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42367 par->pmi_setpal = par->ypan = 0;
42368 } else {
42369 +
42370 +#ifdef CONFIG_PAX_KERNEXEC
42371 +#ifdef CONFIG_MODULES
42372 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42373 +#endif
42374 + if (!par->pmi_code) {
42375 + par->pmi_setpal = par->ypan = 0;
42376 + return 0;
42377 + }
42378 +#endif
42379 +
42380 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42381 + task->t.regs.edi);
42382 +
42383 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42384 + pax_open_kernel();
42385 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42386 + pax_close_kernel();
42387 +
42388 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42389 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42390 +#else
42391 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42392 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42393 +#endif
42394 +
42395 printk(KERN_INFO "uvesafb: protected mode interface info at "
42396 "%04x:%04x\n",
42397 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42398 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42399 par->ypan = ypan;
42400
42401 if (par->pmi_setpal || par->ypan) {
42402 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42403 if (__supported_pte_mask & _PAGE_NX) {
42404 par->pmi_setpal = par->ypan = 0;
42405 printk(KERN_WARNING "uvesafb: NX protection is actively."
42406 "We have better not to use the PMI.\n");
42407 - } else {
42408 + } else
42409 +#endif
42410 uvesafb_vbe_getpmi(task, par);
42411 - }
42412 }
42413 #else
42414 /* The protected mode interface is not available on non-x86. */
42415 @@ -1836,6 +1860,11 @@ out:
42416 if (par->vbe_modes)
42417 kfree(par->vbe_modes);
42418
42419 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42420 + if (par->pmi_code)
42421 + module_free_exec(NULL, par->pmi_code);
42422 +#endif
42423 +
42424 framebuffer_release(info);
42425 return err;
42426 }
42427 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42428 kfree(par->vbe_state_orig);
42429 if (par->vbe_state_saved)
42430 kfree(par->vbe_state_saved);
42431 +
42432 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42433 + if (par->pmi_code)
42434 + module_free_exec(NULL, par->pmi_code);
42435 +#endif
42436 +
42437 }
42438
42439 framebuffer_release(info);
42440 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42441 index 501b340..86bd4cf 100644
42442 --- a/drivers/video/vesafb.c
42443 +++ b/drivers/video/vesafb.c
42444 @@ -9,6 +9,7 @@
42445 */
42446
42447 #include <linux/module.h>
42448 +#include <linux/moduleloader.h>
42449 #include <linux/kernel.h>
42450 #include <linux/errno.h>
42451 #include <linux/string.h>
42452 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42453 static int vram_total __initdata; /* Set total amount of memory */
42454 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42455 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42456 -static void (*pmi_start)(void) __read_mostly;
42457 -static void (*pmi_pal) (void) __read_mostly;
42458 +static void (*pmi_start)(void) __read_only;
42459 +static void (*pmi_pal) (void) __read_only;
42460 static int depth __read_mostly;
42461 static int vga_compat __read_mostly;
42462 /* --------------------------------------------------------------------- */
42463 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42464 unsigned int size_vmode;
42465 unsigned int size_remap;
42466 unsigned int size_total;
42467 + void *pmi_code = NULL;
42468
42469 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42470 return -ENODEV;
42471 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42472 size_remap = size_total;
42473 vesafb_fix.smem_len = size_remap;
42474
42475 -#ifndef __i386__
42476 - screen_info.vesapm_seg = 0;
42477 -#endif
42478 -
42479 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42480 printk(KERN_WARNING
42481 "vesafb: cannot reserve video memory at 0x%lx\n",
42482 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42483 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42484 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42485
42486 +#ifdef __i386__
42487 +
42488 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42489 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42490 + if (!pmi_code)
42491 +#elif !defined(CONFIG_PAX_KERNEXEC)
42492 + if (0)
42493 +#endif
42494 +
42495 +#endif
42496 + screen_info.vesapm_seg = 0;
42497 +
42498 if (screen_info.vesapm_seg) {
42499 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42500 - screen_info.vesapm_seg,screen_info.vesapm_off);
42501 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42502 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42503 }
42504
42505 if (screen_info.vesapm_seg < 0xc000)
42506 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42507
42508 if (ypan || pmi_setpal) {
42509 unsigned short *pmi_base;
42510 +
42511 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42512 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42513 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42514 +
42515 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42516 + pax_open_kernel();
42517 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42518 +#else
42519 + pmi_code = pmi_base;
42520 +#endif
42521 +
42522 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42523 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42524 +
42525 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42526 + pmi_start = ktva_ktla(pmi_start);
42527 + pmi_pal = ktva_ktla(pmi_pal);
42528 + pax_close_kernel();
42529 +#endif
42530 +
42531 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42532 if (pmi_base[3]) {
42533 printk(KERN_INFO "vesafb: pmi: ports = ");
42534 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42535 info->node, info->fix.id);
42536 return 0;
42537 err:
42538 +
42539 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42540 + module_free_exec(NULL, pmi_code);
42541 +#endif
42542 +
42543 if (info->screen_base)
42544 iounmap(info->screen_base);
42545 framebuffer_release(info);
42546 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42547 index 88714ae..16c2e11 100644
42548 --- a/drivers/video/via/via_clock.h
42549 +++ b/drivers/video/via/via_clock.h
42550 @@ -56,7 +56,7 @@ struct via_clock {
42551
42552 void (*set_engine_pll_state)(u8 state);
42553 void (*set_engine_pll)(struct via_pll_config config);
42554 -};
42555 +} __no_const;
42556
42557
42558 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42559 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42560 index 453db0c..604973e 100644
42561 --- a/drivers/virtio/virtio_mmio.c
42562 +++ b/drivers/virtio/virtio_mmio.c
42563 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42564
42565 resources[0].end = memparse(device, &str) - 1;
42566
42567 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42568 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42569 &base, &resources[1].start, &consumed,
42570 &vm_cmdline_id, &consumed);
42571
42572 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42573 index e56c934..fc22f4b 100644
42574 --- a/drivers/xen/xen-pciback/conf_space.h
42575 +++ b/drivers/xen/xen-pciback/conf_space.h
42576 @@ -44,15 +44,15 @@ struct config_field {
42577 struct {
42578 conf_dword_write write;
42579 conf_dword_read read;
42580 - } dw;
42581 + } __no_const dw;
42582 struct {
42583 conf_word_write write;
42584 conf_word_read read;
42585 - } w;
42586 + } __no_const w;
42587 struct {
42588 conf_byte_write write;
42589 conf_byte_read read;
42590 - } b;
42591 + } __no_const b;
42592 } u;
42593 struct list_head list;
42594 };
42595 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42596 index cbf9dbb..35c3af7 100644
42597 --- a/fs/9p/vfs_inode.c
42598 +++ b/fs/9p/vfs_inode.c
42599 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42600 void
42601 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42602 {
42603 - char *s = nd_get_link(nd);
42604 + const char *s = nd_get_link(nd);
42605
42606 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42607 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42608 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42609 index 0225742..1cd4732 100644
42610 --- a/fs/Kconfig.binfmt
42611 +++ b/fs/Kconfig.binfmt
42612 @@ -89,7 +89,7 @@ config HAVE_AOUT
42613
42614 config BINFMT_AOUT
42615 tristate "Kernel support for a.out and ECOFF binaries"
42616 - depends on HAVE_AOUT
42617 + depends on HAVE_AOUT && BROKEN
42618 ---help---
42619 A.out (Assembler.OUTput) is a set of formats for libraries and
42620 executables used in the earliest versions of UNIX. Linux used
42621 diff --git a/fs/aio.c b/fs/aio.c
42622 index 71f613c..9d01f1f 100644
42623 --- a/fs/aio.c
42624 +++ b/fs/aio.c
42625 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42626 size += sizeof(struct io_event) * nr_events;
42627 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42628
42629 - if (nr_pages < 0)
42630 + if (nr_pages <= 0)
42631 return -EINVAL;
42632
42633 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42634 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42635 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42636 {
42637 ssize_t ret;
42638 + struct iovec iovstack;
42639
42640 #ifdef CONFIG_COMPAT
42641 if (compat)
42642 ret = compat_rw_copy_check_uvector(type,
42643 (struct compat_iovec __user *)kiocb->ki_buf,
42644 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42645 + kiocb->ki_nbytes, 1, &iovstack,
42646 &kiocb->ki_iovec);
42647 else
42648 #endif
42649 ret = rw_copy_check_uvector(type,
42650 (struct iovec __user *)kiocb->ki_buf,
42651 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42652 + kiocb->ki_nbytes, 1, &iovstack,
42653 &kiocb->ki_iovec);
42654 if (ret < 0)
42655 goto out;
42656 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42657 if (ret < 0)
42658 goto out;
42659
42660 + if (kiocb->ki_iovec == &iovstack) {
42661 + kiocb->ki_inline_vec = iovstack;
42662 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42663 + }
42664 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42665 kiocb->ki_cur_seg = 0;
42666 /* ki_nbytes/left now reflect bytes instead of segs */
42667 diff --git a/fs/attr.c b/fs/attr.c
42668 index 29e38a1..2bc037b 100644
42669 --- a/fs/attr.c
42670 +++ b/fs/attr.c
42671 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42672 unsigned long limit;
42673
42674 limit = rlimit(RLIMIT_FSIZE);
42675 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42676 if (limit != RLIM_INFINITY && offset > limit)
42677 goto out_sig;
42678 if (offset > inode->i_sb->s_maxbytes)
42679 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42680 index da8876d..4456166 100644
42681 --- a/fs/autofs4/waitq.c
42682 +++ b/fs/autofs4/waitq.c
42683 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42684 {
42685 unsigned long sigpipe, flags;
42686 mm_segment_t fs;
42687 - const char *data = (const char *)addr;
42688 + const char __user *data = (const char __force_user *)addr;
42689 ssize_t wr = 0;
42690
42691 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42692 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42693 return 1;
42694 }
42695
42696 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42697 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42698 +#endif
42699 +
42700 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42701 enum autofs_notify notify)
42702 {
42703 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42704
42705 /* If this is a direct mount request create a dummy name */
42706 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42707 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42708 + /* this name does get written to userland via autofs4_write() */
42709 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42710 +#else
42711 qstr.len = sprintf(name, "%p", dentry);
42712 +#endif
42713 else {
42714 qstr.len = autofs4_getpath(sbi, dentry, &name);
42715 if (!qstr.len) {
42716 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42717 index cf7f3c6..f61080d 100644
42718 --- a/fs/befs/linuxvfs.c
42719 +++ b/fs/befs/linuxvfs.c
42720 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42721 {
42722 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42723 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42724 - char *link = nd_get_link(nd);
42725 + const char *link = nd_get_link(nd);
42726 if (!IS_ERR(link))
42727 kfree(link);
42728 }
42729 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42730 index d146e18..12d1bd1 100644
42731 --- a/fs/binfmt_aout.c
42732 +++ b/fs/binfmt_aout.c
42733 @@ -16,6 +16,7 @@
42734 #include <linux/string.h>
42735 #include <linux/fs.h>
42736 #include <linux/file.h>
42737 +#include <linux/security.h>
42738 #include <linux/stat.h>
42739 #include <linux/fcntl.h>
42740 #include <linux/ptrace.h>
42741 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42742 #endif
42743 # define START_STACK(u) ((void __user *)u.start_stack)
42744
42745 + memset(&dump, 0, sizeof(dump));
42746 +
42747 fs = get_fs();
42748 set_fs(KERNEL_DS);
42749 has_dumped = 1;
42750 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42751
42752 /* If the size of the dump file exceeds the rlimit, then see what would happen
42753 if we wrote the stack, but not the data area. */
42754 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42755 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42756 dump.u_dsize = 0;
42757
42758 /* Make sure we have enough room to write the stack and data areas. */
42759 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42760 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42761 dump.u_ssize = 0;
42762
42763 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42764 rlim = rlimit(RLIMIT_DATA);
42765 if (rlim >= RLIM_INFINITY)
42766 rlim = ~0;
42767 +
42768 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42769 if (ex.a_data + ex.a_bss > rlim)
42770 return -ENOMEM;
42771
42772 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42773
42774 install_exec_creds(bprm);
42775
42776 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42777 + current->mm->pax_flags = 0UL;
42778 +#endif
42779 +
42780 +#ifdef CONFIG_PAX_PAGEEXEC
42781 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42782 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42783 +
42784 +#ifdef CONFIG_PAX_EMUTRAMP
42785 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42786 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42787 +#endif
42788 +
42789 +#ifdef CONFIG_PAX_MPROTECT
42790 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42791 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42792 +#endif
42793 +
42794 + }
42795 +#endif
42796 +
42797 if (N_MAGIC(ex) == OMAGIC) {
42798 unsigned long text_addr, map_size;
42799 loff_t pos;
42800 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42801 }
42802
42803 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42804 - PROT_READ | PROT_WRITE | PROT_EXEC,
42805 + PROT_READ | PROT_WRITE,
42806 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42807 fd_offset + ex.a_text);
42808 if (error != N_DATADDR(ex)) {
42809 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42810 index 0225fdd..9f0ef53 100644
42811 --- a/fs/binfmt_elf.c
42812 +++ b/fs/binfmt_elf.c
42813 @@ -32,6 +32,7 @@
42814 #include <linux/elf.h>
42815 #include <linux/utsname.h>
42816 #include <linux/coredump.h>
42817 +#include <linux/xattr.h>
42818 #include <asm/uaccess.h>
42819 #include <asm/param.h>
42820 #include <asm/page.h>
42821 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42822 #define elf_core_dump NULL
42823 #endif
42824
42825 +#ifdef CONFIG_PAX_MPROTECT
42826 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42827 +#endif
42828 +
42829 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42830 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42831 #else
42832 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42833 .load_binary = load_elf_binary,
42834 .load_shlib = load_elf_library,
42835 .core_dump = elf_core_dump,
42836 +
42837 +#ifdef CONFIG_PAX_MPROTECT
42838 + .handle_mprotect= elf_handle_mprotect,
42839 +#endif
42840 +
42841 .min_coredump = ELF_EXEC_PAGESIZE,
42842 };
42843
42844 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42845
42846 static int set_brk(unsigned long start, unsigned long end)
42847 {
42848 + unsigned long e = end;
42849 +
42850 start = ELF_PAGEALIGN(start);
42851 end = ELF_PAGEALIGN(end);
42852 if (end > start) {
42853 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42854 if (BAD_ADDR(addr))
42855 return addr;
42856 }
42857 - current->mm->start_brk = current->mm->brk = end;
42858 + current->mm->start_brk = current->mm->brk = e;
42859 return 0;
42860 }
42861
42862 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42863 elf_addr_t __user *u_rand_bytes;
42864 const char *k_platform = ELF_PLATFORM;
42865 const char *k_base_platform = ELF_BASE_PLATFORM;
42866 - unsigned char k_rand_bytes[16];
42867 + u32 k_rand_bytes[4];
42868 int items;
42869 elf_addr_t *elf_info;
42870 int ei_index = 0;
42871 const struct cred *cred = current_cred();
42872 struct vm_area_struct *vma;
42873 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42874
42875 /*
42876 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42877 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42878 * Generate 16 random bytes for userspace PRNG seeding.
42879 */
42880 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42881 - u_rand_bytes = (elf_addr_t __user *)
42882 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42883 + srandom32(k_rand_bytes[0] ^ random32());
42884 + srandom32(k_rand_bytes[1] ^ random32());
42885 + srandom32(k_rand_bytes[2] ^ random32());
42886 + srandom32(k_rand_bytes[3] ^ random32());
42887 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42888 + u_rand_bytes = (elf_addr_t __user *) p;
42889 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42890 return -EFAULT;
42891
42892 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42893 return -EFAULT;
42894 current->mm->env_end = p;
42895
42896 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42897 +
42898 /* Put the elf_info on the stack in the right place. */
42899 sp = (elf_addr_t __user *)envp + 1;
42900 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42901 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42902 return -EFAULT;
42903 return 0;
42904 }
42905 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42906 {
42907 struct elf_phdr *elf_phdata;
42908 struct elf_phdr *eppnt;
42909 - unsigned long load_addr = 0;
42910 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42911 int load_addr_set = 0;
42912 unsigned long last_bss = 0, elf_bss = 0;
42913 - unsigned long error = ~0UL;
42914 + unsigned long error = -EINVAL;
42915 unsigned long total_size;
42916 int retval, i, size;
42917
42918 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42919 goto out_close;
42920 }
42921
42922 +#ifdef CONFIG_PAX_SEGMEXEC
42923 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42924 + pax_task_size = SEGMEXEC_TASK_SIZE;
42925 +#endif
42926 +
42927 eppnt = elf_phdata;
42928 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42929 if (eppnt->p_type == PT_LOAD) {
42930 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42931 k = load_addr + eppnt->p_vaddr;
42932 if (BAD_ADDR(k) ||
42933 eppnt->p_filesz > eppnt->p_memsz ||
42934 - eppnt->p_memsz > TASK_SIZE ||
42935 - TASK_SIZE - eppnt->p_memsz < k) {
42936 + eppnt->p_memsz > pax_task_size ||
42937 + pax_task_size - eppnt->p_memsz < k) {
42938 error = -ENOMEM;
42939 goto out_close;
42940 }
42941 @@ -523,6 +547,311 @@ out:
42942 return error;
42943 }
42944
42945 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42946 +#ifdef CONFIG_PAX_SOFTMODE
42947 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42948 +{
42949 + unsigned long pax_flags = 0UL;
42950 +
42951 +#ifdef CONFIG_PAX_PAGEEXEC
42952 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42953 + pax_flags |= MF_PAX_PAGEEXEC;
42954 +#endif
42955 +
42956 +#ifdef CONFIG_PAX_SEGMEXEC
42957 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42958 + pax_flags |= MF_PAX_SEGMEXEC;
42959 +#endif
42960 +
42961 +#ifdef CONFIG_PAX_EMUTRAMP
42962 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42963 + pax_flags |= MF_PAX_EMUTRAMP;
42964 +#endif
42965 +
42966 +#ifdef CONFIG_PAX_MPROTECT
42967 + if (elf_phdata->p_flags & PF_MPROTECT)
42968 + pax_flags |= MF_PAX_MPROTECT;
42969 +#endif
42970 +
42971 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42972 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42973 + pax_flags |= MF_PAX_RANDMMAP;
42974 +#endif
42975 +
42976 + return pax_flags;
42977 +}
42978 +#endif
42979 +
42980 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42981 +{
42982 + unsigned long pax_flags = 0UL;
42983 +
42984 +#ifdef CONFIG_PAX_PAGEEXEC
42985 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42986 + pax_flags |= MF_PAX_PAGEEXEC;
42987 +#endif
42988 +
42989 +#ifdef CONFIG_PAX_SEGMEXEC
42990 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42991 + pax_flags |= MF_PAX_SEGMEXEC;
42992 +#endif
42993 +
42994 +#ifdef CONFIG_PAX_EMUTRAMP
42995 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42996 + pax_flags |= MF_PAX_EMUTRAMP;
42997 +#endif
42998 +
42999 +#ifdef CONFIG_PAX_MPROTECT
43000 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43001 + pax_flags |= MF_PAX_MPROTECT;
43002 +#endif
43003 +
43004 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43005 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43006 + pax_flags |= MF_PAX_RANDMMAP;
43007 +#endif
43008 +
43009 + return pax_flags;
43010 +}
43011 +#endif
43012 +
43013 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43014 +#ifdef CONFIG_PAX_SOFTMODE
43015 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43016 +{
43017 + unsigned long pax_flags = 0UL;
43018 +
43019 +#ifdef CONFIG_PAX_PAGEEXEC
43020 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43021 + pax_flags |= MF_PAX_PAGEEXEC;
43022 +#endif
43023 +
43024 +#ifdef CONFIG_PAX_SEGMEXEC
43025 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43026 + pax_flags |= MF_PAX_SEGMEXEC;
43027 +#endif
43028 +
43029 +#ifdef CONFIG_PAX_EMUTRAMP
43030 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43031 + pax_flags |= MF_PAX_EMUTRAMP;
43032 +#endif
43033 +
43034 +#ifdef CONFIG_PAX_MPROTECT
43035 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43036 + pax_flags |= MF_PAX_MPROTECT;
43037 +#endif
43038 +
43039 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43040 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43041 + pax_flags |= MF_PAX_RANDMMAP;
43042 +#endif
43043 +
43044 + return pax_flags;
43045 +}
43046 +#endif
43047 +
43048 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43049 +{
43050 + unsigned long pax_flags = 0UL;
43051 +
43052 +#ifdef CONFIG_PAX_PAGEEXEC
43053 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43054 + pax_flags |= MF_PAX_PAGEEXEC;
43055 +#endif
43056 +
43057 +#ifdef CONFIG_PAX_SEGMEXEC
43058 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43059 + pax_flags |= MF_PAX_SEGMEXEC;
43060 +#endif
43061 +
43062 +#ifdef CONFIG_PAX_EMUTRAMP
43063 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43064 + pax_flags |= MF_PAX_EMUTRAMP;
43065 +#endif
43066 +
43067 +#ifdef CONFIG_PAX_MPROTECT
43068 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43069 + pax_flags |= MF_PAX_MPROTECT;
43070 +#endif
43071 +
43072 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43073 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43074 + pax_flags |= MF_PAX_RANDMMAP;
43075 +#endif
43076 +
43077 + return pax_flags;
43078 +}
43079 +#endif
43080 +
43081 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43082 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43083 +{
43084 + unsigned long pax_flags = 0UL;
43085 +
43086 +#ifdef CONFIG_PAX_EI_PAX
43087 +
43088 +#ifdef CONFIG_PAX_PAGEEXEC
43089 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43090 + pax_flags |= MF_PAX_PAGEEXEC;
43091 +#endif
43092 +
43093 +#ifdef CONFIG_PAX_SEGMEXEC
43094 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43095 + pax_flags |= MF_PAX_SEGMEXEC;
43096 +#endif
43097 +
43098 +#ifdef CONFIG_PAX_EMUTRAMP
43099 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43100 + pax_flags |= MF_PAX_EMUTRAMP;
43101 +#endif
43102 +
43103 +#ifdef CONFIG_PAX_MPROTECT
43104 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43105 + pax_flags |= MF_PAX_MPROTECT;
43106 +#endif
43107 +
43108 +#ifdef CONFIG_PAX_ASLR
43109 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43110 + pax_flags |= MF_PAX_RANDMMAP;
43111 +#endif
43112 +
43113 +#else
43114 +
43115 +#ifdef CONFIG_PAX_PAGEEXEC
43116 + pax_flags |= MF_PAX_PAGEEXEC;
43117 +#endif
43118 +
43119 +#ifdef CONFIG_PAX_SEGMEXEC
43120 + pax_flags |= MF_PAX_SEGMEXEC;
43121 +#endif
43122 +
43123 +#ifdef CONFIG_PAX_MPROTECT
43124 + pax_flags |= MF_PAX_MPROTECT;
43125 +#endif
43126 +
43127 +#ifdef CONFIG_PAX_RANDMMAP
43128 + if (randomize_va_space)
43129 + pax_flags |= MF_PAX_RANDMMAP;
43130 +#endif
43131 +
43132 +#endif
43133 +
43134 + return pax_flags;
43135 +}
43136 +
43137 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43138 +{
43139 +
43140 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43141 + unsigned long i;
43142 +
43143 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43144 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43145 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43146 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43147 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43148 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43149 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43150 + return ~0UL;
43151 +
43152 +#ifdef CONFIG_PAX_SOFTMODE
43153 + if (pax_softmode)
43154 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43155 + else
43156 +#endif
43157 +
43158 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43159 + break;
43160 + }
43161 +#endif
43162 +
43163 + return ~0UL;
43164 +}
43165 +
43166 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43167 +{
43168 +
43169 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43170 + ssize_t xattr_size, i;
43171 + unsigned char xattr_value[5];
43172 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43173 +
43174 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43175 + if (xattr_size <= 0)
43176 + return ~0UL;
43177 +
43178 + for (i = 0; i < xattr_size; i++)
43179 + switch (xattr_value[i]) {
43180 + default:
43181 + return ~0UL;
43182 +
43183 +#define parse_flag(option1, option2, flag) \
43184 + case option1: \
43185 + pax_flags_hardmode |= MF_PAX_##flag; \
43186 + break; \
43187 + case option2: \
43188 + pax_flags_softmode |= MF_PAX_##flag; \
43189 + break;
43190 +
43191 + parse_flag('p', 'P', PAGEEXEC);
43192 + parse_flag('e', 'E', EMUTRAMP);
43193 + parse_flag('m', 'M', MPROTECT);
43194 + parse_flag('r', 'R', RANDMMAP);
43195 + parse_flag('s', 'S', SEGMEXEC);
43196 +
43197 +#undef parse_flag
43198 + }
43199 +
43200 + if (pax_flags_hardmode & pax_flags_softmode)
43201 + return ~0UL;
43202 +
43203 +#ifdef CONFIG_PAX_SOFTMODE
43204 + if (pax_softmode)
43205 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43206 + else
43207 +#endif
43208 +
43209 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43210 +#else
43211 + return ~0UL;
43212 +#endif
43213 +
43214 +}
43215 +
43216 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43217 +{
43218 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43219 +
43220 + pax_flags = pax_parse_ei_pax(elf_ex);
43221 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43222 + xattr_pax_flags = pax_parse_xattr_pax(file);
43223 +
43224 + if (pt_pax_flags == ~0UL)
43225 + pt_pax_flags = xattr_pax_flags;
43226 + else if (xattr_pax_flags == ~0UL)
43227 + xattr_pax_flags = pt_pax_flags;
43228 + if (pt_pax_flags != xattr_pax_flags)
43229 + return -EINVAL;
43230 + if (pt_pax_flags != ~0UL)
43231 + pax_flags = pt_pax_flags;
43232 +
43233 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43234 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43235 + if ((__supported_pte_mask & _PAGE_NX))
43236 + pax_flags &= ~MF_PAX_SEGMEXEC;
43237 + else
43238 + pax_flags &= ~MF_PAX_PAGEEXEC;
43239 + }
43240 +#endif
43241 +
43242 + if (0 > pax_check_flags(&pax_flags))
43243 + return -EINVAL;
43244 +
43245 + current->mm->pax_flags = pax_flags;
43246 + return 0;
43247 +}
43248 +#endif
43249 +
43250 /*
43251 * These are the functions used to load ELF style executables and shared
43252 * libraries. There is no binary dependent code anywhere else.
43253 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43254 {
43255 unsigned int random_variable = 0;
43256
43257 +#ifdef CONFIG_PAX_RANDUSTACK
43258 + if (randomize_va_space)
43259 + return stack_top - current->mm->delta_stack;
43260 +#endif
43261 +
43262 if ((current->flags & PF_RANDOMIZE) &&
43263 !(current->personality & ADDR_NO_RANDOMIZE)) {
43264 random_variable = get_random_int() & STACK_RND_MASK;
43265 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43266 unsigned long load_addr = 0, load_bias = 0;
43267 int load_addr_set = 0;
43268 char * elf_interpreter = NULL;
43269 - unsigned long error;
43270 + unsigned long error = 0;
43271 struct elf_phdr *elf_ppnt, *elf_phdata;
43272 unsigned long elf_bss, elf_brk;
43273 int retval, i;
43274 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43275 unsigned long start_code, end_code, start_data, end_data;
43276 unsigned long reloc_func_desc __maybe_unused = 0;
43277 int executable_stack = EXSTACK_DEFAULT;
43278 - unsigned long def_flags = 0;
43279 struct {
43280 struct elfhdr elf_ex;
43281 struct elfhdr interp_elf_ex;
43282 } *loc;
43283 + unsigned long pax_task_size = TASK_SIZE;
43284
43285 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43286 if (!loc) {
43287 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43288 goto out_free_dentry;
43289
43290 /* OK, This is the point of no return */
43291 - current->mm->def_flags = def_flags;
43292 +
43293 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43294 + current->mm->pax_flags = 0UL;
43295 +#endif
43296 +
43297 +#ifdef CONFIG_PAX_DLRESOLVE
43298 + current->mm->call_dl_resolve = 0UL;
43299 +#endif
43300 +
43301 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43302 + current->mm->call_syscall = 0UL;
43303 +#endif
43304 +
43305 +#ifdef CONFIG_PAX_ASLR
43306 + current->mm->delta_mmap = 0UL;
43307 + current->mm->delta_stack = 0UL;
43308 +#endif
43309 +
43310 + current->mm->def_flags = 0;
43311 +
43312 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43313 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43314 + send_sig(SIGKILL, current, 0);
43315 + goto out_free_dentry;
43316 + }
43317 +#endif
43318 +
43319 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43320 + pax_set_initial_flags(bprm);
43321 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43322 + if (pax_set_initial_flags_func)
43323 + (pax_set_initial_flags_func)(bprm);
43324 +#endif
43325 +
43326 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43327 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43328 + current->mm->context.user_cs_limit = PAGE_SIZE;
43329 + current->mm->def_flags |= VM_PAGEEXEC;
43330 + }
43331 +#endif
43332 +
43333 +#ifdef CONFIG_PAX_SEGMEXEC
43334 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43335 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43336 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43337 + pax_task_size = SEGMEXEC_TASK_SIZE;
43338 + current->mm->def_flags |= VM_NOHUGEPAGE;
43339 + }
43340 +#endif
43341 +
43342 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43343 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43344 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43345 + put_cpu();
43346 + }
43347 +#endif
43348
43349 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43350 may depend on the personality. */
43351 SET_PERSONALITY(loc->elf_ex);
43352 +
43353 +#ifdef CONFIG_PAX_ASLR
43354 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43355 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43356 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43357 + }
43358 +#endif
43359 +
43360 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43361 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43362 + executable_stack = EXSTACK_DISABLE_X;
43363 + current->personality &= ~READ_IMPLIES_EXEC;
43364 + } else
43365 +#endif
43366 +
43367 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43368 current->personality |= READ_IMPLIES_EXEC;
43369
43370 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43371 #else
43372 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43373 #endif
43374 +
43375 +#ifdef CONFIG_PAX_RANDMMAP
43376 + /* PaX: randomize base address at the default exe base if requested */
43377 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43378 +#ifdef CONFIG_SPARC64
43379 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43380 +#else
43381 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43382 +#endif
43383 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43384 + elf_flags |= MAP_FIXED;
43385 + }
43386 +#endif
43387 +
43388 }
43389
43390 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43391 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43392 * allowed task size. Note that p_filesz must always be
43393 * <= p_memsz so it is only necessary to check p_memsz.
43394 */
43395 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43396 - elf_ppnt->p_memsz > TASK_SIZE ||
43397 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43398 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43399 + elf_ppnt->p_memsz > pax_task_size ||
43400 + pax_task_size - elf_ppnt->p_memsz < k) {
43401 /* set_brk can never work. Avoid overflows. */
43402 send_sig(SIGKILL, current, 0);
43403 retval = -EINVAL;
43404 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43405 goto out_free_dentry;
43406 }
43407 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43408 - send_sig(SIGSEGV, current, 0);
43409 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43410 - goto out_free_dentry;
43411 + /*
43412 + * This bss-zeroing can fail if the ELF
43413 + * file specifies odd protections. So
43414 + * we don't check the return value
43415 + */
43416 }
43417
43418 +#ifdef CONFIG_PAX_RANDMMAP
43419 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43420 + unsigned long start, size;
43421 +
43422 + start = ELF_PAGEALIGN(elf_brk);
43423 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43424 + down_read(&current->mm->mmap_sem);
43425 + retval = -ENOMEM;
43426 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43427 + unsigned long prot = PROT_NONE;
43428 +
43429 + up_read(&current->mm->mmap_sem);
43430 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43431 +// if (current->personality & ADDR_NO_RANDOMIZE)
43432 +// prot = PROT_READ;
43433 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43434 + retval = IS_ERR_VALUE(start) ? start : 0;
43435 + } else
43436 + up_read(&current->mm->mmap_sem);
43437 + if (retval == 0)
43438 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43439 + if (retval < 0) {
43440 + send_sig(SIGKILL, current, 0);
43441 + goto out_free_dentry;
43442 + }
43443 + }
43444 +#endif
43445 +
43446 if (elf_interpreter) {
43447 unsigned long uninitialized_var(interp_map_addr);
43448
43449 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43450 * Decide what to dump of a segment, part, all or none.
43451 */
43452 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43453 - unsigned long mm_flags)
43454 + unsigned long mm_flags, long signr)
43455 {
43456 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43457
43458 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43459 if (vma->vm_file == NULL)
43460 return 0;
43461
43462 - if (FILTER(MAPPED_PRIVATE))
43463 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43464 goto whole;
43465
43466 /*
43467 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43468 {
43469 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43470 int i = 0;
43471 - do
43472 + do {
43473 i += 2;
43474 - while (auxv[i - 2] != AT_NULL);
43475 + } while (auxv[i - 2] != AT_NULL);
43476 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43477 }
43478
43479 @@ -1879,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43480 }
43481
43482 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43483 - unsigned long mm_flags)
43484 + struct coredump_params *cprm)
43485 {
43486 struct vm_area_struct *vma;
43487 size_t size = 0;
43488
43489 for (vma = first_vma(current, gate_vma); vma != NULL;
43490 vma = next_vma(vma, gate_vma))
43491 - size += vma_dump_size(vma, mm_flags);
43492 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43493 return size;
43494 }
43495
43496 @@ -1980,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43497
43498 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43499
43500 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43501 + offset += elf_core_vma_data_size(gate_vma, cprm);
43502 offset += elf_core_extra_data_size();
43503 e_shoff = offset;
43504
43505 @@ -1994,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43506 offset = dataoff;
43507
43508 size += sizeof(*elf);
43509 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43510 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43511 goto end_coredump;
43512
43513 size += sizeof(*phdr4note);
43514 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43515 if (size > cprm->limit
43516 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43517 goto end_coredump;
43518 @@ -2011,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43519 phdr.p_offset = offset;
43520 phdr.p_vaddr = vma->vm_start;
43521 phdr.p_paddr = 0;
43522 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43523 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43524 phdr.p_memsz = vma->vm_end - vma->vm_start;
43525 offset += phdr.p_filesz;
43526 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43527 @@ -2022,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43528 phdr.p_align = ELF_EXEC_PAGESIZE;
43529
43530 size += sizeof(phdr);
43531 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43532 if (size > cprm->limit
43533 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43534 goto end_coredump;
43535 @@ -2046,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43536 unsigned long addr;
43537 unsigned long end;
43538
43539 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43540 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43541
43542 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43543 struct page *page;
43544 @@ -2055,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43545 page = get_dump_page(addr);
43546 if (page) {
43547 void *kaddr = kmap(page);
43548 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43549 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43550 !dump_write(cprm->file, kaddr,
43551 PAGE_SIZE);
43552 @@ -2072,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43553
43554 if (e_phnum == PN_XNUM) {
43555 size += sizeof(*shdr4extnum);
43556 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43557 if (size > cprm->limit
43558 || !dump_write(cprm->file, shdr4extnum,
43559 sizeof(*shdr4extnum)))
43560 @@ -2092,6 +2545,97 @@ out:
43561
43562 #endif /* CONFIG_ELF_CORE */
43563
43564 +#ifdef CONFIG_PAX_MPROTECT
43565 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43566 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43567 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43568 + *
43569 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43570 + * basis because we want to allow the common case and not the special ones.
43571 + */
43572 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43573 +{
43574 + struct elfhdr elf_h;
43575 + struct elf_phdr elf_p;
43576 + unsigned long i;
43577 + unsigned long oldflags;
43578 + bool is_textrel_rw, is_textrel_rx, is_relro;
43579 +
43580 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43581 + return;
43582 +
43583 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43584 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43585 +
43586 +#ifdef CONFIG_PAX_ELFRELOCS
43587 + /* possible TEXTREL */
43588 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43589 + is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
43590 +#else
43591 + is_textrel_rw = false;
43592 + is_textrel_rx = false;
43593 +#endif
43594 +
43595 + /* possible RELRO */
43596 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43597 +
43598 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43599 + return;
43600 +
43601 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43602 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43603 +
43604 +#ifdef CONFIG_PAX_ETEXECRELOCS
43605 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43606 +#else
43607 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43608 +#endif
43609 +
43610 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43611 + !elf_check_arch(&elf_h) ||
43612 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43613 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43614 + return;
43615 +
43616 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43617 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43618 + return;
43619 + switch (elf_p.p_type) {
43620 + case PT_DYNAMIC:
43621 + if (!is_textrel_rw && !is_textrel_rx)
43622 + continue;
43623 + i = 0UL;
43624 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43625 + elf_dyn dyn;
43626 +
43627 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43628 + return;
43629 + if (dyn.d_tag == DT_NULL)
43630 + return;
43631 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43632 + gr_log_textrel(vma);
43633 + if (is_textrel_rw)
43634 + vma->vm_flags |= VM_MAYWRITE;
43635 + else
43636 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43637 + vma->vm_flags &= ~VM_MAYWRITE;
43638 + return;
43639 + }
43640 + i++;
43641 + }
43642 + return;
43643 +
43644 + case PT_GNU_RELRO:
43645 + if (!is_relro)
43646 + continue;
43647 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43648 + vma->vm_flags &= ~VM_MAYWRITE;
43649 + return;
43650 + }
43651 + }
43652 +}
43653 +#endif
43654 +
43655 static int __init init_elf_binfmt(void)
43656 {
43657 register_binfmt(&elf_format);
43658 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43659 index 178cb70..8972997 100644
43660 --- a/fs/binfmt_flat.c
43661 +++ b/fs/binfmt_flat.c
43662 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43663 realdatastart = (unsigned long) -ENOMEM;
43664 printk("Unable to allocate RAM for process data, errno %d\n",
43665 (int)-realdatastart);
43666 + down_write(&current->mm->mmap_sem);
43667 vm_munmap(textpos, text_len);
43668 + up_write(&current->mm->mmap_sem);
43669 ret = realdatastart;
43670 goto err;
43671 }
43672 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43673 }
43674 if (IS_ERR_VALUE(result)) {
43675 printk("Unable to read data+bss, errno %d\n", (int)-result);
43676 + down_write(&current->mm->mmap_sem);
43677 vm_munmap(textpos, text_len);
43678 vm_munmap(realdatastart, len);
43679 + up_write(&current->mm->mmap_sem);
43680 ret = result;
43681 goto err;
43682 }
43683 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43684 }
43685 if (IS_ERR_VALUE(result)) {
43686 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43687 + down_write(&current->mm->mmap_sem);
43688 vm_munmap(textpos, text_len + data_len + extra +
43689 MAX_SHARED_LIBS * sizeof(unsigned long));
43690 + up_write(&current->mm->mmap_sem);
43691 ret = result;
43692 goto err;
43693 }
43694 diff --git a/fs/bio.c b/fs/bio.c
43695 index 71072ab..439851b 100644
43696 --- a/fs/bio.c
43697 +++ b/fs/bio.c
43698 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43699 /*
43700 * Overflow, abort
43701 */
43702 - if (end < start)
43703 + if (end < start || end - start > INT_MAX - nr_pages)
43704 return ERR_PTR(-EINVAL);
43705
43706 nr_pages += end - start;
43707 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43708 /*
43709 * Overflow, abort
43710 */
43711 - if (end < start)
43712 + if (end < start || end - start > INT_MAX - nr_pages)
43713 return ERR_PTR(-EINVAL);
43714
43715 nr_pages += end - start;
43716 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43717 const int read = bio_data_dir(bio) == READ;
43718 struct bio_map_data *bmd = bio->bi_private;
43719 int i;
43720 - char *p = bmd->sgvecs[0].iov_base;
43721 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43722
43723 __bio_for_each_segment(bvec, bio, i, 0) {
43724 char *addr = page_address(bvec->bv_page);
43725 diff --git a/fs/block_dev.c b/fs/block_dev.c
43726 index 38e721b..7a9c5bc 100644
43727 --- a/fs/block_dev.c
43728 +++ b/fs/block_dev.c
43729 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43730 else if (bdev->bd_contains == bdev)
43731 return true; /* is a whole device which isn't held */
43732
43733 - else if (whole->bd_holder == bd_may_claim)
43734 + else if (whole->bd_holder == (void *)bd_may_claim)
43735 return true; /* is a partition of a device that is being partitioned */
43736 else if (whole->bd_holder != NULL)
43737 return false; /* is a partition of a held device */
43738 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43739 index 9197e2e..7f731f8 100644
43740 --- a/fs/btrfs/check-integrity.c
43741 +++ b/fs/btrfs/check-integrity.c
43742 @@ -155,7 +155,7 @@ struct btrfsic_block {
43743 union {
43744 bio_end_io_t *bio;
43745 bh_end_io_t *bh;
43746 - } orig_bio_bh_end_io;
43747 + } __no_const orig_bio_bh_end_io;
43748 int submit_bio_bh_rw;
43749 u64 flush_gen; /* only valid if !never_written */
43750 };
43751 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43752 index 6d183f6..f47cc7a 100644
43753 --- a/fs/btrfs/ctree.c
43754 +++ b/fs/btrfs/ctree.c
43755 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43756 free_extent_buffer(buf);
43757 add_root_to_dirty_list(root);
43758 } else {
43759 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43760 - parent_start = parent->start;
43761 - else
43762 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43763 + if (parent)
43764 + parent_start = parent->start;
43765 + else
43766 + parent_start = 0;
43767 + } else
43768 parent_start = 0;
43769
43770 WARN_ON(trans->transid != btrfs_header_generation(parent));
43771 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43772 index ec154f9..bf617a7 100644
43773 --- a/fs/btrfs/inode.c
43774 +++ b/fs/btrfs/inode.c
43775 @@ -7126,7 +7126,7 @@ fail:
43776 return -ENOMEM;
43777 }
43778
43779 -static int btrfs_getattr(struct vfsmount *mnt,
43780 +int btrfs_getattr(struct vfsmount *mnt,
43781 struct dentry *dentry, struct kstat *stat)
43782 {
43783 struct inode *inode = dentry->d_inode;
43784 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43785 return 0;
43786 }
43787
43788 +EXPORT_SYMBOL(btrfs_getattr);
43789 +
43790 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43791 +{
43792 + return BTRFS_I(inode)->root->anon_dev;
43793 +}
43794 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43795 +
43796 /*
43797 * If a file is moved, it will inherit the cow and compression flags of the new
43798 * directory.
43799 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43800 index 9df50fa..6cd20d0 100644
43801 --- a/fs/btrfs/ioctl.c
43802 +++ b/fs/btrfs/ioctl.c
43803 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43804 for (i = 0; i < num_types; i++) {
43805 struct btrfs_space_info *tmp;
43806
43807 + /* Don't copy in more than we allocated */
43808 if (!slot_count)
43809 break;
43810
43811 + slot_count--;
43812 +
43813 info = NULL;
43814 rcu_read_lock();
43815 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43816 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43817 memcpy(dest, &space, sizeof(space));
43818 dest++;
43819 space_args.total_spaces++;
43820 - slot_count--;
43821 }
43822 - if (!slot_count)
43823 - break;
43824 }
43825 up_read(&info->groups_sem);
43826 }
43827 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43828 index 4da0865..01c4778 100644
43829 --- a/fs/btrfs/relocation.c
43830 +++ b/fs/btrfs/relocation.c
43831 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43832 }
43833 spin_unlock(&rc->reloc_root_tree.lock);
43834
43835 - BUG_ON((struct btrfs_root *)node->data != root);
43836 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43837
43838 if (!del) {
43839 spin_lock(&rc->reloc_root_tree.lock);
43840 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43841 index 622f469..e8d2d55 100644
43842 --- a/fs/cachefiles/bind.c
43843 +++ b/fs/cachefiles/bind.c
43844 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43845 args);
43846
43847 /* start by checking things over */
43848 - ASSERT(cache->fstop_percent >= 0 &&
43849 - cache->fstop_percent < cache->fcull_percent &&
43850 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43851 cache->fcull_percent < cache->frun_percent &&
43852 cache->frun_percent < 100);
43853
43854 - ASSERT(cache->bstop_percent >= 0 &&
43855 - cache->bstop_percent < cache->bcull_percent &&
43856 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43857 cache->bcull_percent < cache->brun_percent &&
43858 cache->brun_percent < 100);
43859
43860 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43861 index 0a1467b..6a53245 100644
43862 --- a/fs/cachefiles/daemon.c
43863 +++ b/fs/cachefiles/daemon.c
43864 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43865 if (n > buflen)
43866 return -EMSGSIZE;
43867
43868 - if (copy_to_user(_buffer, buffer, n) != 0)
43869 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43870 return -EFAULT;
43871
43872 return n;
43873 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43874 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43875 return -EIO;
43876
43877 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43878 + if (datalen > PAGE_SIZE - 1)
43879 return -EOPNOTSUPP;
43880
43881 /* drag the command string into the kernel so we can parse it */
43882 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43883 if (args[0] != '%' || args[1] != '\0')
43884 return -EINVAL;
43885
43886 - if (fstop < 0 || fstop >= cache->fcull_percent)
43887 + if (fstop >= cache->fcull_percent)
43888 return cachefiles_daemon_range_error(cache, args);
43889
43890 cache->fstop_percent = fstop;
43891 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43892 if (args[0] != '%' || args[1] != '\0')
43893 return -EINVAL;
43894
43895 - if (bstop < 0 || bstop >= cache->bcull_percent)
43896 + if (bstop >= cache->bcull_percent)
43897 return cachefiles_daemon_range_error(cache, args);
43898
43899 cache->bstop_percent = bstop;
43900 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43901 index bd6bc1b..b627b53 100644
43902 --- a/fs/cachefiles/internal.h
43903 +++ b/fs/cachefiles/internal.h
43904 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43905 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43906 struct rb_root active_nodes; /* active nodes (can't be culled) */
43907 rwlock_t active_lock; /* lock for active_nodes */
43908 - atomic_t gravecounter; /* graveyard uniquifier */
43909 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43910 unsigned frun_percent; /* when to stop culling (% files) */
43911 unsigned fcull_percent; /* when to start culling (% files) */
43912 unsigned fstop_percent; /* when to stop allocating (% files) */
43913 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43914 * proc.c
43915 */
43916 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43917 -extern atomic_t cachefiles_lookup_histogram[HZ];
43918 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43919 -extern atomic_t cachefiles_create_histogram[HZ];
43920 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43921 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43922 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43923
43924 extern int __init cachefiles_proc_init(void);
43925 extern void cachefiles_proc_cleanup(void);
43926 static inline
43927 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43928 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43929 {
43930 unsigned long jif = jiffies - start_jif;
43931 if (jif >= HZ)
43932 jif = HZ - 1;
43933 - atomic_inc(&histogram[jif]);
43934 + atomic_inc_unchecked(&histogram[jif]);
43935 }
43936
43937 #else
43938 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43939 index b0b5f7c..039bb26 100644
43940 --- a/fs/cachefiles/namei.c
43941 +++ b/fs/cachefiles/namei.c
43942 @@ -318,7 +318,7 @@ try_again:
43943 /* first step is to make up a grave dentry in the graveyard */
43944 sprintf(nbuffer, "%08x%08x",
43945 (uint32_t) get_seconds(),
43946 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43947 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43948
43949 /* do the multiway lock magic */
43950 trap = lock_rename(cache->graveyard, dir);
43951 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43952 index eccd339..4c1d995 100644
43953 --- a/fs/cachefiles/proc.c
43954 +++ b/fs/cachefiles/proc.c
43955 @@ -14,9 +14,9 @@
43956 #include <linux/seq_file.h>
43957 #include "internal.h"
43958
43959 -atomic_t cachefiles_lookup_histogram[HZ];
43960 -atomic_t cachefiles_mkdir_histogram[HZ];
43961 -atomic_t cachefiles_create_histogram[HZ];
43962 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43963 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43964 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43965
43966 /*
43967 * display the latency histogram
43968 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43969 return 0;
43970 default:
43971 index = (unsigned long) v - 3;
43972 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43973 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43974 - z = atomic_read(&cachefiles_create_histogram[index]);
43975 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43976 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43977 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43978 if (x == 0 && y == 0 && z == 0)
43979 return 0;
43980
43981 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43982 index c994691..2a1537f 100644
43983 --- a/fs/cachefiles/rdwr.c
43984 +++ b/fs/cachefiles/rdwr.c
43985 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43986 old_fs = get_fs();
43987 set_fs(KERNEL_DS);
43988 ret = file->f_op->write(
43989 - file, (const void __user *) data, len, &pos);
43990 + file, (const void __force_user *) data, len, &pos);
43991 set_fs(old_fs);
43992 kunmap(page);
43993 if (ret != len)
43994 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43995 index e5b7731..b9c59fb 100644
43996 --- a/fs/ceph/dir.c
43997 +++ b/fs/ceph/dir.c
43998 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43999 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44000 struct ceph_mds_client *mdsc = fsc->mdsc;
44001 unsigned frag = fpos_frag(filp->f_pos);
44002 - int off = fpos_off(filp->f_pos);
44003 + unsigned int off = fpos_off(filp->f_pos);
44004 int err;
44005 u32 ftype;
44006 struct ceph_mds_reply_info_parsed *rinfo;
44007 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44008 index d9ea6ed..1e6c8ac 100644
44009 --- a/fs/cifs/cifs_debug.c
44010 +++ b/fs/cifs/cifs_debug.c
44011 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44012
44013 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44014 #ifdef CONFIG_CIFS_STATS2
44015 - atomic_set(&totBufAllocCount, 0);
44016 - atomic_set(&totSmBufAllocCount, 0);
44017 + atomic_set_unchecked(&totBufAllocCount, 0);
44018 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44019 #endif /* CONFIG_CIFS_STATS2 */
44020 spin_lock(&cifs_tcp_ses_lock);
44021 list_for_each(tmp1, &cifs_tcp_ses_list) {
44022 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44023 tcon = list_entry(tmp3,
44024 struct cifs_tcon,
44025 tcon_list);
44026 - atomic_set(&tcon->num_smbs_sent, 0);
44027 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44028 if (server->ops->clear_stats)
44029 server->ops->clear_stats(tcon);
44030 }
44031 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44032 smBufAllocCount.counter, cifs_min_small);
44033 #ifdef CONFIG_CIFS_STATS2
44034 seq_printf(m, "Total Large %d Small %d Allocations\n",
44035 - atomic_read(&totBufAllocCount),
44036 - atomic_read(&totSmBufAllocCount));
44037 + atomic_read_unchecked(&totBufAllocCount),
44038 + atomic_read_unchecked(&totSmBufAllocCount));
44039 #endif /* CONFIG_CIFS_STATS2 */
44040
44041 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44042 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44043 if (tcon->need_reconnect)
44044 seq_puts(m, "\tDISCONNECTED ");
44045 seq_printf(m, "\nSMBs: %d",
44046 - atomic_read(&tcon->num_smbs_sent));
44047 + atomic_read_unchecked(&tcon->num_smbs_sent));
44048 if (server->ops->print_stats)
44049 server->ops->print_stats(m, tcon);
44050 }
44051 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44052 index db8a404..c712e2e 100644
44053 --- a/fs/cifs/cifsfs.c
44054 +++ b/fs/cifs/cifsfs.c
44055 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44056 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44057 cifs_req_cachep = kmem_cache_create("cifs_request",
44058 CIFSMaxBufSize + max_hdr_size, 0,
44059 - SLAB_HWCACHE_ALIGN, NULL);
44060 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44061 if (cifs_req_cachep == NULL)
44062 return -ENOMEM;
44063
44064 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44065 efficient to alloc 1 per page off the slab compared to 17K (5page)
44066 alloc of large cifs buffers even when page debugging is on */
44067 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44068 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44069 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44070 NULL);
44071 if (cifs_sm_req_cachep == NULL) {
44072 mempool_destroy(cifs_req_poolp);
44073 @@ -1115,8 +1115,8 @@ init_cifs(void)
44074 atomic_set(&bufAllocCount, 0);
44075 atomic_set(&smBufAllocCount, 0);
44076 #ifdef CONFIG_CIFS_STATS2
44077 - atomic_set(&totBufAllocCount, 0);
44078 - atomic_set(&totSmBufAllocCount, 0);
44079 + atomic_set_unchecked(&totBufAllocCount, 0);
44080 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44081 #endif /* CONFIG_CIFS_STATS2 */
44082
44083 atomic_set(&midCount, 0);
44084 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44085 index 977dc0e..ba48ab9 100644
44086 --- a/fs/cifs/cifsglob.h
44087 +++ b/fs/cifs/cifsglob.h
44088 @@ -590,35 +590,35 @@ struct cifs_tcon {
44089 __u16 Flags; /* optional support bits */
44090 enum statusEnum tidStatus;
44091 #ifdef CONFIG_CIFS_STATS
44092 - atomic_t num_smbs_sent;
44093 + atomic_unchecked_t num_smbs_sent;
44094 union {
44095 struct {
44096 - atomic_t num_writes;
44097 - atomic_t num_reads;
44098 - atomic_t num_flushes;
44099 - atomic_t num_oplock_brks;
44100 - atomic_t num_opens;
44101 - atomic_t num_closes;
44102 - atomic_t num_deletes;
44103 - atomic_t num_mkdirs;
44104 - atomic_t num_posixopens;
44105 - atomic_t num_posixmkdirs;
44106 - atomic_t num_rmdirs;
44107 - atomic_t num_renames;
44108 - atomic_t num_t2renames;
44109 - atomic_t num_ffirst;
44110 - atomic_t num_fnext;
44111 - atomic_t num_fclose;
44112 - atomic_t num_hardlinks;
44113 - atomic_t num_symlinks;
44114 - atomic_t num_locks;
44115 - atomic_t num_acl_get;
44116 - atomic_t num_acl_set;
44117 + atomic_unchecked_t num_writes;
44118 + atomic_unchecked_t num_reads;
44119 + atomic_unchecked_t num_flushes;
44120 + atomic_unchecked_t num_oplock_brks;
44121 + atomic_unchecked_t num_opens;
44122 + atomic_unchecked_t num_closes;
44123 + atomic_unchecked_t num_deletes;
44124 + atomic_unchecked_t num_mkdirs;
44125 + atomic_unchecked_t num_posixopens;
44126 + atomic_unchecked_t num_posixmkdirs;
44127 + atomic_unchecked_t num_rmdirs;
44128 + atomic_unchecked_t num_renames;
44129 + atomic_unchecked_t num_t2renames;
44130 + atomic_unchecked_t num_ffirst;
44131 + atomic_unchecked_t num_fnext;
44132 + atomic_unchecked_t num_fclose;
44133 + atomic_unchecked_t num_hardlinks;
44134 + atomic_unchecked_t num_symlinks;
44135 + atomic_unchecked_t num_locks;
44136 + atomic_unchecked_t num_acl_get;
44137 + atomic_unchecked_t num_acl_set;
44138 } cifs_stats;
44139 #ifdef CONFIG_CIFS_SMB2
44140 struct {
44141 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44142 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44143 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44144 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44145 } smb2_stats;
44146 #endif /* CONFIG_CIFS_SMB2 */
44147 } stats;
44148 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44149 }
44150
44151 #ifdef CONFIG_CIFS_STATS
44152 -#define cifs_stats_inc atomic_inc
44153 +#define cifs_stats_inc atomic_inc_unchecked
44154
44155 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44156 unsigned int bytes)
44157 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44158 /* Various Debug counters */
44159 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44160 #ifdef CONFIG_CIFS_STATS2
44161 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44162 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44163 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44164 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44165 #endif
44166 GLOBAL_EXTERN atomic_t smBufAllocCount;
44167 GLOBAL_EXTERN atomic_t midCount;
44168 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44169 index e6ce3b1..adc21fd 100644
44170 --- a/fs/cifs/link.c
44171 +++ b/fs/cifs/link.c
44172 @@ -602,7 +602,7 @@ symlink_exit:
44173
44174 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44175 {
44176 - char *p = nd_get_link(nd);
44177 + const char *p = nd_get_link(nd);
44178 if (!IS_ERR(p))
44179 kfree(p);
44180 }
44181 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44182 index ce41fee..ac0d27a 100644
44183 --- a/fs/cifs/misc.c
44184 +++ b/fs/cifs/misc.c
44185 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44186 memset(ret_buf, 0, buf_size + 3);
44187 atomic_inc(&bufAllocCount);
44188 #ifdef CONFIG_CIFS_STATS2
44189 - atomic_inc(&totBufAllocCount);
44190 + atomic_inc_unchecked(&totBufAllocCount);
44191 #endif /* CONFIG_CIFS_STATS2 */
44192 }
44193
44194 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44195 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44196 atomic_inc(&smBufAllocCount);
44197 #ifdef CONFIG_CIFS_STATS2
44198 - atomic_inc(&totSmBufAllocCount);
44199 + atomic_inc_unchecked(&totSmBufAllocCount);
44200 #endif /* CONFIG_CIFS_STATS2 */
44201
44202 }
44203 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44204 index 3129ac7..cc4a948 100644
44205 --- a/fs/cifs/smb1ops.c
44206 +++ b/fs/cifs/smb1ops.c
44207 @@ -524,27 +524,27 @@ static void
44208 cifs_clear_stats(struct cifs_tcon *tcon)
44209 {
44210 #ifdef CONFIG_CIFS_STATS
44211 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44212 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44213 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44214 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44215 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44216 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44217 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44218 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44219 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44220 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44221 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44222 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44223 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44224 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44225 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44226 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44227 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44228 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44229 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44230 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44231 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44232 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44233 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44234 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44235 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44236 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44237 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44238 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44239 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44240 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44241 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44242 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44243 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44244 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44245 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44246 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44247 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44248 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44249 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44250 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44251 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44252 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44253 #endif
44254 }
44255
44256 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44257 {
44258 #ifdef CONFIG_CIFS_STATS
44259 seq_printf(m, " Oplocks breaks: %d",
44260 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44261 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44262 seq_printf(m, "\nReads: %d Bytes: %llu",
44263 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44264 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44265 (long long)(tcon->bytes_read));
44266 seq_printf(m, "\nWrites: %d Bytes: %llu",
44267 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44268 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44269 (long long)(tcon->bytes_written));
44270 seq_printf(m, "\nFlushes: %d",
44271 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44272 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44273 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44274 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44275 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44276 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44277 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44278 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44279 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44280 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44281 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44282 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44283 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44284 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44285 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44286 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44287 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44288 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44289 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44290 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44291 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44292 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44293 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44294 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44295 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44296 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44297 seq_printf(m, "\nRenames: %d T2 Renames %d",
44298 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44299 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44300 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44301 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44302 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44303 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44304 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44305 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44306 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44307 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44308 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44309 #endif
44310 }
44311
44312 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44313 index 826209b..fa460f4 100644
44314 --- a/fs/cifs/smb2ops.c
44315 +++ b/fs/cifs/smb2ops.c
44316 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44317 #ifdef CONFIG_CIFS_STATS
44318 int i;
44319 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44320 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44321 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44322 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44323 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44324 }
44325 #endif
44326 }
44327 @@ -229,66 +229,66 @@ static void
44328 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44329 {
44330 #ifdef CONFIG_CIFS_STATS
44331 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44332 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44333 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44334 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44335 seq_printf(m, "\nNegotiates: %d sent %d failed",
44336 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44337 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44338 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44339 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44340 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44341 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44342 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44343 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44344 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44345 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44346 seq_printf(m, "\nLogoffs: %d sent %d failed",
44347 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44348 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44349 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44350 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44351 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44352 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44353 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44354 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44355 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44356 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44357 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44358 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44359 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44360 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44361 seq_printf(m, "\nCreates: %d sent %d failed",
44362 - atomic_read(&sent[SMB2_CREATE_HE]),
44363 - atomic_read(&failed[SMB2_CREATE_HE]));
44364 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44365 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44366 seq_printf(m, "\nCloses: %d sent %d failed",
44367 - atomic_read(&sent[SMB2_CLOSE_HE]),
44368 - atomic_read(&failed[SMB2_CLOSE_HE]));
44369 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44370 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44371 seq_printf(m, "\nFlushes: %d sent %d failed",
44372 - atomic_read(&sent[SMB2_FLUSH_HE]),
44373 - atomic_read(&failed[SMB2_FLUSH_HE]));
44374 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44375 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44376 seq_printf(m, "\nReads: %d sent %d failed",
44377 - atomic_read(&sent[SMB2_READ_HE]),
44378 - atomic_read(&failed[SMB2_READ_HE]));
44379 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44380 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44381 seq_printf(m, "\nWrites: %d sent %d failed",
44382 - atomic_read(&sent[SMB2_WRITE_HE]),
44383 - atomic_read(&failed[SMB2_WRITE_HE]));
44384 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44385 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44386 seq_printf(m, "\nLocks: %d sent %d failed",
44387 - atomic_read(&sent[SMB2_LOCK_HE]),
44388 - atomic_read(&failed[SMB2_LOCK_HE]));
44389 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44390 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44391 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44392 - atomic_read(&sent[SMB2_IOCTL_HE]),
44393 - atomic_read(&failed[SMB2_IOCTL_HE]));
44394 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44395 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44396 seq_printf(m, "\nCancels: %d sent %d failed",
44397 - atomic_read(&sent[SMB2_CANCEL_HE]),
44398 - atomic_read(&failed[SMB2_CANCEL_HE]));
44399 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44400 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44401 seq_printf(m, "\nEchos: %d sent %d failed",
44402 - atomic_read(&sent[SMB2_ECHO_HE]),
44403 - atomic_read(&failed[SMB2_ECHO_HE]));
44404 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44405 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44406 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44407 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44408 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44409 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44410 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44411 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44412 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44413 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44414 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44415 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44416 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44417 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44418 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44419 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44420 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44421 seq_printf(m, "\nSetInfos: %d sent %d failed",
44422 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44423 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44424 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44425 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44426 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44427 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44428 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44429 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44430 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44431 #endif
44432 }
44433
44434 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44435 index 958ae0e..505c9d0 100644
44436 --- a/fs/coda/cache.c
44437 +++ b/fs/coda/cache.c
44438 @@ -24,7 +24,7 @@
44439 #include "coda_linux.h"
44440 #include "coda_cache.h"
44441
44442 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44443 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44444
44445 /* replace or extend an acl cache hit */
44446 void coda_cache_enter(struct inode *inode, int mask)
44447 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44448 struct coda_inode_info *cii = ITOC(inode);
44449
44450 spin_lock(&cii->c_lock);
44451 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44452 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44453 if (cii->c_uid != current_fsuid()) {
44454 cii->c_uid = current_fsuid();
44455 cii->c_cached_perm = mask;
44456 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44457 {
44458 struct coda_inode_info *cii = ITOC(inode);
44459 spin_lock(&cii->c_lock);
44460 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44461 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44462 spin_unlock(&cii->c_lock);
44463 }
44464
44465 /* remove all acl caches */
44466 void coda_cache_clear_all(struct super_block *sb)
44467 {
44468 - atomic_inc(&permission_epoch);
44469 + atomic_inc_unchecked(&permission_epoch);
44470 }
44471
44472
44473 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44474 spin_lock(&cii->c_lock);
44475 hit = (mask & cii->c_cached_perm) == mask &&
44476 cii->c_uid == current_fsuid() &&
44477 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44478 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44479 spin_unlock(&cii->c_lock);
44480
44481 return hit;
44482 diff --git a/fs/compat.c b/fs/compat.c
44483 index 1bdb350..9f28287 100644
44484 --- a/fs/compat.c
44485 +++ b/fs/compat.c
44486 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44487
44488 set_fs(KERNEL_DS);
44489 /* The __user pointer cast is valid because of the set_fs() */
44490 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44491 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44492 set_fs(oldfs);
44493 /* truncating is ok because it's a user address */
44494 if (!ret)
44495 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44496 goto out;
44497
44498 ret = -EINVAL;
44499 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44500 + if (nr_segs > UIO_MAXIOV)
44501 goto out;
44502 if (nr_segs > fast_segs) {
44503 ret = -ENOMEM;
44504 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44505
44506 struct compat_readdir_callback {
44507 struct compat_old_linux_dirent __user *dirent;
44508 + struct file * file;
44509 int result;
44510 };
44511
44512 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44513 buf->result = -EOVERFLOW;
44514 return -EOVERFLOW;
44515 }
44516 +
44517 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44518 + return 0;
44519 +
44520 buf->result++;
44521 dirent = buf->dirent;
44522 if (!access_ok(VERIFY_WRITE, dirent,
44523 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44524
44525 buf.result = 0;
44526 buf.dirent = dirent;
44527 + buf.file = file;
44528
44529 error = vfs_readdir(file, compat_fillonedir, &buf);
44530 if (buf.result)
44531 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44532 struct compat_getdents_callback {
44533 struct compat_linux_dirent __user *current_dir;
44534 struct compat_linux_dirent __user *previous;
44535 + struct file * file;
44536 int count;
44537 int error;
44538 };
44539 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44540 buf->error = -EOVERFLOW;
44541 return -EOVERFLOW;
44542 }
44543 +
44544 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44545 + return 0;
44546 +
44547 dirent = buf->previous;
44548 if (dirent) {
44549 if (__put_user(offset, &dirent->d_off))
44550 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44551 buf.previous = NULL;
44552 buf.count = count;
44553 buf.error = 0;
44554 + buf.file = file;
44555
44556 error = vfs_readdir(file, compat_filldir, &buf);
44557 if (error >= 0)
44558 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44559 struct compat_getdents_callback64 {
44560 struct linux_dirent64 __user *current_dir;
44561 struct linux_dirent64 __user *previous;
44562 + struct file * file;
44563 int count;
44564 int error;
44565 };
44566 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44567 buf->error = -EINVAL; /* only used if we fail.. */
44568 if (reclen > buf->count)
44569 return -EINVAL;
44570 +
44571 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44572 + return 0;
44573 +
44574 dirent = buf->previous;
44575
44576 if (dirent) {
44577 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44578 buf.previous = NULL;
44579 buf.count = count;
44580 buf.error = 0;
44581 + buf.file = file;
44582
44583 error = vfs_readdir(file, compat_filldir64, &buf);
44584 if (error >= 0)
44585 error = buf.error;
44586 lastdirent = buf.previous;
44587 if (lastdirent) {
44588 - typeof(lastdirent->d_off) d_off = file->f_pos;
44589 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44590 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44591 error = -EFAULT;
44592 else
44593 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44594 index 112e45a..b59845b 100644
44595 --- a/fs/compat_binfmt_elf.c
44596 +++ b/fs/compat_binfmt_elf.c
44597 @@ -30,11 +30,13 @@
44598 #undef elf_phdr
44599 #undef elf_shdr
44600 #undef elf_note
44601 +#undef elf_dyn
44602 #undef elf_addr_t
44603 #define elfhdr elf32_hdr
44604 #define elf_phdr elf32_phdr
44605 #define elf_shdr elf32_shdr
44606 #define elf_note elf32_note
44607 +#define elf_dyn Elf32_Dyn
44608 #define elf_addr_t Elf32_Addr
44609
44610 /*
44611 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44612 index debdfe0..75d31d4 100644
44613 --- a/fs/compat_ioctl.c
44614 +++ b/fs/compat_ioctl.c
44615 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44616
44617 err = get_user(palp, &up->palette);
44618 err |= get_user(length, &up->length);
44619 + if (err)
44620 + return -EFAULT;
44621
44622 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44623 err = put_user(compat_ptr(palp), &up_native->palette);
44624 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44625 return -EFAULT;
44626 if (__get_user(udata, &ss32->iomem_base))
44627 return -EFAULT;
44628 - ss.iomem_base = compat_ptr(udata);
44629 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44630 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44631 __get_user(ss.port_high, &ss32->port_high))
44632 return -EFAULT;
44633 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44634 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44635 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44636 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44637 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44638 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44639 return -EFAULT;
44640
44641 return ioctl_preallocate(file, p);
44642 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44643 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44644 {
44645 unsigned int a, b;
44646 - a = *(unsigned int *)p;
44647 - b = *(unsigned int *)q;
44648 + a = *(const unsigned int *)p;
44649 + b = *(const unsigned int *)q;
44650 if (a > b)
44651 return 1;
44652 if (a < b)
44653 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44654 index 7414ae2..d98ad6d 100644
44655 --- a/fs/configfs/dir.c
44656 +++ b/fs/configfs/dir.c
44657 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44658 }
44659 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44660 struct configfs_dirent *next;
44661 - const char * name;
44662 + const unsigned char * name;
44663 + char d_name[sizeof(next->s_dentry->d_iname)];
44664 int len;
44665 struct inode *inode = NULL;
44666
44667 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44668 continue;
44669
44670 name = configfs_get_name(next);
44671 - len = strlen(name);
44672 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44673 + len = next->s_dentry->d_name.len;
44674 + memcpy(d_name, name, len);
44675 + name = d_name;
44676 + } else
44677 + len = strlen(name);
44678
44679 /*
44680 * We'll have a dentry and an inode for
44681 diff --git a/fs/dcache.c b/fs/dcache.c
44682 index 693f95b..95f1223 100644
44683 --- a/fs/dcache.c
44684 +++ b/fs/dcache.c
44685 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44686 mempages -= reserve;
44687
44688 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44689 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44690 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44691
44692 dcache_init();
44693 inode_init();
44694 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44695 index 4733eab..71ef6fa 100644
44696 --- a/fs/debugfs/inode.c
44697 +++ b/fs/debugfs/inode.c
44698 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44699 */
44700 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44701 {
44702 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44703 + return __create_file(name, S_IFDIR | S_IRWXU,
44704 +#else
44705 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44706 +#endif
44707 parent, NULL, NULL);
44708 }
44709 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44710 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44711 index cc7709e..7e7211f 100644
44712 --- a/fs/ecryptfs/inode.c
44713 +++ b/fs/ecryptfs/inode.c
44714 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44715 old_fs = get_fs();
44716 set_fs(get_ds());
44717 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44718 - (char __user *)lower_buf,
44719 + (char __force_user *)lower_buf,
44720 PATH_MAX);
44721 set_fs(old_fs);
44722 if (rc < 0)
44723 @@ -706,7 +706,7 @@ out:
44724 static void
44725 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44726 {
44727 - char *buf = nd_get_link(nd);
44728 + const char *buf = nd_get_link(nd);
44729 if (!IS_ERR(buf)) {
44730 /* Free the char* */
44731 kfree(buf);
44732 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44733 index 412e6ed..4292d22 100644
44734 --- a/fs/ecryptfs/miscdev.c
44735 +++ b/fs/ecryptfs/miscdev.c
44736 @@ -315,7 +315,7 @@ check_list:
44737 goto out_unlock_msg_ctx;
44738 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44739 if (msg_ctx->msg) {
44740 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44741 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44742 goto out_unlock_msg_ctx;
44743 i += packet_length_size;
44744 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44745 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44746 index b2a34a1..162fa69 100644
44747 --- a/fs/ecryptfs/read_write.c
44748 +++ b/fs/ecryptfs/read_write.c
44749 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44750 return -EIO;
44751 fs_save = get_fs();
44752 set_fs(get_ds());
44753 - rc = vfs_write(lower_file, data, size, &offset);
44754 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44755 set_fs(fs_save);
44756 mark_inode_dirty_sync(ecryptfs_inode);
44757 return rc;
44758 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44759 return -EIO;
44760 fs_save = get_fs();
44761 set_fs(get_ds());
44762 - rc = vfs_read(lower_file, data, size, &offset);
44763 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44764 set_fs(fs_save);
44765 return rc;
44766 }
44767 diff --git a/fs/exec.c b/fs/exec.c
44768 index 574cf4d..dfe774a 100644
44769 --- a/fs/exec.c
44770 +++ b/fs/exec.c
44771 @@ -55,6 +55,15 @@
44772 #include <linux/pipe_fs_i.h>
44773 #include <linux/oom.h>
44774 #include <linux/compat.h>
44775 +#include <linux/random.h>
44776 +#include <linux/seq_file.h>
44777 +
44778 +#ifdef CONFIG_PAX_REFCOUNT
44779 +#include <linux/kallsyms.h>
44780 +#include <linux/kdebug.h>
44781 +#endif
44782 +
44783 +#include <trace/events/fs.h>
44784
44785 #include <asm/uaccess.h>
44786 #include <asm/mmu_context.h>
44787 @@ -66,6 +75,18 @@
44788
44789 #include <trace/events/sched.h>
44790
44791 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44792 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44793 +{
44794 + WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
44795 +}
44796 +#endif
44797 +
44798 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44799 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44800 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44801 +#endif
44802 +
44803 int core_uses_pid;
44804 char core_pattern[CORENAME_MAX_SIZE] = "core";
44805 unsigned int core_pipe_limit;
44806 @@ -75,7 +96,7 @@ struct core_name {
44807 char *corename;
44808 int used, size;
44809 };
44810 -static atomic_t call_count = ATOMIC_INIT(1);
44811 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44812
44813 /* The maximal length of core_pattern is also specified in sysctl.c */
44814
44815 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44816 int write)
44817 {
44818 struct page *page;
44819 - int ret;
44820
44821 -#ifdef CONFIG_STACK_GROWSUP
44822 - if (write) {
44823 - ret = expand_downwards(bprm->vma, pos);
44824 - if (ret < 0)
44825 - return NULL;
44826 - }
44827 -#endif
44828 - ret = get_user_pages(current, bprm->mm, pos,
44829 - 1, write, 1, &page, NULL);
44830 - if (ret <= 0)
44831 + if (0 > expand_downwards(bprm->vma, pos))
44832 + return NULL;
44833 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44834 return NULL;
44835
44836 if (write) {
44837 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44838 if (size <= ARG_MAX)
44839 return page;
44840
44841 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44842 + // only allow 512KB for argv+env on suid/sgid binaries
44843 + // to prevent easy ASLR exhaustion
44844 + if (((bprm->cred->euid != current_euid()) ||
44845 + (bprm->cred->egid != current_egid())) &&
44846 + (size > (512 * 1024))) {
44847 + put_page(page);
44848 + return NULL;
44849 + }
44850 +#endif
44851 +
44852 /*
44853 * Limit to 1/4-th the stack size for the argv+env strings.
44854 * This ensures that:
44855 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44856 vma->vm_end = STACK_TOP_MAX;
44857 vma->vm_start = vma->vm_end - PAGE_SIZE;
44858 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44859 +
44860 +#ifdef CONFIG_PAX_SEGMEXEC
44861 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44862 +#endif
44863 +
44864 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44865 INIT_LIST_HEAD(&vma->anon_vma_chain);
44866
44867 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44868 mm->stack_vm = mm->total_vm = 1;
44869 up_write(&mm->mmap_sem);
44870 bprm->p = vma->vm_end - sizeof(void *);
44871 +
44872 +#ifdef CONFIG_PAX_RANDUSTACK
44873 + if (randomize_va_space)
44874 + bprm->p ^= random32() & ~PAGE_MASK;
44875 +#endif
44876 +
44877 return 0;
44878 err:
44879 up_write(&mm->mmap_sem);
44880 @@ -395,19 +430,7 @@ err:
44881 return err;
44882 }
44883
44884 -struct user_arg_ptr {
44885 -#ifdef CONFIG_COMPAT
44886 - bool is_compat;
44887 -#endif
44888 - union {
44889 - const char __user *const __user *native;
44890 -#ifdef CONFIG_COMPAT
44891 - compat_uptr_t __user *compat;
44892 -#endif
44893 - } ptr;
44894 -};
44895 -
44896 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44897 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44898 {
44899 const char __user *native;
44900
44901 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44902 compat_uptr_t compat;
44903
44904 if (get_user(compat, argv.ptr.compat + nr))
44905 - return ERR_PTR(-EFAULT);
44906 + return (const char __force_user *)ERR_PTR(-EFAULT);
44907
44908 return compat_ptr(compat);
44909 }
44910 #endif
44911
44912 if (get_user(native, argv.ptr.native + nr))
44913 - return ERR_PTR(-EFAULT);
44914 + return (const char __force_user *)ERR_PTR(-EFAULT);
44915
44916 return native;
44917 }
44918 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44919 if (!p)
44920 break;
44921
44922 - if (IS_ERR(p))
44923 + if (IS_ERR((const char __force_kernel *)p))
44924 return -EFAULT;
44925
44926 if (i++ >= max)
44927 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44928
44929 ret = -EFAULT;
44930 str = get_user_arg_ptr(argv, argc);
44931 - if (IS_ERR(str))
44932 + if (IS_ERR((const char __force_kernel *)str))
44933 goto out;
44934
44935 len = strnlen_user(str, MAX_ARG_STRLEN);
44936 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44937 int r;
44938 mm_segment_t oldfs = get_fs();
44939 struct user_arg_ptr argv = {
44940 - .ptr.native = (const char __user *const __user *)__argv,
44941 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44942 };
44943
44944 set_fs(KERNEL_DS);
44945 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44946 unsigned long new_end = old_end - shift;
44947 struct mmu_gather tlb;
44948
44949 - BUG_ON(new_start > new_end);
44950 + if (new_start >= new_end || new_start < mmap_min_addr)
44951 + return -ENOMEM;
44952
44953 /*
44954 * ensure there are no vmas between where we want to go
44955 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44956 if (vma != find_vma(mm, new_start))
44957 return -EFAULT;
44958
44959 +#ifdef CONFIG_PAX_SEGMEXEC
44960 + BUG_ON(pax_find_mirror_vma(vma));
44961 +#endif
44962 +
44963 /*
44964 * cover the whole range: [new_start, old_end)
44965 */
44966 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44967 stack_top = arch_align_stack(stack_top);
44968 stack_top = PAGE_ALIGN(stack_top);
44969
44970 - if (unlikely(stack_top < mmap_min_addr) ||
44971 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44972 - return -ENOMEM;
44973 -
44974 stack_shift = vma->vm_end - stack_top;
44975
44976 bprm->p -= stack_shift;
44977 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44978 bprm->exec -= stack_shift;
44979
44980 down_write(&mm->mmap_sem);
44981 +
44982 + /* Move stack pages down in memory. */
44983 + if (stack_shift) {
44984 + ret = shift_arg_pages(vma, stack_shift);
44985 + if (ret)
44986 + goto out_unlock;
44987 + }
44988 +
44989 vm_flags = VM_STACK_FLAGS;
44990
44991 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44992 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44993 + vm_flags &= ~VM_EXEC;
44994 +
44995 +#ifdef CONFIG_PAX_MPROTECT
44996 + if (mm->pax_flags & MF_PAX_MPROTECT)
44997 + vm_flags &= ~VM_MAYEXEC;
44998 +#endif
44999 +
45000 + }
45001 +#endif
45002 +
45003 /*
45004 * Adjust stack execute permissions; explicitly enable for
45005 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45006 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45007 goto out_unlock;
45008 BUG_ON(prev != vma);
45009
45010 - /* Move stack pages down in memory. */
45011 - if (stack_shift) {
45012 - ret = shift_arg_pages(vma, stack_shift);
45013 - if (ret)
45014 - goto out_unlock;
45015 - }
45016 -
45017 /* mprotect_fixup is overkill to remove the temporary stack flags */
45018 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45019
45020 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45021
45022 fsnotify_open(file);
45023
45024 + trace_open_exec(name);
45025 +
45026 err = deny_write_access(file);
45027 if (err)
45028 goto exit;
45029 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45030 old_fs = get_fs();
45031 set_fs(get_ds());
45032 /* The cast to a user pointer is valid due to the set_fs() */
45033 - result = vfs_read(file, (void __user *)addr, count, &pos);
45034 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45035 set_fs(old_fs);
45036 return result;
45037 }
45038 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45039 }
45040 rcu_read_unlock();
45041
45042 - if (p->fs->users > n_fs) {
45043 + if (atomic_read(&p->fs->users) > n_fs) {
45044 bprm->unsafe |= LSM_UNSAFE_SHARE;
45045 } else {
45046 res = -EAGAIN;
45047 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45048
45049 EXPORT_SYMBOL(search_binary_handler);
45050
45051 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45052 +static DEFINE_PER_CPU(u64, exec_counter);
45053 +static int __init init_exec_counters(void)
45054 +{
45055 + unsigned int cpu;
45056 +
45057 + for_each_possible_cpu(cpu) {
45058 + per_cpu(exec_counter, cpu) = (u64)cpu;
45059 + }
45060 +
45061 + return 0;
45062 +}
45063 +early_initcall(init_exec_counters);
45064 +static inline void increment_exec_counter(void)
45065 +{
45066 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45067 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45068 +}
45069 +#else
45070 +static inline void increment_exec_counter(void) {}
45071 +#endif
45072 +
45073 /*
45074 * sys_execve() executes a new program.
45075 */
45076 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45077 struct user_arg_ptr envp,
45078 struct pt_regs *regs)
45079 {
45080 +#ifdef CONFIG_GRKERNSEC
45081 + struct file *old_exec_file;
45082 + struct acl_subject_label *old_acl;
45083 + struct rlimit old_rlim[RLIM_NLIMITS];
45084 +#endif
45085 struct linux_binprm *bprm;
45086 struct file *file;
45087 struct files_struct *displaced;
45088 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45089 int retval;
45090 const struct cred *cred = current_cred();
45091
45092 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45093 +
45094 /*
45095 * We move the actual failure in case of RLIMIT_NPROC excess from
45096 * set*uid() to execve() because too many poorly written programs
45097 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45098 if (IS_ERR(file))
45099 goto out_unmark;
45100
45101 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45102 + retval = -EPERM;
45103 + goto out_file;
45104 + }
45105 +
45106 sched_exec();
45107
45108 bprm->file = file;
45109 bprm->filename = filename;
45110 bprm->interp = filename;
45111
45112 + if (gr_process_user_ban()) {
45113 + retval = -EPERM;
45114 + goto out_file;
45115 + }
45116 +
45117 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45118 + retval = -EACCES;
45119 + goto out_file;
45120 + }
45121 +
45122 retval = bprm_mm_init(bprm);
45123 if (retval)
45124 goto out_file;
45125 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45126 if (retval < 0)
45127 goto out;
45128
45129 +#ifdef CONFIG_GRKERNSEC
45130 + old_acl = current->acl;
45131 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45132 + old_exec_file = current->exec_file;
45133 + get_file(file);
45134 + current->exec_file = file;
45135 +#endif
45136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45137 + /* limit suid stack to 8MB
45138 + we saved the old limits above and will restore them if this exec fails
45139 + */
45140 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45141 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45142 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45143 +#endif
45144 +
45145 + if (!gr_tpe_allow(file)) {
45146 + retval = -EACCES;
45147 + goto out_fail;
45148 + }
45149 +
45150 + if (gr_check_crash_exec(file)) {
45151 + retval = -EACCES;
45152 + goto out_fail;
45153 + }
45154 +
45155 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45156 + bprm->unsafe);
45157 + if (retval < 0)
45158 + goto out_fail;
45159 +
45160 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45161 if (retval < 0)
45162 - goto out;
45163 + goto out_fail;
45164
45165 bprm->exec = bprm->p;
45166 retval = copy_strings(bprm->envc, envp, bprm);
45167 if (retval < 0)
45168 - goto out;
45169 + goto out_fail;
45170
45171 retval = copy_strings(bprm->argc, argv, bprm);
45172 if (retval < 0)
45173 - goto out;
45174 + goto out_fail;
45175 +
45176 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45177 +
45178 + gr_handle_exec_args(bprm, argv);
45179
45180 retval = search_binary_handler(bprm,regs);
45181 if (retval < 0)
45182 - goto out;
45183 + goto out_fail;
45184 +#ifdef CONFIG_GRKERNSEC
45185 + if (old_exec_file)
45186 + fput(old_exec_file);
45187 +#endif
45188
45189 /* execve succeeded */
45190 +
45191 + increment_exec_counter();
45192 current->fs->in_exec = 0;
45193 current->in_execve = 0;
45194 acct_update_integrals(current);
45195 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45196 put_files_struct(displaced);
45197 return retval;
45198
45199 +out_fail:
45200 +#ifdef CONFIG_GRKERNSEC
45201 + current->acl = old_acl;
45202 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45203 + fput(current->exec_file);
45204 + current->exec_file = old_exec_file;
45205 +#endif
45206 +
45207 out:
45208 if (bprm->mm) {
45209 acct_arg_size(bprm, 0);
45210 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45211 {
45212 char *old_corename = cn->corename;
45213
45214 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45215 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45216 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45217
45218 if (!cn->corename) {
45219 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45220 int pid_in_pattern = 0;
45221 int err = 0;
45222
45223 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45224 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45225 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45226 cn->used = 0;
45227
45228 @@ -1830,6 +1962,250 @@ out:
45229 return ispipe;
45230 }
45231
45232 +int pax_check_flags(unsigned long *flags)
45233 +{
45234 + int retval = 0;
45235 +
45236 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45237 + if (*flags & MF_PAX_SEGMEXEC)
45238 + {
45239 + *flags &= ~MF_PAX_SEGMEXEC;
45240 + retval = -EINVAL;
45241 + }
45242 +#endif
45243 +
45244 + if ((*flags & MF_PAX_PAGEEXEC)
45245 +
45246 +#ifdef CONFIG_PAX_PAGEEXEC
45247 + && (*flags & MF_PAX_SEGMEXEC)
45248 +#endif
45249 +
45250 + )
45251 + {
45252 + *flags &= ~MF_PAX_PAGEEXEC;
45253 + retval = -EINVAL;
45254 + }
45255 +
45256 + if ((*flags & MF_PAX_MPROTECT)
45257 +
45258 +#ifdef CONFIG_PAX_MPROTECT
45259 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45260 +#endif
45261 +
45262 + )
45263 + {
45264 + *flags &= ~MF_PAX_MPROTECT;
45265 + retval = -EINVAL;
45266 + }
45267 +
45268 + if ((*flags & MF_PAX_EMUTRAMP)
45269 +
45270 +#ifdef CONFIG_PAX_EMUTRAMP
45271 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45272 +#endif
45273 +
45274 + )
45275 + {
45276 + *flags &= ~MF_PAX_EMUTRAMP;
45277 + retval = -EINVAL;
45278 + }
45279 +
45280 + return retval;
45281 +}
45282 +
45283 +EXPORT_SYMBOL(pax_check_flags);
45284 +
45285 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45286 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45287 +{
45288 + struct task_struct *tsk = current;
45289 + struct mm_struct *mm = current->mm;
45290 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45291 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45292 + char *path_exec = NULL;
45293 + char *path_fault = NULL;
45294 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45295 +
45296 + if (buffer_exec && buffer_fault) {
45297 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45298 +
45299 + down_read(&mm->mmap_sem);
45300 + vma = mm->mmap;
45301 + while (vma && (!vma_exec || !vma_fault)) {
45302 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45303 + vma_exec = vma;
45304 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45305 + vma_fault = vma;
45306 + vma = vma->vm_next;
45307 + }
45308 + if (vma_exec) {
45309 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45310 + if (IS_ERR(path_exec))
45311 + path_exec = "<path too long>";
45312 + else {
45313 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45314 + if (path_exec) {
45315 + *path_exec = 0;
45316 + path_exec = buffer_exec;
45317 + } else
45318 + path_exec = "<path too long>";
45319 + }
45320 + }
45321 + if (vma_fault) {
45322 + start = vma_fault->vm_start;
45323 + end = vma_fault->vm_end;
45324 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45325 + if (vma_fault->vm_file) {
45326 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45327 + if (IS_ERR(path_fault))
45328 + path_fault = "<path too long>";
45329 + else {
45330 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45331 + if (path_fault) {
45332 + *path_fault = 0;
45333 + path_fault = buffer_fault;
45334 + } else
45335 + path_fault = "<path too long>";
45336 + }
45337 + } else
45338 + path_fault = "<anonymous mapping>";
45339 + }
45340 + up_read(&mm->mmap_sem);
45341 + }
45342 + if (tsk->signal->curr_ip)
45343 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45344 + else
45345 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45346 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45347 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45348 + task_uid(tsk), task_euid(tsk), pc, sp);
45349 + free_page((unsigned long)buffer_exec);
45350 + free_page((unsigned long)buffer_fault);
45351 + pax_report_insns(regs, pc, sp);
45352 + do_coredump(SIGKILL, SIGKILL, regs);
45353 +}
45354 +#endif
45355 +
45356 +#ifdef CONFIG_PAX_REFCOUNT
45357 +void pax_report_refcount_overflow(struct pt_regs *regs)
45358 +{
45359 + if (current->signal->curr_ip)
45360 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45361 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45362 + else
45363 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45364 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45365 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45366 + show_regs(regs);
45367 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45368 +}
45369 +#endif
45370 +
45371 +#ifdef CONFIG_PAX_USERCOPY
45372 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45373 +static noinline int check_stack_object(const void *obj, unsigned long len)
45374 +{
45375 + const void * const stack = task_stack_page(current);
45376 + const void * const stackend = stack + THREAD_SIZE;
45377 +
45378 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45379 + const void *frame = NULL;
45380 + const void *oldframe;
45381 +#endif
45382 +
45383 + if (obj + len < obj)
45384 + return -1;
45385 +
45386 + if (obj + len <= stack || stackend <= obj)
45387 + return 0;
45388 +
45389 + if (obj < stack || stackend < obj + len)
45390 + return -1;
45391 +
45392 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45393 + oldframe = __builtin_frame_address(1);
45394 + if (oldframe)
45395 + frame = __builtin_frame_address(2);
45396 + /*
45397 + low ----------------------------------------------> high
45398 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45399 + ^----------------^
45400 + allow copies only within here
45401 + */
45402 + while (stack <= frame && frame < stackend) {
45403 + /* if obj + len extends past the last frame, this
45404 + check won't pass and the next frame will be 0,
45405 + causing us to bail out and correctly report
45406 + the copy as invalid
45407 + */
45408 + if (obj + len <= frame)
45409 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45410 + oldframe = frame;
45411 + frame = *(const void * const *)frame;
45412 + }
45413 + return -1;
45414 +#else
45415 + return 1;
45416 +#endif
45417 +}
45418 +
45419 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45420 +{
45421 + if (current->signal->curr_ip)
45422 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45423 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45424 + else
45425 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45426 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45427 + dump_stack();
45428 + gr_handle_kernel_exploit();
45429 + do_group_exit(SIGKILL);
45430 +}
45431 +#endif
45432 +
45433 +void check_object_size(const void *ptr, unsigned long n, bool to)
45434 +{
45435 +
45436 +#ifdef CONFIG_PAX_USERCOPY
45437 + const char *type;
45438 +
45439 + if (!n)
45440 + return;
45441 +
45442 + type = check_heap_object(ptr, n, to);
45443 + if (!type) {
45444 + if (check_stack_object(ptr, n) != -1)
45445 + return;
45446 + type = "<process stack>";
45447 + }
45448 +
45449 + pax_report_usercopy(ptr, n, to, type);
45450 +#endif
45451 +
45452 +}
45453 +EXPORT_SYMBOL(check_object_size);
45454 +
45455 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45456 +void pax_track_stack(void)
45457 +{
45458 + unsigned long sp = (unsigned long)&sp;
45459 + if (sp < current_thread_info()->lowest_stack &&
45460 + sp > (unsigned long)task_stack_page(current))
45461 + current_thread_info()->lowest_stack = sp;
45462 +}
45463 +EXPORT_SYMBOL(pax_track_stack);
45464 +#endif
45465 +
45466 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45467 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45468 +{
45469 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45470 + dump_stack();
45471 + do_group_exit(SIGKILL);
45472 +}
45473 +EXPORT_SYMBOL(report_size_overflow);
45474 +#endif
45475 +
45476 static int zap_process(struct task_struct *start, int exit_code)
45477 {
45478 struct task_struct *t;
45479 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45480 pipe = file->f_path.dentry->d_inode->i_pipe;
45481
45482 pipe_lock(pipe);
45483 - pipe->readers++;
45484 - pipe->writers--;
45485 + atomic_inc(&pipe->readers);
45486 + atomic_dec(&pipe->writers);
45487
45488 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45489 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45490 wake_up_interruptible_sync(&pipe->wait);
45491 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45492 pipe_wait(pipe);
45493 }
45494
45495 - pipe->readers--;
45496 - pipe->writers++;
45497 + atomic_dec(&pipe->readers);
45498 + atomic_inc(&pipe->writers);
45499 pipe_unlock(pipe);
45500
45501 }
45502 @@ -2105,7 +2481,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45503 int flag = 0;
45504 int ispipe;
45505 bool need_nonrelative = false;
45506 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45507 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45508 struct coredump_params cprm = {
45509 .signr = signr,
45510 .regs = regs,
45511 @@ -2120,6 +2496,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45512
45513 audit_core_dumps(signr);
45514
45515 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45516 + gr_handle_brute_attach(current, cprm.mm_flags);
45517 +
45518 binfmt = mm->binfmt;
45519 if (!binfmt || !binfmt->core_dump)
45520 goto fail;
45521 @@ -2190,7 +2569,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45522 }
45523 cprm.limit = RLIM_INFINITY;
45524
45525 - dump_count = atomic_inc_return(&core_dump_count);
45526 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45527 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45528 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45529 task_tgid_vnr(current), current->comm);
45530 @@ -2217,6 +2596,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45531 } else {
45532 struct inode *inode;
45533
45534 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45535 +
45536 if (cprm.limit < binfmt->min_coredump)
45537 goto fail_unlock;
45538
45539 @@ -2268,7 +2649,7 @@ close_fail:
45540 filp_close(cprm.file, NULL);
45541 fail_dropcount:
45542 if (ispipe)
45543 - atomic_dec(&core_dump_count);
45544 + atomic_dec_unchecked(&core_dump_count);
45545 fail_unlock:
45546 kfree(cn.corename);
45547 fail_corename:
45548 @@ -2287,7 +2668,7 @@ fail:
45549 */
45550 int dump_write(struct file *file, const void *addr, int nr)
45551 {
45552 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45553 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45554 }
45555 EXPORT_SYMBOL(dump_write);
45556
45557 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45558 index 376aa77..59a129c 100644
45559 --- a/fs/ext2/balloc.c
45560 +++ b/fs/ext2/balloc.c
45561 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45562
45563 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45564 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45565 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45566 + if (free_blocks < root_blocks + 1 &&
45567 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45568 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45569 - !in_group_p (sbi->s_resgid))) {
45570 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45571 return 0;
45572 }
45573 return 1;
45574 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45575 index 90d901f..159975f 100644
45576 --- a/fs/ext3/balloc.c
45577 +++ b/fs/ext3/balloc.c
45578 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45579
45580 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45581 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45582 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45583 + if (free_blocks < root_blocks + 1 &&
45584 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45585 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45586 - !in_group_p (sbi->s_resgid))) {
45587 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45588 return 0;
45589 }
45590 return 1;
45591 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45592 index 1b50890..e56c5ad 100644
45593 --- a/fs/ext4/balloc.c
45594 +++ b/fs/ext4/balloc.c
45595 @@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45596 /* Hm, nope. Are (enough) root reserved clusters available? */
45597 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45598 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45599 - capable(CAP_SYS_RESOURCE) ||
45600 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45601 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45602 + capable_nolog(CAP_SYS_RESOURCE)) {
45603
45604 if (free_clusters >= (nclusters + dirty_clusters))
45605 return 1;
45606 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45607 index c3411d4..30e4f1b 100644
45608 --- a/fs/ext4/ext4.h
45609 +++ b/fs/ext4/ext4.h
45610 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45611 unsigned long s_mb_last_start;
45612
45613 /* stats for buddy allocator */
45614 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45615 - atomic_t s_bal_success; /* we found long enough chunks */
45616 - atomic_t s_bal_allocated; /* in blocks */
45617 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45618 - atomic_t s_bal_goals; /* goal hits */
45619 - atomic_t s_bal_breaks; /* too long searches */
45620 - atomic_t s_bal_2orders; /* 2^order hits */
45621 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45622 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45623 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45624 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45625 + atomic_unchecked_t s_bal_goals; /* goal hits */
45626 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45627 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45628 spinlock_t s_bal_lock;
45629 unsigned long s_mb_buddies_generated;
45630 unsigned long long s_mb_generation_time;
45631 - atomic_t s_mb_lost_chunks;
45632 - atomic_t s_mb_preallocated;
45633 - atomic_t s_mb_discarded;
45634 + atomic_unchecked_t s_mb_lost_chunks;
45635 + atomic_unchecked_t s_mb_preallocated;
45636 + atomic_unchecked_t s_mb_discarded;
45637 atomic_t s_lock_busy;
45638
45639 /* locality groups */
45640 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45641 index 8eae947..53fc27a 100644
45642 --- a/fs/ext4/mballoc.c
45643 +++ b/fs/ext4/mballoc.c
45644 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45645 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45646
45647 if (EXT4_SB(sb)->s_mb_stats)
45648 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45649 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45650
45651 break;
45652 }
45653 @@ -2040,7 +2040,7 @@ repeat:
45654 ac->ac_status = AC_STATUS_CONTINUE;
45655 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45656 cr = 3;
45657 - atomic_inc(&sbi->s_mb_lost_chunks);
45658 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45659 goto repeat;
45660 }
45661 }
45662 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45663 if (sbi->s_mb_stats) {
45664 ext4_msg(sb, KERN_INFO,
45665 "mballoc: %u blocks %u reqs (%u success)",
45666 - atomic_read(&sbi->s_bal_allocated),
45667 - atomic_read(&sbi->s_bal_reqs),
45668 - atomic_read(&sbi->s_bal_success));
45669 + atomic_read_unchecked(&sbi->s_bal_allocated),
45670 + atomic_read_unchecked(&sbi->s_bal_reqs),
45671 + atomic_read_unchecked(&sbi->s_bal_success));
45672 ext4_msg(sb, KERN_INFO,
45673 "mballoc: %u extents scanned, %u goal hits, "
45674 "%u 2^N hits, %u breaks, %u lost",
45675 - atomic_read(&sbi->s_bal_ex_scanned),
45676 - atomic_read(&sbi->s_bal_goals),
45677 - atomic_read(&sbi->s_bal_2orders),
45678 - atomic_read(&sbi->s_bal_breaks),
45679 - atomic_read(&sbi->s_mb_lost_chunks));
45680 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45681 + atomic_read_unchecked(&sbi->s_bal_goals),
45682 + atomic_read_unchecked(&sbi->s_bal_2orders),
45683 + atomic_read_unchecked(&sbi->s_bal_breaks),
45684 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45685 ext4_msg(sb, KERN_INFO,
45686 "mballoc: %lu generated and it took %Lu",
45687 sbi->s_mb_buddies_generated,
45688 sbi->s_mb_generation_time);
45689 ext4_msg(sb, KERN_INFO,
45690 "mballoc: %u preallocated, %u discarded",
45691 - atomic_read(&sbi->s_mb_preallocated),
45692 - atomic_read(&sbi->s_mb_discarded));
45693 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45694 + atomic_read_unchecked(&sbi->s_mb_discarded));
45695 }
45696
45697 free_percpu(sbi->s_locality_groups);
45698 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45699 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45700
45701 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45702 - atomic_inc(&sbi->s_bal_reqs);
45703 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45704 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45705 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45706 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45707 - atomic_inc(&sbi->s_bal_success);
45708 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45709 + atomic_inc_unchecked(&sbi->s_bal_success);
45710 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45711 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45712 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45713 - atomic_inc(&sbi->s_bal_goals);
45714 + atomic_inc_unchecked(&sbi->s_bal_goals);
45715 if (ac->ac_found > sbi->s_mb_max_to_scan)
45716 - atomic_inc(&sbi->s_bal_breaks);
45717 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45718 }
45719
45720 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45721 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45722 trace_ext4_mb_new_inode_pa(ac, pa);
45723
45724 ext4_mb_use_inode_pa(ac, pa);
45725 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45726 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45727
45728 ei = EXT4_I(ac->ac_inode);
45729 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45730 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45731 trace_ext4_mb_new_group_pa(ac, pa);
45732
45733 ext4_mb_use_group_pa(ac, pa);
45734 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45735 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45736
45737 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45738 lg = ac->ac_lg;
45739 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45740 * from the bitmap and continue.
45741 */
45742 }
45743 - atomic_add(free, &sbi->s_mb_discarded);
45744 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45745
45746 return err;
45747 }
45748 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45749 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45750 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45751 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45752 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45753 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45754 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45755
45756 return 0;
45757 diff --git a/fs/fcntl.c b/fs/fcntl.c
45758 index 887b5ba..0e3f2c3 100644
45759 --- a/fs/fcntl.c
45760 +++ b/fs/fcntl.c
45761 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45762 if (err)
45763 return err;
45764
45765 + if (gr_handle_chroot_fowner(pid, type))
45766 + return -ENOENT;
45767 + if (gr_check_protected_task_fowner(pid, type))
45768 + return -EACCES;
45769 +
45770 f_modown(filp, pid, type, force);
45771 return 0;
45772 }
45773 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45774
45775 static int f_setown_ex(struct file *filp, unsigned long arg)
45776 {
45777 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45778 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45779 struct f_owner_ex owner;
45780 struct pid *pid;
45781 int type;
45782 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45783
45784 static int f_getown_ex(struct file *filp, unsigned long arg)
45785 {
45786 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45787 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45788 struct f_owner_ex owner;
45789 int ret = 0;
45790
45791 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45792 switch (cmd) {
45793 case F_DUPFD:
45794 case F_DUPFD_CLOEXEC:
45795 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45796 if (arg >= rlimit(RLIMIT_NOFILE))
45797 break;
45798 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45799 diff --git a/fs/fifo.c b/fs/fifo.c
45800 index cf6f434..3d7942c 100644
45801 --- a/fs/fifo.c
45802 +++ b/fs/fifo.c
45803 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45804 */
45805 filp->f_op = &read_pipefifo_fops;
45806 pipe->r_counter++;
45807 - if (pipe->readers++ == 0)
45808 + if (atomic_inc_return(&pipe->readers) == 1)
45809 wake_up_partner(inode);
45810
45811 - if (!pipe->writers) {
45812 + if (!atomic_read(&pipe->writers)) {
45813 if ((filp->f_flags & O_NONBLOCK)) {
45814 /* suppress POLLHUP until we have
45815 * seen a writer */
45816 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45817 * errno=ENXIO when there is no process reading the FIFO.
45818 */
45819 ret = -ENXIO;
45820 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45821 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45822 goto err;
45823
45824 filp->f_op = &write_pipefifo_fops;
45825 pipe->w_counter++;
45826 - if (!pipe->writers++)
45827 + if (atomic_inc_return(&pipe->writers) == 1)
45828 wake_up_partner(inode);
45829
45830 - if (!pipe->readers) {
45831 + if (!atomic_read(&pipe->readers)) {
45832 if (wait_for_partner(inode, &pipe->r_counter))
45833 goto err_wr;
45834 }
45835 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45836 */
45837 filp->f_op = &rdwr_pipefifo_fops;
45838
45839 - pipe->readers++;
45840 - pipe->writers++;
45841 + atomic_inc(&pipe->readers);
45842 + atomic_inc(&pipe->writers);
45843 pipe->r_counter++;
45844 pipe->w_counter++;
45845 - if (pipe->readers == 1 || pipe->writers == 1)
45846 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45847 wake_up_partner(inode);
45848 break;
45849
45850 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45851 return 0;
45852
45853 err_rd:
45854 - if (!--pipe->readers)
45855 + if (atomic_dec_and_test(&pipe->readers))
45856 wake_up_interruptible(&pipe->wait);
45857 ret = -ERESTARTSYS;
45858 goto err;
45859
45860 err_wr:
45861 - if (!--pipe->writers)
45862 + if (atomic_dec_and_test(&pipe->writers))
45863 wake_up_interruptible(&pipe->wait);
45864 ret = -ERESTARTSYS;
45865 goto err;
45866
45867 err:
45868 - if (!pipe->readers && !pipe->writers)
45869 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45870 free_pipe_info(inode);
45871
45872 err_nocleanup:
45873 diff --git a/fs/file.c b/fs/file.c
45874 index ba3f605..fade102 100644
45875 --- a/fs/file.c
45876 +++ b/fs/file.c
45877 @@ -15,6 +15,7 @@
45878 #include <linux/slab.h>
45879 #include <linux/vmalloc.h>
45880 #include <linux/file.h>
45881 +#include <linux/security.h>
45882 #include <linux/fdtable.h>
45883 #include <linux/bitops.h>
45884 #include <linux/interrupt.h>
45885 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45886 * N.B. For clone tasks sharing a files structure, this test
45887 * will limit the total number of files that can be opened.
45888 */
45889 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45890 if (nr >= rlimit(RLIMIT_NOFILE))
45891 return -EMFILE;
45892
45893 diff --git a/fs/filesystems.c b/fs/filesystems.c
45894 index 96f2428..f5eeb8e 100644
45895 --- a/fs/filesystems.c
45896 +++ b/fs/filesystems.c
45897 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45898 int len = dot ? dot - name : strlen(name);
45899
45900 fs = __get_fs_type(name, len);
45901 +
45902 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45903 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45904 +#else
45905 if (!fs && (request_module("%.*s", len, name) == 0))
45906 +#endif
45907 fs = __get_fs_type(name, len);
45908
45909 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45910 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45911 index 5df4775..9d9336f 100644
45912 --- a/fs/fs_struct.c
45913 +++ b/fs/fs_struct.c
45914 @@ -4,6 +4,7 @@
45915 #include <linux/path.h>
45916 #include <linux/slab.h>
45917 #include <linux/fs_struct.h>
45918 +#include <linux/grsecurity.h>
45919 #include "internal.h"
45920
45921 /*
45922 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45923 write_seqcount_begin(&fs->seq);
45924 old_root = fs->root;
45925 fs->root = *path;
45926 + gr_set_chroot_entries(current, path);
45927 write_seqcount_end(&fs->seq);
45928 spin_unlock(&fs->lock);
45929 if (old_root.dentry)
45930 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45931 return 1;
45932 }
45933
45934 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45935 +{
45936 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45937 + return 0;
45938 + *p = *new;
45939 +
45940 + /* This function is only called from pivot_root(). Leave our
45941 + gr_chroot_dentry and is_chrooted flags as-is, so that a
45942 + pivoted root isn't treated as a chroot
45943 + */
45944 + //gr_set_chroot_entries(task, new);
45945 +
45946 + return 1;
45947 +}
45948 +
45949 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45950 {
45951 struct task_struct *g, *p;
45952 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45953 int hits = 0;
45954 spin_lock(&fs->lock);
45955 write_seqcount_begin(&fs->seq);
45956 - hits += replace_path(&fs->root, old_root, new_root);
45957 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45958 hits += replace_path(&fs->pwd, old_root, new_root);
45959 write_seqcount_end(&fs->seq);
45960 while (hits--) {
45961 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
45962 task_lock(tsk);
45963 spin_lock(&fs->lock);
45964 tsk->fs = NULL;
45965 - kill = !--fs->users;
45966 + gr_clear_chroot_entries(tsk);
45967 + kill = !atomic_dec_return(&fs->users);
45968 spin_unlock(&fs->lock);
45969 task_unlock(tsk);
45970 if (kill)
45971 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45972 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45973 /* We don't need to lock fs - think why ;-) */
45974 if (fs) {
45975 - fs->users = 1;
45976 + atomic_set(&fs->users, 1);
45977 fs->in_exec = 0;
45978 spin_lock_init(&fs->lock);
45979 seqcount_init(&fs->seq);
45980 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45981 spin_lock(&old->lock);
45982 fs->root = old->root;
45983 path_get(&fs->root);
45984 + /* instead of calling gr_set_chroot_entries here,
45985 + we call it from every caller of this function
45986 + */
45987 fs->pwd = old->pwd;
45988 path_get(&fs->pwd);
45989 spin_unlock(&old->lock);
45990 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
45991
45992 task_lock(current);
45993 spin_lock(&fs->lock);
45994 - kill = !--fs->users;
45995 + kill = !atomic_dec_return(&fs->users);
45996 current->fs = new_fs;
45997 + gr_set_chroot_entries(current, &new_fs->root);
45998 spin_unlock(&fs->lock);
45999 task_unlock(current);
46000
46001 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46002
46003 int current_umask(void)
46004 {
46005 - return current->fs->umask;
46006 + return current->fs->umask | gr_acl_umask();
46007 }
46008 EXPORT_SYMBOL(current_umask);
46009
46010 /* to be mentioned only in INIT_TASK */
46011 struct fs_struct init_fs = {
46012 - .users = 1,
46013 + .users = ATOMIC_INIT(1),
46014 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46015 .seq = SEQCNT_ZERO,
46016 .umask = 0022,
46017 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46018 task_lock(current);
46019
46020 spin_lock(&init_fs.lock);
46021 - init_fs.users++;
46022 + atomic_inc(&init_fs.users);
46023 spin_unlock(&init_fs.lock);
46024
46025 spin_lock(&fs->lock);
46026 current->fs = &init_fs;
46027 - kill = !--fs->users;
46028 + gr_set_chroot_entries(current, &current->fs->root);
46029 + kill = !atomic_dec_return(&fs->users);
46030 spin_unlock(&fs->lock);
46031
46032 task_unlock(current);
46033 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46034 index 9905350..02eaec4 100644
46035 --- a/fs/fscache/cookie.c
46036 +++ b/fs/fscache/cookie.c
46037 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46038 parent ? (char *) parent->def->name : "<no-parent>",
46039 def->name, netfs_data);
46040
46041 - fscache_stat(&fscache_n_acquires);
46042 + fscache_stat_unchecked(&fscache_n_acquires);
46043
46044 /* if there's no parent cookie, then we don't create one here either */
46045 if (!parent) {
46046 - fscache_stat(&fscache_n_acquires_null);
46047 + fscache_stat_unchecked(&fscache_n_acquires_null);
46048 _leave(" [no parent]");
46049 return NULL;
46050 }
46051 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46052 /* allocate and initialise a cookie */
46053 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46054 if (!cookie) {
46055 - fscache_stat(&fscache_n_acquires_oom);
46056 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46057 _leave(" [ENOMEM]");
46058 return NULL;
46059 }
46060 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46061
46062 switch (cookie->def->type) {
46063 case FSCACHE_COOKIE_TYPE_INDEX:
46064 - fscache_stat(&fscache_n_cookie_index);
46065 + fscache_stat_unchecked(&fscache_n_cookie_index);
46066 break;
46067 case FSCACHE_COOKIE_TYPE_DATAFILE:
46068 - fscache_stat(&fscache_n_cookie_data);
46069 + fscache_stat_unchecked(&fscache_n_cookie_data);
46070 break;
46071 default:
46072 - fscache_stat(&fscache_n_cookie_special);
46073 + fscache_stat_unchecked(&fscache_n_cookie_special);
46074 break;
46075 }
46076
46077 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46078 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46079 atomic_dec(&parent->n_children);
46080 __fscache_cookie_put(cookie);
46081 - fscache_stat(&fscache_n_acquires_nobufs);
46082 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46083 _leave(" = NULL");
46084 return NULL;
46085 }
46086 }
46087
46088 - fscache_stat(&fscache_n_acquires_ok);
46089 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46090 _leave(" = %p", cookie);
46091 return cookie;
46092 }
46093 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46094 cache = fscache_select_cache_for_object(cookie->parent);
46095 if (!cache) {
46096 up_read(&fscache_addremove_sem);
46097 - fscache_stat(&fscache_n_acquires_no_cache);
46098 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46099 _leave(" = -ENOMEDIUM [no cache]");
46100 return -ENOMEDIUM;
46101 }
46102 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46103 object = cache->ops->alloc_object(cache, cookie);
46104 fscache_stat_d(&fscache_n_cop_alloc_object);
46105 if (IS_ERR(object)) {
46106 - fscache_stat(&fscache_n_object_no_alloc);
46107 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46108 ret = PTR_ERR(object);
46109 goto error;
46110 }
46111
46112 - fscache_stat(&fscache_n_object_alloc);
46113 + fscache_stat_unchecked(&fscache_n_object_alloc);
46114
46115 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46116
46117 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46118 struct fscache_object *object;
46119 struct hlist_node *_p;
46120
46121 - fscache_stat(&fscache_n_updates);
46122 + fscache_stat_unchecked(&fscache_n_updates);
46123
46124 if (!cookie) {
46125 - fscache_stat(&fscache_n_updates_null);
46126 + fscache_stat_unchecked(&fscache_n_updates_null);
46127 _leave(" [no cookie]");
46128 return;
46129 }
46130 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46131 struct fscache_object *object;
46132 unsigned long event;
46133
46134 - fscache_stat(&fscache_n_relinquishes);
46135 + fscache_stat_unchecked(&fscache_n_relinquishes);
46136 if (retire)
46137 - fscache_stat(&fscache_n_relinquishes_retire);
46138 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46139
46140 if (!cookie) {
46141 - fscache_stat(&fscache_n_relinquishes_null);
46142 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46143 _leave(" [no cookie]");
46144 return;
46145 }
46146 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46147
46148 /* wait for the cookie to finish being instantiated (or to fail) */
46149 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46150 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46151 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46152 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46153 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46154 }
46155 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46156 index f6aad48..88dcf26 100644
46157 --- a/fs/fscache/internal.h
46158 +++ b/fs/fscache/internal.h
46159 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46160 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46161 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46162
46163 -extern atomic_t fscache_n_op_pend;
46164 -extern atomic_t fscache_n_op_run;
46165 -extern atomic_t fscache_n_op_enqueue;
46166 -extern atomic_t fscache_n_op_deferred_release;
46167 -extern atomic_t fscache_n_op_release;
46168 -extern atomic_t fscache_n_op_gc;
46169 -extern atomic_t fscache_n_op_cancelled;
46170 -extern atomic_t fscache_n_op_rejected;
46171 +extern atomic_unchecked_t fscache_n_op_pend;
46172 +extern atomic_unchecked_t fscache_n_op_run;
46173 +extern atomic_unchecked_t fscache_n_op_enqueue;
46174 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46175 +extern atomic_unchecked_t fscache_n_op_release;
46176 +extern atomic_unchecked_t fscache_n_op_gc;
46177 +extern atomic_unchecked_t fscache_n_op_cancelled;
46178 +extern atomic_unchecked_t fscache_n_op_rejected;
46179
46180 -extern atomic_t fscache_n_attr_changed;
46181 -extern atomic_t fscache_n_attr_changed_ok;
46182 -extern atomic_t fscache_n_attr_changed_nobufs;
46183 -extern atomic_t fscache_n_attr_changed_nomem;
46184 -extern atomic_t fscache_n_attr_changed_calls;
46185 +extern atomic_unchecked_t fscache_n_attr_changed;
46186 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46187 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46188 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46189 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46190
46191 -extern atomic_t fscache_n_allocs;
46192 -extern atomic_t fscache_n_allocs_ok;
46193 -extern atomic_t fscache_n_allocs_wait;
46194 -extern atomic_t fscache_n_allocs_nobufs;
46195 -extern atomic_t fscache_n_allocs_intr;
46196 -extern atomic_t fscache_n_allocs_object_dead;
46197 -extern atomic_t fscache_n_alloc_ops;
46198 -extern atomic_t fscache_n_alloc_op_waits;
46199 +extern atomic_unchecked_t fscache_n_allocs;
46200 +extern atomic_unchecked_t fscache_n_allocs_ok;
46201 +extern atomic_unchecked_t fscache_n_allocs_wait;
46202 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46203 +extern atomic_unchecked_t fscache_n_allocs_intr;
46204 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46205 +extern atomic_unchecked_t fscache_n_alloc_ops;
46206 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46207
46208 -extern atomic_t fscache_n_retrievals;
46209 -extern atomic_t fscache_n_retrievals_ok;
46210 -extern atomic_t fscache_n_retrievals_wait;
46211 -extern atomic_t fscache_n_retrievals_nodata;
46212 -extern atomic_t fscache_n_retrievals_nobufs;
46213 -extern atomic_t fscache_n_retrievals_intr;
46214 -extern atomic_t fscache_n_retrievals_nomem;
46215 -extern atomic_t fscache_n_retrievals_object_dead;
46216 -extern atomic_t fscache_n_retrieval_ops;
46217 -extern atomic_t fscache_n_retrieval_op_waits;
46218 +extern atomic_unchecked_t fscache_n_retrievals;
46219 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46220 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46221 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46222 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46223 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46224 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46225 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46226 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46227 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46228
46229 -extern atomic_t fscache_n_stores;
46230 -extern atomic_t fscache_n_stores_ok;
46231 -extern atomic_t fscache_n_stores_again;
46232 -extern atomic_t fscache_n_stores_nobufs;
46233 -extern atomic_t fscache_n_stores_oom;
46234 -extern atomic_t fscache_n_store_ops;
46235 -extern atomic_t fscache_n_store_calls;
46236 -extern atomic_t fscache_n_store_pages;
46237 -extern atomic_t fscache_n_store_radix_deletes;
46238 -extern atomic_t fscache_n_store_pages_over_limit;
46239 +extern atomic_unchecked_t fscache_n_stores;
46240 +extern atomic_unchecked_t fscache_n_stores_ok;
46241 +extern atomic_unchecked_t fscache_n_stores_again;
46242 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46243 +extern atomic_unchecked_t fscache_n_stores_oom;
46244 +extern atomic_unchecked_t fscache_n_store_ops;
46245 +extern atomic_unchecked_t fscache_n_store_calls;
46246 +extern atomic_unchecked_t fscache_n_store_pages;
46247 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46248 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46249
46250 -extern atomic_t fscache_n_store_vmscan_not_storing;
46251 -extern atomic_t fscache_n_store_vmscan_gone;
46252 -extern atomic_t fscache_n_store_vmscan_busy;
46253 -extern atomic_t fscache_n_store_vmscan_cancelled;
46254 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46255 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46256 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46257 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46258
46259 -extern atomic_t fscache_n_marks;
46260 -extern atomic_t fscache_n_uncaches;
46261 +extern atomic_unchecked_t fscache_n_marks;
46262 +extern atomic_unchecked_t fscache_n_uncaches;
46263
46264 -extern atomic_t fscache_n_acquires;
46265 -extern atomic_t fscache_n_acquires_null;
46266 -extern atomic_t fscache_n_acquires_no_cache;
46267 -extern atomic_t fscache_n_acquires_ok;
46268 -extern atomic_t fscache_n_acquires_nobufs;
46269 -extern atomic_t fscache_n_acquires_oom;
46270 +extern atomic_unchecked_t fscache_n_acquires;
46271 +extern atomic_unchecked_t fscache_n_acquires_null;
46272 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46273 +extern atomic_unchecked_t fscache_n_acquires_ok;
46274 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46275 +extern atomic_unchecked_t fscache_n_acquires_oom;
46276
46277 -extern atomic_t fscache_n_updates;
46278 -extern atomic_t fscache_n_updates_null;
46279 -extern atomic_t fscache_n_updates_run;
46280 +extern atomic_unchecked_t fscache_n_updates;
46281 +extern atomic_unchecked_t fscache_n_updates_null;
46282 +extern atomic_unchecked_t fscache_n_updates_run;
46283
46284 -extern atomic_t fscache_n_relinquishes;
46285 -extern atomic_t fscache_n_relinquishes_null;
46286 -extern atomic_t fscache_n_relinquishes_waitcrt;
46287 -extern atomic_t fscache_n_relinquishes_retire;
46288 +extern atomic_unchecked_t fscache_n_relinquishes;
46289 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46290 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46291 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46292
46293 -extern atomic_t fscache_n_cookie_index;
46294 -extern atomic_t fscache_n_cookie_data;
46295 -extern atomic_t fscache_n_cookie_special;
46296 +extern atomic_unchecked_t fscache_n_cookie_index;
46297 +extern atomic_unchecked_t fscache_n_cookie_data;
46298 +extern atomic_unchecked_t fscache_n_cookie_special;
46299
46300 -extern atomic_t fscache_n_object_alloc;
46301 -extern atomic_t fscache_n_object_no_alloc;
46302 -extern atomic_t fscache_n_object_lookups;
46303 -extern atomic_t fscache_n_object_lookups_negative;
46304 -extern atomic_t fscache_n_object_lookups_positive;
46305 -extern atomic_t fscache_n_object_lookups_timed_out;
46306 -extern atomic_t fscache_n_object_created;
46307 -extern atomic_t fscache_n_object_avail;
46308 -extern atomic_t fscache_n_object_dead;
46309 +extern atomic_unchecked_t fscache_n_object_alloc;
46310 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46311 +extern atomic_unchecked_t fscache_n_object_lookups;
46312 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46313 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46314 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46315 +extern atomic_unchecked_t fscache_n_object_created;
46316 +extern atomic_unchecked_t fscache_n_object_avail;
46317 +extern atomic_unchecked_t fscache_n_object_dead;
46318
46319 -extern atomic_t fscache_n_checkaux_none;
46320 -extern atomic_t fscache_n_checkaux_okay;
46321 -extern atomic_t fscache_n_checkaux_update;
46322 -extern atomic_t fscache_n_checkaux_obsolete;
46323 +extern atomic_unchecked_t fscache_n_checkaux_none;
46324 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46325 +extern atomic_unchecked_t fscache_n_checkaux_update;
46326 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46327
46328 extern atomic_t fscache_n_cop_alloc_object;
46329 extern atomic_t fscache_n_cop_lookup_object;
46330 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46331 atomic_inc(stat);
46332 }
46333
46334 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46335 +{
46336 + atomic_inc_unchecked(stat);
46337 +}
46338 +
46339 static inline void fscache_stat_d(atomic_t *stat)
46340 {
46341 atomic_dec(stat);
46342 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46343
46344 #define __fscache_stat(stat) (NULL)
46345 #define fscache_stat(stat) do {} while (0)
46346 +#define fscache_stat_unchecked(stat) do {} while (0)
46347 #define fscache_stat_d(stat) do {} while (0)
46348 #endif
46349
46350 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46351 index b6b897c..0ffff9c 100644
46352 --- a/fs/fscache/object.c
46353 +++ b/fs/fscache/object.c
46354 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46355 /* update the object metadata on disk */
46356 case FSCACHE_OBJECT_UPDATING:
46357 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46358 - fscache_stat(&fscache_n_updates_run);
46359 + fscache_stat_unchecked(&fscache_n_updates_run);
46360 fscache_stat(&fscache_n_cop_update_object);
46361 object->cache->ops->update_object(object);
46362 fscache_stat_d(&fscache_n_cop_update_object);
46363 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46364 spin_lock(&object->lock);
46365 object->state = FSCACHE_OBJECT_DEAD;
46366 spin_unlock(&object->lock);
46367 - fscache_stat(&fscache_n_object_dead);
46368 + fscache_stat_unchecked(&fscache_n_object_dead);
46369 goto terminal_transit;
46370
46371 /* handle the parent cache of this object being withdrawn from
46372 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46373 spin_lock(&object->lock);
46374 object->state = FSCACHE_OBJECT_DEAD;
46375 spin_unlock(&object->lock);
46376 - fscache_stat(&fscache_n_object_dead);
46377 + fscache_stat_unchecked(&fscache_n_object_dead);
46378 goto terminal_transit;
46379
46380 /* complain about the object being woken up once it is
46381 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46382 parent->cookie->def->name, cookie->def->name,
46383 object->cache->tag->name);
46384
46385 - fscache_stat(&fscache_n_object_lookups);
46386 + fscache_stat_unchecked(&fscache_n_object_lookups);
46387 fscache_stat(&fscache_n_cop_lookup_object);
46388 ret = object->cache->ops->lookup_object(object);
46389 fscache_stat_d(&fscache_n_cop_lookup_object);
46390 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46391 if (ret == -ETIMEDOUT) {
46392 /* probably stuck behind another object, so move this one to
46393 * the back of the queue */
46394 - fscache_stat(&fscache_n_object_lookups_timed_out);
46395 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46396 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46397 }
46398
46399 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46400
46401 spin_lock(&object->lock);
46402 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46403 - fscache_stat(&fscache_n_object_lookups_negative);
46404 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46405
46406 /* transit here to allow write requests to begin stacking up
46407 * and read requests to begin returning ENODATA */
46408 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46409 * result, in which case there may be data available */
46410 spin_lock(&object->lock);
46411 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46412 - fscache_stat(&fscache_n_object_lookups_positive);
46413 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46414
46415 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46416
46417 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46418 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46419 } else {
46420 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46421 - fscache_stat(&fscache_n_object_created);
46422 + fscache_stat_unchecked(&fscache_n_object_created);
46423
46424 object->state = FSCACHE_OBJECT_AVAILABLE;
46425 spin_unlock(&object->lock);
46426 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46427 fscache_enqueue_dependents(object);
46428
46429 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46430 - fscache_stat(&fscache_n_object_avail);
46431 + fscache_stat_unchecked(&fscache_n_object_avail);
46432
46433 _leave("");
46434 }
46435 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46436 enum fscache_checkaux result;
46437
46438 if (!object->cookie->def->check_aux) {
46439 - fscache_stat(&fscache_n_checkaux_none);
46440 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46441 return FSCACHE_CHECKAUX_OKAY;
46442 }
46443
46444 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46445 switch (result) {
46446 /* entry okay as is */
46447 case FSCACHE_CHECKAUX_OKAY:
46448 - fscache_stat(&fscache_n_checkaux_okay);
46449 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46450 break;
46451
46452 /* entry requires update */
46453 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46454 - fscache_stat(&fscache_n_checkaux_update);
46455 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46456 break;
46457
46458 /* entry requires deletion */
46459 case FSCACHE_CHECKAUX_OBSOLETE:
46460 - fscache_stat(&fscache_n_checkaux_obsolete);
46461 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46462 break;
46463
46464 default:
46465 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46466 index 30afdfa..2256596 100644
46467 --- a/fs/fscache/operation.c
46468 +++ b/fs/fscache/operation.c
46469 @@ -17,7 +17,7 @@
46470 #include <linux/slab.h>
46471 #include "internal.h"
46472
46473 -atomic_t fscache_op_debug_id;
46474 +atomic_unchecked_t fscache_op_debug_id;
46475 EXPORT_SYMBOL(fscache_op_debug_id);
46476
46477 /**
46478 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46479 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46480 ASSERTCMP(atomic_read(&op->usage), >, 0);
46481
46482 - fscache_stat(&fscache_n_op_enqueue);
46483 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46484 switch (op->flags & FSCACHE_OP_TYPE) {
46485 case FSCACHE_OP_ASYNC:
46486 _debug("queue async");
46487 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46488 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46489 if (op->processor)
46490 fscache_enqueue_operation(op);
46491 - fscache_stat(&fscache_n_op_run);
46492 + fscache_stat_unchecked(&fscache_n_op_run);
46493 }
46494
46495 /*
46496 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46497 if (object->n_ops > 1) {
46498 atomic_inc(&op->usage);
46499 list_add_tail(&op->pend_link, &object->pending_ops);
46500 - fscache_stat(&fscache_n_op_pend);
46501 + fscache_stat_unchecked(&fscache_n_op_pend);
46502 } else if (!list_empty(&object->pending_ops)) {
46503 atomic_inc(&op->usage);
46504 list_add_tail(&op->pend_link, &object->pending_ops);
46505 - fscache_stat(&fscache_n_op_pend);
46506 + fscache_stat_unchecked(&fscache_n_op_pend);
46507 fscache_start_operations(object);
46508 } else {
46509 ASSERTCMP(object->n_in_progress, ==, 0);
46510 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46511 object->n_exclusive++; /* reads and writes must wait */
46512 atomic_inc(&op->usage);
46513 list_add_tail(&op->pend_link, &object->pending_ops);
46514 - fscache_stat(&fscache_n_op_pend);
46515 + fscache_stat_unchecked(&fscache_n_op_pend);
46516 ret = 0;
46517 } else {
46518 /* not allowed to submit ops in any other state */
46519 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46520 if (object->n_exclusive > 0) {
46521 atomic_inc(&op->usage);
46522 list_add_tail(&op->pend_link, &object->pending_ops);
46523 - fscache_stat(&fscache_n_op_pend);
46524 + fscache_stat_unchecked(&fscache_n_op_pend);
46525 } else if (!list_empty(&object->pending_ops)) {
46526 atomic_inc(&op->usage);
46527 list_add_tail(&op->pend_link, &object->pending_ops);
46528 - fscache_stat(&fscache_n_op_pend);
46529 + fscache_stat_unchecked(&fscache_n_op_pend);
46530 fscache_start_operations(object);
46531 } else {
46532 ASSERTCMP(object->n_exclusive, ==, 0);
46533 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46534 object->n_ops++;
46535 atomic_inc(&op->usage);
46536 list_add_tail(&op->pend_link, &object->pending_ops);
46537 - fscache_stat(&fscache_n_op_pend);
46538 + fscache_stat_unchecked(&fscache_n_op_pend);
46539 ret = 0;
46540 } else if (object->state == FSCACHE_OBJECT_DYING ||
46541 object->state == FSCACHE_OBJECT_LC_DYING ||
46542 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46543 - fscache_stat(&fscache_n_op_rejected);
46544 + fscache_stat_unchecked(&fscache_n_op_rejected);
46545 ret = -ENOBUFS;
46546 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46547 fscache_report_unexpected_submission(object, op, ostate);
46548 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46549
46550 ret = -EBUSY;
46551 if (!list_empty(&op->pend_link)) {
46552 - fscache_stat(&fscache_n_op_cancelled);
46553 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46554 list_del_init(&op->pend_link);
46555 object->n_ops--;
46556 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46557 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46558 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46559 BUG();
46560
46561 - fscache_stat(&fscache_n_op_release);
46562 + fscache_stat_unchecked(&fscache_n_op_release);
46563
46564 if (op->release) {
46565 op->release(op);
46566 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46567 * lock, and defer it otherwise */
46568 if (!spin_trylock(&object->lock)) {
46569 _debug("defer put");
46570 - fscache_stat(&fscache_n_op_deferred_release);
46571 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46572
46573 cache = object->cache;
46574 spin_lock(&cache->op_gc_list_lock);
46575 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46576
46577 _debug("GC DEFERRED REL OBJ%x OP%x",
46578 object->debug_id, op->debug_id);
46579 - fscache_stat(&fscache_n_op_gc);
46580 + fscache_stat_unchecked(&fscache_n_op_gc);
46581
46582 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46583
46584 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46585 index 3f7a59b..cf196cc 100644
46586 --- a/fs/fscache/page.c
46587 +++ b/fs/fscache/page.c
46588 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46589 val = radix_tree_lookup(&cookie->stores, page->index);
46590 if (!val) {
46591 rcu_read_unlock();
46592 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46593 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46594 __fscache_uncache_page(cookie, page);
46595 return true;
46596 }
46597 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46598 spin_unlock(&cookie->stores_lock);
46599
46600 if (xpage) {
46601 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46602 - fscache_stat(&fscache_n_store_radix_deletes);
46603 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46604 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46605 ASSERTCMP(xpage, ==, page);
46606 } else {
46607 - fscache_stat(&fscache_n_store_vmscan_gone);
46608 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46609 }
46610
46611 wake_up_bit(&cookie->flags, 0);
46612 @@ -107,7 +107,7 @@ page_busy:
46613 /* we might want to wait here, but that could deadlock the allocator as
46614 * the work threads writing to the cache may all end up sleeping
46615 * on memory allocation */
46616 - fscache_stat(&fscache_n_store_vmscan_busy);
46617 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46618 return false;
46619 }
46620 EXPORT_SYMBOL(__fscache_maybe_release_page);
46621 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46622 FSCACHE_COOKIE_STORING_TAG);
46623 if (!radix_tree_tag_get(&cookie->stores, page->index,
46624 FSCACHE_COOKIE_PENDING_TAG)) {
46625 - fscache_stat(&fscache_n_store_radix_deletes);
46626 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46627 xpage = radix_tree_delete(&cookie->stores, page->index);
46628 }
46629 spin_unlock(&cookie->stores_lock);
46630 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46631
46632 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46633
46634 - fscache_stat(&fscache_n_attr_changed_calls);
46635 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46636
46637 if (fscache_object_is_active(object)) {
46638 fscache_stat(&fscache_n_cop_attr_changed);
46639 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46640
46641 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46642
46643 - fscache_stat(&fscache_n_attr_changed);
46644 + fscache_stat_unchecked(&fscache_n_attr_changed);
46645
46646 op = kzalloc(sizeof(*op), GFP_KERNEL);
46647 if (!op) {
46648 - fscache_stat(&fscache_n_attr_changed_nomem);
46649 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46650 _leave(" = -ENOMEM");
46651 return -ENOMEM;
46652 }
46653 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46654 if (fscache_submit_exclusive_op(object, op) < 0)
46655 goto nobufs;
46656 spin_unlock(&cookie->lock);
46657 - fscache_stat(&fscache_n_attr_changed_ok);
46658 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46659 fscache_put_operation(op);
46660 _leave(" = 0");
46661 return 0;
46662 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46663 nobufs:
46664 spin_unlock(&cookie->lock);
46665 kfree(op);
46666 - fscache_stat(&fscache_n_attr_changed_nobufs);
46667 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46668 _leave(" = %d", -ENOBUFS);
46669 return -ENOBUFS;
46670 }
46671 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46672 /* allocate a retrieval operation and attempt to submit it */
46673 op = kzalloc(sizeof(*op), GFP_NOIO);
46674 if (!op) {
46675 - fscache_stat(&fscache_n_retrievals_nomem);
46676 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46677 return NULL;
46678 }
46679
46680 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46681 return 0;
46682 }
46683
46684 - fscache_stat(&fscache_n_retrievals_wait);
46685 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46686
46687 jif = jiffies;
46688 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46689 fscache_wait_bit_interruptible,
46690 TASK_INTERRUPTIBLE) != 0) {
46691 - fscache_stat(&fscache_n_retrievals_intr);
46692 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46693 _leave(" = -ERESTARTSYS");
46694 return -ERESTARTSYS;
46695 }
46696 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46697 */
46698 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46699 struct fscache_retrieval *op,
46700 - atomic_t *stat_op_waits,
46701 - atomic_t *stat_object_dead)
46702 + atomic_unchecked_t *stat_op_waits,
46703 + atomic_unchecked_t *stat_object_dead)
46704 {
46705 int ret;
46706
46707 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46708 goto check_if_dead;
46709
46710 _debug(">>> WT");
46711 - fscache_stat(stat_op_waits);
46712 + fscache_stat_unchecked(stat_op_waits);
46713 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46714 fscache_wait_bit_interruptible,
46715 TASK_INTERRUPTIBLE) < 0) {
46716 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46717
46718 check_if_dead:
46719 if (unlikely(fscache_object_is_dead(object))) {
46720 - fscache_stat(stat_object_dead);
46721 + fscache_stat_unchecked(stat_object_dead);
46722 return -ENOBUFS;
46723 }
46724 return 0;
46725 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46726
46727 _enter("%p,%p,,,", cookie, page);
46728
46729 - fscache_stat(&fscache_n_retrievals);
46730 + fscache_stat_unchecked(&fscache_n_retrievals);
46731
46732 if (hlist_empty(&cookie->backing_objects))
46733 goto nobufs;
46734 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46735 goto nobufs_unlock;
46736 spin_unlock(&cookie->lock);
46737
46738 - fscache_stat(&fscache_n_retrieval_ops);
46739 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46740
46741 /* pin the netfs read context in case we need to do the actual netfs
46742 * read because we've encountered a cache read failure */
46743 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46744
46745 error:
46746 if (ret == -ENOMEM)
46747 - fscache_stat(&fscache_n_retrievals_nomem);
46748 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46749 else if (ret == -ERESTARTSYS)
46750 - fscache_stat(&fscache_n_retrievals_intr);
46751 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46752 else if (ret == -ENODATA)
46753 - fscache_stat(&fscache_n_retrievals_nodata);
46754 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46755 else if (ret < 0)
46756 - fscache_stat(&fscache_n_retrievals_nobufs);
46757 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46758 else
46759 - fscache_stat(&fscache_n_retrievals_ok);
46760 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46761
46762 fscache_put_retrieval(op);
46763 _leave(" = %d", ret);
46764 @@ -429,7 +429,7 @@ nobufs_unlock:
46765 spin_unlock(&cookie->lock);
46766 kfree(op);
46767 nobufs:
46768 - fscache_stat(&fscache_n_retrievals_nobufs);
46769 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46770 _leave(" = -ENOBUFS");
46771 return -ENOBUFS;
46772 }
46773 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46774
46775 _enter("%p,,%d,,,", cookie, *nr_pages);
46776
46777 - fscache_stat(&fscache_n_retrievals);
46778 + fscache_stat_unchecked(&fscache_n_retrievals);
46779
46780 if (hlist_empty(&cookie->backing_objects))
46781 goto nobufs;
46782 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46783 goto nobufs_unlock;
46784 spin_unlock(&cookie->lock);
46785
46786 - fscache_stat(&fscache_n_retrieval_ops);
46787 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46788
46789 /* pin the netfs read context in case we need to do the actual netfs
46790 * read because we've encountered a cache read failure */
46791 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46792
46793 error:
46794 if (ret == -ENOMEM)
46795 - fscache_stat(&fscache_n_retrievals_nomem);
46796 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46797 else if (ret == -ERESTARTSYS)
46798 - fscache_stat(&fscache_n_retrievals_intr);
46799 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46800 else if (ret == -ENODATA)
46801 - fscache_stat(&fscache_n_retrievals_nodata);
46802 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46803 else if (ret < 0)
46804 - fscache_stat(&fscache_n_retrievals_nobufs);
46805 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46806 else
46807 - fscache_stat(&fscache_n_retrievals_ok);
46808 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46809
46810 fscache_put_retrieval(op);
46811 _leave(" = %d", ret);
46812 @@ -545,7 +545,7 @@ nobufs_unlock:
46813 spin_unlock(&cookie->lock);
46814 kfree(op);
46815 nobufs:
46816 - fscache_stat(&fscache_n_retrievals_nobufs);
46817 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46818 _leave(" = -ENOBUFS");
46819 return -ENOBUFS;
46820 }
46821 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46822
46823 _enter("%p,%p,,,", cookie, page);
46824
46825 - fscache_stat(&fscache_n_allocs);
46826 + fscache_stat_unchecked(&fscache_n_allocs);
46827
46828 if (hlist_empty(&cookie->backing_objects))
46829 goto nobufs;
46830 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46831 goto nobufs_unlock;
46832 spin_unlock(&cookie->lock);
46833
46834 - fscache_stat(&fscache_n_alloc_ops);
46835 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46836
46837 ret = fscache_wait_for_retrieval_activation(
46838 object, op,
46839 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46840
46841 error:
46842 if (ret == -ERESTARTSYS)
46843 - fscache_stat(&fscache_n_allocs_intr);
46844 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46845 else if (ret < 0)
46846 - fscache_stat(&fscache_n_allocs_nobufs);
46847 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46848 else
46849 - fscache_stat(&fscache_n_allocs_ok);
46850 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46851
46852 fscache_put_retrieval(op);
46853 _leave(" = %d", ret);
46854 @@ -625,7 +625,7 @@ nobufs_unlock:
46855 spin_unlock(&cookie->lock);
46856 kfree(op);
46857 nobufs:
46858 - fscache_stat(&fscache_n_allocs_nobufs);
46859 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46860 _leave(" = -ENOBUFS");
46861 return -ENOBUFS;
46862 }
46863 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46864
46865 spin_lock(&cookie->stores_lock);
46866
46867 - fscache_stat(&fscache_n_store_calls);
46868 + fscache_stat_unchecked(&fscache_n_store_calls);
46869
46870 /* find a page to store */
46871 page = NULL;
46872 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46873 page = results[0];
46874 _debug("gang %d [%lx]", n, page->index);
46875 if (page->index > op->store_limit) {
46876 - fscache_stat(&fscache_n_store_pages_over_limit);
46877 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46878 goto superseded;
46879 }
46880
46881 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46882 spin_unlock(&cookie->stores_lock);
46883 spin_unlock(&object->lock);
46884
46885 - fscache_stat(&fscache_n_store_pages);
46886 + fscache_stat_unchecked(&fscache_n_store_pages);
46887 fscache_stat(&fscache_n_cop_write_page);
46888 ret = object->cache->ops->write_page(op, page);
46889 fscache_stat_d(&fscache_n_cop_write_page);
46890 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46891 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46892 ASSERT(PageFsCache(page));
46893
46894 - fscache_stat(&fscache_n_stores);
46895 + fscache_stat_unchecked(&fscache_n_stores);
46896
46897 op = kzalloc(sizeof(*op), GFP_NOIO);
46898 if (!op)
46899 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46900 spin_unlock(&cookie->stores_lock);
46901 spin_unlock(&object->lock);
46902
46903 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46904 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46905 op->store_limit = object->store_limit;
46906
46907 if (fscache_submit_op(object, &op->op) < 0)
46908 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46909
46910 spin_unlock(&cookie->lock);
46911 radix_tree_preload_end();
46912 - fscache_stat(&fscache_n_store_ops);
46913 - fscache_stat(&fscache_n_stores_ok);
46914 + fscache_stat_unchecked(&fscache_n_store_ops);
46915 + fscache_stat_unchecked(&fscache_n_stores_ok);
46916
46917 /* the work queue now carries its own ref on the object */
46918 fscache_put_operation(&op->op);
46919 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46920 return 0;
46921
46922 already_queued:
46923 - fscache_stat(&fscache_n_stores_again);
46924 + fscache_stat_unchecked(&fscache_n_stores_again);
46925 already_pending:
46926 spin_unlock(&cookie->stores_lock);
46927 spin_unlock(&object->lock);
46928 spin_unlock(&cookie->lock);
46929 radix_tree_preload_end();
46930 kfree(op);
46931 - fscache_stat(&fscache_n_stores_ok);
46932 + fscache_stat_unchecked(&fscache_n_stores_ok);
46933 _leave(" = 0");
46934 return 0;
46935
46936 @@ -851,14 +851,14 @@ nobufs:
46937 spin_unlock(&cookie->lock);
46938 radix_tree_preload_end();
46939 kfree(op);
46940 - fscache_stat(&fscache_n_stores_nobufs);
46941 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46942 _leave(" = -ENOBUFS");
46943 return -ENOBUFS;
46944
46945 nomem_free:
46946 kfree(op);
46947 nomem:
46948 - fscache_stat(&fscache_n_stores_oom);
46949 + fscache_stat_unchecked(&fscache_n_stores_oom);
46950 _leave(" = -ENOMEM");
46951 return -ENOMEM;
46952 }
46953 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46954 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46955 ASSERTCMP(page, !=, NULL);
46956
46957 - fscache_stat(&fscache_n_uncaches);
46958 + fscache_stat_unchecked(&fscache_n_uncaches);
46959
46960 /* cache withdrawal may beat us to it */
46961 if (!PageFsCache(page))
46962 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46963 unsigned long loop;
46964
46965 #ifdef CONFIG_FSCACHE_STATS
46966 - atomic_add(pagevec->nr, &fscache_n_marks);
46967 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46968 #endif
46969
46970 for (loop = 0; loop < pagevec->nr; loop++) {
46971 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46972 index 4765190..2a067f2 100644
46973 --- a/fs/fscache/stats.c
46974 +++ b/fs/fscache/stats.c
46975 @@ -18,95 +18,95 @@
46976 /*
46977 * operation counters
46978 */
46979 -atomic_t fscache_n_op_pend;
46980 -atomic_t fscache_n_op_run;
46981 -atomic_t fscache_n_op_enqueue;
46982 -atomic_t fscache_n_op_requeue;
46983 -atomic_t fscache_n_op_deferred_release;
46984 -atomic_t fscache_n_op_release;
46985 -atomic_t fscache_n_op_gc;
46986 -atomic_t fscache_n_op_cancelled;
46987 -atomic_t fscache_n_op_rejected;
46988 +atomic_unchecked_t fscache_n_op_pend;
46989 +atomic_unchecked_t fscache_n_op_run;
46990 +atomic_unchecked_t fscache_n_op_enqueue;
46991 +atomic_unchecked_t fscache_n_op_requeue;
46992 +atomic_unchecked_t fscache_n_op_deferred_release;
46993 +atomic_unchecked_t fscache_n_op_release;
46994 +atomic_unchecked_t fscache_n_op_gc;
46995 +atomic_unchecked_t fscache_n_op_cancelled;
46996 +atomic_unchecked_t fscache_n_op_rejected;
46997
46998 -atomic_t fscache_n_attr_changed;
46999 -atomic_t fscache_n_attr_changed_ok;
47000 -atomic_t fscache_n_attr_changed_nobufs;
47001 -atomic_t fscache_n_attr_changed_nomem;
47002 -atomic_t fscache_n_attr_changed_calls;
47003 +atomic_unchecked_t fscache_n_attr_changed;
47004 +atomic_unchecked_t fscache_n_attr_changed_ok;
47005 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47006 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47007 +atomic_unchecked_t fscache_n_attr_changed_calls;
47008
47009 -atomic_t fscache_n_allocs;
47010 -atomic_t fscache_n_allocs_ok;
47011 -atomic_t fscache_n_allocs_wait;
47012 -atomic_t fscache_n_allocs_nobufs;
47013 -atomic_t fscache_n_allocs_intr;
47014 -atomic_t fscache_n_allocs_object_dead;
47015 -atomic_t fscache_n_alloc_ops;
47016 -atomic_t fscache_n_alloc_op_waits;
47017 +atomic_unchecked_t fscache_n_allocs;
47018 +atomic_unchecked_t fscache_n_allocs_ok;
47019 +atomic_unchecked_t fscache_n_allocs_wait;
47020 +atomic_unchecked_t fscache_n_allocs_nobufs;
47021 +atomic_unchecked_t fscache_n_allocs_intr;
47022 +atomic_unchecked_t fscache_n_allocs_object_dead;
47023 +atomic_unchecked_t fscache_n_alloc_ops;
47024 +atomic_unchecked_t fscache_n_alloc_op_waits;
47025
47026 -atomic_t fscache_n_retrievals;
47027 -atomic_t fscache_n_retrievals_ok;
47028 -atomic_t fscache_n_retrievals_wait;
47029 -atomic_t fscache_n_retrievals_nodata;
47030 -atomic_t fscache_n_retrievals_nobufs;
47031 -atomic_t fscache_n_retrievals_intr;
47032 -atomic_t fscache_n_retrievals_nomem;
47033 -atomic_t fscache_n_retrievals_object_dead;
47034 -atomic_t fscache_n_retrieval_ops;
47035 -atomic_t fscache_n_retrieval_op_waits;
47036 +atomic_unchecked_t fscache_n_retrievals;
47037 +atomic_unchecked_t fscache_n_retrievals_ok;
47038 +atomic_unchecked_t fscache_n_retrievals_wait;
47039 +atomic_unchecked_t fscache_n_retrievals_nodata;
47040 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47041 +atomic_unchecked_t fscache_n_retrievals_intr;
47042 +atomic_unchecked_t fscache_n_retrievals_nomem;
47043 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47044 +atomic_unchecked_t fscache_n_retrieval_ops;
47045 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47046
47047 -atomic_t fscache_n_stores;
47048 -atomic_t fscache_n_stores_ok;
47049 -atomic_t fscache_n_stores_again;
47050 -atomic_t fscache_n_stores_nobufs;
47051 -atomic_t fscache_n_stores_oom;
47052 -atomic_t fscache_n_store_ops;
47053 -atomic_t fscache_n_store_calls;
47054 -atomic_t fscache_n_store_pages;
47055 -atomic_t fscache_n_store_radix_deletes;
47056 -atomic_t fscache_n_store_pages_over_limit;
47057 +atomic_unchecked_t fscache_n_stores;
47058 +atomic_unchecked_t fscache_n_stores_ok;
47059 +atomic_unchecked_t fscache_n_stores_again;
47060 +atomic_unchecked_t fscache_n_stores_nobufs;
47061 +atomic_unchecked_t fscache_n_stores_oom;
47062 +atomic_unchecked_t fscache_n_store_ops;
47063 +atomic_unchecked_t fscache_n_store_calls;
47064 +atomic_unchecked_t fscache_n_store_pages;
47065 +atomic_unchecked_t fscache_n_store_radix_deletes;
47066 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47067
47068 -atomic_t fscache_n_store_vmscan_not_storing;
47069 -atomic_t fscache_n_store_vmscan_gone;
47070 -atomic_t fscache_n_store_vmscan_busy;
47071 -atomic_t fscache_n_store_vmscan_cancelled;
47072 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47073 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47074 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47075 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47076
47077 -atomic_t fscache_n_marks;
47078 -atomic_t fscache_n_uncaches;
47079 +atomic_unchecked_t fscache_n_marks;
47080 +atomic_unchecked_t fscache_n_uncaches;
47081
47082 -atomic_t fscache_n_acquires;
47083 -atomic_t fscache_n_acquires_null;
47084 -atomic_t fscache_n_acquires_no_cache;
47085 -atomic_t fscache_n_acquires_ok;
47086 -atomic_t fscache_n_acquires_nobufs;
47087 -atomic_t fscache_n_acquires_oom;
47088 +atomic_unchecked_t fscache_n_acquires;
47089 +atomic_unchecked_t fscache_n_acquires_null;
47090 +atomic_unchecked_t fscache_n_acquires_no_cache;
47091 +atomic_unchecked_t fscache_n_acquires_ok;
47092 +atomic_unchecked_t fscache_n_acquires_nobufs;
47093 +atomic_unchecked_t fscache_n_acquires_oom;
47094
47095 -atomic_t fscache_n_updates;
47096 -atomic_t fscache_n_updates_null;
47097 -atomic_t fscache_n_updates_run;
47098 +atomic_unchecked_t fscache_n_updates;
47099 +atomic_unchecked_t fscache_n_updates_null;
47100 +atomic_unchecked_t fscache_n_updates_run;
47101
47102 -atomic_t fscache_n_relinquishes;
47103 -atomic_t fscache_n_relinquishes_null;
47104 -atomic_t fscache_n_relinquishes_waitcrt;
47105 -atomic_t fscache_n_relinquishes_retire;
47106 +atomic_unchecked_t fscache_n_relinquishes;
47107 +atomic_unchecked_t fscache_n_relinquishes_null;
47108 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47109 +atomic_unchecked_t fscache_n_relinquishes_retire;
47110
47111 -atomic_t fscache_n_cookie_index;
47112 -atomic_t fscache_n_cookie_data;
47113 -atomic_t fscache_n_cookie_special;
47114 +atomic_unchecked_t fscache_n_cookie_index;
47115 +atomic_unchecked_t fscache_n_cookie_data;
47116 +atomic_unchecked_t fscache_n_cookie_special;
47117
47118 -atomic_t fscache_n_object_alloc;
47119 -atomic_t fscache_n_object_no_alloc;
47120 -atomic_t fscache_n_object_lookups;
47121 -atomic_t fscache_n_object_lookups_negative;
47122 -atomic_t fscache_n_object_lookups_positive;
47123 -atomic_t fscache_n_object_lookups_timed_out;
47124 -atomic_t fscache_n_object_created;
47125 -atomic_t fscache_n_object_avail;
47126 -atomic_t fscache_n_object_dead;
47127 +atomic_unchecked_t fscache_n_object_alloc;
47128 +atomic_unchecked_t fscache_n_object_no_alloc;
47129 +atomic_unchecked_t fscache_n_object_lookups;
47130 +atomic_unchecked_t fscache_n_object_lookups_negative;
47131 +atomic_unchecked_t fscache_n_object_lookups_positive;
47132 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47133 +atomic_unchecked_t fscache_n_object_created;
47134 +atomic_unchecked_t fscache_n_object_avail;
47135 +atomic_unchecked_t fscache_n_object_dead;
47136
47137 -atomic_t fscache_n_checkaux_none;
47138 -atomic_t fscache_n_checkaux_okay;
47139 -atomic_t fscache_n_checkaux_update;
47140 -atomic_t fscache_n_checkaux_obsolete;
47141 +atomic_unchecked_t fscache_n_checkaux_none;
47142 +atomic_unchecked_t fscache_n_checkaux_okay;
47143 +atomic_unchecked_t fscache_n_checkaux_update;
47144 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47145
47146 atomic_t fscache_n_cop_alloc_object;
47147 atomic_t fscache_n_cop_lookup_object;
47148 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47149 seq_puts(m, "FS-Cache statistics\n");
47150
47151 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47152 - atomic_read(&fscache_n_cookie_index),
47153 - atomic_read(&fscache_n_cookie_data),
47154 - atomic_read(&fscache_n_cookie_special));
47155 + atomic_read_unchecked(&fscache_n_cookie_index),
47156 + atomic_read_unchecked(&fscache_n_cookie_data),
47157 + atomic_read_unchecked(&fscache_n_cookie_special));
47158
47159 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47160 - atomic_read(&fscache_n_object_alloc),
47161 - atomic_read(&fscache_n_object_no_alloc),
47162 - atomic_read(&fscache_n_object_avail),
47163 - atomic_read(&fscache_n_object_dead));
47164 + atomic_read_unchecked(&fscache_n_object_alloc),
47165 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47166 + atomic_read_unchecked(&fscache_n_object_avail),
47167 + atomic_read_unchecked(&fscache_n_object_dead));
47168 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47169 - atomic_read(&fscache_n_checkaux_none),
47170 - atomic_read(&fscache_n_checkaux_okay),
47171 - atomic_read(&fscache_n_checkaux_update),
47172 - atomic_read(&fscache_n_checkaux_obsolete));
47173 + atomic_read_unchecked(&fscache_n_checkaux_none),
47174 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47175 + atomic_read_unchecked(&fscache_n_checkaux_update),
47176 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47177
47178 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47179 - atomic_read(&fscache_n_marks),
47180 - atomic_read(&fscache_n_uncaches));
47181 + atomic_read_unchecked(&fscache_n_marks),
47182 + atomic_read_unchecked(&fscache_n_uncaches));
47183
47184 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47185 " oom=%u\n",
47186 - atomic_read(&fscache_n_acquires),
47187 - atomic_read(&fscache_n_acquires_null),
47188 - atomic_read(&fscache_n_acquires_no_cache),
47189 - atomic_read(&fscache_n_acquires_ok),
47190 - atomic_read(&fscache_n_acquires_nobufs),
47191 - atomic_read(&fscache_n_acquires_oom));
47192 + atomic_read_unchecked(&fscache_n_acquires),
47193 + atomic_read_unchecked(&fscache_n_acquires_null),
47194 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47195 + atomic_read_unchecked(&fscache_n_acquires_ok),
47196 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47197 + atomic_read_unchecked(&fscache_n_acquires_oom));
47198
47199 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47200 - atomic_read(&fscache_n_object_lookups),
47201 - atomic_read(&fscache_n_object_lookups_negative),
47202 - atomic_read(&fscache_n_object_lookups_positive),
47203 - atomic_read(&fscache_n_object_created),
47204 - atomic_read(&fscache_n_object_lookups_timed_out));
47205 + atomic_read_unchecked(&fscache_n_object_lookups),
47206 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47207 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47208 + atomic_read_unchecked(&fscache_n_object_created),
47209 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47210
47211 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47212 - atomic_read(&fscache_n_updates),
47213 - atomic_read(&fscache_n_updates_null),
47214 - atomic_read(&fscache_n_updates_run));
47215 + atomic_read_unchecked(&fscache_n_updates),
47216 + atomic_read_unchecked(&fscache_n_updates_null),
47217 + atomic_read_unchecked(&fscache_n_updates_run));
47218
47219 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47220 - atomic_read(&fscache_n_relinquishes),
47221 - atomic_read(&fscache_n_relinquishes_null),
47222 - atomic_read(&fscache_n_relinquishes_waitcrt),
47223 - atomic_read(&fscache_n_relinquishes_retire));
47224 + atomic_read_unchecked(&fscache_n_relinquishes),
47225 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47226 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47227 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47228
47229 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47230 - atomic_read(&fscache_n_attr_changed),
47231 - atomic_read(&fscache_n_attr_changed_ok),
47232 - atomic_read(&fscache_n_attr_changed_nobufs),
47233 - atomic_read(&fscache_n_attr_changed_nomem),
47234 - atomic_read(&fscache_n_attr_changed_calls));
47235 + atomic_read_unchecked(&fscache_n_attr_changed),
47236 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47237 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47238 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47239 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47240
47241 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47242 - atomic_read(&fscache_n_allocs),
47243 - atomic_read(&fscache_n_allocs_ok),
47244 - atomic_read(&fscache_n_allocs_wait),
47245 - atomic_read(&fscache_n_allocs_nobufs),
47246 - atomic_read(&fscache_n_allocs_intr));
47247 + atomic_read_unchecked(&fscache_n_allocs),
47248 + atomic_read_unchecked(&fscache_n_allocs_ok),
47249 + atomic_read_unchecked(&fscache_n_allocs_wait),
47250 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47251 + atomic_read_unchecked(&fscache_n_allocs_intr));
47252 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47253 - atomic_read(&fscache_n_alloc_ops),
47254 - atomic_read(&fscache_n_alloc_op_waits),
47255 - atomic_read(&fscache_n_allocs_object_dead));
47256 + atomic_read_unchecked(&fscache_n_alloc_ops),
47257 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47258 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47259
47260 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47261 " int=%u oom=%u\n",
47262 - atomic_read(&fscache_n_retrievals),
47263 - atomic_read(&fscache_n_retrievals_ok),
47264 - atomic_read(&fscache_n_retrievals_wait),
47265 - atomic_read(&fscache_n_retrievals_nodata),
47266 - atomic_read(&fscache_n_retrievals_nobufs),
47267 - atomic_read(&fscache_n_retrievals_intr),
47268 - atomic_read(&fscache_n_retrievals_nomem));
47269 + atomic_read_unchecked(&fscache_n_retrievals),
47270 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47271 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47272 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47273 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47274 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47275 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47276 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47277 - atomic_read(&fscache_n_retrieval_ops),
47278 - atomic_read(&fscache_n_retrieval_op_waits),
47279 - atomic_read(&fscache_n_retrievals_object_dead));
47280 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47281 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47282 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47283
47284 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47285 - atomic_read(&fscache_n_stores),
47286 - atomic_read(&fscache_n_stores_ok),
47287 - atomic_read(&fscache_n_stores_again),
47288 - atomic_read(&fscache_n_stores_nobufs),
47289 - atomic_read(&fscache_n_stores_oom));
47290 + atomic_read_unchecked(&fscache_n_stores),
47291 + atomic_read_unchecked(&fscache_n_stores_ok),
47292 + atomic_read_unchecked(&fscache_n_stores_again),
47293 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47294 + atomic_read_unchecked(&fscache_n_stores_oom));
47295 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47296 - atomic_read(&fscache_n_store_ops),
47297 - atomic_read(&fscache_n_store_calls),
47298 - atomic_read(&fscache_n_store_pages),
47299 - atomic_read(&fscache_n_store_radix_deletes),
47300 - atomic_read(&fscache_n_store_pages_over_limit));
47301 + atomic_read_unchecked(&fscache_n_store_ops),
47302 + atomic_read_unchecked(&fscache_n_store_calls),
47303 + atomic_read_unchecked(&fscache_n_store_pages),
47304 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47305 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47306
47307 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47308 - atomic_read(&fscache_n_store_vmscan_not_storing),
47309 - atomic_read(&fscache_n_store_vmscan_gone),
47310 - atomic_read(&fscache_n_store_vmscan_busy),
47311 - atomic_read(&fscache_n_store_vmscan_cancelled));
47312 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47313 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47314 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47315 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47316
47317 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47318 - atomic_read(&fscache_n_op_pend),
47319 - atomic_read(&fscache_n_op_run),
47320 - atomic_read(&fscache_n_op_enqueue),
47321 - atomic_read(&fscache_n_op_cancelled),
47322 - atomic_read(&fscache_n_op_rejected));
47323 + atomic_read_unchecked(&fscache_n_op_pend),
47324 + atomic_read_unchecked(&fscache_n_op_run),
47325 + atomic_read_unchecked(&fscache_n_op_enqueue),
47326 + atomic_read_unchecked(&fscache_n_op_cancelled),
47327 + atomic_read_unchecked(&fscache_n_op_rejected));
47328 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47329 - atomic_read(&fscache_n_op_deferred_release),
47330 - atomic_read(&fscache_n_op_release),
47331 - atomic_read(&fscache_n_op_gc));
47332 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47333 + atomic_read_unchecked(&fscache_n_op_release),
47334 + atomic_read_unchecked(&fscache_n_op_gc));
47335
47336 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47337 atomic_read(&fscache_n_cop_alloc_object),
47338 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47339 index ee8d550..7189d8c 100644
47340 --- a/fs/fuse/cuse.c
47341 +++ b/fs/fuse/cuse.c
47342 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47343 INIT_LIST_HEAD(&cuse_conntbl[i]);
47344
47345 /* inherit and extend fuse_dev_operations */
47346 - cuse_channel_fops = fuse_dev_operations;
47347 - cuse_channel_fops.owner = THIS_MODULE;
47348 - cuse_channel_fops.open = cuse_channel_open;
47349 - cuse_channel_fops.release = cuse_channel_release;
47350 + pax_open_kernel();
47351 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47352 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47353 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47354 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47355 + pax_close_kernel();
47356
47357 cuse_class = class_create(THIS_MODULE, "cuse");
47358 if (IS_ERR(cuse_class))
47359 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47360 index f4246cf..b4aed1d 100644
47361 --- a/fs/fuse/dev.c
47362 +++ b/fs/fuse/dev.c
47363 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47364 ret = 0;
47365 pipe_lock(pipe);
47366
47367 - if (!pipe->readers) {
47368 + if (!atomic_read(&pipe->readers)) {
47369 send_sig(SIGPIPE, current, 0);
47370 if (!ret)
47371 ret = -EPIPE;
47372 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47373 index 324bc08..4fdd56e 100644
47374 --- a/fs/fuse/dir.c
47375 +++ b/fs/fuse/dir.c
47376 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47377 return link;
47378 }
47379
47380 -static void free_link(char *link)
47381 +static void free_link(const char *link)
47382 {
47383 if (!IS_ERR(link))
47384 free_page((unsigned long) link);
47385 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47386 index 753af3d..f7b021a 100644
47387 --- a/fs/gfs2/inode.c
47388 +++ b/fs/gfs2/inode.c
47389 @@ -1498,7 +1498,7 @@ out:
47390
47391 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47392 {
47393 - char *s = nd_get_link(nd);
47394 + const char *s = nd_get_link(nd);
47395 if (!IS_ERR(s))
47396 kfree(s);
47397 }
47398 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47399 index 8349a89..51a0254 100644
47400 --- a/fs/hugetlbfs/inode.c
47401 +++ b/fs/hugetlbfs/inode.c
47402 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47403 .kill_sb = kill_litter_super,
47404 };
47405
47406 -static struct vfsmount *hugetlbfs_vfsmount;
47407 +struct vfsmount *hugetlbfs_vfsmount;
47408
47409 static int can_do_hugetlb_shm(void)
47410 {
47411 diff --git a/fs/inode.c b/fs/inode.c
47412 index ac8d904..9f45d40 100644
47413 --- a/fs/inode.c
47414 +++ b/fs/inode.c
47415 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47416
47417 #ifdef CONFIG_SMP
47418 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47419 - static atomic_t shared_last_ino;
47420 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47421 + static atomic_unchecked_t shared_last_ino;
47422 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47423
47424 res = next - LAST_INO_BATCH;
47425 }
47426 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47427 index 4a6cf28..d3a29d3 100644
47428 --- a/fs/jffs2/erase.c
47429 +++ b/fs/jffs2/erase.c
47430 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47431 struct jffs2_unknown_node marker = {
47432 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47433 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47434 - .totlen = cpu_to_je32(c->cleanmarker_size)
47435 + .totlen = cpu_to_je32(c->cleanmarker_size),
47436 + .hdr_crc = cpu_to_je32(0)
47437 };
47438
47439 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47440 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47441 index a6597d6..41b30ec 100644
47442 --- a/fs/jffs2/wbuf.c
47443 +++ b/fs/jffs2/wbuf.c
47444 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47445 {
47446 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47447 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47448 - .totlen = constant_cpu_to_je32(8)
47449 + .totlen = constant_cpu_to_je32(8),
47450 + .hdr_crc = constant_cpu_to_je32(0)
47451 };
47452
47453 /*
47454 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47455 index c55c745..f67ee56 100644
47456 --- a/fs/jfs/super.c
47457 +++ b/fs/jfs/super.c
47458 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47459
47460 jfs_inode_cachep =
47461 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47462 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47463 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47464 init_once);
47465 if (jfs_inode_cachep == NULL)
47466 return -ENOMEM;
47467 diff --git a/fs/libfs.c b/fs/libfs.c
47468 index a74cb17..37fcbe4 100644
47469 --- a/fs/libfs.c
47470 +++ b/fs/libfs.c
47471 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47472
47473 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47474 struct dentry *next;
47475 + char d_name[sizeof(next->d_iname)];
47476 + const unsigned char *name;
47477 +
47478 next = list_entry(p, struct dentry, d_u.d_child);
47479 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47480 if (!simple_positive(next)) {
47481 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47482
47483 spin_unlock(&next->d_lock);
47484 spin_unlock(&dentry->d_lock);
47485 - if (filldir(dirent, next->d_name.name,
47486 + name = next->d_name.name;
47487 + if (name == next->d_iname) {
47488 + memcpy(d_name, name, next->d_name.len);
47489 + name = d_name;
47490 + }
47491 + if (filldir(dirent, name,
47492 next->d_name.len, filp->f_pos,
47493 next->d_inode->i_ino,
47494 dt_type(next->d_inode)) < 0)
47495 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47496 index 05d2912..760abfa 100644
47497 --- a/fs/lockd/clntproc.c
47498 +++ b/fs/lockd/clntproc.c
47499 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47500 /*
47501 * Cookie counter for NLM requests
47502 */
47503 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47504 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47505
47506 void nlmclnt_next_cookie(struct nlm_cookie *c)
47507 {
47508 - u32 cookie = atomic_inc_return(&nlm_cookie);
47509 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47510
47511 memcpy(c->data, &cookie, 4);
47512 c->len=4;
47513 diff --git a/fs/locks.c b/fs/locks.c
47514 index 7e81bfc..c3649aa 100644
47515 --- a/fs/locks.c
47516 +++ b/fs/locks.c
47517 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47518 return;
47519
47520 if (filp->f_op && filp->f_op->flock) {
47521 - struct file_lock fl = {
47522 + struct file_lock flock = {
47523 .fl_pid = current->tgid,
47524 .fl_file = filp,
47525 .fl_flags = FL_FLOCK,
47526 .fl_type = F_UNLCK,
47527 .fl_end = OFFSET_MAX,
47528 };
47529 - filp->f_op->flock(filp, F_SETLKW, &fl);
47530 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47531 - fl.fl_ops->fl_release_private(&fl);
47532 + filp->f_op->flock(filp, F_SETLKW, &flock);
47533 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47534 + flock.fl_ops->fl_release_private(&flock);
47535 }
47536
47537 lock_flocks();
47538 diff --git a/fs/namei.c b/fs/namei.c
47539 index 81bd546..80149d9 100644
47540 --- a/fs/namei.c
47541 +++ b/fs/namei.c
47542 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47543 if (ret != -EACCES)
47544 return ret;
47545
47546 +#ifdef CONFIG_GRKERNSEC
47547 + /* we'll block if we have to log due to a denied capability use */
47548 + if (mask & MAY_NOT_BLOCK)
47549 + return -ECHILD;
47550 +#endif
47551 +
47552 if (S_ISDIR(inode->i_mode)) {
47553 /* DACs are overridable for directories */
47554 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47555 - return 0;
47556 if (!(mask & MAY_WRITE))
47557 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47558 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47559 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47560 return 0;
47561 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47562 + return 0;
47563 return -EACCES;
47564 }
47565 /*
47566 + * Searching includes executable on directories, else just read.
47567 + */
47568 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47569 + if (mask == MAY_READ)
47570 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47571 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47572 + return 0;
47573 +
47574 + /*
47575 * Read/write DACs are always overridable.
47576 * Executable DACs are overridable when there is
47577 * at least one exec bit set.
47578 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47579 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47580 return 0;
47581
47582 - /*
47583 - * Searching includes executable on directories, else just read.
47584 - */
47585 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47586 - if (mask == MAY_READ)
47587 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47588 - return 0;
47589 -
47590 return -EACCES;
47591 }
47592
47593 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47594 {
47595 struct dentry *dentry = link->dentry;
47596 int error;
47597 - char *s;
47598 + const char *s;
47599
47600 BUG_ON(nd->flags & LOOKUP_RCU);
47601
47602 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47603 if (error)
47604 goto out_put_nd_path;
47605
47606 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47607 + dentry->d_inode, dentry, nd->path.mnt)) {
47608 + error = -EACCES;
47609 + goto out_put_nd_path;
47610 + }
47611 +
47612 nd->last_type = LAST_BIND;
47613 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47614 error = PTR_ERR(*p);
47615 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47616 break;
47617 res = walk_component(nd, path, &nd->last,
47618 nd->last_type, LOOKUP_FOLLOW);
47619 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47620 + res = -EACCES;
47621 put_link(nd, &link, cookie);
47622 } while (res > 0);
47623
47624 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47625 if (err)
47626 break;
47627 err = lookup_last(nd, &path);
47628 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47629 + err = -EACCES;
47630 put_link(nd, &link, cookie);
47631 }
47632 }
47633 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47634 if (!err)
47635 err = complete_walk(nd);
47636
47637 + if (!(nd->flags & LOOKUP_PARENT)) {
47638 +#ifdef CONFIG_GRKERNSEC
47639 + if (flags & LOOKUP_RCU) {
47640 + if (!err)
47641 + path_put(&nd->path);
47642 + err = -ECHILD;
47643 + } else
47644 +#endif
47645 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47646 + if (!err)
47647 + path_put(&nd->path);
47648 + err = -ENOENT;
47649 + }
47650 + }
47651 +
47652 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47653 if (!nd->inode->i_op->lookup) {
47654 path_put(&nd->path);
47655 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47656 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47657
47658 if (likely(!retval)) {
47659 + if (*name != '/' && nd->path.dentry && nd->inode) {
47660 +#ifdef CONFIG_GRKERNSEC
47661 + if (flags & LOOKUP_RCU)
47662 + return -ECHILD;
47663 +#endif
47664 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47665 + return -ENOENT;
47666 + }
47667 +
47668 if (unlikely(!audit_dummy_context())) {
47669 if (nd->path.dentry && nd->inode)
47670 audit_inode(name, nd->path.dentry);
47671 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47672 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47673 return -EPERM;
47674
47675 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47676 + return -EPERM;
47677 + if (gr_handle_rawio(inode))
47678 + return -EPERM;
47679 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47680 + return -EACCES;
47681 +
47682 return 0;
47683 }
47684
47685 @@ -2557,7 +2606,7 @@ looked_up:
47686 * cleared otherwise prior to returning.
47687 */
47688 static int lookup_open(struct nameidata *nd, struct path *path,
47689 - struct file *file,
47690 + struct path *link, struct file *file,
47691 const struct open_flags *op,
47692 bool got_write, int *opened)
47693 {
47694 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47695 /* Negative dentry, just create the file */
47696 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47697 umode_t mode = op->mode;
47698 +
47699 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47700 + error = -EACCES;
47701 + goto out_dput;
47702 + }
47703 +
47704 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47705 + error = -EACCES;
47706 + goto out_dput;
47707 + }
47708 +
47709 if (!IS_POSIXACL(dir->d_inode))
47710 mode &= ~current_umask();
47711 /*
47712 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47713 nd->flags & LOOKUP_EXCL);
47714 if (error)
47715 goto out_dput;
47716 + else
47717 + gr_handle_create(dentry, nd->path.mnt);
47718 }
47719 out_no_open:
47720 path->dentry = dentry;
47721 @@ -2627,7 +2689,7 @@ out_dput:
47722 /*
47723 * Handle the last step of open()
47724 */
47725 -static int do_last(struct nameidata *nd, struct path *path,
47726 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47727 struct file *file, const struct open_flags *op,
47728 int *opened, const char *pathname)
47729 {
47730 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47731 error = complete_walk(nd);
47732 if (error)
47733 return error;
47734 +#ifdef CONFIG_GRKERNSEC
47735 + if (nd->flags & LOOKUP_RCU) {
47736 + error = -ECHILD;
47737 + goto out;
47738 + }
47739 +#endif
47740 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47741 + error = -ENOENT;
47742 + goto out;
47743 + }
47744 audit_inode(pathname, nd->path.dentry);
47745 if (open_flag & O_CREAT) {
47746 error = -EISDIR;
47747 goto out;
47748 }
47749 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47750 + error = -EACCES;
47751 + goto out;
47752 + }
47753 goto finish_open;
47754 case LAST_BIND:
47755 error = complete_walk(nd);
47756 if (error)
47757 return error;
47758 +#ifdef CONFIG_GRKERNSEC
47759 + if (nd->flags & LOOKUP_RCU) {
47760 + error = -ECHILD;
47761 + goto out;
47762 + }
47763 +#endif
47764 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47765 + error = -ENOENT;
47766 + goto out;
47767 + }
47768 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47769 + error = -EACCES;
47770 + goto out;
47771 + }
47772 audit_inode(pathname, dir);
47773 goto finish_open;
47774 }
47775 @@ -2714,7 +2804,7 @@ retry_lookup:
47776 */
47777 }
47778 mutex_lock(&dir->d_inode->i_mutex);
47779 - error = lookup_open(nd, path, file, op, got_write, opened);
47780 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47781 mutex_unlock(&dir->d_inode->i_mutex);
47782
47783 if (error <= 0) {
47784 @@ -2738,11 +2828,28 @@ retry_lookup:
47785 goto finish_open_created;
47786 }
47787
47788 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47789 + error = -ENOENT;
47790 + goto exit_dput;
47791 + }
47792 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47793 + error = -EACCES;
47794 + goto exit_dput;
47795 + }
47796 +
47797 /*
47798 * create/update audit record if it already exists.
47799 */
47800 - if (path->dentry->d_inode)
47801 + if (path->dentry->d_inode) {
47802 + /* only check if O_CREAT is specified, all other checks need to go
47803 + into may_open */
47804 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47805 + error = -EACCES;
47806 + goto exit_dput;
47807 + }
47808 +
47809 audit_inode(pathname, path->dentry);
47810 + }
47811
47812 /*
47813 * If atomic_open() acquired write access it is dropped now due to
47814 @@ -2783,6 +2890,11 @@ finish_lookup:
47815 }
47816 }
47817 BUG_ON(inode != path->dentry->d_inode);
47818 + /* if we're resolving a symlink to another symlink */
47819 + if (link && gr_handle_symlink_owner(link, inode)) {
47820 + error = -EACCES;
47821 + goto out;
47822 + }
47823 return 1;
47824 }
47825
47826 @@ -2792,7 +2904,6 @@ finish_lookup:
47827 save_parent.dentry = nd->path.dentry;
47828 save_parent.mnt = mntget(path->mnt);
47829 nd->path.dentry = path->dentry;
47830 -
47831 }
47832 nd->inode = inode;
47833 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47834 @@ -2801,6 +2912,22 @@ finish_lookup:
47835 path_put(&save_parent);
47836 return error;
47837 }
47838 +
47839 +#ifdef CONFIG_GRKERNSEC
47840 + if (nd->flags & LOOKUP_RCU) {
47841 + error = -ECHILD;
47842 + goto out;
47843 + }
47844 +#endif
47845 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47846 + error = -ENOENT;
47847 + goto out;
47848 + }
47849 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47850 + error = -EACCES;
47851 + goto out;
47852 + }
47853 +
47854 error = -EISDIR;
47855 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47856 goto out;
47857 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47858 if (unlikely(error))
47859 goto out;
47860
47861 - error = do_last(nd, &path, file, op, &opened, pathname);
47862 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47863 while (unlikely(error > 0)) { /* trailing symlink */
47864 struct path link = path;
47865 void *cookie;
47866 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47867 error = follow_link(&link, nd, &cookie);
47868 if (unlikely(error))
47869 break;
47870 - error = do_last(nd, &path, file, op, &opened, pathname);
47871 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
47872 put_link(nd, &link, cookie);
47873 }
47874 out:
47875 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47876 goto unlock;
47877
47878 error = -EEXIST;
47879 - if (dentry->d_inode)
47880 + if (dentry->d_inode) {
47881 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47882 + error = -ENOENT;
47883 + }
47884 goto fail;
47885 + }
47886 /*
47887 * Special case - lookup gave negative, but... we had foo/bar/
47888 * From the vfs_mknod() POV we just have a negative dentry -
47889 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47890 }
47891 EXPORT_SYMBOL(user_path_create);
47892
47893 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47894 +{
47895 + char *tmp = getname(pathname);
47896 + struct dentry *res;
47897 + if (IS_ERR(tmp))
47898 + return ERR_CAST(tmp);
47899 + res = kern_path_create(dfd, tmp, path, is_dir);
47900 + if (IS_ERR(res))
47901 + putname(tmp);
47902 + else
47903 + *to = tmp;
47904 + return res;
47905 +}
47906 +
47907 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47908 {
47909 int error = may_create(dir, dentry);
47910 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47911
47912 if (!IS_POSIXACL(path.dentry->d_inode))
47913 mode &= ~current_umask();
47914 +
47915 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47916 + error = -EPERM;
47917 + goto out;
47918 + }
47919 +
47920 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47921 + error = -EACCES;
47922 + goto out;
47923 + }
47924 +
47925 error = security_path_mknod(&path, dentry, mode, dev);
47926 if (error)
47927 goto out;
47928 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47929 break;
47930 }
47931 out:
47932 + if (!error)
47933 + gr_handle_create(dentry, path.mnt);
47934 done_path_create(&path, dentry);
47935 return error;
47936 }
47937 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47938
47939 if (!IS_POSIXACL(path.dentry->d_inode))
47940 mode &= ~current_umask();
47941 +
47942 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47943 + error = -EACCES;
47944 + goto out;
47945 + }
47946 +
47947 error = security_path_mkdir(&path, dentry, mode);
47948 if (!error)
47949 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47950 + if (!error)
47951 + gr_handle_create(dentry, path.mnt);
47952 +out:
47953 done_path_create(&path, dentry);
47954 return error;
47955 }
47956 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47957 char * name;
47958 struct dentry *dentry;
47959 struct nameidata nd;
47960 + ino_t saved_ino = 0;
47961 + dev_t saved_dev = 0;
47962
47963 error = user_path_parent(dfd, pathname, &nd, &name);
47964 if (error)
47965 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
47966 error = -ENOENT;
47967 goto exit3;
47968 }
47969 +
47970 + saved_ino = dentry->d_inode->i_ino;
47971 + saved_dev = gr_get_dev_from_dentry(dentry);
47972 +
47973 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47974 + error = -EACCES;
47975 + goto exit3;
47976 + }
47977 +
47978 error = security_path_rmdir(&nd.path, dentry);
47979 if (error)
47980 goto exit3;
47981 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47982 + if (!error && (saved_dev || saved_ino))
47983 + gr_handle_delete(saved_ino, saved_dev);
47984 exit3:
47985 dput(dentry);
47986 exit2:
47987 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47988 struct dentry *dentry;
47989 struct nameidata nd;
47990 struct inode *inode = NULL;
47991 + ino_t saved_ino = 0;
47992 + dev_t saved_dev = 0;
47993
47994 error = user_path_parent(dfd, pathname, &nd, &name);
47995 if (error)
47996 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47997 if (!inode)
47998 goto slashes;
47999 ihold(inode);
48000 +
48001 + if (inode->i_nlink <= 1) {
48002 + saved_ino = inode->i_ino;
48003 + saved_dev = gr_get_dev_from_dentry(dentry);
48004 + }
48005 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48006 + error = -EACCES;
48007 + goto exit2;
48008 + }
48009 +
48010 error = security_path_unlink(&nd.path, dentry);
48011 if (error)
48012 goto exit2;
48013 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48014 + if (!error && (saved_ino || saved_dev))
48015 + gr_handle_delete(saved_ino, saved_dev);
48016 exit2:
48017 dput(dentry);
48018 }
48019 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48020 if (IS_ERR(dentry))
48021 goto out_putname;
48022
48023 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48024 + error = -EACCES;
48025 + goto out;
48026 + }
48027 +
48028 error = security_path_symlink(&path, dentry, from);
48029 if (!error)
48030 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48031 + if (!error)
48032 + gr_handle_create(dentry, path.mnt);
48033 +out:
48034 done_path_create(&path, dentry);
48035 out_putname:
48036 putname(from);
48037 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48038 {
48039 struct dentry *new_dentry;
48040 struct path old_path, new_path;
48041 + char *to = NULL;
48042 int how = 0;
48043 int error;
48044
48045 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48046 if (error)
48047 return error;
48048
48049 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48050 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48051 error = PTR_ERR(new_dentry);
48052 if (IS_ERR(new_dentry))
48053 goto out;
48054 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48055 error = may_linkat(&old_path);
48056 if (unlikely(error))
48057 goto out_dput;
48058 +
48059 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48060 + old_path.dentry->d_inode,
48061 + old_path.dentry->d_inode->i_mode, to)) {
48062 + error = -EACCES;
48063 + goto out_dput;
48064 + }
48065 +
48066 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48067 + old_path.dentry, old_path.mnt, to)) {
48068 + error = -EACCES;
48069 + goto out_dput;
48070 + }
48071 +
48072 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48073 if (error)
48074 goto out_dput;
48075 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48076 + if (!error)
48077 + gr_handle_create(new_dentry, new_path.mnt);
48078 out_dput:
48079 + putname(to);
48080 done_path_create(&new_path, new_dentry);
48081 out:
48082 path_put(&old_path);
48083 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48084 if (new_dentry == trap)
48085 goto exit5;
48086
48087 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48088 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48089 + to);
48090 + if (error)
48091 + goto exit5;
48092 +
48093 error = security_path_rename(&oldnd.path, old_dentry,
48094 &newnd.path, new_dentry);
48095 if (error)
48096 goto exit5;
48097 error = vfs_rename(old_dir->d_inode, old_dentry,
48098 new_dir->d_inode, new_dentry);
48099 + if (!error)
48100 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48101 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48102 exit5:
48103 dput(new_dentry);
48104 exit4:
48105 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48106
48107 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48108 {
48109 + char tmpbuf[64];
48110 + const char *newlink;
48111 int len;
48112
48113 len = PTR_ERR(link);
48114 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48115 len = strlen(link);
48116 if (len > (unsigned) buflen)
48117 len = buflen;
48118 - if (copy_to_user(buffer, link, len))
48119 +
48120 + if (len < sizeof(tmpbuf)) {
48121 + memcpy(tmpbuf, link, len);
48122 + newlink = tmpbuf;
48123 + } else
48124 + newlink = link;
48125 +
48126 + if (copy_to_user(buffer, newlink, len))
48127 len = -EFAULT;
48128 out:
48129 return len;
48130 diff --git a/fs/namespace.c b/fs/namespace.c
48131 index 7bdf790..eb79c4b 100644
48132 --- a/fs/namespace.c
48133 +++ b/fs/namespace.c
48134 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48135 if (!(sb->s_flags & MS_RDONLY))
48136 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48137 up_write(&sb->s_umount);
48138 +
48139 + gr_log_remount(mnt->mnt_devname, retval);
48140 +
48141 return retval;
48142 }
48143
48144 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48145 br_write_unlock(&vfsmount_lock);
48146 up_write(&namespace_sem);
48147 release_mounts(&umount_list);
48148 +
48149 + gr_log_unmount(mnt->mnt_devname, retval);
48150 +
48151 return retval;
48152 }
48153
48154 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48155 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48156 MS_STRICTATIME);
48157
48158 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48159 + retval = -EPERM;
48160 + goto dput_out;
48161 + }
48162 +
48163 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48164 + retval = -EPERM;
48165 + goto dput_out;
48166 + }
48167 +
48168 if (flags & MS_REMOUNT)
48169 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48170 data_page);
48171 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48172 dev_name, data_page);
48173 dput_out:
48174 path_put(&path);
48175 +
48176 + gr_log_mount(dev_name, dir_name, retval);
48177 +
48178 return retval;
48179 }
48180
48181 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48182 if (error)
48183 goto out2;
48184
48185 + if (gr_handle_chroot_pivot()) {
48186 + error = -EPERM;
48187 + goto out2;
48188 + }
48189 +
48190 get_fs_root(current->fs, &root);
48191 error = lock_mount(&old);
48192 if (error)
48193 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48194 index 9b47610..066975e 100644
48195 --- a/fs/nfs/inode.c
48196 +++ b/fs/nfs/inode.c
48197 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48198 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48199 }
48200
48201 -static atomic_long_t nfs_attr_generation_counter;
48202 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48203
48204 static unsigned long nfs_read_attr_generation_counter(void)
48205 {
48206 - return atomic_long_read(&nfs_attr_generation_counter);
48207 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48208 }
48209
48210 unsigned long nfs_inc_attr_generation_counter(void)
48211 {
48212 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48213 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48214 }
48215
48216 void nfs_fattr_init(struct nfs_fattr *fattr)
48217 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48218 index a9269f1..5490437 100644
48219 --- a/fs/nfsd/vfs.c
48220 +++ b/fs/nfsd/vfs.c
48221 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48222 } else {
48223 oldfs = get_fs();
48224 set_fs(KERNEL_DS);
48225 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48226 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48227 set_fs(oldfs);
48228 }
48229
48230 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48231
48232 /* Write the data. */
48233 oldfs = get_fs(); set_fs(KERNEL_DS);
48234 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48235 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48236 set_fs(oldfs);
48237 if (host_err < 0)
48238 goto out_nfserr;
48239 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48240 */
48241
48242 oldfs = get_fs(); set_fs(KERNEL_DS);
48243 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48244 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48245 set_fs(oldfs);
48246
48247 if (host_err < 0)
48248 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48249 index d438036..0ecadde 100644
48250 --- a/fs/notify/fanotify/fanotify_user.c
48251 +++ b/fs/notify/fanotify/fanotify_user.c
48252 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48253 goto out_close_fd;
48254
48255 ret = -EFAULT;
48256 - if (copy_to_user(buf, &fanotify_event_metadata,
48257 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48258 + copy_to_user(buf, &fanotify_event_metadata,
48259 fanotify_event_metadata.event_len))
48260 goto out_kill_access_response;
48261
48262 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48263 index c887b13..0fdf472 100644
48264 --- a/fs/notify/notification.c
48265 +++ b/fs/notify/notification.c
48266 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48267 * get set to 0 so it will never get 'freed'
48268 */
48269 static struct fsnotify_event *q_overflow_event;
48270 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48271 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48272
48273 /**
48274 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48275 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48276 */
48277 u32 fsnotify_get_cookie(void)
48278 {
48279 - return atomic_inc_return(&fsnotify_sync_cookie);
48280 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48281 }
48282 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48283
48284 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48285 index 99e3610..02c1068 100644
48286 --- a/fs/ntfs/dir.c
48287 +++ b/fs/ntfs/dir.c
48288 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48289 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48290 ~(s64)(ndir->itype.index.block_size - 1)));
48291 /* Bounds checks. */
48292 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48293 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48294 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48295 "inode 0x%lx or driver bug.", vdir->i_ino);
48296 goto err_out;
48297 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48298 index 1ecf464..e1ff8bf 100644
48299 --- a/fs/ntfs/file.c
48300 +++ b/fs/ntfs/file.c
48301 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48302 #endif /* NTFS_RW */
48303 };
48304
48305 -const struct file_operations ntfs_empty_file_ops = {};
48306 +const struct file_operations ntfs_empty_file_ops __read_only;
48307
48308 -const struct inode_operations ntfs_empty_inode_ops = {};
48309 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48310 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48311 index a9f78c7..ed8a381 100644
48312 --- a/fs/ocfs2/localalloc.c
48313 +++ b/fs/ocfs2/localalloc.c
48314 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48315 goto bail;
48316 }
48317
48318 - atomic_inc(&osb->alloc_stats.moves);
48319 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48320
48321 bail:
48322 if (handle)
48323 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48324 index d355e6e..578d905 100644
48325 --- a/fs/ocfs2/ocfs2.h
48326 +++ b/fs/ocfs2/ocfs2.h
48327 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48328
48329 struct ocfs2_alloc_stats
48330 {
48331 - atomic_t moves;
48332 - atomic_t local_data;
48333 - atomic_t bitmap_data;
48334 - atomic_t bg_allocs;
48335 - atomic_t bg_extends;
48336 + atomic_unchecked_t moves;
48337 + atomic_unchecked_t local_data;
48338 + atomic_unchecked_t bitmap_data;
48339 + atomic_unchecked_t bg_allocs;
48340 + atomic_unchecked_t bg_extends;
48341 };
48342
48343 enum ocfs2_local_alloc_state
48344 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48345 index f169da4..9112253 100644
48346 --- a/fs/ocfs2/suballoc.c
48347 +++ b/fs/ocfs2/suballoc.c
48348 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48349 mlog_errno(status);
48350 goto bail;
48351 }
48352 - atomic_inc(&osb->alloc_stats.bg_extends);
48353 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48354
48355 /* You should never ask for this much metadata */
48356 BUG_ON(bits_wanted >
48357 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48358 mlog_errno(status);
48359 goto bail;
48360 }
48361 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48362 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48363
48364 *suballoc_loc = res.sr_bg_blkno;
48365 *suballoc_bit_start = res.sr_bit_offset;
48366 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48367 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48368 res->sr_bits);
48369
48370 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48371 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48372
48373 BUG_ON(res->sr_bits != 1);
48374
48375 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48376 mlog_errno(status);
48377 goto bail;
48378 }
48379 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48380 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48381
48382 BUG_ON(res.sr_bits != 1);
48383
48384 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48385 cluster_start,
48386 num_clusters);
48387 if (!status)
48388 - atomic_inc(&osb->alloc_stats.local_data);
48389 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48390 } else {
48391 if (min_clusters > (osb->bitmap_cpg - 1)) {
48392 /* The only paths asking for contiguousness
48393 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48394 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48395 res.sr_bg_blkno,
48396 res.sr_bit_offset);
48397 - atomic_inc(&osb->alloc_stats.bitmap_data);
48398 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48399 *num_clusters = res.sr_bits;
48400 }
48401 }
48402 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48403 index 68f4541..89cfe6a 100644
48404 --- a/fs/ocfs2/super.c
48405 +++ b/fs/ocfs2/super.c
48406 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48407 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48408 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48409 "Stats",
48410 - atomic_read(&osb->alloc_stats.bitmap_data),
48411 - atomic_read(&osb->alloc_stats.local_data),
48412 - atomic_read(&osb->alloc_stats.bg_allocs),
48413 - atomic_read(&osb->alloc_stats.moves),
48414 - atomic_read(&osb->alloc_stats.bg_extends));
48415 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48416 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48417 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48418 + atomic_read_unchecked(&osb->alloc_stats.moves),
48419 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48420
48421 out += snprintf(buf + out, len - out,
48422 "%10s => State: %u Descriptor: %llu Size: %u bits "
48423 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48424 spin_lock_init(&osb->osb_xattr_lock);
48425 ocfs2_init_steal_slots(osb);
48426
48427 - atomic_set(&osb->alloc_stats.moves, 0);
48428 - atomic_set(&osb->alloc_stats.local_data, 0);
48429 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48430 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48431 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48432 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48433 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48434 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48435 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48436 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48437
48438 /* Copy the blockcheck stats from the superblock probe */
48439 osb->osb_ecc_stats = *stats;
48440 diff --git a/fs/open.c b/fs/open.c
48441 index e1f2cdb..3bd5f39 100644
48442 --- a/fs/open.c
48443 +++ b/fs/open.c
48444 @@ -31,6 +31,8 @@
48445 #include <linux/ima.h>
48446 #include <linux/dnotify.h>
48447
48448 +#define CREATE_TRACE_POINTS
48449 +#include <trace/events/fs.h>
48450 #include "internal.h"
48451
48452 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48453 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48454 error = locks_verify_truncate(inode, NULL, length);
48455 if (!error)
48456 error = security_path_truncate(&path);
48457 +
48458 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48459 + error = -EACCES;
48460 +
48461 if (!error)
48462 error = do_truncate(path.dentry, length, 0, NULL);
48463
48464 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48465 if (__mnt_is_readonly(path.mnt))
48466 res = -EROFS;
48467
48468 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48469 + res = -EACCES;
48470 +
48471 out_path_release:
48472 path_put(&path);
48473 out:
48474 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48475 if (error)
48476 goto dput_and_out;
48477
48478 + gr_log_chdir(path.dentry, path.mnt);
48479 +
48480 set_fs_pwd(current->fs, &path);
48481
48482 dput_and_out:
48483 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48484 goto out_putf;
48485
48486 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48487 +
48488 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48489 + error = -EPERM;
48490 +
48491 + if (!error)
48492 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48493 +
48494 if (!error)
48495 set_fs_pwd(current->fs, &file->f_path);
48496 out_putf:
48497 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48498 if (error)
48499 goto dput_and_out;
48500
48501 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48502 + goto dput_and_out;
48503 +
48504 set_fs_root(current->fs, &path);
48505 +
48506 + gr_handle_chroot_chdir(&path);
48507 +
48508 error = 0;
48509 dput_and_out:
48510 path_put(&path);
48511 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48512 if (error)
48513 return error;
48514 mutex_lock(&inode->i_mutex);
48515 +
48516 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48517 + error = -EACCES;
48518 + goto out_unlock;
48519 + }
48520 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48521 + error = -EACCES;
48522 + goto out_unlock;
48523 + }
48524 +
48525 error = security_path_chmod(path, mode);
48526 if (error)
48527 goto out_unlock;
48528 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48529 uid = make_kuid(current_user_ns(), user);
48530 gid = make_kgid(current_user_ns(), group);
48531
48532 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48533 + return -EACCES;
48534 +
48535 newattrs.ia_valid = ATTR_CTIME;
48536 if (user != (uid_t) -1) {
48537 if (!uid_valid(uid))
48538 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48539 } else {
48540 fsnotify_open(f);
48541 fd_install(fd, f);
48542 + trace_do_sys_open(tmp, flags, mode);
48543 }
48544 }
48545 putname(tmp);
48546 diff --git a/fs/pipe.c b/fs/pipe.c
48547 index 8d85d70..581036b 100644
48548 --- a/fs/pipe.c
48549 +++ b/fs/pipe.c
48550 @@ -438,9 +438,9 @@ redo:
48551 }
48552 if (bufs) /* More to do? */
48553 continue;
48554 - if (!pipe->writers)
48555 + if (!atomic_read(&pipe->writers))
48556 break;
48557 - if (!pipe->waiting_writers) {
48558 + if (!atomic_read(&pipe->waiting_writers)) {
48559 /* syscall merging: Usually we must not sleep
48560 * if O_NONBLOCK is set, or if we got some data.
48561 * But if a writer sleeps in kernel space, then
48562 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48563 mutex_lock(&inode->i_mutex);
48564 pipe = inode->i_pipe;
48565
48566 - if (!pipe->readers) {
48567 + if (!atomic_read(&pipe->readers)) {
48568 send_sig(SIGPIPE, current, 0);
48569 ret = -EPIPE;
48570 goto out;
48571 @@ -553,7 +553,7 @@ redo1:
48572 for (;;) {
48573 int bufs;
48574
48575 - if (!pipe->readers) {
48576 + if (!atomic_read(&pipe->readers)) {
48577 send_sig(SIGPIPE, current, 0);
48578 if (!ret)
48579 ret = -EPIPE;
48580 @@ -644,9 +644,9 @@ redo2:
48581 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48582 do_wakeup = 0;
48583 }
48584 - pipe->waiting_writers++;
48585 + atomic_inc(&pipe->waiting_writers);
48586 pipe_wait(pipe);
48587 - pipe->waiting_writers--;
48588 + atomic_dec(&pipe->waiting_writers);
48589 }
48590 out:
48591 mutex_unlock(&inode->i_mutex);
48592 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48593 mask = 0;
48594 if (filp->f_mode & FMODE_READ) {
48595 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48596 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48597 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48598 mask |= POLLHUP;
48599 }
48600
48601 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48602 * Most Unices do not set POLLERR for FIFOs but on Linux they
48603 * behave exactly like pipes for poll().
48604 */
48605 - if (!pipe->readers)
48606 + if (!atomic_read(&pipe->readers))
48607 mask |= POLLERR;
48608 }
48609
48610 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48611
48612 mutex_lock(&inode->i_mutex);
48613 pipe = inode->i_pipe;
48614 - pipe->readers -= decr;
48615 - pipe->writers -= decw;
48616 + atomic_sub(decr, &pipe->readers);
48617 + atomic_sub(decw, &pipe->writers);
48618
48619 - if (!pipe->readers && !pipe->writers) {
48620 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48621 free_pipe_info(inode);
48622 } else {
48623 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48624 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48625
48626 if (inode->i_pipe) {
48627 ret = 0;
48628 - inode->i_pipe->readers++;
48629 + atomic_inc(&inode->i_pipe->readers);
48630 }
48631
48632 mutex_unlock(&inode->i_mutex);
48633 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48634
48635 if (inode->i_pipe) {
48636 ret = 0;
48637 - inode->i_pipe->writers++;
48638 + atomic_inc(&inode->i_pipe->writers);
48639 }
48640
48641 mutex_unlock(&inode->i_mutex);
48642 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48643 if (inode->i_pipe) {
48644 ret = 0;
48645 if (filp->f_mode & FMODE_READ)
48646 - inode->i_pipe->readers++;
48647 + atomic_inc(&inode->i_pipe->readers);
48648 if (filp->f_mode & FMODE_WRITE)
48649 - inode->i_pipe->writers++;
48650 + atomic_inc(&inode->i_pipe->writers);
48651 }
48652
48653 mutex_unlock(&inode->i_mutex);
48654 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48655 inode->i_pipe = NULL;
48656 }
48657
48658 -static struct vfsmount *pipe_mnt __read_mostly;
48659 +struct vfsmount *pipe_mnt __read_mostly;
48660
48661 /*
48662 * pipefs_dname() is called from d_path().
48663 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48664 goto fail_iput;
48665 inode->i_pipe = pipe;
48666
48667 - pipe->readers = pipe->writers = 1;
48668 + atomic_set(&pipe->readers, 1);
48669 + atomic_set(&pipe->writers, 1);
48670 inode->i_fop = &rdwr_pipefifo_fops;
48671
48672 /*
48673 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48674 index 15af622..0e9f4467 100644
48675 --- a/fs/proc/Kconfig
48676 +++ b/fs/proc/Kconfig
48677 @@ -30,12 +30,12 @@ config PROC_FS
48678
48679 config PROC_KCORE
48680 bool "/proc/kcore support" if !ARM
48681 - depends on PROC_FS && MMU
48682 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48683
48684 config PROC_VMCORE
48685 bool "/proc/vmcore support"
48686 - depends on PROC_FS && CRASH_DUMP
48687 - default y
48688 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48689 + default n
48690 help
48691 Exports the dump image of crashed kernel in ELF format.
48692
48693 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48694 limited in memory.
48695
48696 config PROC_PAGE_MONITOR
48697 - default y
48698 - depends on PROC_FS && MMU
48699 + default n
48700 + depends on PROC_FS && MMU && !GRKERNSEC
48701 bool "Enable /proc page monitoring" if EXPERT
48702 help
48703 Various /proc files exist to monitor process memory utilization:
48704 diff --git a/fs/proc/array.c b/fs/proc/array.c
48705 index c1c207c..01ce725 100644
48706 --- a/fs/proc/array.c
48707 +++ b/fs/proc/array.c
48708 @@ -60,6 +60,7 @@
48709 #include <linux/tty.h>
48710 #include <linux/string.h>
48711 #include <linux/mman.h>
48712 +#include <linux/grsecurity.h>
48713 #include <linux/proc_fs.h>
48714 #include <linux/ioport.h>
48715 #include <linux/uaccess.h>
48716 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48717 seq_putc(m, '\n');
48718 }
48719
48720 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48721 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48722 +{
48723 + if (p->mm)
48724 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48725 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48726 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48727 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48728 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48729 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48730 + else
48731 + seq_printf(m, "PaX:\t-----\n");
48732 +}
48733 +#endif
48734 +
48735 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48736 struct pid *pid, struct task_struct *task)
48737 {
48738 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48739 task_cpus_allowed(m, task);
48740 cpuset_task_status_allowed(m, task);
48741 task_context_switch_counts(m, task);
48742 +
48743 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48744 + task_pax(m, task);
48745 +#endif
48746 +
48747 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48748 + task_grsec_rbac(m, task);
48749 +#endif
48750 +
48751 return 0;
48752 }
48753
48754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48755 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48756 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48757 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48758 +#endif
48759 +
48760 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48761 struct pid *pid, struct task_struct *task, int whole)
48762 {
48763 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48764 char tcomm[sizeof(task->comm)];
48765 unsigned long flags;
48766
48767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48768 + if (current->exec_id != m->exec_id) {
48769 + gr_log_badprocpid("stat");
48770 + return 0;
48771 + }
48772 +#endif
48773 +
48774 state = *get_task_state(task);
48775 vsize = eip = esp = 0;
48776 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48777 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48778 gtime = task->gtime;
48779 }
48780
48781 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48782 + if (PAX_RAND_FLAGS(mm)) {
48783 + eip = 0;
48784 + esp = 0;
48785 + wchan = 0;
48786 + }
48787 +#endif
48788 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48789 + wchan = 0;
48790 + eip =0;
48791 + esp =0;
48792 +#endif
48793 +
48794 /* scale priority and nice values from timeslices to -20..20 */
48795 /* to make it look like a "normal" Unix priority/nice value */
48796 priority = task_prio(task);
48797 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48798 seq_put_decimal_ull(m, ' ', vsize);
48799 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48800 seq_put_decimal_ull(m, ' ', rsslim);
48801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48802 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48803 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48804 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48805 +#else
48806 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48807 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48808 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48809 +#endif
48810 seq_put_decimal_ull(m, ' ', esp);
48811 seq_put_decimal_ull(m, ' ', eip);
48812 /* The signal information here is obsolete.
48813 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48814 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48815 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48816
48817 - if (mm && permitted) {
48818 + if (mm && permitted
48819 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48820 + && !PAX_RAND_FLAGS(mm)
48821 +#endif
48822 + ) {
48823 seq_put_decimal_ull(m, ' ', mm->start_data);
48824 seq_put_decimal_ull(m, ' ', mm->end_data);
48825 seq_put_decimal_ull(m, ' ', mm->start_brk);
48826 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48827 struct pid *pid, struct task_struct *task)
48828 {
48829 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48830 - struct mm_struct *mm = get_task_mm(task);
48831 + struct mm_struct *mm;
48832
48833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48834 + if (current->exec_id != m->exec_id) {
48835 + gr_log_badprocpid("statm");
48836 + return 0;
48837 + }
48838 +#endif
48839 + mm = get_task_mm(task);
48840 if (mm) {
48841 size = task_statm(mm, &shared, &text, &data, &resident);
48842 mmput(mm);
48843 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48844 return 0;
48845 }
48846
48847 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48848 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48849 +{
48850 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48851 +}
48852 +#endif
48853 +
48854 #ifdef CONFIG_CHECKPOINT_RESTORE
48855 static struct pid *
48856 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48857 diff --git a/fs/proc/base.c b/fs/proc/base.c
48858 index 1b6c84c..66b738b 100644
48859 --- a/fs/proc/base.c
48860 +++ b/fs/proc/base.c
48861 @@ -110,6 +110,14 @@ struct pid_entry {
48862 union proc_op op;
48863 };
48864
48865 +struct getdents_callback {
48866 + struct linux_dirent __user * current_dir;
48867 + struct linux_dirent __user * previous;
48868 + struct file * file;
48869 + int count;
48870 + int error;
48871 +};
48872 +
48873 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48874 .name = (NAME), \
48875 .len = sizeof(NAME) - 1, \
48876 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48877 if (!mm->arg_end)
48878 goto out_mm; /* Shh! No looking before we're done */
48879
48880 + if (gr_acl_handle_procpidmem(task))
48881 + goto out_mm;
48882 +
48883 len = mm->arg_end - mm->arg_start;
48884
48885 if (len > PAGE_SIZE)
48886 @@ -236,12 +247,28 @@ out:
48887 return res;
48888 }
48889
48890 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48891 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48892 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48893 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48894 +#endif
48895 +
48896 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48897 {
48898 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48899 int res = PTR_ERR(mm);
48900 if (mm && !IS_ERR(mm)) {
48901 unsigned int nwords = 0;
48902 +
48903 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48904 + /* allow if we're currently ptracing this task */
48905 + if (PAX_RAND_FLAGS(mm) &&
48906 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48907 + mmput(mm);
48908 + return 0;
48909 + }
48910 +#endif
48911 +
48912 do {
48913 nwords += 2;
48914 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48915 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48916 }
48917
48918
48919 -#ifdef CONFIG_KALLSYMS
48920 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48921 /*
48922 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48923 * Returns the resolved symbol. If that fails, simply return the address.
48924 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48925 mutex_unlock(&task->signal->cred_guard_mutex);
48926 }
48927
48928 -#ifdef CONFIG_STACKTRACE
48929 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48930
48931 #define MAX_STACK_TRACE_DEPTH 64
48932
48933 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48934 return count;
48935 }
48936
48937 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48938 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48939 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48940 {
48941 long nr;
48942 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48943 /************************************************************************/
48944
48945 /* permission checks */
48946 -static int proc_fd_access_allowed(struct inode *inode)
48947 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48948 {
48949 struct task_struct *task;
48950 int allowed = 0;
48951 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48952 */
48953 task = get_proc_task(inode);
48954 if (task) {
48955 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48956 + if (log)
48957 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48958 + else
48959 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48960 put_task_struct(task);
48961 }
48962 return allowed;
48963 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48964 struct task_struct *task,
48965 int hide_pid_min)
48966 {
48967 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48968 + return false;
48969 +
48970 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48971 + rcu_read_lock();
48972 + {
48973 + const struct cred *tmpcred = current_cred();
48974 + const struct cred *cred = __task_cred(task);
48975 +
48976 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48977 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48978 + || in_group_p(grsec_proc_gid)
48979 +#endif
48980 + ) {
48981 + rcu_read_unlock();
48982 + return true;
48983 + }
48984 + }
48985 + rcu_read_unlock();
48986 +
48987 + if (!pid->hide_pid)
48988 + return false;
48989 +#endif
48990 +
48991 if (pid->hide_pid < hide_pid_min)
48992 return true;
48993 if (in_group_p(pid->pid_gid))
48994 return true;
48995 +
48996 return ptrace_may_access(task, PTRACE_MODE_READ);
48997 }
48998
48999 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49000 put_task_struct(task);
49001
49002 if (!has_perms) {
49003 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49004 + {
49005 +#else
49006 if (pid->hide_pid == 2) {
49007 +#endif
49008 /*
49009 * Let's make getdents(), stat(), and open()
49010 * consistent with each other. If a process
49011 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49012 if (!task)
49013 return -ESRCH;
49014
49015 + if (gr_acl_handle_procpidmem(task)) {
49016 + put_task_struct(task);
49017 + return -EPERM;
49018 + }
49019 +
49020 mm = mm_access(task, mode);
49021 put_task_struct(task);
49022
49023 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49024
49025 file->private_data = mm;
49026
49027 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49028 + file->f_version = current->exec_id;
49029 +#endif
49030 +
49031 return 0;
49032 }
49033
49034 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49035 ssize_t copied;
49036 char *page;
49037
49038 +#ifdef CONFIG_GRKERNSEC
49039 + if (write)
49040 + return -EPERM;
49041 +#endif
49042 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49043 + if (file->f_version != current->exec_id) {
49044 + gr_log_badprocpid("mem");
49045 + return 0;
49046 + }
49047 +#endif
49048 +
49049 if (!mm)
49050 return 0;
49051
49052 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49053 if (!mm)
49054 return 0;
49055
49056 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49057 + if (file->f_version != current->exec_id) {
49058 + gr_log_badprocpid("environ");
49059 + return 0;
49060 + }
49061 +#endif
49062 +
49063 page = (char *)__get_free_page(GFP_TEMPORARY);
49064 if (!page)
49065 return -ENOMEM;
49066 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49067 int error = -EACCES;
49068
49069 /* Are we allowed to snoop on the tasks file descriptors? */
49070 - if (!proc_fd_access_allowed(inode))
49071 + if (!proc_fd_access_allowed(inode, 0))
49072 goto out;
49073
49074 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49075 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49076 struct path path;
49077
49078 /* Are we allowed to snoop on the tasks file descriptors? */
49079 - if (!proc_fd_access_allowed(inode))
49080 - goto out;
49081 + /* logging this is needed for learning on chromium to work properly,
49082 + but we don't want to flood the logs from 'ps' which does a readlink
49083 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49084 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49085 + */
49086 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49087 + if (!proc_fd_access_allowed(inode,0))
49088 + goto out;
49089 + } else {
49090 + if (!proc_fd_access_allowed(inode,1))
49091 + goto out;
49092 + }
49093
49094 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49095 if (error)
49096 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49097 rcu_read_lock();
49098 cred = __task_cred(task);
49099 inode->i_uid = cred->euid;
49100 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49101 + inode->i_gid = grsec_proc_gid;
49102 +#else
49103 inode->i_gid = cred->egid;
49104 +#endif
49105 rcu_read_unlock();
49106 }
49107 security_task_to_inode(task, inode);
49108 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49109 return -ENOENT;
49110 }
49111 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49112 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49113 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49114 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49115 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49116 +#endif
49117 task_dumpable(task)) {
49118 cred = __task_cred(task);
49119 stat->uid = cred->euid;
49120 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49121 + stat->gid = grsec_proc_gid;
49122 +#else
49123 stat->gid = cred->egid;
49124 +#endif
49125 }
49126 }
49127 rcu_read_unlock();
49128 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49129
49130 if (task) {
49131 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49133 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49134 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49135 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49136 +#endif
49137 task_dumpable(task)) {
49138 rcu_read_lock();
49139 cred = __task_cred(task);
49140 inode->i_uid = cred->euid;
49141 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49142 + inode->i_gid = grsec_proc_gid;
49143 +#else
49144 inode->i_gid = cred->egid;
49145 +#endif
49146 rcu_read_unlock();
49147 } else {
49148 inode->i_uid = GLOBAL_ROOT_UID;
49149 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49150 int fd = proc_fd(inode);
49151
49152 if (task) {
49153 - files = get_files_struct(task);
49154 + if (!gr_acl_handle_procpidmem(task))
49155 + files = get_files_struct(task);
49156 put_task_struct(task);
49157 }
49158 if (files) {
49159 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49160 */
49161 static int proc_fd_permission(struct inode *inode, int mask)
49162 {
49163 + struct task_struct *task;
49164 int rv = generic_permission(inode, mask);
49165 - if (rv == 0)
49166 - return 0;
49167 +
49168 if (task_pid(current) == proc_pid(inode))
49169 rv = 0;
49170 +
49171 + task = get_proc_task(inode);
49172 + if (task == NULL)
49173 + return rv;
49174 +
49175 + if (gr_acl_handle_procpidmem(task))
49176 + rv = -EACCES;
49177 +
49178 + put_task_struct(task);
49179 +
49180 return rv;
49181 }
49182
49183 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49184 if (!task)
49185 goto out_no_task;
49186
49187 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49188 + goto out;
49189 +
49190 /*
49191 * Yes, it does not scale. And it should not. Don't add
49192 * new entries into /proc/<tgid>/ without very good reasons.
49193 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49194 if (!task)
49195 goto out_no_task;
49196
49197 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49198 + goto out;
49199 +
49200 ret = 0;
49201 i = filp->f_pos;
49202 switch (i) {
49203 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49204 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49205 void *cookie)
49206 {
49207 - char *s = nd_get_link(nd);
49208 + const char *s = nd_get_link(nd);
49209 if (!IS_ERR(s))
49210 __putname(s);
49211 }
49212 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49213 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49214 #endif
49215 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49216 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49217 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49218 INF("syscall", S_IRUGO, proc_pid_syscall),
49219 #endif
49220 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49221 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49222 #ifdef CONFIG_SECURITY
49223 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49224 #endif
49225 -#ifdef CONFIG_KALLSYMS
49226 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49227 INF("wchan", S_IRUGO, proc_pid_wchan),
49228 #endif
49229 -#ifdef CONFIG_STACKTRACE
49230 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49231 ONE("stack", S_IRUGO, proc_pid_stack),
49232 #endif
49233 #ifdef CONFIG_SCHEDSTATS
49234 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49235 #ifdef CONFIG_HARDWALL
49236 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49237 #endif
49238 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49239 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49240 +#endif
49241 #ifdef CONFIG_USER_NS
49242 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49243 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49244 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49245 if (!inode)
49246 goto out;
49247
49248 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49249 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49250 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49251 + inode->i_gid = grsec_proc_gid;
49252 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49253 +#else
49254 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49255 +#endif
49256 inode->i_op = &proc_tgid_base_inode_operations;
49257 inode->i_fop = &proc_tgid_base_operations;
49258 inode->i_flags|=S_IMMUTABLE;
49259 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49260 if (!task)
49261 goto out;
49262
49263 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49264 + goto out_put_task;
49265 +
49266 result = proc_pid_instantiate(dir, dentry, task, NULL);
49267 +out_put_task:
49268 put_task_struct(task);
49269 out:
49270 return result;
49271 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49272 static int fake_filldir(void *buf, const char *name, int namelen,
49273 loff_t offset, u64 ino, unsigned d_type)
49274 {
49275 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49276 + __buf->error = -EINVAL;
49277 return 0;
49278 }
49279
49280 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49281 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49282 #endif
49283 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49284 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49285 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49286 INF("syscall", S_IRUGO, proc_pid_syscall),
49287 #endif
49288 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49289 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49290 #ifdef CONFIG_SECURITY
49291 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49292 #endif
49293 -#ifdef CONFIG_KALLSYMS
49294 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49295 INF("wchan", S_IRUGO, proc_pid_wchan),
49296 #endif
49297 -#ifdef CONFIG_STACKTRACE
49298 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49299 ONE("stack", S_IRUGO, proc_pid_stack),
49300 #endif
49301 #ifdef CONFIG_SCHEDSTATS
49302 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49303 index 82676e3..5f8518a 100644
49304 --- a/fs/proc/cmdline.c
49305 +++ b/fs/proc/cmdline.c
49306 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49307
49308 static int __init proc_cmdline_init(void)
49309 {
49310 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49311 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49312 +#else
49313 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49314 +#endif
49315 return 0;
49316 }
49317 module_init(proc_cmdline_init);
49318 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49319 index b143471..bb105e5 100644
49320 --- a/fs/proc/devices.c
49321 +++ b/fs/proc/devices.c
49322 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49323
49324 static int __init proc_devices_init(void)
49325 {
49326 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49327 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49328 +#else
49329 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49330 +#endif
49331 return 0;
49332 }
49333 module_init(proc_devices_init);
49334 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49335 index 7ac817b..c5c9eb0 100644
49336 --- a/fs/proc/inode.c
49337 +++ b/fs/proc/inode.c
49338 @@ -21,11 +21,17 @@
49339 #include <linux/seq_file.h>
49340 #include <linux/slab.h>
49341 #include <linux/mount.h>
49342 +#include <linux/grsecurity.h>
49343
49344 #include <asm/uaccess.h>
49345
49346 #include "internal.h"
49347
49348 +#ifdef CONFIG_PROC_SYSCTL
49349 +extern const struct inode_operations proc_sys_inode_operations;
49350 +extern const struct inode_operations proc_sys_dir_operations;
49351 +#endif
49352 +
49353 static void proc_evict_inode(struct inode *inode)
49354 {
49355 struct proc_dir_entry *de;
49356 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49357 ns_ops = PROC_I(inode)->ns_ops;
49358 if (ns_ops && ns_ops->put)
49359 ns_ops->put(PROC_I(inode)->ns);
49360 +
49361 +#ifdef CONFIG_PROC_SYSCTL
49362 + if (inode->i_op == &proc_sys_inode_operations ||
49363 + inode->i_op == &proc_sys_dir_operations)
49364 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49365 +#endif
49366 +
49367 }
49368
49369 static struct kmem_cache * proc_inode_cachep;
49370 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49371 if (de->mode) {
49372 inode->i_mode = de->mode;
49373 inode->i_uid = de->uid;
49374 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49375 + inode->i_gid = grsec_proc_gid;
49376 +#else
49377 inode->i_gid = de->gid;
49378 +#endif
49379 }
49380 if (de->size)
49381 inode->i_size = de->size;
49382 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49383 index e1167a1..bd24f20 100644
49384 --- a/fs/proc/internal.h
49385 +++ b/fs/proc/internal.h
49386 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49387 struct pid *pid, struct task_struct *task);
49388 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49389 struct pid *pid, struct task_struct *task);
49390 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49391 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49392 +#endif
49393 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49394
49395 extern const struct file_operations proc_tid_children_operations;
49396 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49397 index 86c67ee..cdca321 100644
49398 --- a/fs/proc/kcore.c
49399 +++ b/fs/proc/kcore.c
49400 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49401 * the addresses in the elf_phdr on our list.
49402 */
49403 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49404 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49405 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49406 + if (tsz > buflen)
49407 tsz = buflen;
49408 -
49409 +
49410 while (buflen) {
49411 struct kcore_list *m;
49412
49413 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49414 kfree(elf_buf);
49415 } else {
49416 if (kern_addr_valid(start)) {
49417 - unsigned long n;
49418 + char *elf_buf;
49419 + mm_segment_t oldfs;
49420
49421 - n = copy_to_user(buffer, (char *)start, tsz);
49422 - /*
49423 - * We cannot distinguish between fault on source
49424 - * and fault on destination. When this happens
49425 - * we clear too and hope it will trigger the
49426 - * EFAULT again.
49427 - */
49428 - if (n) {
49429 - if (clear_user(buffer + tsz - n,
49430 - n))
49431 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49432 + if (!elf_buf)
49433 + return -ENOMEM;
49434 + oldfs = get_fs();
49435 + set_fs(KERNEL_DS);
49436 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49437 + set_fs(oldfs);
49438 + if (copy_to_user(buffer, elf_buf, tsz)) {
49439 + kfree(elf_buf);
49440 return -EFAULT;
49441 + }
49442 }
49443 + set_fs(oldfs);
49444 + kfree(elf_buf);
49445 } else {
49446 if (clear_user(buffer, tsz))
49447 return -EFAULT;
49448 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49449
49450 static int open_kcore(struct inode *inode, struct file *filp)
49451 {
49452 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49453 + return -EPERM;
49454 +#endif
49455 if (!capable(CAP_SYS_RAWIO))
49456 return -EPERM;
49457 if (kcore_need_update)
49458 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49459 index 80e4645..53e5fcf 100644
49460 --- a/fs/proc/meminfo.c
49461 +++ b/fs/proc/meminfo.c
49462 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49463 vmi.used >> 10,
49464 vmi.largest_chunk >> 10
49465 #ifdef CONFIG_MEMORY_FAILURE
49466 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49467 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49468 #endif
49469 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49470 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49471 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49472 index b1822dd..df622cb 100644
49473 --- a/fs/proc/nommu.c
49474 +++ b/fs/proc/nommu.c
49475 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49476 if (len < 1)
49477 len = 1;
49478 seq_printf(m, "%*c", len, ' ');
49479 - seq_path(m, &file->f_path, "");
49480 + seq_path(m, &file->f_path, "\n\\");
49481 }
49482
49483 seq_putc(m, '\n');
49484 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49485 index fe72cd0..cb9b67d 100644
49486 --- a/fs/proc/proc_net.c
49487 +++ b/fs/proc/proc_net.c
49488 @@ -23,6 +23,7 @@
49489 #include <linux/nsproxy.h>
49490 #include <net/net_namespace.h>
49491 #include <linux/seq_file.h>
49492 +#include <linux/grsecurity.h>
49493
49494 #include "internal.h"
49495
49496 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49497 struct task_struct *task;
49498 struct nsproxy *ns;
49499 struct net *net = NULL;
49500 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49501 + const struct cred *cred = current_cred();
49502 +#endif
49503 +
49504 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49505 + if (cred->fsuid)
49506 + return net;
49507 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49508 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49509 + return net;
49510 +#endif
49511
49512 rcu_read_lock();
49513 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49514 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49515 index eb7cc91..7327a46 100644
49516 --- a/fs/proc/proc_sysctl.c
49517 +++ b/fs/proc/proc_sysctl.c
49518 @@ -12,11 +12,15 @@
49519 #include <linux/module.h>
49520 #include "internal.h"
49521
49522 +extern int gr_handle_chroot_sysctl(const int op);
49523 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49524 + const int op);
49525 +
49526 static const struct dentry_operations proc_sys_dentry_operations;
49527 static const struct file_operations proc_sys_file_operations;
49528 -static const struct inode_operations proc_sys_inode_operations;
49529 +const struct inode_operations proc_sys_inode_operations;
49530 static const struct file_operations proc_sys_dir_file_operations;
49531 -static const struct inode_operations proc_sys_dir_operations;
49532 +const struct inode_operations proc_sys_dir_operations;
49533
49534 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49535 {
49536 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49537
49538 err = NULL;
49539 d_set_d_op(dentry, &proc_sys_dentry_operations);
49540 +
49541 + gr_handle_proc_create(dentry, inode);
49542 +
49543 d_add(dentry, inode);
49544
49545 out:
49546 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49547 struct inode *inode = filp->f_path.dentry->d_inode;
49548 struct ctl_table_header *head = grab_header(inode);
49549 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49550 + int op = write ? MAY_WRITE : MAY_READ;
49551 ssize_t error;
49552 size_t res;
49553
49554 if (IS_ERR(head))
49555 return PTR_ERR(head);
49556
49557 +
49558 /*
49559 * At this point we know that the sysctl was not unregistered
49560 * and won't be until we finish.
49561 */
49562 error = -EPERM;
49563 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49564 + if (sysctl_perm(head->root, table, op))
49565 goto out;
49566
49567 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49568 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49569 if (!table->proc_handler)
49570 goto out;
49571
49572 +#ifdef CONFIG_GRKERNSEC
49573 + error = -EPERM;
49574 + if (gr_handle_chroot_sysctl(op))
49575 + goto out;
49576 + dget(filp->f_path.dentry);
49577 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49578 + dput(filp->f_path.dentry);
49579 + goto out;
49580 + }
49581 + dput(filp->f_path.dentry);
49582 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49583 + goto out;
49584 + if (write && !capable(CAP_SYS_ADMIN))
49585 + goto out;
49586 +#endif
49587 +
49588 /* careful: calling conventions are nasty here */
49589 res = count;
49590 error = table->proc_handler(table, write, buf, &res, ppos);
49591 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49592 return -ENOMEM;
49593 } else {
49594 d_set_d_op(child, &proc_sys_dentry_operations);
49595 +
49596 + gr_handle_proc_create(child, inode);
49597 +
49598 d_add(child, inode);
49599 }
49600 } else {
49601 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49602 if ((*pos)++ < file->f_pos)
49603 return 0;
49604
49605 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49606 + return 0;
49607 +
49608 if (unlikely(S_ISLNK(table->mode)))
49609 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49610 else
49611 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49612 if (IS_ERR(head))
49613 return PTR_ERR(head);
49614
49615 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49616 + return -ENOENT;
49617 +
49618 generic_fillattr(inode, stat);
49619 if (table)
49620 stat->mode = (stat->mode & S_IFMT) | table->mode;
49621 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49622 .llseek = generic_file_llseek,
49623 };
49624
49625 -static const struct inode_operations proc_sys_inode_operations = {
49626 +const struct inode_operations proc_sys_inode_operations = {
49627 .permission = proc_sys_permission,
49628 .setattr = proc_sys_setattr,
49629 .getattr = proc_sys_getattr,
49630 };
49631
49632 -static const struct inode_operations proc_sys_dir_operations = {
49633 +const struct inode_operations proc_sys_dir_operations = {
49634 .lookup = proc_sys_lookup,
49635 .permission = proc_sys_permission,
49636 .setattr = proc_sys_setattr,
49637 diff --git a/fs/proc/root.c b/fs/proc/root.c
49638 index 9a2d9fd..ddfc92a 100644
49639 --- a/fs/proc/root.c
49640 +++ b/fs/proc/root.c
49641 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49642 #ifdef CONFIG_PROC_DEVICETREE
49643 proc_device_tree_init();
49644 #endif
49645 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49646 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49647 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49648 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49649 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49650 +#endif
49651 +#else
49652 proc_mkdir("bus", NULL);
49653 +#endif
49654 proc_sys_init();
49655 }
49656
49657 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49658 index 4540b8f..1b9772f 100644
49659 --- a/fs/proc/task_mmu.c
49660 +++ b/fs/proc/task_mmu.c
49661 @@ -11,12 +11,19 @@
49662 #include <linux/rmap.h>
49663 #include <linux/swap.h>
49664 #include <linux/swapops.h>
49665 +#include <linux/grsecurity.h>
49666
49667 #include <asm/elf.h>
49668 #include <asm/uaccess.h>
49669 #include <asm/tlbflush.h>
49670 #include "internal.h"
49671
49672 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49673 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49674 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49675 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49676 +#endif
49677 +
49678 void task_mem(struct seq_file *m, struct mm_struct *mm)
49679 {
49680 unsigned long data, text, lib, swap;
49681 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49682 "VmExe:\t%8lu kB\n"
49683 "VmLib:\t%8lu kB\n"
49684 "VmPTE:\t%8lu kB\n"
49685 - "VmSwap:\t%8lu kB\n",
49686 - hiwater_vm << (PAGE_SHIFT-10),
49687 + "VmSwap:\t%8lu kB\n"
49688 +
49689 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49690 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49691 +#endif
49692 +
49693 + ,hiwater_vm << (PAGE_SHIFT-10),
49694 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49695 mm->locked_vm << (PAGE_SHIFT-10),
49696 mm->pinned_vm << (PAGE_SHIFT-10),
49697 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49698 data << (PAGE_SHIFT-10),
49699 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49700 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49701 - swap << (PAGE_SHIFT-10));
49702 + swap << (PAGE_SHIFT-10)
49703 +
49704 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49705 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49706 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49707 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49708 +#else
49709 + , mm->context.user_cs_base
49710 + , mm->context.user_cs_limit
49711 +#endif
49712 +#endif
49713 +
49714 + );
49715 }
49716
49717 unsigned long task_vsize(struct mm_struct *mm)
49718 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49719 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49720 }
49721
49722 - /* We don't show the stack guard page in /proc/maps */
49723 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49724 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49725 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49726 +#else
49727 start = vma->vm_start;
49728 - if (stack_guard_page_start(vma, start))
49729 - start += PAGE_SIZE;
49730 end = vma->vm_end;
49731 - if (stack_guard_page_end(vma, end))
49732 - end -= PAGE_SIZE;
49733 +#endif
49734
49735 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49736 start,
49737 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49738 flags & VM_WRITE ? 'w' : '-',
49739 flags & VM_EXEC ? 'x' : '-',
49740 flags & VM_MAYSHARE ? 's' : 'p',
49741 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49742 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49743 +#else
49744 pgoff,
49745 +#endif
49746 MAJOR(dev), MINOR(dev), ino, &len);
49747
49748 /*
49749 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49750 */
49751 if (file) {
49752 pad_len_spaces(m, len);
49753 - seq_path(m, &file->f_path, "\n");
49754 + seq_path(m, &file->f_path, "\n\\");
49755 goto done;
49756 }
49757
49758 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49759 * Thread stack in /proc/PID/task/TID/maps or
49760 * the main process stack.
49761 */
49762 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49763 - vma->vm_end >= mm->start_stack)) {
49764 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49765 + (vma->vm_start <= mm->start_stack &&
49766 + vma->vm_end >= mm->start_stack)) {
49767 name = "[stack]";
49768 } else {
49769 /* Thread stack in /proc/PID/maps */
49770 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49771 struct proc_maps_private *priv = m->private;
49772 struct task_struct *task = priv->task;
49773
49774 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49775 + if (current->exec_id != m->exec_id) {
49776 + gr_log_badprocpid("maps");
49777 + return 0;
49778 + }
49779 +#endif
49780 +
49781 show_map_vma(m, vma, is_pid);
49782
49783 if (m->count < m->size) /* vma is copied successfully */
49784 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49785 .private = &mss,
49786 };
49787
49788 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49789 + if (current->exec_id != m->exec_id) {
49790 + gr_log_badprocpid("smaps");
49791 + return 0;
49792 + }
49793 +#endif
49794 memset(&mss, 0, sizeof mss);
49795 - mss.vma = vma;
49796 - /* mmap_sem is held in m_start */
49797 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49798 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49799 -
49800 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49801 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49802 +#endif
49803 + mss.vma = vma;
49804 + /* mmap_sem is held in m_start */
49805 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49806 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49807 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49808 + }
49809 +#endif
49810 show_map_vma(m, vma, is_pid);
49811
49812 seq_printf(m,
49813 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49814 "KernelPageSize: %8lu kB\n"
49815 "MMUPageSize: %8lu kB\n"
49816 "Locked: %8lu kB\n",
49817 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49818 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49819 +#else
49820 (vma->vm_end - vma->vm_start) >> 10,
49821 +#endif
49822 mss.resident >> 10,
49823 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49824 mss.shared_clean >> 10,
49825 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49826 int n;
49827 char buffer[50];
49828
49829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49830 + if (current->exec_id != m->exec_id) {
49831 + gr_log_badprocpid("numa_maps");
49832 + return 0;
49833 + }
49834 +#endif
49835 +
49836 if (!mm)
49837 return 0;
49838
49839 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49840 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49841 mpol_cond_put(pol);
49842
49843 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49844 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49845 +#else
49846 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49847 +#endif
49848
49849 if (file) {
49850 seq_printf(m, " file=");
49851 - seq_path(m, &file->f_path, "\n\t= ");
49852 + seq_path(m, &file->f_path, "\n\t\\= ");
49853 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49854 seq_printf(m, " heap");
49855 } else {
49856 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49857 index 1ccfa53..0848f95 100644
49858 --- a/fs/proc/task_nommu.c
49859 +++ b/fs/proc/task_nommu.c
49860 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49861 else
49862 bytes += kobjsize(mm);
49863
49864 - if (current->fs && current->fs->users > 1)
49865 + if (current->fs && atomic_read(&current->fs->users) > 1)
49866 sbytes += kobjsize(current->fs);
49867 else
49868 bytes += kobjsize(current->fs);
49869 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49870
49871 if (file) {
49872 pad_len_spaces(m, len);
49873 - seq_path(m, &file->f_path, "");
49874 + seq_path(m, &file->f_path, "\n\\");
49875 } else if (mm) {
49876 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49877
49878 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49879 index d67908b..d13f6a6 100644
49880 --- a/fs/quota/netlink.c
49881 +++ b/fs/quota/netlink.c
49882 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49883 void quota_send_warning(short type, unsigned int id, dev_t dev,
49884 const char warntype)
49885 {
49886 - static atomic_t seq;
49887 + static atomic_unchecked_t seq;
49888 struct sk_buff *skb;
49889 void *msg_head;
49890 int ret;
49891 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49892 "VFS: Not enough memory to send quota warning.\n");
49893 return;
49894 }
49895 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49896 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49897 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49898 if (!msg_head) {
49899 printk(KERN_ERR
49900 diff --git a/fs/readdir.c b/fs/readdir.c
49901 index 39e3370..20d446d 100644
49902 --- a/fs/readdir.c
49903 +++ b/fs/readdir.c
49904 @@ -17,6 +17,7 @@
49905 #include <linux/security.h>
49906 #include <linux/syscalls.h>
49907 #include <linux/unistd.h>
49908 +#include <linux/namei.h>
49909
49910 #include <asm/uaccess.h>
49911
49912 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49913
49914 struct readdir_callback {
49915 struct old_linux_dirent __user * dirent;
49916 + struct file * file;
49917 int result;
49918 };
49919
49920 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49921 buf->result = -EOVERFLOW;
49922 return -EOVERFLOW;
49923 }
49924 +
49925 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49926 + return 0;
49927 +
49928 buf->result++;
49929 dirent = buf->dirent;
49930 if (!access_ok(VERIFY_WRITE, dirent,
49931 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49932
49933 buf.result = 0;
49934 buf.dirent = dirent;
49935 + buf.file = file;
49936
49937 error = vfs_readdir(file, fillonedir, &buf);
49938 if (buf.result)
49939 @@ -141,6 +148,7 @@ struct linux_dirent {
49940 struct getdents_callback {
49941 struct linux_dirent __user * current_dir;
49942 struct linux_dirent __user * previous;
49943 + struct file * file;
49944 int count;
49945 int error;
49946 };
49947 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49948 buf->error = -EOVERFLOW;
49949 return -EOVERFLOW;
49950 }
49951 +
49952 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49953 + return 0;
49954 +
49955 dirent = buf->previous;
49956 if (dirent) {
49957 if (__put_user(offset, &dirent->d_off))
49958 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49959 buf.previous = NULL;
49960 buf.count = count;
49961 buf.error = 0;
49962 + buf.file = file;
49963
49964 error = vfs_readdir(file, filldir, &buf);
49965 if (error >= 0)
49966 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49967 struct getdents_callback64 {
49968 struct linux_dirent64 __user * current_dir;
49969 struct linux_dirent64 __user * previous;
49970 + struct file *file;
49971 int count;
49972 int error;
49973 };
49974 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49975 buf->error = -EINVAL; /* only used if we fail.. */
49976 if (reclen > buf->count)
49977 return -EINVAL;
49978 +
49979 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49980 + return 0;
49981 +
49982 dirent = buf->previous;
49983 if (dirent) {
49984 if (__put_user(offset, &dirent->d_off))
49985 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49986
49987 buf.current_dir = dirent;
49988 buf.previous = NULL;
49989 + buf.file = file;
49990 buf.count = count;
49991 buf.error = 0;
49992
49993 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49994 error = buf.error;
49995 lastdirent = buf.previous;
49996 if (lastdirent) {
49997 - typeof(lastdirent->d_off) d_off = file->f_pos;
49998 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49999 if (__put_user(d_off, &lastdirent->d_off))
50000 error = -EFAULT;
50001 else
50002 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50003 index 2b7882b..1c5ef48 100644
50004 --- a/fs/reiserfs/do_balan.c
50005 +++ b/fs/reiserfs/do_balan.c
50006 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50007 return;
50008 }
50009
50010 - atomic_inc(&(fs_generation(tb->tb_sb)));
50011 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50012 do_balance_starts(tb);
50013
50014 /* balance leaf returns 0 except if combining L R and S into
50015 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50016 index e60e870..f40ac16 100644
50017 --- a/fs/reiserfs/procfs.c
50018 +++ b/fs/reiserfs/procfs.c
50019 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50020 "SMALL_TAILS " : "NO_TAILS ",
50021 replay_only(sb) ? "REPLAY_ONLY " : "",
50022 convert_reiserfs(sb) ? "CONV " : "",
50023 - atomic_read(&r->s_generation_counter),
50024 + atomic_read_unchecked(&r->s_generation_counter),
50025 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50026 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50027 SF(s_good_search_by_key_reada), SF(s_bmaps),
50028 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50029 index 33215f5..c5d427a 100644
50030 --- a/fs/reiserfs/reiserfs.h
50031 +++ b/fs/reiserfs/reiserfs.h
50032 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50033 /* Comment? -Hans */
50034 wait_queue_head_t s_wait;
50035 /* To be obsoleted soon by per buffer seals.. -Hans */
50036 - atomic_t s_generation_counter; // increased by one every time the
50037 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50038 // tree gets re-balanced
50039 unsigned long s_properties; /* File system properties. Currently holds
50040 on-disk FS format */
50041 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50042 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50043
50044 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50045 -#define get_generation(s) atomic_read (&fs_generation(s))
50046 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50047 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50048 #define __fs_changed(gen,s) (gen != get_generation (s))
50049 #define fs_changed(gen,s) \
50050 diff --git a/fs/select.c b/fs/select.c
50051 index db14c78..3aae1bd 100644
50052 --- a/fs/select.c
50053 +++ b/fs/select.c
50054 @@ -20,6 +20,7 @@
50055 #include <linux/export.h>
50056 #include <linux/slab.h>
50057 #include <linux/poll.h>
50058 +#include <linux/security.h>
50059 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50060 #include <linux/file.h>
50061 #include <linux/fdtable.h>
50062 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50063 struct poll_list *walk = head;
50064 unsigned long todo = nfds;
50065
50066 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50067 if (nfds > rlimit(RLIMIT_NOFILE))
50068 return -EINVAL;
50069
50070 diff --git a/fs/seq_file.c b/fs/seq_file.c
50071 index 14cf9de..adc4d5b 100644
50072 --- a/fs/seq_file.c
50073 +++ b/fs/seq_file.c
50074 @@ -9,6 +9,7 @@
50075 #include <linux/export.h>
50076 #include <linux/seq_file.h>
50077 #include <linux/slab.h>
50078 +#include <linux/sched.h>
50079
50080 #include <asm/uaccess.h>
50081 #include <asm/page.h>
50082 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50083 memset(p, 0, sizeof(*p));
50084 mutex_init(&p->lock);
50085 p->op = op;
50086 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50087 + p->exec_id = current->exec_id;
50088 +#endif
50089
50090 /*
50091 * Wrappers around seq_open(e.g. swaps_open) need to be
50092 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50093 return 0;
50094 }
50095 if (!m->buf) {
50096 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50097 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50098 if (!m->buf)
50099 return -ENOMEM;
50100 }
50101 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50102 Eoverflow:
50103 m->op->stop(m, p);
50104 kfree(m->buf);
50105 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50106 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50107 return !m->buf ? -ENOMEM : -EAGAIN;
50108 }
50109
50110 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50111
50112 /* grab buffer if we didn't have one */
50113 if (!m->buf) {
50114 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50115 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50116 if (!m->buf)
50117 goto Enomem;
50118 }
50119 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50120 goto Fill;
50121 m->op->stop(m, p);
50122 kfree(m->buf);
50123 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50124 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50125 if (!m->buf)
50126 goto Enomem;
50127 m->count = 0;
50128 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50129 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50130 void *data)
50131 {
50132 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50133 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50134 int res = -ENOMEM;
50135
50136 if (op) {
50137 diff --git a/fs/splice.c b/fs/splice.c
50138 index 41514dd..6564a93 100644
50139 --- a/fs/splice.c
50140 +++ b/fs/splice.c
50141 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50142 pipe_lock(pipe);
50143
50144 for (;;) {
50145 - if (!pipe->readers) {
50146 + if (!atomic_read(&pipe->readers)) {
50147 send_sig(SIGPIPE, current, 0);
50148 if (!ret)
50149 ret = -EPIPE;
50150 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50151 do_wakeup = 0;
50152 }
50153
50154 - pipe->waiting_writers++;
50155 + atomic_inc(&pipe->waiting_writers);
50156 pipe_wait(pipe);
50157 - pipe->waiting_writers--;
50158 + atomic_dec(&pipe->waiting_writers);
50159 }
50160
50161 pipe_unlock(pipe);
50162 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50163 old_fs = get_fs();
50164 set_fs(get_ds());
50165 /* The cast to a user pointer is valid due to the set_fs() */
50166 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50167 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50168 set_fs(old_fs);
50169
50170 return res;
50171 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50172 old_fs = get_fs();
50173 set_fs(get_ds());
50174 /* The cast to a user pointer is valid due to the set_fs() */
50175 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50176 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50177 set_fs(old_fs);
50178
50179 return res;
50180 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50181 goto err;
50182
50183 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50184 - vec[i].iov_base = (void __user *) page_address(page);
50185 + vec[i].iov_base = (void __force_user *) page_address(page);
50186 vec[i].iov_len = this_len;
50187 spd.pages[i] = page;
50188 spd.nr_pages++;
50189 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50190 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50191 {
50192 while (!pipe->nrbufs) {
50193 - if (!pipe->writers)
50194 + if (!atomic_read(&pipe->writers))
50195 return 0;
50196
50197 - if (!pipe->waiting_writers && sd->num_spliced)
50198 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50199 return 0;
50200
50201 if (sd->flags & SPLICE_F_NONBLOCK)
50202 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50203 * out of the pipe right after the splice_to_pipe(). So set
50204 * PIPE_READERS appropriately.
50205 */
50206 - pipe->readers = 1;
50207 + atomic_set(&pipe->readers, 1);
50208
50209 current->splice_pipe = pipe;
50210 }
50211 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50212 ret = -ERESTARTSYS;
50213 break;
50214 }
50215 - if (!pipe->writers)
50216 + if (!atomic_read(&pipe->writers))
50217 break;
50218 - if (!pipe->waiting_writers) {
50219 + if (!atomic_read(&pipe->waiting_writers)) {
50220 if (flags & SPLICE_F_NONBLOCK) {
50221 ret = -EAGAIN;
50222 break;
50223 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50224 pipe_lock(pipe);
50225
50226 while (pipe->nrbufs >= pipe->buffers) {
50227 - if (!pipe->readers) {
50228 + if (!atomic_read(&pipe->readers)) {
50229 send_sig(SIGPIPE, current, 0);
50230 ret = -EPIPE;
50231 break;
50232 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50233 ret = -ERESTARTSYS;
50234 break;
50235 }
50236 - pipe->waiting_writers++;
50237 + atomic_inc(&pipe->waiting_writers);
50238 pipe_wait(pipe);
50239 - pipe->waiting_writers--;
50240 + atomic_dec(&pipe->waiting_writers);
50241 }
50242
50243 pipe_unlock(pipe);
50244 @@ -1828,14 +1828,14 @@ retry:
50245 pipe_double_lock(ipipe, opipe);
50246
50247 do {
50248 - if (!opipe->readers) {
50249 + if (!atomic_read(&opipe->readers)) {
50250 send_sig(SIGPIPE, current, 0);
50251 if (!ret)
50252 ret = -EPIPE;
50253 break;
50254 }
50255
50256 - if (!ipipe->nrbufs && !ipipe->writers)
50257 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50258 break;
50259
50260 /*
50261 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50262 pipe_double_lock(ipipe, opipe);
50263
50264 do {
50265 - if (!opipe->readers) {
50266 + if (!atomic_read(&opipe->readers)) {
50267 send_sig(SIGPIPE, current, 0);
50268 if (!ret)
50269 ret = -EPIPE;
50270 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50271 * return EAGAIN if we have the potential of some data in the
50272 * future, otherwise just return 0
50273 */
50274 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50275 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50276 ret = -EAGAIN;
50277
50278 pipe_unlock(ipipe);
50279 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50280 index 6b0bb00..75db2fe 100644
50281 --- a/fs/sysfs/dir.c
50282 +++ b/fs/sysfs/dir.c
50283 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50284 struct sysfs_dirent *sd;
50285 int rc;
50286
50287 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50288 + const char *parent_name = parent_sd->s_name;
50289 +
50290 + mode = S_IFDIR | S_IRWXU;
50291 +
50292 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50293 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50294 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50295 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50296 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50297 +#endif
50298 +
50299 /* allocate */
50300 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50301 if (!sd)
50302 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50303 index 00012e3..8392349 100644
50304 --- a/fs/sysfs/file.c
50305 +++ b/fs/sysfs/file.c
50306 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50307
50308 struct sysfs_open_dirent {
50309 atomic_t refcnt;
50310 - atomic_t event;
50311 + atomic_unchecked_t event;
50312 wait_queue_head_t poll;
50313 struct list_head buffers; /* goes through sysfs_buffer.list */
50314 };
50315 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50316 if (!sysfs_get_active(attr_sd))
50317 return -ENODEV;
50318
50319 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50320 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50321 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50322
50323 sysfs_put_active(attr_sd);
50324 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50325 return -ENOMEM;
50326
50327 atomic_set(&new_od->refcnt, 0);
50328 - atomic_set(&new_od->event, 1);
50329 + atomic_set_unchecked(&new_od->event, 1);
50330 init_waitqueue_head(&new_od->poll);
50331 INIT_LIST_HEAD(&new_od->buffers);
50332 goto retry;
50333 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50334
50335 sysfs_put_active(attr_sd);
50336
50337 - if (buffer->event != atomic_read(&od->event))
50338 + if (buffer->event != atomic_read_unchecked(&od->event))
50339 goto trigger;
50340
50341 return DEFAULT_POLLMASK;
50342 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50343
50344 od = sd->s_attr.open;
50345 if (od) {
50346 - atomic_inc(&od->event);
50347 + atomic_inc_unchecked(&od->event);
50348 wake_up_interruptible(&od->poll);
50349 }
50350
50351 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50352 index a7ac78f..02158e1 100644
50353 --- a/fs/sysfs/symlink.c
50354 +++ b/fs/sysfs/symlink.c
50355 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50356
50357 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50358 {
50359 - char *page = nd_get_link(nd);
50360 + const char *page = nd_get_link(nd);
50361 if (!IS_ERR(page))
50362 free_page((unsigned long)page);
50363 }
50364 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50365 index c175b4d..8f36a16 100644
50366 --- a/fs/udf/misc.c
50367 +++ b/fs/udf/misc.c
50368 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50369
50370 u8 udf_tag_checksum(const struct tag *t)
50371 {
50372 - u8 *data = (u8 *)t;
50373 + const u8 *data = (const u8 *)t;
50374 u8 checksum = 0;
50375 int i;
50376 for (i = 0; i < sizeof(struct tag); ++i)
50377 diff --git a/fs/utimes.c b/fs/utimes.c
50378 index fa4dbe4..e12d1b9 100644
50379 --- a/fs/utimes.c
50380 +++ b/fs/utimes.c
50381 @@ -1,6 +1,7 @@
50382 #include <linux/compiler.h>
50383 #include <linux/file.h>
50384 #include <linux/fs.h>
50385 +#include <linux/security.h>
50386 #include <linux/linkage.h>
50387 #include <linux/mount.h>
50388 #include <linux/namei.h>
50389 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50390 goto mnt_drop_write_and_out;
50391 }
50392 }
50393 +
50394 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50395 + error = -EACCES;
50396 + goto mnt_drop_write_and_out;
50397 + }
50398 +
50399 mutex_lock(&inode->i_mutex);
50400 error = notify_change(path->dentry, &newattrs);
50401 mutex_unlock(&inode->i_mutex);
50402 diff --git a/fs/xattr.c b/fs/xattr.c
50403 index 4d45b71..2ec08e10 100644
50404 --- a/fs/xattr.c
50405 +++ b/fs/xattr.c
50406 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50407 * Extended attribute SET operations
50408 */
50409 static long
50410 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50411 +setxattr(struct path *path, const char __user *name, const void __user *value,
50412 size_t size, int flags)
50413 {
50414 int error;
50415 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50416 }
50417 }
50418
50419 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50420 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50421 + error = -EACCES;
50422 + goto out;
50423 + }
50424 +
50425 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50426 out:
50427 if (vvalue)
50428 vfree(vvalue);
50429 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50430 return error;
50431 error = mnt_want_write(path.mnt);
50432 if (!error) {
50433 - error = setxattr(path.dentry, name, value, size, flags);
50434 + error = setxattr(&path, name, value, size, flags);
50435 mnt_drop_write(path.mnt);
50436 }
50437 path_put(&path);
50438 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50439 return error;
50440 error = mnt_want_write(path.mnt);
50441 if (!error) {
50442 - error = setxattr(path.dentry, name, value, size, flags);
50443 + error = setxattr(&path, name, value, size, flags);
50444 mnt_drop_write(path.mnt);
50445 }
50446 path_put(&path);
50447 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50448 {
50449 int fput_needed;
50450 struct file *f;
50451 - struct dentry *dentry;
50452 int error = -EBADF;
50453
50454 f = fget_light(fd, &fput_needed);
50455 if (!f)
50456 return error;
50457 - dentry = f->f_path.dentry;
50458 - audit_inode(NULL, dentry);
50459 + audit_inode(NULL, f->f_path.dentry);
50460 error = mnt_want_write_file(f);
50461 if (!error) {
50462 - error = setxattr(dentry, name, value, size, flags);
50463 + error = setxattr(&f->f_path, name, value, size, flags);
50464 mnt_drop_write_file(f);
50465 }
50466 fput_light(f, fput_needed);
50467 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50468 index 69d06b0..c0996e5 100644
50469 --- a/fs/xattr_acl.c
50470 +++ b/fs/xattr_acl.c
50471 @@ -17,8 +17,8 @@
50472 struct posix_acl *
50473 posix_acl_from_xattr(const void *value, size_t size)
50474 {
50475 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50476 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50477 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50478 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50479 int count;
50480 struct posix_acl *acl;
50481 struct posix_acl_entry *acl_e;
50482 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50483 index 848ffa7..1f249bf 100644
50484 --- a/fs/xfs/xfs_bmap.c
50485 +++ b/fs/xfs/xfs_bmap.c
50486 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50487 int nmap,
50488 int ret_nmap);
50489 #else
50490 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50491 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50492 #endif /* DEBUG */
50493
50494 STATIC int
50495 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50496 index 1b9fc3e..e1bdde0 100644
50497 --- a/fs/xfs/xfs_dir2_sf.c
50498 +++ b/fs/xfs/xfs_dir2_sf.c
50499 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50500 }
50501
50502 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50503 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50504 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50505 + char name[sfep->namelen];
50506 + memcpy(name, sfep->name, sfep->namelen);
50507 + if (filldir(dirent, name, sfep->namelen,
50508 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50509 + *offset = off & 0x7fffffff;
50510 + return 0;
50511 + }
50512 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50513 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50514 *offset = off & 0x7fffffff;
50515 return 0;
50516 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50517 index 0e0232c..fa5c3fe 100644
50518 --- a/fs/xfs/xfs_ioctl.c
50519 +++ b/fs/xfs/xfs_ioctl.c
50520 @@ -126,7 +126,7 @@ xfs_find_handle(
50521 }
50522
50523 error = -EFAULT;
50524 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50525 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50526 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50527 goto out_put;
50528
50529 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50530 index 4e00cf0..3374374 100644
50531 --- a/fs/xfs/xfs_iops.c
50532 +++ b/fs/xfs/xfs_iops.c
50533 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50534 struct nameidata *nd,
50535 void *p)
50536 {
50537 - char *s = nd_get_link(nd);
50538 + const char *s = nd_get_link(nd);
50539
50540 if (!IS_ERR(s))
50541 kfree(s);
50542 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50543 new file mode 100644
50544 index 0000000..d38b430
50545 --- /dev/null
50546 +++ b/grsecurity/Kconfig
50547 @@ -0,0 +1,947 @@
50548 +#
50549 +# grecurity configuration
50550 +#
50551 +menu "Memory Protections"
50552 +depends on GRKERNSEC
50553 +
50554 +config GRKERNSEC_KMEM
50555 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50556 + default y if GRKERNSEC_CONFIG_AUTO
50557 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50558 + help
50559 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50560 + be written to or read from to modify or leak the contents of the running
50561 + kernel. /dev/port will also not be allowed to be opened. If you have module
50562 + support disabled, enabling this will close up four ways that are
50563 + currently used to insert malicious code into the running kernel.
50564 + Even with all these features enabled, we still highly recommend that
50565 + you use the RBAC system, as it is still possible for an attacker to
50566 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50567 + If you are not using XFree86, you may be able to stop this additional
50568 + case by enabling the 'Disable privileged I/O' option. Though nothing
50569 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50570 + but only to video memory, which is the only writing we allow in this
50571 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50572 + not be allowed to mprotect it with PROT_WRITE later.
50573 + It is highly recommended that you say Y here if you meet all the
50574 + conditions above.
50575 +
50576 +config GRKERNSEC_VM86
50577 + bool "Restrict VM86 mode"
50578 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50579 + depends on X86_32
50580 +
50581 + help
50582 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50583 + make use of a special execution mode on 32bit x86 processors called
50584 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50585 + video cards and will still work with this option enabled. The purpose
50586 + of the option is to prevent exploitation of emulation errors in
50587 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50588 + Nearly all users should be able to enable this option.
50589 +
50590 +config GRKERNSEC_IO
50591 + bool "Disable privileged I/O"
50592 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50593 + depends on X86
50594 + select RTC_CLASS
50595 + select RTC_INTF_DEV
50596 + select RTC_DRV_CMOS
50597 +
50598 + help
50599 + If you say Y here, all ioperm and iopl calls will return an error.
50600 + Ioperm and iopl can be used to modify the running kernel.
50601 + Unfortunately, some programs need this access to operate properly,
50602 + the most notable of which are XFree86 and hwclock. hwclock can be
50603 + remedied by having RTC support in the kernel, so real-time
50604 + clock support is enabled if this option is enabled, to ensure
50605 + that hwclock operates correctly. XFree86 still will not
50606 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50607 + IF YOU USE XFree86. If you use XFree86 and you still want to
50608 + protect your kernel against modification, use the RBAC system.
50609 +
50610 +config GRKERNSEC_PROC_MEMMAP
50611 + bool "Harden ASLR against information leaks and entropy reduction"
50612 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50613 + depends on PAX_NOEXEC || PAX_ASLR
50614 + help
50615 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50616 + give no information about the addresses of its mappings if
50617 + PaX features that rely on random addresses are enabled on the task.
50618 + In addition to sanitizing this information and disabling other
50619 + dangerous sources of information, this option causes reads of sensitive
50620 + /proc/<pid> entries where the file descriptor was opened in a different
50621 + task than the one performing the read. Such attempts are logged.
50622 + This option also limits argv/env strings for suid/sgid binaries
50623 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50624 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50625 + binaries to prevent alternative mmap layouts from being abused.
50626 +
50627 + If you use PaX it is essential that you say Y here as it closes up
50628 + several holes that make full ASLR useless locally.
50629 +
50630 +config GRKERNSEC_BRUTE
50631 + bool "Deter exploit bruteforcing"
50632 + default y if GRKERNSEC_CONFIG_AUTO
50633 + help
50634 + If you say Y here, attempts to bruteforce exploits against forking
50635 + daemons such as apache or sshd, as well as against suid/sgid binaries
50636 + will be deterred. When a child of a forking daemon is killed by PaX
50637 + or crashes due to an illegal instruction or other suspicious signal,
50638 + the parent process will be delayed 30 seconds upon every subsequent
50639 + fork until the administrator is able to assess the situation and
50640 + restart the daemon.
50641 + In the suid/sgid case, the attempt is logged, the user has all their
50642 + processes terminated, and they are prevented from executing any further
50643 + processes for 15 minutes.
50644 + It is recommended that you also enable signal logging in the auditing
50645 + section so that logs are generated when a process triggers a suspicious
50646 + signal.
50647 + If the sysctl option is enabled, a sysctl option with name
50648 + "deter_bruteforce" is created.
50649 +
50650 +
50651 +config GRKERNSEC_MODHARDEN
50652 + bool "Harden module auto-loading"
50653 + default y if GRKERNSEC_CONFIG_AUTO
50654 + depends on MODULES
50655 + help
50656 + If you say Y here, module auto-loading in response to use of some
50657 + feature implemented by an unloaded module will be restricted to
50658 + root users. Enabling this option helps defend against attacks
50659 + by unprivileged users who abuse the auto-loading behavior to
50660 + cause a vulnerable module to load that is then exploited.
50661 +
50662 + If this option prevents a legitimate use of auto-loading for a
50663 + non-root user, the administrator can execute modprobe manually
50664 + with the exact name of the module mentioned in the alert log.
50665 + Alternatively, the administrator can add the module to the list
50666 + of modules loaded at boot by modifying init scripts.
50667 +
50668 + Modification of init scripts will most likely be needed on
50669 + Ubuntu servers with encrypted home directory support enabled,
50670 + as the first non-root user logging in will cause the ecb(aes),
50671 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50672 +
50673 +config GRKERNSEC_HIDESYM
50674 + bool "Hide kernel symbols"
50675 + default y if GRKERNSEC_CONFIG_AUTO
50676 + select PAX_USERCOPY_SLABS
50677 + help
50678 + If you say Y here, getting information on loaded modules, and
50679 + displaying all kernel symbols through a syscall will be restricted
50680 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50681 + /proc/kallsyms will be restricted to the root user. The RBAC
50682 + system can hide that entry even from root.
50683 +
50684 + This option also prevents leaking of kernel addresses through
50685 + several /proc entries.
50686 +
50687 + Note that this option is only effective provided the following
50688 + conditions are met:
50689 + 1) The kernel using grsecurity is not precompiled by some distribution
50690 + 2) You have also enabled GRKERNSEC_DMESG
50691 + 3) You are using the RBAC system and hiding other files such as your
50692 + kernel image and System.map. Alternatively, enabling this option
50693 + causes the permissions on /boot, /lib/modules, and the kernel
50694 + source directory to change at compile time to prevent
50695 + reading by non-root users.
50696 + If the above conditions are met, this option will aid in providing a
50697 + useful protection against local kernel exploitation of overflows
50698 + and arbitrary read/write vulnerabilities.
50699 +
50700 +config GRKERNSEC_KERN_LOCKOUT
50701 + bool "Active kernel exploit response"
50702 + default y if GRKERNSEC_CONFIG_AUTO
50703 + depends on X86 || ARM || PPC || SPARC
50704 + help
50705 + If you say Y here, when a PaX alert is triggered due to suspicious
50706 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50707 + or an OOPS occurs due to bad memory accesses, instead of just
50708 + terminating the offending process (and potentially allowing
50709 + a subsequent exploit from the same user), we will take one of two
50710 + actions:
50711 + If the user was root, we will panic the system
50712 + If the user was non-root, we will log the attempt, terminate
50713 + all processes owned by the user, then prevent them from creating
50714 + any new processes until the system is restarted
50715 + This deters repeated kernel exploitation/bruteforcing attempts
50716 + and is useful for later forensics.
50717 +
50718 +endmenu
50719 +menu "Role Based Access Control Options"
50720 +depends on GRKERNSEC
50721 +
50722 +config GRKERNSEC_RBAC_DEBUG
50723 + bool
50724 +
50725 +config GRKERNSEC_NO_RBAC
50726 + bool "Disable RBAC system"
50727 + help
50728 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50729 + preventing the RBAC system from being enabled. You should only say Y
50730 + here if you have no intention of using the RBAC system, so as to prevent
50731 + an attacker with root access from misusing the RBAC system to hide files
50732 + and processes when loadable module support and /dev/[k]mem have been
50733 + locked down.
50734 +
50735 +config GRKERNSEC_ACL_HIDEKERN
50736 + bool "Hide kernel processes"
50737 + help
50738 + If you say Y here, all kernel threads will be hidden to all
50739 + processes but those whose subject has the "view hidden processes"
50740 + flag.
50741 +
50742 +config GRKERNSEC_ACL_MAXTRIES
50743 + int "Maximum tries before password lockout"
50744 + default 3
50745 + help
50746 + This option enforces the maximum number of times a user can attempt
50747 + to authorize themselves with the grsecurity RBAC system before being
50748 + denied the ability to attempt authorization again for a specified time.
50749 + The lower the number, the harder it will be to brute-force a password.
50750 +
50751 +config GRKERNSEC_ACL_TIMEOUT
50752 + int "Time to wait after max password tries, in seconds"
50753 + default 30
50754 + help
50755 + This option specifies the time the user must wait after attempting to
50756 + authorize to the RBAC system with the maximum number of invalid
50757 + passwords. The higher the number, the harder it will be to brute-force
50758 + a password.
50759 +
50760 +endmenu
50761 +menu "Filesystem Protections"
50762 +depends on GRKERNSEC
50763 +
50764 +config GRKERNSEC_PROC
50765 + bool "Proc restrictions"
50766 + default y if GRKERNSEC_CONFIG_AUTO
50767 + help
50768 + If you say Y here, the permissions of the /proc filesystem
50769 + will be altered to enhance system security and privacy. You MUST
50770 + choose either a user only restriction or a user and group restriction.
50771 + Depending upon the option you choose, you can either restrict users to
50772 + see only the processes they themselves run, or choose a group that can
50773 + view all processes and files normally restricted to root if you choose
50774 + the "restrict to user only" option. NOTE: If you're running identd or
50775 + ntpd as a non-root user, you will have to run it as the group you
50776 + specify here.
50777 +
50778 +config GRKERNSEC_PROC_USER
50779 + bool "Restrict /proc to user only"
50780 + depends on GRKERNSEC_PROC
50781 + help
50782 + If you say Y here, non-root users will only be able to view their own
50783 + processes, and restricts them from viewing network-related information,
50784 + and viewing kernel symbol and module information.
50785 +
50786 +config GRKERNSEC_PROC_USERGROUP
50787 + bool "Allow special group"
50788 + default y if GRKERNSEC_CONFIG_AUTO
50789 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50790 + help
50791 + If you say Y here, you will be able to select a group that will be
50792 + able to view all processes and network-related information. If you've
50793 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50794 + remain hidden. This option is useful if you want to run identd as
50795 + a non-root user. The group you select may also be chosen at boot time
50796 + via "grsec_proc_gid=" on the kernel commandline.
50797 +
50798 +config GRKERNSEC_PROC_GID
50799 + int "GID for special group"
50800 + depends on GRKERNSEC_PROC_USERGROUP
50801 + default 1001
50802 +
50803 +config GRKERNSEC_PROC_ADD
50804 + bool "Additional restrictions"
50805 + default y if GRKERNSEC_CONFIG_AUTO
50806 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50807 + help
50808 + If you say Y here, additional restrictions will be placed on
50809 + /proc that keep normal users from viewing device information and
50810 + slabinfo information that could be useful for exploits.
50811 +
50812 +config GRKERNSEC_LINK
50813 + bool "Linking restrictions"
50814 + default y if GRKERNSEC_CONFIG_AUTO
50815 + help
50816 + If you say Y here, /tmp race exploits will be prevented, since users
50817 + will no longer be able to follow symlinks owned by other users in
50818 + world-writable +t directories (e.g. /tmp), unless the owner of the
50819 + symlink is the owner of the directory. users will also not be
50820 + able to hardlink to files they do not own. If the sysctl option is
50821 + enabled, a sysctl option with name "linking_restrictions" is created.
50822 +
50823 +config GRKERNSEC_SYMLINKOWN
50824 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50825 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50826 + help
50827 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50828 + that prevents it from being used as a security feature. As Apache
50829 + verifies the symlink by performing a stat() against the target of
50830 + the symlink before it is followed, an attacker can setup a symlink
50831 + to point to a same-owned file, then replace the symlink with one
50832 + that targets another user's file just after Apache "validates" the
50833 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50834 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50835 + will be in place for the group you specify. If the sysctl option
50836 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50837 + created.
50838 +
50839 +config GRKERNSEC_SYMLINKOWN_GID
50840 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50841 + depends on GRKERNSEC_SYMLINKOWN
50842 + default 1006
50843 + help
50844 + Setting this GID determines what group kernel-enforced
50845 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50846 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50847 +
50848 +config GRKERNSEC_FIFO
50849 + bool "FIFO restrictions"
50850 + default y if GRKERNSEC_CONFIG_AUTO
50851 + help
50852 + If you say Y here, users will not be able to write to FIFOs they don't
50853 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50854 + the FIFO is the same owner of the directory it's held in. If the sysctl
50855 + option is enabled, a sysctl option with name "fifo_restrictions" is
50856 + created.
50857 +
50858 +config GRKERNSEC_SYSFS_RESTRICT
50859 + bool "Sysfs/debugfs restriction"
50860 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50861 + depends on SYSFS
50862 + help
50863 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50864 + any filesystem normally mounted under it (e.g. debugfs) will be
50865 + mostly accessible only by root. These filesystems generally provide access
50866 + to hardware and debug information that isn't appropriate for unprivileged
50867 + users of the system. Sysfs and debugfs have also become a large source
50868 + of new vulnerabilities, ranging from infoleaks to local compromise.
50869 + There has been very little oversight with an eye toward security involved
50870 + in adding new exporters of information to these filesystems, so their
50871 + use is discouraged.
50872 + For reasons of compatibility, a few directories have been whitelisted
50873 + for access by non-root users:
50874 + /sys/fs/selinux
50875 + /sys/fs/fuse
50876 + /sys/devices/system/cpu
50877 +
50878 +config GRKERNSEC_ROFS
50879 + bool "Runtime read-only mount protection"
50880 + help
50881 + If you say Y here, a sysctl option with name "romount_protect" will
50882 + be created. By setting this option to 1 at runtime, filesystems
50883 + will be protected in the following ways:
50884 + * No new writable mounts will be allowed
50885 + * Existing read-only mounts won't be able to be remounted read/write
50886 + * Write operations will be denied on all block devices
50887 + This option acts independently of grsec_lock: once it is set to 1,
50888 + it cannot be turned off. Therefore, please be mindful of the resulting
50889 + behavior if this option is enabled in an init script on a read-only
50890 + filesystem. This feature is mainly intended for secure embedded systems.
50891 +
50892 +config GRKERNSEC_CHROOT
50893 + bool "Chroot jail restrictions"
50894 + default y if GRKERNSEC_CONFIG_AUTO
50895 + help
50896 + If you say Y here, you will be able to choose several options that will
50897 + make breaking out of a chrooted jail much more difficult. If you
50898 + encounter no software incompatibilities with the following options, it
50899 + is recommended that you enable each one.
50900 +
50901 +config GRKERNSEC_CHROOT_MOUNT
50902 + bool "Deny mounts"
50903 + default y if GRKERNSEC_CONFIG_AUTO
50904 + depends on GRKERNSEC_CHROOT
50905 + help
50906 + If you say Y here, processes inside a chroot will not be able to
50907 + mount or remount filesystems. If the sysctl option is enabled, a
50908 + sysctl option with name "chroot_deny_mount" is created.
50909 +
50910 +config GRKERNSEC_CHROOT_DOUBLE
50911 + bool "Deny double-chroots"
50912 + default y if GRKERNSEC_CONFIG_AUTO
50913 + depends on GRKERNSEC_CHROOT
50914 + help
50915 + If you say Y here, processes inside a chroot will not be able to chroot
50916 + again outside the chroot. This is a widely used method of breaking
50917 + out of a chroot jail and should not be allowed. If the sysctl
50918 + option is enabled, a sysctl option with name
50919 + "chroot_deny_chroot" is created.
50920 +
50921 +config GRKERNSEC_CHROOT_PIVOT
50922 + bool "Deny pivot_root in chroot"
50923 + default y if GRKERNSEC_CONFIG_AUTO
50924 + depends on GRKERNSEC_CHROOT
50925 + help
50926 + If you say Y here, processes inside a chroot will not be able to use
50927 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50928 + works similar to chroot in that it changes the root filesystem. This
50929 + function could be misused in a chrooted process to attempt to break out
50930 + of the chroot, and therefore should not be allowed. If the sysctl
50931 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50932 + created.
50933 +
50934 +config GRKERNSEC_CHROOT_CHDIR
50935 + bool "Enforce chdir(\"/\") on all chroots"
50936 + default y if GRKERNSEC_CONFIG_AUTO
50937 + depends on GRKERNSEC_CHROOT
50938 + help
50939 + If you say Y here, the current working directory of all newly-chrooted
50940 + applications will be set to the the root directory of the chroot.
50941 + The man page on chroot(2) states:
50942 + Note that this call does not change the current working
50943 + directory, so that `.' can be outside the tree rooted at
50944 + `/'. In particular, the super-user can escape from a
50945 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50946 +
50947 + It is recommended that you say Y here, since it's not known to break
50948 + any software. If the sysctl option is enabled, a sysctl option with
50949 + name "chroot_enforce_chdir" is created.
50950 +
50951 +config GRKERNSEC_CHROOT_CHMOD
50952 + bool "Deny (f)chmod +s"
50953 + default y if GRKERNSEC_CONFIG_AUTO
50954 + depends on GRKERNSEC_CHROOT
50955 + help
50956 + If you say Y here, processes inside a chroot will not be able to chmod
50957 + or fchmod files to make them have suid or sgid bits. This protects
50958 + against another published method of breaking a chroot. If the sysctl
50959 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50960 + created.
50961 +
50962 +config GRKERNSEC_CHROOT_FCHDIR
50963 + bool "Deny fchdir out of chroot"
50964 + default y if GRKERNSEC_CONFIG_AUTO
50965 + depends on GRKERNSEC_CHROOT
50966 + help
50967 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50968 + to a file descriptor of the chrooting process that points to a directory
50969 + outside the filesystem will be stopped. If the sysctl option
50970 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50971 +
50972 +config GRKERNSEC_CHROOT_MKNOD
50973 + bool "Deny mknod"
50974 + default y if GRKERNSEC_CONFIG_AUTO
50975 + depends on GRKERNSEC_CHROOT
50976 + help
50977 + If you say Y here, processes inside a chroot will not be allowed to
50978 + mknod. The problem with using mknod inside a chroot is that it
50979 + would allow an attacker to create a device entry that is the same
50980 + as one on the physical root of your system, which could range from
50981 + anything from the console device to a device for your harddrive (which
50982 + they could then use to wipe the drive or steal data). It is recommended
50983 + that you say Y here, unless you run into software incompatibilities.
50984 + If the sysctl option is enabled, a sysctl option with name
50985 + "chroot_deny_mknod" is created.
50986 +
50987 +config GRKERNSEC_CHROOT_SHMAT
50988 + bool "Deny shmat() out of chroot"
50989 + default y if GRKERNSEC_CONFIG_AUTO
50990 + depends on GRKERNSEC_CHROOT
50991 + help
50992 + If you say Y here, processes inside a chroot will not be able to attach
50993 + to shared memory segments that were created outside of the chroot jail.
50994 + It is recommended that you say Y here. If the sysctl option is enabled,
50995 + a sysctl option with name "chroot_deny_shmat" is created.
50996 +
50997 +config GRKERNSEC_CHROOT_UNIX
50998 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50999 + default y if GRKERNSEC_CONFIG_AUTO
51000 + depends on GRKERNSEC_CHROOT
51001 + help
51002 + If you say Y here, processes inside a chroot will not be able to
51003 + connect to abstract (meaning not belonging to a filesystem) Unix
51004 + domain sockets that were bound outside of a chroot. It is recommended
51005 + that you say Y here. If the sysctl option is enabled, a sysctl option
51006 + with name "chroot_deny_unix" is created.
51007 +
51008 +config GRKERNSEC_CHROOT_FINDTASK
51009 + bool "Protect outside processes"
51010 + default y if GRKERNSEC_CONFIG_AUTO
51011 + depends on GRKERNSEC_CHROOT
51012 + help
51013 + If you say Y here, processes inside a chroot will not be able to
51014 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51015 + getsid, or view any process outside of the chroot. If the sysctl
51016 + option is enabled, a sysctl option with name "chroot_findtask" is
51017 + created.
51018 +
51019 +config GRKERNSEC_CHROOT_NICE
51020 + bool "Restrict priority changes"
51021 + default y if GRKERNSEC_CONFIG_AUTO
51022 + depends on GRKERNSEC_CHROOT
51023 + help
51024 + If you say Y here, processes inside a chroot will not be able to raise
51025 + the priority of processes in the chroot, or alter the priority of
51026 + processes outside the chroot. This provides more security than simply
51027 + removing CAP_SYS_NICE from the process' capability set. If the
51028 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51029 + is created.
51030 +
51031 +config GRKERNSEC_CHROOT_SYSCTL
51032 + bool "Deny sysctl writes"
51033 + default y if GRKERNSEC_CONFIG_AUTO
51034 + depends on GRKERNSEC_CHROOT
51035 + help
51036 + If you say Y here, an attacker in a chroot will not be able to
51037 + write to sysctl entries, either by sysctl(2) or through a /proc
51038 + interface. It is strongly recommended that you say Y here. If the
51039 + sysctl option is enabled, a sysctl option with name
51040 + "chroot_deny_sysctl" is created.
51041 +
51042 +config GRKERNSEC_CHROOT_CAPS
51043 + bool "Capability restrictions"
51044 + default y if GRKERNSEC_CONFIG_AUTO
51045 + depends on GRKERNSEC_CHROOT
51046 + help
51047 + If you say Y here, the capabilities on all processes within a
51048 + chroot jail will be lowered to stop module insertion, raw i/o,
51049 + system and net admin tasks, rebooting the system, modifying immutable
51050 + files, modifying IPC owned by another, and changing the system time.
51051 + This is left an option because it can break some apps. Disable this
51052 + if your chrooted apps are having problems performing those kinds of
51053 + tasks. If the sysctl option is enabled, a sysctl option with
51054 + name "chroot_caps" is created.
51055 +
51056 +endmenu
51057 +menu "Kernel Auditing"
51058 +depends on GRKERNSEC
51059 +
51060 +config GRKERNSEC_AUDIT_GROUP
51061 + bool "Single group for auditing"
51062 + help
51063 + If you say Y here, the exec, chdir, and (un)mount logging features
51064 + will only operate on a group you specify. This option is recommended
51065 + if you only want to watch certain users instead of having a large
51066 + amount of logs from the entire system. If the sysctl option is enabled,
51067 + a sysctl option with name "audit_group" is created.
51068 +
51069 +config GRKERNSEC_AUDIT_GID
51070 + int "GID for auditing"
51071 + depends on GRKERNSEC_AUDIT_GROUP
51072 + default 1007
51073 +
51074 +config GRKERNSEC_EXECLOG
51075 + bool "Exec logging"
51076 + help
51077 + If you say Y here, all execve() calls will be logged (since the
51078 + other exec*() calls are frontends to execve(), all execution
51079 + will be logged). Useful for shell-servers that like to keep track
51080 + of their users. If the sysctl option is enabled, a sysctl option with
51081 + name "exec_logging" is created.
51082 + WARNING: This option when enabled will produce a LOT of logs, especially
51083 + on an active system.
51084 +
51085 +config GRKERNSEC_RESLOG
51086 + bool "Resource logging"
51087 + default y if GRKERNSEC_CONFIG_AUTO
51088 + help
51089 + If you say Y here, all attempts to overstep resource limits will
51090 + be logged with the resource name, the requested size, and the current
51091 + limit. It is highly recommended that you say Y here. If the sysctl
51092 + option is enabled, a sysctl option with name "resource_logging" is
51093 + created. If the RBAC system is enabled, the sysctl value is ignored.
51094 +
51095 +config GRKERNSEC_CHROOT_EXECLOG
51096 + bool "Log execs within chroot"
51097 + help
51098 + If you say Y here, all executions inside a chroot jail will be logged
51099 + to syslog. This can cause a large amount of logs if certain
51100 + applications (eg. djb's daemontools) are installed on the system, and
51101 + is therefore left as an option. If the sysctl option is enabled, a
51102 + sysctl option with name "chroot_execlog" is created.
51103 +
51104 +config GRKERNSEC_AUDIT_PTRACE
51105 + bool "Ptrace logging"
51106 + help
51107 + If you say Y here, all attempts to attach to a process via ptrace
51108 + will be logged. If the sysctl option is enabled, a sysctl option
51109 + with name "audit_ptrace" is created.
51110 +
51111 +config GRKERNSEC_AUDIT_CHDIR
51112 + bool "Chdir logging"
51113 + help
51114 + If you say Y here, all chdir() calls will be logged. If the sysctl
51115 + option is enabled, a sysctl option with name "audit_chdir" is created.
51116 +
51117 +config GRKERNSEC_AUDIT_MOUNT
51118 + bool "(Un)Mount logging"
51119 + help
51120 + If you say Y here, all mounts and unmounts will be logged. If the
51121 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51122 + created.
51123 +
51124 +config GRKERNSEC_SIGNAL
51125 + bool "Signal logging"
51126 + default y if GRKERNSEC_CONFIG_AUTO
51127 + help
51128 + If you say Y here, certain important signals will be logged, such as
51129 + SIGSEGV, which will as a result inform you of when a error in a program
51130 + occurred, which in some cases could mean a possible exploit attempt.
51131 + If the sysctl option is enabled, a sysctl option with name
51132 + "signal_logging" is created.
51133 +
51134 +config GRKERNSEC_FORKFAIL
51135 + bool "Fork failure logging"
51136 + help
51137 + If you say Y here, all failed fork() attempts will be logged.
51138 + This could suggest a fork bomb, or someone attempting to overstep
51139 + their process limit. If the sysctl option is enabled, a sysctl option
51140 + with name "forkfail_logging" is created.
51141 +
51142 +config GRKERNSEC_TIME
51143 + bool "Time change logging"
51144 + default y if GRKERNSEC_CONFIG_AUTO
51145 + help
51146 + If you say Y here, any changes of the system clock will be logged.
51147 + If the sysctl option is enabled, a sysctl option with name
51148 + "timechange_logging" is created.
51149 +
51150 +config GRKERNSEC_PROC_IPADDR
51151 + bool "/proc/<pid>/ipaddr support"
51152 + default y if GRKERNSEC_CONFIG_AUTO
51153 + help
51154 + If you say Y here, a new entry will be added to each /proc/<pid>
51155 + directory that contains the IP address of the person using the task.
51156 + The IP is carried across local TCP and AF_UNIX stream sockets.
51157 + This information can be useful for IDS/IPSes to perform remote response
51158 + to a local attack. The entry is readable by only the owner of the
51159 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51160 + the RBAC system), and thus does not create privacy concerns.
51161 +
51162 +config GRKERNSEC_RWXMAP_LOG
51163 + bool 'Denied RWX mmap/mprotect logging'
51164 + default y if GRKERNSEC_CONFIG_AUTO
51165 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51166 + help
51167 + If you say Y here, calls to mmap() and mprotect() with explicit
51168 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51169 + denied by the PAX_MPROTECT feature. If the sysctl option is
51170 + enabled, a sysctl option with name "rwxmap_logging" is created.
51171 +
51172 +config GRKERNSEC_AUDIT_TEXTREL
51173 + bool 'ELF text relocations logging (READ HELP)'
51174 + depends on PAX_MPROTECT
51175 + help
51176 + If you say Y here, text relocations will be logged with the filename
51177 + of the offending library or binary. The purpose of the feature is
51178 + to help Linux distribution developers get rid of libraries and
51179 + binaries that need text relocations which hinder the future progress
51180 + of PaX. Only Linux distribution developers should say Y here, and
51181 + never on a production machine, as this option creates an information
51182 + leak that could aid an attacker in defeating the randomization of
51183 + a single memory region. If the sysctl option is enabled, a sysctl
51184 + option with name "audit_textrel" is created.
51185 +
51186 +endmenu
51187 +
51188 +menu "Executable Protections"
51189 +depends on GRKERNSEC
51190 +
51191 +config GRKERNSEC_DMESG
51192 + bool "Dmesg(8) restriction"
51193 + default y if GRKERNSEC_CONFIG_AUTO
51194 + help
51195 + If you say Y here, non-root users will not be able to use dmesg(8)
51196 + to view up to the last 4kb of messages in the kernel's log buffer.
51197 + The kernel's log buffer often contains kernel addresses and other
51198 + identifying information useful to an attacker in fingerprinting a
51199 + system for a targeted exploit.
51200 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51201 + created.
51202 +
51203 +config GRKERNSEC_HARDEN_PTRACE
51204 + bool "Deter ptrace-based process snooping"
51205 + default y if GRKERNSEC_CONFIG_AUTO
51206 + help
51207 + If you say Y here, TTY sniffers and other malicious monitoring
51208 + programs implemented through ptrace will be defeated. If you
51209 + have been using the RBAC system, this option has already been
51210 + enabled for several years for all users, with the ability to make
51211 + fine-grained exceptions.
51212 +
51213 + This option only affects the ability of non-root users to ptrace
51214 + processes that are not a descendent of the ptracing process.
51215 + This means that strace ./binary and gdb ./binary will still work,
51216 + but attaching to arbitrary processes will not. If the sysctl
51217 + option is enabled, a sysctl option with name "harden_ptrace" is
51218 + created.
51219 +
51220 +config GRKERNSEC_PTRACE_READEXEC
51221 + bool "Require read access to ptrace sensitive binaries"
51222 + default y if GRKERNSEC_CONFIG_AUTO
51223 + help
51224 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51225 + binaries. This option is useful in environments that
51226 + remove the read bits (e.g. file mode 4711) from suid binaries to
51227 + prevent infoleaking of their contents. This option adds
51228 + consistency to the use of that file mode, as the binary could normally
51229 + be read out when run without privileges while ptracing.
51230 +
51231 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51232 + is created.
51233 +
51234 +config GRKERNSEC_SETXID
51235 + bool "Enforce consistent multithreaded privileges"
51236 + default y if GRKERNSEC_CONFIG_AUTO
51237 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51238 + help
51239 + If you say Y here, a change from a root uid to a non-root uid
51240 + in a multithreaded application will cause the resulting uids,
51241 + gids, supplementary groups, and capabilities in that thread
51242 + to be propagated to the other threads of the process. In most
51243 + cases this is unnecessary, as glibc will emulate this behavior
51244 + on behalf of the application. Other libcs do not act in the
51245 + same way, allowing the other threads of the process to continue
51246 + running with root privileges. If the sysctl option is enabled,
51247 + a sysctl option with name "consistent_setxid" is created.
51248 +
51249 +config GRKERNSEC_TPE
51250 + bool "Trusted Path Execution (TPE)"
51251 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51252 + help
51253 + If you say Y here, you will be able to choose a gid to add to the
51254 + supplementary groups of users you want to mark as "untrusted."
51255 + These users will not be able to execute any files that are not in
51256 + root-owned directories writable only by root. If the sysctl option
51257 + is enabled, a sysctl option with name "tpe" is created.
51258 +
51259 +config GRKERNSEC_TPE_ALL
51260 + bool "Partially restrict all non-root users"
51261 + depends on GRKERNSEC_TPE
51262 + help
51263 + If you say Y here, all non-root users will be covered under
51264 + a weaker TPE restriction. This is separate from, and in addition to,
51265 + the main TPE options that you have selected elsewhere. Thus, if a
51266 + "trusted" GID is chosen, this restriction applies to even that GID.
51267 + Under this restriction, all non-root users will only be allowed to
51268 + execute files in directories they own that are not group or
51269 + world-writable, or in directories owned by root and writable only by
51270 + root. If the sysctl option is enabled, a sysctl option with name
51271 + "tpe_restrict_all" is created.
51272 +
51273 +config GRKERNSEC_TPE_INVERT
51274 + bool "Invert GID option"
51275 + depends on GRKERNSEC_TPE
51276 + help
51277 + If you say Y here, the group you specify in the TPE configuration will
51278 + decide what group TPE restrictions will be *disabled* for. This
51279 + option is useful if you want TPE restrictions to be applied to most
51280 + users on the system. If the sysctl option is enabled, a sysctl option
51281 + with name "tpe_invert" is created. Unlike other sysctl options, this
51282 + entry will default to on for backward-compatibility.
51283 +
51284 +config GRKERNSEC_TPE_GID
51285 + int
51286 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51287 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51288 +
51289 +config GRKERNSEC_TPE_UNTRUSTED_GID
51290 + int "GID for TPE-untrusted users"
51291 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51292 + default 1005
51293 + help
51294 + Setting this GID determines what group TPE restrictions will be
51295 + *enabled* for. If the sysctl option is enabled, a sysctl option
51296 + with name "tpe_gid" is created.
51297 +
51298 +config GRKERNSEC_TPE_TRUSTED_GID
51299 + int "GID for TPE-trusted users"
51300 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51301 + default 1005
51302 + help
51303 + Setting this GID determines what group TPE restrictions will be
51304 + *disabled* for. If the sysctl option is enabled, a sysctl option
51305 + with name "tpe_gid" is created.
51306 +
51307 +endmenu
51308 +menu "Network Protections"
51309 +depends on GRKERNSEC
51310 +
51311 +config GRKERNSEC_RANDNET
51312 + bool "Larger entropy pools"
51313 + default y if GRKERNSEC_CONFIG_AUTO
51314 + help
51315 + If you say Y here, the entropy pools used for many features of Linux
51316 + and grsecurity will be doubled in size. Since several grsecurity
51317 + features use additional randomness, it is recommended that you say Y
51318 + here. Saying Y here has a similar effect as modifying
51319 + /proc/sys/kernel/random/poolsize.
51320 +
51321 +config GRKERNSEC_BLACKHOLE
51322 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51323 + default y if GRKERNSEC_CONFIG_AUTO
51324 + depends on NET
51325 + help
51326 + If you say Y here, neither TCP resets nor ICMP
51327 + destination-unreachable packets will be sent in response to packets
51328 + sent to ports for which no associated listening process exists.
51329 + This feature supports both IPV4 and IPV6 and exempts the
51330 + loopback interface from blackholing. Enabling this feature
51331 + makes a host more resilient to DoS attacks and reduces network
51332 + visibility against scanners.
51333 +
51334 + The blackhole feature as-implemented is equivalent to the FreeBSD
51335 + blackhole feature, as it prevents RST responses to all packets, not
51336 + just SYNs. Under most application behavior this causes no
51337 + problems, but applications (like haproxy) may not close certain
51338 + connections in a way that cleanly terminates them on the remote
51339 + end, leaving the remote host in LAST_ACK state. Because of this
51340 + side-effect and to prevent intentional LAST_ACK DoSes, this
51341 + feature also adds automatic mitigation against such attacks.
51342 + The mitigation drastically reduces the amount of time a socket
51343 + can spend in LAST_ACK state. If you're using haproxy and not
51344 + all servers it connects to have this option enabled, consider
51345 + disabling this feature on the haproxy host.
51346 +
51347 + If the sysctl option is enabled, two sysctl options with names
51348 + "ip_blackhole" and "lastack_retries" will be created.
51349 + While "ip_blackhole" takes the standard zero/non-zero on/off
51350 + toggle, "lastack_retries" uses the same kinds of values as
51351 + "tcp_retries1" and "tcp_retries2". The default value of 4
51352 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51353 + state.
51354 +
51355 +config GRKERNSEC_SOCKET
51356 + bool "Socket restrictions"
51357 + depends on NET
51358 + help
51359 + If you say Y here, you will be able to choose from several options.
51360 + If you assign a GID on your system and add it to the supplementary
51361 + groups of users you want to restrict socket access to, this patch
51362 + will perform up to three things, based on the option(s) you choose.
51363 +
51364 +config GRKERNSEC_SOCKET_ALL
51365 + bool "Deny any sockets to group"
51366 + depends on GRKERNSEC_SOCKET
51367 + help
51368 + If you say Y here, you will be able to choose a GID of whose users will
51369 + be unable to connect to other hosts from your machine or run server
51370 + applications from your machine. If the sysctl option is enabled, a
51371 + sysctl option with name "socket_all" is created.
51372 +
51373 +config GRKERNSEC_SOCKET_ALL_GID
51374 + int "GID to deny all sockets for"
51375 + depends on GRKERNSEC_SOCKET_ALL
51376 + default 1004
51377 + help
51378 + Here you can choose the GID to disable socket access for. Remember to
51379 + add the users you want socket access disabled for to the GID
51380 + specified here. If the sysctl option is enabled, a sysctl option
51381 + with name "socket_all_gid" is created.
51382 +
51383 +config GRKERNSEC_SOCKET_CLIENT
51384 + bool "Deny client sockets to group"
51385 + depends on GRKERNSEC_SOCKET
51386 + help
51387 + If you say Y here, you will be able to choose a GID of whose users will
51388 + be unable to connect to other hosts from your machine, but will be
51389 + able to run servers. If this option is enabled, all users in the group
51390 + you specify will have to use passive mode when initiating ftp transfers
51391 + from the shell on your machine. If the sysctl option is enabled, a
51392 + sysctl option with name "socket_client" is created.
51393 +
51394 +config GRKERNSEC_SOCKET_CLIENT_GID
51395 + int "GID to deny client sockets for"
51396 + depends on GRKERNSEC_SOCKET_CLIENT
51397 + default 1003
51398 + help
51399 + Here you can choose the GID to disable client socket access for.
51400 + Remember to add the users you want client socket access disabled for to
51401 + the GID specified here. If the sysctl option is enabled, a sysctl
51402 + option with name "socket_client_gid" is created.
51403 +
51404 +config GRKERNSEC_SOCKET_SERVER
51405 + bool "Deny server sockets to group"
51406 + depends on GRKERNSEC_SOCKET
51407 + help
51408 + If you say Y here, you will be able to choose a GID of whose users will
51409 + be unable to run server applications from your machine. If the sysctl
51410 + option is enabled, a sysctl option with name "socket_server" is created.
51411 +
51412 +config GRKERNSEC_SOCKET_SERVER_GID
51413 + int "GID to deny server sockets for"
51414 + depends on GRKERNSEC_SOCKET_SERVER
51415 + default 1002
51416 + help
51417 + Here you can choose the GID to disable server socket access for.
51418 + Remember to add the users you want server socket access disabled for to
51419 + the GID specified here. If the sysctl option is enabled, a sysctl
51420 + option with name "socket_server_gid" is created.
51421 +
51422 +endmenu
51423 +menu "Sysctl Support"
51424 +depends on GRKERNSEC && SYSCTL
51425 +
51426 +config GRKERNSEC_SYSCTL
51427 + bool "Sysctl support"
51428 + default y if GRKERNSEC_CONFIG_AUTO
51429 + help
51430 + If you say Y here, you will be able to change the options that
51431 + grsecurity runs with at bootup, without having to recompile your
51432 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51433 + to enable (1) or disable (0) various features. All the sysctl entries
51434 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51435 + All features enabled in the kernel configuration are disabled at boot
51436 + if you do not say Y to the "Turn on features by default" option.
51437 + All options should be set at startup, and the grsec_lock entry should
51438 + be set to a non-zero value after all the options are set.
51439 + *THIS IS EXTREMELY IMPORTANT*
51440 +
51441 +config GRKERNSEC_SYSCTL_DISTRO
51442 + bool "Extra sysctl support for distro makers (READ HELP)"
51443 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51444 + help
51445 + If you say Y here, additional sysctl options will be created
51446 + for features that affect processes running as root. Therefore,
51447 + it is critical when using this option that the grsec_lock entry be
51448 + enabled after boot. Only distros with prebuilt kernel packages
51449 + with this option enabled that can ensure grsec_lock is enabled
51450 + after boot should use this option.
51451 + *Failure to set grsec_lock after boot makes all grsec features
51452 + this option covers useless*
51453 +
51454 + Currently this option creates the following sysctl entries:
51455 + "Disable Privileged I/O": "disable_priv_io"
51456 +
51457 +config GRKERNSEC_SYSCTL_ON
51458 + bool "Turn on features by default"
51459 + default y if GRKERNSEC_CONFIG_AUTO
51460 + depends on GRKERNSEC_SYSCTL
51461 + help
51462 + If you say Y here, instead of having all features enabled in the
51463 + kernel configuration disabled at boot time, the features will be
51464 + enabled at boot time. It is recommended you say Y here unless
51465 + there is some reason you would want all sysctl-tunable features to
51466 + be disabled by default. As mentioned elsewhere, it is important
51467 + to enable the grsec_lock entry once you have finished modifying
51468 + the sysctl entries.
51469 +
51470 +endmenu
51471 +menu "Logging Options"
51472 +depends on GRKERNSEC
51473 +
51474 +config GRKERNSEC_FLOODTIME
51475 + int "Seconds in between log messages (minimum)"
51476 + default 10
51477 + help
51478 + This option allows you to enforce the number of seconds between
51479 + grsecurity log messages. The default should be suitable for most
51480 + people, however, if you choose to change it, choose a value small enough
51481 + to allow informative logs to be produced, but large enough to
51482 + prevent flooding.
51483 +
51484 +config GRKERNSEC_FLOODBURST
51485 + int "Number of messages in a burst (maximum)"
51486 + default 6
51487 + help
51488 + This option allows you to choose the maximum number of messages allowed
51489 + within the flood time interval you chose in a separate option. The
51490 + default should be suitable for most people, however if you find that
51491 + many of your logs are being interpreted as flooding, you may want to
51492 + raise this value.
51493 +
51494 +endmenu
51495 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51496 new file mode 100644
51497 index 0000000..1b9afa9
51498 --- /dev/null
51499 +++ b/grsecurity/Makefile
51500 @@ -0,0 +1,38 @@
51501 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51502 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51503 +# into an RBAC system
51504 +#
51505 +# All code in this directory and various hooks inserted throughout the kernel
51506 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51507 +# under the GPL v2 or higher
51508 +
51509 +KBUILD_CFLAGS += -Werror
51510 +
51511 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51512 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51513 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51514 +
51515 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51516 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51517 + gracl_learn.o grsec_log.o
51518 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51519 +
51520 +ifdef CONFIG_NET
51521 +obj-y += grsec_sock.o
51522 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51523 +endif
51524 +
51525 +ifndef CONFIG_GRKERNSEC
51526 +obj-y += grsec_disabled.o
51527 +endif
51528 +
51529 +ifdef CONFIG_GRKERNSEC_HIDESYM
51530 +extra-y := grsec_hidesym.o
51531 +$(obj)/grsec_hidesym.o:
51532 + @-chmod -f 500 /boot
51533 + @-chmod -f 500 /lib/modules
51534 + @-chmod -f 500 /lib64/modules
51535 + @-chmod -f 500 /lib32/modules
51536 + @-chmod -f 700 .
51537 + @echo ' grsec: protected kernel image paths'
51538 +endif
51539 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51540 new file mode 100644
51541 index 0000000..3d58260
51542 --- /dev/null
51543 +++ b/grsecurity/gracl.c
51544 @@ -0,0 +1,4029 @@
51545 +#include <linux/kernel.h>
51546 +#include <linux/module.h>
51547 +#include <linux/sched.h>
51548 +#include <linux/mm.h>
51549 +#include <linux/file.h>
51550 +#include <linux/fs.h>
51551 +#include <linux/namei.h>
51552 +#include <linux/mount.h>
51553 +#include <linux/tty.h>
51554 +#include <linux/proc_fs.h>
51555 +#include <linux/lglock.h>
51556 +#include <linux/slab.h>
51557 +#include <linux/vmalloc.h>
51558 +#include <linux/types.h>
51559 +#include <linux/sysctl.h>
51560 +#include <linux/netdevice.h>
51561 +#include <linux/ptrace.h>
51562 +#include <linux/gracl.h>
51563 +#include <linux/gralloc.h>
51564 +#include <linux/security.h>
51565 +#include <linux/grinternal.h>
51566 +#include <linux/pid_namespace.h>
51567 +#include <linux/stop_machine.h>
51568 +#include <linux/fdtable.h>
51569 +#include <linux/percpu.h>
51570 +#include <linux/lglock.h>
51571 +#include "../fs/mount.h"
51572 +
51573 +#include <asm/uaccess.h>
51574 +#include <asm/errno.h>
51575 +#include <asm/mman.h>
51576 +
51577 +extern struct lglock vfsmount_lock;
51578 +
51579 +static struct acl_role_db acl_role_set;
51580 +static struct name_db name_set;
51581 +static struct inodev_db inodev_set;
51582 +
51583 +/* for keeping track of userspace pointers used for subjects, so we
51584 + can share references in the kernel as well
51585 +*/
51586 +
51587 +static struct path real_root;
51588 +
51589 +static struct acl_subj_map_db subj_map_set;
51590 +
51591 +static struct acl_role_label *default_role;
51592 +
51593 +static struct acl_role_label *role_list;
51594 +
51595 +static u16 acl_sp_role_value;
51596 +
51597 +extern char *gr_shared_page[4];
51598 +static DEFINE_MUTEX(gr_dev_mutex);
51599 +DEFINE_RWLOCK(gr_inode_lock);
51600 +
51601 +struct gr_arg *gr_usermode;
51602 +
51603 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51604 +
51605 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51606 +extern void gr_clear_learn_entries(void);
51607 +
51608 +#ifdef CONFIG_GRKERNSEC_RESLOG
51609 +extern void gr_log_resource(const struct task_struct *task,
51610 + const int res, const unsigned long wanted, const int gt);
51611 +#endif
51612 +
51613 +unsigned char *gr_system_salt;
51614 +unsigned char *gr_system_sum;
51615 +
51616 +static struct sprole_pw **acl_special_roles = NULL;
51617 +static __u16 num_sprole_pws = 0;
51618 +
51619 +static struct acl_role_label *kernel_role = NULL;
51620 +
51621 +static unsigned int gr_auth_attempts = 0;
51622 +static unsigned long gr_auth_expires = 0UL;
51623 +
51624 +#ifdef CONFIG_NET
51625 +extern struct vfsmount *sock_mnt;
51626 +#endif
51627 +
51628 +extern struct vfsmount *pipe_mnt;
51629 +extern struct vfsmount *shm_mnt;
51630 +#ifdef CONFIG_HUGETLBFS
51631 +extern struct vfsmount *hugetlbfs_vfsmount;
51632 +#endif
51633 +
51634 +static struct acl_object_label *fakefs_obj_rw;
51635 +static struct acl_object_label *fakefs_obj_rwx;
51636 +
51637 +extern int gr_init_uidset(void);
51638 +extern void gr_free_uidset(void);
51639 +extern void gr_remove_uid(uid_t uid);
51640 +extern int gr_find_uid(uid_t uid);
51641 +
51642 +__inline__ int
51643 +gr_acl_is_enabled(void)
51644 +{
51645 + return (gr_status & GR_READY);
51646 +}
51647 +
51648 +#ifdef CONFIG_BTRFS_FS
51649 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51650 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51651 +#endif
51652 +
51653 +static inline dev_t __get_dev(const struct dentry *dentry)
51654 +{
51655 +#ifdef CONFIG_BTRFS_FS
51656 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51657 + return get_btrfs_dev_from_inode(dentry->d_inode);
51658 + else
51659 +#endif
51660 + return dentry->d_inode->i_sb->s_dev;
51661 +}
51662 +
51663 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51664 +{
51665 + return __get_dev(dentry);
51666 +}
51667 +
51668 +static char gr_task_roletype_to_char(struct task_struct *task)
51669 +{
51670 + switch (task->role->roletype &
51671 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51672 + GR_ROLE_SPECIAL)) {
51673 + case GR_ROLE_DEFAULT:
51674 + return 'D';
51675 + case GR_ROLE_USER:
51676 + return 'U';
51677 + case GR_ROLE_GROUP:
51678 + return 'G';
51679 + case GR_ROLE_SPECIAL:
51680 + return 'S';
51681 + }
51682 +
51683 + return 'X';
51684 +}
51685 +
51686 +char gr_roletype_to_char(void)
51687 +{
51688 + return gr_task_roletype_to_char(current);
51689 +}
51690 +
51691 +__inline__ int
51692 +gr_acl_tpe_check(void)
51693 +{
51694 + if (unlikely(!(gr_status & GR_READY)))
51695 + return 0;
51696 + if (current->role->roletype & GR_ROLE_TPE)
51697 + return 1;
51698 + else
51699 + return 0;
51700 +}
51701 +
51702 +int
51703 +gr_handle_rawio(const struct inode *inode)
51704 +{
51705 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51706 + if (inode && S_ISBLK(inode->i_mode) &&
51707 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51708 + !capable(CAP_SYS_RAWIO))
51709 + return 1;
51710 +#endif
51711 + return 0;
51712 +}
51713 +
51714 +static int
51715 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51716 +{
51717 + if (likely(lena != lenb))
51718 + return 0;
51719 +
51720 + return !memcmp(a, b, lena);
51721 +}
51722 +
51723 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51724 +{
51725 + *buflen -= namelen;
51726 + if (*buflen < 0)
51727 + return -ENAMETOOLONG;
51728 + *buffer -= namelen;
51729 + memcpy(*buffer, str, namelen);
51730 + return 0;
51731 +}
51732 +
51733 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51734 +{
51735 + return prepend(buffer, buflen, name->name, name->len);
51736 +}
51737 +
51738 +static int prepend_path(const struct path *path, struct path *root,
51739 + char **buffer, int *buflen)
51740 +{
51741 + struct dentry *dentry = path->dentry;
51742 + struct vfsmount *vfsmnt = path->mnt;
51743 + struct mount *mnt = real_mount(vfsmnt);
51744 + bool slash = false;
51745 + int error = 0;
51746 +
51747 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51748 + struct dentry * parent;
51749 +
51750 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51751 + /* Global root? */
51752 + if (!mnt_has_parent(mnt)) {
51753 + goto out;
51754 + }
51755 + dentry = mnt->mnt_mountpoint;
51756 + mnt = mnt->mnt_parent;
51757 + vfsmnt = &mnt->mnt;
51758 + continue;
51759 + }
51760 + parent = dentry->d_parent;
51761 + prefetch(parent);
51762 + spin_lock(&dentry->d_lock);
51763 + error = prepend_name(buffer, buflen, &dentry->d_name);
51764 + spin_unlock(&dentry->d_lock);
51765 + if (!error)
51766 + error = prepend(buffer, buflen, "/", 1);
51767 + if (error)
51768 + break;
51769 +
51770 + slash = true;
51771 + dentry = parent;
51772 + }
51773 +
51774 +out:
51775 + if (!error && !slash)
51776 + error = prepend(buffer, buflen, "/", 1);
51777 +
51778 + return error;
51779 +}
51780 +
51781 +/* this must be called with vfsmount_lock and rename_lock held */
51782 +
51783 +static char *__our_d_path(const struct path *path, struct path *root,
51784 + char *buf, int buflen)
51785 +{
51786 + char *res = buf + buflen;
51787 + int error;
51788 +
51789 + prepend(&res, &buflen, "\0", 1);
51790 + error = prepend_path(path, root, &res, &buflen);
51791 + if (error)
51792 + return ERR_PTR(error);
51793 +
51794 + return res;
51795 +}
51796 +
51797 +static char *
51798 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51799 +{
51800 + char *retval;
51801 +
51802 + retval = __our_d_path(path, root, buf, buflen);
51803 + if (unlikely(IS_ERR(retval)))
51804 + retval = strcpy(buf, "<path too long>");
51805 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51806 + retval[1] = '\0';
51807 +
51808 + return retval;
51809 +}
51810 +
51811 +static char *
51812 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51813 + char *buf, int buflen)
51814 +{
51815 + struct path path;
51816 + char *res;
51817 +
51818 + path.dentry = (struct dentry *)dentry;
51819 + path.mnt = (struct vfsmount *)vfsmnt;
51820 +
51821 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51822 + by the RBAC system */
51823 + res = gen_full_path(&path, &real_root, buf, buflen);
51824 +
51825 + return res;
51826 +}
51827 +
51828 +static char *
51829 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51830 + char *buf, int buflen)
51831 +{
51832 + char *res;
51833 + struct path path;
51834 + struct path root;
51835 + struct task_struct *reaper = init_pid_ns.child_reaper;
51836 +
51837 + path.dentry = (struct dentry *)dentry;
51838 + path.mnt = (struct vfsmount *)vfsmnt;
51839 +
51840 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51841 + get_fs_root(reaper->fs, &root);
51842 +
51843 + write_seqlock(&rename_lock);
51844 + br_read_lock(&vfsmount_lock);
51845 + res = gen_full_path(&path, &root, buf, buflen);
51846 + br_read_unlock(&vfsmount_lock);
51847 + write_sequnlock(&rename_lock);
51848 +
51849 + path_put(&root);
51850 + return res;
51851 +}
51852 +
51853 +static char *
51854 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51855 +{
51856 + char *ret;
51857 + write_seqlock(&rename_lock);
51858 + br_read_lock(&vfsmount_lock);
51859 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51860 + PAGE_SIZE);
51861 + br_read_unlock(&vfsmount_lock);
51862 + write_sequnlock(&rename_lock);
51863 + return ret;
51864 +}
51865 +
51866 +static char *
51867 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51868 +{
51869 + char *ret;
51870 + char *buf;
51871 + int buflen;
51872 +
51873 + write_seqlock(&rename_lock);
51874 + br_read_lock(&vfsmount_lock);
51875 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51876 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51877 + buflen = (int)(ret - buf);
51878 + if (buflen >= 5)
51879 + prepend(&ret, &buflen, "/proc", 5);
51880 + else
51881 + ret = strcpy(buf, "<path too long>");
51882 + br_read_unlock(&vfsmount_lock);
51883 + write_sequnlock(&rename_lock);
51884 + return ret;
51885 +}
51886 +
51887 +char *
51888 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51889 +{
51890 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51891 + PAGE_SIZE);
51892 +}
51893 +
51894 +char *
51895 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51896 +{
51897 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51898 + PAGE_SIZE);
51899 +}
51900 +
51901 +char *
51902 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51903 +{
51904 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51905 + PAGE_SIZE);
51906 +}
51907 +
51908 +char *
51909 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51910 +{
51911 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51912 + PAGE_SIZE);
51913 +}
51914 +
51915 +char *
51916 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51917 +{
51918 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51919 + PAGE_SIZE);
51920 +}
51921 +
51922 +__inline__ __u32
51923 +to_gr_audit(const __u32 reqmode)
51924 +{
51925 + /* masks off auditable permission flags, then shifts them to create
51926 + auditing flags, and adds the special case of append auditing if
51927 + we're requesting write */
51928 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51929 +}
51930 +
51931 +struct acl_subject_label *
51932 +lookup_subject_map(const struct acl_subject_label *userp)
51933 +{
51934 + unsigned int index = shash(userp, subj_map_set.s_size);
51935 + struct subject_map *match;
51936 +
51937 + match = subj_map_set.s_hash[index];
51938 +
51939 + while (match && match->user != userp)
51940 + match = match->next;
51941 +
51942 + if (match != NULL)
51943 + return match->kernel;
51944 + else
51945 + return NULL;
51946 +}
51947 +
51948 +static void
51949 +insert_subj_map_entry(struct subject_map *subjmap)
51950 +{
51951 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51952 + struct subject_map **curr;
51953 +
51954 + subjmap->prev = NULL;
51955 +
51956 + curr = &subj_map_set.s_hash[index];
51957 + if (*curr != NULL)
51958 + (*curr)->prev = subjmap;
51959 +
51960 + subjmap->next = *curr;
51961 + *curr = subjmap;
51962 +
51963 + return;
51964 +}
51965 +
51966 +static struct acl_role_label *
51967 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51968 + const gid_t gid)
51969 +{
51970 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51971 + struct acl_role_label *match;
51972 + struct role_allowed_ip *ipp;
51973 + unsigned int x;
51974 + u32 curr_ip = task->signal->curr_ip;
51975 +
51976 + task->signal->saved_ip = curr_ip;
51977 +
51978 + match = acl_role_set.r_hash[index];
51979 +
51980 + while (match) {
51981 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51982 + for (x = 0; x < match->domain_child_num; x++) {
51983 + if (match->domain_children[x] == uid)
51984 + goto found;
51985 + }
51986 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51987 + break;
51988 + match = match->next;
51989 + }
51990 +found:
51991 + if (match == NULL) {
51992 + try_group:
51993 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51994 + match = acl_role_set.r_hash[index];
51995 +
51996 + while (match) {
51997 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51998 + for (x = 0; x < match->domain_child_num; x++) {
51999 + if (match->domain_children[x] == gid)
52000 + goto found2;
52001 + }
52002 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52003 + break;
52004 + match = match->next;
52005 + }
52006 +found2:
52007 + if (match == NULL)
52008 + match = default_role;
52009 + if (match->allowed_ips == NULL)
52010 + return match;
52011 + else {
52012 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52013 + if (likely
52014 + ((ntohl(curr_ip) & ipp->netmask) ==
52015 + (ntohl(ipp->addr) & ipp->netmask)))
52016 + return match;
52017 + }
52018 + match = default_role;
52019 + }
52020 + } else if (match->allowed_ips == NULL) {
52021 + return match;
52022 + } else {
52023 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52024 + if (likely
52025 + ((ntohl(curr_ip) & ipp->netmask) ==
52026 + (ntohl(ipp->addr) & ipp->netmask)))
52027 + return match;
52028 + }
52029 + goto try_group;
52030 + }
52031 +
52032 + return match;
52033 +}
52034 +
52035 +struct acl_subject_label *
52036 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52037 + const struct acl_role_label *role)
52038 +{
52039 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52040 + struct acl_subject_label *match;
52041 +
52042 + match = role->subj_hash[index];
52043 +
52044 + while (match && (match->inode != ino || match->device != dev ||
52045 + (match->mode & GR_DELETED))) {
52046 + match = match->next;
52047 + }
52048 +
52049 + if (match && !(match->mode & GR_DELETED))
52050 + return match;
52051 + else
52052 + return NULL;
52053 +}
52054 +
52055 +struct acl_subject_label *
52056 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52057 + const struct acl_role_label *role)
52058 +{
52059 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52060 + struct acl_subject_label *match;
52061 +
52062 + match = role->subj_hash[index];
52063 +
52064 + while (match && (match->inode != ino || match->device != dev ||
52065 + !(match->mode & GR_DELETED))) {
52066 + match = match->next;
52067 + }
52068 +
52069 + if (match && (match->mode & GR_DELETED))
52070 + return match;
52071 + else
52072 + return NULL;
52073 +}
52074 +
52075 +static struct acl_object_label *
52076 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52077 + const struct acl_subject_label *subj)
52078 +{
52079 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52080 + struct acl_object_label *match;
52081 +
52082 + match = subj->obj_hash[index];
52083 +
52084 + while (match && (match->inode != ino || match->device != dev ||
52085 + (match->mode & GR_DELETED))) {
52086 + match = match->next;
52087 + }
52088 +
52089 + if (match && !(match->mode & GR_DELETED))
52090 + return match;
52091 + else
52092 + return NULL;
52093 +}
52094 +
52095 +static struct acl_object_label *
52096 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52097 + const struct acl_subject_label *subj)
52098 +{
52099 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52100 + struct acl_object_label *match;
52101 +
52102 + match = subj->obj_hash[index];
52103 +
52104 + while (match && (match->inode != ino || match->device != dev ||
52105 + !(match->mode & GR_DELETED))) {
52106 + match = match->next;
52107 + }
52108 +
52109 + if (match && (match->mode & GR_DELETED))
52110 + return match;
52111 +
52112 + match = subj->obj_hash[index];
52113 +
52114 + while (match && (match->inode != ino || match->device != dev ||
52115 + (match->mode & GR_DELETED))) {
52116 + match = match->next;
52117 + }
52118 +
52119 + if (match && !(match->mode & GR_DELETED))
52120 + return match;
52121 + else
52122 + return NULL;
52123 +}
52124 +
52125 +static struct name_entry *
52126 +lookup_name_entry(const char *name)
52127 +{
52128 + unsigned int len = strlen(name);
52129 + unsigned int key = full_name_hash(name, len);
52130 + unsigned int index = key % name_set.n_size;
52131 + struct name_entry *match;
52132 +
52133 + match = name_set.n_hash[index];
52134 +
52135 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52136 + match = match->next;
52137 +
52138 + return match;
52139 +}
52140 +
52141 +static struct name_entry *
52142 +lookup_name_entry_create(const char *name)
52143 +{
52144 + unsigned int len = strlen(name);
52145 + unsigned int key = full_name_hash(name, len);
52146 + unsigned int index = key % name_set.n_size;
52147 + struct name_entry *match;
52148 +
52149 + match = name_set.n_hash[index];
52150 +
52151 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52152 + !match->deleted))
52153 + match = match->next;
52154 +
52155 + if (match && match->deleted)
52156 + return match;
52157 +
52158 + match = name_set.n_hash[index];
52159 +
52160 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52161 + match->deleted))
52162 + match = match->next;
52163 +
52164 + if (match && !match->deleted)
52165 + return match;
52166 + else
52167 + return NULL;
52168 +}
52169 +
52170 +static struct inodev_entry *
52171 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52172 +{
52173 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52174 + struct inodev_entry *match;
52175 +
52176 + match = inodev_set.i_hash[index];
52177 +
52178 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52179 + match = match->next;
52180 +
52181 + return match;
52182 +}
52183 +
52184 +static void
52185 +insert_inodev_entry(struct inodev_entry *entry)
52186 +{
52187 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52188 + inodev_set.i_size);
52189 + struct inodev_entry **curr;
52190 +
52191 + entry->prev = NULL;
52192 +
52193 + curr = &inodev_set.i_hash[index];
52194 + if (*curr != NULL)
52195 + (*curr)->prev = entry;
52196 +
52197 + entry->next = *curr;
52198 + *curr = entry;
52199 +
52200 + return;
52201 +}
52202 +
52203 +static void
52204 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52205 +{
52206 + unsigned int index =
52207 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52208 + struct acl_role_label **curr;
52209 + struct acl_role_label *tmp, *tmp2;
52210 +
52211 + curr = &acl_role_set.r_hash[index];
52212 +
52213 + /* simple case, slot is empty, just set it to our role */
52214 + if (*curr == NULL) {
52215 + *curr = role;
52216 + } else {
52217 + /* example:
52218 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52219 + 2 -> 3
52220 + */
52221 + /* first check to see if we can already be reached via this slot */
52222 + tmp = *curr;
52223 + while (tmp && tmp != role)
52224 + tmp = tmp->next;
52225 + if (tmp == role) {
52226 + /* we don't need to add ourselves to this slot's chain */
52227 + return;
52228 + }
52229 + /* we need to add ourselves to this chain, two cases */
52230 + if (role->next == NULL) {
52231 + /* simple case, append the current chain to our role */
52232 + role->next = *curr;
52233 + *curr = role;
52234 + } else {
52235 + /* 1 -> 2 -> 3 -> 4
52236 + 2 -> 3 -> 4
52237 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52238 + */
52239 + /* trickier case: walk our role's chain until we find
52240 + the role for the start of the current slot's chain */
52241 + tmp = role;
52242 + tmp2 = *curr;
52243 + while (tmp->next && tmp->next != tmp2)
52244 + tmp = tmp->next;
52245 + if (tmp->next == tmp2) {
52246 + /* from example above, we found 3, so just
52247 + replace this slot's chain with ours */
52248 + *curr = role;
52249 + } else {
52250 + /* we didn't find a subset of our role's chain
52251 + in the current slot's chain, so append their
52252 + chain to ours, and set us as the first role in
52253 + the slot's chain
52254 +
52255 + we could fold this case with the case above,
52256 + but making it explicit for clarity
52257 + */
52258 + tmp->next = tmp2;
52259 + *curr = role;
52260 + }
52261 + }
52262 + }
52263 +
52264 + return;
52265 +}
52266 +
52267 +static void
52268 +insert_acl_role_label(struct acl_role_label *role)
52269 +{
52270 + int i;
52271 +
52272 + if (role_list == NULL) {
52273 + role_list = role;
52274 + role->prev = NULL;
52275 + } else {
52276 + role->prev = role_list;
52277 + role_list = role;
52278 + }
52279 +
52280 + /* used for hash chains */
52281 + role->next = NULL;
52282 +
52283 + if (role->roletype & GR_ROLE_DOMAIN) {
52284 + for (i = 0; i < role->domain_child_num; i++)
52285 + __insert_acl_role_label(role, role->domain_children[i]);
52286 + } else
52287 + __insert_acl_role_label(role, role->uidgid);
52288 +}
52289 +
52290 +static int
52291 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52292 +{
52293 + struct name_entry **curr, *nentry;
52294 + struct inodev_entry *ientry;
52295 + unsigned int len = strlen(name);
52296 + unsigned int key = full_name_hash(name, len);
52297 + unsigned int index = key % name_set.n_size;
52298 +
52299 + curr = &name_set.n_hash[index];
52300 +
52301 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52302 + curr = &((*curr)->next);
52303 +
52304 + if (*curr != NULL)
52305 + return 1;
52306 +
52307 + nentry = acl_alloc(sizeof (struct name_entry));
52308 + if (nentry == NULL)
52309 + return 0;
52310 + ientry = acl_alloc(sizeof (struct inodev_entry));
52311 + if (ientry == NULL)
52312 + return 0;
52313 + ientry->nentry = nentry;
52314 +
52315 + nentry->key = key;
52316 + nentry->name = name;
52317 + nentry->inode = inode;
52318 + nentry->device = device;
52319 + nentry->len = len;
52320 + nentry->deleted = deleted;
52321 +
52322 + nentry->prev = NULL;
52323 + curr = &name_set.n_hash[index];
52324 + if (*curr != NULL)
52325 + (*curr)->prev = nentry;
52326 + nentry->next = *curr;
52327 + *curr = nentry;
52328 +
52329 + /* insert us into the table searchable by inode/dev */
52330 + insert_inodev_entry(ientry);
52331 +
52332 + return 1;
52333 +}
52334 +
52335 +static void
52336 +insert_acl_obj_label(struct acl_object_label *obj,
52337 + struct acl_subject_label *subj)
52338 +{
52339 + unsigned int index =
52340 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52341 + struct acl_object_label **curr;
52342 +
52343 +
52344 + obj->prev = NULL;
52345 +
52346 + curr = &subj->obj_hash[index];
52347 + if (*curr != NULL)
52348 + (*curr)->prev = obj;
52349 +
52350 + obj->next = *curr;
52351 + *curr = obj;
52352 +
52353 + return;
52354 +}
52355 +
52356 +static void
52357 +insert_acl_subj_label(struct acl_subject_label *obj,
52358 + struct acl_role_label *role)
52359 +{
52360 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52361 + struct acl_subject_label **curr;
52362 +
52363 + obj->prev = NULL;
52364 +
52365 + curr = &role->subj_hash[index];
52366 + if (*curr != NULL)
52367 + (*curr)->prev = obj;
52368 +
52369 + obj->next = *curr;
52370 + *curr = obj;
52371 +
52372 + return;
52373 +}
52374 +
52375 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52376 +
52377 +static void *
52378 +create_table(__u32 * len, int elementsize)
52379 +{
52380 + unsigned int table_sizes[] = {
52381 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52382 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52383 + 4194301, 8388593, 16777213, 33554393, 67108859
52384 + };
52385 + void *newtable = NULL;
52386 + unsigned int pwr = 0;
52387 +
52388 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52389 + table_sizes[pwr] <= *len)
52390 + pwr++;
52391 +
52392 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52393 + return newtable;
52394 +
52395 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52396 + newtable =
52397 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52398 + else
52399 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52400 +
52401 + *len = table_sizes[pwr];
52402 +
52403 + return newtable;
52404 +}
52405 +
52406 +static int
52407 +init_variables(const struct gr_arg *arg)
52408 +{
52409 + struct task_struct *reaper = init_pid_ns.child_reaper;
52410 + unsigned int stacksize;
52411 +
52412 + subj_map_set.s_size = arg->role_db.num_subjects;
52413 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52414 + name_set.n_size = arg->role_db.num_objects;
52415 + inodev_set.i_size = arg->role_db.num_objects;
52416 +
52417 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52418 + !name_set.n_size || !inodev_set.i_size)
52419 + return 1;
52420 +
52421 + if (!gr_init_uidset())
52422 + return 1;
52423 +
52424 + /* set up the stack that holds allocation info */
52425 +
52426 + stacksize = arg->role_db.num_pointers + 5;
52427 +
52428 + if (!acl_alloc_stack_init(stacksize))
52429 + return 1;
52430 +
52431 + /* grab reference for the real root dentry and vfsmount */
52432 + get_fs_root(reaper->fs, &real_root);
52433 +
52434 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52435 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52436 +#endif
52437 +
52438 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52439 + if (fakefs_obj_rw == NULL)
52440 + return 1;
52441 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52442 +
52443 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52444 + if (fakefs_obj_rwx == NULL)
52445 + return 1;
52446 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52447 +
52448 + subj_map_set.s_hash =
52449 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52450 + acl_role_set.r_hash =
52451 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52452 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52453 + inodev_set.i_hash =
52454 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52455 +
52456 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52457 + !name_set.n_hash || !inodev_set.i_hash)
52458 + return 1;
52459 +
52460 + memset(subj_map_set.s_hash, 0,
52461 + sizeof(struct subject_map *) * subj_map_set.s_size);
52462 + memset(acl_role_set.r_hash, 0,
52463 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52464 + memset(name_set.n_hash, 0,
52465 + sizeof (struct name_entry *) * name_set.n_size);
52466 + memset(inodev_set.i_hash, 0,
52467 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52468 +
52469 + return 0;
52470 +}
52471 +
52472 +/* free information not needed after startup
52473 + currently contains user->kernel pointer mappings for subjects
52474 +*/
52475 +
52476 +static void
52477 +free_init_variables(void)
52478 +{
52479 + __u32 i;
52480 +
52481 + if (subj_map_set.s_hash) {
52482 + for (i = 0; i < subj_map_set.s_size; i++) {
52483 + if (subj_map_set.s_hash[i]) {
52484 + kfree(subj_map_set.s_hash[i]);
52485 + subj_map_set.s_hash[i] = NULL;
52486 + }
52487 + }
52488 +
52489 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52490 + PAGE_SIZE)
52491 + kfree(subj_map_set.s_hash);
52492 + else
52493 + vfree(subj_map_set.s_hash);
52494 + }
52495 +
52496 + return;
52497 +}
52498 +
52499 +static void
52500 +free_variables(void)
52501 +{
52502 + struct acl_subject_label *s;
52503 + struct acl_role_label *r;
52504 + struct task_struct *task, *task2;
52505 + unsigned int x;
52506 +
52507 + gr_clear_learn_entries();
52508 +
52509 + read_lock(&tasklist_lock);
52510 + do_each_thread(task2, task) {
52511 + task->acl_sp_role = 0;
52512 + task->acl_role_id = 0;
52513 + task->acl = NULL;
52514 + task->role = NULL;
52515 + } while_each_thread(task2, task);
52516 + read_unlock(&tasklist_lock);
52517 +
52518 + /* release the reference to the real root dentry and vfsmount */
52519 + path_put(&real_root);
52520 + memset(&real_root, 0, sizeof(real_root));
52521 +
52522 + /* free all object hash tables */
52523 +
52524 + FOR_EACH_ROLE_START(r)
52525 + if (r->subj_hash == NULL)
52526 + goto next_role;
52527 + FOR_EACH_SUBJECT_START(r, s, x)
52528 + if (s->obj_hash == NULL)
52529 + break;
52530 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52531 + kfree(s->obj_hash);
52532 + else
52533 + vfree(s->obj_hash);
52534 + FOR_EACH_SUBJECT_END(s, x)
52535 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52536 + if (s->obj_hash == NULL)
52537 + break;
52538 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52539 + kfree(s->obj_hash);
52540 + else
52541 + vfree(s->obj_hash);
52542 + FOR_EACH_NESTED_SUBJECT_END(s)
52543 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52544 + kfree(r->subj_hash);
52545 + else
52546 + vfree(r->subj_hash);
52547 + r->subj_hash = NULL;
52548 +next_role:
52549 + FOR_EACH_ROLE_END(r)
52550 +
52551 + acl_free_all();
52552 +
52553 + if (acl_role_set.r_hash) {
52554 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52555 + PAGE_SIZE)
52556 + kfree(acl_role_set.r_hash);
52557 + else
52558 + vfree(acl_role_set.r_hash);
52559 + }
52560 + if (name_set.n_hash) {
52561 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52562 + PAGE_SIZE)
52563 + kfree(name_set.n_hash);
52564 + else
52565 + vfree(name_set.n_hash);
52566 + }
52567 +
52568 + if (inodev_set.i_hash) {
52569 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52570 + PAGE_SIZE)
52571 + kfree(inodev_set.i_hash);
52572 + else
52573 + vfree(inodev_set.i_hash);
52574 + }
52575 +
52576 + gr_free_uidset();
52577 +
52578 + memset(&name_set, 0, sizeof (struct name_db));
52579 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52580 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52581 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52582 +
52583 + default_role = NULL;
52584 + kernel_role = NULL;
52585 + role_list = NULL;
52586 +
52587 + return;
52588 +}
52589 +
52590 +static __u32
52591 +count_user_objs(struct acl_object_label *userp)
52592 +{
52593 + struct acl_object_label o_tmp;
52594 + __u32 num = 0;
52595 +
52596 + while (userp) {
52597 + if (copy_from_user(&o_tmp, userp,
52598 + sizeof (struct acl_object_label)))
52599 + break;
52600 +
52601 + userp = o_tmp.prev;
52602 + num++;
52603 + }
52604 +
52605 + return num;
52606 +}
52607 +
52608 +static struct acl_subject_label *
52609 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52610 +
52611 +static int
52612 +copy_user_glob(struct acl_object_label *obj)
52613 +{
52614 + struct acl_object_label *g_tmp, **guser;
52615 + unsigned int len;
52616 + char *tmp;
52617 +
52618 + if (obj->globbed == NULL)
52619 + return 0;
52620 +
52621 + guser = &obj->globbed;
52622 + while (*guser) {
52623 + g_tmp = (struct acl_object_label *)
52624 + acl_alloc(sizeof (struct acl_object_label));
52625 + if (g_tmp == NULL)
52626 + return -ENOMEM;
52627 +
52628 + if (copy_from_user(g_tmp, *guser,
52629 + sizeof (struct acl_object_label)))
52630 + return -EFAULT;
52631 +
52632 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52633 +
52634 + if (!len || len >= PATH_MAX)
52635 + return -EINVAL;
52636 +
52637 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52638 + return -ENOMEM;
52639 +
52640 + if (copy_from_user(tmp, g_tmp->filename, len))
52641 + return -EFAULT;
52642 + tmp[len-1] = '\0';
52643 + g_tmp->filename = tmp;
52644 +
52645 + *guser = g_tmp;
52646 + guser = &(g_tmp->next);
52647 + }
52648 +
52649 + return 0;
52650 +}
52651 +
52652 +static int
52653 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52654 + struct acl_role_label *role)
52655 +{
52656 + struct acl_object_label *o_tmp;
52657 + unsigned int len;
52658 + int ret;
52659 + char *tmp;
52660 +
52661 + while (userp) {
52662 + if ((o_tmp = (struct acl_object_label *)
52663 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52664 + return -ENOMEM;
52665 +
52666 + if (copy_from_user(o_tmp, userp,
52667 + sizeof (struct acl_object_label)))
52668 + return -EFAULT;
52669 +
52670 + userp = o_tmp->prev;
52671 +
52672 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52673 +
52674 + if (!len || len >= PATH_MAX)
52675 + return -EINVAL;
52676 +
52677 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52678 + return -ENOMEM;
52679 +
52680 + if (copy_from_user(tmp, o_tmp->filename, len))
52681 + return -EFAULT;
52682 + tmp[len-1] = '\0';
52683 + o_tmp->filename = tmp;
52684 +
52685 + insert_acl_obj_label(o_tmp, subj);
52686 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52687 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52688 + return -ENOMEM;
52689 +
52690 + ret = copy_user_glob(o_tmp);
52691 + if (ret)
52692 + return ret;
52693 +
52694 + if (o_tmp->nested) {
52695 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52696 + if (IS_ERR(o_tmp->nested))
52697 + return PTR_ERR(o_tmp->nested);
52698 +
52699 + /* insert into nested subject list */
52700 + o_tmp->nested->next = role->hash->first;
52701 + role->hash->first = o_tmp->nested;
52702 + }
52703 + }
52704 +
52705 + return 0;
52706 +}
52707 +
52708 +static __u32
52709 +count_user_subjs(struct acl_subject_label *userp)
52710 +{
52711 + struct acl_subject_label s_tmp;
52712 + __u32 num = 0;
52713 +
52714 + while (userp) {
52715 + if (copy_from_user(&s_tmp, userp,
52716 + sizeof (struct acl_subject_label)))
52717 + break;
52718 +
52719 + userp = s_tmp.prev;
52720 + /* do not count nested subjects against this count, since
52721 + they are not included in the hash table, but are
52722 + attached to objects. We have already counted
52723 + the subjects in userspace for the allocation
52724 + stack
52725 + */
52726 + if (!(s_tmp.mode & GR_NESTED))
52727 + num++;
52728 + }
52729 +
52730 + return num;
52731 +}
52732 +
52733 +static int
52734 +copy_user_allowedips(struct acl_role_label *rolep)
52735 +{
52736 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52737 +
52738 + ruserip = rolep->allowed_ips;
52739 +
52740 + while (ruserip) {
52741 + rlast = rtmp;
52742 +
52743 + if ((rtmp = (struct role_allowed_ip *)
52744 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52745 + return -ENOMEM;
52746 +
52747 + if (copy_from_user(rtmp, ruserip,
52748 + sizeof (struct role_allowed_ip)))
52749 + return -EFAULT;
52750 +
52751 + ruserip = rtmp->prev;
52752 +
52753 + if (!rlast) {
52754 + rtmp->prev = NULL;
52755 + rolep->allowed_ips = rtmp;
52756 + } else {
52757 + rlast->next = rtmp;
52758 + rtmp->prev = rlast;
52759 + }
52760 +
52761 + if (!ruserip)
52762 + rtmp->next = NULL;
52763 + }
52764 +
52765 + return 0;
52766 +}
52767 +
52768 +static int
52769 +copy_user_transitions(struct acl_role_label *rolep)
52770 +{
52771 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52772 +
52773 + unsigned int len;
52774 + char *tmp;
52775 +
52776 + rusertp = rolep->transitions;
52777 +
52778 + while (rusertp) {
52779 + rlast = rtmp;
52780 +
52781 + if ((rtmp = (struct role_transition *)
52782 + acl_alloc(sizeof (struct role_transition))) == NULL)
52783 + return -ENOMEM;
52784 +
52785 + if (copy_from_user(rtmp, rusertp,
52786 + sizeof (struct role_transition)))
52787 + return -EFAULT;
52788 +
52789 + rusertp = rtmp->prev;
52790 +
52791 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52792 +
52793 + if (!len || len >= GR_SPROLE_LEN)
52794 + return -EINVAL;
52795 +
52796 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52797 + return -ENOMEM;
52798 +
52799 + if (copy_from_user(tmp, rtmp->rolename, len))
52800 + return -EFAULT;
52801 + tmp[len-1] = '\0';
52802 + rtmp->rolename = tmp;
52803 +
52804 + if (!rlast) {
52805 + rtmp->prev = NULL;
52806 + rolep->transitions = rtmp;
52807 + } else {
52808 + rlast->next = rtmp;
52809 + rtmp->prev = rlast;
52810 + }
52811 +
52812 + if (!rusertp)
52813 + rtmp->next = NULL;
52814 + }
52815 +
52816 + return 0;
52817 +}
52818 +
52819 +static struct acl_subject_label *
52820 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52821 +{
52822 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52823 + unsigned int len;
52824 + char *tmp;
52825 + __u32 num_objs;
52826 + struct acl_ip_label **i_tmp, *i_utmp2;
52827 + struct gr_hash_struct ghash;
52828 + struct subject_map *subjmap;
52829 + unsigned int i_num;
52830 + int err;
52831 +
52832 + s_tmp = lookup_subject_map(userp);
52833 +
52834 + /* we've already copied this subject into the kernel, just return
52835 + the reference to it, and don't copy it over again
52836 + */
52837 + if (s_tmp)
52838 + return(s_tmp);
52839 +
52840 + if ((s_tmp = (struct acl_subject_label *)
52841 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52842 + return ERR_PTR(-ENOMEM);
52843 +
52844 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52845 + if (subjmap == NULL)
52846 + return ERR_PTR(-ENOMEM);
52847 +
52848 + subjmap->user = userp;
52849 + subjmap->kernel = s_tmp;
52850 + insert_subj_map_entry(subjmap);
52851 +
52852 + if (copy_from_user(s_tmp, userp,
52853 + sizeof (struct acl_subject_label)))
52854 + return ERR_PTR(-EFAULT);
52855 +
52856 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52857 +
52858 + if (!len || len >= PATH_MAX)
52859 + return ERR_PTR(-EINVAL);
52860 +
52861 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52862 + return ERR_PTR(-ENOMEM);
52863 +
52864 + if (copy_from_user(tmp, s_tmp->filename, len))
52865 + return ERR_PTR(-EFAULT);
52866 + tmp[len-1] = '\0';
52867 + s_tmp->filename = tmp;
52868 +
52869 + if (!strcmp(s_tmp->filename, "/"))
52870 + role->root_label = s_tmp;
52871 +
52872 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52873 + return ERR_PTR(-EFAULT);
52874 +
52875 + /* copy user and group transition tables */
52876 +
52877 + if (s_tmp->user_trans_num) {
52878 + uid_t *uidlist;
52879 +
52880 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52881 + if (uidlist == NULL)
52882 + return ERR_PTR(-ENOMEM);
52883 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52884 + return ERR_PTR(-EFAULT);
52885 +
52886 + s_tmp->user_transitions = uidlist;
52887 + }
52888 +
52889 + if (s_tmp->group_trans_num) {
52890 + gid_t *gidlist;
52891 +
52892 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52893 + if (gidlist == NULL)
52894 + return ERR_PTR(-ENOMEM);
52895 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52896 + return ERR_PTR(-EFAULT);
52897 +
52898 + s_tmp->group_transitions = gidlist;
52899 + }
52900 +
52901 + /* set up object hash table */
52902 + num_objs = count_user_objs(ghash.first);
52903 +
52904 + s_tmp->obj_hash_size = num_objs;
52905 + s_tmp->obj_hash =
52906 + (struct acl_object_label **)
52907 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52908 +
52909 + if (!s_tmp->obj_hash)
52910 + return ERR_PTR(-ENOMEM);
52911 +
52912 + memset(s_tmp->obj_hash, 0,
52913 + s_tmp->obj_hash_size *
52914 + sizeof (struct acl_object_label *));
52915 +
52916 + /* add in objects */
52917 + err = copy_user_objs(ghash.first, s_tmp, role);
52918 +
52919 + if (err)
52920 + return ERR_PTR(err);
52921 +
52922 + /* set pointer for parent subject */
52923 + if (s_tmp->parent_subject) {
52924 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52925 +
52926 + if (IS_ERR(s_tmp2))
52927 + return s_tmp2;
52928 +
52929 + s_tmp->parent_subject = s_tmp2;
52930 + }
52931 +
52932 + /* add in ip acls */
52933 +
52934 + if (!s_tmp->ip_num) {
52935 + s_tmp->ips = NULL;
52936 + goto insert;
52937 + }
52938 +
52939 + i_tmp =
52940 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52941 + sizeof (struct acl_ip_label *));
52942 +
52943 + if (!i_tmp)
52944 + return ERR_PTR(-ENOMEM);
52945 +
52946 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52947 + *(i_tmp + i_num) =
52948 + (struct acl_ip_label *)
52949 + acl_alloc(sizeof (struct acl_ip_label));
52950 + if (!*(i_tmp + i_num))
52951 + return ERR_PTR(-ENOMEM);
52952 +
52953 + if (copy_from_user
52954 + (&i_utmp2, s_tmp->ips + i_num,
52955 + sizeof (struct acl_ip_label *)))
52956 + return ERR_PTR(-EFAULT);
52957 +
52958 + if (copy_from_user
52959 + (*(i_tmp + i_num), i_utmp2,
52960 + sizeof (struct acl_ip_label)))
52961 + return ERR_PTR(-EFAULT);
52962 +
52963 + if ((*(i_tmp + i_num))->iface == NULL)
52964 + continue;
52965 +
52966 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52967 + if (!len || len >= IFNAMSIZ)
52968 + return ERR_PTR(-EINVAL);
52969 + tmp = acl_alloc(len);
52970 + if (tmp == NULL)
52971 + return ERR_PTR(-ENOMEM);
52972 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52973 + return ERR_PTR(-EFAULT);
52974 + (*(i_tmp + i_num))->iface = tmp;
52975 + }
52976 +
52977 + s_tmp->ips = i_tmp;
52978 +
52979 +insert:
52980 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52981 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52982 + return ERR_PTR(-ENOMEM);
52983 +
52984 + return s_tmp;
52985 +}
52986 +
52987 +static int
52988 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52989 +{
52990 + struct acl_subject_label s_pre;
52991 + struct acl_subject_label * ret;
52992 + int err;
52993 +
52994 + while (userp) {
52995 + if (copy_from_user(&s_pre, userp,
52996 + sizeof (struct acl_subject_label)))
52997 + return -EFAULT;
52998 +
52999 + /* do not add nested subjects here, add
53000 + while parsing objects
53001 + */
53002 +
53003 + if (s_pre.mode & GR_NESTED) {
53004 + userp = s_pre.prev;
53005 + continue;
53006 + }
53007 +
53008 + ret = do_copy_user_subj(userp, role);
53009 +
53010 + err = PTR_ERR(ret);
53011 + if (IS_ERR(ret))
53012 + return err;
53013 +
53014 + insert_acl_subj_label(ret, role);
53015 +
53016 + userp = s_pre.prev;
53017 + }
53018 +
53019 + return 0;
53020 +}
53021 +
53022 +static int
53023 +copy_user_acl(struct gr_arg *arg)
53024 +{
53025 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53026 + struct acl_subject_label *subj_list;
53027 + struct sprole_pw *sptmp;
53028 + struct gr_hash_struct *ghash;
53029 + uid_t *domainlist;
53030 + unsigned int r_num;
53031 + unsigned int len;
53032 + char *tmp;
53033 + int err = 0;
53034 + __u16 i;
53035 + __u32 num_subjs;
53036 +
53037 + /* we need a default and kernel role */
53038 + if (arg->role_db.num_roles < 2)
53039 + return -EINVAL;
53040 +
53041 + /* copy special role authentication info from userspace */
53042 +
53043 + num_sprole_pws = arg->num_sprole_pws;
53044 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53045 +
53046 + if (!acl_special_roles && num_sprole_pws)
53047 + return -ENOMEM;
53048 +
53049 + for (i = 0; i < num_sprole_pws; i++) {
53050 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53051 + if (!sptmp)
53052 + return -ENOMEM;
53053 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53054 + sizeof (struct sprole_pw)))
53055 + return -EFAULT;
53056 +
53057 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53058 +
53059 + if (!len || len >= GR_SPROLE_LEN)
53060 + return -EINVAL;
53061 +
53062 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53063 + return -ENOMEM;
53064 +
53065 + if (copy_from_user(tmp, sptmp->rolename, len))
53066 + return -EFAULT;
53067 +
53068 + tmp[len-1] = '\0';
53069 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53070 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53071 +#endif
53072 + sptmp->rolename = tmp;
53073 + acl_special_roles[i] = sptmp;
53074 + }
53075 +
53076 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53077 +
53078 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53079 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53080 +
53081 + if (!r_tmp)
53082 + return -ENOMEM;
53083 +
53084 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53085 + sizeof (struct acl_role_label *)))
53086 + return -EFAULT;
53087 +
53088 + if (copy_from_user(r_tmp, r_utmp2,
53089 + sizeof (struct acl_role_label)))
53090 + return -EFAULT;
53091 +
53092 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53093 +
53094 + if (!len || len >= PATH_MAX)
53095 + return -EINVAL;
53096 +
53097 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53098 + return -ENOMEM;
53099 +
53100 + if (copy_from_user(tmp, r_tmp->rolename, len))
53101 + return -EFAULT;
53102 +
53103 + tmp[len-1] = '\0';
53104 + r_tmp->rolename = tmp;
53105 +
53106 + if (!strcmp(r_tmp->rolename, "default")
53107 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53108 + default_role = r_tmp;
53109 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53110 + kernel_role = r_tmp;
53111 + }
53112 +
53113 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53114 + return -ENOMEM;
53115 +
53116 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53117 + return -EFAULT;
53118 +
53119 + r_tmp->hash = ghash;
53120 +
53121 + num_subjs = count_user_subjs(r_tmp->hash->first);
53122 +
53123 + r_tmp->subj_hash_size = num_subjs;
53124 + r_tmp->subj_hash =
53125 + (struct acl_subject_label **)
53126 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53127 +
53128 + if (!r_tmp->subj_hash)
53129 + return -ENOMEM;
53130 +
53131 + err = copy_user_allowedips(r_tmp);
53132 + if (err)
53133 + return err;
53134 +
53135 + /* copy domain info */
53136 + if (r_tmp->domain_children != NULL) {
53137 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53138 + if (domainlist == NULL)
53139 + return -ENOMEM;
53140 +
53141 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53142 + return -EFAULT;
53143 +
53144 + r_tmp->domain_children = domainlist;
53145 + }
53146 +
53147 + err = copy_user_transitions(r_tmp);
53148 + if (err)
53149 + return err;
53150 +
53151 + memset(r_tmp->subj_hash, 0,
53152 + r_tmp->subj_hash_size *
53153 + sizeof (struct acl_subject_label *));
53154 +
53155 + /* acquire the list of subjects, then NULL out
53156 + the list prior to parsing the subjects for this role,
53157 + as during this parsing the list is replaced with a list
53158 + of *nested* subjects for the role
53159 + */
53160 + subj_list = r_tmp->hash->first;
53161 +
53162 + /* set nested subject list to null */
53163 + r_tmp->hash->first = NULL;
53164 +
53165 + err = copy_user_subjs(subj_list, r_tmp);
53166 +
53167 + if (err)
53168 + return err;
53169 +
53170 + insert_acl_role_label(r_tmp);
53171 + }
53172 +
53173 + if (default_role == NULL || kernel_role == NULL)
53174 + return -EINVAL;
53175 +
53176 + return err;
53177 +}
53178 +
53179 +static int
53180 +gracl_init(struct gr_arg *args)
53181 +{
53182 + int error = 0;
53183 +
53184 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53185 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53186 +
53187 + if (init_variables(args)) {
53188 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53189 + error = -ENOMEM;
53190 + free_variables();
53191 + goto out;
53192 + }
53193 +
53194 + error = copy_user_acl(args);
53195 + free_init_variables();
53196 + if (error) {
53197 + free_variables();
53198 + goto out;
53199 + }
53200 +
53201 + if ((error = gr_set_acls(0))) {
53202 + free_variables();
53203 + goto out;
53204 + }
53205 +
53206 + pax_open_kernel();
53207 + gr_status |= GR_READY;
53208 + pax_close_kernel();
53209 +
53210 + out:
53211 + return error;
53212 +}
53213 +
53214 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53215 +
53216 +static int
53217 +glob_match(const char *p, const char *n)
53218 +{
53219 + char c;
53220 +
53221 + while ((c = *p++) != '\0') {
53222 + switch (c) {
53223 + case '?':
53224 + if (*n == '\0')
53225 + return 1;
53226 + else if (*n == '/')
53227 + return 1;
53228 + break;
53229 + case '\\':
53230 + if (*n != c)
53231 + return 1;
53232 + break;
53233 + case '*':
53234 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53235 + if (*n == '/')
53236 + return 1;
53237 + else if (c == '?') {
53238 + if (*n == '\0')
53239 + return 1;
53240 + else
53241 + ++n;
53242 + }
53243 + }
53244 + if (c == '\0') {
53245 + return 0;
53246 + } else {
53247 + const char *endp;
53248 +
53249 + if ((endp = strchr(n, '/')) == NULL)
53250 + endp = n + strlen(n);
53251 +
53252 + if (c == '[') {
53253 + for (--p; n < endp; ++n)
53254 + if (!glob_match(p, n))
53255 + return 0;
53256 + } else if (c == '/') {
53257 + while (*n != '\0' && *n != '/')
53258 + ++n;
53259 + if (*n == '/' && !glob_match(p, n + 1))
53260 + return 0;
53261 + } else {
53262 + for (--p; n < endp; ++n)
53263 + if (*n == c && !glob_match(p, n))
53264 + return 0;
53265 + }
53266 +
53267 + return 1;
53268 + }
53269 + case '[':
53270 + {
53271 + int not;
53272 + char cold;
53273 +
53274 + if (*n == '\0' || *n == '/')
53275 + return 1;
53276 +
53277 + not = (*p == '!' || *p == '^');
53278 + if (not)
53279 + ++p;
53280 +
53281 + c = *p++;
53282 + for (;;) {
53283 + unsigned char fn = (unsigned char)*n;
53284 +
53285 + if (c == '\0')
53286 + return 1;
53287 + else {
53288 + if (c == fn)
53289 + goto matched;
53290 + cold = c;
53291 + c = *p++;
53292 +
53293 + if (c == '-' && *p != ']') {
53294 + unsigned char cend = *p++;
53295 +
53296 + if (cend == '\0')
53297 + return 1;
53298 +
53299 + if (cold <= fn && fn <= cend)
53300 + goto matched;
53301 +
53302 + c = *p++;
53303 + }
53304 + }
53305 +
53306 + if (c == ']')
53307 + break;
53308 + }
53309 + if (!not)
53310 + return 1;
53311 + break;
53312 + matched:
53313 + while (c != ']') {
53314 + if (c == '\0')
53315 + return 1;
53316 +
53317 + c = *p++;
53318 + }
53319 + if (not)
53320 + return 1;
53321 + }
53322 + break;
53323 + default:
53324 + if (c != *n)
53325 + return 1;
53326 + }
53327 +
53328 + ++n;
53329 + }
53330 +
53331 + if (*n == '\0')
53332 + return 0;
53333 +
53334 + if (*n == '/')
53335 + return 0;
53336 +
53337 + return 1;
53338 +}
53339 +
53340 +static struct acl_object_label *
53341 +chk_glob_label(struct acl_object_label *globbed,
53342 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53343 +{
53344 + struct acl_object_label *tmp;
53345 +
53346 + if (*path == NULL)
53347 + *path = gr_to_filename_nolock(dentry, mnt);
53348 +
53349 + tmp = globbed;
53350 +
53351 + while (tmp) {
53352 + if (!glob_match(tmp->filename, *path))
53353 + return tmp;
53354 + tmp = tmp->next;
53355 + }
53356 +
53357 + return NULL;
53358 +}
53359 +
53360 +static struct acl_object_label *
53361 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53362 + const ino_t curr_ino, const dev_t curr_dev,
53363 + const struct acl_subject_label *subj, char **path, const int checkglob)
53364 +{
53365 + struct acl_subject_label *tmpsubj;
53366 + struct acl_object_label *retval;
53367 + struct acl_object_label *retval2;
53368 +
53369 + tmpsubj = (struct acl_subject_label *) subj;
53370 + read_lock(&gr_inode_lock);
53371 + do {
53372 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53373 + if (retval) {
53374 + if (checkglob && retval->globbed) {
53375 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53376 + if (retval2)
53377 + retval = retval2;
53378 + }
53379 + break;
53380 + }
53381 + } while ((tmpsubj = tmpsubj->parent_subject));
53382 + read_unlock(&gr_inode_lock);
53383 +
53384 + return retval;
53385 +}
53386 +
53387 +static __inline__ struct acl_object_label *
53388 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53389 + struct dentry *curr_dentry,
53390 + const struct acl_subject_label *subj, char **path, const int checkglob)
53391 +{
53392 + int newglob = checkglob;
53393 + ino_t inode;
53394 + dev_t device;
53395 +
53396 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53397 + as we don't want a / * rule to match instead of the / object
53398 + don't do this for create lookups that call this function though, since they're looking up
53399 + on the parent and thus need globbing checks on all paths
53400 + */
53401 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53402 + newglob = GR_NO_GLOB;
53403 +
53404 + spin_lock(&curr_dentry->d_lock);
53405 + inode = curr_dentry->d_inode->i_ino;
53406 + device = __get_dev(curr_dentry);
53407 + spin_unlock(&curr_dentry->d_lock);
53408 +
53409 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53410 +}
53411 +
53412 +static struct acl_object_label *
53413 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53414 + const struct acl_subject_label *subj, char *path, const int checkglob)
53415 +{
53416 + struct dentry *dentry = (struct dentry *) l_dentry;
53417 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53418 + struct mount *real_mnt = real_mount(mnt);
53419 + struct acl_object_label *retval;
53420 + struct dentry *parent;
53421 +
53422 + write_seqlock(&rename_lock);
53423 + br_read_lock(&vfsmount_lock);
53424 +
53425 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53426 +#ifdef CONFIG_NET
53427 + mnt == sock_mnt ||
53428 +#endif
53429 +#ifdef CONFIG_HUGETLBFS
53430 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53431 +#endif
53432 + /* ignore Eric Biederman */
53433 + IS_PRIVATE(l_dentry->d_inode))) {
53434 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53435 + goto out;
53436 + }
53437 +
53438 + for (;;) {
53439 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53440 + break;
53441 +
53442 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53443 + if (!mnt_has_parent(real_mnt))
53444 + break;
53445 +
53446 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53447 + if (retval != NULL)
53448 + goto out;
53449 +
53450 + dentry = real_mnt->mnt_mountpoint;
53451 + real_mnt = real_mnt->mnt_parent;
53452 + mnt = &real_mnt->mnt;
53453 + continue;
53454 + }
53455 +
53456 + parent = dentry->d_parent;
53457 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53458 + if (retval != NULL)
53459 + goto out;
53460 +
53461 + dentry = parent;
53462 + }
53463 +
53464 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53465 +
53466 + /* real_root is pinned so we don't have to hold a reference */
53467 + if (retval == NULL)
53468 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53469 +out:
53470 + br_read_unlock(&vfsmount_lock);
53471 + write_sequnlock(&rename_lock);
53472 +
53473 + BUG_ON(retval == NULL);
53474 +
53475 + return retval;
53476 +}
53477 +
53478 +static __inline__ struct acl_object_label *
53479 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53480 + const struct acl_subject_label *subj)
53481 +{
53482 + char *path = NULL;
53483 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53484 +}
53485 +
53486 +static __inline__ struct acl_object_label *
53487 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53488 + const struct acl_subject_label *subj)
53489 +{
53490 + char *path = NULL;
53491 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53492 +}
53493 +
53494 +static __inline__ struct acl_object_label *
53495 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53496 + const struct acl_subject_label *subj, char *path)
53497 +{
53498 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53499 +}
53500 +
53501 +static struct acl_subject_label *
53502 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53503 + const struct acl_role_label *role)
53504 +{
53505 + struct dentry *dentry = (struct dentry *) l_dentry;
53506 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53507 + struct mount *real_mnt = real_mount(mnt);
53508 + struct acl_subject_label *retval;
53509 + struct dentry *parent;
53510 +
53511 + write_seqlock(&rename_lock);
53512 + br_read_lock(&vfsmount_lock);
53513 +
53514 + for (;;) {
53515 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53516 + break;
53517 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53518 + if (!mnt_has_parent(real_mnt))
53519 + break;
53520 +
53521 + spin_lock(&dentry->d_lock);
53522 + read_lock(&gr_inode_lock);
53523 + retval =
53524 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53525 + __get_dev(dentry), role);
53526 + read_unlock(&gr_inode_lock);
53527 + spin_unlock(&dentry->d_lock);
53528 + if (retval != NULL)
53529 + goto out;
53530 +
53531 + dentry = real_mnt->mnt_mountpoint;
53532 + real_mnt = real_mnt->mnt_parent;
53533 + mnt = &real_mnt->mnt;
53534 + continue;
53535 + }
53536 +
53537 + spin_lock(&dentry->d_lock);
53538 + read_lock(&gr_inode_lock);
53539 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53540 + __get_dev(dentry), role);
53541 + read_unlock(&gr_inode_lock);
53542 + parent = dentry->d_parent;
53543 + spin_unlock(&dentry->d_lock);
53544 +
53545 + if (retval != NULL)
53546 + goto out;
53547 +
53548 + dentry = parent;
53549 + }
53550 +
53551 + spin_lock(&dentry->d_lock);
53552 + read_lock(&gr_inode_lock);
53553 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53554 + __get_dev(dentry), role);
53555 + read_unlock(&gr_inode_lock);
53556 + spin_unlock(&dentry->d_lock);
53557 +
53558 + if (unlikely(retval == NULL)) {
53559 + /* real_root is pinned, we don't need to hold a reference */
53560 + read_lock(&gr_inode_lock);
53561 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53562 + __get_dev(real_root.dentry), role);
53563 + read_unlock(&gr_inode_lock);
53564 + }
53565 +out:
53566 + br_read_unlock(&vfsmount_lock);
53567 + write_sequnlock(&rename_lock);
53568 +
53569 + BUG_ON(retval == NULL);
53570 +
53571 + return retval;
53572 +}
53573 +
53574 +static void
53575 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53576 +{
53577 + struct task_struct *task = current;
53578 + const struct cred *cred = current_cred();
53579 +
53580 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53581 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53582 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53583 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53584 +
53585 + return;
53586 +}
53587 +
53588 +static void
53589 +gr_log_learn_id_change(const char type, const unsigned int real,
53590 + const unsigned int effective, const unsigned int fs)
53591 +{
53592 + struct task_struct *task = current;
53593 + const struct cred *cred = current_cred();
53594 +
53595 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53596 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53597 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53598 + type, real, effective, fs, &task->signal->saved_ip);
53599 +
53600 + return;
53601 +}
53602 +
53603 +__u32
53604 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53605 + const struct vfsmount * mnt)
53606 +{
53607 + __u32 retval = mode;
53608 + struct acl_subject_label *curracl;
53609 + struct acl_object_label *currobj;
53610 +
53611 + if (unlikely(!(gr_status & GR_READY)))
53612 + return (mode & ~GR_AUDITS);
53613 +
53614 + curracl = current->acl;
53615 +
53616 + currobj = chk_obj_label(dentry, mnt, curracl);
53617 + retval = currobj->mode & mode;
53618 +
53619 + /* if we're opening a specified transfer file for writing
53620 + (e.g. /dev/initctl), then transfer our role to init
53621 + */
53622 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53623 + current->role->roletype & GR_ROLE_PERSIST)) {
53624 + struct task_struct *task = init_pid_ns.child_reaper;
53625 +
53626 + if (task->role != current->role) {
53627 + task->acl_sp_role = 0;
53628 + task->acl_role_id = current->acl_role_id;
53629 + task->role = current->role;
53630 + rcu_read_lock();
53631 + read_lock(&grsec_exec_file_lock);
53632 + gr_apply_subject_to_task(task);
53633 + read_unlock(&grsec_exec_file_lock);
53634 + rcu_read_unlock();
53635 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53636 + }
53637 + }
53638 +
53639 + if (unlikely
53640 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53641 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53642 + __u32 new_mode = mode;
53643 +
53644 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53645 +
53646 + retval = new_mode;
53647 +
53648 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53649 + new_mode |= GR_INHERIT;
53650 +
53651 + if (!(mode & GR_NOLEARN))
53652 + gr_log_learn(dentry, mnt, new_mode);
53653 + }
53654 +
53655 + return retval;
53656 +}
53657 +
53658 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53659 + const struct dentry *parent,
53660 + const struct vfsmount *mnt)
53661 +{
53662 + struct name_entry *match;
53663 + struct acl_object_label *matchpo;
53664 + struct acl_subject_label *curracl;
53665 + char *path;
53666 +
53667 + if (unlikely(!(gr_status & GR_READY)))
53668 + return NULL;
53669 +
53670 + preempt_disable();
53671 + path = gr_to_filename_rbac(new_dentry, mnt);
53672 + match = lookup_name_entry_create(path);
53673 +
53674 + curracl = current->acl;
53675 +
53676 + if (match) {
53677 + read_lock(&gr_inode_lock);
53678 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53679 + read_unlock(&gr_inode_lock);
53680 +
53681 + if (matchpo) {
53682 + preempt_enable();
53683 + return matchpo;
53684 + }
53685 + }
53686 +
53687 + // lookup parent
53688 +
53689 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53690 +
53691 + preempt_enable();
53692 + return matchpo;
53693 +}
53694 +
53695 +__u32
53696 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53697 + const struct vfsmount * mnt, const __u32 mode)
53698 +{
53699 + struct acl_object_label *matchpo;
53700 + __u32 retval;
53701 +
53702 + if (unlikely(!(gr_status & GR_READY)))
53703 + return (mode & ~GR_AUDITS);
53704 +
53705 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53706 +
53707 + retval = matchpo->mode & mode;
53708 +
53709 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53710 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53711 + __u32 new_mode = mode;
53712 +
53713 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53714 +
53715 + gr_log_learn(new_dentry, mnt, new_mode);
53716 + return new_mode;
53717 + }
53718 +
53719 + return retval;
53720 +}
53721 +
53722 +__u32
53723 +gr_check_link(const struct dentry * new_dentry,
53724 + const struct dentry * parent_dentry,
53725 + const struct vfsmount * parent_mnt,
53726 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53727 +{
53728 + struct acl_object_label *obj;
53729 + __u32 oldmode, newmode;
53730 + __u32 needmode;
53731 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53732 + GR_DELETE | GR_INHERIT;
53733 +
53734 + if (unlikely(!(gr_status & GR_READY)))
53735 + return (GR_CREATE | GR_LINK);
53736 +
53737 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53738 + oldmode = obj->mode;
53739 +
53740 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53741 + newmode = obj->mode;
53742 +
53743 + needmode = newmode & checkmodes;
53744 +
53745 + // old name for hardlink must have at least the permissions of the new name
53746 + if ((oldmode & needmode) != needmode)
53747 + goto bad;
53748 +
53749 + // if old name had restrictions/auditing, make sure the new name does as well
53750 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53751 +
53752 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53753 + if (is_privileged_binary(old_dentry))
53754 + needmode |= GR_SETID;
53755 +
53756 + if ((newmode & needmode) != needmode)
53757 + goto bad;
53758 +
53759 + // enforce minimum permissions
53760 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53761 + return newmode;
53762 +bad:
53763 + needmode = oldmode;
53764 + if (is_privileged_binary(old_dentry))
53765 + needmode |= GR_SETID;
53766 +
53767 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53768 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53769 + return (GR_CREATE | GR_LINK);
53770 + } else if (newmode & GR_SUPPRESS)
53771 + return GR_SUPPRESS;
53772 + else
53773 + return 0;
53774 +}
53775 +
53776 +int
53777 +gr_check_hidden_task(const struct task_struct *task)
53778 +{
53779 + if (unlikely(!(gr_status & GR_READY)))
53780 + return 0;
53781 +
53782 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53783 + return 1;
53784 +
53785 + return 0;
53786 +}
53787 +
53788 +int
53789 +gr_check_protected_task(const struct task_struct *task)
53790 +{
53791 + if (unlikely(!(gr_status & GR_READY) || !task))
53792 + return 0;
53793 +
53794 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53795 + task->acl != current->acl)
53796 + return 1;
53797 +
53798 + return 0;
53799 +}
53800 +
53801 +int
53802 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53803 +{
53804 + struct task_struct *p;
53805 + int ret = 0;
53806 +
53807 + if (unlikely(!(gr_status & GR_READY) || !pid))
53808 + return ret;
53809 +
53810 + read_lock(&tasklist_lock);
53811 + do_each_pid_task(pid, type, p) {
53812 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53813 + p->acl != current->acl) {
53814 + ret = 1;
53815 + goto out;
53816 + }
53817 + } while_each_pid_task(pid, type, p);
53818 +out:
53819 + read_unlock(&tasklist_lock);
53820 +
53821 + return ret;
53822 +}
53823 +
53824 +void
53825 +gr_copy_label(struct task_struct *tsk)
53826 +{
53827 + tsk->signal->used_accept = 0;
53828 + tsk->acl_sp_role = 0;
53829 + tsk->acl_role_id = current->acl_role_id;
53830 + tsk->acl = current->acl;
53831 + tsk->role = current->role;
53832 + tsk->signal->curr_ip = current->signal->curr_ip;
53833 + tsk->signal->saved_ip = current->signal->saved_ip;
53834 + if (current->exec_file)
53835 + get_file(current->exec_file);
53836 + tsk->exec_file = current->exec_file;
53837 + tsk->is_writable = current->is_writable;
53838 + if (unlikely(current->signal->used_accept)) {
53839 + current->signal->curr_ip = 0;
53840 + current->signal->saved_ip = 0;
53841 + }
53842 +
53843 + return;
53844 +}
53845 +
53846 +static void
53847 +gr_set_proc_res(struct task_struct *task)
53848 +{
53849 + struct acl_subject_label *proc;
53850 + unsigned short i;
53851 +
53852 + proc = task->acl;
53853 +
53854 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53855 + return;
53856 +
53857 + for (i = 0; i < RLIM_NLIMITS; i++) {
53858 + if (!(proc->resmask & (1 << i)))
53859 + continue;
53860 +
53861 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53862 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53863 + }
53864 +
53865 + return;
53866 +}
53867 +
53868 +extern int __gr_process_user_ban(struct user_struct *user);
53869 +
53870 +int
53871 +gr_check_user_change(int real, int effective, int fs)
53872 +{
53873 + unsigned int i;
53874 + __u16 num;
53875 + uid_t *uidlist;
53876 + int curuid;
53877 + int realok = 0;
53878 + int effectiveok = 0;
53879 + int fsok = 0;
53880 +
53881 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53882 + struct user_struct *user;
53883 +
53884 + if (real == -1)
53885 + goto skipit;
53886 +
53887 + user = find_user(real);
53888 + if (user == NULL)
53889 + goto skipit;
53890 +
53891 + if (__gr_process_user_ban(user)) {
53892 + /* for find_user */
53893 + free_uid(user);
53894 + return 1;
53895 + }
53896 +
53897 + /* for find_user */
53898 + free_uid(user);
53899 +
53900 +skipit:
53901 +#endif
53902 +
53903 + if (unlikely(!(gr_status & GR_READY)))
53904 + return 0;
53905 +
53906 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53907 + gr_log_learn_id_change('u', real, effective, fs);
53908 +
53909 + num = current->acl->user_trans_num;
53910 + uidlist = current->acl->user_transitions;
53911 +
53912 + if (uidlist == NULL)
53913 + return 0;
53914 +
53915 + if (real == -1)
53916 + realok = 1;
53917 + if (effective == -1)
53918 + effectiveok = 1;
53919 + if (fs == -1)
53920 + fsok = 1;
53921 +
53922 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53923 + for (i = 0; i < num; i++) {
53924 + curuid = (int)uidlist[i];
53925 + if (real == curuid)
53926 + realok = 1;
53927 + if (effective == curuid)
53928 + effectiveok = 1;
53929 + if (fs == curuid)
53930 + fsok = 1;
53931 + }
53932 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53933 + for (i = 0; i < num; i++) {
53934 + curuid = (int)uidlist[i];
53935 + if (real == curuid)
53936 + break;
53937 + if (effective == curuid)
53938 + break;
53939 + if (fs == curuid)
53940 + break;
53941 + }
53942 + /* not in deny list */
53943 + if (i == num) {
53944 + realok = 1;
53945 + effectiveok = 1;
53946 + fsok = 1;
53947 + }
53948 + }
53949 +
53950 + if (realok && effectiveok && fsok)
53951 + return 0;
53952 + else {
53953 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53954 + return 1;
53955 + }
53956 +}
53957 +
53958 +int
53959 +gr_check_group_change(int real, int effective, int fs)
53960 +{
53961 + unsigned int i;
53962 + __u16 num;
53963 + gid_t *gidlist;
53964 + int curgid;
53965 + int realok = 0;
53966 + int effectiveok = 0;
53967 + int fsok = 0;
53968 +
53969 + if (unlikely(!(gr_status & GR_READY)))
53970 + return 0;
53971 +
53972 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53973 + gr_log_learn_id_change('g', real, effective, fs);
53974 +
53975 + num = current->acl->group_trans_num;
53976 + gidlist = current->acl->group_transitions;
53977 +
53978 + if (gidlist == NULL)
53979 + return 0;
53980 +
53981 + if (real == -1)
53982 + realok = 1;
53983 + if (effective == -1)
53984 + effectiveok = 1;
53985 + if (fs == -1)
53986 + fsok = 1;
53987 +
53988 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53989 + for (i = 0; i < num; i++) {
53990 + curgid = (int)gidlist[i];
53991 + if (real == curgid)
53992 + realok = 1;
53993 + if (effective == curgid)
53994 + effectiveok = 1;
53995 + if (fs == curgid)
53996 + fsok = 1;
53997 + }
53998 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53999 + for (i = 0; i < num; i++) {
54000 + curgid = (int)gidlist[i];
54001 + if (real == curgid)
54002 + break;
54003 + if (effective == curgid)
54004 + break;
54005 + if (fs == curgid)
54006 + break;
54007 + }
54008 + /* not in deny list */
54009 + if (i == num) {
54010 + realok = 1;
54011 + effectiveok = 1;
54012 + fsok = 1;
54013 + }
54014 + }
54015 +
54016 + if (realok && effectiveok && fsok)
54017 + return 0;
54018 + else {
54019 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54020 + return 1;
54021 + }
54022 +}
54023 +
54024 +extern int gr_acl_is_capable(const int cap);
54025 +
54026 +void
54027 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54028 +{
54029 + struct acl_role_label *role = task->role;
54030 + struct acl_subject_label *subj = NULL;
54031 + struct acl_object_label *obj;
54032 + struct file *filp;
54033 +
54034 + if (unlikely(!(gr_status & GR_READY)))
54035 + return;
54036 +
54037 + filp = task->exec_file;
54038 +
54039 + /* kernel process, we'll give them the kernel role */
54040 + if (unlikely(!filp)) {
54041 + task->role = kernel_role;
54042 + task->acl = kernel_role->root_label;
54043 + return;
54044 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54045 + role = lookup_acl_role_label(task, uid, gid);
54046 +
54047 + /* don't change the role if we're not a privileged process */
54048 + if (role && task->role != role &&
54049 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54050 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54051 + return;
54052 +
54053 + /* perform subject lookup in possibly new role
54054 + we can use this result below in the case where role == task->role
54055 + */
54056 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54057 +
54058 + /* if we changed uid/gid, but result in the same role
54059 + and are using inheritance, don't lose the inherited subject
54060 + if current subject is other than what normal lookup
54061 + would result in, we arrived via inheritance, don't
54062 + lose subject
54063 + */
54064 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54065 + (subj == task->acl)))
54066 + task->acl = subj;
54067 +
54068 + task->role = role;
54069 +
54070 + task->is_writable = 0;
54071 +
54072 + /* ignore additional mmap checks for processes that are writable
54073 + by the default ACL */
54074 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54075 + if (unlikely(obj->mode & GR_WRITE))
54076 + task->is_writable = 1;
54077 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54078 + if (unlikely(obj->mode & GR_WRITE))
54079 + task->is_writable = 1;
54080 +
54081 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54082 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54083 +#endif
54084 +
54085 + gr_set_proc_res(task);
54086 +
54087 + return;
54088 +}
54089 +
54090 +int
54091 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54092 + const int unsafe_flags)
54093 +{
54094 + struct task_struct *task = current;
54095 + struct acl_subject_label *newacl;
54096 + struct acl_object_label *obj;
54097 + __u32 retmode;
54098 +
54099 + if (unlikely(!(gr_status & GR_READY)))
54100 + return 0;
54101 +
54102 + newacl = chk_subj_label(dentry, mnt, task->role);
54103 +
54104 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54105 + did an exec
54106 + */
54107 + rcu_read_lock();
54108 + read_lock(&tasklist_lock);
54109 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54110 + (task->parent->acl->mode & GR_POVERRIDE))) {
54111 + read_unlock(&tasklist_lock);
54112 + rcu_read_unlock();
54113 + goto skip_check;
54114 + }
54115 + read_unlock(&tasklist_lock);
54116 + rcu_read_unlock();
54117 +
54118 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54119 + !(task->role->roletype & GR_ROLE_GOD) &&
54120 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54121 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54122 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54123 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54124 + else
54125 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54126 + return -EACCES;
54127 + }
54128 +
54129 +skip_check:
54130 +
54131 + obj = chk_obj_label(dentry, mnt, task->acl);
54132 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54133 +
54134 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54135 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54136 + if (obj->nested)
54137 + task->acl = obj->nested;
54138 + else
54139 + task->acl = newacl;
54140 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54141 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54142 +
54143 + task->is_writable = 0;
54144 +
54145 + /* ignore additional mmap checks for processes that are writable
54146 + by the default ACL */
54147 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54148 + if (unlikely(obj->mode & GR_WRITE))
54149 + task->is_writable = 1;
54150 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54151 + if (unlikely(obj->mode & GR_WRITE))
54152 + task->is_writable = 1;
54153 +
54154 + gr_set_proc_res(task);
54155 +
54156 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54157 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54158 +#endif
54159 + return 0;
54160 +}
54161 +
54162 +/* always called with valid inodev ptr */
54163 +static void
54164 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54165 +{
54166 + struct acl_object_label *matchpo;
54167 + struct acl_subject_label *matchps;
54168 + struct acl_subject_label *subj;
54169 + struct acl_role_label *role;
54170 + unsigned int x;
54171 +
54172 + FOR_EACH_ROLE_START(role)
54173 + FOR_EACH_SUBJECT_START(role, subj, x)
54174 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54175 + matchpo->mode |= GR_DELETED;
54176 + FOR_EACH_SUBJECT_END(subj,x)
54177 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54178 + /* nested subjects aren't in the role's subj_hash table */
54179 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54180 + matchpo->mode |= GR_DELETED;
54181 + FOR_EACH_NESTED_SUBJECT_END(subj)
54182 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54183 + matchps->mode |= GR_DELETED;
54184 + FOR_EACH_ROLE_END(role)
54185 +
54186 + inodev->nentry->deleted = 1;
54187 +
54188 + return;
54189 +}
54190 +
54191 +void
54192 +gr_handle_delete(const ino_t ino, const dev_t dev)
54193 +{
54194 + struct inodev_entry *inodev;
54195 +
54196 + if (unlikely(!(gr_status & GR_READY)))
54197 + return;
54198 +
54199 + write_lock(&gr_inode_lock);
54200 + inodev = lookup_inodev_entry(ino, dev);
54201 + if (inodev != NULL)
54202 + do_handle_delete(inodev, ino, dev);
54203 + write_unlock(&gr_inode_lock);
54204 +
54205 + return;
54206 +}
54207 +
54208 +static void
54209 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54210 + const ino_t newinode, const dev_t newdevice,
54211 + struct acl_subject_label *subj)
54212 +{
54213 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54214 + struct acl_object_label *match;
54215 +
54216 + match = subj->obj_hash[index];
54217 +
54218 + while (match && (match->inode != oldinode ||
54219 + match->device != olddevice ||
54220 + !(match->mode & GR_DELETED)))
54221 + match = match->next;
54222 +
54223 + if (match && (match->inode == oldinode)
54224 + && (match->device == olddevice)
54225 + && (match->mode & GR_DELETED)) {
54226 + if (match->prev == NULL) {
54227 + subj->obj_hash[index] = match->next;
54228 + if (match->next != NULL)
54229 + match->next->prev = NULL;
54230 + } else {
54231 + match->prev->next = match->next;
54232 + if (match->next != NULL)
54233 + match->next->prev = match->prev;
54234 + }
54235 + match->prev = NULL;
54236 + match->next = NULL;
54237 + match->inode = newinode;
54238 + match->device = newdevice;
54239 + match->mode &= ~GR_DELETED;
54240 +
54241 + insert_acl_obj_label(match, subj);
54242 + }
54243 +
54244 + return;
54245 +}
54246 +
54247 +static void
54248 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54249 + const ino_t newinode, const dev_t newdevice,
54250 + struct acl_role_label *role)
54251 +{
54252 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54253 + struct acl_subject_label *match;
54254 +
54255 + match = role->subj_hash[index];
54256 +
54257 + while (match && (match->inode != oldinode ||
54258 + match->device != olddevice ||
54259 + !(match->mode & GR_DELETED)))
54260 + match = match->next;
54261 +
54262 + if (match && (match->inode == oldinode)
54263 + && (match->device == olddevice)
54264 + && (match->mode & GR_DELETED)) {
54265 + if (match->prev == NULL) {
54266 + role->subj_hash[index] = match->next;
54267 + if (match->next != NULL)
54268 + match->next->prev = NULL;
54269 + } else {
54270 + match->prev->next = match->next;
54271 + if (match->next != NULL)
54272 + match->next->prev = match->prev;
54273 + }
54274 + match->prev = NULL;
54275 + match->next = NULL;
54276 + match->inode = newinode;
54277 + match->device = newdevice;
54278 + match->mode &= ~GR_DELETED;
54279 +
54280 + insert_acl_subj_label(match, role);
54281 + }
54282 +
54283 + return;
54284 +}
54285 +
54286 +static void
54287 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54288 + const ino_t newinode, const dev_t newdevice)
54289 +{
54290 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54291 + struct inodev_entry *match;
54292 +
54293 + match = inodev_set.i_hash[index];
54294 +
54295 + while (match && (match->nentry->inode != oldinode ||
54296 + match->nentry->device != olddevice || !match->nentry->deleted))
54297 + match = match->next;
54298 +
54299 + if (match && (match->nentry->inode == oldinode)
54300 + && (match->nentry->device == olddevice) &&
54301 + match->nentry->deleted) {
54302 + if (match->prev == NULL) {
54303 + inodev_set.i_hash[index] = match->next;
54304 + if (match->next != NULL)
54305 + match->next->prev = NULL;
54306 + } else {
54307 + match->prev->next = match->next;
54308 + if (match->next != NULL)
54309 + match->next->prev = match->prev;
54310 + }
54311 + match->prev = NULL;
54312 + match->next = NULL;
54313 + match->nentry->inode = newinode;
54314 + match->nentry->device = newdevice;
54315 + match->nentry->deleted = 0;
54316 +
54317 + insert_inodev_entry(match);
54318 + }
54319 +
54320 + return;
54321 +}
54322 +
54323 +static void
54324 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54325 +{
54326 + struct acl_subject_label *subj;
54327 + struct acl_role_label *role;
54328 + unsigned int x;
54329 +
54330 + FOR_EACH_ROLE_START(role)
54331 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54332 +
54333 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54334 + if ((subj->inode == ino) && (subj->device == dev)) {
54335 + subj->inode = ino;
54336 + subj->device = dev;
54337 + }
54338 + /* nested subjects aren't in the role's subj_hash table */
54339 + update_acl_obj_label(matchn->inode, matchn->device,
54340 + ino, dev, subj);
54341 + FOR_EACH_NESTED_SUBJECT_END(subj)
54342 + FOR_EACH_SUBJECT_START(role, subj, x)
54343 + update_acl_obj_label(matchn->inode, matchn->device,
54344 + ino, dev, subj);
54345 + FOR_EACH_SUBJECT_END(subj,x)
54346 + FOR_EACH_ROLE_END(role)
54347 +
54348 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54349 +
54350 + return;
54351 +}
54352 +
54353 +static void
54354 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54355 + const struct vfsmount *mnt)
54356 +{
54357 + ino_t ino = dentry->d_inode->i_ino;
54358 + dev_t dev = __get_dev(dentry);
54359 +
54360 + __do_handle_create(matchn, ino, dev);
54361 +
54362 + return;
54363 +}
54364 +
54365 +void
54366 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54367 +{
54368 + struct name_entry *matchn;
54369 +
54370 + if (unlikely(!(gr_status & GR_READY)))
54371 + return;
54372 +
54373 + preempt_disable();
54374 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54375 +
54376 + if (unlikely((unsigned long)matchn)) {
54377 + write_lock(&gr_inode_lock);
54378 + do_handle_create(matchn, dentry, mnt);
54379 + write_unlock(&gr_inode_lock);
54380 + }
54381 + preempt_enable();
54382 +
54383 + return;
54384 +}
54385 +
54386 +void
54387 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54388 +{
54389 + struct name_entry *matchn;
54390 +
54391 + if (unlikely(!(gr_status & GR_READY)))
54392 + return;
54393 +
54394 + preempt_disable();
54395 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54396 +
54397 + if (unlikely((unsigned long)matchn)) {
54398 + write_lock(&gr_inode_lock);
54399 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54400 + write_unlock(&gr_inode_lock);
54401 + }
54402 + preempt_enable();
54403 +
54404 + return;
54405 +}
54406 +
54407 +void
54408 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54409 + struct dentry *old_dentry,
54410 + struct dentry *new_dentry,
54411 + struct vfsmount *mnt, const __u8 replace)
54412 +{
54413 + struct name_entry *matchn;
54414 + struct inodev_entry *inodev;
54415 + struct inode *inode = new_dentry->d_inode;
54416 + ino_t old_ino = old_dentry->d_inode->i_ino;
54417 + dev_t old_dev = __get_dev(old_dentry);
54418 +
54419 + /* vfs_rename swaps the name and parent link for old_dentry and
54420 + new_dentry
54421 + at this point, old_dentry has the new name, parent link, and inode
54422 + for the renamed file
54423 + if a file is being replaced by a rename, new_dentry has the inode
54424 + and name for the replaced file
54425 + */
54426 +
54427 + if (unlikely(!(gr_status & GR_READY)))
54428 + return;
54429 +
54430 + preempt_disable();
54431 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54432 +
54433 + /* we wouldn't have to check d_inode if it weren't for
54434 + NFS silly-renaming
54435 + */
54436 +
54437 + write_lock(&gr_inode_lock);
54438 + if (unlikely(replace && inode)) {
54439 + ino_t new_ino = inode->i_ino;
54440 + dev_t new_dev = __get_dev(new_dentry);
54441 +
54442 + inodev = lookup_inodev_entry(new_ino, new_dev);
54443 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54444 + do_handle_delete(inodev, new_ino, new_dev);
54445 + }
54446 +
54447 + inodev = lookup_inodev_entry(old_ino, old_dev);
54448 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54449 + do_handle_delete(inodev, old_ino, old_dev);
54450 +
54451 + if (unlikely((unsigned long)matchn))
54452 + do_handle_create(matchn, old_dentry, mnt);
54453 +
54454 + write_unlock(&gr_inode_lock);
54455 + preempt_enable();
54456 +
54457 + return;
54458 +}
54459 +
54460 +static int
54461 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54462 + unsigned char **sum)
54463 +{
54464 + struct acl_role_label *r;
54465 + struct role_allowed_ip *ipp;
54466 + struct role_transition *trans;
54467 + unsigned int i;
54468 + int found = 0;
54469 + u32 curr_ip = current->signal->curr_ip;
54470 +
54471 + current->signal->saved_ip = curr_ip;
54472 +
54473 + /* check transition table */
54474 +
54475 + for (trans = current->role->transitions; trans; trans = trans->next) {
54476 + if (!strcmp(rolename, trans->rolename)) {
54477 + found = 1;
54478 + break;
54479 + }
54480 + }
54481 +
54482 + if (!found)
54483 + return 0;
54484 +
54485 + /* handle special roles that do not require authentication
54486 + and check ip */
54487 +
54488 + FOR_EACH_ROLE_START(r)
54489 + if (!strcmp(rolename, r->rolename) &&
54490 + (r->roletype & GR_ROLE_SPECIAL)) {
54491 + found = 0;
54492 + if (r->allowed_ips != NULL) {
54493 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54494 + if ((ntohl(curr_ip) & ipp->netmask) ==
54495 + (ntohl(ipp->addr) & ipp->netmask))
54496 + found = 1;
54497 + }
54498 + } else
54499 + found = 2;
54500 + if (!found)
54501 + return 0;
54502 +
54503 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54504 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54505 + *salt = NULL;
54506 + *sum = NULL;
54507 + return 1;
54508 + }
54509 + }
54510 + FOR_EACH_ROLE_END(r)
54511 +
54512 + for (i = 0; i < num_sprole_pws; i++) {
54513 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54514 + *salt = acl_special_roles[i]->salt;
54515 + *sum = acl_special_roles[i]->sum;
54516 + return 1;
54517 + }
54518 + }
54519 +
54520 + return 0;
54521 +}
54522 +
54523 +static void
54524 +assign_special_role(char *rolename)
54525 +{
54526 + struct acl_object_label *obj;
54527 + struct acl_role_label *r;
54528 + struct acl_role_label *assigned = NULL;
54529 + struct task_struct *tsk;
54530 + struct file *filp;
54531 +
54532 + FOR_EACH_ROLE_START(r)
54533 + if (!strcmp(rolename, r->rolename) &&
54534 + (r->roletype & GR_ROLE_SPECIAL)) {
54535 + assigned = r;
54536 + break;
54537 + }
54538 + FOR_EACH_ROLE_END(r)
54539 +
54540 + if (!assigned)
54541 + return;
54542 +
54543 + read_lock(&tasklist_lock);
54544 + read_lock(&grsec_exec_file_lock);
54545 +
54546 + tsk = current->real_parent;
54547 + if (tsk == NULL)
54548 + goto out_unlock;
54549 +
54550 + filp = tsk->exec_file;
54551 + if (filp == NULL)
54552 + goto out_unlock;
54553 +
54554 + tsk->is_writable = 0;
54555 +
54556 + tsk->acl_sp_role = 1;
54557 + tsk->acl_role_id = ++acl_sp_role_value;
54558 + tsk->role = assigned;
54559 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54560 +
54561 + /* ignore additional mmap checks for processes that are writable
54562 + by the default ACL */
54563 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54564 + if (unlikely(obj->mode & GR_WRITE))
54565 + tsk->is_writable = 1;
54566 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54567 + if (unlikely(obj->mode & GR_WRITE))
54568 + tsk->is_writable = 1;
54569 +
54570 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54571 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54572 +#endif
54573 +
54574 +out_unlock:
54575 + read_unlock(&grsec_exec_file_lock);
54576 + read_unlock(&tasklist_lock);
54577 + return;
54578 +}
54579 +
54580 +int gr_check_secure_terminal(struct task_struct *task)
54581 +{
54582 + struct task_struct *p, *p2, *p3;
54583 + struct files_struct *files;
54584 + struct fdtable *fdt;
54585 + struct file *our_file = NULL, *file;
54586 + int i;
54587 +
54588 + if (task->signal->tty == NULL)
54589 + return 1;
54590 +
54591 + files = get_files_struct(task);
54592 + if (files != NULL) {
54593 + rcu_read_lock();
54594 + fdt = files_fdtable(files);
54595 + for (i=0; i < fdt->max_fds; i++) {
54596 + file = fcheck_files(files, i);
54597 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54598 + get_file(file);
54599 + our_file = file;
54600 + }
54601 + }
54602 + rcu_read_unlock();
54603 + put_files_struct(files);
54604 + }
54605 +
54606 + if (our_file == NULL)
54607 + return 1;
54608 +
54609 + read_lock(&tasklist_lock);
54610 + do_each_thread(p2, p) {
54611 + files = get_files_struct(p);
54612 + if (files == NULL ||
54613 + (p->signal && p->signal->tty == task->signal->tty)) {
54614 + if (files != NULL)
54615 + put_files_struct(files);
54616 + continue;
54617 + }
54618 + rcu_read_lock();
54619 + fdt = files_fdtable(files);
54620 + for (i=0; i < fdt->max_fds; i++) {
54621 + file = fcheck_files(files, i);
54622 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54623 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54624 + p3 = task;
54625 + while (p3->pid > 0) {
54626 + if (p3 == p)
54627 + break;
54628 + p3 = p3->real_parent;
54629 + }
54630 + if (p3 == p)
54631 + break;
54632 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54633 + gr_handle_alertkill(p);
54634 + rcu_read_unlock();
54635 + put_files_struct(files);
54636 + read_unlock(&tasklist_lock);
54637 + fput(our_file);
54638 + return 0;
54639 + }
54640 + }
54641 + rcu_read_unlock();
54642 + put_files_struct(files);
54643 + } while_each_thread(p2, p);
54644 + read_unlock(&tasklist_lock);
54645 +
54646 + fput(our_file);
54647 + return 1;
54648 +}
54649 +
54650 +static int gr_rbac_disable(void *unused)
54651 +{
54652 + pax_open_kernel();
54653 + gr_status &= ~GR_READY;
54654 + pax_close_kernel();
54655 +
54656 + return 0;
54657 +}
54658 +
54659 +ssize_t
54660 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54661 +{
54662 + struct gr_arg_wrapper uwrap;
54663 + unsigned char *sprole_salt = NULL;
54664 + unsigned char *sprole_sum = NULL;
54665 + int error = sizeof (struct gr_arg_wrapper);
54666 + int error2 = 0;
54667 +
54668 + mutex_lock(&gr_dev_mutex);
54669 +
54670 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54671 + error = -EPERM;
54672 + goto out;
54673 + }
54674 +
54675 + if (count != sizeof (struct gr_arg_wrapper)) {
54676 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54677 + error = -EINVAL;
54678 + goto out;
54679 + }
54680 +
54681 +
54682 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54683 + gr_auth_expires = 0;
54684 + gr_auth_attempts = 0;
54685 + }
54686 +
54687 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54688 + error = -EFAULT;
54689 + goto out;
54690 + }
54691 +
54692 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54693 + error = -EINVAL;
54694 + goto out;
54695 + }
54696 +
54697 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54698 + error = -EFAULT;
54699 + goto out;
54700 + }
54701 +
54702 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54703 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54704 + time_after(gr_auth_expires, get_seconds())) {
54705 + error = -EBUSY;
54706 + goto out;
54707 + }
54708 +
54709 + /* if non-root trying to do anything other than use a special role,
54710 + do not attempt authentication, do not count towards authentication
54711 + locking
54712 + */
54713 +
54714 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54715 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54716 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54717 + error = -EPERM;
54718 + goto out;
54719 + }
54720 +
54721 + /* ensure pw and special role name are null terminated */
54722 +
54723 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54724 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54725 +
54726 + /* Okay.
54727 + * We have our enough of the argument structure..(we have yet
54728 + * to copy_from_user the tables themselves) . Copy the tables
54729 + * only if we need them, i.e. for loading operations. */
54730 +
54731 + switch (gr_usermode->mode) {
54732 + case GR_STATUS:
54733 + if (gr_status & GR_READY) {
54734 + error = 1;
54735 + if (!gr_check_secure_terminal(current))
54736 + error = 3;
54737 + } else
54738 + error = 2;
54739 + goto out;
54740 + case GR_SHUTDOWN:
54741 + if ((gr_status & GR_READY)
54742 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54743 + stop_machine(gr_rbac_disable, NULL, NULL);
54744 + free_variables();
54745 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54746 + memset(gr_system_salt, 0, GR_SALT_LEN);
54747 + memset(gr_system_sum, 0, GR_SHA_LEN);
54748 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54749 + } else if (gr_status & GR_READY) {
54750 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54751 + error = -EPERM;
54752 + } else {
54753 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54754 + error = -EAGAIN;
54755 + }
54756 + break;
54757 + case GR_ENABLE:
54758 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54759 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54760 + else {
54761 + if (gr_status & GR_READY)
54762 + error = -EAGAIN;
54763 + else
54764 + error = error2;
54765 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54766 + }
54767 + break;
54768 + case GR_RELOAD:
54769 + if (!(gr_status & GR_READY)) {
54770 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54771 + error = -EAGAIN;
54772 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54773 + stop_machine(gr_rbac_disable, NULL, NULL);
54774 + free_variables();
54775 + error2 = gracl_init(gr_usermode);
54776 + if (!error2)
54777 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54778 + else {
54779 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54780 + error = error2;
54781 + }
54782 + } else {
54783 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54784 + error = -EPERM;
54785 + }
54786 + break;
54787 + case GR_SEGVMOD:
54788 + if (unlikely(!(gr_status & GR_READY))) {
54789 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54790 + error = -EAGAIN;
54791 + break;
54792 + }
54793 +
54794 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54795 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54796 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54797 + struct acl_subject_label *segvacl;
54798 + segvacl =
54799 + lookup_acl_subj_label(gr_usermode->segv_inode,
54800 + gr_usermode->segv_device,
54801 + current->role);
54802 + if (segvacl) {
54803 + segvacl->crashes = 0;
54804 + segvacl->expires = 0;
54805 + }
54806 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54807 + gr_remove_uid(gr_usermode->segv_uid);
54808 + }
54809 + } else {
54810 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54811 + error = -EPERM;
54812 + }
54813 + break;
54814 + case GR_SPROLE:
54815 + case GR_SPROLEPAM:
54816 + if (unlikely(!(gr_status & GR_READY))) {
54817 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54818 + error = -EAGAIN;
54819 + break;
54820 + }
54821 +
54822 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54823 + current->role->expires = 0;
54824 + current->role->auth_attempts = 0;
54825 + }
54826 +
54827 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54828 + time_after(current->role->expires, get_seconds())) {
54829 + error = -EBUSY;
54830 + goto out;
54831 + }
54832 +
54833 + if (lookup_special_role_auth
54834 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54835 + && ((!sprole_salt && !sprole_sum)
54836 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54837 + char *p = "";
54838 + assign_special_role(gr_usermode->sp_role);
54839 + read_lock(&tasklist_lock);
54840 + if (current->real_parent)
54841 + p = current->real_parent->role->rolename;
54842 + read_unlock(&tasklist_lock);
54843 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54844 + p, acl_sp_role_value);
54845 + } else {
54846 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54847 + error = -EPERM;
54848 + if(!(current->role->auth_attempts++))
54849 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54850 +
54851 + goto out;
54852 + }
54853 + break;
54854 + case GR_UNSPROLE:
54855 + if (unlikely(!(gr_status & GR_READY))) {
54856 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54857 + error = -EAGAIN;
54858 + break;
54859 + }
54860 +
54861 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54862 + char *p = "";
54863 + int i = 0;
54864 +
54865 + read_lock(&tasklist_lock);
54866 + if (current->real_parent) {
54867 + p = current->real_parent->role->rolename;
54868 + i = current->real_parent->acl_role_id;
54869 + }
54870 + read_unlock(&tasklist_lock);
54871 +
54872 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54873 + gr_set_acls(1);
54874 + } else {
54875 + error = -EPERM;
54876 + goto out;
54877 + }
54878 + break;
54879 + default:
54880 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54881 + error = -EINVAL;
54882 + break;
54883 + }
54884 +
54885 + if (error != -EPERM)
54886 + goto out;
54887 +
54888 + if(!(gr_auth_attempts++))
54889 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54890 +
54891 + out:
54892 + mutex_unlock(&gr_dev_mutex);
54893 + return error;
54894 +}
54895 +
54896 +/* must be called with
54897 + rcu_read_lock();
54898 + read_lock(&tasklist_lock);
54899 + read_lock(&grsec_exec_file_lock);
54900 +*/
54901 +int gr_apply_subject_to_task(struct task_struct *task)
54902 +{
54903 + struct acl_object_label *obj;
54904 + char *tmpname;
54905 + struct acl_subject_label *tmpsubj;
54906 + struct file *filp;
54907 + struct name_entry *nmatch;
54908 +
54909 + filp = task->exec_file;
54910 + if (filp == NULL)
54911 + return 0;
54912 +
54913 + /* the following is to apply the correct subject
54914 + on binaries running when the RBAC system
54915 + is enabled, when the binaries have been
54916 + replaced or deleted since their execution
54917 + -----
54918 + when the RBAC system starts, the inode/dev
54919 + from exec_file will be one the RBAC system
54920 + is unaware of. It only knows the inode/dev
54921 + of the present file on disk, or the absence
54922 + of it.
54923 + */
54924 + preempt_disable();
54925 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54926 +
54927 + nmatch = lookup_name_entry(tmpname);
54928 + preempt_enable();
54929 + tmpsubj = NULL;
54930 + if (nmatch) {
54931 + if (nmatch->deleted)
54932 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54933 + else
54934 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54935 + if (tmpsubj != NULL)
54936 + task->acl = tmpsubj;
54937 + }
54938 + if (tmpsubj == NULL)
54939 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54940 + task->role);
54941 + if (task->acl) {
54942 + task->is_writable = 0;
54943 + /* ignore additional mmap checks for processes that are writable
54944 + by the default ACL */
54945 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54946 + if (unlikely(obj->mode & GR_WRITE))
54947 + task->is_writable = 1;
54948 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54949 + if (unlikely(obj->mode & GR_WRITE))
54950 + task->is_writable = 1;
54951 +
54952 + gr_set_proc_res(task);
54953 +
54954 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54955 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54956 +#endif
54957 + } else {
54958 + return 1;
54959 + }
54960 +
54961 + return 0;
54962 +}
54963 +
54964 +int
54965 +gr_set_acls(const int type)
54966 +{
54967 + struct task_struct *task, *task2;
54968 + struct acl_role_label *role = current->role;
54969 + __u16 acl_role_id = current->acl_role_id;
54970 + const struct cred *cred;
54971 + int ret;
54972 +
54973 + rcu_read_lock();
54974 + read_lock(&tasklist_lock);
54975 + read_lock(&grsec_exec_file_lock);
54976 + do_each_thread(task2, task) {
54977 + /* check to see if we're called from the exit handler,
54978 + if so, only replace ACLs that have inherited the admin
54979 + ACL */
54980 +
54981 + if (type && (task->role != role ||
54982 + task->acl_role_id != acl_role_id))
54983 + continue;
54984 +
54985 + task->acl_role_id = 0;
54986 + task->acl_sp_role = 0;
54987 +
54988 + if (task->exec_file) {
54989 + cred = __task_cred(task);
54990 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54991 + ret = gr_apply_subject_to_task(task);
54992 + if (ret) {
54993 + read_unlock(&grsec_exec_file_lock);
54994 + read_unlock(&tasklist_lock);
54995 + rcu_read_unlock();
54996 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54997 + return ret;
54998 + }
54999 + } else {
55000 + // it's a kernel process
55001 + task->role = kernel_role;
55002 + task->acl = kernel_role->root_label;
55003 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55004 + task->acl->mode &= ~GR_PROCFIND;
55005 +#endif
55006 + }
55007 + } while_each_thread(task2, task);
55008 + read_unlock(&grsec_exec_file_lock);
55009 + read_unlock(&tasklist_lock);
55010 + rcu_read_unlock();
55011 +
55012 + return 0;
55013 +}
55014 +
55015 +void
55016 +gr_learn_resource(const struct task_struct *task,
55017 + const int res, const unsigned long wanted, const int gt)
55018 +{
55019 + struct acl_subject_label *acl;
55020 + const struct cred *cred;
55021 +
55022 + if (unlikely((gr_status & GR_READY) &&
55023 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55024 + goto skip_reslog;
55025 +
55026 +#ifdef CONFIG_GRKERNSEC_RESLOG
55027 + gr_log_resource(task, res, wanted, gt);
55028 +#endif
55029 + skip_reslog:
55030 +
55031 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55032 + return;
55033 +
55034 + acl = task->acl;
55035 +
55036 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55037 + !(acl->resmask & (1 << (unsigned short) res))))
55038 + return;
55039 +
55040 + if (wanted >= acl->res[res].rlim_cur) {
55041 + unsigned long res_add;
55042 +
55043 + res_add = wanted;
55044 + switch (res) {
55045 + case RLIMIT_CPU:
55046 + res_add += GR_RLIM_CPU_BUMP;
55047 + break;
55048 + case RLIMIT_FSIZE:
55049 + res_add += GR_RLIM_FSIZE_BUMP;
55050 + break;
55051 + case RLIMIT_DATA:
55052 + res_add += GR_RLIM_DATA_BUMP;
55053 + break;
55054 + case RLIMIT_STACK:
55055 + res_add += GR_RLIM_STACK_BUMP;
55056 + break;
55057 + case RLIMIT_CORE:
55058 + res_add += GR_RLIM_CORE_BUMP;
55059 + break;
55060 + case RLIMIT_RSS:
55061 + res_add += GR_RLIM_RSS_BUMP;
55062 + break;
55063 + case RLIMIT_NPROC:
55064 + res_add += GR_RLIM_NPROC_BUMP;
55065 + break;
55066 + case RLIMIT_NOFILE:
55067 + res_add += GR_RLIM_NOFILE_BUMP;
55068 + break;
55069 + case RLIMIT_MEMLOCK:
55070 + res_add += GR_RLIM_MEMLOCK_BUMP;
55071 + break;
55072 + case RLIMIT_AS:
55073 + res_add += GR_RLIM_AS_BUMP;
55074 + break;
55075 + case RLIMIT_LOCKS:
55076 + res_add += GR_RLIM_LOCKS_BUMP;
55077 + break;
55078 + case RLIMIT_SIGPENDING:
55079 + res_add += GR_RLIM_SIGPENDING_BUMP;
55080 + break;
55081 + case RLIMIT_MSGQUEUE:
55082 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55083 + break;
55084 + case RLIMIT_NICE:
55085 + res_add += GR_RLIM_NICE_BUMP;
55086 + break;
55087 + case RLIMIT_RTPRIO:
55088 + res_add += GR_RLIM_RTPRIO_BUMP;
55089 + break;
55090 + case RLIMIT_RTTIME:
55091 + res_add += GR_RLIM_RTTIME_BUMP;
55092 + break;
55093 + }
55094 +
55095 + acl->res[res].rlim_cur = res_add;
55096 +
55097 + if (wanted > acl->res[res].rlim_max)
55098 + acl->res[res].rlim_max = res_add;
55099 +
55100 + /* only log the subject filename, since resource logging is supported for
55101 + single-subject learning only */
55102 + rcu_read_lock();
55103 + cred = __task_cred(task);
55104 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55105 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55106 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55107 + "", (unsigned long) res, &task->signal->saved_ip);
55108 + rcu_read_unlock();
55109 + }
55110 +
55111 + return;
55112 +}
55113 +
55114 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55115 +void
55116 +pax_set_initial_flags(struct linux_binprm *bprm)
55117 +{
55118 + struct task_struct *task = current;
55119 + struct acl_subject_label *proc;
55120 + unsigned long flags;
55121 +
55122 + if (unlikely(!(gr_status & GR_READY)))
55123 + return;
55124 +
55125 + flags = pax_get_flags(task);
55126 +
55127 + proc = task->acl;
55128 +
55129 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55130 + flags &= ~MF_PAX_PAGEEXEC;
55131 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55132 + flags &= ~MF_PAX_SEGMEXEC;
55133 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55134 + flags &= ~MF_PAX_RANDMMAP;
55135 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55136 + flags &= ~MF_PAX_EMUTRAMP;
55137 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55138 + flags &= ~MF_PAX_MPROTECT;
55139 +
55140 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55141 + flags |= MF_PAX_PAGEEXEC;
55142 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55143 + flags |= MF_PAX_SEGMEXEC;
55144 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55145 + flags |= MF_PAX_RANDMMAP;
55146 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55147 + flags |= MF_PAX_EMUTRAMP;
55148 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55149 + flags |= MF_PAX_MPROTECT;
55150 +
55151 + pax_set_flags(task, flags);
55152 +
55153 + return;
55154 +}
55155 +#endif
55156 +
55157 +int
55158 +gr_handle_proc_ptrace(struct task_struct *task)
55159 +{
55160 + struct file *filp;
55161 + struct task_struct *tmp = task;
55162 + struct task_struct *curtemp = current;
55163 + __u32 retmode;
55164 +
55165 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55166 + if (unlikely(!(gr_status & GR_READY)))
55167 + return 0;
55168 +#endif
55169 +
55170 + read_lock(&tasklist_lock);
55171 + read_lock(&grsec_exec_file_lock);
55172 + filp = task->exec_file;
55173 +
55174 + while (tmp->pid > 0) {
55175 + if (tmp == curtemp)
55176 + break;
55177 + tmp = tmp->real_parent;
55178 + }
55179 +
55180 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55181 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55182 + read_unlock(&grsec_exec_file_lock);
55183 + read_unlock(&tasklist_lock);
55184 + return 1;
55185 + }
55186 +
55187 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55188 + if (!(gr_status & GR_READY)) {
55189 + read_unlock(&grsec_exec_file_lock);
55190 + read_unlock(&tasklist_lock);
55191 + return 0;
55192 + }
55193 +#endif
55194 +
55195 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55196 + read_unlock(&grsec_exec_file_lock);
55197 + read_unlock(&tasklist_lock);
55198 +
55199 + if (retmode & GR_NOPTRACE)
55200 + return 1;
55201 +
55202 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55203 + && (current->acl != task->acl || (current->acl != current->role->root_label
55204 + && current->pid != task->pid)))
55205 + return 1;
55206 +
55207 + return 0;
55208 +}
55209 +
55210 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55211 +{
55212 + if (unlikely(!(gr_status & GR_READY)))
55213 + return;
55214 +
55215 + if (!(current->role->roletype & GR_ROLE_GOD))
55216 + return;
55217 +
55218 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55219 + p->role->rolename, gr_task_roletype_to_char(p),
55220 + p->acl->filename);
55221 +}
55222 +
55223 +int
55224 +gr_handle_ptrace(struct task_struct *task, const long request)
55225 +{
55226 + struct task_struct *tmp = task;
55227 + struct task_struct *curtemp = current;
55228 + __u32 retmode;
55229 +
55230 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55231 + if (unlikely(!(gr_status & GR_READY)))
55232 + return 0;
55233 +#endif
55234 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55235 + read_lock(&tasklist_lock);
55236 + while (tmp->pid > 0) {
55237 + if (tmp == curtemp)
55238 + break;
55239 + tmp = tmp->real_parent;
55240 + }
55241 +
55242 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55243 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55244 + read_unlock(&tasklist_lock);
55245 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55246 + return 1;
55247 + }
55248 + read_unlock(&tasklist_lock);
55249 + }
55250 +
55251 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55252 + if (!(gr_status & GR_READY))
55253 + return 0;
55254 +#endif
55255 +
55256 + read_lock(&grsec_exec_file_lock);
55257 + if (unlikely(!task->exec_file)) {
55258 + read_unlock(&grsec_exec_file_lock);
55259 + return 0;
55260 + }
55261 +
55262 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55263 + read_unlock(&grsec_exec_file_lock);
55264 +
55265 + if (retmode & GR_NOPTRACE) {
55266 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55267 + return 1;
55268 + }
55269 +
55270 + if (retmode & GR_PTRACERD) {
55271 + switch (request) {
55272 + case PTRACE_SEIZE:
55273 + case PTRACE_POKETEXT:
55274 + case PTRACE_POKEDATA:
55275 + case PTRACE_POKEUSR:
55276 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55277 + case PTRACE_SETREGS:
55278 + case PTRACE_SETFPREGS:
55279 +#endif
55280 +#ifdef CONFIG_X86
55281 + case PTRACE_SETFPXREGS:
55282 +#endif
55283 +#ifdef CONFIG_ALTIVEC
55284 + case PTRACE_SETVRREGS:
55285 +#endif
55286 + return 1;
55287 + default:
55288 + return 0;
55289 + }
55290 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55291 + !(current->role->roletype & GR_ROLE_GOD) &&
55292 + (current->acl != task->acl)) {
55293 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55294 + return 1;
55295 + }
55296 +
55297 + return 0;
55298 +}
55299 +
55300 +static int is_writable_mmap(const struct file *filp)
55301 +{
55302 + struct task_struct *task = current;
55303 + struct acl_object_label *obj, *obj2;
55304 +
55305 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55306 + !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))) {
55307 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55308 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55309 + task->role->root_label);
55310 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55311 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55312 + return 1;
55313 + }
55314 + }
55315 + return 0;
55316 +}
55317 +
55318 +int
55319 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55320 +{
55321 + __u32 mode;
55322 +
55323 + if (unlikely(!file || !(prot & PROT_EXEC)))
55324 + return 1;
55325 +
55326 + if (is_writable_mmap(file))
55327 + return 0;
55328 +
55329 + mode =
55330 + gr_search_file(file->f_path.dentry,
55331 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55332 + file->f_path.mnt);
55333 +
55334 + if (!gr_tpe_allow(file))
55335 + return 0;
55336 +
55337 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55338 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55339 + return 0;
55340 + } else if (unlikely(!(mode & GR_EXEC))) {
55341 + return 0;
55342 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55343 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55344 + return 1;
55345 + }
55346 +
55347 + return 1;
55348 +}
55349 +
55350 +int
55351 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55352 +{
55353 + __u32 mode;
55354 +
55355 + if (unlikely(!file || !(prot & PROT_EXEC)))
55356 + return 1;
55357 +
55358 + if (is_writable_mmap(file))
55359 + return 0;
55360 +
55361 + mode =
55362 + gr_search_file(file->f_path.dentry,
55363 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55364 + file->f_path.mnt);
55365 +
55366 + if (!gr_tpe_allow(file))
55367 + return 0;
55368 +
55369 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55370 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55371 + return 0;
55372 + } else if (unlikely(!(mode & GR_EXEC))) {
55373 + return 0;
55374 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55375 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55376 + return 1;
55377 + }
55378 +
55379 + return 1;
55380 +}
55381 +
55382 +void
55383 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55384 +{
55385 + unsigned long runtime;
55386 + unsigned long cputime;
55387 + unsigned int wday, cday;
55388 + __u8 whr, chr;
55389 + __u8 wmin, cmin;
55390 + __u8 wsec, csec;
55391 + struct timespec timeval;
55392 +
55393 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55394 + !(task->acl->mode & GR_PROCACCT)))
55395 + return;
55396 +
55397 + do_posix_clock_monotonic_gettime(&timeval);
55398 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55399 + wday = runtime / (3600 * 24);
55400 + runtime -= wday * (3600 * 24);
55401 + whr = runtime / 3600;
55402 + runtime -= whr * 3600;
55403 + wmin = runtime / 60;
55404 + runtime -= wmin * 60;
55405 + wsec = runtime;
55406 +
55407 + cputime = (task->utime + task->stime) / HZ;
55408 + cday = cputime / (3600 * 24);
55409 + cputime -= cday * (3600 * 24);
55410 + chr = cputime / 3600;
55411 + cputime -= chr * 3600;
55412 + cmin = cputime / 60;
55413 + cputime -= cmin * 60;
55414 + csec = cputime;
55415 +
55416 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55417 +
55418 + return;
55419 +}
55420 +
55421 +void gr_set_kernel_label(struct task_struct *task)
55422 +{
55423 + if (gr_status & GR_READY) {
55424 + task->role = kernel_role;
55425 + task->acl = kernel_role->root_label;
55426 + }
55427 + return;
55428 +}
55429 +
55430 +#ifdef CONFIG_TASKSTATS
55431 +int gr_is_taskstats_denied(int pid)
55432 +{
55433 + struct task_struct *task;
55434 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55435 + const struct cred *cred;
55436 +#endif
55437 + int ret = 0;
55438 +
55439 + /* restrict taskstats viewing to un-chrooted root users
55440 + who have the 'view' subject flag if the RBAC system is enabled
55441 + */
55442 +
55443 + rcu_read_lock();
55444 + read_lock(&tasklist_lock);
55445 + task = find_task_by_vpid(pid);
55446 + if (task) {
55447 +#ifdef CONFIG_GRKERNSEC_CHROOT
55448 + if (proc_is_chrooted(task))
55449 + ret = -EACCES;
55450 +#endif
55451 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55452 + cred = __task_cred(task);
55453 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55454 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55455 + ret = -EACCES;
55456 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55457 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55458 + ret = -EACCES;
55459 +#endif
55460 +#endif
55461 + if (gr_status & GR_READY) {
55462 + if (!(task->acl->mode & GR_VIEW))
55463 + ret = -EACCES;
55464 + }
55465 + } else
55466 + ret = -ENOENT;
55467 +
55468 + read_unlock(&tasklist_lock);
55469 + rcu_read_unlock();
55470 +
55471 + return ret;
55472 +}
55473 +#endif
55474 +
55475 +/* AUXV entries are filled via a descendant of search_binary_handler
55476 + after we've already applied the subject for the target
55477 +*/
55478 +int gr_acl_enable_at_secure(void)
55479 +{
55480 + if (unlikely(!(gr_status & GR_READY)))
55481 + return 0;
55482 +
55483 + if (current->acl->mode & GR_ATSECURE)
55484 + return 1;
55485 +
55486 + return 0;
55487 +}
55488 +
55489 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55490 +{
55491 + struct task_struct *task = current;
55492 + struct dentry *dentry = file->f_path.dentry;
55493 + struct vfsmount *mnt = file->f_path.mnt;
55494 + struct acl_object_label *obj, *tmp;
55495 + struct acl_subject_label *subj;
55496 + unsigned int bufsize;
55497 + int is_not_root;
55498 + char *path;
55499 + dev_t dev = __get_dev(dentry);
55500 +
55501 + if (unlikely(!(gr_status & GR_READY)))
55502 + return 1;
55503 +
55504 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55505 + return 1;
55506 +
55507 + /* ignore Eric Biederman */
55508 + if (IS_PRIVATE(dentry->d_inode))
55509 + return 1;
55510 +
55511 + subj = task->acl;
55512 + read_lock(&gr_inode_lock);
55513 + do {
55514 + obj = lookup_acl_obj_label(ino, dev, subj);
55515 + if (obj != NULL) {
55516 + read_unlock(&gr_inode_lock);
55517 + return (obj->mode & GR_FIND) ? 1 : 0;
55518 + }
55519 + } while ((subj = subj->parent_subject));
55520 + read_unlock(&gr_inode_lock);
55521 +
55522 + /* this is purely an optimization since we're looking for an object
55523 + for the directory we're doing a readdir on
55524 + if it's possible for any globbed object to match the entry we're
55525 + filling into the directory, then the object we find here will be
55526 + an anchor point with attached globbed objects
55527 + */
55528 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55529 + if (obj->globbed == NULL)
55530 + return (obj->mode & GR_FIND) ? 1 : 0;
55531 +
55532 + is_not_root = ((obj->filename[0] == '/') &&
55533 + (obj->filename[1] == '\0')) ? 0 : 1;
55534 + bufsize = PAGE_SIZE - namelen - is_not_root;
55535 +
55536 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55537 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55538 + return 1;
55539 +
55540 + preempt_disable();
55541 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55542 + bufsize);
55543 +
55544 + bufsize = strlen(path);
55545 +
55546 + /* if base is "/", don't append an additional slash */
55547 + if (is_not_root)
55548 + *(path + bufsize) = '/';
55549 + memcpy(path + bufsize + is_not_root, name, namelen);
55550 + *(path + bufsize + namelen + is_not_root) = '\0';
55551 +
55552 + tmp = obj->globbed;
55553 + while (tmp) {
55554 + if (!glob_match(tmp->filename, path)) {
55555 + preempt_enable();
55556 + return (tmp->mode & GR_FIND) ? 1 : 0;
55557 + }
55558 + tmp = tmp->next;
55559 + }
55560 + preempt_enable();
55561 + return (obj->mode & GR_FIND) ? 1 : 0;
55562 +}
55563 +
55564 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55565 +EXPORT_SYMBOL(gr_acl_is_enabled);
55566 +#endif
55567 +EXPORT_SYMBOL(gr_learn_resource);
55568 +EXPORT_SYMBOL(gr_set_kernel_label);
55569 +#ifdef CONFIG_SECURITY
55570 +EXPORT_SYMBOL(gr_check_user_change);
55571 +EXPORT_SYMBOL(gr_check_group_change);
55572 +#endif
55573 +
55574 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55575 new file mode 100644
55576 index 0000000..34fefda
55577 --- /dev/null
55578 +++ b/grsecurity/gracl_alloc.c
55579 @@ -0,0 +1,105 @@
55580 +#include <linux/kernel.h>
55581 +#include <linux/mm.h>
55582 +#include <linux/slab.h>
55583 +#include <linux/vmalloc.h>
55584 +#include <linux/gracl.h>
55585 +#include <linux/grsecurity.h>
55586 +
55587 +static unsigned long alloc_stack_next = 1;
55588 +static unsigned long alloc_stack_size = 1;
55589 +static void **alloc_stack;
55590 +
55591 +static __inline__ int
55592 +alloc_pop(void)
55593 +{
55594 + if (alloc_stack_next == 1)
55595 + return 0;
55596 +
55597 + kfree(alloc_stack[alloc_stack_next - 2]);
55598 +
55599 + alloc_stack_next--;
55600 +
55601 + return 1;
55602 +}
55603 +
55604 +static __inline__ int
55605 +alloc_push(void *buf)
55606 +{
55607 + if (alloc_stack_next >= alloc_stack_size)
55608 + return 1;
55609 +
55610 + alloc_stack[alloc_stack_next - 1] = buf;
55611 +
55612 + alloc_stack_next++;
55613 +
55614 + return 0;
55615 +}
55616 +
55617 +void *
55618 +acl_alloc(unsigned long len)
55619 +{
55620 + void *ret = NULL;
55621 +
55622 + if (!len || len > PAGE_SIZE)
55623 + goto out;
55624 +
55625 + ret = kmalloc(len, GFP_KERNEL);
55626 +
55627 + if (ret) {
55628 + if (alloc_push(ret)) {
55629 + kfree(ret);
55630 + ret = NULL;
55631 + }
55632 + }
55633 +
55634 +out:
55635 + return ret;
55636 +}
55637 +
55638 +void *
55639 +acl_alloc_num(unsigned long num, unsigned long len)
55640 +{
55641 + if (!len || (num > (PAGE_SIZE / len)))
55642 + return NULL;
55643 +
55644 + return acl_alloc(num * len);
55645 +}
55646 +
55647 +void
55648 +acl_free_all(void)
55649 +{
55650 + if (gr_acl_is_enabled() || !alloc_stack)
55651 + return;
55652 +
55653 + while (alloc_pop()) ;
55654 +
55655 + if (alloc_stack) {
55656 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55657 + kfree(alloc_stack);
55658 + else
55659 + vfree(alloc_stack);
55660 + }
55661 +
55662 + alloc_stack = NULL;
55663 + alloc_stack_size = 1;
55664 + alloc_stack_next = 1;
55665 +
55666 + return;
55667 +}
55668 +
55669 +int
55670 +acl_alloc_stack_init(unsigned long size)
55671 +{
55672 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55673 + alloc_stack =
55674 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55675 + else
55676 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55677 +
55678 + alloc_stack_size = size;
55679 +
55680 + if (!alloc_stack)
55681 + return 0;
55682 + else
55683 + return 1;
55684 +}
55685 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55686 new file mode 100644
55687 index 0000000..6d21049
55688 --- /dev/null
55689 +++ b/grsecurity/gracl_cap.c
55690 @@ -0,0 +1,110 @@
55691 +#include <linux/kernel.h>
55692 +#include <linux/module.h>
55693 +#include <linux/sched.h>
55694 +#include <linux/gracl.h>
55695 +#include <linux/grsecurity.h>
55696 +#include <linux/grinternal.h>
55697 +
55698 +extern const char *captab_log[];
55699 +extern int captab_log_entries;
55700 +
55701 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55702 +{
55703 + struct acl_subject_label *curracl;
55704 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55705 + kernel_cap_t cap_audit = __cap_empty_set;
55706 +
55707 + if (!gr_acl_is_enabled())
55708 + return 1;
55709 +
55710 + curracl = task->acl;
55711 +
55712 + cap_drop = curracl->cap_lower;
55713 + cap_mask = curracl->cap_mask;
55714 + cap_audit = curracl->cap_invert_audit;
55715 +
55716 + while ((curracl = curracl->parent_subject)) {
55717 + /* if the cap isn't specified in the current computed mask but is specified in the
55718 + current level subject, and is lowered in the current level subject, then add
55719 + it to the set of dropped capabilities
55720 + otherwise, add the current level subject's mask to the current computed mask
55721 + */
55722 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55723 + cap_raise(cap_mask, cap);
55724 + if (cap_raised(curracl->cap_lower, cap))
55725 + cap_raise(cap_drop, cap);
55726 + if (cap_raised(curracl->cap_invert_audit, cap))
55727 + cap_raise(cap_audit, cap);
55728 + }
55729 + }
55730 +
55731 + if (!cap_raised(cap_drop, cap)) {
55732 + if (cap_raised(cap_audit, cap))
55733 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55734 + return 1;
55735 + }
55736 +
55737 + curracl = task->acl;
55738 +
55739 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55740 + && cap_raised(cred->cap_effective, cap)) {
55741 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55742 + task->role->roletype, cred->uid,
55743 + cred->gid, task->exec_file ?
55744 + gr_to_filename(task->exec_file->f_path.dentry,
55745 + task->exec_file->f_path.mnt) : curracl->filename,
55746 + curracl->filename, 0UL,
55747 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55748 + return 1;
55749 + }
55750 +
55751 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55752 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55753 +
55754 + return 0;
55755 +}
55756 +
55757 +int
55758 +gr_acl_is_capable(const int cap)
55759 +{
55760 + return gr_task_acl_is_capable(current, current_cred(), cap);
55761 +}
55762 +
55763 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55764 +{
55765 + struct acl_subject_label *curracl;
55766 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55767 +
55768 + if (!gr_acl_is_enabled())
55769 + return 1;
55770 +
55771 + curracl = task->acl;
55772 +
55773 + cap_drop = curracl->cap_lower;
55774 + cap_mask = curracl->cap_mask;
55775 +
55776 + while ((curracl = curracl->parent_subject)) {
55777 + /* if the cap isn't specified in the current computed mask but is specified in the
55778 + current level subject, and is lowered in the current level subject, then add
55779 + it to the set of dropped capabilities
55780 + otherwise, add the current level subject's mask to the current computed mask
55781 + */
55782 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55783 + cap_raise(cap_mask, cap);
55784 + if (cap_raised(curracl->cap_lower, cap))
55785 + cap_raise(cap_drop, cap);
55786 + }
55787 + }
55788 +
55789 + if (!cap_raised(cap_drop, cap))
55790 + return 1;
55791 +
55792 + return 0;
55793 +}
55794 +
55795 +int
55796 +gr_acl_is_capable_nolog(const int cap)
55797 +{
55798 + return gr_task_acl_is_capable_nolog(current, cap);
55799 +}
55800 +
55801 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55802 new file mode 100644
55803 index 0000000..d28e241
55804 --- /dev/null
55805 +++ b/grsecurity/gracl_fs.c
55806 @@ -0,0 +1,437 @@
55807 +#include <linux/kernel.h>
55808 +#include <linux/sched.h>
55809 +#include <linux/types.h>
55810 +#include <linux/fs.h>
55811 +#include <linux/file.h>
55812 +#include <linux/stat.h>
55813 +#include <linux/grsecurity.h>
55814 +#include <linux/grinternal.h>
55815 +#include <linux/gracl.h>
55816 +
55817 +umode_t
55818 +gr_acl_umask(void)
55819 +{
55820 + if (unlikely(!gr_acl_is_enabled()))
55821 + return 0;
55822 +
55823 + return current->role->umask;
55824 +}
55825 +
55826 +__u32
55827 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55828 + const struct vfsmount * mnt)
55829 +{
55830 + __u32 mode;
55831 +
55832 + if (unlikely(!dentry->d_inode))
55833 + return GR_FIND;
55834 +
55835 + mode =
55836 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55837 +
55838 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55839 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55840 + return mode;
55841 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55842 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55843 + return 0;
55844 + } else if (unlikely(!(mode & GR_FIND)))
55845 + return 0;
55846 +
55847 + return GR_FIND;
55848 +}
55849 +
55850 +__u32
55851 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55852 + int acc_mode)
55853 +{
55854 + __u32 reqmode = GR_FIND;
55855 + __u32 mode;
55856 +
55857 + if (unlikely(!dentry->d_inode))
55858 + return reqmode;
55859 +
55860 + if (acc_mode & MAY_APPEND)
55861 + reqmode |= GR_APPEND;
55862 + else if (acc_mode & MAY_WRITE)
55863 + reqmode |= GR_WRITE;
55864 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55865 + reqmode |= GR_READ;
55866 +
55867 + mode =
55868 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55869 + mnt);
55870 +
55871 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55872 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55873 + reqmode & GR_READ ? " reading" : "",
55874 + reqmode & GR_WRITE ? " writing" : reqmode &
55875 + GR_APPEND ? " appending" : "");
55876 + return reqmode;
55877 + } else
55878 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55879 + {
55880 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55881 + reqmode & GR_READ ? " reading" : "",
55882 + reqmode & GR_WRITE ? " writing" : reqmode &
55883 + GR_APPEND ? " appending" : "");
55884 + return 0;
55885 + } else if (unlikely((mode & reqmode) != reqmode))
55886 + return 0;
55887 +
55888 + return reqmode;
55889 +}
55890 +
55891 +__u32
55892 +gr_acl_handle_creat(const struct dentry * dentry,
55893 + const struct dentry * p_dentry,
55894 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55895 + const int imode)
55896 +{
55897 + __u32 reqmode = GR_WRITE | GR_CREATE;
55898 + __u32 mode;
55899 +
55900 + if (acc_mode & MAY_APPEND)
55901 + reqmode |= GR_APPEND;
55902 + // if a directory was required or the directory already exists, then
55903 + // don't count this open as a read
55904 + if ((acc_mode & MAY_READ) &&
55905 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55906 + reqmode |= GR_READ;
55907 + if ((open_flags & O_CREAT) &&
55908 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55909 + reqmode |= GR_SETID;
55910 +
55911 + mode =
55912 + gr_check_create(dentry, p_dentry, p_mnt,
55913 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55914 +
55915 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55916 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55917 + reqmode & GR_READ ? " reading" : "",
55918 + reqmode & GR_WRITE ? " writing" : reqmode &
55919 + GR_APPEND ? " appending" : "");
55920 + return reqmode;
55921 + } else
55922 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55923 + {
55924 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55925 + reqmode & GR_READ ? " reading" : "",
55926 + reqmode & GR_WRITE ? " writing" : reqmode &
55927 + GR_APPEND ? " appending" : "");
55928 + return 0;
55929 + } else if (unlikely((mode & reqmode) != reqmode))
55930 + return 0;
55931 +
55932 + return reqmode;
55933 +}
55934 +
55935 +__u32
55936 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55937 + const int fmode)
55938 +{
55939 + __u32 mode, reqmode = GR_FIND;
55940 +
55941 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55942 + reqmode |= GR_EXEC;
55943 + if (fmode & S_IWOTH)
55944 + reqmode |= GR_WRITE;
55945 + if (fmode & S_IROTH)
55946 + reqmode |= GR_READ;
55947 +
55948 + mode =
55949 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55950 + mnt);
55951 +
55952 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55953 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55954 + reqmode & GR_READ ? " reading" : "",
55955 + reqmode & GR_WRITE ? " writing" : "",
55956 + reqmode & GR_EXEC ? " executing" : "");
55957 + return reqmode;
55958 + } else
55959 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55960 + {
55961 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55962 + reqmode & GR_READ ? " reading" : "",
55963 + reqmode & GR_WRITE ? " writing" : "",
55964 + reqmode & GR_EXEC ? " executing" : "");
55965 + return 0;
55966 + } else if (unlikely((mode & reqmode) != reqmode))
55967 + return 0;
55968 +
55969 + return reqmode;
55970 +}
55971 +
55972 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55973 +{
55974 + __u32 mode;
55975 +
55976 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55977 +
55978 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55979 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55980 + return mode;
55981 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55982 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55983 + return 0;
55984 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55985 + return 0;
55986 +
55987 + return (reqmode);
55988 +}
55989 +
55990 +__u32
55991 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55992 +{
55993 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55994 +}
55995 +
55996 +__u32
55997 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55998 +{
55999 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56000 +}
56001 +
56002 +__u32
56003 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56004 +{
56005 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56006 +}
56007 +
56008 +__u32
56009 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56010 +{
56011 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56012 +}
56013 +
56014 +__u32
56015 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56016 + umode_t *modeptr)
56017 +{
56018 + umode_t mode;
56019 +
56020 + *modeptr &= ~gr_acl_umask();
56021 + mode = *modeptr;
56022 +
56023 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56024 + return 1;
56025 +
56026 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56027 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56028 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56029 + GR_CHMOD_ACL_MSG);
56030 + } else {
56031 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56032 + }
56033 +}
56034 +
56035 +__u32
56036 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56037 +{
56038 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56039 +}
56040 +
56041 +__u32
56042 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56043 +{
56044 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56045 +}
56046 +
56047 +__u32
56048 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56049 +{
56050 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56051 +}
56052 +
56053 +__u32
56054 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56055 +{
56056 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56057 + GR_UNIXCONNECT_ACL_MSG);
56058 +}
56059 +
56060 +/* hardlinks require at minimum create and link permission,
56061 + any additional privilege required is based on the
56062 + privilege of the file being linked to
56063 +*/
56064 +__u32
56065 +gr_acl_handle_link(const struct dentry * new_dentry,
56066 + const struct dentry * parent_dentry,
56067 + const struct vfsmount * parent_mnt,
56068 + const struct dentry * old_dentry,
56069 + const struct vfsmount * old_mnt, const char *to)
56070 +{
56071 + __u32 mode;
56072 + __u32 needmode = GR_CREATE | GR_LINK;
56073 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56074 +
56075 + mode =
56076 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56077 + old_mnt);
56078 +
56079 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56080 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56081 + return mode;
56082 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56083 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56084 + return 0;
56085 + } else if (unlikely((mode & needmode) != needmode))
56086 + return 0;
56087 +
56088 + return 1;
56089 +}
56090 +
56091 +__u32
56092 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56093 + const struct dentry * parent_dentry,
56094 + const struct vfsmount * parent_mnt, const char *from)
56095 +{
56096 + __u32 needmode = GR_WRITE | GR_CREATE;
56097 + __u32 mode;
56098 +
56099 + mode =
56100 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56101 + GR_CREATE | GR_AUDIT_CREATE |
56102 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56103 +
56104 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56105 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56106 + return mode;
56107 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56108 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56109 + return 0;
56110 + } else if (unlikely((mode & needmode) != needmode))
56111 + return 0;
56112 +
56113 + return (GR_WRITE | GR_CREATE);
56114 +}
56115 +
56116 +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)
56117 +{
56118 + __u32 mode;
56119 +
56120 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56121 +
56122 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56123 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56124 + return mode;
56125 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56126 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56127 + return 0;
56128 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56129 + return 0;
56130 +
56131 + return (reqmode);
56132 +}
56133 +
56134 +__u32
56135 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56136 + const struct dentry * parent_dentry,
56137 + const struct vfsmount * parent_mnt,
56138 + const int mode)
56139 +{
56140 + __u32 reqmode = GR_WRITE | GR_CREATE;
56141 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56142 + reqmode |= GR_SETID;
56143 +
56144 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56145 + reqmode, GR_MKNOD_ACL_MSG);
56146 +}
56147 +
56148 +__u32
56149 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56150 + const struct dentry *parent_dentry,
56151 + const struct vfsmount *parent_mnt)
56152 +{
56153 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56154 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56155 +}
56156 +
56157 +#define RENAME_CHECK_SUCCESS(old, new) \
56158 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56159 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56160 +
56161 +int
56162 +gr_acl_handle_rename(struct dentry *new_dentry,
56163 + struct dentry *parent_dentry,
56164 + const struct vfsmount *parent_mnt,
56165 + struct dentry *old_dentry,
56166 + struct inode *old_parent_inode,
56167 + struct vfsmount *old_mnt, const char *newname)
56168 +{
56169 + __u32 comp1, comp2;
56170 + int error = 0;
56171 +
56172 + if (unlikely(!gr_acl_is_enabled()))
56173 + return 0;
56174 +
56175 + if (!new_dentry->d_inode) {
56176 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56177 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56178 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56179 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56180 + GR_DELETE | GR_AUDIT_DELETE |
56181 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56182 + GR_SUPPRESS, old_mnt);
56183 + } else {
56184 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56185 + GR_CREATE | GR_DELETE |
56186 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56187 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56188 + GR_SUPPRESS, parent_mnt);
56189 + comp2 =
56190 + gr_search_file(old_dentry,
56191 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56192 + GR_DELETE | GR_AUDIT_DELETE |
56193 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56194 + }
56195 +
56196 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56197 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56198 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56199 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56200 + && !(comp2 & GR_SUPPRESS)) {
56201 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56202 + error = -EACCES;
56203 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56204 + error = -EACCES;
56205 +
56206 + return error;
56207 +}
56208 +
56209 +void
56210 +gr_acl_handle_exit(void)
56211 +{
56212 + u16 id;
56213 + char *rolename;
56214 + struct file *exec_file;
56215 +
56216 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56217 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56218 + id = current->acl_role_id;
56219 + rolename = current->role->rolename;
56220 + gr_set_acls(1);
56221 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56222 + }
56223 +
56224 + write_lock(&grsec_exec_file_lock);
56225 + exec_file = current->exec_file;
56226 + current->exec_file = NULL;
56227 + write_unlock(&grsec_exec_file_lock);
56228 +
56229 + if (exec_file)
56230 + fput(exec_file);
56231 +}
56232 +
56233 +int
56234 +gr_acl_handle_procpidmem(const struct task_struct *task)
56235 +{
56236 + if (unlikely(!gr_acl_is_enabled()))
56237 + return 0;
56238 +
56239 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56240 + return -EACCES;
56241 +
56242 + return 0;
56243 +}
56244 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56245 new file mode 100644
56246 index 0000000..58800a7
56247 --- /dev/null
56248 +++ b/grsecurity/gracl_ip.c
56249 @@ -0,0 +1,384 @@
56250 +#include <linux/kernel.h>
56251 +#include <asm/uaccess.h>
56252 +#include <asm/errno.h>
56253 +#include <net/sock.h>
56254 +#include <linux/file.h>
56255 +#include <linux/fs.h>
56256 +#include <linux/net.h>
56257 +#include <linux/in.h>
56258 +#include <linux/skbuff.h>
56259 +#include <linux/ip.h>
56260 +#include <linux/udp.h>
56261 +#include <linux/types.h>
56262 +#include <linux/sched.h>
56263 +#include <linux/netdevice.h>
56264 +#include <linux/inetdevice.h>
56265 +#include <linux/gracl.h>
56266 +#include <linux/grsecurity.h>
56267 +#include <linux/grinternal.h>
56268 +
56269 +#define GR_BIND 0x01
56270 +#define GR_CONNECT 0x02
56271 +#define GR_INVERT 0x04
56272 +#define GR_BINDOVERRIDE 0x08
56273 +#define GR_CONNECTOVERRIDE 0x10
56274 +#define GR_SOCK_FAMILY 0x20
56275 +
56276 +static const char * gr_protocols[IPPROTO_MAX] = {
56277 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56278 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56279 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56280 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56281 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56282 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56283 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56284 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56285 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56286 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56287 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56288 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56289 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56290 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56291 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56292 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56293 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56294 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56295 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56296 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56297 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56298 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56299 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56300 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56301 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56302 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56303 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56304 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56305 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56306 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56307 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56308 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56309 + };
56310 +
56311 +static const char * gr_socktypes[SOCK_MAX] = {
56312 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56313 + "unknown:7", "unknown:8", "unknown:9", "packet"
56314 + };
56315 +
56316 +static const char * gr_sockfamilies[AF_MAX+1] = {
56317 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56318 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56319 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56320 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56321 + };
56322 +
56323 +const char *
56324 +gr_proto_to_name(unsigned char proto)
56325 +{
56326 + return gr_protocols[proto];
56327 +}
56328 +
56329 +const char *
56330 +gr_socktype_to_name(unsigned char type)
56331 +{
56332 + return gr_socktypes[type];
56333 +}
56334 +
56335 +const char *
56336 +gr_sockfamily_to_name(unsigned char family)
56337 +{
56338 + return gr_sockfamilies[family];
56339 +}
56340 +
56341 +int
56342 +gr_search_socket(const int domain, const int type, const int protocol)
56343 +{
56344 + struct acl_subject_label *curr;
56345 + const struct cred *cred = current_cred();
56346 +
56347 + if (unlikely(!gr_acl_is_enabled()))
56348 + goto exit;
56349 +
56350 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56351 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56352 + goto exit; // let the kernel handle it
56353 +
56354 + curr = current->acl;
56355 +
56356 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56357 + /* the family is allowed, if this is PF_INET allow it only if
56358 + the extra sock type/protocol checks pass */
56359 + if (domain == PF_INET)
56360 + goto inet_check;
56361 + goto exit;
56362 + } else {
56363 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56364 + __u32 fakeip = 0;
56365 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56366 + current->role->roletype, cred->uid,
56367 + cred->gid, current->exec_file ?
56368 + gr_to_filename(current->exec_file->f_path.dentry,
56369 + current->exec_file->f_path.mnt) :
56370 + curr->filename, curr->filename,
56371 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56372 + &current->signal->saved_ip);
56373 + goto exit;
56374 + }
56375 + goto exit_fail;
56376 + }
56377 +
56378 +inet_check:
56379 + /* the rest of this checking is for IPv4 only */
56380 + if (!curr->ips)
56381 + goto exit;
56382 +
56383 + if ((curr->ip_type & (1 << type)) &&
56384 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56385 + goto exit;
56386 +
56387 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56388 + /* we don't place acls on raw sockets , and sometimes
56389 + dgram/ip sockets are opened for ioctl and not
56390 + bind/connect, so we'll fake a bind learn log */
56391 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56392 + __u32 fakeip = 0;
56393 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56394 + current->role->roletype, cred->uid,
56395 + cred->gid, current->exec_file ?
56396 + gr_to_filename(current->exec_file->f_path.dentry,
56397 + current->exec_file->f_path.mnt) :
56398 + curr->filename, curr->filename,
56399 + &fakeip, 0, type,
56400 + protocol, GR_CONNECT, &current->signal->saved_ip);
56401 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56402 + __u32 fakeip = 0;
56403 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56404 + current->role->roletype, cred->uid,
56405 + cred->gid, current->exec_file ?
56406 + gr_to_filename(current->exec_file->f_path.dentry,
56407 + current->exec_file->f_path.mnt) :
56408 + curr->filename, curr->filename,
56409 + &fakeip, 0, type,
56410 + protocol, GR_BIND, &current->signal->saved_ip);
56411 + }
56412 + /* we'll log when they use connect or bind */
56413 + goto exit;
56414 + }
56415 +
56416 +exit_fail:
56417 + if (domain == PF_INET)
56418 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56419 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56420 + else
56421 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56422 + gr_socktype_to_name(type), protocol);
56423 +
56424 + return 0;
56425 +exit:
56426 + return 1;
56427 +}
56428 +
56429 +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)
56430 +{
56431 + if ((ip->mode & mode) &&
56432 + (ip_port >= ip->low) &&
56433 + (ip_port <= ip->high) &&
56434 + ((ntohl(ip_addr) & our_netmask) ==
56435 + (ntohl(our_addr) & our_netmask))
56436 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56437 + && (ip->type & (1 << type))) {
56438 + if (ip->mode & GR_INVERT)
56439 + return 2; // specifically denied
56440 + else
56441 + return 1; // allowed
56442 + }
56443 +
56444 + return 0; // not specifically allowed, may continue parsing
56445 +}
56446 +
56447 +static int
56448 +gr_search_connectbind(const int full_mode, struct sock *sk,
56449 + struct sockaddr_in *addr, const int type)
56450 +{
56451 + char iface[IFNAMSIZ] = {0};
56452 + struct acl_subject_label *curr;
56453 + struct acl_ip_label *ip;
56454 + struct inet_sock *isk;
56455 + struct net_device *dev;
56456 + struct in_device *idev;
56457 + unsigned long i;
56458 + int ret;
56459 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56460 + __u32 ip_addr = 0;
56461 + __u32 our_addr;
56462 + __u32 our_netmask;
56463 + char *p;
56464 + __u16 ip_port = 0;
56465 + const struct cred *cred = current_cred();
56466 +
56467 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56468 + return 0;
56469 +
56470 + curr = current->acl;
56471 + isk = inet_sk(sk);
56472 +
56473 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56474 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56475 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56476 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56477 + struct sockaddr_in saddr;
56478 + int err;
56479 +
56480 + saddr.sin_family = AF_INET;
56481 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56482 + saddr.sin_port = isk->inet_sport;
56483 +
56484 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56485 + if (err)
56486 + return err;
56487 +
56488 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56489 + if (err)
56490 + return err;
56491 + }
56492 +
56493 + if (!curr->ips)
56494 + return 0;
56495 +
56496 + ip_addr = addr->sin_addr.s_addr;
56497 + ip_port = ntohs(addr->sin_port);
56498 +
56499 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56500 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56501 + current->role->roletype, cred->uid,
56502 + cred->gid, current->exec_file ?
56503 + gr_to_filename(current->exec_file->f_path.dentry,
56504 + current->exec_file->f_path.mnt) :
56505 + curr->filename, curr->filename,
56506 + &ip_addr, ip_port, type,
56507 + sk->sk_protocol, mode, &current->signal->saved_ip);
56508 + return 0;
56509 + }
56510 +
56511 + for (i = 0; i < curr->ip_num; i++) {
56512 + ip = *(curr->ips + i);
56513 + if (ip->iface != NULL) {
56514 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56515 + p = strchr(iface, ':');
56516 + if (p != NULL)
56517 + *p = '\0';
56518 + dev = dev_get_by_name(sock_net(sk), iface);
56519 + if (dev == NULL)
56520 + continue;
56521 + idev = in_dev_get(dev);
56522 + if (idev == NULL) {
56523 + dev_put(dev);
56524 + continue;
56525 + }
56526 + rcu_read_lock();
56527 + for_ifa(idev) {
56528 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56529 + our_addr = ifa->ifa_address;
56530 + our_netmask = 0xffffffff;
56531 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56532 + if (ret == 1) {
56533 + rcu_read_unlock();
56534 + in_dev_put(idev);
56535 + dev_put(dev);
56536 + return 0;
56537 + } else if (ret == 2) {
56538 + rcu_read_unlock();
56539 + in_dev_put(idev);
56540 + dev_put(dev);
56541 + goto denied;
56542 + }
56543 + }
56544 + } endfor_ifa(idev);
56545 + rcu_read_unlock();
56546 + in_dev_put(idev);
56547 + dev_put(dev);
56548 + } else {
56549 + our_addr = ip->addr;
56550 + our_netmask = ip->netmask;
56551 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56552 + if (ret == 1)
56553 + return 0;
56554 + else if (ret == 2)
56555 + goto denied;
56556 + }
56557 + }
56558 +
56559 +denied:
56560 + if (mode == GR_BIND)
56561 + 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));
56562 + else if (mode == GR_CONNECT)
56563 + 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));
56564 +
56565 + return -EACCES;
56566 +}
56567 +
56568 +int
56569 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56570 +{
56571 + /* always allow disconnection of dgram sockets with connect */
56572 + if (addr->sin_family == AF_UNSPEC)
56573 + return 0;
56574 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56575 +}
56576 +
56577 +int
56578 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56579 +{
56580 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56581 +}
56582 +
56583 +int gr_search_listen(struct socket *sock)
56584 +{
56585 + struct sock *sk = sock->sk;
56586 + struct sockaddr_in addr;
56587 +
56588 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56589 + addr.sin_port = inet_sk(sk)->inet_sport;
56590 +
56591 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56592 +}
56593 +
56594 +int gr_search_accept(struct socket *sock)
56595 +{
56596 + struct sock *sk = sock->sk;
56597 + struct sockaddr_in addr;
56598 +
56599 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56600 + addr.sin_port = inet_sk(sk)->inet_sport;
56601 +
56602 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56603 +}
56604 +
56605 +int
56606 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56607 +{
56608 + if (addr)
56609 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56610 + else {
56611 + struct sockaddr_in sin;
56612 + const struct inet_sock *inet = inet_sk(sk);
56613 +
56614 + sin.sin_addr.s_addr = inet->inet_daddr;
56615 + sin.sin_port = inet->inet_dport;
56616 +
56617 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56618 + }
56619 +}
56620 +
56621 +int
56622 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56623 +{
56624 + struct sockaddr_in sin;
56625 +
56626 + if (unlikely(skb->len < sizeof (struct udphdr)))
56627 + return 0; // skip this packet
56628 +
56629 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56630 + sin.sin_port = udp_hdr(skb)->source;
56631 +
56632 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56633 +}
56634 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56635 new file mode 100644
56636 index 0000000..25f54ef
56637 --- /dev/null
56638 +++ b/grsecurity/gracl_learn.c
56639 @@ -0,0 +1,207 @@
56640 +#include <linux/kernel.h>
56641 +#include <linux/mm.h>
56642 +#include <linux/sched.h>
56643 +#include <linux/poll.h>
56644 +#include <linux/string.h>
56645 +#include <linux/file.h>
56646 +#include <linux/types.h>
56647 +#include <linux/vmalloc.h>
56648 +#include <linux/grinternal.h>
56649 +
56650 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56651 + size_t count, loff_t *ppos);
56652 +extern int gr_acl_is_enabled(void);
56653 +
56654 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56655 +static int gr_learn_attached;
56656 +
56657 +/* use a 512k buffer */
56658 +#define LEARN_BUFFER_SIZE (512 * 1024)
56659 +
56660 +static DEFINE_SPINLOCK(gr_learn_lock);
56661 +static DEFINE_MUTEX(gr_learn_user_mutex);
56662 +
56663 +/* we need to maintain two buffers, so that the kernel context of grlearn
56664 + uses a semaphore around the userspace copying, and the other kernel contexts
56665 + use a spinlock when copying into the buffer, since they cannot sleep
56666 +*/
56667 +static char *learn_buffer;
56668 +static char *learn_buffer_user;
56669 +static int learn_buffer_len;
56670 +static int learn_buffer_user_len;
56671 +
56672 +static ssize_t
56673 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56674 +{
56675 + DECLARE_WAITQUEUE(wait, current);
56676 + ssize_t retval = 0;
56677 +
56678 + add_wait_queue(&learn_wait, &wait);
56679 + set_current_state(TASK_INTERRUPTIBLE);
56680 + do {
56681 + mutex_lock(&gr_learn_user_mutex);
56682 + spin_lock(&gr_learn_lock);
56683 + if (learn_buffer_len)
56684 + break;
56685 + spin_unlock(&gr_learn_lock);
56686 + mutex_unlock(&gr_learn_user_mutex);
56687 + if (file->f_flags & O_NONBLOCK) {
56688 + retval = -EAGAIN;
56689 + goto out;
56690 + }
56691 + if (signal_pending(current)) {
56692 + retval = -ERESTARTSYS;
56693 + goto out;
56694 + }
56695 +
56696 + schedule();
56697 + } while (1);
56698 +
56699 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56700 + learn_buffer_user_len = learn_buffer_len;
56701 + retval = learn_buffer_len;
56702 + learn_buffer_len = 0;
56703 +
56704 + spin_unlock(&gr_learn_lock);
56705 +
56706 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56707 + retval = -EFAULT;
56708 +
56709 + mutex_unlock(&gr_learn_user_mutex);
56710 +out:
56711 + set_current_state(TASK_RUNNING);
56712 + remove_wait_queue(&learn_wait, &wait);
56713 + return retval;
56714 +}
56715 +
56716 +static unsigned int
56717 +poll_learn(struct file * file, poll_table * wait)
56718 +{
56719 + poll_wait(file, &learn_wait, wait);
56720 +
56721 + if (learn_buffer_len)
56722 + return (POLLIN | POLLRDNORM);
56723 +
56724 + return 0;
56725 +}
56726 +
56727 +void
56728 +gr_clear_learn_entries(void)
56729 +{
56730 + char *tmp;
56731 +
56732 + mutex_lock(&gr_learn_user_mutex);
56733 + spin_lock(&gr_learn_lock);
56734 + tmp = learn_buffer;
56735 + learn_buffer = NULL;
56736 + spin_unlock(&gr_learn_lock);
56737 + if (tmp)
56738 + vfree(tmp);
56739 + if (learn_buffer_user != NULL) {
56740 + vfree(learn_buffer_user);
56741 + learn_buffer_user = NULL;
56742 + }
56743 + learn_buffer_len = 0;
56744 + mutex_unlock(&gr_learn_user_mutex);
56745 +
56746 + return;
56747 +}
56748 +
56749 +void
56750 +gr_add_learn_entry(const char *fmt, ...)
56751 +{
56752 + va_list args;
56753 + unsigned int len;
56754 +
56755 + if (!gr_learn_attached)
56756 + return;
56757 +
56758 + spin_lock(&gr_learn_lock);
56759 +
56760 + /* leave a gap at the end so we know when it's "full" but don't have to
56761 + compute the exact length of the string we're trying to append
56762 + */
56763 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56764 + spin_unlock(&gr_learn_lock);
56765 + wake_up_interruptible(&learn_wait);
56766 + return;
56767 + }
56768 + if (learn_buffer == NULL) {
56769 + spin_unlock(&gr_learn_lock);
56770 + return;
56771 + }
56772 +
56773 + va_start(args, fmt);
56774 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56775 + va_end(args);
56776 +
56777 + learn_buffer_len += len + 1;
56778 +
56779 + spin_unlock(&gr_learn_lock);
56780 + wake_up_interruptible(&learn_wait);
56781 +
56782 + return;
56783 +}
56784 +
56785 +static int
56786 +open_learn(struct inode *inode, struct file *file)
56787 +{
56788 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56789 + return -EBUSY;
56790 + if (file->f_mode & FMODE_READ) {
56791 + int retval = 0;
56792 + mutex_lock(&gr_learn_user_mutex);
56793 + if (learn_buffer == NULL)
56794 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56795 + if (learn_buffer_user == NULL)
56796 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56797 + if (learn_buffer == NULL) {
56798 + retval = -ENOMEM;
56799 + goto out_error;
56800 + }
56801 + if (learn_buffer_user == NULL) {
56802 + retval = -ENOMEM;
56803 + goto out_error;
56804 + }
56805 + learn_buffer_len = 0;
56806 + learn_buffer_user_len = 0;
56807 + gr_learn_attached = 1;
56808 +out_error:
56809 + mutex_unlock(&gr_learn_user_mutex);
56810 + return retval;
56811 + }
56812 + return 0;
56813 +}
56814 +
56815 +static int
56816 +close_learn(struct inode *inode, struct file *file)
56817 +{
56818 + if (file->f_mode & FMODE_READ) {
56819 + char *tmp = NULL;
56820 + mutex_lock(&gr_learn_user_mutex);
56821 + spin_lock(&gr_learn_lock);
56822 + tmp = learn_buffer;
56823 + learn_buffer = NULL;
56824 + spin_unlock(&gr_learn_lock);
56825 + if (tmp)
56826 + vfree(tmp);
56827 + if (learn_buffer_user != NULL) {
56828 + vfree(learn_buffer_user);
56829 + learn_buffer_user = NULL;
56830 + }
56831 + learn_buffer_len = 0;
56832 + learn_buffer_user_len = 0;
56833 + gr_learn_attached = 0;
56834 + mutex_unlock(&gr_learn_user_mutex);
56835 + }
56836 +
56837 + return 0;
56838 +}
56839 +
56840 +const struct file_operations grsec_fops = {
56841 + .read = read_learn,
56842 + .write = write_grsec_handler,
56843 + .open = open_learn,
56844 + .release = close_learn,
56845 + .poll = poll_learn,
56846 +};
56847 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56848 new file mode 100644
56849 index 0000000..39645c9
56850 --- /dev/null
56851 +++ b/grsecurity/gracl_res.c
56852 @@ -0,0 +1,68 @@
56853 +#include <linux/kernel.h>
56854 +#include <linux/sched.h>
56855 +#include <linux/gracl.h>
56856 +#include <linux/grinternal.h>
56857 +
56858 +static const char *restab_log[] = {
56859 + [RLIMIT_CPU] = "RLIMIT_CPU",
56860 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56861 + [RLIMIT_DATA] = "RLIMIT_DATA",
56862 + [RLIMIT_STACK] = "RLIMIT_STACK",
56863 + [RLIMIT_CORE] = "RLIMIT_CORE",
56864 + [RLIMIT_RSS] = "RLIMIT_RSS",
56865 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56866 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56867 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56868 + [RLIMIT_AS] = "RLIMIT_AS",
56869 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56870 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56871 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56872 + [RLIMIT_NICE] = "RLIMIT_NICE",
56873 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56874 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56875 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56876 +};
56877 +
56878 +void
56879 +gr_log_resource(const struct task_struct *task,
56880 + const int res, const unsigned long wanted, const int gt)
56881 +{
56882 + const struct cred *cred;
56883 + unsigned long rlim;
56884 +
56885 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56886 + return;
56887 +
56888 + // not yet supported resource
56889 + if (unlikely(!restab_log[res]))
56890 + return;
56891 +
56892 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56893 + rlim = task_rlimit_max(task, res);
56894 + else
56895 + rlim = task_rlimit(task, res);
56896 +
56897 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56898 + return;
56899 +
56900 + rcu_read_lock();
56901 + cred = __task_cred(task);
56902 +
56903 + if (res == RLIMIT_NPROC &&
56904 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56905 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56906 + goto out_rcu_unlock;
56907 + else if (res == RLIMIT_MEMLOCK &&
56908 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56909 + goto out_rcu_unlock;
56910 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56911 + goto out_rcu_unlock;
56912 + rcu_read_unlock();
56913 +
56914 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56915 +
56916 + return;
56917 +out_rcu_unlock:
56918 + rcu_read_unlock();
56919 + return;
56920 +}
56921 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56922 new file mode 100644
56923 index 0000000..25197e9
56924 --- /dev/null
56925 +++ b/grsecurity/gracl_segv.c
56926 @@ -0,0 +1,299 @@
56927 +#include <linux/kernel.h>
56928 +#include <linux/mm.h>
56929 +#include <asm/uaccess.h>
56930 +#include <asm/errno.h>
56931 +#include <asm/mman.h>
56932 +#include <net/sock.h>
56933 +#include <linux/file.h>
56934 +#include <linux/fs.h>
56935 +#include <linux/net.h>
56936 +#include <linux/in.h>
56937 +#include <linux/slab.h>
56938 +#include <linux/types.h>
56939 +#include <linux/sched.h>
56940 +#include <linux/timer.h>
56941 +#include <linux/gracl.h>
56942 +#include <linux/grsecurity.h>
56943 +#include <linux/grinternal.h>
56944 +
56945 +static struct crash_uid *uid_set;
56946 +static unsigned short uid_used;
56947 +static DEFINE_SPINLOCK(gr_uid_lock);
56948 +extern rwlock_t gr_inode_lock;
56949 +extern struct acl_subject_label *
56950 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56951 + struct acl_role_label *role);
56952 +
56953 +#ifdef CONFIG_BTRFS_FS
56954 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56955 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56956 +#endif
56957 +
56958 +static inline dev_t __get_dev(const struct dentry *dentry)
56959 +{
56960 +#ifdef CONFIG_BTRFS_FS
56961 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56962 + return get_btrfs_dev_from_inode(dentry->d_inode);
56963 + else
56964 +#endif
56965 + return dentry->d_inode->i_sb->s_dev;
56966 +}
56967 +
56968 +int
56969 +gr_init_uidset(void)
56970 +{
56971 + uid_set =
56972 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56973 + uid_used = 0;
56974 +
56975 + return uid_set ? 1 : 0;
56976 +}
56977 +
56978 +void
56979 +gr_free_uidset(void)
56980 +{
56981 + if (uid_set)
56982 + kfree(uid_set);
56983 +
56984 + return;
56985 +}
56986 +
56987 +int
56988 +gr_find_uid(const uid_t uid)
56989 +{
56990 + struct crash_uid *tmp = uid_set;
56991 + uid_t buid;
56992 + int low = 0, high = uid_used - 1, mid;
56993 +
56994 + while (high >= low) {
56995 + mid = (low + high) >> 1;
56996 + buid = tmp[mid].uid;
56997 + if (buid == uid)
56998 + return mid;
56999 + if (buid > uid)
57000 + high = mid - 1;
57001 + if (buid < uid)
57002 + low = mid + 1;
57003 + }
57004 +
57005 + return -1;
57006 +}
57007 +
57008 +static __inline__ void
57009 +gr_insertsort(void)
57010 +{
57011 + unsigned short i, j;
57012 + struct crash_uid index;
57013 +
57014 + for (i = 1; i < uid_used; i++) {
57015 + index = uid_set[i];
57016 + j = i;
57017 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57018 + uid_set[j] = uid_set[j - 1];
57019 + j--;
57020 + }
57021 + uid_set[j] = index;
57022 + }
57023 +
57024 + return;
57025 +}
57026 +
57027 +static __inline__ void
57028 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57029 +{
57030 + int loc;
57031 +
57032 + if (uid_used == GR_UIDTABLE_MAX)
57033 + return;
57034 +
57035 + loc = gr_find_uid(uid);
57036 +
57037 + if (loc >= 0) {
57038 + uid_set[loc].expires = expires;
57039 + return;
57040 + }
57041 +
57042 + uid_set[uid_used].uid = uid;
57043 + uid_set[uid_used].expires = expires;
57044 + uid_used++;
57045 +
57046 + gr_insertsort();
57047 +
57048 + return;
57049 +}
57050 +
57051 +void
57052 +gr_remove_uid(const unsigned short loc)
57053 +{
57054 + unsigned short i;
57055 +
57056 + for (i = loc + 1; i < uid_used; i++)
57057 + uid_set[i - 1] = uid_set[i];
57058 +
57059 + uid_used--;
57060 +
57061 + return;
57062 +}
57063 +
57064 +int
57065 +gr_check_crash_uid(const uid_t uid)
57066 +{
57067 + int loc;
57068 + int ret = 0;
57069 +
57070 + if (unlikely(!gr_acl_is_enabled()))
57071 + return 0;
57072 +
57073 + spin_lock(&gr_uid_lock);
57074 + loc = gr_find_uid(uid);
57075 +
57076 + if (loc < 0)
57077 + goto out_unlock;
57078 +
57079 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57080 + gr_remove_uid(loc);
57081 + else
57082 + ret = 1;
57083 +
57084 +out_unlock:
57085 + spin_unlock(&gr_uid_lock);
57086 + return ret;
57087 +}
57088 +
57089 +static __inline__ int
57090 +proc_is_setxid(const struct cred *cred)
57091 +{
57092 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57093 + !uid_eq(cred->uid, cred->fsuid))
57094 + return 1;
57095 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57096 + !uid_eq(cred->gid, cred->fsgid))
57097 + return 1;
57098 +
57099 + return 0;
57100 +}
57101 +
57102 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57103 +
57104 +void
57105 +gr_handle_crash(struct task_struct *task, const int sig)
57106 +{
57107 + struct acl_subject_label *curr;
57108 + struct task_struct *tsk, *tsk2;
57109 + const struct cred *cred;
57110 + const struct cred *cred2;
57111 +
57112 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57113 + return;
57114 +
57115 + if (unlikely(!gr_acl_is_enabled()))
57116 + return;
57117 +
57118 + curr = task->acl;
57119 +
57120 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57121 + return;
57122 +
57123 + if (time_before_eq(curr->expires, get_seconds())) {
57124 + curr->expires = 0;
57125 + curr->crashes = 0;
57126 + }
57127 +
57128 + curr->crashes++;
57129 +
57130 + if (!curr->expires)
57131 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57132 +
57133 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57134 + time_after(curr->expires, get_seconds())) {
57135 + rcu_read_lock();
57136 + cred = __task_cred(task);
57137 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57138 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57139 + spin_lock(&gr_uid_lock);
57140 + gr_insert_uid(cred->uid, curr->expires);
57141 + spin_unlock(&gr_uid_lock);
57142 + curr->expires = 0;
57143 + curr->crashes = 0;
57144 + read_lock(&tasklist_lock);
57145 + do_each_thread(tsk2, tsk) {
57146 + cred2 = __task_cred(tsk);
57147 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57148 + gr_fake_force_sig(SIGKILL, tsk);
57149 + } while_each_thread(tsk2, tsk);
57150 + read_unlock(&tasklist_lock);
57151 + } else {
57152 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57153 + read_lock(&tasklist_lock);
57154 + read_lock(&grsec_exec_file_lock);
57155 + do_each_thread(tsk2, tsk) {
57156 + if (likely(tsk != task)) {
57157 + // if this thread has the same subject as the one that triggered
57158 + // RES_CRASH and it's the same binary, kill it
57159 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57160 + gr_fake_force_sig(SIGKILL, tsk);
57161 + }
57162 + } while_each_thread(tsk2, tsk);
57163 + read_unlock(&grsec_exec_file_lock);
57164 + read_unlock(&tasklist_lock);
57165 + }
57166 + rcu_read_unlock();
57167 + }
57168 +
57169 + return;
57170 +}
57171 +
57172 +int
57173 +gr_check_crash_exec(const struct file *filp)
57174 +{
57175 + struct acl_subject_label *curr;
57176 +
57177 + if (unlikely(!gr_acl_is_enabled()))
57178 + return 0;
57179 +
57180 + read_lock(&gr_inode_lock);
57181 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57182 + __get_dev(filp->f_path.dentry),
57183 + current->role);
57184 + read_unlock(&gr_inode_lock);
57185 +
57186 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57187 + (!curr->crashes && !curr->expires))
57188 + return 0;
57189 +
57190 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57191 + time_after(curr->expires, get_seconds()))
57192 + return 1;
57193 + else if (time_before_eq(curr->expires, get_seconds())) {
57194 + curr->crashes = 0;
57195 + curr->expires = 0;
57196 + }
57197 +
57198 + return 0;
57199 +}
57200 +
57201 +void
57202 +gr_handle_alertkill(struct task_struct *task)
57203 +{
57204 + struct acl_subject_label *curracl;
57205 + __u32 curr_ip;
57206 + struct task_struct *p, *p2;
57207 +
57208 + if (unlikely(!gr_acl_is_enabled()))
57209 + return;
57210 +
57211 + curracl = task->acl;
57212 + curr_ip = task->signal->curr_ip;
57213 +
57214 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57215 + read_lock(&tasklist_lock);
57216 + do_each_thread(p2, p) {
57217 + if (p->signal->curr_ip == curr_ip)
57218 + gr_fake_force_sig(SIGKILL, p);
57219 + } while_each_thread(p2, p);
57220 + read_unlock(&tasklist_lock);
57221 + } else if (curracl->mode & GR_KILLPROC)
57222 + gr_fake_force_sig(SIGKILL, task);
57223 +
57224 + return;
57225 +}
57226 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57227 new file mode 100644
57228 index 0000000..9d83a69
57229 --- /dev/null
57230 +++ b/grsecurity/gracl_shm.c
57231 @@ -0,0 +1,40 @@
57232 +#include <linux/kernel.h>
57233 +#include <linux/mm.h>
57234 +#include <linux/sched.h>
57235 +#include <linux/file.h>
57236 +#include <linux/ipc.h>
57237 +#include <linux/gracl.h>
57238 +#include <linux/grsecurity.h>
57239 +#include <linux/grinternal.h>
57240 +
57241 +int
57242 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57243 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57244 +{
57245 + struct task_struct *task;
57246 +
57247 + if (!gr_acl_is_enabled())
57248 + return 1;
57249 +
57250 + rcu_read_lock();
57251 + read_lock(&tasklist_lock);
57252 +
57253 + task = find_task_by_vpid(shm_cprid);
57254 +
57255 + if (unlikely(!task))
57256 + task = find_task_by_vpid(shm_lapid);
57257 +
57258 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57259 + (task->pid == shm_lapid)) &&
57260 + (task->acl->mode & GR_PROTSHM) &&
57261 + (task->acl != current->acl))) {
57262 + read_unlock(&tasklist_lock);
57263 + rcu_read_unlock();
57264 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57265 + return 0;
57266 + }
57267 + read_unlock(&tasklist_lock);
57268 + rcu_read_unlock();
57269 +
57270 + return 1;
57271 +}
57272 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57273 new file mode 100644
57274 index 0000000..bc0be01
57275 --- /dev/null
57276 +++ b/grsecurity/grsec_chdir.c
57277 @@ -0,0 +1,19 @@
57278 +#include <linux/kernel.h>
57279 +#include <linux/sched.h>
57280 +#include <linux/fs.h>
57281 +#include <linux/file.h>
57282 +#include <linux/grsecurity.h>
57283 +#include <linux/grinternal.h>
57284 +
57285 +void
57286 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57287 +{
57288 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57289 + if ((grsec_enable_chdir && grsec_enable_group &&
57290 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57291 + !grsec_enable_group)) {
57292 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57293 + }
57294 +#endif
57295 + return;
57296 +}
57297 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57298 new file mode 100644
57299 index 0000000..9807ee2
57300 --- /dev/null
57301 +++ b/grsecurity/grsec_chroot.c
57302 @@ -0,0 +1,368 @@
57303 +#include <linux/kernel.h>
57304 +#include <linux/module.h>
57305 +#include <linux/sched.h>
57306 +#include <linux/file.h>
57307 +#include <linux/fs.h>
57308 +#include <linux/mount.h>
57309 +#include <linux/types.h>
57310 +#include "../fs/mount.h"
57311 +#include <linux/grsecurity.h>
57312 +#include <linux/grinternal.h>
57313 +
57314 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57315 +{
57316 +#ifdef CONFIG_GRKERNSEC
57317 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57318 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57319 + task->gr_is_chrooted = 1;
57320 + else
57321 + task->gr_is_chrooted = 0;
57322 +
57323 + task->gr_chroot_dentry = path->dentry;
57324 +#endif
57325 + return;
57326 +}
57327 +
57328 +void gr_clear_chroot_entries(struct task_struct *task)
57329 +{
57330 +#ifdef CONFIG_GRKERNSEC
57331 + task->gr_is_chrooted = 0;
57332 + task->gr_chroot_dentry = NULL;
57333 +#endif
57334 + return;
57335 +}
57336 +
57337 +int
57338 +gr_handle_chroot_unix(const pid_t pid)
57339 +{
57340 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57341 + struct task_struct *p;
57342 +
57343 + if (unlikely(!grsec_enable_chroot_unix))
57344 + return 1;
57345 +
57346 + if (likely(!proc_is_chrooted(current)))
57347 + return 1;
57348 +
57349 + rcu_read_lock();
57350 + read_lock(&tasklist_lock);
57351 + p = find_task_by_vpid_unrestricted(pid);
57352 + if (unlikely(p && !have_same_root(current, p))) {
57353 + read_unlock(&tasklist_lock);
57354 + rcu_read_unlock();
57355 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57356 + return 0;
57357 + }
57358 + read_unlock(&tasklist_lock);
57359 + rcu_read_unlock();
57360 +#endif
57361 + return 1;
57362 +}
57363 +
57364 +int
57365 +gr_handle_chroot_nice(void)
57366 +{
57367 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57368 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57369 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57370 + return -EPERM;
57371 + }
57372 +#endif
57373 + return 0;
57374 +}
57375 +
57376 +int
57377 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57378 +{
57379 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57380 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57381 + && proc_is_chrooted(current)) {
57382 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57383 + return -EACCES;
57384 + }
57385 +#endif
57386 + return 0;
57387 +}
57388 +
57389 +int
57390 +gr_handle_chroot_rawio(const struct inode *inode)
57391 +{
57392 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57393 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57394 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57395 + return 1;
57396 +#endif
57397 + return 0;
57398 +}
57399 +
57400 +int
57401 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57402 +{
57403 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57404 + struct task_struct *p;
57405 + int ret = 0;
57406 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57407 + return ret;
57408 +
57409 + read_lock(&tasklist_lock);
57410 + do_each_pid_task(pid, type, p) {
57411 + if (!have_same_root(current, p)) {
57412 + ret = 1;
57413 + goto out;
57414 + }
57415 + } while_each_pid_task(pid, type, p);
57416 +out:
57417 + read_unlock(&tasklist_lock);
57418 + return ret;
57419 +#endif
57420 + return 0;
57421 +}
57422 +
57423 +int
57424 +gr_pid_is_chrooted(struct task_struct *p)
57425 +{
57426 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57427 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57428 + return 0;
57429 +
57430 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57431 + !have_same_root(current, p)) {
57432 + return 1;
57433 + }
57434 +#endif
57435 + return 0;
57436 +}
57437 +
57438 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57439 +
57440 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57441 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57442 +{
57443 + struct path path, currentroot;
57444 + int ret = 0;
57445 +
57446 + path.dentry = (struct dentry *)u_dentry;
57447 + path.mnt = (struct vfsmount *)u_mnt;
57448 + get_fs_root(current->fs, &currentroot);
57449 + if (path_is_under(&path, &currentroot))
57450 + ret = 1;
57451 + path_put(&currentroot);
57452 +
57453 + return ret;
57454 +}
57455 +#endif
57456 +
57457 +int
57458 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57459 +{
57460 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57461 + if (!grsec_enable_chroot_fchdir)
57462 + return 1;
57463 +
57464 + if (!proc_is_chrooted(current))
57465 + return 1;
57466 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57467 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57468 + return 0;
57469 + }
57470 +#endif
57471 + return 1;
57472 +}
57473 +
57474 +int
57475 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57476 + const time_t shm_createtime)
57477 +{
57478 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57479 + struct task_struct *p;
57480 + time_t starttime;
57481 +
57482 + if (unlikely(!grsec_enable_chroot_shmat))
57483 + return 1;
57484 +
57485 + if (likely(!proc_is_chrooted(current)))
57486 + return 1;
57487 +
57488 + rcu_read_lock();
57489 + read_lock(&tasklist_lock);
57490 +
57491 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57492 + starttime = p->start_time.tv_sec;
57493 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57494 + if (have_same_root(current, p)) {
57495 + goto allow;
57496 + } else {
57497 + read_unlock(&tasklist_lock);
57498 + rcu_read_unlock();
57499 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57500 + return 0;
57501 + }
57502 + }
57503 + /* creator exited, pid reuse, fall through to next check */
57504 + }
57505 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57506 + if (unlikely(!have_same_root(current, p))) {
57507 + read_unlock(&tasklist_lock);
57508 + rcu_read_unlock();
57509 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57510 + return 0;
57511 + }
57512 + }
57513 +
57514 +allow:
57515 + read_unlock(&tasklist_lock);
57516 + rcu_read_unlock();
57517 +#endif
57518 + return 1;
57519 +}
57520 +
57521 +void
57522 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57523 +{
57524 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57525 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57526 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57527 +#endif
57528 + return;
57529 +}
57530 +
57531 +int
57532 +gr_handle_chroot_mknod(const struct dentry *dentry,
57533 + const struct vfsmount *mnt, const int mode)
57534 +{
57535 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57536 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57537 + proc_is_chrooted(current)) {
57538 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57539 + return -EPERM;
57540 + }
57541 +#endif
57542 + return 0;
57543 +}
57544 +
57545 +int
57546 +gr_handle_chroot_mount(const struct dentry *dentry,
57547 + const struct vfsmount *mnt, const char *dev_name)
57548 +{
57549 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57550 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57551 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57552 + return -EPERM;
57553 + }
57554 +#endif
57555 + return 0;
57556 +}
57557 +
57558 +int
57559 +gr_handle_chroot_pivot(void)
57560 +{
57561 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57562 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57563 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57564 + return -EPERM;
57565 + }
57566 +#endif
57567 + return 0;
57568 +}
57569 +
57570 +int
57571 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57572 +{
57573 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57574 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57575 + !gr_is_outside_chroot(dentry, mnt)) {
57576 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57577 + return -EPERM;
57578 + }
57579 +#endif
57580 + return 0;
57581 +}
57582 +
57583 +extern const char *captab_log[];
57584 +extern int captab_log_entries;
57585 +
57586 +int
57587 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57588 +{
57589 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57590 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57591 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57592 + if (cap_raised(chroot_caps, cap)) {
57593 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57594 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57595 + }
57596 + return 0;
57597 + }
57598 + }
57599 +#endif
57600 + return 1;
57601 +}
57602 +
57603 +int
57604 +gr_chroot_is_capable(const int cap)
57605 +{
57606 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57607 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57608 +#endif
57609 + return 1;
57610 +}
57611 +
57612 +int
57613 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57614 +{
57615 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57616 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57617 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57618 + if (cap_raised(chroot_caps, cap)) {
57619 + return 0;
57620 + }
57621 + }
57622 +#endif
57623 + return 1;
57624 +}
57625 +
57626 +int
57627 +gr_chroot_is_capable_nolog(const int cap)
57628 +{
57629 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57630 + return gr_task_chroot_is_capable_nolog(current, cap);
57631 +#endif
57632 + return 1;
57633 +}
57634 +
57635 +int
57636 +gr_handle_chroot_sysctl(const int op)
57637 +{
57638 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57639 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57640 + proc_is_chrooted(current))
57641 + return -EACCES;
57642 +#endif
57643 + return 0;
57644 +}
57645 +
57646 +void
57647 +gr_handle_chroot_chdir(struct path *path)
57648 +{
57649 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57650 + if (grsec_enable_chroot_chdir)
57651 + set_fs_pwd(current->fs, path);
57652 +#endif
57653 + return;
57654 +}
57655 +
57656 +int
57657 +gr_handle_chroot_chmod(const struct dentry *dentry,
57658 + const struct vfsmount *mnt, const int mode)
57659 +{
57660 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57661 + /* allow chmod +s on directories, but not files */
57662 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57663 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57664 + proc_is_chrooted(current)) {
57665 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57666 + return -EPERM;
57667 + }
57668 +#endif
57669 + return 0;
57670 +}
57671 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57672 new file mode 100644
57673 index 0000000..213ad8b
57674 --- /dev/null
57675 +++ b/grsecurity/grsec_disabled.c
57676 @@ -0,0 +1,437 @@
57677 +#include <linux/kernel.h>
57678 +#include <linux/module.h>
57679 +#include <linux/sched.h>
57680 +#include <linux/file.h>
57681 +#include <linux/fs.h>
57682 +#include <linux/kdev_t.h>
57683 +#include <linux/net.h>
57684 +#include <linux/in.h>
57685 +#include <linux/ip.h>
57686 +#include <linux/skbuff.h>
57687 +#include <linux/sysctl.h>
57688 +
57689 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57690 +void
57691 +pax_set_initial_flags(struct linux_binprm *bprm)
57692 +{
57693 + return;
57694 +}
57695 +#endif
57696 +
57697 +#ifdef CONFIG_SYSCTL
57698 +__u32
57699 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57700 +{
57701 + return 0;
57702 +}
57703 +#endif
57704 +
57705 +#ifdef CONFIG_TASKSTATS
57706 +int gr_is_taskstats_denied(int pid)
57707 +{
57708 + return 0;
57709 +}
57710 +#endif
57711 +
57712 +int
57713 +gr_acl_is_enabled(void)
57714 +{
57715 + return 0;
57716 +}
57717 +
57718 +void
57719 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57720 +{
57721 + return;
57722 +}
57723 +
57724 +int
57725 +gr_handle_rawio(const struct inode *inode)
57726 +{
57727 + return 0;
57728 +}
57729 +
57730 +void
57731 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57732 +{
57733 + return;
57734 +}
57735 +
57736 +int
57737 +gr_handle_ptrace(struct task_struct *task, const long request)
57738 +{
57739 + return 0;
57740 +}
57741 +
57742 +int
57743 +gr_handle_proc_ptrace(struct task_struct *task)
57744 +{
57745 + return 0;
57746 +}
57747 +
57748 +void
57749 +gr_learn_resource(const struct task_struct *task,
57750 + const int res, const unsigned long wanted, const int gt)
57751 +{
57752 + return;
57753 +}
57754 +
57755 +int
57756 +gr_set_acls(const int type)
57757 +{
57758 + return 0;
57759 +}
57760 +
57761 +int
57762 +gr_check_hidden_task(const struct task_struct *tsk)
57763 +{
57764 + return 0;
57765 +}
57766 +
57767 +int
57768 +gr_check_protected_task(const struct task_struct *task)
57769 +{
57770 + return 0;
57771 +}
57772 +
57773 +int
57774 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57775 +{
57776 + return 0;
57777 +}
57778 +
57779 +void
57780 +gr_copy_label(struct task_struct *tsk)
57781 +{
57782 + return;
57783 +}
57784 +
57785 +void
57786 +gr_set_pax_flags(struct task_struct *task)
57787 +{
57788 + return;
57789 +}
57790 +
57791 +int
57792 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57793 + const int unsafe_share)
57794 +{
57795 + return 0;
57796 +}
57797 +
57798 +void
57799 +gr_handle_delete(const ino_t ino, const dev_t dev)
57800 +{
57801 + return;
57802 +}
57803 +
57804 +void
57805 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57806 +{
57807 + return;
57808 +}
57809 +
57810 +void
57811 +gr_handle_crash(struct task_struct *task, const int sig)
57812 +{
57813 + return;
57814 +}
57815 +
57816 +int
57817 +gr_check_crash_exec(const struct file *filp)
57818 +{
57819 + return 0;
57820 +}
57821 +
57822 +int
57823 +gr_check_crash_uid(const uid_t uid)
57824 +{
57825 + return 0;
57826 +}
57827 +
57828 +void
57829 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57830 + struct dentry *old_dentry,
57831 + struct dentry *new_dentry,
57832 + struct vfsmount *mnt, const __u8 replace)
57833 +{
57834 + return;
57835 +}
57836 +
57837 +int
57838 +gr_search_socket(const int family, const int type, const int protocol)
57839 +{
57840 + return 1;
57841 +}
57842 +
57843 +int
57844 +gr_search_connectbind(const int mode, const struct socket *sock,
57845 + const struct sockaddr_in *addr)
57846 +{
57847 + return 0;
57848 +}
57849 +
57850 +void
57851 +gr_handle_alertkill(struct task_struct *task)
57852 +{
57853 + return;
57854 +}
57855 +
57856 +__u32
57857 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57858 +{
57859 + return 1;
57860 +}
57861 +
57862 +__u32
57863 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57864 + const struct vfsmount * mnt)
57865 +{
57866 + return 1;
57867 +}
57868 +
57869 +__u32
57870 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57871 + int acc_mode)
57872 +{
57873 + return 1;
57874 +}
57875 +
57876 +__u32
57877 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57878 +{
57879 + return 1;
57880 +}
57881 +
57882 +__u32
57883 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57884 +{
57885 + return 1;
57886 +}
57887 +
57888 +int
57889 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57890 + unsigned int *vm_flags)
57891 +{
57892 + return 1;
57893 +}
57894 +
57895 +__u32
57896 +gr_acl_handle_truncate(const struct dentry * dentry,
57897 + const struct vfsmount * mnt)
57898 +{
57899 + return 1;
57900 +}
57901 +
57902 +__u32
57903 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57904 +{
57905 + return 1;
57906 +}
57907 +
57908 +__u32
57909 +gr_acl_handle_access(const struct dentry * dentry,
57910 + const struct vfsmount * mnt, const int fmode)
57911 +{
57912 + return 1;
57913 +}
57914 +
57915 +__u32
57916 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57917 + umode_t *mode)
57918 +{
57919 + return 1;
57920 +}
57921 +
57922 +__u32
57923 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57924 +{
57925 + return 1;
57926 +}
57927 +
57928 +__u32
57929 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57930 +{
57931 + return 1;
57932 +}
57933 +
57934 +void
57935 +grsecurity_init(void)
57936 +{
57937 + return;
57938 +}
57939 +
57940 +umode_t gr_acl_umask(void)
57941 +{
57942 + return 0;
57943 +}
57944 +
57945 +__u32
57946 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57947 + const struct dentry * parent_dentry,
57948 + const struct vfsmount * parent_mnt,
57949 + const int mode)
57950 +{
57951 + return 1;
57952 +}
57953 +
57954 +__u32
57955 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57956 + const struct dentry * parent_dentry,
57957 + const struct vfsmount * parent_mnt)
57958 +{
57959 + return 1;
57960 +}
57961 +
57962 +__u32
57963 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57964 + const struct dentry * parent_dentry,
57965 + const struct vfsmount * parent_mnt, const char *from)
57966 +{
57967 + return 1;
57968 +}
57969 +
57970 +__u32
57971 +gr_acl_handle_link(const struct dentry * new_dentry,
57972 + const struct dentry * parent_dentry,
57973 + const struct vfsmount * parent_mnt,
57974 + const struct dentry * old_dentry,
57975 + const struct vfsmount * old_mnt, const char *to)
57976 +{
57977 + return 1;
57978 +}
57979 +
57980 +int
57981 +gr_acl_handle_rename(const struct dentry *new_dentry,
57982 + const struct dentry *parent_dentry,
57983 + const struct vfsmount *parent_mnt,
57984 + const struct dentry *old_dentry,
57985 + const struct inode *old_parent_inode,
57986 + const struct vfsmount *old_mnt, const char *newname)
57987 +{
57988 + return 0;
57989 +}
57990 +
57991 +int
57992 +gr_acl_handle_filldir(const struct file *file, const char *name,
57993 + const int namelen, const ino_t ino)
57994 +{
57995 + return 1;
57996 +}
57997 +
57998 +int
57999 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58000 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58001 +{
58002 + return 1;
58003 +}
58004 +
58005 +int
58006 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58007 +{
58008 + return 0;
58009 +}
58010 +
58011 +int
58012 +gr_search_accept(const struct socket *sock)
58013 +{
58014 + return 0;
58015 +}
58016 +
58017 +int
58018 +gr_search_listen(const struct socket *sock)
58019 +{
58020 + return 0;
58021 +}
58022 +
58023 +int
58024 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58025 +{
58026 + return 0;
58027 +}
58028 +
58029 +__u32
58030 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58031 +{
58032 + return 1;
58033 +}
58034 +
58035 +__u32
58036 +gr_acl_handle_creat(const struct dentry * dentry,
58037 + const struct dentry * p_dentry,
58038 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58039 + const int imode)
58040 +{
58041 + return 1;
58042 +}
58043 +
58044 +void
58045 +gr_acl_handle_exit(void)
58046 +{
58047 + return;
58048 +}
58049 +
58050 +int
58051 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58052 +{
58053 + return 1;
58054 +}
58055 +
58056 +void
58057 +gr_set_role_label(const uid_t uid, const gid_t gid)
58058 +{
58059 + return;
58060 +}
58061 +
58062 +int
58063 +gr_acl_handle_procpidmem(const struct task_struct *task)
58064 +{
58065 + return 0;
58066 +}
58067 +
58068 +int
58069 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58070 +{
58071 + return 0;
58072 +}
58073 +
58074 +int
58075 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58076 +{
58077 + return 0;
58078 +}
58079 +
58080 +void
58081 +gr_set_kernel_label(struct task_struct *task)
58082 +{
58083 + return;
58084 +}
58085 +
58086 +int
58087 +gr_check_user_change(int real, int effective, int fs)
58088 +{
58089 + return 0;
58090 +}
58091 +
58092 +int
58093 +gr_check_group_change(int real, int effective, int fs)
58094 +{
58095 + return 0;
58096 +}
58097 +
58098 +int gr_acl_enable_at_secure(void)
58099 +{
58100 + return 0;
58101 +}
58102 +
58103 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58104 +{
58105 + return dentry->d_inode->i_sb->s_dev;
58106 +}
58107 +
58108 +EXPORT_SYMBOL(gr_learn_resource);
58109 +EXPORT_SYMBOL(gr_set_kernel_label);
58110 +#ifdef CONFIG_SECURITY
58111 +EXPORT_SYMBOL(gr_check_user_change);
58112 +EXPORT_SYMBOL(gr_check_group_change);
58113 +#endif
58114 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58115 new file mode 100644
58116 index 0000000..abfa971
58117 --- /dev/null
58118 +++ b/grsecurity/grsec_exec.c
58119 @@ -0,0 +1,174 @@
58120 +#include <linux/kernel.h>
58121 +#include <linux/sched.h>
58122 +#include <linux/file.h>
58123 +#include <linux/binfmts.h>
58124 +#include <linux/fs.h>
58125 +#include <linux/types.h>
58126 +#include <linux/grdefs.h>
58127 +#include <linux/grsecurity.h>
58128 +#include <linux/grinternal.h>
58129 +#include <linux/capability.h>
58130 +#include <linux/module.h>
58131 +
58132 +#include <asm/uaccess.h>
58133 +
58134 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58135 +static char gr_exec_arg_buf[132];
58136 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58137 +#endif
58138 +
58139 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58140 +
58141 +void
58142 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58143 +{
58144 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58145 + char *grarg = gr_exec_arg_buf;
58146 + unsigned int i, x, execlen = 0;
58147 + char c;
58148 +
58149 + if (!((grsec_enable_execlog && grsec_enable_group &&
58150 + in_group_p(grsec_audit_gid))
58151 + || (grsec_enable_execlog && !grsec_enable_group)))
58152 + return;
58153 +
58154 + mutex_lock(&gr_exec_arg_mutex);
58155 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58156 +
58157 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58158 + const char __user *p;
58159 + unsigned int len;
58160 +
58161 + p = get_user_arg_ptr(argv, i);
58162 + if (IS_ERR(p))
58163 + goto log;
58164 +
58165 + len = strnlen_user(p, 128 - execlen);
58166 + if (len > 128 - execlen)
58167 + len = 128 - execlen;
58168 + else if (len > 0)
58169 + len--;
58170 + if (copy_from_user(grarg + execlen, p, len))
58171 + goto log;
58172 +
58173 + /* rewrite unprintable characters */
58174 + for (x = 0; x < len; x++) {
58175 + c = *(grarg + execlen + x);
58176 + if (c < 32 || c > 126)
58177 + *(grarg + execlen + x) = ' ';
58178 + }
58179 +
58180 + execlen += len;
58181 + *(grarg + execlen) = ' ';
58182 + *(grarg + execlen + 1) = '\0';
58183 + execlen++;
58184 + }
58185 +
58186 + log:
58187 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58188 + bprm->file->f_path.mnt, grarg);
58189 + mutex_unlock(&gr_exec_arg_mutex);
58190 +#endif
58191 + return;
58192 +}
58193 +
58194 +#ifdef CONFIG_GRKERNSEC
58195 +extern int gr_acl_is_capable(const int cap);
58196 +extern int gr_acl_is_capable_nolog(const int cap);
58197 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58198 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58199 +extern int gr_chroot_is_capable(const int cap);
58200 +extern int gr_chroot_is_capable_nolog(const int cap);
58201 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58202 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58203 +#endif
58204 +
58205 +const char *captab_log[] = {
58206 + "CAP_CHOWN",
58207 + "CAP_DAC_OVERRIDE",
58208 + "CAP_DAC_READ_SEARCH",
58209 + "CAP_FOWNER",
58210 + "CAP_FSETID",
58211 + "CAP_KILL",
58212 + "CAP_SETGID",
58213 + "CAP_SETUID",
58214 + "CAP_SETPCAP",
58215 + "CAP_LINUX_IMMUTABLE",
58216 + "CAP_NET_BIND_SERVICE",
58217 + "CAP_NET_BROADCAST",
58218 + "CAP_NET_ADMIN",
58219 + "CAP_NET_RAW",
58220 + "CAP_IPC_LOCK",
58221 + "CAP_IPC_OWNER",
58222 + "CAP_SYS_MODULE",
58223 + "CAP_SYS_RAWIO",
58224 + "CAP_SYS_CHROOT",
58225 + "CAP_SYS_PTRACE",
58226 + "CAP_SYS_PACCT",
58227 + "CAP_SYS_ADMIN",
58228 + "CAP_SYS_BOOT",
58229 + "CAP_SYS_NICE",
58230 + "CAP_SYS_RESOURCE",
58231 + "CAP_SYS_TIME",
58232 + "CAP_SYS_TTY_CONFIG",
58233 + "CAP_MKNOD",
58234 + "CAP_LEASE",
58235 + "CAP_AUDIT_WRITE",
58236 + "CAP_AUDIT_CONTROL",
58237 + "CAP_SETFCAP",
58238 + "CAP_MAC_OVERRIDE",
58239 + "CAP_MAC_ADMIN",
58240 + "CAP_SYSLOG",
58241 + "CAP_WAKE_ALARM"
58242 +};
58243 +
58244 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58245 +
58246 +int gr_is_capable(const int cap)
58247 +{
58248 +#ifdef CONFIG_GRKERNSEC
58249 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58250 + return 1;
58251 + return 0;
58252 +#else
58253 + return 1;
58254 +#endif
58255 +}
58256 +
58257 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58258 +{
58259 +#ifdef CONFIG_GRKERNSEC
58260 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58261 + return 1;
58262 + return 0;
58263 +#else
58264 + return 1;
58265 +#endif
58266 +}
58267 +
58268 +int gr_is_capable_nolog(const int cap)
58269 +{
58270 +#ifdef CONFIG_GRKERNSEC
58271 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58272 + return 1;
58273 + return 0;
58274 +#else
58275 + return 1;
58276 +#endif
58277 +}
58278 +
58279 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58280 +{
58281 +#ifdef CONFIG_GRKERNSEC
58282 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58283 + return 1;
58284 + return 0;
58285 +#else
58286 + return 1;
58287 +#endif
58288 +}
58289 +
58290 +EXPORT_SYMBOL(gr_is_capable);
58291 +EXPORT_SYMBOL(gr_is_capable_nolog);
58292 +EXPORT_SYMBOL(gr_task_is_capable);
58293 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58294 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58295 new file mode 100644
58296 index 0000000..d3ee748
58297 --- /dev/null
58298 +++ b/grsecurity/grsec_fifo.c
58299 @@ -0,0 +1,24 @@
58300 +#include <linux/kernel.h>
58301 +#include <linux/sched.h>
58302 +#include <linux/fs.h>
58303 +#include <linux/file.h>
58304 +#include <linux/grinternal.h>
58305 +
58306 +int
58307 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58308 + const struct dentry *dir, const int flag, const int acc_mode)
58309 +{
58310 +#ifdef CONFIG_GRKERNSEC_FIFO
58311 + const struct cred *cred = current_cred();
58312 +
58313 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58314 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58315 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58316 + (cred->fsuid != dentry->d_inode->i_uid)) {
58317 + if (!inode_permission(dentry->d_inode, acc_mode))
58318 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58319 + return -EACCES;
58320 + }
58321 +#endif
58322 + return 0;
58323 +}
58324 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58325 new file mode 100644
58326 index 0000000..8ca18bf
58327 --- /dev/null
58328 +++ b/grsecurity/grsec_fork.c
58329 @@ -0,0 +1,23 @@
58330 +#include <linux/kernel.h>
58331 +#include <linux/sched.h>
58332 +#include <linux/grsecurity.h>
58333 +#include <linux/grinternal.h>
58334 +#include <linux/errno.h>
58335 +
58336 +void
58337 +gr_log_forkfail(const int retval)
58338 +{
58339 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58340 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58341 + switch (retval) {
58342 + case -EAGAIN:
58343 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58344 + break;
58345 + case -ENOMEM:
58346 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58347 + break;
58348 + }
58349 + }
58350 +#endif
58351 + return;
58352 +}
58353 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58354 new file mode 100644
58355 index 0000000..05a6015
58356 --- /dev/null
58357 +++ b/grsecurity/grsec_init.c
58358 @@ -0,0 +1,283 @@
58359 +#include <linux/kernel.h>
58360 +#include <linux/sched.h>
58361 +#include <linux/mm.h>
58362 +#include <linux/gracl.h>
58363 +#include <linux/slab.h>
58364 +#include <linux/vmalloc.h>
58365 +#include <linux/percpu.h>
58366 +#include <linux/module.h>
58367 +
58368 +int grsec_enable_ptrace_readexec;
58369 +int grsec_enable_setxid;
58370 +int grsec_enable_symlinkown;
58371 +int grsec_symlinkown_gid;
58372 +int grsec_enable_brute;
58373 +int grsec_enable_link;
58374 +int grsec_enable_dmesg;
58375 +int grsec_enable_harden_ptrace;
58376 +int grsec_enable_fifo;
58377 +int grsec_enable_execlog;
58378 +int grsec_enable_signal;
58379 +int grsec_enable_forkfail;
58380 +int grsec_enable_audit_ptrace;
58381 +int grsec_enable_time;
58382 +int grsec_enable_audit_textrel;
58383 +int grsec_enable_group;
58384 +int grsec_audit_gid;
58385 +int grsec_enable_chdir;
58386 +int grsec_enable_mount;
58387 +int grsec_enable_rofs;
58388 +int grsec_enable_chroot_findtask;
58389 +int grsec_enable_chroot_mount;
58390 +int grsec_enable_chroot_shmat;
58391 +int grsec_enable_chroot_fchdir;
58392 +int grsec_enable_chroot_double;
58393 +int grsec_enable_chroot_pivot;
58394 +int grsec_enable_chroot_chdir;
58395 +int grsec_enable_chroot_chmod;
58396 +int grsec_enable_chroot_mknod;
58397 +int grsec_enable_chroot_nice;
58398 +int grsec_enable_chroot_execlog;
58399 +int grsec_enable_chroot_caps;
58400 +int grsec_enable_chroot_sysctl;
58401 +int grsec_enable_chroot_unix;
58402 +int grsec_enable_tpe;
58403 +int grsec_tpe_gid;
58404 +int grsec_enable_blackhole;
58405 +#ifdef CONFIG_IPV6_MODULE
58406 +EXPORT_SYMBOL(grsec_enable_blackhole);
58407 +#endif
58408 +int grsec_lastack_retries;
58409 +int grsec_enable_tpe_all;
58410 +int grsec_enable_tpe_invert;
58411 +int grsec_enable_socket_all;
58412 +int grsec_socket_all_gid;
58413 +int grsec_enable_socket_client;
58414 +int grsec_socket_client_gid;
58415 +int grsec_enable_socket_server;
58416 +int grsec_socket_server_gid;
58417 +int grsec_resource_logging;
58418 +int grsec_disable_privio;
58419 +int grsec_enable_log_rwxmaps;
58420 +int grsec_lock;
58421 +
58422 +DEFINE_SPINLOCK(grsec_alert_lock);
58423 +unsigned long grsec_alert_wtime = 0;
58424 +unsigned long grsec_alert_fyet = 0;
58425 +
58426 +DEFINE_SPINLOCK(grsec_audit_lock);
58427 +
58428 +DEFINE_RWLOCK(grsec_exec_file_lock);
58429 +
58430 +char *gr_shared_page[4];
58431 +
58432 +char *gr_alert_log_fmt;
58433 +char *gr_audit_log_fmt;
58434 +char *gr_alert_log_buf;
58435 +char *gr_audit_log_buf;
58436 +
58437 +extern struct gr_arg *gr_usermode;
58438 +extern unsigned char *gr_system_salt;
58439 +extern unsigned char *gr_system_sum;
58440 +
58441 +void __init
58442 +grsecurity_init(void)
58443 +{
58444 + int j;
58445 + /* create the per-cpu shared pages */
58446 +
58447 +#ifdef CONFIG_X86
58448 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58449 +#endif
58450 +
58451 + for (j = 0; j < 4; j++) {
58452 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58453 + if (gr_shared_page[j] == NULL) {
58454 + panic("Unable to allocate grsecurity shared page");
58455 + return;
58456 + }
58457 + }
58458 +
58459 + /* allocate log buffers */
58460 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58461 + if (!gr_alert_log_fmt) {
58462 + panic("Unable to allocate grsecurity alert log format buffer");
58463 + return;
58464 + }
58465 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58466 + if (!gr_audit_log_fmt) {
58467 + panic("Unable to allocate grsecurity audit log format buffer");
58468 + return;
58469 + }
58470 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58471 + if (!gr_alert_log_buf) {
58472 + panic("Unable to allocate grsecurity alert log buffer");
58473 + return;
58474 + }
58475 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58476 + if (!gr_audit_log_buf) {
58477 + panic("Unable to allocate grsecurity audit log buffer");
58478 + return;
58479 + }
58480 +
58481 + /* allocate memory for authentication structure */
58482 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58483 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58484 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58485 +
58486 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58487 + panic("Unable to allocate grsecurity authentication structure");
58488 + return;
58489 + }
58490 +
58491 +
58492 +#ifdef CONFIG_GRKERNSEC_IO
58493 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58494 + grsec_disable_privio = 1;
58495 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58496 + grsec_disable_privio = 1;
58497 +#else
58498 + grsec_disable_privio = 0;
58499 +#endif
58500 +#endif
58501 +
58502 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58503 + /* for backward compatibility, tpe_invert always defaults to on if
58504 + enabled in the kernel
58505 + */
58506 + grsec_enable_tpe_invert = 1;
58507 +#endif
58508 +
58509 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58510 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58511 + grsec_lock = 1;
58512 +#endif
58513 +
58514 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58515 + grsec_enable_audit_textrel = 1;
58516 +#endif
58517 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58518 + grsec_enable_log_rwxmaps = 1;
58519 +#endif
58520 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58521 + grsec_enable_group = 1;
58522 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58523 +#endif
58524 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58525 + grsec_enable_ptrace_readexec = 1;
58526 +#endif
58527 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58528 + grsec_enable_chdir = 1;
58529 +#endif
58530 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58531 + grsec_enable_harden_ptrace = 1;
58532 +#endif
58533 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58534 + grsec_enable_mount = 1;
58535 +#endif
58536 +#ifdef CONFIG_GRKERNSEC_LINK
58537 + grsec_enable_link = 1;
58538 +#endif
58539 +#ifdef CONFIG_GRKERNSEC_BRUTE
58540 + grsec_enable_brute = 1;
58541 +#endif
58542 +#ifdef CONFIG_GRKERNSEC_DMESG
58543 + grsec_enable_dmesg = 1;
58544 +#endif
58545 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58546 + grsec_enable_blackhole = 1;
58547 + grsec_lastack_retries = 4;
58548 +#endif
58549 +#ifdef CONFIG_GRKERNSEC_FIFO
58550 + grsec_enable_fifo = 1;
58551 +#endif
58552 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58553 + grsec_enable_execlog = 1;
58554 +#endif
58555 +#ifdef CONFIG_GRKERNSEC_SETXID
58556 + grsec_enable_setxid = 1;
58557 +#endif
58558 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58559 + grsec_enable_signal = 1;
58560 +#endif
58561 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58562 + grsec_enable_forkfail = 1;
58563 +#endif
58564 +#ifdef CONFIG_GRKERNSEC_TIME
58565 + grsec_enable_time = 1;
58566 +#endif
58567 +#ifdef CONFIG_GRKERNSEC_RESLOG
58568 + grsec_resource_logging = 1;
58569 +#endif
58570 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58571 + grsec_enable_chroot_findtask = 1;
58572 +#endif
58573 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58574 + grsec_enable_chroot_unix = 1;
58575 +#endif
58576 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58577 + grsec_enable_chroot_mount = 1;
58578 +#endif
58579 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58580 + grsec_enable_chroot_fchdir = 1;
58581 +#endif
58582 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58583 + grsec_enable_chroot_shmat = 1;
58584 +#endif
58585 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58586 + grsec_enable_audit_ptrace = 1;
58587 +#endif
58588 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58589 + grsec_enable_chroot_double = 1;
58590 +#endif
58591 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58592 + grsec_enable_chroot_pivot = 1;
58593 +#endif
58594 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58595 + grsec_enable_chroot_chdir = 1;
58596 +#endif
58597 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58598 + grsec_enable_chroot_chmod = 1;
58599 +#endif
58600 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58601 + grsec_enable_chroot_mknod = 1;
58602 +#endif
58603 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58604 + grsec_enable_chroot_nice = 1;
58605 +#endif
58606 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58607 + grsec_enable_chroot_execlog = 1;
58608 +#endif
58609 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58610 + grsec_enable_chroot_caps = 1;
58611 +#endif
58612 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58613 + grsec_enable_chroot_sysctl = 1;
58614 +#endif
58615 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58616 + grsec_enable_symlinkown = 1;
58617 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58618 +#endif
58619 +#ifdef CONFIG_GRKERNSEC_TPE
58620 + grsec_enable_tpe = 1;
58621 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58622 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58623 + grsec_enable_tpe_all = 1;
58624 +#endif
58625 +#endif
58626 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58627 + grsec_enable_socket_all = 1;
58628 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58629 +#endif
58630 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58631 + grsec_enable_socket_client = 1;
58632 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58633 +#endif
58634 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58635 + grsec_enable_socket_server = 1;
58636 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58637 +#endif
58638 +#endif
58639 +
58640 + return;
58641 +}
58642 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58643 new file mode 100644
58644 index 0000000..589481f
58645 --- /dev/null
58646 +++ b/grsecurity/grsec_link.c
58647 @@ -0,0 +1,58 @@
58648 +#include <linux/kernel.h>
58649 +#include <linux/sched.h>
58650 +#include <linux/fs.h>
58651 +#include <linux/file.h>
58652 +#include <linux/grinternal.h>
58653 +
58654 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58655 +{
58656 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58657 + const struct inode *link_inode = link->dentry->d_inode;
58658 +
58659 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58660 + /* ignore root-owned links, e.g. /proc/self */
58661 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58662 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58663 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58664 + return 1;
58665 + }
58666 +#endif
58667 + return 0;
58668 +}
58669 +
58670 +int
58671 +gr_handle_follow_link(const struct inode *parent,
58672 + const struct inode *inode,
58673 + const struct dentry *dentry, const struct vfsmount *mnt)
58674 +{
58675 +#ifdef CONFIG_GRKERNSEC_LINK
58676 + const struct cred *cred = current_cred();
58677 +
58678 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58679 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58680 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58681 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58682 + return -EACCES;
58683 + }
58684 +#endif
58685 + return 0;
58686 +}
58687 +
58688 +int
58689 +gr_handle_hardlink(const struct dentry *dentry,
58690 + const struct vfsmount *mnt,
58691 + struct inode *inode, const int mode, const char *to)
58692 +{
58693 +#ifdef CONFIG_GRKERNSEC_LINK
58694 + const struct cred *cred = current_cred();
58695 +
58696 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58697 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58698 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58699 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58700 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58701 + return -EPERM;
58702 + }
58703 +#endif
58704 + return 0;
58705 +}
58706 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58707 new file mode 100644
58708 index 0000000..a45d2e9
58709 --- /dev/null
58710 +++ b/grsecurity/grsec_log.c
58711 @@ -0,0 +1,322 @@
58712 +#include <linux/kernel.h>
58713 +#include <linux/sched.h>
58714 +#include <linux/file.h>
58715 +#include <linux/tty.h>
58716 +#include <linux/fs.h>
58717 +#include <linux/grinternal.h>
58718 +
58719 +#ifdef CONFIG_TREE_PREEMPT_RCU
58720 +#define DISABLE_PREEMPT() preempt_disable()
58721 +#define ENABLE_PREEMPT() preempt_enable()
58722 +#else
58723 +#define DISABLE_PREEMPT()
58724 +#define ENABLE_PREEMPT()
58725 +#endif
58726 +
58727 +#define BEGIN_LOCKS(x) \
58728 + DISABLE_PREEMPT(); \
58729 + rcu_read_lock(); \
58730 + read_lock(&tasklist_lock); \
58731 + read_lock(&grsec_exec_file_lock); \
58732 + if (x != GR_DO_AUDIT) \
58733 + spin_lock(&grsec_alert_lock); \
58734 + else \
58735 + spin_lock(&grsec_audit_lock)
58736 +
58737 +#define END_LOCKS(x) \
58738 + if (x != GR_DO_AUDIT) \
58739 + spin_unlock(&grsec_alert_lock); \
58740 + else \
58741 + spin_unlock(&grsec_audit_lock); \
58742 + read_unlock(&grsec_exec_file_lock); \
58743 + read_unlock(&tasklist_lock); \
58744 + rcu_read_unlock(); \
58745 + ENABLE_PREEMPT(); \
58746 + if (x == GR_DONT_AUDIT) \
58747 + gr_handle_alertkill(current)
58748 +
58749 +enum {
58750 + FLOODING,
58751 + NO_FLOODING
58752 +};
58753 +
58754 +extern char *gr_alert_log_fmt;
58755 +extern char *gr_audit_log_fmt;
58756 +extern char *gr_alert_log_buf;
58757 +extern char *gr_audit_log_buf;
58758 +
58759 +static int gr_log_start(int audit)
58760 +{
58761 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58762 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58763 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58764 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58765 + unsigned long curr_secs = get_seconds();
58766 +
58767 + if (audit == GR_DO_AUDIT)
58768 + goto set_fmt;
58769 +
58770 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58771 + grsec_alert_wtime = curr_secs;
58772 + grsec_alert_fyet = 0;
58773 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58774 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58775 + grsec_alert_fyet++;
58776 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58777 + grsec_alert_wtime = curr_secs;
58778 + grsec_alert_fyet++;
58779 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58780 + return FLOODING;
58781 + }
58782 + else return FLOODING;
58783 +
58784 +set_fmt:
58785 +#endif
58786 + memset(buf, 0, PAGE_SIZE);
58787 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58788 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58789 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58790 + } else if (current->signal->curr_ip) {
58791 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58792 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58793 + } else if (gr_acl_is_enabled()) {
58794 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58795 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58796 + } else {
58797 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58798 + strcpy(buf, fmt);
58799 + }
58800 +
58801 + return NO_FLOODING;
58802 +}
58803 +
58804 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58805 + __attribute__ ((format (printf, 2, 0)));
58806 +
58807 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58808 +{
58809 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58810 + unsigned int len = strlen(buf);
58811 +
58812 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58813 +
58814 + return;
58815 +}
58816 +
58817 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58818 + __attribute__ ((format (printf, 2, 3)));
58819 +
58820 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58821 +{
58822 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58823 + unsigned int len = strlen(buf);
58824 + va_list ap;
58825 +
58826 + va_start(ap, msg);
58827 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58828 + va_end(ap);
58829 +
58830 + return;
58831 +}
58832 +
58833 +static void gr_log_end(int audit, int append_default)
58834 +{
58835 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58836 +
58837 + if (append_default) {
58838 + unsigned int len = strlen(buf);
58839 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58840 + }
58841 +
58842 + printk("%s\n", buf);
58843 +
58844 + return;
58845 +}
58846 +
58847 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58848 +{
58849 + int logtype;
58850 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58851 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58852 + void *voidptr = NULL;
58853 + int num1 = 0, num2 = 0;
58854 + unsigned long ulong1 = 0, ulong2 = 0;
58855 + struct dentry *dentry = NULL;
58856 + struct vfsmount *mnt = NULL;
58857 + struct file *file = NULL;
58858 + struct task_struct *task = NULL;
58859 + const struct cred *cred, *pcred;
58860 + va_list ap;
58861 +
58862 + BEGIN_LOCKS(audit);
58863 + logtype = gr_log_start(audit);
58864 + if (logtype == FLOODING) {
58865 + END_LOCKS(audit);
58866 + return;
58867 + }
58868 + va_start(ap, argtypes);
58869 + switch (argtypes) {
58870 + case GR_TTYSNIFF:
58871 + task = va_arg(ap, struct task_struct *);
58872 + 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);
58873 + break;
58874 + case GR_SYSCTL_HIDDEN:
58875 + str1 = va_arg(ap, char *);
58876 + gr_log_middle_varargs(audit, msg, result, str1);
58877 + break;
58878 + case GR_RBAC:
58879 + dentry = va_arg(ap, struct dentry *);
58880 + mnt = va_arg(ap, struct vfsmount *);
58881 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58882 + break;
58883 + case GR_RBAC_STR:
58884 + dentry = va_arg(ap, struct dentry *);
58885 + mnt = va_arg(ap, struct vfsmount *);
58886 + str1 = va_arg(ap, char *);
58887 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58888 + break;
58889 + case GR_STR_RBAC:
58890 + str1 = va_arg(ap, char *);
58891 + dentry = va_arg(ap, struct dentry *);
58892 + mnt = va_arg(ap, struct vfsmount *);
58893 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58894 + break;
58895 + case GR_RBAC_MODE2:
58896 + dentry = va_arg(ap, struct dentry *);
58897 + mnt = va_arg(ap, struct vfsmount *);
58898 + str1 = va_arg(ap, char *);
58899 + str2 = va_arg(ap, char *);
58900 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58901 + break;
58902 + case GR_RBAC_MODE3:
58903 + dentry = va_arg(ap, struct dentry *);
58904 + mnt = va_arg(ap, struct vfsmount *);
58905 + str1 = va_arg(ap, char *);
58906 + str2 = va_arg(ap, char *);
58907 + str3 = va_arg(ap, char *);
58908 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58909 + break;
58910 + case GR_FILENAME:
58911 + dentry = va_arg(ap, struct dentry *);
58912 + mnt = va_arg(ap, struct vfsmount *);
58913 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58914 + break;
58915 + case GR_STR_FILENAME:
58916 + str1 = va_arg(ap, char *);
58917 + dentry = va_arg(ap, struct dentry *);
58918 + mnt = va_arg(ap, struct vfsmount *);
58919 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58920 + break;
58921 + case GR_FILENAME_STR:
58922 + dentry = va_arg(ap, struct dentry *);
58923 + mnt = va_arg(ap, struct vfsmount *);
58924 + str1 = va_arg(ap, char *);
58925 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58926 + break;
58927 + case GR_FILENAME_TWO_INT:
58928 + dentry = va_arg(ap, struct dentry *);
58929 + mnt = va_arg(ap, struct vfsmount *);
58930 + num1 = va_arg(ap, int);
58931 + num2 = va_arg(ap, int);
58932 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58933 + break;
58934 + case GR_FILENAME_TWO_INT_STR:
58935 + dentry = va_arg(ap, struct dentry *);
58936 + mnt = va_arg(ap, struct vfsmount *);
58937 + num1 = va_arg(ap, int);
58938 + num2 = va_arg(ap, int);
58939 + str1 = va_arg(ap, char *);
58940 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58941 + break;
58942 + case GR_TEXTREL:
58943 + file = va_arg(ap, struct file *);
58944 + ulong1 = va_arg(ap, unsigned long);
58945 + ulong2 = va_arg(ap, unsigned long);
58946 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58947 + break;
58948 + case GR_PTRACE:
58949 + task = va_arg(ap, struct task_struct *);
58950 + 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);
58951 + break;
58952 + case GR_RESOURCE:
58953 + task = va_arg(ap, struct task_struct *);
58954 + cred = __task_cred(task);
58955 + pcred = __task_cred(task->real_parent);
58956 + ulong1 = va_arg(ap, unsigned long);
58957 + str1 = va_arg(ap, char *);
58958 + ulong2 = va_arg(ap, unsigned long);
58959 + 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);
58960 + break;
58961 + case GR_CAP:
58962 + task = va_arg(ap, struct task_struct *);
58963 + cred = __task_cred(task);
58964 + pcred = __task_cred(task->real_parent);
58965 + str1 = va_arg(ap, char *);
58966 + 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);
58967 + break;
58968 + case GR_SIG:
58969 + str1 = va_arg(ap, char *);
58970 + voidptr = va_arg(ap, void *);
58971 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58972 + break;
58973 + case GR_SIG2:
58974 + task = va_arg(ap, struct task_struct *);
58975 + cred = __task_cred(task);
58976 + pcred = __task_cred(task->real_parent);
58977 + num1 = va_arg(ap, int);
58978 + 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);
58979 + break;
58980 + case GR_CRASH1:
58981 + task = va_arg(ap, struct task_struct *);
58982 + cred = __task_cred(task);
58983 + pcred = __task_cred(task->real_parent);
58984 + ulong1 = va_arg(ap, unsigned long);
58985 + 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);
58986 + break;
58987 + case GR_CRASH2:
58988 + task = va_arg(ap, struct task_struct *);
58989 + cred = __task_cred(task);
58990 + pcred = __task_cred(task->real_parent);
58991 + ulong1 = va_arg(ap, unsigned long);
58992 + 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);
58993 + break;
58994 + case GR_RWXMAP:
58995 + file = va_arg(ap, struct file *);
58996 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58997 + break;
58998 + case GR_PSACCT:
58999 + {
59000 + unsigned int wday, cday;
59001 + __u8 whr, chr;
59002 + __u8 wmin, cmin;
59003 + __u8 wsec, csec;
59004 + char cur_tty[64] = { 0 };
59005 + char parent_tty[64] = { 0 };
59006 +
59007 + task = va_arg(ap, struct task_struct *);
59008 + wday = va_arg(ap, unsigned int);
59009 + cday = va_arg(ap, unsigned int);
59010 + whr = va_arg(ap, int);
59011 + chr = va_arg(ap, int);
59012 + wmin = va_arg(ap, int);
59013 + cmin = va_arg(ap, int);
59014 + wsec = va_arg(ap, int);
59015 + csec = va_arg(ap, int);
59016 + ulong1 = va_arg(ap, unsigned long);
59017 + cred = __task_cred(task);
59018 + pcred = __task_cred(task->real_parent);
59019 +
59020 + 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);
59021 + }
59022 + break;
59023 + default:
59024 + gr_log_middle(audit, msg, ap);
59025 + }
59026 + va_end(ap);
59027 + // these don't need DEFAULTSECARGS printed on the end
59028 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59029 + gr_log_end(audit, 0);
59030 + else
59031 + gr_log_end(audit, 1);
59032 + END_LOCKS(audit);
59033 +}
59034 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59035 new file mode 100644
59036 index 0000000..f536303
59037 --- /dev/null
59038 +++ b/grsecurity/grsec_mem.c
59039 @@ -0,0 +1,40 @@
59040 +#include <linux/kernel.h>
59041 +#include <linux/sched.h>
59042 +#include <linux/mm.h>
59043 +#include <linux/mman.h>
59044 +#include <linux/grinternal.h>
59045 +
59046 +void
59047 +gr_handle_ioperm(void)
59048 +{
59049 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59050 + return;
59051 +}
59052 +
59053 +void
59054 +gr_handle_iopl(void)
59055 +{
59056 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59057 + return;
59058 +}
59059 +
59060 +void
59061 +gr_handle_mem_readwrite(u64 from, u64 to)
59062 +{
59063 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59064 + return;
59065 +}
59066 +
59067 +void
59068 +gr_handle_vm86(void)
59069 +{
59070 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59071 + return;
59072 +}
59073 +
59074 +void
59075 +gr_log_badprocpid(const char *entry)
59076 +{
59077 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59078 + return;
59079 +}
59080 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59081 new file mode 100644
59082 index 0000000..2131422
59083 --- /dev/null
59084 +++ b/grsecurity/grsec_mount.c
59085 @@ -0,0 +1,62 @@
59086 +#include <linux/kernel.h>
59087 +#include <linux/sched.h>
59088 +#include <linux/mount.h>
59089 +#include <linux/grsecurity.h>
59090 +#include <linux/grinternal.h>
59091 +
59092 +void
59093 +gr_log_remount(const char *devname, const int retval)
59094 +{
59095 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59096 + if (grsec_enable_mount && (retval >= 0))
59097 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59098 +#endif
59099 + return;
59100 +}
59101 +
59102 +void
59103 +gr_log_unmount(const char *devname, const int retval)
59104 +{
59105 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59106 + if (grsec_enable_mount && (retval >= 0))
59107 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59108 +#endif
59109 + return;
59110 +}
59111 +
59112 +void
59113 +gr_log_mount(const char *from, const char *to, const int retval)
59114 +{
59115 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59116 + if (grsec_enable_mount && (retval >= 0))
59117 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59118 +#endif
59119 + return;
59120 +}
59121 +
59122 +int
59123 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59124 +{
59125 +#ifdef CONFIG_GRKERNSEC_ROFS
59126 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59127 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59128 + return -EPERM;
59129 + } else
59130 + return 0;
59131 +#endif
59132 + return 0;
59133 +}
59134 +
59135 +int
59136 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59137 +{
59138 +#ifdef CONFIG_GRKERNSEC_ROFS
59139 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59140 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59141 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59142 + return -EPERM;
59143 + } else
59144 + return 0;
59145 +#endif
59146 + return 0;
59147 +}
59148 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59149 new file mode 100644
59150 index 0000000..a3b12a0
59151 --- /dev/null
59152 +++ b/grsecurity/grsec_pax.c
59153 @@ -0,0 +1,36 @@
59154 +#include <linux/kernel.h>
59155 +#include <linux/sched.h>
59156 +#include <linux/mm.h>
59157 +#include <linux/file.h>
59158 +#include <linux/grinternal.h>
59159 +#include <linux/grsecurity.h>
59160 +
59161 +void
59162 +gr_log_textrel(struct vm_area_struct * vma)
59163 +{
59164 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59165 + if (grsec_enable_audit_textrel)
59166 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59167 +#endif
59168 + return;
59169 +}
59170 +
59171 +void
59172 +gr_log_rwxmmap(struct file *file)
59173 +{
59174 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59175 + if (grsec_enable_log_rwxmaps)
59176 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59177 +#endif
59178 + return;
59179 +}
59180 +
59181 +void
59182 +gr_log_rwxmprotect(struct file *file)
59183 +{
59184 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59185 + if (grsec_enable_log_rwxmaps)
59186 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59187 +#endif
59188 + return;
59189 +}
59190 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59191 new file mode 100644
59192 index 0000000..f7f29aa
59193 --- /dev/null
59194 +++ b/grsecurity/grsec_ptrace.c
59195 @@ -0,0 +1,30 @@
59196 +#include <linux/kernel.h>
59197 +#include <linux/sched.h>
59198 +#include <linux/grinternal.h>
59199 +#include <linux/security.h>
59200 +
59201 +void
59202 +gr_audit_ptrace(struct task_struct *task)
59203 +{
59204 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59205 + if (grsec_enable_audit_ptrace)
59206 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59207 +#endif
59208 + return;
59209 +}
59210 +
59211 +int
59212 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59213 +{
59214 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59215 + const struct dentry *dentry = file->f_path.dentry;
59216 + const struct vfsmount *mnt = file->f_path.mnt;
59217 +
59218 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59219 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59220 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59221 + return -EACCES;
59222 + }
59223 +#endif
59224 + return 0;
59225 +}
59226 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59227 new file mode 100644
59228 index 0000000..b4ac94c
59229 --- /dev/null
59230 +++ b/grsecurity/grsec_sig.c
59231 @@ -0,0 +1,209 @@
59232 +#include <linux/kernel.h>
59233 +#include <linux/sched.h>
59234 +#include <linux/delay.h>
59235 +#include <linux/grsecurity.h>
59236 +#include <linux/grinternal.h>
59237 +#include <linux/hardirq.h>
59238 +
59239 +char *signames[] = {
59240 + [SIGSEGV] = "Segmentation fault",
59241 + [SIGILL] = "Illegal instruction",
59242 + [SIGABRT] = "Abort",
59243 + [SIGBUS] = "Invalid alignment/Bus error"
59244 +};
59245 +
59246 +void
59247 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59248 +{
59249 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59250 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59251 + (sig == SIGABRT) || (sig == SIGBUS))) {
59252 + if (t->pid == current->pid) {
59253 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59254 + } else {
59255 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59256 + }
59257 + }
59258 +#endif
59259 + return;
59260 +}
59261 +
59262 +int
59263 +gr_handle_signal(const struct task_struct *p, const int sig)
59264 +{
59265 +#ifdef CONFIG_GRKERNSEC
59266 + /* ignore the 0 signal for protected task checks */
59267 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59268 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59269 + return -EPERM;
59270 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59271 + return -EPERM;
59272 + }
59273 +#endif
59274 + return 0;
59275 +}
59276 +
59277 +#ifdef CONFIG_GRKERNSEC
59278 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59279 +
59280 +int gr_fake_force_sig(int sig, struct task_struct *t)
59281 +{
59282 + unsigned long int flags;
59283 + int ret, blocked, ignored;
59284 + struct k_sigaction *action;
59285 +
59286 + spin_lock_irqsave(&t->sighand->siglock, flags);
59287 + action = &t->sighand->action[sig-1];
59288 + ignored = action->sa.sa_handler == SIG_IGN;
59289 + blocked = sigismember(&t->blocked, sig);
59290 + if (blocked || ignored) {
59291 + action->sa.sa_handler = SIG_DFL;
59292 + if (blocked) {
59293 + sigdelset(&t->blocked, sig);
59294 + recalc_sigpending_and_wake(t);
59295 + }
59296 + }
59297 + if (action->sa.sa_handler == SIG_DFL)
59298 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59299 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59300 +
59301 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59302 +
59303 + return ret;
59304 +}
59305 +#endif
59306 +
59307 +#ifdef CONFIG_GRKERNSEC_BRUTE
59308 +#define GR_USER_BAN_TIME (15 * 60)
59309 +
59310 +static int __get_dumpable(unsigned long mm_flags)
59311 +{
59312 + int ret;
59313 +
59314 + ret = mm_flags & MMF_DUMPABLE_MASK;
59315 + return (ret >= 2) ? 2 : ret;
59316 +}
59317 +#endif
59318 +
59319 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59320 +{
59321 +#ifdef CONFIG_GRKERNSEC_BRUTE
59322 + kuid_t uid = GLOBAL_ROOT_UID;
59323 +
59324 + if (!grsec_enable_brute)
59325 + return;
59326 +
59327 + rcu_read_lock();
59328 + read_lock(&tasklist_lock);
59329 + read_lock(&grsec_exec_file_lock);
59330 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59331 + p->real_parent->brute = 1;
59332 + else {
59333 + const struct cred *cred = __task_cred(p), *cred2;
59334 + struct task_struct *tsk, *tsk2;
59335 +
59336 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59337 + struct user_struct *user;
59338 +
59339 + uid = cred->uid;
59340 +
59341 + /* this is put upon execution past expiration */
59342 + user = find_user(uid);
59343 + if (user == NULL)
59344 + goto unlock;
59345 + user->banned = 1;
59346 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59347 + if (user->ban_expires == ~0UL)
59348 + user->ban_expires--;
59349 +
59350 + do_each_thread(tsk2, tsk) {
59351 + cred2 = __task_cred(tsk);
59352 + if (tsk != p && uid_eq(cred2->uid, uid))
59353 + gr_fake_force_sig(SIGKILL, tsk);
59354 + } while_each_thread(tsk2, tsk);
59355 + }
59356 + }
59357 +unlock:
59358 + read_unlock(&grsec_exec_file_lock);
59359 + read_unlock(&tasklist_lock);
59360 + rcu_read_unlock();
59361 +
59362 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59363 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59364 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59365 +
59366 +#endif
59367 + return;
59368 +}
59369 +
59370 +void gr_handle_brute_check(void)
59371 +{
59372 +#ifdef CONFIG_GRKERNSEC_BRUTE
59373 + if (current->brute)
59374 + msleep(30 * 1000);
59375 +#endif
59376 + return;
59377 +}
59378 +
59379 +void gr_handle_kernel_exploit(void)
59380 +{
59381 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59382 + const struct cred *cred;
59383 + struct task_struct *tsk, *tsk2;
59384 + struct user_struct *user;
59385 + kuid_t uid;
59386 +
59387 + if (in_irq() || in_serving_softirq() || in_nmi())
59388 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59389 +
59390 + uid = current_uid();
59391 +
59392 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59393 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59394 + else {
59395 + /* kill all the processes of this user, hold a reference
59396 + to their creds struct, and prevent them from creating
59397 + another process until system reset
59398 + */
59399 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59400 + from_kuid_munged(&init_user_ns, uid));
59401 + /* we intentionally leak this ref */
59402 + user = get_uid(current->cred->user);
59403 + if (user) {
59404 + user->banned = 1;
59405 + user->ban_expires = ~0UL;
59406 + }
59407 +
59408 + read_lock(&tasklist_lock);
59409 + do_each_thread(tsk2, tsk) {
59410 + cred = __task_cred(tsk);
59411 + if (uid_eq(cred->uid, uid))
59412 + gr_fake_force_sig(SIGKILL, tsk);
59413 + } while_each_thread(tsk2, tsk);
59414 + read_unlock(&tasklist_lock);
59415 + }
59416 +#endif
59417 +}
59418 +
59419 +int __gr_process_user_ban(struct user_struct *user)
59420 +{
59421 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59422 + if (unlikely(user->banned)) {
59423 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59424 + user->banned = 0;
59425 + user->ban_expires = 0;
59426 + free_uid(user);
59427 + } else
59428 + return -EPERM;
59429 + }
59430 +#endif
59431 + return 0;
59432 +}
59433 +
59434 +int gr_process_user_ban(void)
59435 +{
59436 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59437 + return __gr_process_user_ban(current->cred->user);
59438 +#endif
59439 + return 0;
59440 +}
59441 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59442 new file mode 100644
59443 index 0000000..4030d57
59444 --- /dev/null
59445 +++ b/grsecurity/grsec_sock.c
59446 @@ -0,0 +1,244 @@
59447 +#include <linux/kernel.h>
59448 +#include <linux/module.h>
59449 +#include <linux/sched.h>
59450 +#include <linux/file.h>
59451 +#include <linux/net.h>
59452 +#include <linux/in.h>
59453 +#include <linux/ip.h>
59454 +#include <net/sock.h>
59455 +#include <net/inet_sock.h>
59456 +#include <linux/grsecurity.h>
59457 +#include <linux/grinternal.h>
59458 +#include <linux/gracl.h>
59459 +
59460 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59461 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59462 +
59463 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59464 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59465 +
59466 +#ifdef CONFIG_UNIX_MODULE
59467 +EXPORT_SYMBOL(gr_acl_handle_unix);
59468 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59469 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59470 +EXPORT_SYMBOL(gr_handle_create);
59471 +#endif
59472 +
59473 +#ifdef CONFIG_GRKERNSEC
59474 +#define gr_conn_table_size 32749
59475 +struct conn_table_entry {
59476 + struct conn_table_entry *next;
59477 + struct signal_struct *sig;
59478 +};
59479 +
59480 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59481 +DEFINE_SPINLOCK(gr_conn_table_lock);
59482 +
59483 +extern const char * gr_socktype_to_name(unsigned char type);
59484 +extern const char * gr_proto_to_name(unsigned char proto);
59485 +extern const char * gr_sockfamily_to_name(unsigned char family);
59486 +
59487 +static __inline__ int
59488 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59489 +{
59490 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59491 +}
59492 +
59493 +static __inline__ int
59494 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59495 + __u16 sport, __u16 dport)
59496 +{
59497 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59498 + sig->gr_sport == sport && sig->gr_dport == dport))
59499 + return 1;
59500 + else
59501 + return 0;
59502 +}
59503 +
59504 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59505 +{
59506 + struct conn_table_entry **match;
59507 + unsigned int index;
59508 +
59509 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59510 + sig->gr_sport, sig->gr_dport,
59511 + gr_conn_table_size);
59512 +
59513 + newent->sig = sig;
59514 +
59515 + match = &gr_conn_table[index];
59516 + newent->next = *match;
59517 + *match = newent;
59518 +
59519 + return;
59520 +}
59521 +
59522 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59523 +{
59524 + struct conn_table_entry *match, *last = NULL;
59525 + unsigned int index;
59526 +
59527 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59528 + sig->gr_sport, sig->gr_dport,
59529 + gr_conn_table_size);
59530 +
59531 + match = gr_conn_table[index];
59532 + while (match && !conn_match(match->sig,
59533 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59534 + sig->gr_dport)) {
59535 + last = match;
59536 + match = match->next;
59537 + }
59538 +
59539 + if (match) {
59540 + if (last)
59541 + last->next = match->next;
59542 + else
59543 + gr_conn_table[index] = NULL;
59544 + kfree(match);
59545 + }
59546 +
59547 + return;
59548 +}
59549 +
59550 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59551 + __u16 sport, __u16 dport)
59552 +{
59553 + struct conn_table_entry *match;
59554 + unsigned int index;
59555 +
59556 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59557 +
59558 + match = gr_conn_table[index];
59559 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59560 + match = match->next;
59561 +
59562 + if (match)
59563 + return match->sig;
59564 + else
59565 + return NULL;
59566 +}
59567 +
59568 +#endif
59569 +
59570 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59571 +{
59572 +#ifdef CONFIG_GRKERNSEC
59573 + struct signal_struct *sig = task->signal;
59574 + struct conn_table_entry *newent;
59575 +
59576 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59577 + if (newent == NULL)
59578 + return;
59579 + /* no bh lock needed since we are called with bh disabled */
59580 + spin_lock(&gr_conn_table_lock);
59581 + gr_del_task_from_ip_table_nolock(sig);
59582 + sig->gr_saddr = inet->inet_rcv_saddr;
59583 + sig->gr_daddr = inet->inet_daddr;
59584 + sig->gr_sport = inet->inet_sport;
59585 + sig->gr_dport = inet->inet_dport;
59586 + gr_add_to_task_ip_table_nolock(sig, newent);
59587 + spin_unlock(&gr_conn_table_lock);
59588 +#endif
59589 + return;
59590 +}
59591 +
59592 +void gr_del_task_from_ip_table(struct task_struct *task)
59593 +{
59594 +#ifdef CONFIG_GRKERNSEC
59595 + spin_lock_bh(&gr_conn_table_lock);
59596 + gr_del_task_from_ip_table_nolock(task->signal);
59597 + spin_unlock_bh(&gr_conn_table_lock);
59598 +#endif
59599 + return;
59600 +}
59601 +
59602 +void
59603 +gr_attach_curr_ip(const struct sock *sk)
59604 +{
59605 +#ifdef CONFIG_GRKERNSEC
59606 + struct signal_struct *p, *set;
59607 + const struct inet_sock *inet = inet_sk(sk);
59608 +
59609 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59610 + return;
59611 +
59612 + set = current->signal;
59613 +
59614 + spin_lock_bh(&gr_conn_table_lock);
59615 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59616 + inet->inet_dport, inet->inet_sport);
59617 + if (unlikely(p != NULL)) {
59618 + set->curr_ip = p->curr_ip;
59619 + set->used_accept = 1;
59620 + gr_del_task_from_ip_table_nolock(p);
59621 + spin_unlock_bh(&gr_conn_table_lock);
59622 + return;
59623 + }
59624 + spin_unlock_bh(&gr_conn_table_lock);
59625 +
59626 + set->curr_ip = inet->inet_daddr;
59627 + set->used_accept = 1;
59628 +#endif
59629 + return;
59630 +}
59631 +
59632 +int
59633 +gr_handle_sock_all(const int family, const int type, const int protocol)
59634 +{
59635 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59636 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59637 + (family != AF_UNIX)) {
59638 + if (family == AF_INET)
59639 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59640 + else
59641 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59642 + return -EACCES;
59643 + }
59644 +#endif
59645 + return 0;
59646 +}
59647 +
59648 +int
59649 +gr_handle_sock_server(const struct sockaddr *sck)
59650 +{
59651 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59652 + if (grsec_enable_socket_server &&
59653 + in_group_p(grsec_socket_server_gid) &&
59654 + sck && (sck->sa_family != AF_UNIX) &&
59655 + (sck->sa_family != AF_LOCAL)) {
59656 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59657 + return -EACCES;
59658 + }
59659 +#endif
59660 + return 0;
59661 +}
59662 +
59663 +int
59664 +gr_handle_sock_server_other(const struct sock *sck)
59665 +{
59666 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59667 + if (grsec_enable_socket_server &&
59668 + in_group_p(grsec_socket_server_gid) &&
59669 + sck && (sck->sk_family != AF_UNIX) &&
59670 + (sck->sk_family != AF_LOCAL)) {
59671 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59672 + return -EACCES;
59673 + }
59674 +#endif
59675 + return 0;
59676 +}
59677 +
59678 +int
59679 +gr_handle_sock_client(const struct sockaddr *sck)
59680 +{
59681 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59682 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59683 + sck && (sck->sa_family != AF_UNIX) &&
59684 + (sck->sa_family != AF_LOCAL)) {
59685 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59686 + return -EACCES;
59687 + }
59688 +#endif
59689 + return 0;
59690 +}
59691 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59692 new file mode 100644
59693 index 0000000..f55ef0f
59694 --- /dev/null
59695 +++ b/grsecurity/grsec_sysctl.c
59696 @@ -0,0 +1,469 @@
59697 +#include <linux/kernel.h>
59698 +#include <linux/sched.h>
59699 +#include <linux/sysctl.h>
59700 +#include <linux/grsecurity.h>
59701 +#include <linux/grinternal.h>
59702 +
59703 +int
59704 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59705 +{
59706 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59707 + if (dirname == NULL || name == NULL)
59708 + return 0;
59709 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59710 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59711 + return -EACCES;
59712 + }
59713 +#endif
59714 + return 0;
59715 +}
59716 +
59717 +#ifdef CONFIG_GRKERNSEC_ROFS
59718 +static int __maybe_unused one = 1;
59719 +#endif
59720 +
59721 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59722 +struct ctl_table grsecurity_table[] = {
59723 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59724 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59725 +#ifdef CONFIG_GRKERNSEC_IO
59726 + {
59727 + .procname = "disable_priv_io",
59728 + .data = &grsec_disable_privio,
59729 + .maxlen = sizeof(int),
59730 + .mode = 0600,
59731 + .proc_handler = &proc_dointvec,
59732 + },
59733 +#endif
59734 +#endif
59735 +#ifdef CONFIG_GRKERNSEC_LINK
59736 + {
59737 + .procname = "linking_restrictions",
59738 + .data = &grsec_enable_link,
59739 + .maxlen = sizeof(int),
59740 + .mode = 0600,
59741 + .proc_handler = &proc_dointvec,
59742 + },
59743 +#endif
59744 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59745 + {
59746 + .procname = "enforce_symlinksifowner",
59747 + .data = &grsec_enable_symlinkown,
59748 + .maxlen = sizeof(int),
59749 + .mode = 0600,
59750 + .proc_handler = &proc_dointvec,
59751 + },
59752 + {
59753 + .procname = "symlinkown_gid",
59754 + .data = &grsec_symlinkown_gid,
59755 + .maxlen = sizeof(int),
59756 + .mode = 0600,
59757 + .proc_handler = &proc_dointvec,
59758 + },
59759 +#endif
59760 +#ifdef CONFIG_GRKERNSEC_BRUTE
59761 + {
59762 + .procname = "deter_bruteforce",
59763 + .data = &grsec_enable_brute,
59764 + .maxlen = sizeof(int),
59765 + .mode = 0600,
59766 + .proc_handler = &proc_dointvec,
59767 + },
59768 +#endif
59769 +#ifdef CONFIG_GRKERNSEC_FIFO
59770 + {
59771 + .procname = "fifo_restrictions",
59772 + .data = &grsec_enable_fifo,
59773 + .maxlen = sizeof(int),
59774 + .mode = 0600,
59775 + .proc_handler = &proc_dointvec,
59776 + },
59777 +#endif
59778 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59779 + {
59780 + .procname = "ptrace_readexec",
59781 + .data = &grsec_enable_ptrace_readexec,
59782 + .maxlen = sizeof(int),
59783 + .mode = 0600,
59784 + .proc_handler = &proc_dointvec,
59785 + },
59786 +#endif
59787 +#ifdef CONFIG_GRKERNSEC_SETXID
59788 + {
59789 + .procname = "consistent_setxid",
59790 + .data = &grsec_enable_setxid,
59791 + .maxlen = sizeof(int),
59792 + .mode = 0600,
59793 + .proc_handler = &proc_dointvec,
59794 + },
59795 +#endif
59796 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59797 + {
59798 + .procname = "ip_blackhole",
59799 + .data = &grsec_enable_blackhole,
59800 + .maxlen = sizeof(int),
59801 + .mode = 0600,
59802 + .proc_handler = &proc_dointvec,
59803 + },
59804 + {
59805 + .procname = "lastack_retries",
59806 + .data = &grsec_lastack_retries,
59807 + .maxlen = sizeof(int),
59808 + .mode = 0600,
59809 + .proc_handler = &proc_dointvec,
59810 + },
59811 +#endif
59812 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59813 + {
59814 + .procname = "exec_logging",
59815 + .data = &grsec_enable_execlog,
59816 + .maxlen = sizeof(int),
59817 + .mode = 0600,
59818 + .proc_handler = &proc_dointvec,
59819 + },
59820 +#endif
59821 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59822 + {
59823 + .procname = "rwxmap_logging",
59824 + .data = &grsec_enable_log_rwxmaps,
59825 + .maxlen = sizeof(int),
59826 + .mode = 0600,
59827 + .proc_handler = &proc_dointvec,
59828 + },
59829 +#endif
59830 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59831 + {
59832 + .procname = "signal_logging",
59833 + .data = &grsec_enable_signal,
59834 + .maxlen = sizeof(int),
59835 + .mode = 0600,
59836 + .proc_handler = &proc_dointvec,
59837 + },
59838 +#endif
59839 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59840 + {
59841 + .procname = "forkfail_logging",
59842 + .data = &grsec_enable_forkfail,
59843 + .maxlen = sizeof(int),
59844 + .mode = 0600,
59845 + .proc_handler = &proc_dointvec,
59846 + },
59847 +#endif
59848 +#ifdef CONFIG_GRKERNSEC_TIME
59849 + {
59850 + .procname = "timechange_logging",
59851 + .data = &grsec_enable_time,
59852 + .maxlen = sizeof(int),
59853 + .mode = 0600,
59854 + .proc_handler = &proc_dointvec,
59855 + },
59856 +#endif
59857 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59858 + {
59859 + .procname = "chroot_deny_shmat",
59860 + .data = &grsec_enable_chroot_shmat,
59861 + .maxlen = sizeof(int),
59862 + .mode = 0600,
59863 + .proc_handler = &proc_dointvec,
59864 + },
59865 +#endif
59866 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59867 + {
59868 + .procname = "chroot_deny_unix",
59869 + .data = &grsec_enable_chroot_unix,
59870 + .maxlen = sizeof(int),
59871 + .mode = 0600,
59872 + .proc_handler = &proc_dointvec,
59873 + },
59874 +#endif
59875 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59876 + {
59877 + .procname = "chroot_deny_mount",
59878 + .data = &grsec_enable_chroot_mount,
59879 + .maxlen = sizeof(int),
59880 + .mode = 0600,
59881 + .proc_handler = &proc_dointvec,
59882 + },
59883 +#endif
59884 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59885 + {
59886 + .procname = "chroot_deny_fchdir",
59887 + .data = &grsec_enable_chroot_fchdir,
59888 + .maxlen = sizeof(int),
59889 + .mode = 0600,
59890 + .proc_handler = &proc_dointvec,
59891 + },
59892 +#endif
59893 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59894 + {
59895 + .procname = "chroot_deny_chroot",
59896 + .data = &grsec_enable_chroot_double,
59897 + .maxlen = sizeof(int),
59898 + .mode = 0600,
59899 + .proc_handler = &proc_dointvec,
59900 + },
59901 +#endif
59902 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59903 + {
59904 + .procname = "chroot_deny_pivot",
59905 + .data = &grsec_enable_chroot_pivot,
59906 + .maxlen = sizeof(int),
59907 + .mode = 0600,
59908 + .proc_handler = &proc_dointvec,
59909 + },
59910 +#endif
59911 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59912 + {
59913 + .procname = "chroot_enforce_chdir",
59914 + .data = &grsec_enable_chroot_chdir,
59915 + .maxlen = sizeof(int),
59916 + .mode = 0600,
59917 + .proc_handler = &proc_dointvec,
59918 + },
59919 +#endif
59920 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59921 + {
59922 + .procname = "chroot_deny_chmod",
59923 + .data = &grsec_enable_chroot_chmod,
59924 + .maxlen = sizeof(int),
59925 + .mode = 0600,
59926 + .proc_handler = &proc_dointvec,
59927 + },
59928 +#endif
59929 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59930 + {
59931 + .procname = "chroot_deny_mknod",
59932 + .data = &grsec_enable_chroot_mknod,
59933 + .maxlen = sizeof(int),
59934 + .mode = 0600,
59935 + .proc_handler = &proc_dointvec,
59936 + },
59937 +#endif
59938 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59939 + {
59940 + .procname = "chroot_restrict_nice",
59941 + .data = &grsec_enable_chroot_nice,
59942 + .maxlen = sizeof(int),
59943 + .mode = 0600,
59944 + .proc_handler = &proc_dointvec,
59945 + },
59946 +#endif
59947 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59948 + {
59949 + .procname = "chroot_execlog",
59950 + .data = &grsec_enable_chroot_execlog,
59951 + .maxlen = sizeof(int),
59952 + .mode = 0600,
59953 + .proc_handler = &proc_dointvec,
59954 + },
59955 +#endif
59956 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59957 + {
59958 + .procname = "chroot_caps",
59959 + .data = &grsec_enable_chroot_caps,
59960 + .maxlen = sizeof(int),
59961 + .mode = 0600,
59962 + .proc_handler = &proc_dointvec,
59963 + },
59964 +#endif
59965 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59966 + {
59967 + .procname = "chroot_deny_sysctl",
59968 + .data = &grsec_enable_chroot_sysctl,
59969 + .maxlen = sizeof(int),
59970 + .mode = 0600,
59971 + .proc_handler = &proc_dointvec,
59972 + },
59973 +#endif
59974 +#ifdef CONFIG_GRKERNSEC_TPE
59975 + {
59976 + .procname = "tpe",
59977 + .data = &grsec_enable_tpe,
59978 + .maxlen = sizeof(int),
59979 + .mode = 0600,
59980 + .proc_handler = &proc_dointvec,
59981 + },
59982 + {
59983 + .procname = "tpe_gid",
59984 + .data = &grsec_tpe_gid,
59985 + .maxlen = sizeof(int),
59986 + .mode = 0600,
59987 + .proc_handler = &proc_dointvec,
59988 + },
59989 +#endif
59990 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59991 + {
59992 + .procname = "tpe_invert",
59993 + .data = &grsec_enable_tpe_invert,
59994 + .maxlen = sizeof(int),
59995 + .mode = 0600,
59996 + .proc_handler = &proc_dointvec,
59997 + },
59998 +#endif
59999 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60000 + {
60001 + .procname = "tpe_restrict_all",
60002 + .data = &grsec_enable_tpe_all,
60003 + .maxlen = sizeof(int),
60004 + .mode = 0600,
60005 + .proc_handler = &proc_dointvec,
60006 + },
60007 +#endif
60008 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60009 + {
60010 + .procname = "socket_all",
60011 + .data = &grsec_enable_socket_all,
60012 + .maxlen = sizeof(int),
60013 + .mode = 0600,
60014 + .proc_handler = &proc_dointvec,
60015 + },
60016 + {
60017 + .procname = "socket_all_gid",
60018 + .data = &grsec_socket_all_gid,
60019 + .maxlen = sizeof(int),
60020 + .mode = 0600,
60021 + .proc_handler = &proc_dointvec,
60022 + },
60023 +#endif
60024 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60025 + {
60026 + .procname = "socket_client",
60027 + .data = &grsec_enable_socket_client,
60028 + .maxlen = sizeof(int),
60029 + .mode = 0600,
60030 + .proc_handler = &proc_dointvec,
60031 + },
60032 + {
60033 + .procname = "socket_client_gid",
60034 + .data = &grsec_socket_client_gid,
60035 + .maxlen = sizeof(int),
60036 + .mode = 0600,
60037 + .proc_handler = &proc_dointvec,
60038 + },
60039 +#endif
60040 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60041 + {
60042 + .procname = "socket_server",
60043 + .data = &grsec_enable_socket_server,
60044 + .maxlen = sizeof(int),
60045 + .mode = 0600,
60046 + .proc_handler = &proc_dointvec,
60047 + },
60048 + {
60049 + .procname = "socket_server_gid",
60050 + .data = &grsec_socket_server_gid,
60051 + .maxlen = sizeof(int),
60052 + .mode = 0600,
60053 + .proc_handler = &proc_dointvec,
60054 + },
60055 +#endif
60056 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60057 + {
60058 + .procname = "audit_group",
60059 + .data = &grsec_enable_group,
60060 + .maxlen = sizeof(int),
60061 + .mode = 0600,
60062 + .proc_handler = &proc_dointvec,
60063 + },
60064 + {
60065 + .procname = "audit_gid",
60066 + .data = &grsec_audit_gid,
60067 + .maxlen = sizeof(int),
60068 + .mode = 0600,
60069 + .proc_handler = &proc_dointvec,
60070 + },
60071 +#endif
60072 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60073 + {
60074 + .procname = "audit_chdir",
60075 + .data = &grsec_enable_chdir,
60076 + .maxlen = sizeof(int),
60077 + .mode = 0600,
60078 + .proc_handler = &proc_dointvec,
60079 + },
60080 +#endif
60081 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60082 + {
60083 + .procname = "audit_mount",
60084 + .data = &grsec_enable_mount,
60085 + .maxlen = sizeof(int),
60086 + .mode = 0600,
60087 + .proc_handler = &proc_dointvec,
60088 + },
60089 +#endif
60090 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60091 + {
60092 + .procname = "audit_textrel",
60093 + .data = &grsec_enable_audit_textrel,
60094 + .maxlen = sizeof(int),
60095 + .mode = 0600,
60096 + .proc_handler = &proc_dointvec,
60097 + },
60098 +#endif
60099 +#ifdef CONFIG_GRKERNSEC_DMESG
60100 + {
60101 + .procname = "dmesg",
60102 + .data = &grsec_enable_dmesg,
60103 + .maxlen = sizeof(int),
60104 + .mode = 0600,
60105 + .proc_handler = &proc_dointvec,
60106 + },
60107 +#endif
60108 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60109 + {
60110 + .procname = "chroot_findtask",
60111 + .data = &grsec_enable_chroot_findtask,
60112 + .maxlen = sizeof(int),
60113 + .mode = 0600,
60114 + .proc_handler = &proc_dointvec,
60115 + },
60116 +#endif
60117 +#ifdef CONFIG_GRKERNSEC_RESLOG
60118 + {
60119 + .procname = "resource_logging",
60120 + .data = &grsec_resource_logging,
60121 + .maxlen = sizeof(int),
60122 + .mode = 0600,
60123 + .proc_handler = &proc_dointvec,
60124 + },
60125 +#endif
60126 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60127 + {
60128 + .procname = "audit_ptrace",
60129 + .data = &grsec_enable_audit_ptrace,
60130 + .maxlen = sizeof(int),
60131 + .mode = 0600,
60132 + .proc_handler = &proc_dointvec,
60133 + },
60134 +#endif
60135 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60136 + {
60137 + .procname = "harden_ptrace",
60138 + .data = &grsec_enable_harden_ptrace,
60139 + .maxlen = sizeof(int),
60140 + .mode = 0600,
60141 + .proc_handler = &proc_dointvec,
60142 + },
60143 +#endif
60144 + {
60145 + .procname = "grsec_lock",
60146 + .data = &grsec_lock,
60147 + .maxlen = sizeof(int),
60148 + .mode = 0600,
60149 + .proc_handler = &proc_dointvec,
60150 + },
60151 +#endif
60152 +#ifdef CONFIG_GRKERNSEC_ROFS
60153 + {
60154 + .procname = "romount_protect",
60155 + .data = &grsec_enable_rofs,
60156 + .maxlen = sizeof(int),
60157 + .mode = 0600,
60158 + .proc_handler = &proc_dointvec_minmax,
60159 + .extra1 = &one,
60160 + .extra2 = &one,
60161 + },
60162 +#endif
60163 + { }
60164 +};
60165 +#endif
60166 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60167 new file mode 100644
60168 index 0000000..0dc13c3
60169 --- /dev/null
60170 +++ b/grsecurity/grsec_time.c
60171 @@ -0,0 +1,16 @@
60172 +#include <linux/kernel.h>
60173 +#include <linux/sched.h>
60174 +#include <linux/grinternal.h>
60175 +#include <linux/module.h>
60176 +
60177 +void
60178 +gr_log_timechange(void)
60179 +{
60180 +#ifdef CONFIG_GRKERNSEC_TIME
60181 + if (grsec_enable_time)
60182 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60183 +#endif
60184 + return;
60185 +}
60186 +
60187 +EXPORT_SYMBOL(gr_log_timechange);
60188 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60189 new file mode 100644
60190 index 0000000..07e0dc0
60191 --- /dev/null
60192 +++ b/grsecurity/grsec_tpe.c
60193 @@ -0,0 +1,73 @@
60194 +#include <linux/kernel.h>
60195 +#include <linux/sched.h>
60196 +#include <linux/file.h>
60197 +#include <linux/fs.h>
60198 +#include <linux/grinternal.h>
60199 +
60200 +extern int gr_acl_tpe_check(void);
60201 +
60202 +int
60203 +gr_tpe_allow(const struct file *file)
60204 +{
60205 +#ifdef CONFIG_GRKERNSEC
60206 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60207 + const struct cred *cred = current_cred();
60208 + char *msg = NULL;
60209 + char *msg2 = NULL;
60210 +
60211 + // never restrict root
60212 + if (!cred->uid)
60213 + return 1;
60214 +
60215 + if (grsec_enable_tpe) {
60216 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60217 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60218 + msg = "not being in trusted group";
60219 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60220 + msg = "being in untrusted group";
60221 +#else
60222 + if (in_group_p(grsec_tpe_gid))
60223 + msg = "being in untrusted group";
60224 +#endif
60225 + }
60226 + if (!msg && gr_acl_tpe_check())
60227 + msg = "being in untrusted role";
60228 +
60229 + // not in any affected group/role
60230 + if (!msg)
60231 + goto next_check;
60232 +
60233 + if (inode->i_uid)
60234 + msg2 = "file in non-root-owned directory";
60235 + else if (inode->i_mode & S_IWOTH)
60236 + msg2 = "file in world-writable directory";
60237 + else if (inode->i_mode & S_IWGRP)
60238 + msg2 = "file in group-writable directory";
60239 +
60240 + if (msg && msg2) {
60241 + char fullmsg[70] = {0};
60242 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60243 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60244 + return 0;
60245 + }
60246 + msg = NULL;
60247 +next_check:
60248 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60249 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60250 + return 1;
60251 +
60252 + if (inode->i_uid && (inode->i_uid != cred->uid))
60253 + msg = "directory not owned by user";
60254 + else if (inode->i_mode & S_IWOTH)
60255 + msg = "file in world-writable directory";
60256 + else if (inode->i_mode & S_IWGRP)
60257 + msg = "file in group-writable directory";
60258 +
60259 + if (msg) {
60260 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60261 + return 0;
60262 + }
60263 +#endif
60264 +#endif
60265 + return 1;
60266 +}
60267 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60268 new file mode 100644
60269 index 0000000..9f7b1ac
60270 --- /dev/null
60271 +++ b/grsecurity/grsum.c
60272 @@ -0,0 +1,61 @@
60273 +#include <linux/err.h>
60274 +#include <linux/kernel.h>
60275 +#include <linux/sched.h>
60276 +#include <linux/mm.h>
60277 +#include <linux/scatterlist.h>
60278 +#include <linux/crypto.h>
60279 +#include <linux/gracl.h>
60280 +
60281 +
60282 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60283 +#error "crypto and sha256 must be built into the kernel"
60284 +#endif
60285 +
60286 +int
60287 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60288 +{
60289 + char *p;
60290 + struct crypto_hash *tfm;
60291 + struct hash_desc desc;
60292 + struct scatterlist sg;
60293 + unsigned char temp_sum[GR_SHA_LEN];
60294 + volatile int retval = 0;
60295 + volatile int dummy = 0;
60296 + unsigned int i;
60297 +
60298 + sg_init_table(&sg, 1);
60299 +
60300 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60301 + if (IS_ERR(tfm)) {
60302 + /* should never happen, since sha256 should be built in */
60303 + return 1;
60304 + }
60305 +
60306 + desc.tfm = tfm;
60307 + desc.flags = 0;
60308 +
60309 + crypto_hash_init(&desc);
60310 +
60311 + p = salt;
60312 + sg_set_buf(&sg, p, GR_SALT_LEN);
60313 + crypto_hash_update(&desc, &sg, sg.length);
60314 +
60315 + p = entry->pw;
60316 + sg_set_buf(&sg, p, strlen(p));
60317 +
60318 + crypto_hash_update(&desc, &sg, sg.length);
60319 +
60320 + crypto_hash_final(&desc, temp_sum);
60321 +
60322 + memset(entry->pw, 0, GR_PW_LEN);
60323 +
60324 + for (i = 0; i < GR_SHA_LEN; i++)
60325 + if (sum[i] != temp_sum[i])
60326 + retval = 1;
60327 + else
60328 + dummy = 1; // waste a cycle
60329 +
60330 + crypto_free_hash(tfm);
60331 +
60332 + return retval;
60333 +}
60334 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60335 index bde976e..a1cc32a 100644
60336 --- a/include/acpi/acpi_bus.h
60337 +++ b/include/acpi/acpi_bus.h
60338 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60339 acpi_op_bind bind;
60340 acpi_op_unbind unbind;
60341 acpi_op_notify notify;
60342 -};
60343 +} __no_const;
60344
60345 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60346
60347 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60348 index 77ff547..181834f 100644
60349 --- a/include/asm-generic/4level-fixup.h
60350 +++ b/include/asm-generic/4level-fixup.h
60351 @@ -13,8 +13,10 @@
60352 #define pmd_alloc(mm, pud, address) \
60353 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60354 NULL: pmd_offset(pud, address))
60355 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60356
60357 #define pud_alloc(mm, pgd, address) (pgd)
60358 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60359 #define pud_offset(pgd, start) (pgd)
60360 #define pud_none(pud) 0
60361 #define pud_bad(pud) 0
60362 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60363 index b7babf0..3ba8aee 100644
60364 --- a/include/asm-generic/atomic-long.h
60365 +++ b/include/asm-generic/atomic-long.h
60366 @@ -22,6 +22,12 @@
60367
60368 typedef atomic64_t atomic_long_t;
60369
60370 +#ifdef CONFIG_PAX_REFCOUNT
60371 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60372 +#else
60373 +typedef atomic64_t atomic_long_unchecked_t;
60374 +#endif
60375 +
60376 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60377
60378 static inline long atomic_long_read(atomic_long_t *l)
60379 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60380 return (long)atomic64_read(v);
60381 }
60382
60383 +#ifdef CONFIG_PAX_REFCOUNT
60384 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60385 +{
60386 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60387 +
60388 + return (long)atomic64_read_unchecked(v);
60389 +}
60390 +#endif
60391 +
60392 static inline void atomic_long_set(atomic_long_t *l, long i)
60393 {
60394 atomic64_t *v = (atomic64_t *)l;
60395 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60396 atomic64_set(v, i);
60397 }
60398
60399 +#ifdef CONFIG_PAX_REFCOUNT
60400 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60401 +{
60402 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60403 +
60404 + atomic64_set_unchecked(v, i);
60405 +}
60406 +#endif
60407 +
60408 static inline void atomic_long_inc(atomic_long_t *l)
60409 {
60410 atomic64_t *v = (atomic64_t *)l;
60411 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60412 atomic64_inc(v);
60413 }
60414
60415 +#ifdef CONFIG_PAX_REFCOUNT
60416 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60417 +{
60418 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60419 +
60420 + atomic64_inc_unchecked(v);
60421 +}
60422 +#endif
60423 +
60424 static inline void atomic_long_dec(atomic_long_t *l)
60425 {
60426 atomic64_t *v = (atomic64_t *)l;
60427 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60428 atomic64_dec(v);
60429 }
60430
60431 +#ifdef CONFIG_PAX_REFCOUNT
60432 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60433 +{
60434 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60435 +
60436 + atomic64_dec_unchecked(v);
60437 +}
60438 +#endif
60439 +
60440 static inline void atomic_long_add(long i, atomic_long_t *l)
60441 {
60442 atomic64_t *v = (atomic64_t *)l;
60443 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60444 atomic64_add(i, v);
60445 }
60446
60447 +#ifdef CONFIG_PAX_REFCOUNT
60448 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60449 +{
60450 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60451 +
60452 + atomic64_add_unchecked(i, v);
60453 +}
60454 +#endif
60455 +
60456 static inline void atomic_long_sub(long i, atomic_long_t *l)
60457 {
60458 atomic64_t *v = (atomic64_t *)l;
60459 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60460 atomic64_sub(i, v);
60461 }
60462
60463 +#ifdef CONFIG_PAX_REFCOUNT
60464 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60465 +{
60466 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60467 +
60468 + atomic64_sub_unchecked(i, v);
60469 +}
60470 +#endif
60471 +
60472 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60473 {
60474 atomic64_t *v = (atomic64_t *)l;
60475 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60476 return (long)atomic64_inc_return(v);
60477 }
60478
60479 +#ifdef CONFIG_PAX_REFCOUNT
60480 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60481 +{
60482 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60483 +
60484 + return (long)atomic64_inc_return_unchecked(v);
60485 +}
60486 +#endif
60487 +
60488 static inline long atomic_long_dec_return(atomic_long_t *l)
60489 {
60490 atomic64_t *v = (atomic64_t *)l;
60491 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60492
60493 typedef atomic_t atomic_long_t;
60494
60495 +#ifdef CONFIG_PAX_REFCOUNT
60496 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60497 +#else
60498 +typedef atomic_t atomic_long_unchecked_t;
60499 +#endif
60500 +
60501 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60502 static inline long atomic_long_read(atomic_long_t *l)
60503 {
60504 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60505 return (long)atomic_read(v);
60506 }
60507
60508 +#ifdef CONFIG_PAX_REFCOUNT
60509 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60510 +{
60511 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60512 +
60513 + return (long)atomic_read_unchecked(v);
60514 +}
60515 +#endif
60516 +
60517 static inline void atomic_long_set(atomic_long_t *l, long i)
60518 {
60519 atomic_t *v = (atomic_t *)l;
60520 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60521 atomic_set(v, i);
60522 }
60523
60524 +#ifdef CONFIG_PAX_REFCOUNT
60525 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60526 +{
60527 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60528 +
60529 + atomic_set_unchecked(v, i);
60530 +}
60531 +#endif
60532 +
60533 static inline void atomic_long_inc(atomic_long_t *l)
60534 {
60535 atomic_t *v = (atomic_t *)l;
60536 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60537 atomic_inc(v);
60538 }
60539
60540 +#ifdef CONFIG_PAX_REFCOUNT
60541 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60542 +{
60543 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60544 +
60545 + atomic_inc_unchecked(v);
60546 +}
60547 +#endif
60548 +
60549 static inline void atomic_long_dec(atomic_long_t *l)
60550 {
60551 atomic_t *v = (atomic_t *)l;
60552 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60553 atomic_dec(v);
60554 }
60555
60556 +#ifdef CONFIG_PAX_REFCOUNT
60557 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60558 +{
60559 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60560 +
60561 + atomic_dec_unchecked(v);
60562 +}
60563 +#endif
60564 +
60565 static inline void atomic_long_add(long i, atomic_long_t *l)
60566 {
60567 atomic_t *v = (atomic_t *)l;
60568 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60569 atomic_add(i, v);
60570 }
60571
60572 +#ifdef CONFIG_PAX_REFCOUNT
60573 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60574 +{
60575 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60576 +
60577 + atomic_add_unchecked(i, v);
60578 +}
60579 +#endif
60580 +
60581 static inline void atomic_long_sub(long i, atomic_long_t *l)
60582 {
60583 atomic_t *v = (atomic_t *)l;
60584 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60585 atomic_sub(i, v);
60586 }
60587
60588 +#ifdef CONFIG_PAX_REFCOUNT
60589 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60590 +{
60591 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60592 +
60593 + atomic_sub_unchecked(i, v);
60594 +}
60595 +#endif
60596 +
60597 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60598 {
60599 atomic_t *v = (atomic_t *)l;
60600 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60601 return (long)atomic_inc_return(v);
60602 }
60603
60604 +#ifdef CONFIG_PAX_REFCOUNT
60605 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60606 +{
60607 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60608 +
60609 + return (long)atomic_inc_return_unchecked(v);
60610 +}
60611 +#endif
60612 +
60613 static inline long atomic_long_dec_return(atomic_long_t *l)
60614 {
60615 atomic_t *v = (atomic_t *)l;
60616 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60617
60618 #endif /* BITS_PER_LONG == 64 */
60619
60620 +#ifdef CONFIG_PAX_REFCOUNT
60621 +static inline void pax_refcount_needs_these_functions(void)
60622 +{
60623 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60624 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60625 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60626 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60627 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60628 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60629 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60630 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60631 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60632 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60633 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60634 +#ifdef CONFIG_X86
60635 + atomic_clear_mask_unchecked(0, NULL);
60636 + atomic_set_mask_unchecked(0, NULL);
60637 +#endif
60638 +
60639 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60640 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60641 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60642 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60643 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60644 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60645 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60646 +}
60647 +#else
60648 +#define atomic_read_unchecked(v) atomic_read(v)
60649 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60650 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60651 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60652 +#define atomic_inc_unchecked(v) atomic_inc(v)
60653 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60654 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60655 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60656 +#define atomic_dec_unchecked(v) atomic_dec(v)
60657 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60658 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60659 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60660 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60661 +
60662 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60663 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60664 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60665 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60666 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60667 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60668 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60669 +#endif
60670 +
60671 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60672 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60673 index 1ced641..c896ee8 100644
60674 --- a/include/asm-generic/atomic.h
60675 +++ b/include/asm-generic/atomic.h
60676 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60677 * Atomically clears the bits set in @mask from @v
60678 */
60679 #ifndef atomic_clear_mask
60680 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60681 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60682 {
60683 unsigned long flags;
60684
60685 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60686 index b18ce4f..2ee2843 100644
60687 --- a/include/asm-generic/atomic64.h
60688 +++ b/include/asm-generic/atomic64.h
60689 @@ -16,6 +16,8 @@ typedef struct {
60690 long long counter;
60691 } atomic64_t;
60692
60693 +typedef atomic64_t atomic64_unchecked_t;
60694 +
60695 #define ATOMIC64_INIT(i) { (i) }
60696
60697 extern long long atomic64_read(const atomic64_t *v);
60698 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60699 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60700 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60701
60702 +#define atomic64_read_unchecked(v) atomic64_read(v)
60703 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60704 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60705 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60706 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60707 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60708 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60709 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60710 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60711 +
60712 #endif /* _ASM_GENERIC_ATOMIC64_H */
60713 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60714 index 1bfcfe5..e04c5c9 100644
60715 --- a/include/asm-generic/cache.h
60716 +++ b/include/asm-generic/cache.h
60717 @@ -6,7 +6,7 @@
60718 * cache lines need to provide their own cache.h.
60719 */
60720
60721 -#define L1_CACHE_SHIFT 5
60722 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60723 +#define L1_CACHE_SHIFT 5UL
60724 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60725
60726 #endif /* __ASM_GENERIC_CACHE_H */
60727 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60728 index 0d68a1e..b74a761 100644
60729 --- a/include/asm-generic/emergency-restart.h
60730 +++ b/include/asm-generic/emergency-restart.h
60731 @@ -1,7 +1,7 @@
60732 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60733 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60734
60735 -static inline void machine_emergency_restart(void)
60736 +static inline __noreturn void machine_emergency_restart(void)
60737 {
60738 machine_restart(NULL);
60739 }
60740 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60741 index 90f99c7..00ce236 100644
60742 --- a/include/asm-generic/kmap_types.h
60743 +++ b/include/asm-generic/kmap_types.h
60744 @@ -2,9 +2,9 @@
60745 #define _ASM_GENERIC_KMAP_TYPES_H
60746
60747 #ifdef __WITH_KM_FENCE
60748 -# define KM_TYPE_NR 41
60749 +# define KM_TYPE_NR 42
60750 #else
60751 -# define KM_TYPE_NR 20
60752 +# define KM_TYPE_NR 21
60753 #endif
60754
60755 #endif
60756 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60757 index 9ceb03b..2efbcbd 100644
60758 --- a/include/asm-generic/local.h
60759 +++ b/include/asm-generic/local.h
60760 @@ -39,6 +39,7 @@ typedef struct
60761 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60762 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60763 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60764 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60765
60766 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60767 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60768 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60769 index 725612b..9cc513a 100644
60770 --- a/include/asm-generic/pgtable-nopmd.h
60771 +++ b/include/asm-generic/pgtable-nopmd.h
60772 @@ -1,14 +1,19 @@
60773 #ifndef _PGTABLE_NOPMD_H
60774 #define _PGTABLE_NOPMD_H
60775
60776 -#ifndef __ASSEMBLY__
60777 -
60778 #include <asm-generic/pgtable-nopud.h>
60779
60780 -struct mm_struct;
60781 -
60782 #define __PAGETABLE_PMD_FOLDED
60783
60784 +#define PMD_SHIFT PUD_SHIFT
60785 +#define PTRS_PER_PMD 1
60786 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60787 +#define PMD_MASK (~(PMD_SIZE-1))
60788 +
60789 +#ifndef __ASSEMBLY__
60790 +
60791 +struct mm_struct;
60792 +
60793 /*
60794 * Having the pmd type consist of a pud gets the size right, and allows
60795 * us to conceptually access the pud entry that this pmd is folded into
60796 @@ -16,11 +21,6 @@ struct mm_struct;
60797 */
60798 typedef struct { pud_t pud; } pmd_t;
60799
60800 -#define PMD_SHIFT PUD_SHIFT
60801 -#define PTRS_PER_PMD 1
60802 -#define PMD_SIZE (1UL << PMD_SHIFT)
60803 -#define PMD_MASK (~(PMD_SIZE-1))
60804 -
60805 /*
60806 * The "pud_xxx()" functions here are trivial for a folded two-level
60807 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60808 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60809 index 810431d..0ec4804f 100644
60810 --- a/include/asm-generic/pgtable-nopud.h
60811 +++ b/include/asm-generic/pgtable-nopud.h
60812 @@ -1,10 +1,15 @@
60813 #ifndef _PGTABLE_NOPUD_H
60814 #define _PGTABLE_NOPUD_H
60815
60816 -#ifndef __ASSEMBLY__
60817 -
60818 #define __PAGETABLE_PUD_FOLDED
60819
60820 +#define PUD_SHIFT PGDIR_SHIFT
60821 +#define PTRS_PER_PUD 1
60822 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60823 +#define PUD_MASK (~(PUD_SIZE-1))
60824 +
60825 +#ifndef __ASSEMBLY__
60826 +
60827 /*
60828 * Having the pud type consist of a pgd gets the size right, and allows
60829 * us to conceptually access the pgd entry that this pud is folded into
60830 @@ -12,11 +17,6 @@
60831 */
60832 typedef struct { pgd_t pgd; } pud_t;
60833
60834 -#define PUD_SHIFT PGDIR_SHIFT
60835 -#define PTRS_PER_PUD 1
60836 -#define PUD_SIZE (1UL << PUD_SHIFT)
60837 -#define PUD_MASK (~(PUD_SIZE-1))
60838 -
60839 /*
60840 * The "pgd_xxx()" functions here are trivial for a folded two-level
60841 * setup: the pud is never bad, and a pud always exists (as it's folded
60842 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60843 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60844
60845 #define pgd_populate(mm, pgd, pud) do { } while (0)
60846 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60847 /*
60848 * (puds are folded into pgds so this doesn't get actually called,
60849 * but the define is needed for a generic inline function.)
60850 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60851 index ff4947b..f48183f 100644
60852 --- a/include/asm-generic/pgtable.h
60853 +++ b/include/asm-generic/pgtable.h
60854 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60855 #endif
60856 }
60857
60858 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60859 +static inline unsigned long pax_open_kernel(void) { return 0; }
60860 +#endif
60861 +
60862 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60863 +static inline unsigned long pax_close_kernel(void) { return 0; }
60864 +#endif
60865 +
60866 #endif /* CONFIG_MMU */
60867
60868 #endif /* !__ASSEMBLY__ */
60869 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60870 index 4e2e1cc..12c266b 100644
60871 --- a/include/asm-generic/vmlinux.lds.h
60872 +++ b/include/asm-generic/vmlinux.lds.h
60873 @@ -218,6 +218,7 @@
60874 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60875 VMLINUX_SYMBOL(__start_rodata) = .; \
60876 *(.rodata) *(.rodata.*) \
60877 + *(.data..read_only) \
60878 *(__vermagic) /* Kernel version magic */ \
60879 . = ALIGN(8); \
60880 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60881 @@ -716,17 +717,18 @@
60882 * section in the linker script will go there too. @phdr should have
60883 * a leading colon.
60884 *
60885 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60886 + * Note that this macros defines per_cpu_load as an absolute symbol.
60887 * If there is no need to put the percpu section at a predetermined
60888 * address, use PERCPU_SECTION.
60889 */
60890 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60891 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60892 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60893 + per_cpu_load = .; \
60894 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60895 - LOAD_OFFSET) { \
60896 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60897 PERCPU_INPUT(cacheline) \
60898 } phdr \
60899 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60900 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60901
60902 /**
60903 * PERCPU_SECTION - define output section for percpu area, simple version
60904 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60905 index d6b67bb..a272c29 100644
60906 --- a/include/drm/drmP.h
60907 +++ b/include/drm/drmP.h
60908 @@ -72,6 +72,7 @@
60909 #include <linux/workqueue.h>
60910 #include <linux/poll.h>
60911 #include <asm/pgalloc.h>
60912 +#include <asm/local.h>
60913 #include "drm.h"
60914
60915 #include <linux/idr.h>
60916 @@ -1067,7 +1068,7 @@ struct drm_device {
60917
60918 /** \name Usage Counters */
60919 /*@{ */
60920 - int open_count; /**< Outstanding files open */
60921 + local_t open_count; /**< Outstanding files open */
60922 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60923 atomic_t vma_count; /**< Outstanding vma areas open */
60924 int buf_use; /**< Buffers in use -- cannot alloc */
60925 @@ -1078,7 +1079,7 @@ struct drm_device {
60926 /*@{ */
60927 unsigned long counters;
60928 enum drm_stat_type types[15];
60929 - atomic_t counts[15];
60930 + atomic_unchecked_t counts[15];
60931 /*@} */
60932
60933 struct list_head filelist;
60934 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60935 index e01cc80..319855d 100644
60936 --- a/include/drm/drm_crtc_helper.h
60937 +++ b/include/drm/drm_crtc_helper.h
60938 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60939
60940 /* disable crtc when not in use - more explicit than dpms off */
60941 void (*disable)(struct drm_crtc *crtc);
60942 -};
60943 +} __no_const;
60944
60945 /**
60946 * drm_encoder_helper_funcs - helper operations for encoders
60947 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60948 struct drm_connector *connector);
60949 /* disable encoder when not in use - more explicit than dpms off */
60950 void (*disable)(struct drm_encoder *encoder);
60951 -};
60952 +} __no_const;
60953
60954 /**
60955 * drm_connector_helper_funcs - helper operations for connectors
60956 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60957 index d6d1da4..fdd1ac5 100644
60958 --- a/include/drm/ttm/ttm_memory.h
60959 +++ b/include/drm/ttm/ttm_memory.h
60960 @@ -48,7 +48,7 @@
60961
60962 struct ttm_mem_shrink {
60963 int (*do_shrink) (struct ttm_mem_shrink *);
60964 -};
60965 +} __no_const;
60966
60967 /**
60968 * struct ttm_mem_global - Global memory accounting structure.
60969 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60970 index e86dfca..40cc55f 100644
60971 --- a/include/linux/a.out.h
60972 +++ b/include/linux/a.out.h
60973 @@ -39,6 +39,14 @@ enum machine_type {
60974 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60975 };
60976
60977 +/* Constants for the N_FLAGS field */
60978 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60979 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60980 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60981 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60982 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60983 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60984 +
60985 #if !defined (N_MAGIC)
60986 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60987 #endif
60988 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60989 index 06fd4bb..1caec0d 100644
60990 --- a/include/linux/atmdev.h
60991 +++ b/include/linux/atmdev.h
60992 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60993 #endif
60994
60995 struct k_atm_aal_stats {
60996 -#define __HANDLE_ITEM(i) atomic_t i
60997 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60998 __AAL_STAT_ITEMS
60999 #undef __HANDLE_ITEM
61000 };
61001 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61002 index 366422b..1fa7f84 100644
61003 --- a/include/linux/binfmts.h
61004 +++ b/include/linux/binfmts.h
61005 @@ -89,6 +89,7 @@ struct linux_binfmt {
61006 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61007 int (*load_shlib)(struct file *);
61008 int (*core_dump)(struct coredump_params *cprm);
61009 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61010 unsigned long min_coredump; /* minimal dump size */
61011 };
61012
61013 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61014 index 4a2ab7c..a2de7a8 100644
61015 --- a/include/linux/blkdev.h
61016 +++ b/include/linux/blkdev.h
61017 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61018 /* this callback is with swap_lock and sometimes page table lock held */
61019 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61020 struct module *owner;
61021 -};
61022 +} __do_const;
61023
61024 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61025 unsigned long);
61026 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61027 index 4d1a074..88f929a 100644
61028 --- a/include/linux/blktrace_api.h
61029 +++ b/include/linux/blktrace_api.h
61030 @@ -162,7 +162,7 @@ struct blk_trace {
61031 struct dentry *dir;
61032 struct dentry *dropped_file;
61033 struct dentry *msg_file;
61034 - atomic_t dropped;
61035 + atomic_unchecked_t dropped;
61036 };
61037
61038 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61039 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61040 index 83195fb..0b0f77d 100644
61041 --- a/include/linux/byteorder/little_endian.h
61042 +++ b/include/linux/byteorder/little_endian.h
61043 @@ -42,51 +42,51 @@
61044
61045 static inline __le64 __cpu_to_le64p(const __u64 *p)
61046 {
61047 - return (__force __le64)*p;
61048 + return (__force const __le64)*p;
61049 }
61050 static inline __u64 __le64_to_cpup(const __le64 *p)
61051 {
61052 - return (__force __u64)*p;
61053 + return (__force const __u64)*p;
61054 }
61055 static inline __le32 __cpu_to_le32p(const __u32 *p)
61056 {
61057 - return (__force __le32)*p;
61058 + return (__force const __le32)*p;
61059 }
61060 static inline __u32 __le32_to_cpup(const __le32 *p)
61061 {
61062 - return (__force __u32)*p;
61063 + return (__force const __u32)*p;
61064 }
61065 static inline __le16 __cpu_to_le16p(const __u16 *p)
61066 {
61067 - return (__force __le16)*p;
61068 + return (__force const __le16)*p;
61069 }
61070 static inline __u16 __le16_to_cpup(const __le16 *p)
61071 {
61072 - return (__force __u16)*p;
61073 + return (__force const __u16)*p;
61074 }
61075 static inline __be64 __cpu_to_be64p(const __u64 *p)
61076 {
61077 - return (__force __be64)__swab64p(p);
61078 + return (__force const __be64)__swab64p(p);
61079 }
61080 static inline __u64 __be64_to_cpup(const __be64 *p)
61081 {
61082 - return __swab64p((__u64 *)p);
61083 + return __swab64p((const __u64 *)p);
61084 }
61085 static inline __be32 __cpu_to_be32p(const __u32 *p)
61086 {
61087 - return (__force __be32)__swab32p(p);
61088 + return (__force const __be32)__swab32p(p);
61089 }
61090 static inline __u32 __be32_to_cpup(const __be32 *p)
61091 {
61092 - return __swab32p((__u32 *)p);
61093 + return __swab32p((const __u32 *)p);
61094 }
61095 static inline __be16 __cpu_to_be16p(const __u16 *p)
61096 {
61097 - return (__force __be16)__swab16p(p);
61098 + return (__force const __be16)__swab16p(p);
61099 }
61100 static inline __u16 __be16_to_cpup(const __be16 *p)
61101 {
61102 - return __swab16p((__u16 *)p);
61103 + return __swab16p((const __u16 *)p);
61104 }
61105 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61106 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61107 diff --git a/include/linux/cache.h b/include/linux/cache.h
61108 index 4c57065..4307975 100644
61109 --- a/include/linux/cache.h
61110 +++ b/include/linux/cache.h
61111 @@ -16,6 +16,10 @@
61112 #define __read_mostly
61113 #endif
61114
61115 +#ifndef __read_only
61116 +#define __read_only __read_mostly
61117 +#endif
61118 +
61119 #ifndef ____cacheline_aligned
61120 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61121 #endif
61122 diff --git a/include/linux/capability.h b/include/linux/capability.h
61123 index d10b7ed..0288b79 100644
61124 --- a/include/linux/capability.h
61125 +++ b/include/linux/capability.h
61126 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61127 extern bool ns_capable(struct user_namespace *ns, int cap);
61128 extern bool nsown_capable(int cap);
61129 extern bool inode_capable(const struct inode *inode, int cap);
61130 +extern bool capable_nolog(int cap);
61131 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61132 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61133
61134 /* audit system wants to get cap info from files as well */
61135 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61136
61137 +extern int is_privileged_binary(const struct dentry *dentry);
61138 +
61139 #endif /* __KERNEL__ */
61140
61141 #endif /* !_LINUX_CAPABILITY_H */
61142 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61143 index 42e55de..1cd0e66 100644
61144 --- a/include/linux/cleancache.h
61145 +++ b/include/linux/cleancache.h
61146 @@ -31,7 +31,7 @@ struct cleancache_ops {
61147 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61148 void (*invalidate_inode)(int, struct cleancache_filekey);
61149 void (*invalidate_fs)(int);
61150 -};
61151 +} __no_const;
61152
61153 extern struct cleancache_ops
61154 cleancache_register_ops(struct cleancache_ops *ops);
61155 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61156 index 77335fa..6cbe7dd 100644
61157 --- a/include/linux/clk-provider.h
61158 +++ b/include/linux/clk-provider.h
61159 @@ -111,6 +111,7 @@ struct clk_ops {
61160 unsigned long);
61161 void (*init)(struct clk_hw *hw);
61162 };
61163 +typedef struct clk_ops __no_const clk_ops_no_const;
61164
61165 /**
61166 * struct clk_init_data - holds init data that's common to all clocks and is
61167 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61168 index 934bc34..1b47129 100644
61169 --- a/include/linux/compiler-gcc4.h
61170 +++ b/include/linux/compiler-gcc4.h
61171 @@ -32,6 +32,21 @@
61172 #define __linktime_error(message) __attribute__((__error__(message)))
61173
61174 #if __GNUC_MINOR__ >= 5
61175 +
61176 +#ifdef CONSTIFY_PLUGIN
61177 +#define __no_const __attribute__((no_const))
61178 +#define __do_const __attribute__((do_const))
61179 +#endif
61180 +
61181 +#ifdef SIZE_OVERFLOW_PLUGIN
61182 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61183 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61184 +#endif
61185 +
61186 +#ifdef LATENT_ENTROPY_PLUGIN
61187 +#define __latent_entropy __attribute__((latent_entropy))
61188 +#endif
61189 +
61190 /*
61191 * Mark a position in code as unreachable. This can be used to
61192 * suppress control flow warnings after asm blocks that transfer
61193 @@ -47,6 +62,11 @@
61194 #define __noclone __attribute__((__noclone__))
61195
61196 #endif
61197 +
61198 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61199 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61200 +#define __bos0(ptr) __bos((ptr), 0)
61201 +#define __bos1(ptr) __bos((ptr), 1)
61202 #endif
61203
61204 #if __GNUC_MINOR__ >= 6
61205 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61206 index f430e41..38be90f 100644
61207 --- a/include/linux/compiler.h
61208 +++ b/include/linux/compiler.h
61209 @@ -5,31 +5,62 @@
61210
61211 #ifdef __CHECKER__
61212 # define __user __attribute__((noderef, address_space(1)))
61213 +# define __force_user __force __user
61214 # define __kernel __attribute__((address_space(0)))
61215 +# define __force_kernel __force __kernel
61216 # define __safe __attribute__((safe))
61217 # define __force __attribute__((force))
61218 # define __nocast __attribute__((nocast))
61219 # define __iomem __attribute__((noderef, address_space(2)))
61220 +# define __force_iomem __force __iomem
61221 # define __acquires(x) __attribute__((context(x,0,1)))
61222 # define __releases(x) __attribute__((context(x,1,0)))
61223 # define __acquire(x) __context__(x,1)
61224 # define __release(x) __context__(x,-1)
61225 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61226 # define __percpu __attribute__((noderef, address_space(3)))
61227 +# define __force_percpu __force __percpu
61228 #ifdef CONFIG_SPARSE_RCU_POINTER
61229 # define __rcu __attribute__((noderef, address_space(4)))
61230 +# define __force_rcu __force __rcu
61231 #else
61232 # define __rcu
61233 +# define __force_rcu
61234 #endif
61235 extern void __chk_user_ptr(const volatile void __user *);
61236 extern void __chk_io_ptr(const volatile void __iomem *);
61237 +#elif defined(CHECKER_PLUGIN)
61238 +//# define __user
61239 +//# define __force_user
61240 +//# define __kernel
61241 +//# define __force_kernel
61242 +# define __safe
61243 +# define __force
61244 +# define __nocast
61245 +# define __iomem
61246 +# define __force_iomem
61247 +# define __chk_user_ptr(x) (void)0
61248 +# define __chk_io_ptr(x) (void)0
61249 +# define __builtin_warning(x, y...) (1)
61250 +# define __acquires(x)
61251 +# define __releases(x)
61252 +# define __acquire(x) (void)0
61253 +# define __release(x) (void)0
61254 +# define __cond_lock(x,c) (c)
61255 +# define __percpu
61256 +# define __force_percpu
61257 +# define __rcu
61258 +# define __force_rcu
61259 #else
61260 # define __user
61261 +# define __force_user
61262 # define __kernel
61263 +# define __force_kernel
61264 # define __safe
61265 # define __force
61266 # define __nocast
61267 # define __iomem
61268 +# define __force_iomem
61269 # define __chk_user_ptr(x) (void)0
61270 # define __chk_io_ptr(x) (void)0
61271 # define __builtin_warning(x, y...) (1)
61272 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61273 # define __release(x) (void)0
61274 # define __cond_lock(x,c) (c)
61275 # define __percpu
61276 +# define __force_percpu
61277 # define __rcu
61278 +# define __force_rcu
61279 #endif
61280
61281 #ifdef __KERNEL__
61282 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61283 # define __attribute_const__ /* unimplemented */
61284 #endif
61285
61286 +#ifndef __no_const
61287 +# define __no_const
61288 +#endif
61289 +
61290 +#ifndef __do_const
61291 +# define __do_const
61292 +#endif
61293 +
61294 +#ifndef __size_overflow
61295 +# define __size_overflow(...)
61296 +#endif
61297 +
61298 +#ifndef __intentional_overflow
61299 +# define __intentional_overflow(...)
61300 +#endif
61301 +
61302 +#ifndef __latent_entropy
61303 +# define __latent_entropy
61304 +#endif
61305 +
61306 /*
61307 * Tell gcc if a function is cold. The compiler will assume any path
61308 * directly leading to the call is unlikely.
61309 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61310 #define __cold
61311 #endif
61312
61313 +#ifndef __alloc_size
61314 +#define __alloc_size(...)
61315 +#endif
61316 +
61317 +#ifndef __bos
61318 +#define __bos(ptr, arg)
61319 +#endif
61320 +
61321 +#ifndef __bos0
61322 +#define __bos0(ptr)
61323 +#endif
61324 +
61325 +#ifndef __bos1
61326 +#define __bos1(ptr)
61327 +#endif
61328 +
61329 /* Simple shorthand for a section definition */
61330 #ifndef __section
61331 # define __section(S) __attribute__ ((__section__(#S)))
61332 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61333 * use is to mediate communication between process-level code and irq/NMI
61334 * handlers, all running on the same CPU.
61335 */
61336 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61337 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61338 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61339
61340 #endif /* __LINUX_COMPILER_H */
61341 diff --git a/include/linux/cred.h b/include/linux/cred.h
61342 index ebbed2c..908cc2c 100644
61343 --- a/include/linux/cred.h
61344 +++ b/include/linux/cred.h
61345 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61346 static inline void validate_process_creds(void)
61347 {
61348 }
61349 +static inline void validate_task_creds(struct task_struct *task)
61350 +{
61351 +}
61352 #endif
61353
61354 /**
61355 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61356 index b92eadf..b4ecdc1 100644
61357 --- a/include/linux/crypto.h
61358 +++ b/include/linux/crypto.h
61359 @@ -373,7 +373,7 @@ struct cipher_tfm {
61360 const u8 *key, unsigned int keylen);
61361 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61362 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61363 -};
61364 +} __no_const;
61365
61366 struct hash_tfm {
61367 int (*init)(struct hash_desc *desc);
61368 @@ -394,13 +394,13 @@ struct compress_tfm {
61369 int (*cot_decompress)(struct crypto_tfm *tfm,
61370 const u8 *src, unsigned int slen,
61371 u8 *dst, unsigned int *dlen);
61372 -};
61373 +} __no_const;
61374
61375 struct rng_tfm {
61376 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61377 unsigned int dlen);
61378 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61379 -};
61380 +} __no_const;
61381
61382 #define crt_ablkcipher crt_u.ablkcipher
61383 #define crt_aead crt_u.aead
61384 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61385 index 7925bf0..d5143d2 100644
61386 --- a/include/linux/decompress/mm.h
61387 +++ b/include/linux/decompress/mm.h
61388 @@ -77,7 +77,7 @@ static void free(void *where)
61389 * warnings when not needed (indeed large_malloc / large_free are not
61390 * needed by inflate */
61391
61392 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61393 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61394 #define free(a) kfree(a)
61395
61396 #define large_malloc(a) vmalloc(a)
61397 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61398 index 94af418..b1ca7a2 100644
61399 --- a/include/linux/dma-mapping.h
61400 +++ b/include/linux/dma-mapping.h
61401 @@ -54,7 +54,7 @@ struct dma_map_ops {
61402 u64 (*get_required_mask)(struct device *dev);
61403 #endif
61404 int is_phys;
61405 -};
61406 +} __do_const;
61407
61408 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61409
61410 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61411 index 9c02a45..89fdd73 100644
61412 --- a/include/linux/dmaengine.h
61413 +++ b/include/linux/dmaengine.h
61414 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61415 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61416 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61417
61418 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61419 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61420 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61421 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61422 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61423 struct dma_pinned_list *pinned_list, struct page *page,
61424 unsigned int offset, size_t len);
61425
61426 diff --git a/include/linux/efi.h b/include/linux/efi.h
61427 index ec45ccd..9923c32 100644
61428 --- a/include/linux/efi.h
61429 +++ b/include/linux/efi.h
61430 @@ -635,7 +635,7 @@ struct efivar_operations {
61431 efi_get_variable_t *get_variable;
61432 efi_get_next_variable_t *get_next_variable;
61433 efi_set_variable_t *set_variable;
61434 -};
61435 +} __no_const;
61436
61437 struct efivars {
61438 /*
61439 diff --git a/include/linux/elf.h b/include/linux/elf.h
61440 index 999b4f5..57753b4 100644
61441 --- a/include/linux/elf.h
61442 +++ b/include/linux/elf.h
61443 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61444 #define PT_GNU_EH_FRAME 0x6474e550
61445
61446 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61447 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61448 +
61449 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61450 +
61451 +/* Constants for the e_flags field */
61452 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61453 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61454 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61455 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61456 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61457 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61458
61459 /*
61460 * Extended Numbering
61461 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61462 #define DT_DEBUG 21
61463 #define DT_TEXTREL 22
61464 #define DT_JMPREL 23
61465 +#define DT_FLAGS 30
61466 + #define DF_TEXTREL 0x00000004
61467 #define DT_ENCODING 32
61468 #define OLD_DT_LOOS 0x60000000
61469 #define DT_LOOS 0x6000000d
61470 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61471 #define PF_W 0x2
61472 #define PF_X 0x1
61473
61474 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61475 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61476 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61477 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61478 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61479 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61480 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61481 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61482 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61483 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61484 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61485 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61486 +
61487 typedef struct elf32_phdr{
61488 Elf32_Word p_type;
61489 Elf32_Off p_offset;
61490 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61491 #define EI_OSABI 7
61492 #define EI_PAD 8
61493
61494 +#define EI_PAX 14
61495 +
61496 #define ELFMAG0 0x7f /* EI_MAG */
61497 #define ELFMAG1 'E'
61498 #define ELFMAG2 'L'
61499 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61500 #define elf_note elf32_note
61501 #define elf_addr_t Elf32_Off
61502 #define Elf_Half Elf32_Half
61503 +#define elf_dyn Elf32_Dyn
61504
61505 #else
61506
61507 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61508 #define elf_note elf64_note
61509 #define elf_addr_t Elf64_Off
61510 #define Elf_Half Elf64_Half
61511 +#define elf_dyn Elf64_Dyn
61512
61513 #endif
61514
61515 diff --git a/include/linux/filter.h b/include/linux/filter.h
61516 index 82b0135..917914d 100644
61517 --- a/include/linux/filter.h
61518 +++ b/include/linux/filter.h
61519 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61520
61521 struct sk_buff;
61522 struct sock;
61523 +struct bpf_jit_work;
61524
61525 struct sk_filter
61526 {
61527 @@ -153,6 +154,9 @@ struct sk_filter
61528 unsigned int len; /* Number of filter blocks */
61529 unsigned int (*bpf_func)(const struct sk_buff *skb,
61530 const struct sock_filter *filter);
61531 +#ifdef CONFIG_BPF_JIT
61532 + struct bpf_jit_work *work;
61533 +#endif
61534 struct rcu_head rcu;
61535 struct sock_filter insns[0];
61536 };
61537 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61538 index db04ec5..f6ed627 100644
61539 --- a/include/linux/firewire.h
61540 +++ b/include/linux/firewire.h
61541 @@ -430,7 +430,7 @@ struct fw_iso_context {
61542 union {
61543 fw_iso_callback_t sc;
61544 fw_iso_mc_callback_t mc;
61545 - } callback;
61546 + } __no_const callback;
61547 void *callback_data;
61548 };
61549
61550 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61551 index 0e4e2ee..4ff4312 100644
61552 --- a/include/linux/frontswap.h
61553 +++ b/include/linux/frontswap.h
61554 @@ -11,7 +11,7 @@ struct frontswap_ops {
61555 int (*load)(unsigned, pgoff_t, struct page *);
61556 void (*invalidate_page)(unsigned, pgoff_t);
61557 void (*invalidate_area)(unsigned);
61558 -};
61559 +} __no_const;
61560
61561 extern bool frontswap_enabled;
61562 extern struct frontswap_ops
61563 diff --git a/include/linux/fs.h b/include/linux/fs.h
61564 index aa11047..7d046d0 100644
61565 --- a/include/linux/fs.h
61566 +++ b/include/linux/fs.h
61567 @@ -1802,7 +1802,8 @@ struct file_operations {
61568 int (*setlease)(struct file *, long, struct file_lock **);
61569 long (*fallocate)(struct file *file, int mode, loff_t offset,
61570 loff_t len);
61571 -};
61572 +} __do_const;
61573 +typedef struct file_operations __no_const file_operations_no_const;
61574
61575 struct inode_operations {
61576 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61577 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61578 index 003dc0f..3c4ea97 100644
61579 --- a/include/linux/fs_struct.h
61580 +++ b/include/linux/fs_struct.h
61581 @@ -6,7 +6,7 @@
61582 #include <linux/seqlock.h>
61583
61584 struct fs_struct {
61585 - int users;
61586 + atomic_t users;
61587 spinlock_t lock;
61588 seqcount_t seq;
61589 int umask;
61590 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61591 index ce31408..b1ad003 100644
61592 --- a/include/linux/fscache-cache.h
61593 +++ b/include/linux/fscache-cache.h
61594 @@ -102,7 +102,7 @@ struct fscache_operation {
61595 fscache_operation_release_t release;
61596 };
61597
61598 -extern atomic_t fscache_op_debug_id;
61599 +extern atomic_unchecked_t fscache_op_debug_id;
61600 extern void fscache_op_work_func(struct work_struct *work);
61601
61602 extern void fscache_enqueue_operation(struct fscache_operation *);
61603 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61604 {
61605 INIT_WORK(&op->work, fscache_op_work_func);
61606 atomic_set(&op->usage, 1);
61607 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61608 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61609 op->processor = processor;
61610 op->release = release;
61611 INIT_LIST_HEAD(&op->pend_link);
61612 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61613 index a6dfe69..569586df 100644
61614 --- a/include/linux/fsnotify.h
61615 +++ b/include/linux/fsnotify.h
61616 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61617 */
61618 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61619 {
61620 - return kstrdup(name, GFP_KERNEL);
61621 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61622 }
61623
61624 /*
61625 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61626 index 63d966d..cdcb717 100644
61627 --- a/include/linux/fsnotify_backend.h
61628 +++ b/include/linux/fsnotify_backend.h
61629 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61630 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61631 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61632 };
61633 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61634
61635 /*
61636 * A group is a "thing" that wants to receive notification about filesystem
61637 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61638 index 642928c..e6c83a7 100644
61639 --- a/include/linux/ftrace_event.h
61640 +++ b/include/linux/ftrace_event.h
61641 @@ -97,7 +97,7 @@ struct trace_event_functions {
61642 trace_print_func raw;
61643 trace_print_func hex;
61644 trace_print_func binary;
61645 -};
61646 +} __no_const;
61647
61648 struct trace_event {
61649 struct hlist_node node;
61650 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61651 extern int trace_add_event_call(struct ftrace_event_call *call);
61652 extern void trace_remove_event_call(struct ftrace_event_call *call);
61653
61654 -#define is_signed_type(type) (((type)(-1)) < 0)
61655 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61656
61657 int trace_set_clr_event(const char *system, const char *event, int set);
61658
61659 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61660 index 4f440b3..342233a 100644
61661 --- a/include/linux/genhd.h
61662 +++ b/include/linux/genhd.h
61663 @@ -190,7 +190,7 @@ struct gendisk {
61664 struct kobject *slave_dir;
61665
61666 struct timer_rand_state *random;
61667 - atomic_t sync_io; /* RAID */
61668 + atomic_unchecked_t sync_io; /* RAID */
61669 struct disk_events *ev;
61670 #ifdef CONFIG_BLK_DEV_INTEGRITY
61671 struct blk_integrity *integrity;
61672 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61673 index 4883f39..26688a8 100644
61674 --- a/include/linux/gfp.h
61675 +++ b/include/linux/gfp.h
61676 @@ -39,6 +39,12 @@ struct vm_area_struct;
61677 #define ___GFP_OTHER_NODE 0x800000u
61678 #define ___GFP_WRITE 0x1000000u
61679
61680 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61681 +#define ___GFP_USERCOPY 0x2000000u
61682 +#else
61683 +#define ___GFP_USERCOPY 0
61684 +#endif
61685 +
61686 /*
61687 * GFP bitmasks..
61688 *
61689 @@ -93,6 +99,7 @@ struct vm_area_struct;
61690 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61691 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61692 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61693 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61694
61695 /*
61696 * This may seem redundant, but it's a way of annotating false positives vs.
61697 @@ -100,7 +107,7 @@ struct vm_area_struct;
61698 */
61699 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61700
61701 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61702 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61703 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61704
61705 /* This equals 0, but use constants in case they ever change */
61706 @@ -154,6 +161,8 @@ struct vm_area_struct;
61707 /* 4GB DMA on some platforms */
61708 #define GFP_DMA32 __GFP_DMA32
61709
61710 +#define GFP_USERCOPY __GFP_USERCOPY
61711 +
61712 /* Convert GFP flags to their corresponding migrate type */
61713 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61714 {
61715 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61716 new file mode 100644
61717 index 0000000..c938b1f
61718 --- /dev/null
61719 +++ b/include/linux/gracl.h
61720 @@ -0,0 +1,319 @@
61721 +#ifndef GR_ACL_H
61722 +#define GR_ACL_H
61723 +
61724 +#include <linux/grdefs.h>
61725 +#include <linux/resource.h>
61726 +#include <linux/capability.h>
61727 +#include <linux/dcache.h>
61728 +#include <asm/resource.h>
61729 +
61730 +/* Major status information */
61731 +
61732 +#define GR_VERSION "grsecurity 2.9.1"
61733 +#define GRSECURITY_VERSION 0x2901
61734 +
61735 +enum {
61736 + GR_SHUTDOWN = 0,
61737 + GR_ENABLE = 1,
61738 + GR_SPROLE = 2,
61739 + GR_RELOAD = 3,
61740 + GR_SEGVMOD = 4,
61741 + GR_STATUS = 5,
61742 + GR_UNSPROLE = 6,
61743 + GR_PASSSET = 7,
61744 + GR_SPROLEPAM = 8,
61745 +};
61746 +
61747 +/* Password setup definitions
61748 + * kernel/grhash.c */
61749 +enum {
61750 + GR_PW_LEN = 128,
61751 + GR_SALT_LEN = 16,
61752 + GR_SHA_LEN = 32,
61753 +};
61754 +
61755 +enum {
61756 + GR_SPROLE_LEN = 64,
61757 +};
61758 +
61759 +enum {
61760 + GR_NO_GLOB = 0,
61761 + GR_REG_GLOB,
61762 + GR_CREATE_GLOB
61763 +};
61764 +
61765 +#define GR_NLIMITS 32
61766 +
61767 +/* Begin Data Structures */
61768 +
61769 +struct sprole_pw {
61770 + unsigned char *rolename;
61771 + unsigned char salt[GR_SALT_LEN];
61772 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61773 +};
61774 +
61775 +struct name_entry {
61776 + __u32 key;
61777 + ino_t inode;
61778 + dev_t device;
61779 + char *name;
61780 + __u16 len;
61781 + __u8 deleted;
61782 + struct name_entry *prev;
61783 + struct name_entry *next;
61784 +};
61785 +
61786 +struct inodev_entry {
61787 + struct name_entry *nentry;
61788 + struct inodev_entry *prev;
61789 + struct inodev_entry *next;
61790 +};
61791 +
61792 +struct acl_role_db {
61793 + struct acl_role_label **r_hash;
61794 + __u32 r_size;
61795 +};
61796 +
61797 +struct inodev_db {
61798 + struct inodev_entry **i_hash;
61799 + __u32 i_size;
61800 +};
61801 +
61802 +struct name_db {
61803 + struct name_entry **n_hash;
61804 + __u32 n_size;
61805 +};
61806 +
61807 +struct crash_uid {
61808 + uid_t uid;
61809 + unsigned long expires;
61810 +};
61811 +
61812 +struct gr_hash_struct {
61813 + void **table;
61814 + void **nametable;
61815 + void *first;
61816 + __u32 table_size;
61817 + __u32 used_size;
61818 + int type;
61819 +};
61820 +
61821 +/* Userspace Grsecurity ACL data structures */
61822 +
61823 +struct acl_subject_label {
61824 + char *filename;
61825 + ino_t inode;
61826 + dev_t device;
61827 + __u32 mode;
61828 + kernel_cap_t cap_mask;
61829 + kernel_cap_t cap_lower;
61830 + kernel_cap_t cap_invert_audit;
61831 +
61832 + struct rlimit res[GR_NLIMITS];
61833 + __u32 resmask;
61834 +
61835 + __u8 user_trans_type;
61836 + __u8 group_trans_type;
61837 + uid_t *user_transitions;
61838 + gid_t *group_transitions;
61839 + __u16 user_trans_num;
61840 + __u16 group_trans_num;
61841 +
61842 + __u32 sock_families[2];
61843 + __u32 ip_proto[8];
61844 + __u32 ip_type;
61845 + struct acl_ip_label **ips;
61846 + __u32 ip_num;
61847 + __u32 inaddr_any_override;
61848 +
61849 + __u32 crashes;
61850 + unsigned long expires;
61851 +
61852 + struct acl_subject_label *parent_subject;
61853 + struct gr_hash_struct *hash;
61854 + struct acl_subject_label *prev;
61855 + struct acl_subject_label *next;
61856 +
61857 + struct acl_object_label **obj_hash;
61858 + __u32 obj_hash_size;
61859 + __u16 pax_flags;
61860 +};
61861 +
61862 +struct role_allowed_ip {
61863 + __u32 addr;
61864 + __u32 netmask;
61865 +
61866 + struct role_allowed_ip *prev;
61867 + struct role_allowed_ip *next;
61868 +};
61869 +
61870 +struct role_transition {
61871 + char *rolename;
61872 +
61873 + struct role_transition *prev;
61874 + struct role_transition *next;
61875 +};
61876 +
61877 +struct acl_role_label {
61878 + char *rolename;
61879 + uid_t uidgid;
61880 + __u16 roletype;
61881 +
61882 + __u16 auth_attempts;
61883 + unsigned long expires;
61884 +
61885 + struct acl_subject_label *root_label;
61886 + struct gr_hash_struct *hash;
61887 +
61888 + struct acl_role_label *prev;
61889 + struct acl_role_label *next;
61890 +
61891 + struct role_transition *transitions;
61892 + struct role_allowed_ip *allowed_ips;
61893 + uid_t *domain_children;
61894 + __u16 domain_child_num;
61895 +
61896 + umode_t umask;
61897 +
61898 + struct acl_subject_label **subj_hash;
61899 + __u32 subj_hash_size;
61900 +};
61901 +
61902 +struct user_acl_role_db {
61903 + struct acl_role_label **r_table;
61904 + __u32 num_pointers; /* Number of allocations to track */
61905 + __u32 num_roles; /* Number of roles */
61906 + __u32 num_domain_children; /* Number of domain children */
61907 + __u32 num_subjects; /* Number of subjects */
61908 + __u32 num_objects; /* Number of objects */
61909 +};
61910 +
61911 +struct acl_object_label {
61912 + char *filename;
61913 + ino_t inode;
61914 + dev_t device;
61915 + __u32 mode;
61916 +
61917 + struct acl_subject_label *nested;
61918 + struct acl_object_label *globbed;
61919 +
61920 + /* next two structures not used */
61921 +
61922 + struct acl_object_label *prev;
61923 + struct acl_object_label *next;
61924 +};
61925 +
61926 +struct acl_ip_label {
61927 + char *iface;
61928 + __u32 addr;
61929 + __u32 netmask;
61930 + __u16 low, high;
61931 + __u8 mode;
61932 + __u32 type;
61933 + __u32 proto[8];
61934 +
61935 + /* next two structures not used */
61936 +
61937 + struct acl_ip_label *prev;
61938 + struct acl_ip_label *next;
61939 +};
61940 +
61941 +struct gr_arg {
61942 + struct user_acl_role_db role_db;
61943 + unsigned char pw[GR_PW_LEN];
61944 + unsigned char salt[GR_SALT_LEN];
61945 + unsigned char sum[GR_SHA_LEN];
61946 + unsigned char sp_role[GR_SPROLE_LEN];
61947 + struct sprole_pw *sprole_pws;
61948 + dev_t segv_device;
61949 + ino_t segv_inode;
61950 + uid_t segv_uid;
61951 + __u16 num_sprole_pws;
61952 + __u16 mode;
61953 +};
61954 +
61955 +struct gr_arg_wrapper {
61956 + struct gr_arg *arg;
61957 + __u32 version;
61958 + __u32 size;
61959 +};
61960 +
61961 +struct subject_map {
61962 + struct acl_subject_label *user;
61963 + struct acl_subject_label *kernel;
61964 + struct subject_map *prev;
61965 + struct subject_map *next;
61966 +};
61967 +
61968 +struct acl_subj_map_db {
61969 + struct subject_map **s_hash;
61970 + __u32 s_size;
61971 +};
61972 +
61973 +/* End Data Structures Section */
61974 +
61975 +/* Hash functions generated by empirical testing by Brad Spengler
61976 + Makes good use of the low bits of the inode. Generally 0-1 times
61977 + in loop for successful match. 0-3 for unsuccessful match.
61978 + Shift/add algorithm with modulus of table size and an XOR*/
61979 +
61980 +static __inline__ unsigned int
61981 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61982 +{
61983 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61984 +}
61985 +
61986 + static __inline__ unsigned int
61987 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61988 +{
61989 + return ((const unsigned long)userp % sz);
61990 +}
61991 +
61992 +static __inline__ unsigned int
61993 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61994 +{
61995 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61996 +}
61997 +
61998 +static __inline__ unsigned int
61999 +nhash(const char *name, const __u16 len, const unsigned int sz)
62000 +{
62001 + return full_name_hash((const unsigned char *)name, len) % sz;
62002 +}
62003 +
62004 +#define FOR_EACH_ROLE_START(role) \
62005 + role = role_list; \
62006 + while (role) {
62007 +
62008 +#define FOR_EACH_ROLE_END(role) \
62009 + role = role->prev; \
62010 + }
62011 +
62012 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62013 + subj = NULL; \
62014 + iter = 0; \
62015 + while (iter < role->subj_hash_size) { \
62016 + if (subj == NULL) \
62017 + subj = role->subj_hash[iter]; \
62018 + if (subj == NULL) { \
62019 + iter++; \
62020 + continue; \
62021 + }
62022 +
62023 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62024 + subj = subj->next; \
62025 + if (subj == NULL) \
62026 + iter++; \
62027 + }
62028 +
62029 +
62030 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62031 + subj = role->hash->first; \
62032 + while (subj != NULL) {
62033 +
62034 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62035 + subj = subj->next; \
62036 + }
62037 +
62038 +#endif
62039 +
62040 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62041 new file mode 100644
62042 index 0000000..323ecf2
62043 --- /dev/null
62044 +++ b/include/linux/gralloc.h
62045 @@ -0,0 +1,9 @@
62046 +#ifndef __GRALLOC_H
62047 +#define __GRALLOC_H
62048 +
62049 +void acl_free_all(void);
62050 +int acl_alloc_stack_init(unsigned long size);
62051 +void *acl_alloc(unsigned long len);
62052 +void *acl_alloc_num(unsigned long num, unsigned long len);
62053 +
62054 +#endif
62055 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62056 new file mode 100644
62057 index 0000000..b30e9bc
62058 --- /dev/null
62059 +++ b/include/linux/grdefs.h
62060 @@ -0,0 +1,140 @@
62061 +#ifndef GRDEFS_H
62062 +#define GRDEFS_H
62063 +
62064 +/* Begin grsecurity status declarations */
62065 +
62066 +enum {
62067 + GR_READY = 0x01,
62068 + GR_STATUS_INIT = 0x00 // disabled state
62069 +};
62070 +
62071 +/* Begin ACL declarations */
62072 +
62073 +/* Role flags */
62074 +
62075 +enum {
62076 + GR_ROLE_USER = 0x0001,
62077 + GR_ROLE_GROUP = 0x0002,
62078 + GR_ROLE_DEFAULT = 0x0004,
62079 + GR_ROLE_SPECIAL = 0x0008,
62080 + GR_ROLE_AUTH = 0x0010,
62081 + GR_ROLE_NOPW = 0x0020,
62082 + GR_ROLE_GOD = 0x0040,
62083 + GR_ROLE_LEARN = 0x0080,
62084 + GR_ROLE_TPE = 0x0100,
62085 + GR_ROLE_DOMAIN = 0x0200,
62086 + GR_ROLE_PAM = 0x0400,
62087 + GR_ROLE_PERSIST = 0x0800
62088 +};
62089 +
62090 +/* ACL Subject and Object mode flags */
62091 +enum {
62092 + GR_DELETED = 0x80000000
62093 +};
62094 +
62095 +/* ACL Object-only mode flags */
62096 +enum {
62097 + GR_READ = 0x00000001,
62098 + GR_APPEND = 0x00000002,
62099 + GR_WRITE = 0x00000004,
62100 + GR_EXEC = 0x00000008,
62101 + GR_FIND = 0x00000010,
62102 + GR_INHERIT = 0x00000020,
62103 + GR_SETID = 0x00000040,
62104 + GR_CREATE = 0x00000080,
62105 + GR_DELETE = 0x00000100,
62106 + GR_LINK = 0x00000200,
62107 + GR_AUDIT_READ = 0x00000400,
62108 + GR_AUDIT_APPEND = 0x00000800,
62109 + GR_AUDIT_WRITE = 0x00001000,
62110 + GR_AUDIT_EXEC = 0x00002000,
62111 + GR_AUDIT_FIND = 0x00004000,
62112 + GR_AUDIT_INHERIT= 0x00008000,
62113 + GR_AUDIT_SETID = 0x00010000,
62114 + GR_AUDIT_CREATE = 0x00020000,
62115 + GR_AUDIT_DELETE = 0x00040000,
62116 + GR_AUDIT_LINK = 0x00080000,
62117 + GR_PTRACERD = 0x00100000,
62118 + GR_NOPTRACE = 0x00200000,
62119 + GR_SUPPRESS = 0x00400000,
62120 + GR_NOLEARN = 0x00800000,
62121 + GR_INIT_TRANSFER= 0x01000000
62122 +};
62123 +
62124 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62125 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62126 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62127 +
62128 +/* ACL subject-only mode flags */
62129 +enum {
62130 + GR_KILL = 0x00000001,
62131 + GR_VIEW = 0x00000002,
62132 + GR_PROTECTED = 0x00000004,
62133 + GR_LEARN = 0x00000008,
62134 + GR_OVERRIDE = 0x00000010,
62135 + /* just a placeholder, this mode is only used in userspace */
62136 + GR_DUMMY = 0x00000020,
62137 + GR_PROTSHM = 0x00000040,
62138 + GR_KILLPROC = 0x00000080,
62139 + GR_KILLIPPROC = 0x00000100,
62140 + /* just a placeholder, this mode is only used in userspace */
62141 + GR_NOTROJAN = 0x00000200,
62142 + GR_PROTPROCFD = 0x00000400,
62143 + GR_PROCACCT = 0x00000800,
62144 + GR_RELAXPTRACE = 0x00001000,
62145 + GR_NESTED = 0x00002000,
62146 + GR_INHERITLEARN = 0x00004000,
62147 + GR_PROCFIND = 0x00008000,
62148 + GR_POVERRIDE = 0x00010000,
62149 + GR_KERNELAUTH = 0x00020000,
62150 + GR_ATSECURE = 0x00040000,
62151 + GR_SHMEXEC = 0x00080000
62152 +};
62153 +
62154 +enum {
62155 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62156 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62157 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62158 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62159 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62160 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62161 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62162 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62163 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62164 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62165 +};
62166 +
62167 +enum {
62168 + GR_ID_USER = 0x01,
62169 + GR_ID_GROUP = 0x02,
62170 +};
62171 +
62172 +enum {
62173 + GR_ID_ALLOW = 0x01,
62174 + GR_ID_DENY = 0x02,
62175 +};
62176 +
62177 +#define GR_CRASH_RES 31
62178 +#define GR_UIDTABLE_MAX 500
62179 +
62180 +/* begin resource learning section */
62181 +enum {
62182 + GR_RLIM_CPU_BUMP = 60,
62183 + GR_RLIM_FSIZE_BUMP = 50000,
62184 + GR_RLIM_DATA_BUMP = 10000,
62185 + GR_RLIM_STACK_BUMP = 1000,
62186 + GR_RLIM_CORE_BUMP = 10000,
62187 + GR_RLIM_RSS_BUMP = 500000,
62188 + GR_RLIM_NPROC_BUMP = 1,
62189 + GR_RLIM_NOFILE_BUMP = 5,
62190 + GR_RLIM_MEMLOCK_BUMP = 50000,
62191 + GR_RLIM_AS_BUMP = 500000,
62192 + GR_RLIM_LOCKS_BUMP = 2,
62193 + GR_RLIM_SIGPENDING_BUMP = 5,
62194 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62195 + GR_RLIM_NICE_BUMP = 1,
62196 + GR_RLIM_RTPRIO_BUMP = 1,
62197 + GR_RLIM_RTTIME_BUMP = 1000000
62198 +};
62199 +
62200 +#endif
62201 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62202 new file mode 100644
62203 index 0000000..c9292f7
62204 --- /dev/null
62205 +++ b/include/linux/grinternal.h
62206 @@ -0,0 +1,223 @@
62207 +#ifndef __GRINTERNAL_H
62208 +#define __GRINTERNAL_H
62209 +
62210 +#ifdef CONFIG_GRKERNSEC
62211 +
62212 +#include <linux/fs.h>
62213 +#include <linux/mnt_namespace.h>
62214 +#include <linux/nsproxy.h>
62215 +#include <linux/gracl.h>
62216 +#include <linux/grdefs.h>
62217 +#include <linux/grmsg.h>
62218 +
62219 +void gr_add_learn_entry(const char *fmt, ...)
62220 + __attribute__ ((format (printf, 1, 2)));
62221 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62222 + const struct vfsmount *mnt);
62223 +__u32 gr_check_create(const struct dentry *new_dentry,
62224 + const struct dentry *parent,
62225 + const struct vfsmount *mnt, const __u32 mode);
62226 +int gr_check_protected_task(const struct task_struct *task);
62227 +__u32 to_gr_audit(const __u32 reqmode);
62228 +int gr_set_acls(const int type);
62229 +int gr_apply_subject_to_task(struct task_struct *task);
62230 +int gr_acl_is_enabled(void);
62231 +char gr_roletype_to_char(void);
62232 +
62233 +void gr_handle_alertkill(struct task_struct *task);
62234 +char *gr_to_filename(const struct dentry *dentry,
62235 + const struct vfsmount *mnt);
62236 +char *gr_to_filename1(const struct dentry *dentry,
62237 + const struct vfsmount *mnt);
62238 +char *gr_to_filename2(const struct dentry *dentry,
62239 + const struct vfsmount *mnt);
62240 +char *gr_to_filename3(const struct dentry *dentry,
62241 + const struct vfsmount *mnt);
62242 +
62243 +extern int grsec_enable_ptrace_readexec;
62244 +extern int grsec_enable_harden_ptrace;
62245 +extern int grsec_enable_link;
62246 +extern int grsec_enable_fifo;
62247 +extern int grsec_enable_execve;
62248 +extern int grsec_enable_shm;
62249 +extern int grsec_enable_execlog;
62250 +extern int grsec_enable_signal;
62251 +extern int grsec_enable_audit_ptrace;
62252 +extern int grsec_enable_forkfail;
62253 +extern int grsec_enable_time;
62254 +extern int grsec_enable_rofs;
62255 +extern int grsec_enable_chroot_shmat;
62256 +extern int grsec_enable_chroot_mount;
62257 +extern int grsec_enable_chroot_double;
62258 +extern int grsec_enable_chroot_pivot;
62259 +extern int grsec_enable_chroot_chdir;
62260 +extern int grsec_enable_chroot_chmod;
62261 +extern int grsec_enable_chroot_mknod;
62262 +extern int grsec_enable_chroot_fchdir;
62263 +extern int grsec_enable_chroot_nice;
62264 +extern int grsec_enable_chroot_execlog;
62265 +extern int grsec_enable_chroot_caps;
62266 +extern int grsec_enable_chroot_sysctl;
62267 +extern int grsec_enable_chroot_unix;
62268 +extern int grsec_enable_symlinkown;
62269 +extern int grsec_symlinkown_gid;
62270 +extern int grsec_enable_tpe;
62271 +extern int grsec_tpe_gid;
62272 +extern int grsec_enable_tpe_all;
62273 +extern int grsec_enable_tpe_invert;
62274 +extern int grsec_enable_socket_all;
62275 +extern int grsec_socket_all_gid;
62276 +extern int grsec_enable_socket_client;
62277 +extern int grsec_socket_client_gid;
62278 +extern int grsec_enable_socket_server;
62279 +extern int grsec_socket_server_gid;
62280 +extern int grsec_audit_gid;
62281 +extern int grsec_enable_group;
62282 +extern int grsec_enable_audit_textrel;
62283 +extern int grsec_enable_log_rwxmaps;
62284 +extern int grsec_enable_mount;
62285 +extern int grsec_enable_chdir;
62286 +extern int grsec_resource_logging;
62287 +extern int grsec_enable_blackhole;
62288 +extern int grsec_lastack_retries;
62289 +extern int grsec_enable_brute;
62290 +extern int grsec_lock;
62291 +
62292 +extern spinlock_t grsec_alert_lock;
62293 +extern unsigned long grsec_alert_wtime;
62294 +extern unsigned long grsec_alert_fyet;
62295 +
62296 +extern spinlock_t grsec_audit_lock;
62297 +
62298 +extern rwlock_t grsec_exec_file_lock;
62299 +
62300 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62301 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62302 + (tsk)->exec_file->f_vfsmnt) : "/")
62303 +
62304 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62305 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62306 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62307 +
62308 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62309 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62310 + (tsk)->exec_file->f_vfsmnt) : "/")
62311 +
62312 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62313 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62314 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62315 +
62316 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62317 +
62318 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62319 +
62320 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62321 + (task)->pid, (cred)->uid, \
62322 + (cred)->euid, (cred)->gid, (cred)->egid, \
62323 + gr_parent_task_fullpath(task), \
62324 + (task)->real_parent->comm, (task)->real_parent->pid, \
62325 + (pcred)->uid, (pcred)->euid, \
62326 + (pcred)->gid, (pcred)->egid
62327 +
62328 +#define GR_CHROOT_CAPS {{ \
62329 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62330 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62331 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62332 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62333 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62334 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62335 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62336 +
62337 +#define security_learn(normal_msg,args...) \
62338 +({ \
62339 + read_lock(&grsec_exec_file_lock); \
62340 + gr_add_learn_entry(normal_msg "\n", ## args); \
62341 + read_unlock(&grsec_exec_file_lock); \
62342 +})
62343 +
62344 +enum {
62345 + GR_DO_AUDIT,
62346 + GR_DONT_AUDIT,
62347 + /* used for non-audit messages that we shouldn't kill the task on */
62348 + GR_DONT_AUDIT_GOOD
62349 +};
62350 +
62351 +enum {
62352 + GR_TTYSNIFF,
62353 + GR_RBAC,
62354 + GR_RBAC_STR,
62355 + GR_STR_RBAC,
62356 + GR_RBAC_MODE2,
62357 + GR_RBAC_MODE3,
62358 + GR_FILENAME,
62359 + GR_SYSCTL_HIDDEN,
62360 + GR_NOARGS,
62361 + GR_ONE_INT,
62362 + GR_ONE_INT_TWO_STR,
62363 + GR_ONE_STR,
62364 + GR_STR_INT,
62365 + GR_TWO_STR_INT,
62366 + GR_TWO_INT,
62367 + GR_TWO_U64,
62368 + GR_THREE_INT,
62369 + GR_FIVE_INT_TWO_STR,
62370 + GR_TWO_STR,
62371 + GR_THREE_STR,
62372 + GR_FOUR_STR,
62373 + GR_STR_FILENAME,
62374 + GR_FILENAME_STR,
62375 + GR_FILENAME_TWO_INT,
62376 + GR_FILENAME_TWO_INT_STR,
62377 + GR_TEXTREL,
62378 + GR_PTRACE,
62379 + GR_RESOURCE,
62380 + GR_CAP,
62381 + GR_SIG,
62382 + GR_SIG2,
62383 + GR_CRASH1,
62384 + GR_CRASH2,
62385 + GR_PSACCT,
62386 + GR_RWXMAP
62387 +};
62388 +
62389 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62390 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62391 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62392 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62393 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62394 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62395 +#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)
62396 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62397 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62398 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62399 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62400 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62401 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62402 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62403 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62404 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62405 +#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)
62406 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62407 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62408 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62409 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62410 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62411 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62412 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62413 +#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)
62414 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62415 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62416 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62417 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62418 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62419 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62420 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62421 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62422 +#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)
62423 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62424 +
62425 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62426 +
62427 +#endif
62428 +
62429 +#endif
62430 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62431 new file mode 100644
62432 index 0000000..54f4e85
62433 --- /dev/null
62434 +++ b/include/linux/grmsg.h
62435 @@ -0,0 +1,110 @@
62436 +#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"
62437 +#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"
62438 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62439 +#define GR_STOPMOD_MSG "denied modification of module state by "
62440 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62441 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62442 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62443 +#define GR_IOPL_MSG "denied use of iopl() by "
62444 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62445 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62446 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62447 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62448 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62449 +#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"
62450 +#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"
62451 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62452 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62453 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62454 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62455 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62456 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62457 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62458 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62459 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62460 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62461 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62462 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62463 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62464 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62465 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62466 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62467 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62468 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62469 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62470 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62471 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62472 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62473 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62474 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62475 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62476 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62477 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62478 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62479 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62480 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62481 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62482 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62483 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62484 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62485 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62486 +#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"
62487 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62488 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62489 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62490 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62491 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62492 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62493 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62494 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62495 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62496 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62497 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62498 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62499 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62500 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62501 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62502 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62503 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62504 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62505 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62506 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62507 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62508 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62509 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62510 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62511 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62512 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62513 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62514 +#define GR_TIME_MSG "time set by "
62515 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62516 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62517 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62518 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62519 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62520 +#define GR_BIND_MSG "denied bind() by "
62521 +#define GR_CONNECT_MSG "denied connect() by "
62522 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62523 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62524 +#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"
62525 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62526 +#define GR_CAP_ACL_MSG "use of %s denied for "
62527 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62528 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62529 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62530 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62531 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62532 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62533 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62534 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62535 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62536 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62537 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62538 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62539 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62540 +#define GR_VM86_MSG "denied use of vm86 by "
62541 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62542 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62543 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62544 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62545 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62546 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62547 new file mode 100644
62548 index 0000000..f9b9a21
62549 --- /dev/null
62550 +++ b/include/linux/grsecurity.h
62551 @@ -0,0 +1,238 @@
62552 +#ifndef GR_SECURITY_H
62553 +#define GR_SECURITY_H
62554 +#include <linux/fs.h>
62555 +#include <linux/fs_struct.h>
62556 +#include <linux/binfmts.h>
62557 +#include <linux/gracl.h>
62558 +
62559 +/* notify of brain-dead configs */
62560 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62561 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62562 +#endif
62563 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62564 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62565 +#endif
62566 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62567 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62568 +#endif
62569 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62570 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62571 +#endif
62572 +
62573 +#include <linux/compat.h>
62574 +
62575 +struct user_arg_ptr {
62576 +#ifdef CONFIG_COMPAT
62577 + bool is_compat;
62578 +#endif
62579 + union {
62580 + const char __user *const __user *native;
62581 +#ifdef CONFIG_COMPAT
62582 + compat_uptr_t __user *compat;
62583 +#endif
62584 + } ptr;
62585 +};
62586 +
62587 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62588 +void gr_handle_brute_check(void);
62589 +void gr_handle_kernel_exploit(void);
62590 +int gr_process_user_ban(void);
62591 +
62592 +char gr_roletype_to_char(void);
62593 +
62594 +int gr_acl_enable_at_secure(void);
62595 +
62596 +int gr_check_user_change(int real, int effective, int fs);
62597 +int gr_check_group_change(int real, int effective, int fs);
62598 +
62599 +void gr_del_task_from_ip_table(struct task_struct *p);
62600 +
62601 +int gr_pid_is_chrooted(struct task_struct *p);
62602 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62603 +int gr_handle_chroot_nice(void);
62604 +int gr_handle_chroot_sysctl(const int op);
62605 +int gr_handle_chroot_setpriority(struct task_struct *p,
62606 + const int niceval);
62607 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62608 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62609 + const struct vfsmount *mnt);
62610 +void gr_handle_chroot_chdir(struct path *path);
62611 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62612 + const struct vfsmount *mnt, const int mode);
62613 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62614 + const struct vfsmount *mnt, const int mode);
62615 +int gr_handle_chroot_mount(const struct dentry *dentry,
62616 + const struct vfsmount *mnt,
62617 + const char *dev_name);
62618 +int gr_handle_chroot_pivot(void);
62619 +int gr_handle_chroot_unix(const pid_t pid);
62620 +
62621 +int gr_handle_rawio(const struct inode *inode);
62622 +
62623 +void gr_handle_ioperm(void);
62624 +void gr_handle_iopl(void);
62625 +
62626 +umode_t gr_acl_umask(void);
62627 +
62628 +int gr_tpe_allow(const struct file *file);
62629 +
62630 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62631 +void gr_clear_chroot_entries(struct task_struct *task);
62632 +
62633 +void gr_log_forkfail(const int retval);
62634 +void gr_log_timechange(void);
62635 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62636 +void gr_log_chdir(const struct dentry *dentry,
62637 + const struct vfsmount *mnt);
62638 +void gr_log_chroot_exec(const struct dentry *dentry,
62639 + const struct vfsmount *mnt);
62640 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62641 +void gr_log_remount(const char *devname, const int retval);
62642 +void gr_log_unmount(const char *devname, const int retval);
62643 +void gr_log_mount(const char *from, const char *to, const int retval);
62644 +void gr_log_textrel(struct vm_area_struct *vma);
62645 +void gr_log_rwxmmap(struct file *file);
62646 +void gr_log_rwxmprotect(struct file *file);
62647 +
62648 +int gr_handle_follow_link(const struct inode *parent,
62649 + const struct inode *inode,
62650 + const struct dentry *dentry,
62651 + const struct vfsmount *mnt);
62652 +int gr_handle_fifo(const struct dentry *dentry,
62653 + const struct vfsmount *mnt,
62654 + const struct dentry *dir, const int flag,
62655 + const int acc_mode);
62656 +int gr_handle_hardlink(const struct dentry *dentry,
62657 + const struct vfsmount *mnt,
62658 + struct inode *inode,
62659 + const int mode, const char *to);
62660 +
62661 +int gr_is_capable(const int cap);
62662 +int gr_is_capable_nolog(const int cap);
62663 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62664 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62665 +
62666 +void gr_learn_resource(const struct task_struct *task, const int limit,
62667 + const unsigned long wanted, const int gt);
62668 +void gr_copy_label(struct task_struct *tsk);
62669 +void gr_handle_crash(struct task_struct *task, const int sig);
62670 +int gr_handle_signal(const struct task_struct *p, const int sig);
62671 +int gr_check_crash_uid(const uid_t uid);
62672 +int gr_check_protected_task(const struct task_struct *task);
62673 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62674 +int gr_acl_handle_mmap(const struct file *file,
62675 + const unsigned long prot);
62676 +int gr_acl_handle_mprotect(const struct file *file,
62677 + const unsigned long prot);
62678 +int gr_check_hidden_task(const struct task_struct *tsk);
62679 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62680 + const struct vfsmount *mnt);
62681 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62682 + const struct vfsmount *mnt);
62683 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62684 + const struct vfsmount *mnt, const int fmode);
62685 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62686 + const struct vfsmount *mnt, umode_t *mode);
62687 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62688 + const struct vfsmount *mnt);
62689 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62690 + const struct vfsmount *mnt);
62691 +int gr_handle_ptrace(struct task_struct *task, const long request);
62692 +int gr_handle_proc_ptrace(struct task_struct *task);
62693 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62694 + const struct vfsmount *mnt);
62695 +int gr_check_crash_exec(const struct file *filp);
62696 +int gr_acl_is_enabled(void);
62697 +void gr_set_kernel_label(struct task_struct *task);
62698 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62699 + const gid_t gid);
62700 +int gr_set_proc_label(const struct dentry *dentry,
62701 + const struct vfsmount *mnt,
62702 + const int unsafe_flags);
62703 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62704 + const struct vfsmount *mnt);
62705 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62706 + const struct vfsmount *mnt, int acc_mode);
62707 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62708 + const struct dentry *p_dentry,
62709 + const struct vfsmount *p_mnt,
62710 + int open_flags, int acc_mode, const int imode);
62711 +void gr_handle_create(const struct dentry *dentry,
62712 + const struct vfsmount *mnt);
62713 +void gr_handle_proc_create(const struct dentry *dentry,
62714 + const struct inode *inode);
62715 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62716 + const struct dentry *parent_dentry,
62717 + const struct vfsmount *parent_mnt,
62718 + const int mode);
62719 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62720 + const struct dentry *parent_dentry,
62721 + const struct vfsmount *parent_mnt);
62722 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62723 + const struct vfsmount *mnt);
62724 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62725 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62726 + const struct vfsmount *mnt);
62727 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62728 + const struct dentry *parent_dentry,
62729 + const struct vfsmount *parent_mnt,
62730 + const char *from);
62731 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62732 + const struct dentry *parent_dentry,
62733 + const struct vfsmount *parent_mnt,
62734 + const struct dentry *old_dentry,
62735 + const struct vfsmount *old_mnt, const char *to);
62736 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62737 +int gr_acl_handle_rename(struct dentry *new_dentry,
62738 + struct dentry *parent_dentry,
62739 + const struct vfsmount *parent_mnt,
62740 + struct dentry *old_dentry,
62741 + struct inode *old_parent_inode,
62742 + struct vfsmount *old_mnt, const char *newname);
62743 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62744 + struct dentry *old_dentry,
62745 + struct dentry *new_dentry,
62746 + struct vfsmount *mnt, const __u8 replace);
62747 +__u32 gr_check_link(const struct dentry *new_dentry,
62748 + const struct dentry *parent_dentry,
62749 + const struct vfsmount *parent_mnt,
62750 + const struct dentry *old_dentry,
62751 + const struct vfsmount *old_mnt);
62752 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62753 + const unsigned int namelen, const ino_t ino);
62754 +
62755 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62756 + const struct vfsmount *mnt);
62757 +void gr_acl_handle_exit(void);
62758 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62759 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62760 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62761 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62762 +void gr_audit_ptrace(struct task_struct *task);
62763 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62764 +
62765 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62766 +
62767 +#ifdef CONFIG_GRKERNSEC
62768 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62769 +void gr_handle_vm86(void);
62770 +void gr_handle_mem_readwrite(u64 from, u64 to);
62771 +
62772 +void gr_log_badprocpid(const char *entry);
62773 +
62774 +extern int grsec_enable_dmesg;
62775 +extern int grsec_disable_privio;
62776 +
62777 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62778 +extern int grsec_proc_gid;
62779 +#endif
62780 +
62781 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62782 +extern int grsec_enable_chroot_findtask;
62783 +#endif
62784 +#ifdef CONFIG_GRKERNSEC_SETXID
62785 +extern int grsec_enable_setxid;
62786 +#endif
62787 +#endif
62788 +
62789 +#endif
62790 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62791 new file mode 100644
62792 index 0000000..e7ffaaf
62793 --- /dev/null
62794 +++ b/include/linux/grsock.h
62795 @@ -0,0 +1,19 @@
62796 +#ifndef __GRSOCK_H
62797 +#define __GRSOCK_H
62798 +
62799 +extern void gr_attach_curr_ip(const struct sock *sk);
62800 +extern int gr_handle_sock_all(const int family, const int type,
62801 + const int protocol);
62802 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62803 +extern int gr_handle_sock_server_other(const struct sock *sck);
62804 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62805 +extern int gr_search_connect(struct socket * sock,
62806 + struct sockaddr_in * addr);
62807 +extern int gr_search_bind(struct socket * sock,
62808 + struct sockaddr_in * addr);
62809 +extern int gr_search_listen(struct socket * sock);
62810 +extern int gr_search_accept(struct socket * sock);
62811 +extern int gr_search_socket(const int domain, const int type,
62812 + const int protocol);
62813 +
62814 +#endif
62815 diff --git a/include/linux/hid.h b/include/linux/hid.h
62816 index 42970de..5db3c92 100644
62817 --- a/include/linux/hid.h
62818 +++ b/include/linux/hid.h
62819 @@ -705,7 +705,7 @@ struct hid_ll_driver {
62820 unsigned int code, int value);
62821
62822 int (*parse)(struct hid_device *hdev);
62823 -};
62824 +} __no_const;
62825
62826 #define PM_HINT_FULLON 1<<5
62827 #define PM_HINT_NORMAL 1<<1
62828 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62829 index ef788b5..ac41b7b 100644
62830 --- a/include/linux/highmem.h
62831 +++ b/include/linux/highmem.h
62832 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62833 kunmap_atomic(kaddr);
62834 }
62835
62836 +static inline void sanitize_highpage(struct page *page)
62837 +{
62838 + void *kaddr;
62839 + unsigned long flags;
62840 +
62841 + local_irq_save(flags);
62842 + kaddr = kmap_atomic(page);
62843 + clear_page(kaddr);
62844 + kunmap_atomic(kaddr);
62845 + local_irq_restore(flags);
62846 +}
62847 +
62848 static inline void zero_user_segments(struct page *page,
62849 unsigned start1, unsigned end1,
62850 unsigned start2, unsigned end2)
62851 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62852 index 5970266..1c48c3b 100644
62853 --- a/include/linux/i2c.h
62854 +++ b/include/linux/i2c.h
62855 @@ -369,6 +369,7 @@ struct i2c_algorithm {
62856 /* To determine what the adapter supports */
62857 u32 (*functionality) (struct i2c_adapter *);
62858 };
62859 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62860
62861 /*
62862 * i2c_adapter is the structure used to identify a physical i2c bus along
62863 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62864 index d23c3c2..eb63c81 100644
62865 --- a/include/linux/i2o.h
62866 +++ b/include/linux/i2o.h
62867 @@ -565,7 +565,7 @@ struct i2o_controller {
62868 struct i2o_device *exec; /* Executive */
62869 #if BITS_PER_LONG == 64
62870 spinlock_t context_list_lock; /* lock for context_list */
62871 - atomic_t context_list_counter; /* needed for unique contexts */
62872 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62873 struct list_head context_list; /* list of context id's
62874 and pointers */
62875 #endif
62876 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62877 index aa2e167..84024ce 100644
62878 --- a/include/linux/if_team.h
62879 +++ b/include/linux/if_team.h
62880 @@ -109,6 +109,7 @@ struct team_mode_ops {
62881 void (*port_enabled)(struct team *team, struct team_port *port);
62882 void (*port_disabled)(struct team *team, struct team_port *port);
62883 };
62884 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62885
62886 enum team_option_type {
62887 TEAM_OPTION_TYPE_U32,
62888 @@ -181,7 +182,7 @@ struct team {
62889 struct list_head option_inst_list; /* list of option instances */
62890
62891 const struct team_mode *mode;
62892 - struct team_mode_ops ops;
62893 + team_mode_ops_no_const ops;
62894 long mode_priv[TEAM_MODE_PRIV_LONGS];
62895 };
62896
62897 diff --git a/include/linux/init.h b/include/linux/init.h
62898 index 5e664f6..0a1225c 100644
62899 --- a/include/linux/init.h
62900 +++ b/include/linux/init.h
62901 @@ -39,9 +39,15 @@
62902 * Also note, that this data cannot be "const".
62903 */
62904
62905 +#ifdef MODULE
62906 +#define add_latent_entropy
62907 +#else
62908 +#define add_latent_entropy __latent_entropy
62909 +#endif
62910 +
62911 /* These are for everybody (although not all archs will actually
62912 discard it in modules) */
62913 -#define __init __section(.init.text) __cold notrace
62914 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62915 #define __initdata __section(.init.data)
62916 #define __initconst __section(.init.rodata)
62917 #define __exitdata __section(.exit.data)
62918 @@ -83,7 +89,7 @@
62919 #define __exit __section(.exit.text) __exitused __cold notrace
62920
62921 /* Used for HOTPLUG */
62922 -#define __devinit __section(.devinit.text) __cold notrace
62923 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62924 #define __devinitdata __section(.devinit.data)
62925 #define __devinitconst __section(.devinit.rodata)
62926 #define __devexit __section(.devexit.text) __exitused __cold notrace
62927 @@ -91,7 +97,7 @@
62928 #define __devexitconst __section(.devexit.rodata)
62929
62930 /* Used for HOTPLUG_CPU */
62931 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62932 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62933 #define __cpuinitdata __section(.cpuinit.data)
62934 #define __cpuinitconst __section(.cpuinit.rodata)
62935 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62936 @@ -99,7 +105,7 @@
62937 #define __cpuexitconst __section(.cpuexit.rodata)
62938
62939 /* Used for MEMORY_HOTPLUG */
62940 -#define __meminit __section(.meminit.text) __cold notrace
62941 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62942 #define __meminitdata __section(.meminit.data)
62943 #define __meminitconst __section(.meminit.rodata)
62944 #define __memexit __section(.memexit.text) __exitused __cold notrace
62945 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62946 index 89f1cb1..7986c0f 100644
62947 --- a/include/linux/init_task.h
62948 +++ b/include/linux/init_task.h
62949 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
62950
62951 #define INIT_TASK_COMM "swapper"
62952
62953 +#ifdef CONFIG_X86
62954 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62955 +#else
62956 +#define INIT_TASK_THREAD_INFO
62957 +#endif
62958 +
62959 /*
62960 * INIT_TASK is used to set up the first task table, touch at
62961 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62962 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
62963 RCU_POINTER_INITIALIZER(cred, &init_cred), \
62964 .comm = INIT_TASK_COMM, \
62965 .thread = INIT_THREAD, \
62966 + INIT_TASK_THREAD_INFO \
62967 .fs = &init_fs, \
62968 .files = &init_files, \
62969 .signal = &init_signals, \
62970 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62971 index 78e2ada..745564d 100644
62972 --- a/include/linux/intel-iommu.h
62973 +++ b/include/linux/intel-iommu.h
62974 @@ -296,7 +296,7 @@ struct iommu_flush {
62975 u8 fm, u64 type);
62976 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62977 unsigned int size_order, u64 type);
62978 -};
62979 +} __no_const;
62980
62981 enum {
62982 SR_DMAR_FECTL_REG,
62983 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62984 index c5f856a..d29c117 100644
62985 --- a/include/linux/interrupt.h
62986 +++ b/include/linux/interrupt.h
62987 @@ -433,7 +433,7 @@ enum
62988 /* map softirq index to softirq name. update 'softirq_to_name' in
62989 * kernel/softirq.c when adding a new softirq.
62990 */
62991 -extern char *softirq_to_name[NR_SOFTIRQS];
62992 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62993
62994 /* softirq mask and active fields moved to irq_cpustat_t in
62995 * asm/hardirq.h to get better cache usage. KAO
62996 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62997
62998 struct softirq_action
62999 {
63000 - void (*action)(struct softirq_action *);
63001 + void (*action)(void);
63002 };
63003
63004 asmlinkage void do_softirq(void);
63005 asmlinkage void __do_softirq(void);
63006 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63007 +extern void open_softirq(int nr, void (*action)(void));
63008 extern void softirq_init(void);
63009 extern void __raise_softirq_irqoff(unsigned int nr);
63010
63011 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63012 index 6883e19..06992b1 100644
63013 --- a/include/linux/kallsyms.h
63014 +++ b/include/linux/kallsyms.h
63015 @@ -15,7 +15,8 @@
63016
63017 struct module;
63018
63019 -#ifdef CONFIG_KALLSYMS
63020 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63021 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63022 /* Lookup the address for a symbol. Returns 0 if not found. */
63023 unsigned long kallsyms_lookup_name(const char *name);
63024
63025 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63026 /* Stupid that this does nothing, but I didn't create this mess. */
63027 #define __print_symbol(fmt, addr)
63028 #endif /*CONFIG_KALLSYMS*/
63029 +#else /* when included by kallsyms.c, vsnprintf.c, or
63030 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63031 +extern void __print_symbol(const char *fmt, unsigned long address);
63032 +extern int sprint_backtrace(char *buffer, unsigned long address);
63033 +extern int sprint_symbol(char *buffer, unsigned long address);
63034 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63035 +const char *kallsyms_lookup(unsigned long addr,
63036 + unsigned long *symbolsize,
63037 + unsigned long *offset,
63038 + char **modname, char *namebuf);
63039 +#endif
63040
63041 /* This macro allows us to keep printk typechecking */
63042 static __printf(1, 2)
63043 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63044 index c4d2fc1..5df9c19 100644
63045 --- a/include/linux/kgdb.h
63046 +++ b/include/linux/kgdb.h
63047 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63048 extern int kgdb_io_module_registered;
63049
63050 extern atomic_t kgdb_setting_breakpoint;
63051 -extern atomic_t kgdb_cpu_doing_single_step;
63052 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63053
63054 extern struct task_struct *kgdb_usethread;
63055 extern struct task_struct *kgdb_contthread;
63056 @@ -252,7 +252,7 @@ struct kgdb_arch {
63057 void (*disable_hw_break)(struct pt_regs *regs);
63058 void (*remove_all_hw_break)(void);
63059 void (*correct_hw_break)(void);
63060 -};
63061 +} __do_const;
63062
63063 /**
63064 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63065 @@ -277,7 +277,7 @@ struct kgdb_io {
63066 void (*pre_exception) (void);
63067 void (*post_exception) (void);
63068 int is_console;
63069 -};
63070 +} __do_const;
63071
63072 extern struct kgdb_arch arch_kgdb_ops;
63073
63074 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63075 index 5398d58..5883a34 100644
63076 --- a/include/linux/kmod.h
63077 +++ b/include/linux/kmod.h
63078 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63079 * usually useless though. */
63080 extern __printf(2, 3)
63081 int __request_module(bool wait, const char *name, ...);
63082 +extern __printf(3, 4)
63083 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63084 #define request_module(mod...) __request_module(true, mod)
63085 #define request_module_nowait(mod...) __request_module(false, mod)
63086 #define try_then_request_module(x, mod...) \
63087 diff --git a/include/linux/kref.h b/include/linux/kref.h
63088 index 65af688..0592677 100644
63089 --- a/include/linux/kref.h
63090 +++ b/include/linux/kref.h
63091 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63092 static inline int kref_sub(struct kref *kref, unsigned int count,
63093 void (*release)(struct kref *kref))
63094 {
63095 - WARN_ON(release == NULL);
63096 + BUG_ON(release == NULL);
63097
63098 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63099 release(kref);
63100 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63101 index b70b48b..0d7153b 100644
63102 --- a/include/linux/kvm_host.h
63103 +++ b/include/linux/kvm_host.h
63104 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63105 void vcpu_load(struct kvm_vcpu *vcpu);
63106 void vcpu_put(struct kvm_vcpu *vcpu);
63107
63108 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63109 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63110 struct module *module);
63111 void kvm_exit(void);
63112
63113 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63114 struct kvm_guest_debug *dbg);
63115 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63116
63117 -int kvm_arch_init(void *opaque);
63118 +int kvm_arch_init(const void *opaque);
63119 void kvm_arch_exit(void);
63120
63121 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63122 diff --git a/include/linux/libata.h b/include/linux/libata.h
63123 index 64f90e1..32b945b 100644
63124 --- a/include/linux/libata.h
63125 +++ b/include/linux/libata.h
63126 @@ -909,7 +909,7 @@ struct ata_port_operations {
63127 * fields must be pointers.
63128 */
63129 const struct ata_port_operations *inherits;
63130 -};
63131 +} __do_const;
63132
63133 struct ata_port_info {
63134 unsigned long flags;
63135 diff --git a/include/linux/memory.h b/include/linux/memory.h
63136 index ff9a9f8..c715deb 100644
63137 --- a/include/linux/memory.h
63138 +++ b/include/linux/memory.h
63139 @@ -143,7 +143,7 @@ struct memory_accessor {
63140 size_t count);
63141 ssize_t (*write)(struct memory_accessor *, const char *buf,
63142 off_t offset, size_t count);
63143 -};
63144 +} __no_const;
63145
63146 /*
63147 * Kernel text modification mutex, used for code patching. Users of this lock
63148 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63149 index 1318ca6..7521340 100644
63150 --- a/include/linux/mfd/abx500.h
63151 +++ b/include/linux/mfd/abx500.h
63152 @@ -452,6 +452,7 @@ struct abx500_ops {
63153 int (*event_registers_startup_state_get) (struct device *, u8 *);
63154 int (*startup_irq_enabled) (struct device *, unsigned int);
63155 };
63156 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63157
63158 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63159 void abx500_remove_ops(struct device *dev);
63160 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63161 index 9b07725..3d55001 100644
63162 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63163 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63164 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63165 int (*enable) (struct ux500_charger *, int, int, int);
63166 int (*kick_wd) (struct ux500_charger *);
63167 int (*update_curr) (struct ux500_charger *, int);
63168 -};
63169 +} __no_const;
63170
63171 /**
63172 * struct ux500_charger - power supply ux500 charger sub class
63173 diff --git a/include/linux/mm.h b/include/linux/mm.h
63174 index 311be90..5f1638c 100644
63175 --- a/include/linux/mm.h
63176 +++ b/include/linux/mm.h
63177 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63178
63179 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63180 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63181 +
63182 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63183 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63184 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63185 +#else
63186 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63187 +#endif
63188 +
63189 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63190 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63191
63192 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63193 int set_page_dirty_lock(struct page *page);
63194 int clear_page_dirty_for_io(struct page *page);
63195
63196 -/* Is the vma a continuation of the stack vma above it? */
63197 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63198 -{
63199 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63200 -}
63201 -
63202 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63203 - unsigned long addr)
63204 -{
63205 - return (vma->vm_flags & VM_GROWSDOWN) &&
63206 - (vma->vm_start == addr) &&
63207 - !vma_growsdown(vma->vm_prev, addr);
63208 -}
63209 -
63210 -/* Is the vma a continuation of the stack vma below it? */
63211 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63212 -{
63213 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63214 -}
63215 -
63216 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63217 - unsigned long addr)
63218 -{
63219 - return (vma->vm_flags & VM_GROWSUP) &&
63220 - (vma->vm_end == addr) &&
63221 - !vma_growsup(vma->vm_next, addr);
63222 -}
63223 -
63224 extern pid_t
63225 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63226
63227 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63228 }
63229 #endif
63230
63231 +#ifdef CONFIG_MMU
63232 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63233 +#else
63234 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63235 +{
63236 + return __pgprot(0);
63237 +}
63238 +#endif
63239 +
63240 int vma_wants_writenotify(struct vm_area_struct *vma);
63241
63242 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63243 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63244 {
63245 return 0;
63246 }
63247 +
63248 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63249 + unsigned long address)
63250 +{
63251 + return 0;
63252 +}
63253 #else
63254 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63255 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63256 #endif
63257
63258 #ifdef __PAGETABLE_PMD_FOLDED
63259 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63260 {
63261 return 0;
63262 }
63263 +
63264 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63265 + unsigned long address)
63266 +{
63267 + return 0;
63268 +}
63269 #else
63270 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63271 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63272 #endif
63273
63274 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63275 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63276 NULL: pud_offset(pgd, address);
63277 }
63278
63279 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63280 +{
63281 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63282 + NULL: pud_offset(pgd, address);
63283 +}
63284 +
63285 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63286 {
63287 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63288 NULL: pmd_offset(pud, address);
63289 }
63290 +
63291 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63292 +{
63293 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63294 + NULL: pmd_offset(pud, address);
63295 +}
63296 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63297
63298 #if USE_SPLIT_PTLOCKS
63299 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63300 unsigned long, unsigned long,
63301 unsigned long, unsigned long);
63302 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63303 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63304
63305 /* These take the mm semaphore themselves */
63306 extern unsigned long vm_brk(unsigned long, unsigned long);
63307 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63308 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63309 struct vm_area_struct **pprev);
63310
63311 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63312 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63313 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63314 +
63315 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63316 NULL if none. Assume start_addr < end_addr. */
63317 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63318 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63319 return vma;
63320 }
63321
63322 -#ifdef CONFIG_MMU
63323 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63324 -#else
63325 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63326 -{
63327 - return __pgprot(0);
63328 -}
63329 -#endif
63330 -
63331 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63332 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63333 unsigned long pfn, unsigned long size, pgprot_t);
63334 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63335 extern int sysctl_memory_failure_early_kill;
63336 extern int sysctl_memory_failure_recovery;
63337 extern void shake_page(struct page *p, int access);
63338 -extern atomic_long_t mce_bad_pages;
63339 +extern atomic_long_unchecked_t mce_bad_pages;
63340 extern int soft_offline_page(struct page *page, int flags);
63341
63342 extern void dump_page(struct page *page);
63343 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63344 static inline bool page_is_guard(struct page *page) { return false; }
63345 #endif /* CONFIG_DEBUG_PAGEALLOC */
63346
63347 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63348 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63349 +#else
63350 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63351 +#endif
63352 +
63353 #endif /* __KERNEL__ */
63354 #endif /* _LINUX_MM_H */
63355 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63356 index bf78672..debc693 100644
63357 --- a/include/linux/mm_types.h
63358 +++ b/include/linux/mm_types.h
63359 @@ -279,6 +279,8 @@ struct vm_area_struct {
63360 #ifdef CONFIG_NUMA
63361 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63362 #endif
63363 +
63364 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63365 };
63366
63367 struct core_thread {
63368 @@ -353,7 +355,7 @@ struct mm_struct {
63369 unsigned long def_flags;
63370 unsigned long nr_ptes; /* Page table pages */
63371 unsigned long start_code, end_code, start_data, end_data;
63372 - unsigned long start_brk, brk, start_stack;
63373 + unsigned long brk_gap, start_brk, brk, start_stack;
63374 unsigned long arg_start, arg_end, env_start, env_end;
63375
63376 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63377 @@ -405,6 +407,24 @@ struct mm_struct {
63378 struct cpumask cpumask_allocation;
63379 #endif
63380 struct uprobes_state uprobes_state;
63381 +
63382 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63383 + unsigned long pax_flags;
63384 +#endif
63385 +
63386 +#ifdef CONFIG_PAX_DLRESOLVE
63387 + unsigned long call_dl_resolve;
63388 +#endif
63389 +
63390 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63391 + unsigned long call_syscall;
63392 +#endif
63393 +
63394 +#ifdef CONFIG_PAX_ASLR
63395 + unsigned long delta_mmap; /* randomized offset */
63396 + unsigned long delta_stack; /* randomized offset */
63397 +#endif
63398 +
63399 };
63400
63401 static inline void mm_init_cpumask(struct mm_struct *mm)
63402 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63403 index 1d1b1e1..2a13c78 100644
63404 --- a/include/linux/mmu_notifier.h
63405 +++ b/include/linux/mmu_notifier.h
63406 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63407 */
63408 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63409 ({ \
63410 - pte_t __pte; \
63411 + pte_t ___pte; \
63412 struct vm_area_struct *___vma = __vma; \
63413 unsigned long ___address = __address; \
63414 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63415 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63416 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63417 - __pte; \
63418 + ___pte; \
63419 })
63420
63421 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63422 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63423 index 2daa54f..bfdf2f5 100644
63424 --- a/include/linux/mmzone.h
63425 +++ b/include/linux/mmzone.h
63426 @@ -414,7 +414,7 @@ struct zone {
63427 unsigned long flags; /* zone flags, see below */
63428
63429 /* Zone statistics */
63430 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63431 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63432
63433 /*
63434 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63435 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63436 index 6955045..ebdb7cd 100644
63437 --- a/include/linux/mod_devicetable.h
63438 +++ b/include/linux/mod_devicetable.h
63439 @@ -12,7 +12,7 @@
63440 typedef unsigned long kernel_ulong_t;
63441 #endif
63442
63443 -#define PCI_ANY_ID (~0)
63444 +#define PCI_ANY_ID ((__u16)~0)
63445
63446 struct pci_device_id {
63447 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63448 @@ -139,7 +139,7 @@ struct usb_device_id {
63449 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63450 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63451
63452 -#define HID_ANY_ID (~0)
63453 +#define HID_ANY_ID (~0U)
63454 #define HID_BUS_ANY 0xffff
63455 #define HID_GROUP_ANY 0x0000
63456
63457 diff --git a/include/linux/module.h b/include/linux/module.h
63458 index fbcafe2..e5d9587 100644
63459 --- a/include/linux/module.h
63460 +++ b/include/linux/module.h
63461 @@ -17,6 +17,7 @@
63462 #include <linux/moduleparam.h>
63463 #include <linux/tracepoint.h>
63464 #include <linux/export.h>
63465 +#include <linux/fs.h>
63466
63467 #include <linux/percpu.h>
63468 #include <asm/module.h>
63469 @@ -273,19 +274,16 @@ struct module
63470 int (*init)(void);
63471
63472 /* If this is non-NULL, vfree after init() returns */
63473 - void *module_init;
63474 + void *module_init_rx, *module_init_rw;
63475
63476 /* Here is the actual code + data, vfree'd on unload. */
63477 - void *module_core;
63478 + void *module_core_rx, *module_core_rw;
63479
63480 /* Here are the sizes of the init and core sections */
63481 - unsigned int init_size, core_size;
63482 + unsigned int init_size_rw, core_size_rw;
63483
63484 /* The size of the executable code in each section. */
63485 - unsigned int init_text_size, core_text_size;
63486 -
63487 - /* Size of RO sections of the module (text+rodata) */
63488 - unsigned int init_ro_size, core_ro_size;
63489 + unsigned int init_size_rx, core_size_rx;
63490
63491 /* Arch-specific module values */
63492 struct mod_arch_specific arch;
63493 @@ -341,6 +339,10 @@ struct module
63494 #ifdef CONFIG_EVENT_TRACING
63495 struct ftrace_event_call **trace_events;
63496 unsigned int num_trace_events;
63497 + struct file_operations trace_id;
63498 + struct file_operations trace_enable;
63499 + struct file_operations trace_format;
63500 + struct file_operations trace_filter;
63501 #endif
63502 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63503 unsigned int num_ftrace_callsites;
63504 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63505 bool is_module_percpu_address(unsigned long addr);
63506 bool is_module_text_address(unsigned long addr);
63507
63508 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63509 +{
63510 +
63511 +#ifdef CONFIG_PAX_KERNEXEC
63512 + if (ktla_ktva(addr) >= (unsigned long)start &&
63513 + ktla_ktva(addr) < (unsigned long)start + size)
63514 + return 1;
63515 +#endif
63516 +
63517 + return ((void *)addr >= start && (void *)addr < start + size);
63518 +}
63519 +
63520 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63521 +{
63522 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63523 +}
63524 +
63525 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63526 +{
63527 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63528 +}
63529 +
63530 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63531 +{
63532 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63533 +}
63534 +
63535 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63536 +{
63537 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63538 +}
63539 +
63540 static inline int within_module_core(unsigned long addr, struct module *mod)
63541 {
63542 - return (unsigned long)mod->module_core <= addr &&
63543 - addr < (unsigned long)mod->module_core + mod->core_size;
63544 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63545 }
63546
63547 static inline int within_module_init(unsigned long addr, struct module *mod)
63548 {
63549 - return (unsigned long)mod->module_init <= addr &&
63550 - addr < (unsigned long)mod->module_init + mod->init_size;
63551 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63552 }
63553
63554 /* Search for module by name: must hold module_mutex. */
63555 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63556 index b2be02e..72d2f78 100644
63557 --- a/include/linux/moduleloader.h
63558 +++ b/include/linux/moduleloader.h
63559 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63560
63561 /* Allocator used for allocating struct module, core sections and init
63562 sections. Returns NULL on failure. */
63563 -void *module_alloc(unsigned long size);
63564 +void *module_alloc(unsigned long size) __size_overflow(1);
63565 +
63566 +#ifdef CONFIG_PAX_KERNEXEC
63567 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63568 +#else
63569 +#define module_alloc_exec(x) module_alloc(x)
63570 +#endif
63571
63572 /* Free memory returned from module_alloc. */
63573 void module_free(struct module *mod, void *module_region);
63574
63575 +#ifdef CONFIG_PAX_KERNEXEC
63576 +void module_free_exec(struct module *mod, void *module_region);
63577 +#else
63578 +#define module_free_exec(x, y) module_free((x), (y))
63579 +#endif
63580 +
63581 /* Apply the given relocation to the (simplified) ELF. Return -error
63582 or 0. */
63583 int apply_relocate(Elf_Shdr *sechdrs,
63584 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63585 index d6a5806..7c13347 100644
63586 --- a/include/linux/moduleparam.h
63587 +++ b/include/linux/moduleparam.h
63588 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63589 * @len is usually just sizeof(string).
63590 */
63591 #define module_param_string(name, string, len, perm) \
63592 - static const struct kparam_string __param_string_##name \
63593 + static const struct kparam_string __param_string_##name __used \
63594 = { len, string }; \
63595 __module_param_call(MODULE_PARAM_PREFIX, name, \
63596 &param_ops_string, \
63597 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63598 */
63599 #define module_param_array_named(name, array, type, nump, perm) \
63600 param_check_##type(name, &(array)[0]); \
63601 - static const struct kparam_array __param_arr_##name \
63602 + static const struct kparam_array __param_arr_##name __used \
63603 = { .max = ARRAY_SIZE(array), .num = nump, \
63604 .ops = &param_ops_##type, \
63605 .elemsize = sizeof(array[0]), .elem = array }; \
63606 diff --git a/include/linux/namei.h b/include/linux/namei.h
63607 index 4bf19d8..5268cea 100644
63608 --- a/include/linux/namei.h
63609 +++ b/include/linux/namei.h
63610 @@ -18,7 +18,7 @@ struct nameidata {
63611 unsigned seq;
63612 int last_type;
63613 unsigned depth;
63614 - char *saved_names[MAX_NESTED_LINKS + 1];
63615 + const char *saved_names[MAX_NESTED_LINKS + 1];
63616 };
63617
63618 /*
63619 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63620
63621 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63622
63623 -static inline void nd_set_link(struct nameidata *nd, char *path)
63624 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63625 {
63626 nd->saved_names[nd->depth] = path;
63627 }
63628
63629 -static inline char *nd_get_link(struct nameidata *nd)
63630 +static inline const char *nd_get_link(const struct nameidata *nd)
63631 {
63632 return nd->saved_names[nd->depth];
63633 }
63634 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63635 index 59dc05f3..c905a34 100644
63636 --- a/include/linux/netdevice.h
63637 +++ b/include/linux/netdevice.h
63638 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63639 struct net_device *dev,
63640 int idx);
63641 };
63642 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63643
63644 /*
63645 * The DEVICE structure.
63646 @@ -1087,7 +1088,7 @@ struct net_device {
63647 int iflink;
63648
63649 struct net_device_stats stats;
63650 - atomic_long_t rx_dropped; /* dropped packets by core network
63651 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63652 * Do not use this in drivers.
63653 */
63654
63655 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63656 new file mode 100644
63657 index 0000000..33f4af8
63658 --- /dev/null
63659 +++ b/include/linux/netfilter/xt_gradm.h
63660 @@ -0,0 +1,9 @@
63661 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63662 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63663 +
63664 +struct xt_gradm_mtinfo {
63665 + __u16 flags;
63666 + __u16 invflags;
63667 +};
63668 +
63669 +#endif
63670 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63671 index c65a18a..0c05f3a 100644
63672 --- a/include/linux/of_pdt.h
63673 +++ b/include/linux/of_pdt.h
63674 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63675
63676 /* return 0 on success; fill in 'len' with number of bytes in path */
63677 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63678 -};
63679 +} __no_const;
63680
63681 extern void *prom_early_alloc(unsigned long size);
63682
63683 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63684 index a4c5624..79d6d88 100644
63685 --- a/include/linux/oprofile.h
63686 +++ b/include/linux/oprofile.h
63687 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63688 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63689 char const * name, ulong * val);
63690
63691 -/** Create a file for read-only access to an atomic_t. */
63692 +/** Create a file for read-only access to an atomic_unchecked_t. */
63693 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63694 - char const * name, atomic_t * val);
63695 + char const * name, atomic_unchecked_t * val);
63696
63697 /** create a directory */
63698 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63699 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63700 index bdb4161..f373d41 100644
63701 --- a/include/linux/perf_event.h
63702 +++ b/include/linux/perf_event.h
63703 @@ -882,8 +882,8 @@ struct perf_event {
63704
63705 enum perf_event_active_state state;
63706 unsigned int attach_state;
63707 - local64_t count;
63708 - atomic64_t child_count;
63709 + local64_t count; /* PaX: fix it one day */
63710 + atomic64_unchecked_t child_count;
63711
63712 /*
63713 * These are the total time in nanoseconds that the event
63714 @@ -934,8 +934,8 @@ struct perf_event {
63715 * These accumulate total time (in nanoseconds) that children
63716 * events have been enabled and running, respectively.
63717 */
63718 - atomic64_t child_total_time_enabled;
63719 - atomic64_t child_total_time_running;
63720 + atomic64_unchecked_t child_total_time_enabled;
63721 + atomic64_unchecked_t child_total_time_running;
63722
63723 /*
63724 * Protect attach/detach and child_list:
63725 diff --git a/include/linux/personality.h b/include/linux/personality.h
63726 index 8fc7dd1a..c19d89e 100644
63727 --- a/include/linux/personality.h
63728 +++ b/include/linux/personality.h
63729 @@ -44,6 +44,7 @@ enum {
63730 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63731 ADDR_NO_RANDOMIZE | \
63732 ADDR_COMPAT_LAYOUT | \
63733 + ADDR_LIMIT_3GB | \
63734 MMAP_PAGE_ZERO)
63735
63736 /*
63737 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63738 index ad1a427..6419649 100644
63739 --- a/include/linux/pipe_fs_i.h
63740 +++ b/include/linux/pipe_fs_i.h
63741 @@ -45,9 +45,9 @@ struct pipe_buffer {
63742 struct pipe_inode_info {
63743 wait_queue_head_t wait;
63744 unsigned int nrbufs, curbuf, buffers;
63745 - unsigned int readers;
63746 - unsigned int writers;
63747 - unsigned int waiting_writers;
63748 + atomic_t readers;
63749 + atomic_t writers;
63750 + atomic_t waiting_writers;
63751 unsigned int r_counter;
63752 unsigned int w_counter;
63753 struct page *tmp_page;
63754 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63755 index f271860..6b3bec5 100644
63756 --- a/include/linux/pm_runtime.h
63757 +++ b/include/linux/pm_runtime.h
63758 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63759
63760 static inline void pm_runtime_mark_last_busy(struct device *dev)
63761 {
63762 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63763 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63764 }
63765
63766 #else /* !CONFIG_PM_RUNTIME */
63767 diff --git a/include/linux/poison.h b/include/linux/poison.h
63768 index 2110a81..13a11bb 100644
63769 --- a/include/linux/poison.h
63770 +++ b/include/linux/poison.h
63771 @@ -19,8 +19,8 @@
63772 * under normal circumstances, used to verify that nobody uses
63773 * non-initialized list entries.
63774 */
63775 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63776 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63777 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63778 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63779
63780 /********** include/linux/timer.h **********/
63781 /*
63782 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63783 index 5a710b9..0b0dab9 100644
63784 --- a/include/linux/preempt.h
63785 +++ b/include/linux/preempt.h
63786 @@ -126,7 +126,7 @@ struct preempt_ops {
63787 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63788 void (*sched_out)(struct preempt_notifier *notifier,
63789 struct task_struct *next);
63790 -};
63791 +} __no_const;
63792
63793 /**
63794 * preempt_notifier - key for installing preemption notifiers
63795 diff --git a/include/linux/printk.h b/include/linux/printk.h
63796 index 9afc01e..92c32e8 100644
63797 --- a/include/linux/printk.h
63798 +++ b/include/linux/printk.h
63799 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63800 extern int printk_needs_cpu(int cpu);
63801 extern void printk_tick(void);
63802
63803 +extern int kptr_restrict;
63804 +
63805 #ifdef CONFIG_PRINTK
63806 asmlinkage __printf(5, 0)
63807 int vprintk_emit(int facility, int level,
63808 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63809
63810 extern int printk_delay_msec;
63811 extern int dmesg_restrict;
63812 -extern int kptr_restrict;
63813
63814 void log_buf_kexec_setup(void);
63815 void __init setup_log_buf(int early);
63816 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63817 index 3fd2e87..d93a721 100644
63818 --- a/include/linux/proc_fs.h
63819 +++ b/include/linux/proc_fs.h
63820 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63821 return proc_create_data(name, mode, parent, proc_fops, NULL);
63822 }
63823
63824 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63825 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63826 +{
63827 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63828 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63829 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63830 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63831 +#else
63832 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63833 +#endif
63834 +}
63835 +
63836 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63837 umode_t mode, struct proc_dir_entry *base,
63838 read_proc_t *read_proc, void * data)
63839 @@ -258,7 +270,7 @@ union proc_op {
63840 int (*proc_show)(struct seq_file *m,
63841 struct pid_namespace *ns, struct pid *pid,
63842 struct task_struct *task);
63843 -};
63844 +} __no_const;
63845
63846 struct ctl_table_header;
63847 struct ctl_table;
63848 diff --git a/include/linux/random.h b/include/linux/random.h
63849 index ac621ce..c1215f3 100644
63850 --- a/include/linux/random.h
63851 +++ b/include/linux/random.h
63852 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63853 unsigned int value);
63854 extern void add_interrupt_randomness(int irq, int irq_flags);
63855
63856 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63857 +extern void transfer_latent_entropy(void);
63858 +#endif
63859 +
63860 extern void get_random_bytes(void *buf, int nbytes);
63861 extern void get_random_bytes_arch(void *buf, int nbytes);
63862 void generate_random_uuid(unsigned char uuid_out[16]);
63863 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63864
63865 u32 prandom32(struct rnd_state *);
63866
63867 +static inline unsigned long pax_get_random_long(void)
63868 +{
63869 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63870 +}
63871 +
63872 /*
63873 * Handle minimum values for seeds
63874 */
63875 static inline u32 __seed(u32 x, u32 m)
63876 {
63877 - return (x < m) ? x + m : x;
63878 + return (x <= m) ? x + m + 1 : x;
63879 }
63880
63881 /**
63882 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63883 index e0879a7..a12f962 100644
63884 --- a/include/linux/reboot.h
63885 +++ b/include/linux/reboot.h
63886 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63887 * Architecture-specific implementations of sys_reboot commands.
63888 */
63889
63890 -extern void machine_restart(char *cmd);
63891 -extern void machine_halt(void);
63892 -extern void machine_power_off(void);
63893 +extern void machine_restart(char *cmd) __noreturn;
63894 +extern void machine_halt(void) __noreturn;
63895 +extern void machine_power_off(void) __noreturn;
63896
63897 extern void machine_shutdown(void);
63898 struct pt_regs;
63899 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63900 */
63901
63902 extern void kernel_restart_prepare(char *cmd);
63903 -extern void kernel_restart(char *cmd);
63904 -extern void kernel_halt(void);
63905 -extern void kernel_power_off(void);
63906 +extern void kernel_restart(char *cmd) __noreturn;
63907 +extern void kernel_halt(void) __noreturn;
63908 +extern void kernel_power_off(void) __noreturn;
63909
63910 extern int C_A_D; /* for sysctl */
63911 void ctrl_alt_del(void);
63912 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63913 * Emergency restart, callable from an interrupt handler.
63914 */
63915
63916 -extern void emergency_restart(void);
63917 +extern void emergency_restart(void) __noreturn;
63918 #include <asm/emergency-restart.h>
63919
63920 #endif
63921 diff --git a/include/linux/relay.h b/include/linux/relay.h
63922 index 91cacc3..b55ff74 100644
63923 --- a/include/linux/relay.h
63924 +++ b/include/linux/relay.h
63925 @@ -160,7 +160,7 @@ struct rchan_callbacks
63926 * The callback should return 0 if successful, negative if not.
63927 */
63928 int (*remove_buf_file)(struct dentry *dentry);
63929 -};
63930 +} __no_const;
63931
63932 /*
63933 * CONFIG_RELAY kernel API, kernel/relay.c
63934 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63935 index 6fdf027..ff72610 100644
63936 --- a/include/linux/rfkill.h
63937 +++ b/include/linux/rfkill.h
63938 @@ -147,6 +147,7 @@ struct rfkill_ops {
63939 void (*query)(struct rfkill *rfkill, void *data);
63940 int (*set_block)(void *data, bool blocked);
63941 };
63942 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63943
63944 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63945 /**
63946 diff --git a/include/linux/rio.h b/include/linux/rio.h
63947 index a90ebad..fd87b5d 100644
63948 --- a/include/linux/rio.h
63949 +++ b/include/linux/rio.h
63950 @@ -321,7 +321,7 @@ struct rio_ops {
63951 int mbox, void *buffer, size_t len);
63952 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63953 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63954 -};
63955 +} __no_const;
63956
63957 #define RIO_RESOURCE_MEM 0x00000100
63958 #define RIO_RESOURCE_DOORBELL 0x00000200
63959 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63960 index 3fce545..b4fed6e 100644
63961 --- a/include/linux/rmap.h
63962 +++ b/include/linux/rmap.h
63963 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63964 void anon_vma_init(void); /* create anon_vma_cachep */
63965 int anon_vma_prepare(struct vm_area_struct *);
63966 void unlink_anon_vmas(struct vm_area_struct *);
63967 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63968 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63969 void anon_vma_moveto_tail(struct vm_area_struct *);
63970 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63971 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63972
63973 static inline void anon_vma_merge(struct vm_area_struct *vma,
63974 struct vm_area_struct *next)
63975 diff --git a/include/linux/sched.h b/include/linux/sched.h
63976 index 23bddac..5976055 100644
63977 --- a/include/linux/sched.h
63978 +++ b/include/linux/sched.h
63979 @@ -101,6 +101,7 @@ struct bio_list;
63980 struct fs_struct;
63981 struct perf_event_context;
63982 struct blk_plug;
63983 +struct linux_binprm;
63984
63985 /*
63986 * List of flags we want to share for kernel threads,
63987 @@ -384,10 +385,13 @@ struct user_namespace;
63988 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63989
63990 extern int sysctl_max_map_count;
63991 +extern unsigned long sysctl_heap_stack_gap;
63992
63993 #include <linux/aio.h>
63994
63995 #ifdef CONFIG_MMU
63996 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63997 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63998 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63999 extern unsigned long
64000 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64001 @@ -651,6 +655,17 @@ struct signal_struct {
64002 #ifdef CONFIG_TASKSTATS
64003 struct taskstats *stats;
64004 #endif
64005 +
64006 +#ifdef CONFIG_GRKERNSEC
64007 + u32 curr_ip;
64008 + u32 saved_ip;
64009 + u32 gr_saddr;
64010 + u32 gr_daddr;
64011 + u16 gr_sport;
64012 + u16 gr_dport;
64013 + u8 used_accept:1;
64014 +#endif
64015 +
64016 #ifdef CONFIG_AUDIT
64017 unsigned audit_tty;
64018 struct tty_audit_buf *tty_audit_buf;
64019 @@ -734,6 +749,11 @@ struct user_struct {
64020 struct key *session_keyring; /* UID's default session keyring */
64021 #endif
64022
64023 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64024 + unsigned int banned;
64025 + unsigned long ban_expires;
64026 +#endif
64027 +
64028 /* Hash table maintenance information */
64029 struct hlist_node uidhash_node;
64030 kuid_t uid;
64031 @@ -1356,8 +1376,8 @@ struct task_struct {
64032 struct list_head thread_group;
64033
64034 struct completion *vfork_done; /* for vfork() */
64035 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64036 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64037 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64038 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64039
64040 cputime_t utime, stime, utimescaled, stimescaled;
64041 cputime_t gtime;
64042 @@ -1373,11 +1393,6 @@ struct task_struct {
64043 struct task_cputime cputime_expires;
64044 struct list_head cpu_timers[3];
64045
64046 -/* process credentials */
64047 - const struct cred __rcu *real_cred; /* objective and real subjective task
64048 - * credentials (COW) */
64049 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64050 - * credentials (COW) */
64051 char comm[TASK_COMM_LEN]; /* executable name excluding path
64052 - access with [gs]et_task_comm (which lock
64053 it with task_lock())
64054 @@ -1394,6 +1409,10 @@ struct task_struct {
64055 #endif
64056 /* CPU-specific state of this task */
64057 struct thread_struct thread;
64058 +/* thread_info moved to task_struct */
64059 +#ifdef CONFIG_X86
64060 + struct thread_info tinfo;
64061 +#endif
64062 /* filesystem information */
64063 struct fs_struct *fs;
64064 /* open file information */
64065 @@ -1467,6 +1486,10 @@ struct task_struct {
64066 gfp_t lockdep_reclaim_gfp;
64067 #endif
64068
64069 +/* process credentials */
64070 + const struct cred __rcu *real_cred; /* objective and real subjective task
64071 + * credentials (COW) */
64072 +
64073 /* journalling filesystem info */
64074 void *journal_info;
64075
64076 @@ -1505,6 +1528,10 @@ struct task_struct {
64077 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64078 struct list_head cg_list;
64079 #endif
64080 +
64081 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64082 + * credentials (COW) */
64083 +
64084 #ifdef CONFIG_FUTEX
64085 struct robust_list_head __user *robust_list;
64086 #ifdef CONFIG_COMPAT
64087 @@ -1589,8 +1616,74 @@ struct task_struct {
64088 #ifdef CONFIG_UPROBES
64089 struct uprobe_task *utask;
64090 #endif
64091 +
64092 +#ifdef CONFIG_GRKERNSEC
64093 + /* grsecurity */
64094 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64095 + u64 exec_id;
64096 +#endif
64097 +#ifdef CONFIG_GRKERNSEC_SETXID
64098 + const struct cred *delayed_cred;
64099 +#endif
64100 + struct dentry *gr_chroot_dentry;
64101 + struct acl_subject_label *acl;
64102 + struct acl_role_label *role;
64103 + struct file *exec_file;
64104 + u16 acl_role_id;
64105 + /* is this the task that authenticated to the special role */
64106 + u8 acl_sp_role;
64107 + u8 is_writable;
64108 + u8 brute;
64109 + u8 gr_is_chrooted;
64110 +#endif
64111 +
64112 };
64113
64114 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64115 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64116 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64117 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64118 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64119 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64120 +
64121 +#ifdef CONFIG_PAX_SOFTMODE
64122 +extern int pax_softmode;
64123 +#endif
64124 +
64125 +extern int pax_check_flags(unsigned long *);
64126 +
64127 +/* if tsk != current then task_lock must be held on it */
64128 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64129 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64130 +{
64131 + if (likely(tsk->mm))
64132 + return tsk->mm->pax_flags;
64133 + else
64134 + return 0UL;
64135 +}
64136 +
64137 +/* if tsk != current then task_lock must be held on it */
64138 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64139 +{
64140 + if (likely(tsk->mm)) {
64141 + tsk->mm->pax_flags = flags;
64142 + return 0;
64143 + }
64144 + return -EINVAL;
64145 +}
64146 +#endif
64147 +
64148 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64149 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64150 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64151 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64152 +#endif
64153 +
64154 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64155 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64156 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64157 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64158 +
64159 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64160 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64161
64162 @@ -2125,7 +2218,9 @@ void yield(void);
64163 extern struct exec_domain default_exec_domain;
64164
64165 union thread_union {
64166 +#ifndef CONFIG_X86
64167 struct thread_info thread_info;
64168 +#endif
64169 unsigned long stack[THREAD_SIZE/sizeof(long)];
64170 };
64171
64172 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64173 */
64174
64175 extern struct task_struct *find_task_by_vpid(pid_t nr);
64176 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64177 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64178 struct pid_namespace *ns);
64179
64180 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64181 extern void exit_itimers(struct signal_struct *);
64182 extern void flush_itimer_signals(void);
64183
64184 -extern void do_group_exit(int);
64185 +extern __noreturn void do_group_exit(int);
64186
64187 extern void daemonize(const char *, ...);
64188 extern int allow_signal(int);
64189 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64190
64191 #endif
64192
64193 -static inline int object_is_on_stack(void *obj)
64194 +static inline int object_starts_on_stack(void *obj)
64195 {
64196 - void *stack = task_stack_page(current);
64197 + const void *stack = task_stack_page(current);
64198
64199 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64200 }
64201 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64202 index 899fbb4..1cb4138 100644
64203 --- a/include/linux/screen_info.h
64204 +++ b/include/linux/screen_info.h
64205 @@ -43,7 +43,8 @@ struct screen_info {
64206 __u16 pages; /* 0x32 */
64207 __u16 vesa_attributes; /* 0x34 */
64208 __u32 capabilities; /* 0x36 */
64209 - __u8 _reserved[6]; /* 0x3a */
64210 + __u16 vesapm_size; /* 0x3a */
64211 + __u8 _reserved[4]; /* 0x3c */
64212 } __attribute__((packed));
64213
64214 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64215 diff --git a/include/linux/security.h b/include/linux/security.h
64216 index d143b8e..9f27b95 100644
64217 --- a/include/linux/security.h
64218 +++ b/include/linux/security.h
64219 @@ -26,6 +26,7 @@
64220 #include <linux/capability.h>
64221 #include <linux/slab.h>
64222 #include <linux/err.h>
64223 +#include <linux/grsecurity.h>
64224
64225 struct linux_binprm;
64226 struct cred;
64227 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64228 index 83c44ee..e8a9eba 100644
64229 --- a/include/linux/seq_file.h
64230 +++ b/include/linux/seq_file.h
64231 @@ -25,6 +25,9 @@ struct seq_file {
64232 struct mutex lock;
64233 const struct seq_operations *op;
64234 int poll_event;
64235 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64236 + u64 exec_id;
64237 +#endif
64238 void *private;
64239 };
64240
64241 @@ -34,6 +37,7 @@ struct seq_operations {
64242 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64243 int (*show) (struct seq_file *m, void *v);
64244 };
64245 +typedef struct seq_operations __no_const seq_operations_no_const;
64246
64247 #define SEQ_SKIP 1
64248
64249 diff --git a/include/linux/shm.h b/include/linux/shm.h
64250 index edd0868..f98feee 100644
64251 --- a/include/linux/shm.h
64252 +++ b/include/linux/shm.h
64253 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64254
64255 /* The task created the shm object. NULL if the task is dead. */
64256 struct task_struct *shm_creator;
64257 +#ifdef CONFIG_GRKERNSEC
64258 + time_t shm_createtime;
64259 + pid_t shm_lapid;
64260 +#endif
64261 };
64262
64263 /* shm_mode upper byte flags */
64264 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64265 index 7632c87..8fd660f 100644
64266 --- a/include/linux/skbuff.h
64267 +++ b/include/linux/skbuff.h
64268 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64269 extern struct sk_buff *__alloc_skb(unsigned int size,
64270 gfp_t priority, int flags, int node);
64271 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64272 -static inline struct sk_buff *alloc_skb(unsigned int size,
64273 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64274 gfp_t priority)
64275 {
64276 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64277 @@ -690,7 +690,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64278 */
64279 static inline int skb_queue_empty(const struct sk_buff_head *list)
64280 {
64281 - return list->next == (struct sk_buff *)list;
64282 + return list->next == (const struct sk_buff *)list;
64283 }
64284
64285 /**
64286 @@ -703,7 +703,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64287 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64288 const struct sk_buff *skb)
64289 {
64290 - return skb->next == (struct sk_buff *)list;
64291 + return skb->next == (const struct sk_buff *)list;
64292 }
64293
64294 /**
64295 @@ -716,7 +716,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64296 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64297 const struct sk_buff *skb)
64298 {
64299 - return skb->prev == (struct sk_buff *)list;
64300 + return skb->prev == (const struct sk_buff *)list;
64301 }
64302
64303 /**
64304 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64305 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64306 */
64307 #ifndef NET_SKB_PAD
64308 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64309 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64310 #endif
64311
64312 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64313 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64314 int noblock, int *err);
64315 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64316 struct poll_table_struct *wait);
64317 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64318 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64319 int offset, struct iovec *to,
64320 int size);
64321 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64322 diff --git a/include/linux/slab.h b/include/linux/slab.h
64323 index 0dd2dfa..2b8677c 100644
64324 --- a/include/linux/slab.h
64325 +++ b/include/linux/slab.h
64326 @@ -11,12 +11,20 @@
64327
64328 #include <linux/gfp.h>
64329 #include <linux/types.h>
64330 +#include <linux/err.h>
64331
64332 /*
64333 * Flags to pass to kmem_cache_create().
64334 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64335 */
64336 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64337 +
64338 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64339 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64340 +#else
64341 +#define SLAB_USERCOPY 0x00000000UL
64342 +#endif
64343 +
64344 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64345 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64346 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64347 @@ -87,10 +95,13 @@
64348 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64349 * Both make kfree a no-op.
64350 */
64351 -#define ZERO_SIZE_PTR ((void *)16)
64352 +#define ZERO_SIZE_PTR \
64353 +({ \
64354 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64355 + (void *)(-MAX_ERRNO-1L); \
64356 +})
64357
64358 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64359 - (unsigned long)ZERO_SIZE_PTR)
64360 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64361
64362 /*
64363 * Common fields provided in kmem_cache by all slab allocators
64364 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64365 void kfree(const void *);
64366 void kzfree(const void *);
64367 size_t ksize(const void *);
64368 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64369 +bool is_usercopy_object(const void *ptr);
64370
64371 /*
64372 * Allocator specific definitions. These are mainly used to establish optimized
64373 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64374 */
64375 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64376 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64377 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64378 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64379 #define kmalloc_track_caller(size, flags) \
64380 __kmalloc_track_caller(size, flags, _RET_IP_)
64381 #else
64382 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64383 */
64384 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64385 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64386 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64387 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64388 #define kmalloc_node_track_caller(size, flags, node) \
64389 __kmalloc_node_track_caller(size, flags, node, \
64390 _RET_IP_)
64391 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64392 index 0c634fa..8616300 100644
64393 --- a/include/linux/slab_def.h
64394 +++ b/include/linux/slab_def.h
64395 @@ -69,10 +69,10 @@ struct kmem_cache {
64396 unsigned long node_allocs;
64397 unsigned long node_frees;
64398 unsigned long node_overflow;
64399 - atomic_t allochit;
64400 - atomic_t allocmiss;
64401 - atomic_t freehit;
64402 - atomic_t freemiss;
64403 + atomic_unchecked_t allochit;
64404 + atomic_unchecked_t allocmiss;
64405 + atomic_unchecked_t freehit;
64406 + atomic_unchecked_t freemiss;
64407
64408 /*
64409 * If debugging is enabled, then the allocator can add additional
64410 @@ -105,11 +105,16 @@ struct cache_sizes {
64411 #ifdef CONFIG_ZONE_DMA
64412 struct kmem_cache *cs_dmacachep;
64413 #endif
64414 +
64415 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64416 + struct kmem_cache *cs_usercopycachep;
64417 +#endif
64418 +
64419 };
64420 extern struct cache_sizes malloc_sizes[];
64421
64422 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64423 -void *__kmalloc(size_t size, gfp_t flags);
64424 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64425
64426 #ifdef CONFIG_TRACING
64427 extern void *kmem_cache_alloc_trace(size_t size,
64428 @@ -152,6 +157,13 @@ found:
64429 cachep = malloc_sizes[i].cs_dmacachep;
64430 else
64431 #endif
64432 +
64433 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64434 + if (flags & GFP_USERCOPY)
64435 + cachep = malloc_sizes[i].cs_usercopycachep;
64436 + else
64437 +#endif
64438 +
64439 cachep = malloc_sizes[i].cs_cachep;
64440
64441 ret = kmem_cache_alloc_trace(size, cachep, flags);
64442 @@ -162,7 +174,7 @@ found:
64443 }
64444
64445 #ifdef CONFIG_NUMA
64446 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64447 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64448 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64449
64450 #ifdef CONFIG_TRACING
64451 @@ -205,6 +217,13 @@ found:
64452 cachep = malloc_sizes[i].cs_dmacachep;
64453 else
64454 #endif
64455 +
64456 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64457 + if (flags & GFP_USERCOPY)
64458 + cachep = malloc_sizes[i].cs_usercopycachep;
64459 + else
64460 +#endif
64461 +
64462 cachep = malloc_sizes[i].cs_cachep;
64463
64464 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64465 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64466 index 0ec00b3..22b4715 100644
64467 --- a/include/linux/slob_def.h
64468 +++ b/include/linux/slob_def.h
64469 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64470 return kmem_cache_alloc_node(cachep, flags, -1);
64471 }
64472
64473 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64474 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64475
64476 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64477 {
64478 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64479 return __kmalloc_node(size, flags, -1);
64480 }
64481
64482 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64483 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64484 {
64485 return kmalloc(size, flags);
64486 }
64487 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64488 index df448ad..b99e7f6 100644
64489 --- a/include/linux/slub_def.h
64490 +++ b/include/linux/slub_def.h
64491 @@ -91,7 +91,7 @@ struct kmem_cache {
64492 struct kmem_cache_order_objects max;
64493 struct kmem_cache_order_objects min;
64494 gfp_t allocflags; /* gfp flags to use on each alloc */
64495 - int refcount; /* Refcount for slab cache destroy */
64496 + atomic_t refcount; /* Refcount for slab cache destroy */
64497 void (*ctor)(void *);
64498 int inuse; /* Offset to metadata */
64499 int align; /* Alignment */
64500 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64501 * Sorry that the following has to be that ugly but some versions of GCC
64502 * have trouble with constant propagation and loops.
64503 */
64504 -static __always_inline int kmalloc_index(size_t size)
64505 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64506 {
64507 if (!size)
64508 return 0;
64509 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64510 }
64511
64512 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64513 -void *__kmalloc(size_t size, gfp_t flags);
64514 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64515
64516 static __always_inline void *
64517 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64518 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64519 }
64520 #endif
64521
64522 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64523 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64524 {
64525 unsigned int order = get_order(size);
64526 return kmalloc_order_trace(size, flags, order);
64527 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64528 }
64529
64530 #ifdef CONFIG_NUMA
64531 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64532 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64533 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64534
64535 #ifdef CONFIG_TRACING
64536 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64537 index de8832d..0147b46 100644
64538 --- a/include/linux/sonet.h
64539 +++ b/include/linux/sonet.h
64540 @@ -61,7 +61,7 @@ struct sonet_stats {
64541 #include <linux/atomic.h>
64542
64543 struct k_sonet_stats {
64544 -#define __HANDLE_ITEM(i) atomic_t i
64545 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64546 __SONET_ITEMS
64547 #undef __HANDLE_ITEM
64548 };
64549 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64550 index 523547e..2cb7140 100644
64551 --- a/include/linux/sunrpc/clnt.h
64552 +++ b/include/linux/sunrpc/clnt.h
64553 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64554 {
64555 switch (sap->sa_family) {
64556 case AF_INET:
64557 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64558 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64559 case AF_INET6:
64560 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64561 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64562 }
64563 return 0;
64564 }
64565 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64566 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64567 const struct sockaddr *src)
64568 {
64569 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64570 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64571 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64572
64573 dsin->sin_family = ssin->sin_family;
64574 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64575 if (sa->sa_family != AF_INET6)
64576 return 0;
64577
64578 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64579 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64580 }
64581
64582 #endif /* __KERNEL__ */
64583 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64584 index dc0c3cc..8503fb6 100644
64585 --- a/include/linux/sunrpc/sched.h
64586 +++ b/include/linux/sunrpc/sched.h
64587 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64588 void (*rpc_count_stats)(struct rpc_task *, void *);
64589 void (*rpc_release)(void *);
64590 };
64591 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64592
64593 struct rpc_task_setup {
64594 struct rpc_task *task;
64595 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64596 index 0b8e3e6..33e0a01 100644
64597 --- a/include/linux/sunrpc/svc_rdma.h
64598 +++ b/include/linux/sunrpc/svc_rdma.h
64599 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64600 extern unsigned int svcrdma_max_requests;
64601 extern unsigned int svcrdma_max_req_size;
64602
64603 -extern atomic_t rdma_stat_recv;
64604 -extern atomic_t rdma_stat_read;
64605 -extern atomic_t rdma_stat_write;
64606 -extern atomic_t rdma_stat_sq_starve;
64607 -extern atomic_t rdma_stat_rq_starve;
64608 -extern atomic_t rdma_stat_rq_poll;
64609 -extern atomic_t rdma_stat_rq_prod;
64610 -extern atomic_t rdma_stat_sq_poll;
64611 -extern atomic_t rdma_stat_sq_prod;
64612 +extern atomic_unchecked_t rdma_stat_recv;
64613 +extern atomic_unchecked_t rdma_stat_read;
64614 +extern atomic_unchecked_t rdma_stat_write;
64615 +extern atomic_unchecked_t rdma_stat_sq_starve;
64616 +extern atomic_unchecked_t rdma_stat_rq_starve;
64617 +extern atomic_unchecked_t rdma_stat_rq_poll;
64618 +extern atomic_unchecked_t rdma_stat_rq_prod;
64619 +extern atomic_unchecked_t rdma_stat_sq_poll;
64620 +extern atomic_unchecked_t rdma_stat_sq_prod;
64621
64622 #define RPCRDMA_VERSION 1
64623
64624 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64625 index c34b4c8..a65b67d 100644
64626 --- a/include/linux/sysctl.h
64627 +++ b/include/linux/sysctl.h
64628 @@ -155,7 +155,11 @@ enum
64629 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64630 };
64631
64632 -
64633 +#ifdef CONFIG_PAX_SOFTMODE
64634 +enum {
64635 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64636 +};
64637 +#endif
64638
64639 /* CTL_VM names: */
64640 enum
64641 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64642
64643 extern int proc_dostring(struct ctl_table *, int,
64644 void __user *, size_t *, loff_t *);
64645 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64646 + void __user *, size_t *, loff_t *);
64647 extern int proc_dointvec(struct ctl_table *, int,
64648 void __user *, size_t *, loff_t *);
64649 extern int proc_dointvec_minmax(struct ctl_table *, int,
64650 diff --git a/include/linux/tty.h b/include/linux/tty.h
64651 index 9f47ab5..73da944 100644
64652 --- a/include/linux/tty.h
64653 +++ b/include/linux/tty.h
64654 @@ -225,7 +225,7 @@ struct tty_port {
64655 const struct tty_port_operations *ops; /* Port operations */
64656 spinlock_t lock; /* Lock protecting tty field */
64657 int blocked_open; /* Waiting to open */
64658 - int count; /* Usage count */
64659 + atomic_t count; /* Usage count */
64660 wait_queue_head_t open_wait; /* Open waiters */
64661 wait_queue_head_t close_wait; /* Close waiters */
64662 wait_queue_head_t delta_msr_wait; /* Modem status change */
64663 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64664 struct tty_struct *tty, struct file *filp);
64665 static inline int tty_port_users(struct tty_port *port)
64666 {
64667 - return port->count + port->blocked_open;
64668 + return atomic_read(&port->count) + port->blocked_open;
64669 }
64670
64671 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64672 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64673 index fb79dd8d..07d4773 100644
64674 --- a/include/linux/tty_ldisc.h
64675 +++ b/include/linux/tty_ldisc.h
64676 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64677
64678 struct module *owner;
64679
64680 - int refcount;
64681 + atomic_t refcount;
64682 };
64683
64684 struct tty_ldisc {
64685 diff --git a/include/linux/types.h b/include/linux/types.h
64686 index bf0dd75..a1f23aaa 100644
64687 --- a/include/linux/types.h
64688 +++ b/include/linux/types.h
64689 @@ -220,10 +220,26 @@ typedef struct {
64690 int counter;
64691 } atomic_t;
64692
64693 +#ifdef CONFIG_PAX_REFCOUNT
64694 +typedef struct {
64695 + int counter;
64696 +} atomic_unchecked_t;
64697 +#else
64698 +typedef atomic_t atomic_unchecked_t;
64699 +#endif
64700 +
64701 #ifdef CONFIG_64BIT
64702 typedef struct {
64703 long counter;
64704 } atomic64_t;
64705 +
64706 +#ifdef CONFIG_PAX_REFCOUNT
64707 +typedef struct {
64708 + long counter;
64709 +} atomic64_unchecked_t;
64710 +#else
64711 +typedef atomic64_t atomic64_unchecked_t;
64712 +#endif
64713 #endif
64714
64715 struct list_head {
64716 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64717 index 5ca0951..ab496a5 100644
64718 --- a/include/linux/uaccess.h
64719 +++ b/include/linux/uaccess.h
64720 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64721 long ret; \
64722 mm_segment_t old_fs = get_fs(); \
64723 \
64724 - set_fs(KERNEL_DS); \
64725 pagefault_disable(); \
64726 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64727 - pagefault_enable(); \
64728 + set_fs(KERNEL_DS); \
64729 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64730 set_fs(old_fs); \
64731 + pagefault_enable(); \
64732 ret; \
64733 })
64734
64735 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64736 index 99c1b4d..bb94261 100644
64737 --- a/include/linux/unaligned/access_ok.h
64738 +++ b/include/linux/unaligned/access_ok.h
64739 @@ -6,32 +6,32 @@
64740
64741 static inline u16 get_unaligned_le16(const void *p)
64742 {
64743 - return le16_to_cpup((__le16 *)p);
64744 + return le16_to_cpup((const __le16 *)p);
64745 }
64746
64747 static inline u32 get_unaligned_le32(const void *p)
64748 {
64749 - return le32_to_cpup((__le32 *)p);
64750 + return le32_to_cpup((const __le32 *)p);
64751 }
64752
64753 static inline u64 get_unaligned_le64(const void *p)
64754 {
64755 - return le64_to_cpup((__le64 *)p);
64756 + return le64_to_cpup((const __le64 *)p);
64757 }
64758
64759 static inline u16 get_unaligned_be16(const void *p)
64760 {
64761 - return be16_to_cpup((__be16 *)p);
64762 + return be16_to_cpup((const __be16 *)p);
64763 }
64764
64765 static inline u32 get_unaligned_be32(const void *p)
64766 {
64767 - return be32_to_cpup((__be32 *)p);
64768 + return be32_to_cpup((const __be32 *)p);
64769 }
64770
64771 static inline u64 get_unaligned_be64(const void *p)
64772 {
64773 - return be64_to_cpup((__be64 *)p);
64774 + return be64_to_cpup((const __be64 *)p);
64775 }
64776
64777 static inline void put_unaligned_le16(u16 val, void *p)
64778 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64779 index c5d36c6..8478c90 100644
64780 --- a/include/linux/usb/renesas_usbhs.h
64781 +++ b/include/linux/usb/renesas_usbhs.h
64782 @@ -39,7 +39,7 @@ enum {
64783 */
64784 struct renesas_usbhs_driver_callback {
64785 int (*notify_hotplug)(struct platform_device *pdev);
64786 -};
64787 +} __no_const;
64788
64789 /*
64790 * callback functions for platform
64791 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64792 * VBUS control is needed for Host
64793 */
64794 int (*set_vbus)(struct platform_device *pdev, int enable);
64795 -};
64796 +} __no_const;
64797
64798 /*
64799 * parameters for renesas usbhs
64800 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64801 index 6f8fbcf..8259001 100644
64802 --- a/include/linux/vermagic.h
64803 +++ b/include/linux/vermagic.h
64804 @@ -25,9 +25,35 @@
64805 #define MODULE_ARCH_VERMAGIC ""
64806 #endif
64807
64808 +#ifdef CONFIG_PAX_REFCOUNT
64809 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64810 +#else
64811 +#define MODULE_PAX_REFCOUNT ""
64812 +#endif
64813 +
64814 +#ifdef CONSTIFY_PLUGIN
64815 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64816 +#else
64817 +#define MODULE_CONSTIFY_PLUGIN ""
64818 +#endif
64819 +
64820 +#ifdef STACKLEAK_PLUGIN
64821 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64822 +#else
64823 +#define MODULE_STACKLEAK_PLUGIN ""
64824 +#endif
64825 +
64826 +#ifdef CONFIG_GRKERNSEC
64827 +#define MODULE_GRSEC "GRSEC "
64828 +#else
64829 +#define MODULE_GRSEC ""
64830 +#endif
64831 +
64832 #define VERMAGIC_STRING \
64833 UTS_RELEASE " " \
64834 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64835 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64836 - MODULE_ARCH_VERMAGIC
64837 + MODULE_ARCH_VERMAGIC \
64838 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64839 + MODULE_GRSEC
64840
64841 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64842 index 6071e91..ca6a489 100644
64843 --- a/include/linux/vmalloc.h
64844 +++ b/include/linux/vmalloc.h
64845 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64846 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64847 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64848 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64849 +
64850 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64851 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64852 +#endif
64853 +
64854 /* bits [20..32] reserved for arch specific ioremap internals */
64855
64856 /*
64857 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64858 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64859 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64860 unsigned long start, unsigned long end, gfp_t gfp_mask,
64861 - pgprot_t prot, int node, const void *caller);
64862 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
64863 extern void vfree(const void *addr);
64864
64865 extern void *vmap(struct page **pages, unsigned int count,
64866 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64867 extern void free_vm_area(struct vm_struct *area);
64868
64869 /* for /dev/kmem */
64870 -extern long vread(char *buf, char *addr, unsigned long count);
64871 -extern long vwrite(char *buf, char *addr, unsigned long count);
64872 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64873 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64874
64875 /*
64876 * Internals. Dont't use..
64877 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64878 index ad2cfd5..74c94ad 100644
64879 --- a/include/linux/vmstat.h
64880 +++ b/include/linux/vmstat.h
64881 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64882 /*
64883 * Zone based page accounting with per cpu differentials.
64884 */
64885 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64886 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64887
64888 static inline void zone_page_state_add(long x, struct zone *zone,
64889 enum zone_stat_item item)
64890 {
64891 - atomic_long_add(x, &zone->vm_stat[item]);
64892 - atomic_long_add(x, &vm_stat[item]);
64893 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64894 + atomic_long_add_unchecked(x, &vm_stat[item]);
64895 }
64896
64897 static inline unsigned long global_page_state(enum zone_stat_item item)
64898 {
64899 - long x = atomic_long_read(&vm_stat[item]);
64900 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64901 #ifdef CONFIG_SMP
64902 if (x < 0)
64903 x = 0;
64904 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64905 static inline unsigned long zone_page_state(struct zone *zone,
64906 enum zone_stat_item item)
64907 {
64908 - long x = atomic_long_read(&zone->vm_stat[item]);
64909 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64910 #ifdef CONFIG_SMP
64911 if (x < 0)
64912 x = 0;
64913 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64914 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64915 enum zone_stat_item item)
64916 {
64917 - long x = atomic_long_read(&zone->vm_stat[item]);
64918 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64919
64920 #ifdef CONFIG_SMP
64921 int cpu;
64922 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64923
64924 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64925 {
64926 - atomic_long_inc(&zone->vm_stat[item]);
64927 - atomic_long_inc(&vm_stat[item]);
64928 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64929 + atomic_long_inc_unchecked(&vm_stat[item]);
64930 }
64931
64932 static inline void __inc_zone_page_state(struct page *page,
64933 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
64934
64935 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64936 {
64937 - atomic_long_dec(&zone->vm_stat[item]);
64938 - atomic_long_dec(&vm_stat[item]);
64939 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64940 + atomic_long_dec_unchecked(&vm_stat[item]);
64941 }
64942
64943 static inline void __dec_zone_page_state(struct page *page,
64944 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64945 index e5d1220..ef6e406 100644
64946 --- a/include/linux/xattr.h
64947 +++ b/include/linux/xattr.h
64948 @@ -57,6 +57,11 @@
64949 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64950 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64951
64952 +/* User namespace */
64953 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64954 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64955 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64956 +
64957 #ifdef __KERNEL__
64958
64959 #include <linux/types.h>
64960 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64961 index 944ecdf..a3994fc 100644
64962 --- a/include/media/saa7146_vv.h
64963 +++ b/include/media/saa7146_vv.h
64964 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64965 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64966
64967 /* the extension can override this */
64968 - struct v4l2_ioctl_ops vid_ops;
64969 - struct v4l2_ioctl_ops vbi_ops;
64970 + v4l2_ioctl_ops_no_const vid_ops;
64971 + v4l2_ioctl_ops_no_const vbi_ops;
64972 /* pointer to the saa7146 core ops */
64973 const struct v4l2_ioctl_ops *core_ops;
64974
64975 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64976 index 5c416cd..20021aa 100644
64977 --- a/include/media/v4l2-dev.h
64978 +++ b/include/media/v4l2-dev.h
64979 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64980 int (*mmap) (struct file *, struct vm_area_struct *);
64981 int (*open) (struct file *);
64982 int (*release) (struct file *);
64983 -};
64984 +} __do_const;
64985 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64986
64987 /*
64988 * Newer version of video_device, handled by videodev2.c
64989 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64990 index e614c9c..20602b7 100644
64991 --- a/include/media/v4l2-ioctl.h
64992 +++ b/include/media/v4l2-ioctl.h
64993 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
64994 long (*vidioc_default) (struct file *file, void *fh,
64995 bool valid_prio, int cmd, void *arg);
64996 };
64997 -
64998 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64999
65000 /* v4l debugging and diagnostics */
65001
65002 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65003 index bcb9cc3..f4ec722e 100644
65004 --- a/include/net/caif/caif_hsi.h
65005 +++ b/include/net/caif/caif_hsi.h
65006 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65007 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65008 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65009 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65010 -};
65011 +} __no_const;
65012
65013 /* Structure implemented by HSI device. */
65014 struct cfhsi_ops {
65015 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65016 index 9e5425b..8136ffc 100644
65017 --- a/include/net/caif/cfctrl.h
65018 +++ b/include/net/caif/cfctrl.h
65019 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65020 void (*radioset_rsp)(void);
65021 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65022 struct cflayer *client_layer);
65023 -};
65024 +} __no_const;
65025
65026 /* Link Setup Parameters for CAIF-Links. */
65027 struct cfctrl_link_param {
65028 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65029 struct cfctrl {
65030 struct cfsrvl serv;
65031 struct cfctrl_rsp res;
65032 - atomic_t req_seq_no;
65033 - atomic_t rsp_seq_no;
65034 + atomic_unchecked_t req_seq_no;
65035 + atomic_unchecked_t rsp_seq_no;
65036 struct list_head list;
65037 /* Protects from simultaneous access to first_req list */
65038 spinlock_t info_list_lock;
65039 diff --git a/include/net/flow.h b/include/net/flow.h
65040 index e1dd508..2873851 100644
65041 --- a/include/net/flow.h
65042 +++ b/include/net/flow.h
65043 @@ -220,6 +220,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65044
65045 extern void flow_cache_flush(void);
65046 extern void flow_cache_flush_deferred(void);
65047 -extern atomic_t flow_cache_genid;
65048 +extern atomic_unchecked_t flow_cache_genid;
65049
65050 #endif
65051 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65052 index 53f464d..ba76aaa 100644
65053 --- a/include/net/inetpeer.h
65054 +++ b/include/net/inetpeer.h
65055 @@ -47,8 +47,8 @@ struct inet_peer {
65056 */
65057 union {
65058 struct {
65059 - atomic_t rid; /* Frag reception counter */
65060 - atomic_t ip_id_count; /* IP ID for the next packet */
65061 + atomic_unchecked_t rid; /* Frag reception counter */
65062 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65063 };
65064 struct rcu_head rcu;
65065 struct inet_peer *gc_next;
65066 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65067 more++;
65068 inet_peer_refcheck(p);
65069 do {
65070 - old = atomic_read(&p->ip_id_count);
65071 + old = atomic_read_unchecked(&p->ip_id_count);
65072 new = old + more;
65073 if (!new)
65074 new = 1;
65075 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65076 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65077 return new;
65078 }
65079
65080 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65081 index 9497be1..5a4fafe 100644
65082 --- a/include/net/ip_fib.h
65083 +++ b/include/net/ip_fib.h
65084 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65085
65086 #define FIB_RES_SADDR(net, res) \
65087 ((FIB_RES_NH(res).nh_saddr_genid == \
65088 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65089 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65090 FIB_RES_NH(res).nh_saddr : \
65091 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65092 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65093 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65094 index 95374d1..2300e36 100644
65095 --- a/include/net/ip_vs.h
65096 +++ b/include/net/ip_vs.h
65097 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65098 struct ip_vs_conn *control; /* Master control connection */
65099 atomic_t n_control; /* Number of controlled ones */
65100 struct ip_vs_dest *dest; /* real server */
65101 - atomic_t in_pkts; /* incoming packet counter */
65102 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65103
65104 /* packet transmitter for different forwarding methods. If it
65105 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65106 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65107 __be16 port; /* port number of the server */
65108 union nf_inet_addr addr; /* IP address of the server */
65109 volatile unsigned int flags; /* dest status flags */
65110 - atomic_t conn_flags; /* flags to copy to conn */
65111 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65112 atomic_t weight; /* server weight */
65113
65114 atomic_t refcnt; /* reference counter */
65115 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65116 index 69b610a..fe3962c 100644
65117 --- a/include/net/irda/ircomm_core.h
65118 +++ b/include/net/irda/ircomm_core.h
65119 @@ -51,7 +51,7 @@ typedef struct {
65120 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65121 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65122 struct ircomm_info *);
65123 -} call_t;
65124 +} __no_const call_t;
65125
65126 struct ircomm_cb {
65127 irda_queue_t queue;
65128 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65129 index 59ba38bc..d515662 100644
65130 --- a/include/net/irda/ircomm_tty.h
65131 +++ b/include/net/irda/ircomm_tty.h
65132 @@ -35,6 +35,7 @@
65133 #include <linux/termios.h>
65134 #include <linux/timer.h>
65135 #include <linux/tty.h> /* struct tty_struct */
65136 +#include <asm/local.h>
65137
65138 #include <net/irda/irias_object.h>
65139 #include <net/irda/ircomm_core.h>
65140 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65141 unsigned short close_delay;
65142 unsigned short closing_wait; /* time to wait before closing */
65143
65144 - int open_count;
65145 - int blocked_open; /* # of blocked opens */
65146 + local_t open_count;
65147 + local_t blocked_open; /* # of blocked opens */
65148
65149 /* Protect concurent access to :
65150 * o self->open_count
65151 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65152 index cc7c197..9f2da2a 100644
65153 --- a/include/net/iucv/af_iucv.h
65154 +++ b/include/net/iucv/af_iucv.h
65155 @@ -141,7 +141,7 @@ struct iucv_sock {
65156 struct iucv_sock_list {
65157 struct hlist_head head;
65158 rwlock_t lock;
65159 - atomic_t autobind_name;
65160 + atomic_unchecked_t autobind_name;
65161 };
65162
65163 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65164 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65165 index 344d898..2ae1302 100644
65166 --- a/include/net/neighbour.h
65167 +++ b/include/net/neighbour.h
65168 @@ -123,7 +123,7 @@ struct neigh_ops {
65169 void (*error_report)(struct neighbour *, struct sk_buff *);
65170 int (*output)(struct neighbour *, struct sk_buff *);
65171 int (*connected_output)(struct neighbour *, struct sk_buff *);
65172 -};
65173 +} __do_const;
65174
65175 struct pneigh_entry {
65176 struct pneigh_entry *next;
65177 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65178 index fd87963..312a11f 100644
65179 --- a/include/net/net_namespace.h
65180 +++ b/include/net/net_namespace.h
65181 @@ -102,7 +102,7 @@ struct net {
65182 #endif
65183 struct netns_ipvs *ipvs;
65184 struct sock *diag_nlsk;
65185 - atomic_t rt_genid;
65186 + atomic_unchecked_t rt_genid;
65187 };
65188
65189
65190 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65191
65192 static inline int rt_genid(struct net *net)
65193 {
65194 - return atomic_read(&net->rt_genid);
65195 + return atomic_read_unchecked(&net->rt_genid);
65196 }
65197
65198 static inline void rt_genid_bump(struct net *net)
65199 {
65200 - atomic_inc(&net->rt_genid);
65201 + atomic_inc_unchecked(&net->rt_genid);
65202 }
65203
65204 #endif /* __NET_NET_NAMESPACE_H */
65205 diff --git a/include/net/netdma.h b/include/net/netdma.h
65206 index 8ba8ce2..99b7fff 100644
65207 --- a/include/net/netdma.h
65208 +++ b/include/net/netdma.h
65209 @@ -24,7 +24,7 @@
65210 #include <linux/dmaengine.h>
65211 #include <linux/skbuff.h>
65212
65213 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65214 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65215 struct sk_buff *skb, int offset, struct iovec *to,
65216 size_t len, struct dma_pinned_list *pinned_list);
65217
65218 diff --git a/include/net/netlink.h b/include/net/netlink.h
65219 index 785f37a..c81dc0c 100644
65220 --- a/include/net/netlink.h
65221 +++ b/include/net/netlink.h
65222 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65223 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65224 {
65225 if (mark)
65226 - skb_trim(skb, (unsigned char *) mark - skb->data);
65227 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65228 }
65229
65230 /**
65231 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65232 index eb24dbc..567d6ed 100644
65233 --- a/include/net/netns/ipv4.h
65234 +++ b/include/net/netns/ipv4.h
65235 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65236 unsigned int sysctl_ping_group_range[2];
65237 long sysctl_tcp_mem[3];
65238
65239 - atomic_t dev_addr_genid;
65240 + atomic_unchecked_t dev_addr_genid;
65241
65242 #ifdef CONFIG_IP_MROUTE
65243 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65244 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65245 index ff49964..1411fee 100644
65246 --- a/include/net/sctp/sctp.h
65247 +++ b/include/net/sctp/sctp.h
65248 @@ -320,9 +320,9 @@ do { \
65249
65250 #else /* SCTP_DEBUG */
65251
65252 -#define SCTP_DEBUG_PRINTK(whatever...)
65253 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65254 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65255 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65256 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65257 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65258 #define SCTP_ENABLE_DEBUG
65259 #define SCTP_DISABLE_DEBUG
65260 #define SCTP_ASSERT(expr, str, func)
65261 diff --git a/include/net/sock.h b/include/net/sock.h
65262 index adb7da2..1100002 100644
65263 --- a/include/net/sock.h
65264 +++ b/include/net/sock.h
65265 @@ -305,7 +305,7 @@ struct sock {
65266 #ifdef CONFIG_RPS
65267 __u32 sk_rxhash;
65268 #endif
65269 - atomic_t sk_drops;
65270 + atomic_unchecked_t sk_drops;
65271 int sk_rcvbuf;
65272
65273 struct sk_filter __rcu *sk_filter;
65274 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65275 }
65276
65277 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65278 - char __user *from, char *to,
65279 + char __user *from, unsigned char *to,
65280 int copy, int offset)
65281 {
65282 if (skb->ip_summed == CHECKSUM_NONE) {
65283 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65284 }
65285 }
65286
65287 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65288 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65289
65290 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65291 {
65292 diff --git a/include/net/tcp.h b/include/net/tcp.h
65293 index 1f000ff..e5a8dfb 100644
65294 --- a/include/net/tcp.h
65295 +++ b/include/net/tcp.h
65296 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65297 extern void tcp_xmit_retransmit_queue(struct sock *);
65298 extern void tcp_simple_retransmit(struct sock *);
65299 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65300 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65301 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65302
65303 extern void tcp_send_probe0(struct sock *);
65304 extern void tcp_send_partial(struct sock *);
65305 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65306 struct inet6_skb_parm h6;
65307 #endif
65308 } header; /* For incoming frames */
65309 - __u32 seq; /* Starting sequence number */
65310 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65311 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65312 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65313 __u32 when; /* used to compute rtt's */
65314 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65315
65316 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65317
65318 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65319 /* 1 byte hole */
65320 - __u32 ack_seq; /* Sequence number ACK'd */
65321 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65322 };
65323
65324 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65325 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65326 char *name;
65327 sa_family_t family;
65328 const struct file_operations *seq_fops;
65329 - struct seq_operations seq_ops;
65330 + seq_operations_no_const seq_ops;
65331 };
65332
65333 struct tcp_iter_state {
65334 diff --git a/include/net/udp.h b/include/net/udp.h
65335 index 065f379..b661b40 100644
65336 --- a/include/net/udp.h
65337 +++ b/include/net/udp.h
65338 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65339 sa_family_t family;
65340 struct udp_table *udp_table;
65341 const struct file_operations *seq_fops;
65342 - struct seq_operations seq_ops;
65343 + seq_operations_no_const seq_ops;
65344 };
65345
65346 struct udp_iter_state {
65347 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65348 index 639dd13..15b206c 100644
65349 --- a/include/net/xfrm.h
65350 +++ b/include/net/xfrm.h
65351 @@ -514,7 +514,7 @@ struct xfrm_policy {
65352 struct timer_list timer;
65353
65354 struct flow_cache_object flo;
65355 - atomic_t genid;
65356 + atomic_unchecked_t genid;
65357 u32 priority;
65358 u32 index;
65359 struct xfrm_mark mark;
65360 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65361 index 1a046b1..ee0bef0 100644
65362 --- a/include/rdma/iw_cm.h
65363 +++ b/include/rdma/iw_cm.h
65364 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65365 int backlog);
65366
65367 int (*destroy_listen)(struct iw_cm_id *cm_id);
65368 -};
65369 +} __no_const;
65370
65371 /**
65372 * iw_create_cm_id - Create an IW CM identifier.
65373 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65374 index 399162b..b337f1a 100644
65375 --- a/include/scsi/libfc.h
65376 +++ b/include/scsi/libfc.h
65377 @@ -762,6 +762,7 @@ struct libfc_function_template {
65378 */
65379 void (*disc_stop_final) (struct fc_lport *);
65380 };
65381 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65382
65383 /**
65384 * struct fc_disc - Discovery context
65385 @@ -866,7 +867,7 @@ struct fc_lport {
65386 struct fc_vport *vport;
65387
65388 /* Operational Information */
65389 - struct libfc_function_template tt;
65390 + libfc_function_template_no_const tt;
65391 u8 link_up;
65392 u8 qfull;
65393 enum fc_lport_state state;
65394 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65395 index 9895f69..f1418f0 100644
65396 --- a/include/scsi/scsi_device.h
65397 +++ b/include/scsi/scsi_device.h
65398 @@ -166,9 +166,9 @@ struct scsi_device {
65399 unsigned int max_device_blocked; /* what device_blocked counts down from */
65400 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65401
65402 - atomic_t iorequest_cnt;
65403 - atomic_t iodone_cnt;
65404 - atomic_t ioerr_cnt;
65405 + atomic_unchecked_t iorequest_cnt;
65406 + atomic_unchecked_t iodone_cnt;
65407 + atomic_unchecked_t ioerr_cnt;
65408
65409 struct device sdev_gendev,
65410 sdev_dev;
65411 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65412 index b797e8f..8e2c3aa 100644
65413 --- a/include/scsi/scsi_transport_fc.h
65414 +++ b/include/scsi/scsi_transport_fc.h
65415 @@ -751,7 +751,8 @@ struct fc_function_template {
65416 unsigned long show_host_system_hostname:1;
65417
65418 unsigned long disable_target_scan:1;
65419 -};
65420 +} __do_const;
65421 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65422
65423
65424 /**
65425 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65426 index 030b87c..98a6954 100644
65427 --- a/include/sound/ak4xxx-adda.h
65428 +++ b/include/sound/ak4xxx-adda.h
65429 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65430 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65431 unsigned char val);
65432 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65433 -};
65434 +} __no_const;
65435
65436 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65437
65438 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65439 index 8c05e47..2b5df97 100644
65440 --- a/include/sound/hwdep.h
65441 +++ b/include/sound/hwdep.h
65442 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65443 struct snd_hwdep_dsp_status *status);
65444 int (*dsp_load)(struct snd_hwdep *hw,
65445 struct snd_hwdep_dsp_image *image);
65446 -};
65447 +} __no_const;
65448
65449 struct snd_hwdep {
65450 struct snd_card *card;
65451 diff --git a/include/sound/info.h b/include/sound/info.h
65452 index 9ca1a49..aba1728 100644
65453 --- a/include/sound/info.h
65454 +++ b/include/sound/info.h
65455 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65456 struct snd_info_buffer *buffer);
65457 void (*write)(struct snd_info_entry *entry,
65458 struct snd_info_buffer *buffer);
65459 -};
65460 +} __no_const;
65461
65462 struct snd_info_entry_ops {
65463 int (*open)(struct snd_info_entry *entry,
65464 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65465 index cdca2ab..10bbe05 100644
65466 --- a/include/sound/pcm.h
65467 +++ b/include/sound/pcm.h
65468 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65469 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65470 int (*ack)(struct snd_pcm_substream *substream);
65471 };
65472 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65473
65474 /*
65475 *
65476 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65477 index af1b49e..a5d55a5 100644
65478 --- a/include/sound/sb16_csp.h
65479 +++ b/include/sound/sb16_csp.h
65480 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65481 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65482 int (*csp_stop) (struct snd_sb_csp * p);
65483 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65484 -};
65485 +} __no_const;
65486
65487 /*
65488 * CSP private data
65489 diff --git a/include/sound/soc.h b/include/sound/soc.h
65490 index e063380..e8077d5 100644
65491 --- a/include/sound/soc.h
65492 +++ b/include/sound/soc.h
65493 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65494 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65495 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65496 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65497 -};
65498 +} __do_const;
65499
65500 struct snd_soc_platform {
65501 const char *name;
65502 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65503 struct snd_soc_dai_link *dai_link;
65504 struct mutex pcm_mutex;
65505 enum snd_soc_pcm_subclass pcm_subclass;
65506 - struct snd_pcm_ops ops;
65507 + snd_pcm_ops_no_const ops;
65508
65509 unsigned int dev_registered:1;
65510
65511 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65512 index fe8590c..aaed363 100644
65513 --- a/include/sound/tea575x-tuner.h
65514 +++ b/include/sound/tea575x-tuner.h
65515 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65516
65517 struct snd_tea575x {
65518 struct v4l2_device *v4l2_dev;
65519 - struct v4l2_file_operations fops;
65520 + v4l2_file_operations_no_const fops;
65521 struct video_device vd; /* video device */
65522 int radio_nr; /* radio_nr */
65523 bool tea5759; /* 5759 chip is present */
65524 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65525 index 5be8937..a8e46e9 100644
65526 --- a/include/target/target_core_base.h
65527 +++ b/include/target/target_core_base.h
65528 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65529 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65530 int (*t10_pr_register)(struct se_cmd *);
65531 int (*t10_pr_clear)(struct se_cmd *);
65532 -};
65533 +} __no_const;
65534
65535 struct t10_reservation {
65536 /* Reservation effects all target ports */
65537 @@ -758,7 +758,7 @@ struct se_device {
65538 spinlock_t stats_lock;
65539 /* Active commands on this virtual SE device */
65540 atomic_t simple_cmds;
65541 - atomic_t dev_ordered_id;
65542 + atomic_unchecked_t dev_ordered_id;
65543 atomic_t dev_ordered_sync;
65544 atomic_t dev_qf_count;
65545 struct se_obj dev_obj;
65546 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65547 new file mode 100644
65548 index 0000000..2efe49d
65549 --- /dev/null
65550 +++ b/include/trace/events/fs.h
65551 @@ -0,0 +1,53 @@
65552 +#undef TRACE_SYSTEM
65553 +#define TRACE_SYSTEM fs
65554 +
65555 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65556 +#define _TRACE_FS_H
65557 +
65558 +#include <linux/fs.h>
65559 +#include <linux/tracepoint.h>
65560 +
65561 +TRACE_EVENT(do_sys_open,
65562 +
65563 + TP_PROTO(char *filename, int flags, int mode),
65564 +
65565 + TP_ARGS(filename, flags, mode),
65566 +
65567 + TP_STRUCT__entry(
65568 + __string( filename, filename )
65569 + __field( int, flags )
65570 + __field( int, mode )
65571 + ),
65572 +
65573 + TP_fast_assign(
65574 + __assign_str(filename, filename);
65575 + __entry->flags = flags;
65576 + __entry->mode = mode;
65577 + ),
65578 +
65579 + TP_printk("\"%s\" %x %o",
65580 + __get_str(filename), __entry->flags, __entry->mode)
65581 +);
65582 +
65583 +TRACE_EVENT(open_exec,
65584 +
65585 + TP_PROTO(const char *filename),
65586 +
65587 + TP_ARGS(filename),
65588 +
65589 + TP_STRUCT__entry(
65590 + __string( filename, filename )
65591 + ),
65592 +
65593 + TP_fast_assign(
65594 + __assign_str(filename, filename);
65595 + ),
65596 +
65597 + TP_printk("\"%s\"",
65598 + __get_str(filename))
65599 +);
65600 +
65601 +#endif /* _TRACE_FS_H */
65602 +
65603 +/* This part must be outside protection */
65604 +#include <trace/define_trace.h>
65605 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65606 index 1c09820..7f5ec79 100644
65607 --- a/include/trace/events/irq.h
65608 +++ b/include/trace/events/irq.h
65609 @@ -36,7 +36,7 @@ struct softirq_action;
65610 */
65611 TRACE_EVENT(irq_handler_entry,
65612
65613 - TP_PROTO(int irq, struct irqaction *action),
65614 + TP_PROTO(int irq, const struct irqaction *action),
65615
65616 TP_ARGS(irq, action),
65617
65618 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65619 */
65620 TRACE_EVENT(irq_handler_exit,
65621
65622 - TP_PROTO(int irq, struct irqaction *action, int ret),
65623 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65624
65625 TP_ARGS(irq, action, ret),
65626
65627 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65628 index f9466fa..f4e2b81 100644
65629 --- a/include/video/udlfb.h
65630 +++ b/include/video/udlfb.h
65631 @@ -53,10 +53,10 @@ struct dlfb_data {
65632 u32 pseudo_palette[256];
65633 int blank_mode; /*one of FB_BLANK_ */
65634 /* blit-only rendering path metrics, exposed through sysfs */
65635 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65636 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65637 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65638 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65639 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65640 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65641 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65642 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65643 };
65644
65645 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65646 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65647 index 0993a22..32ba2fe 100644
65648 --- a/include/video/uvesafb.h
65649 +++ b/include/video/uvesafb.h
65650 @@ -177,6 +177,7 @@ struct uvesafb_par {
65651 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65652 u8 pmi_setpal; /* PMI for palette changes */
65653 u16 *pmi_base; /* protected mode interface location */
65654 + u8 *pmi_code; /* protected mode code location */
65655 void *pmi_start;
65656 void *pmi_pal;
65657 u8 *vbe_state_orig; /*
65658 diff --git a/init/Kconfig b/init/Kconfig
65659 index af6c7f8..5c188f8 100644
65660 --- a/init/Kconfig
65661 +++ b/init/Kconfig
65662 @@ -850,6 +850,7 @@ endif # CGROUPS
65663
65664 config CHECKPOINT_RESTORE
65665 bool "Checkpoint/restore support" if EXPERT
65666 + depends on !GRKERNSEC
65667 default n
65668 help
65669 Enables additional kernel features in a sake of checkpoint/restore.
65670 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65671 # Security modules
65672 depends on SECURITY_TOMOYO = n
65673 depends on SECURITY_APPARMOR = n
65674 + depends on GRKERNSEC = n
65675
65676 config UIDGID_STRICT_TYPE_CHECKS
65677 bool "Require conversions between uid/gids and their internal representation"
65678 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65679
65680 config COMPAT_BRK
65681 bool "Disable heap randomization"
65682 - default y
65683 + default n
65684 help
65685 Randomizing heap placement makes heap exploits harder, but it
65686 also breaks ancient binaries (including anything libc5 based).
65687 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65688 config STOP_MACHINE
65689 bool
65690 default y
65691 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65692 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65693 help
65694 Need stop_machine() primitive.
65695
65696 diff --git a/init/Makefile b/init/Makefile
65697 index 7bc47ee..6da2dc7 100644
65698 --- a/init/Makefile
65699 +++ b/init/Makefile
65700 @@ -2,6 +2,9 @@
65701 # Makefile for the linux kernel.
65702 #
65703
65704 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65705 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65706 +
65707 obj-y := main.o version.o mounts.o
65708 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65709 obj-y += noinitramfs.o
65710 diff --git a/init/do_mounts.c b/init/do_mounts.c
65711 index d3f0aee..c9322f5 100644
65712 --- a/init/do_mounts.c
65713 +++ b/init/do_mounts.c
65714 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65715 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65716 {
65717 struct super_block *s;
65718 - int err = sys_mount(name, "/root", fs, flags, data);
65719 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65720 if (err)
65721 return err;
65722
65723 - sys_chdir("/root");
65724 + sys_chdir((const char __force_user *)"/root");
65725 s = current->fs->pwd.dentry->d_sb;
65726 ROOT_DEV = s->s_dev;
65727 printk(KERN_INFO
65728 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65729 va_start(args, fmt);
65730 vsprintf(buf, fmt, args);
65731 va_end(args);
65732 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65733 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65734 if (fd >= 0) {
65735 sys_ioctl(fd, FDEJECT, 0);
65736 sys_close(fd);
65737 }
65738 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65739 - fd = sys_open("/dev/console", O_RDWR, 0);
65740 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65741 if (fd >= 0) {
65742 sys_ioctl(fd, TCGETS, (long)&termios);
65743 termios.c_lflag &= ~ICANON;
65744 sys_ioctl(fd, TCSETSF, (long)&termios);
65745 - sys_read(fd, &c, 1);
65746 + sys_read(fd, (char __user *)&c, 1);
65747 termios.c_lflag |= ICANON;
65748 sys_ioctl(fd, TCSETSF, (long)&termios);
65749 sys_close(fd);
65750 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65751 mount_root();
65752 out:
65753 devtmpfs_mount("dev");
65754 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65755 - sys_chroot(".");
65756 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65757 + sys_chroot((const char __force_user *)".");
65758 }
65759 diff --git a/init/do_mounts.h b/init/do_mounts.h
65760 index f5b978a..69dbfe8 100644
65761 --- a/init/do_mounts.h
65762 +++ b/init/do_mounts.h
65763 @@ -15,15 +15,15 @@ extern int root_mountflags;
65764
65765 static inline int create_dev(char *name, dev_t dev)
65766 {
65767 - sys_unlink(name);
65768 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65769 + sys_unlink((char __force_user *)name);
65770 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65771 }
65772
65773 #if BITS_PER_LONG == 32
65774 static inline u32 bstat(char *name)
65775 {
65776 struct stat64 stat;
65777 - if (sys_stat64(name, &stat) != 0)
65778 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65779 return 0;
65780 if (!S_ISBLK(stat.st_mode))
65781 return 0;
65782 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65783 static inline u32 bstat(char *name)
65784 {
65785 struct stat stat;
65786 - if (sys_newstat(name, &stat) != 0)
65787 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65788 return 0;
65789 if (!S_ISBLK(stat.st_mode))
65790 return 0;
65791 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65792 index 135959a2..28a3f43 100644
65793 --- a/init/do_mounts_initrd.c
65794 +++ b/init/do_mounts_initrd.c
65795 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65796 create_dev("/dev/root.old", Root_RAM0);
65797 /* mount initrd on rootfs' /root */
65798 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65799 - sys_mkdir("/old", 0700);
65800 - root_fd = sys_open("/", 0, 0);
65801 - old_fd = sys_open("/old", 0, 0);
65802 + sys_mkdir((const char __force_user *)"/old", 0700);
65803 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65804 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65805 /* move initrd over / and chdir/chroot in initrd root */
65806 - sys_chdir("/root");
65807 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65808 - sys_chroot(".");
65809 + sys_chdir((const char __force_user *)"/root");
65810 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65811 + sys_chroot((const char __force_user *)".");
65812
65813 /*
65814 * In case that a resume from disk is carried out by linuxrc or one of
65815 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65816
65817 /* move initrd to rootfs' /old */
65818 sys_fchdir(old_fd);
65819 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65820 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65821 /* switch root and cwd back to / of rootfs */
65822 sys_fchdir(root_fd);
65823 - sys_chroot(".");
65824 + sys_chroot((const char __force_user *)".");
65825 sys_close(old_fd);
65826 sys_close(root_fd);
65827
65828 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65829 - sys_chdir("/old");
65830 + sys_chdir((const char __force_user *)"/old");
65831 return;
65832 }
65833
65834 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65835 mount_root();
65836
65837 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65838 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65839 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65840 if (!error)
65841 printk("okay\n");
65842 else {
65843 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65844 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65845 if (error == -ENOENT)
65846 printk("/initrd does not exist. Ignored.\n");
65847 else
65848 printk("failed\n");
65849 printk(KERN_NOTICE "Unmounting old root\n");
65850 - sys_umount("/old", MNT_DETACH);
65851 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65852 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65853 if (fd < 0) {
65854 error = fd;
65855 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65856 * mounted in the normal path.
65857 */
65858 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65859 - sys_unlink("/initrd.image");
65860 + sys_unlink((const char __force_user *)"/initrd.image");
65861 handle_initrd();
65862 return 1;
65863 }
65864 }
65865 - sys_unlink("/initrd.image");
65866 + sys_unlink((const char __force_user *)"/initrd.image");
65867 return 0;
65868 }
65869 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65870 index 8cb6db5..d729f50 100644
65871 --- a/init/do_mounts_md.c
65872 +++ b/init/do_mounts_md.c
65873 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65874 partitioned ? "_d" : "", minor,
65875 md_setup_args[ent].device_names);
65876
65877 - fd = sys_open(name, 0, 0);
65878 + fd = sys_open((char __force_user *)name, 0, 0);
65879 if (fd < 0) {
65880 printk(KERN_ERR "md: open failed - cannot start "
65881 "array %s\n", name);
65882 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65883 * array without it
65884 */
65885 sys_close(fd);
65886 - fd = sys_open(name, 0, 0);
65887 + fd = sys_open((char __force_user *)name, 0, 0);
65888 sys_ioctl(fd, BLKRRPART, 0);
65889 }
65890 sys_close(fd);
65891 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65892
65893 wait_for_device_probe();
65894
65895 - fd = sys_open("/dev/md0", 0, 0);
65896 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65897 if (fd >= 0) {
65898 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65899 sys_close(fd);
65900 diff --git a/init/init_task.c b/init/init_task.c
65901 index 8b2f399..f0797c9 100644
65902 --- a/init/init_task.c
65903 +++ b/init/init_task.c
65904 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65905 * Initial thread structure. Alignment of this is handled by a special
65906 * linker map entry.
65907 */
65908 +#ifdef CONFIG_X86
65909 +union thread_union init_thread_union __init_task_data;
65910 +#else
65911 union thread_union init_thread_union __init_task_data =
65912 { INIT_THREAD_INFO(init_task) };
65913 +#endif
65914 diff --git a/init/initramfs.c b/init/initramfs.c
65915 index 84c6bf1..8899338 100644
65916 --- a/init/initramfs.c
65917 +++ b/init/initramfs.c
65918 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65919 }
65920 }
65921
65922 -static long __init do_utime(char *filename, time_t mtime)
65923 +static long __init do_utime(char __force_user *filename, time_t mtime)
65924 {
65925 struct timespec t[2];
65926
65927 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65928 struct dir_entry *de, *tmp;
65929 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65930 list_del(&de->list);
65931 - do_utime(de->name, de->mtime);
65932 + do_utime((char __force_user *)de->name, de->mtime);
65933 kfree(de->name);
65934 kfree(de);
65935 }
65936 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65937 if (nlink >= 2) {
65938 char *old = find_link(major, minor, ino, mode, collected);
65939 if (old)
65940 - return (sys_link(old, collected) < 0) ? -1 : 1;
65941 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65942 }
65943 return 0;
65944 }
65945 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65946 {
65947 struct stat st;
65948
65949 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65950 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65951 if (S_ISDIR(st.st_mode))
65952 - sys_rmdir(path);
65953 + sys_rmdir((char __force_user *)path);
65954 else
65955 - sys_unlink(path);
65956 + sys_unlink((char __force_user *)path);
65957 }
65958 }
65959
65960 @@ -315,7 +315,7 @@ static int __init do_name(void)
65961 int openflags = O_WRONLY|O_CREAT;
65962 if (ml != 1)
65963 openflags |= O_TRUNC;
65964 - wfd = sys_open(collected, openflags, mode);
65965 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65966
65967 if (wfd >= 0) {
65968 sys_fchown(wfd, uid, gid);
65969 @@ -327,17 +327,17 @@ static int __init do_name(void)
65970 }
65971 }
65972 } else if (S_ISDIR(mode)) {
65973 - sys_mkdir(collected, mode);
65974 - sys_chown(collected, uid, gid);
65975 - sys_chmod(collected, mode);
65976 + sys_mkdir((char __force_user *)collected, mode);
65977 + sys_chown((char __force_user *)collected, uid, gid);
65978 + sys_chmod((char __force_user *)collected, mode);
65979 dir_add(collected, mtime);
65980 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65981 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65982 if (maybe_link() == 0) {
65983 - sys_mknod(collected, mode, rdev);
65984 - sys_chown(collected, uid, gid);
65985 - sys_chmod(collected, mode);
65986 - do_utime(collected, mtime);
65987 + sys_mknod((char __force_user *)collected, mode, rdev);
65988 + sys_chown((char __force_user *)collected, uid, gid);
65989 + sys_chmod((char __force_user *)collected, mode);
65990 + do_utime((char __force_user *)collected, mtime);
65991 }
65992 }
65993 return 0;
65994 @@ -346,15 +346,15 @@ static int __init do_name(void)
65995 static int __init do_copy(void)
65996 {
65997 if (count >= body_len) {
65998 - sys_write(wfd, victim, body_len);
65999 + sys_write(wfd, (char __force_user *)victim, body_len);
66000 sys_close(wfd);
66001 - do_utime(vcollected, mtime);
66002 + do_utime((char __force_user *)vcollected, mtime);
66003 kfree(vcollected);
66004 eat(body_len);
66005 state = SkipIt;
66006 return 0;
66007 } else {
66008 - sys_write(wfd, victim, count);
66009 + sys_write(wfd, (char __force_user *)victim, count);
66010 body_len -= count;
66011 eat(count);
66012 return 1;
66013 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66014 {
66015 collected[N_ALIGN(name_len) + body_len] = '\0';
66016 clean_path(collected, 0);
66017 - sys_symlink(collected + N_ALIGN(name_len), collected);
66018 - sys_lchown(collected, uid, gid);
66019 - do_utime(collected, mtime);
66020 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66021 + sys_lchown((char __force_user *)collected, uid, gid);
66022 + do_utime((char __force_user *)collected, mtime);
66023 state = SkipIt;
66024 next_state = Reset;
66025 return 0;
66026 diff --git a/init/main.c b/init/main.c
66027 index b286730..9ff6135 100644
66028 --- a/init/main.c
66029 +++ b/init/main.c
66030 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66031 extern void tc_init(void);
66032 #endif
66033
66034 +extern void grsecurity_init(void);
66035 +
66036 /*
66037 * Debug helper: via this flag we know that we are in 'early bootup code'
66038 * where only the boot processor is running with IRQ disabled. This means
66039 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66040
66041 __setup("reset_devices", set_reset_devices);
66042
66043 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66044 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66045 +static int __init setup_grsec_proc_gid(char *str)
66046 +{
66047 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66048 + return 1;
66049 +}
66050 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66051 +#endif
66052 +
66053 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66054 +extern char pax_enter_kernel_user[];
66055 +extern char pax_exit_kernel_user[];
66056 +extern pgdval_t clone_pgd_mask;
66057 +#endif
66058 +
66059 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66060 +static int __init setup_pax_nouderef(char *str)
66061 +{
66062 +#ifdef CONFIG_X86_32
66063 + unsigned int cpu;
66064 + struct desc_struct *gdt;
66065 +
66066 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66067 + gdt = get_cpu_gdt_table(cpu);
66068 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66069 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66070 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66071 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66072 + }
66073 + loadsegment(ds, __KERNEL_DS);
66074 + loadsegment(es, __KERNEL_DS);
66075 + loadsegment(ss, __KERNEL_DS);
66076 +#else
66077 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66078 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66079 + clone_pgd_mask = ~(pgdval_t)0UL;
66080 +#endif
66081 +
66082 + return 0;
66083 +}
66084 +early_param("pax_nouderef", setup_pax_nouderef);
66085 +#endif
66086 +
66087 +#ifdef CONFIG_PAX_SOFTMODE
66088 +int pax_softmode;
66089 +
66090 +static int __init setup_pax_softmode(char *str)
66091 +{
66092 + get_option(&str, &pax_softmode);
66093 + return 1;
66094 +}
66095 +__setup("pax_softmode=", setup_pax_softmode);
66096 +#endif
66097 +
66098 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66099 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66100 static const char *panic_later, *panic_param;
66101 @@ -675,6 +732,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66102 {
66103 int count = preempt_count();
66104 int ret;
66105 + const char *msg1 = "", *msg2 = "";
66106
66107 if (initcall_debug)
66108 ret = do_one_initcall_debug(fn);
66109 @@ -687,15 +745,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66110 sprintf(msgbuf, "error code %d ", ret);
66111
66112 if (preempt_count() != count) {
66113 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66114 + msg1 = " preemption imbalance";
66115 preempt_count() = count;
66116 }
66117 if (irqs_disabled()) {
66118 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66119 + msg2 = " disabled interrupts";
66120 local_irq_enable();
66121 }
66122 - if (msgbuf[0]) {
66123 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66124 + if (msgbuf[0] || *msg1 || *msg2) {
66125 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66126 }
66127
66128 return ret;
66129 @@ -749,8 +807,14 @@ static void __init do_initcall_level(int level)
66130 level, level,
66131 &repair_env_string);
66132
66133 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66134 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66135 do_one_initcall(*fn);
66136 +
66137 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66138 + transfer_latent_entropy();
66139 +#endif
66140 +
66141 + }
66142 }
66143
66144 static void __init do_initcalls(void)
66145 @@ -784,8 +848,14 @@ static void __init do_pre_smp_initcalls(void)
66146 {
66147 initcall_t *fn;
66148
66149 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66150 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66151 do_one_initcall(*fn);
66152 +
66153 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66154 + transfer_latent_entropy();
66155 +#endif
66156 +
66157 + }
66158 }
66159
66160 static void run_init_process(const char *init_filename)
66161 @@ -867,7 +937,7 @@ static int __init kernel_init(void * unused)
66162 do_basic_setup();
66163
66164 /* Open the /dev/console on the rootfs, this should never fail */
66165 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66166 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66167 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66168
66169 (void) sys_dup(0);
66170 @@ -880,11 +950,13 @@ static int __init kernel_init(void * unused)
66171 if (!ramdisk_execute_command)
66172 ramdisk_execute_command = "/init";
66173
66174 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66175 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66176 ramdisk_execute_command = NULL;
66177 prepare_namespace();
66178 }
66179
66180 + grsecurity_init();
66181 +
66182 /*
66183 * Ok, we have completed the initial bootup, and
66184 * we're essentially up and running. Get rid of the
66185 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66186 index 9a08acc..e65ebe7 100644
66187 --- a/ipc/mqueue.c
66188 +++ b/ipc/mqueue.c
66189 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66190 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66191 info->attr.mq_msgsize);
66192
66193 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66194 spin_lock(&mq_lock);
66195 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66196 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66197 diff --git a/ipc/msg.c b/ipc/msg.c
66198 index 7385de2..a8180e08 100644
66199 --- a/ipc/msg.c
66200 +++ b/ipc/msg.c
66201 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66202 return security_msg_queue_associate(msq, msgflg);
66203 }
66204
66205 +static struct ipc_ops msg_ops = {
66206 + .getnew = newque,
66207 + .associate = msg_security,
66208 + .more_checks = NULL
66209 +};
66210 +
66211 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66212 {
66213 struct ipc_namespace *ns;
66214 - struct ipc_ops msg_ops;
66215 struct ipc_params msg_params;
66216
66217 ns = current->nsproxy->ipc_ns;
66218
66219 - msg_ops.getnew = newque;
66220 - msg_ops.associate = msg_security;
66221 - msg_ops.more_checks = NULL;
66222 -
66223 msg_params.key = key;
66224 msg_params.flg = msgflg;
66225
66226 diff --git a/ipc/sem.c b/ipc/sem.c
66227 index 5215a81..cfc0cac 100644
66228 --- a/ipc/sem.c
66229 +++ b/ipc/sem.c
66230 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66231 return 0;
66232 }
66233
66234 +static struct ipc_ops sem_ops = {
66235 + .getnew = newary,
66236 + .associate = sem_security,
66237 + .more_checks = sem_more_checks
66238 +};
66239 +
66240 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66241 {
66242 struct ipc_namespace *ns;
66243 - struct ipc_ops sem_ops;
66244 struct ipc_params sem_params;
66245
66246 ns = current->nsproxy->ipc_ns;
66247 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66248 if (nsems < 0 || nsems > ns->sc_semmsl)
66249 return -EINVAL;
66250
66251 - sem_ops.getnew = newary;
66252 - sem_ops.associate = sem_security;
66253 - sem_ops.more_checks = sem_more_checks;
66254 -
66255 sem_params.key = key;
66256 sem_params.flg = semflg;
66257 sem_params.u.nsems = nsems;
66258 diff --git a/ipc/shm.c b/ipc/shm.c
66259 index 00faa05..7040960 100644
66260 --- a/ipc/shm.c
66261 +++ b/ipc/shm.c
66262 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66263 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66264 #endif
66265
66266 +#ifdef CONFIG_GRKERNSEC
66267 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66268 + const time_t shm_createtime, const uid_t cuid,
66269 + const int shmid);
66270 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66271 + const time_t shm_createtime);
66272 +#endif
66273 +
66274 void shm_init_ns(struct ipc_namespace *ns)
66275 {
66276 ns->shm_ctlmax = SHMMAX;
66277 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66278 shp->shm_lprid = 0;
66279 shp->shm_atim = shp->shm_dtim = 0;
66280 shp->shm_ctim = get_seconds();
66281 +#ifdef CONFIG_GRKERNSEC
66282 + {
66283 + struct timespec timeval;
66284 + do_posix_clock_monotonic_gettime(&timeval);
66285 +
66286 + shp->shm_createtime = timeval.tv_sec;
66287 + }
66288 +#endif
66289 shp->shm_segsz = size;
66290 shp->shm_nattch = 0;
66291 shp->shm_file = file;
66292 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66293 return 0;
66294 }
66295
66296 +static struct ipc_ops shm_ops = {
66297 + .getnew = newseg,
66298 + .associate = shm_security,
66299 + .more_checks = shm_more_checks
66300 +};
66301 +
66302 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66303 {
66304 struct ipc_namespace *ns;
66305 - struct ipc_ops shm_ops;
66306 struct ipc_params shm_params;
66307
66308 ns = current->nsproxy->ipc_ns;
66309
66310 - shm_ops.getnew = newseg;
66311 - shm_ops.associate = shm_security;
66312 - shm_ops.more_checks = shm_more_checks;
66313 -
66314 shm_params.key = key;
66315 shm_params.flg = shmflg;
66316 shm_params.u.size = size;
66317 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66318 f_mode = FMODE_READ | FMODE_WRITE;
66319 }
66320 if (shmflg & SHM_EXEC) {
66321 +
66322 +#ifdef CONFIG_PAX_MPROTECT
66323 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66324 + goto out;
66325 +#endif
66326 +
66327 prot |= PROT_EXEC;
66328 acc_mode |= S_IXUGO;
66329 }
66330 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66331 if (err)
66332 goto out_unlock;
66333
66334 +#ifdef CONFIG_GRKERNSEC
66335 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66336 + shp->shm_perm.cuid, shmid) ||
66337 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66338 + err = -EACCES;
66339 + goto out_unlock;
66340 + }
66341 +#endif
66342 +
66343 path = shp->shm_file->f_path;
66344 path_get(&path);
66345 shp->shm_nattch++;
66346 +#ifdef CONFIG_GRKERNSEC
66347 + shp->shm_lapid = current->pid;
66348 +#endif
66349 size = i_size_read(path.dentry->d_inode);
66350 shm_unlock(shp);
66351
66352 diff --git a/kernel/acct.c b/kernel/acct.c
66353 index 02e6167..54824f7 100644
66354 --- a/kernel/acct.c
66355 +++ b/kernel/acct.c
66356 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66357 */
66358 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66359 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66360 - file->f_op->write(file, (char *)&ac,
66361 + file->f_op->write(file, (char __force_user *)&ac,
66362 sizeof(acct_t), &file->f_pos);
66363 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66364 set_fs(fs);
66365 diff --git a/kernel/audit.c b/kernel/audit.c
66366 index a8c84be..8bd034c 100644
66367 --- a/kernel/audit.c
66368 +++ b/kernel/audit.c
66369 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66370 3) suppressed due to audit_rate_limit
66371 4) suppressed due to audit_backlog_limit
66372 */
66373 -static atomic_t audit_lost = ATOMIC_INIT(0);
66374 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66375
66376 /* The netlink socket. */
66377 static struct sock *audit_sock;
66378 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66379 unsigned long now;
66380 int print;
66381
66382 - atomic_inc(&audit_lost);
66383 + atomic_inc_unchecked(&audit_lost);
66384
66385 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66386
66387 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66388 printk(KERN_WARNING
66389 "audit: audit_lost=%d audit_rate_limit=%d "
66390 "audit_backlog_limit=%d\n",
66391 - atomic_read(&audit_lost),
66392 + atomic_read_unchecked(&audit_lost),
66393 audit_rate_limit,
66394 audit_backlog_limit);
66395 audit_panic(message);
66396 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66397 status_set.pid = audit_pid;
66398 status_set.rate_limit = audit_rate_limit;
66399 status_set.backlog_limit = audit_backlog_limit;
66400 - status_set.lost = atomic_read(&audit_lost);
66401 + status_set.lost = atomic_read_unchecked(&audit_lost);
66402 status_set.backlog = skb_queue_len(&audit_skb_queue);
66403 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66404 &status_set, sizeof(status_set));
66405 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66406 index 4b96415..d8c16ee 100644
66407 --- a/kernel/auditsc.c
66408 +++ b/kernel/auditsc.c
66409 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66410 }
66411
66412 /* global counter which is incremented every time something logs in */
66413 -static atomic_t session_id = ATOMIC_INIT(0);
66414 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66415
66416 /**
66417 * audit_set_loginuid - set current task's audit_context loginuid
66418 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66419 return -EPERM;
66420 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66421
66422 - sessionid = atomic_inc_return(&session_id);
66423 + sessionid = atomic_inc_return_unchecked(&session_id);
66424 if (context && context->in_syscall) {
66425 struct audit_buffer *ab;
66426
66427 diff --git a/kernel/capability.c b/kernel/capability.c
66428 index 493d972..ea17248 100644
66429 --- a/kernel/capability.c
66430 +++ b/kernel/capability.c
66431 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66432 * before modification is attempted and the application
66433 * fails.
66434 */
66435 + if (tocopy > ARRAY_SIZE(kdata))
66436 + return -EFAULT;
66437 +
66438 if (copy_to_user(dataptr, kdata, tocopy
66439 * sizeof(struct __user_cap_data_struct))) {
66440 return -EFAULT;
66441 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66442 int ret;
66443
66444 rcu_read_lock();
66445 - ret = security_capable(__task_cred(t), ns, cap);
66446 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66447 + gr_task_is_capable(t, __task_cred(t), cap);
66448 rcu_read_unlock();
66449
66450 - return (ret == 0);
66451 + return ret;
66452 }
66453
66454 /**
66455 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66456 int ret;
66457
66458 rcu_read_lock();
66459 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66460 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66461 rcu_read_unlock();
66462
66463 - return (ret == 0);
66464 + return ret;
66465 }
66466
66467 /**
66468 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66469 BUG();
66470 }
66471
66472 - if (security_capable(current_cred(), ns, cap) == 0) {
66473 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66474 current->flags |= PF_SUPERPRIV;
66475 return true;
66476 }
66477 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66478 }
66479 EXPORT_SYMBOL(ns_capable);
66480
66481 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66482 +{
66483 + if (unlikely(!cap_valid(cap))) {
66484 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66485 + BUG();
66486 + }
66487 +
66488 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66489 + current->flags |= PF_SUPERPRIV;
66490 + return true;
66491 + }
66492 + return false;
66493 +}
66494 +EXPORT_SYMBOL(ns_capable_nolog);
66495 +
66496 /**
66497 * capable - Determine if the current task has a superior capability in effect
66498 * @cap: The capability to be tested for
66499 @@ -408,6 +427,12 @@ bool capable(int cap)
66500 }
66501 EXPORT_SYMBOL(capable);
66502
66503 +bool capable_nolog(int cap)
66504 +{
66505 + return ns_capable_nolog(&init_user_ns, cap);
66506 +}
66507 +EXPORT_SYMBOL(capable_nolog);
66508 +
66509 /**
66510 * nsown_capable - Check superior capability to one's own user_ns
66511 * @cap: The capability in question
66512 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66513
66514 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66515 }
66516 +
66517 +bool inode_capable_nolog(const struct inode *inode, int cap)
66518 +{
66519 + struct user_namespace *ns = current_user_ns();
66520 +
66521 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66522 +}
66523 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66524 index 7981850..370878f 100644
66525 --- a/kernel/cgroup.c
66526 +++ b/kernel/cgroup.c
66527 @@ -5411,7 +5411,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66528 struct css_set *cg = link->cg;
66529 struct task_struct *task;
66530 int count = 0;
66531 - seq_printf(seq, "css_set %p\n", cg);
66532 + seq_printf(seq, "css_set %pK\n", cg);
66533 list_for_each_entry(task, &cg->tasks, cg_list) {
66534 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66535 seq_puts(seq, " ...\n");
66536 diff --git a/kernel/compat.c b/kernel/compat.c
66537 index c28a306..b4d0cf3 100644
66538 --- a/kernel/compat.c
66539 +++ b/kernel/compat.c
66540 @@ -13,6 +13,7 @@
66541
66542 #include <linux/linkage.h>
66543 #include <linux/compat.h>
66544 +#include <linux/module.h>
66545 #include <linux/errno.h>
66546 #include <linux/time.h>
66547 #include <linux/signal.h>
66548 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66549 mm_segment_t oldfs;
66550 long ret;
66551
66552 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66553 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66554 oldfs = get_fs();
66555 set_fs(KERNEL_DS);
66556 ret = hrtimer_nanosleep_restart(restart);
66557 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66558 oldfs = get_fs();
66559 set_fs(KERNEL_DS);
66560 ret = hrtimer_nanosleep(&tu,
66561 - rmtp ? (struct timespec __user *)&rmt : NULL,
66562 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66563 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66564 set_fs(oldfs);
66565
66566 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66567 mm_segment_t old_fs = get_fs();
66568
66569 set_fs(KERNEL_DS);
66570 - ret = sys_sigpending((old_sigset_t __user *) &s);
66571 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66572 set_fs(old_fs);
66573 if (ret == 0)
66574 ret = put_user(s, set);
66575 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66576 mm_segment_t old_fs = get_fs();
66577
66578 set_fs(KERNEL_DS);
66579 - ret = sys_old_getrlimit(resource, &r);
66580 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66581 set_fs(old_fs);
66582
66583 if (!ret) {
66584 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66585 mm_segment_t old_fs = get_fs();
66586
66587 set_fs(KERNEL_DS);
66588 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66589 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66590 set_fs(old_fs);
66591
66592 if (ret)
66593 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66594 set_fs (KERNEL_DS);
66595 ret = sys_wait4(pid,
66596 (stat_addr ?
66597 - (unsigned int __user *) &status : NULL),
66598 - options, (struct rusage __user *) &r);
66599 + (unsigned int __force_user *) &status : NULL),
66600 + options, (struct rusage __force_user *) &r);
66601 set_fs (old_fs);
66602
66603 if (ret > 0) {
66604 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66605 memset(&info, 0, sizeof(info));
66606
66607 set_fs(KERNEL_DS);
66608 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66609 - uru ? (struct rusage __user *)&ru : NULL);
66610 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66611 + uru ? (struct rusage __force_user *)&ru : NULL);
66612 set_fs(old_fs);
66613
66614 if ((ret < 0) || (info.si_signo == 0))
66615 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66616 oldfs = get_fs();
66617 set_fs(KERNEL_DS);
66618 err = sys_timer_settime(timer_id, flags,
66619 - (struct itimerspec __user *) &newts,
66620 - (struct itimerspec __user *) &oldts);
66621 + (struct itimerspec __force_user *) &newts,
66622 + (struct itimerspec __force_user *) &oldts);
66623 set_fs(oldfs);
66624 if (!err && old && put_compat_itimerspec(old, &oldts))
66625 return -EFAULT;
66626 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66627 oldfs = get_fs();
66628 set_fs(KERNEL_DS);
66629 err = sys_timer_gettime(timer_id,
66630 - (struct itimerspec __user *) &ts);
66631 + (struct itimerspec __force_user *) &ts);
66632 set_fs(oldfs);
66633 if (!err && put_compat_itimerspec(setting, &ts))
66634 return -EFAULT;
66635 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66636 oldfs = get_fs();
66637 set_fs(KERNEL_DS);
66638 err = sys_clock_settime(which_clock,
66639 - (struct timespec __user *) &ts);
66640 + (struct timespec __force_user *) &ts);
66641 set_fs(oldfs);
66642 return err;
66643 }
66644 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66645 oldfs = get_fs();
66646 set_fs(KERNEL_DS);
66647 err = sys_clock_gettime(which_clock,
66648 - (struct timespec __user *) &ts);
66649 + (struct timespec __force_user *) &ts);
66650 set_fs(oldfs);
66651 if (!err && put_compat_timespec(&ts, tp))
66652 return -EFAULT;
66653 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66654
66655 oldfs = get_fs();
66656 set_fs(KERNEL_DS);
66657 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66658 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66659 set_fs(oldfs);
66660
66661 err = compat_put_timex(utp, &txc);
66662 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66663 oldfs = get_fs();
66664 set_fs(KERNEL_DS);
66665 err = sys_clock_getres(which_clock,
66666 - (struct timespec __user *) &ts);
66667 + (struct timespec __force_user *) &ts);
66668 set_fs(oldfs);
66669 if (!err && tp && put_compat_timespec(&ts, tp))
66670 return -EFAULT;
66671 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66672 long err;
66673 mm_segment_t oldfs;
66674 struct timespec tu;
66675 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66676 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66677
66678 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66679 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66680 oldfs = get_fs();
66681 set_fs(KERNEL_DS);
66682 err = clock_nanosleep_restart(restart);
66683 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66684 oldfs = get_fs();
66685 set_fs(KERNEL_DS);
66686 err = sys_clock_nanosleep(which_clock, flags,
66687 - (struct timespec __user *) &in,
66688 - (struct timespec __user *) &out);
66689 + (struct timespec __force_user *) &in,
66690 + (struct timespec __force_user *) &out);
66691 set_fs(oldfs);
66692
66693 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66694 diff --git a/kernel/configs.c b/kernel/configs.c
66695 index 42e8fa0..9e7406b 100644
66696 --- a/kernel/configs.c
66697 +++ b/kernel/configs.c
66698 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66699 struct proc_dir_entry *entry;
66700
66701 /* create the current config file */
66702 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66703 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66704 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66705 + &ikconfig_file_ops);
66706 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66707 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66708 + &ikconfig_file_ops);
66709 +#endif
66710 +#else
66711 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66712 &ikconfig_file_ops);
66713 +#endif
66714 +
66715 if (!entry)
66716 return -ENOMEM;
66717
66718 diff --git a/kernel/cred.c b/kernel/cred.c
66719 index de728ac..e3c267c 100644
66720 --- a/kernel/cred.c
66721 +++ b/kernel/cred.c
66722 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66723 validate_creds(cred);
66724 alter_cred_subscribers(cred, -1);
66725 put_cred(cred);
66726 +
66727 +#ifdef CONFIG_GRKERNSEC_SETXID
66728 + cred = (struct cred *) tsk->delayed_cred;
66729 + if (cred != NULL) {
66730 + tsk->delayed_cred = NULL;
66731 + validate_creds(cred);
66732 + alter_cred_subscribers(cred, -1);
66733 + put_cred(cred);
66734 + }
66735 +#endif
66736 }
66737
66738 /**
66739 @@ -469,7 +479,7 @@ error_put:
66740 * Always returns 0 thus allowing this function to be tail-called at the end
66741 * of, say, sys_setgid().
66742 */
66743 -int commit_creds(struct cred *new)
66744 +static int __commit_creds(struct cred *new)
66745 {
66746 struct task_struct *task = current;
66747 const struct cred *old = task->real_cred;
66748 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66749
66750 get_cred(new); /* we will require a ref for the subj creds too */
66751
66752 + gr_set_role_label(task, new->uid, new->gid);
66753 +
66754 /* dumpability changes */
66755 if (!uid_eq(old->euid, new->euid) ||
66756 !gid_eq(old->egid, new->egid) ||
66757 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66758 put_cred(old);
66759 return 0;
66760 }
66761 +#ifdef CONFIG_GRKERNSEC_SETXID
66762 +extern int set_user(struct cred *new);
66763 +
66764 +void gr_delayed_cred_worker(void)
66765 +{
66766 + const struct cred *new = current->delayed_cred;
66767 + struct cred *ncred;
66768 +
66769 + current->delayed_cred = NULL;
66770 +
66771 + if (current_uid() && new != NULL) {
66772 + // from doing get_cred on it when queueing this
66773 + put_cred(new);
66774 + return;
66775 + } else if (new == NULL)
66776 + return;
66777 +
66778 + ncred = prepare_creds();
66779 + if (!ncred)
66780 + goto die;
66781 + // uids
66782 + ncred->uid = new->uid;
66783 + ncred->euid = new->euid;
66784 + ncred->suid = new->suid;
66785 + ncred->fsuid = new->fsuid;
66786 + // gids
66787 + ncred->gid = new->gid;
66788 + ncred->egid = new->egid;
66789 + ncred->sgid = new->sgid;
66790 + ncred->fsgid = new->fsgid;
66791 + // groups
66792 + if (set_groups(ncred, new->group_info) < 0) {
66793 + abort_creds(ncred);
66794 + goto die;
66795 + }
66796 + // caps
66797 + ncred->securebits = new->securebits;
66798 + ncred->cap_inheritable = new->cap_inheritable;
66799 + ncred->cap_permitted = new->cap_permitted;
66800 + ncred->cap_effective = new->cap_effective;
66801 + ncred->cap_bset = new->cap_bset;
66802 +
66803 + if (set_user(ncred)) {
66804 + abort_creds(ncred);
66805 + goto die;
66806 + }
66807 +
66808 + // from doing get_cred on it when queueing this
66809 + put_cred(new);
66810 +
66811 + __commit_creds(ncred);
66812 + return;
66813 +die:
66814 + // from doing get_cred on it when queueing this
66815 + put_cred(new);
66816 + do_group_exit(SIGKILL);
66817 +}
66818 +#endif
66819 +
66820 +int commit_creds(struct cred *new)
66821 +{
66822 +#ifdef CONFIG_GRKERNSEC_SETXID
66823 + int ret;
66824 + int schedule_it = 0;
66825 + struct task_struct *t;
66826 +
66827 + /* we won't get called with tasklist_lock held for writing
66828 + and interrupts disabled as the cred struct in that case is
66829 + init_cred
66830 + */
66831 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66832 + !current_uid() && new->uid) {
66833 + schedule_it = 1;
66834 + }
66835 + ret = __commit_creds(new);
66836 + if (schedule_it) {
66837 + rcu_read_lock();
66838 + read_lock(&tasklist_lock);
66839 + for (t = next_thread(current); t != current;
66840 + t = next_thread(t)) {
66841 + if (t->delayed_cred == NULL) {
66842 + t->delayed_cred = get_cred(new);
66843 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66844 + set_tsk_need_resched(t);
66845 + }
66846 + }
66847 + read_unlock(&tasklist_lock);
66848 + rcu_read_unlock();
66849 + }
66850 + return ret;
66851 +#else
66852 + return __commit_creds(new);
66853 +#endif
66854 +}
66855 +
66856 EXPORT_SYMBOL(commit_creds);
66857
66858 /**
66859 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66860 index 0557f24..1a00d9a 100644
66861 --- a/kernel/debug/debug_core.c
66862 +++ b/kernel/debug/debug_core.c
66863 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66864 */
66865 static atomic_t masters_in_kgdb;
66866 static atomic_t slaves_in_kgdb;
66867 -static atomic_t kgdb_break_tasklet_var;
66868 +static atomic_unchecked_t kgdb_break_tasklet_var;
66869 atomic_t kgdb_setting_breakpoint;
66870
66871 struct task_struct *kgdb_usethread;
66872 @@ -132,7 +132,7 @@ int kgdb_single_step;
66873 static pid_t kgdb_sstep_pid;
66874
66875 /* to keep track of the CPU which is doing the single stepping*/
66876 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66877 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66878
66879 /*
66880 * If you are debugging a problem where roundup (the collection of
66881 @@ -540,7 +540,7 @@ return_normal:
66882 * kernel will only try for the value of sstep_tries before
66883 * giving up and continuing on.
66884 */
66885 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66886 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66887 (kgdb_info[cpu].task &&
66888 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66889 atomic_set(&kgdb_active, -1);
66890 @@ -634,8 +634,8 @@ cpu_master_loop:
66891 }
66892
66893 kgdb_restore:
66894 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66895 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66896 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66897 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66898 if (kgdb_info[sstep_cpu].task)
66899 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66900 else
66901 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66902 static void kgdb_tasklet_bpt(unsigned long ing)
66903 {
66904 kgdb_breakpoint();
66905 - atomic_set(&kgdb_break_tasklet_var, 0);
66906 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66907 }
66908
66909 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66910
66911 void kgdb_schedule_breakpoint(void)
66912 {
66913 - if (atomic_read(&kgdb_break_tasklet_var) ||
66914 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66915 atomic_read(&kgdb_active) != -1 ||
66916 atomic_read(&kgdb_setting_breakpoint))
66917 return;
66918 - atomic_inc(&kgdb_break_tasklet_var);
66919 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66920 tasklet_schedule(&kgdb_tasklet_breakpoint);
66921 }
66922 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66923 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66924 index 31df170..bc98840 100644
66925 --- a/kernel/debug/kdb/kdb_main.c
66926 +++ b/kernel/debug/kdb/kdb_main.c
66927 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
66928 list_for_each_entry(mod, kdb_modules, list) {
66929
66930 kdb_printf("%-20s%8u 0x%p ", mod->name,
66931 - mod->core_size, (void *)mod);
66932 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66933 #ifdef CONFIG_MODULE_UNLOAD
66934 kdb_printf("%4ld ", module_refcount(mod));
66935 #endif
66936 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
66937 kdb_printf(" (Loading)");
66938 else
66939 kdb_printf(" (Live)");
66940 - kdb_printf(" 0x%p", mod->module_core);
66941 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66942
66943 #ifdef CONFIG_MODULE_UNLOAD
66944 {
66945 diff --git a/kernel/events/core.c b/kernel/events/core.c
66946 index 7fee567..8affa2c 100644
66947 --- a/kernel/events/core.c
66948 +++ b/kernel/events/core.c
66949 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66950 return 0;
66951 }
66952
66953 -static atomic64_t perf_event_id;
66954 +static atomic64_unchecked_t perf_event_id;
66955
66956 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66957 enum event_type_t event_type);
66958 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
66959
66960 static inline u64 perf_event_count(struct perf_event *event)
66961 {
66962 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66963 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66964 }
66965
66966 static u64 perf_event_read(struct perf_event *event)
66967 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66968 mutex_lock(&event->child_mutex);
66969 total += perf_event_read(event);
66970 *enabled += event->total_time_enabled +
66971 - atomic64_read(&event->child_total_time_enabled);
66972 + atomic64_read_unchecked(&event->child_total_time_enabled);
66973 *running += event->total_time_running +
66974 - atomic64_read(&event->child_total_time_running);
66975 + atomic64_read_unchecked(&event->child_total_time_running);
66976
66977 list_for_each_entry(child, &event->child_list, child_list) {
66978 total += perf_event_read(child);
66979 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
66980 userpg->offset -= local64_read(&event->hw.prev_count);
66981
66982 userpg->time_enabled = enabled +
66983 - atomic64_read(&event->child_total_time_enabled);
66984 + atomic64_read_unchecked(&event->child_total_time_enabled);
66985
66986 userpg->time_running = running +
66987 - atomic64_read(&event->child_total_time_running);
66988 + atomic64_read_unchecked(&event->child_total_time_running);
66989
66990 arch_perf_update_userpage(userpg, now);
66991
66992 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66993 values[n++] = perf_event_count(event);
66994 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66995 values[n++] = enabled +
66996 - atomic64_read(&event->child_total_time_enabled);
66997 + atomic64_read_unchecked(&event->child_total_time_enabled);
66998 }
66999 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67000 values[n++] = running +
67001 - atomic64_read(&event->child_total_time_running);
67002 + atomic64_read_unchecked(&event->child_total_time_running);
67003 }
67004 if (read_format & PERF_FORMAT_ID)
67005 values[n++] = primary_event_id(event);
67006 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67007 * need to add enough zero bytes after the string to handle
67008 * the 64bit alignment we do later.
67009 */
67010 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67011 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67012 if (!buf) {
67013 name = strncpy(tmp, "//enomem", sizeof(tmp));
67014 goto got_name;
67015 }
67016 - name = d_path(&file->f_path, buf, PATH_MAX);
67017 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67018 if (IS_ERR(name)) {
67019 name = strncpy(tmp, "//toolong", sizeof(tmp));
67020 goto got_name;
67021 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67022 event->parent = parent_event;
67023
67024 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67025 - event->id = atomic64_inc_return(&perf_event_id);
67026 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67027
67028 event->state = PERF_EVENT_STATE_INACTIVE;
67029
67030 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67031 /*
67032 * Add back the child's count to the parent's count:
67033 */
67034 - atomic64_add(child_val, &parent_event->child_count);
67035 - atomic64_add(child_event->total_time_enabled,
67036 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67037 + atomic64_add_unchecked(child_event->total_time_enabled,
67038 &parent_event->child_total_time_enabled);
67039 - atomic64_add(child_event->total_time_running,
67040 + atomic64_add_unchecked(child_event->total_time_running,
67041 &parent_event->child_total_time_running);
67042
67043 /*
67044 diff --git a/kernel/exit.c b/kernel/exit.c
67045 index f65345f9..9c28dab 100644
67046 --- a/kernel/exit.c
67047 +++ b/kernel/exit.c
67048 @@ -59,6 +59,10 @@
67049 #include <asm/pgtable.h>
67050 #include <asm/mmu_context.h>
67051
67052 +#ifdef CONFIG_GRKERNSEC
67053 +extern rwlock_t grsec_exec_file_lock;
67054 +#endif
67055 +
67056 static void exit_mm(struct task_struct * tsk);
67057
67058 static void __unhash_process(struct task_struct *p, bool group_dead)
67059 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67060 struct task_struct *leader;
67061 int zap_leader;
67062 repeat:
67063 +#ifdef CONFIG_NET
67064 + gr_del_task_from_ip_table(p);
67065 +#endif
67066 +
67067 /* don't need to get the RCU readlock here - the process is dead and
67068 * can't be modifying its own credentials. But shut RCU-lockdep up */
67069 rcu_read_lock();
67070 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67071 * know it'll be handled, so that they don't get converted to
67072 * SIGKILL or just silently dropped.
67073 */
67074 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67075 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67076 recalc_sigpending();
67077 spin_unlock_irq(&current->sighand->siglock);
67078 return 0;
67079 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67080 vsnprintf(current->comm, sizeof(current->comm), name, args);
67081 va_end(args);
67082
67083 +#ifdef CONFIG_GRKERNSEC
67084 + write_lock(&grsec_exec_file_lock);
67085 + if (current->exec_file) {
67086 + fput(current->exec_file);
67087 + current->exec_file = NULL;
67088 + }
67089 + write_unlock(&grsec_exec_file_lock);
67090 +#endif
67091 +
67092 + gr_set_kernel_label(current);
67093 +
67094 /*
67095 * If we were started as result of loading a module, close all of the
67096 * user space pages. We don't need them, and if we didn't close them
67097 @@ -907,6 +926,8 @@ void do_exit(long code)
67098 struct task_struct *tsk = current;
67099 int group_dead;
67100
67101 + set_fs(USER_DS);
67102 +
67103 profile_task_exit(tsk);
67104
67105 WARN_ON(blk_needs_flush_plug(tsk));
67106 @@ -923,7 +944,6 @@ void do_exit(long code)
67107 * mm_release()->clear_child_tid() from writing to a user-controlled
67108 * kernel address.
67109 */
67110 - set_fs(USER_DS);
67111
67112 ptrace_event(PTRACE_EVENT_EXIT, code);
67113
67114 @@ -982,6 +1002,9 @@ void do_exit(long code)
67115 tsk->exit_code = code;
67116 taskstats_exit(tsk, group_dead);
67117
67118 + gr_acl_handle_psacct(tsk, code);
67119 + gr_acl_handle_exit();
67120 +
67121 exit_mm(tsk);
67122
67123 if (group_dead)
67124 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67125 * Take down every thread in the group. This is called by fatal signals
67126 * as well as by sys_exit_group (below).
67127 */
67128 -void
67129 +__noreturn void
67130 do_group_exit(int exit_code)
67131 {
67132 struct signal_struct *sig = current->signal;
67133 diff --git a/kernel/fork.c b/kernel/fork.c
67134 index 2c8857e..288c9c7 100644
67135 --- a/kernel/fork.c
67136 +++ b/kernel/fork.c
67137 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67138 *stackend = STACK_END_MAGIC; /* for overflow detection */
67139
67140 #ifdef CONFIG_CC_STACKPROTECTOR
67141 - tsk->stack_canary = get_random_int();
67142 + tsk->stack_canary = pax_get_random_long();
67143 #endif
67144
67145 /*
67146 @@ -343,13 +343,78 @@ free_tsk:
67147 }
67148
67149 #ifdef CONFIG_MMU
67150 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67151 +{
67152 + struct vm_area_struct *tmp;
67153 + unsigned long charge;
67154 + struct mempolicy *pol;
67155 + struct file *file;
67156 +
67157 + charge = 0;
67158 + if (mpnt->vm_flags & VM_ACCOUNT) {
67159 + unsigned long len = vma_pages(mpnt);
67160 +
67161 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67162 + goto fail_nomem;
67163 + charge = len;
67164 + }
67165 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67166 + if (!tmp)
67167 + goto fail_nomem;
67168 + *tmp = *mpnt;
67169 + tmp->vm_mm = mm;
67170 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67171 + pol = mpol_dup(vma_policy(mpnt));
67172 + if (IS_ERR(pol))
67173 + goto fail_nomem_policy;
67174 + vma_set_policy(tmp, pol);
67175 + if (anon_vma_fork(tmp, mpnt))
67176 + goto fail_nomem_anon_vma_fork;
67177 + tmp->vm_flags &= ~VM_LOCKED;
67178 + tmp->vm_next = tmp->vm_prev = NULL;
67179 + tmp->vm_mirror = NULL;
67180 + file = tmp->vm_file;
67181 + if (file) {
67182 + struct inode *inode = file->f_path.dentry->d_inode;
67183 + struct address_space *mapping = file->f_mapping;
67184 +
67185 + get_file(file);
67186 + if (tmp->vm_flags & VM_DENYWRITE)
67187 + atomic_dec(&inode->i_writecount);
67188 + mutex_lock(&mapping->i_mmap_mutex);
67189 + if (tmp->vm_flags & VM_SHARED)
67190 + mapping->i_mmap_writable++;
67191 + flush_dcache_mmap_lock(mapping);
67192 + /* insert tmp into the share list, just after mpnt */
67193 + vma_prio_tree_add(tmp, mpnt);
67194 + flush_dcache_mmap_unlock(mapping);
67195 + mutex_unlock(&mapping->i_mmap_mutex);
67196 + }
67197 +
67198 + /*
67199 + * Clear hugetlb-related page reserves for children. This only
67200 + * affects MAP_PRIVATE mappings. Faults generated by the child
67201 + * are not guaranteed to succeed, even if read-only
67202 + */
67203 + if (is_vm_hugetlb_page(tmp))
67204 + reset_vma_resv_huge_pages(tmp);
67205 +
67206 + return tmp;
67207 +
67208 +fail_nomem_anon_vma_fork:
67209 + mpol_put(pol);
67210 +fail_nomem_policy:
67211 + kmem_cache_free(vm_area_cachep, tmp);
67212 +fail_nomem:
67213 + vm_unacct_memory(charge);
67214 + return NULL;
67215 +}
67216 +
67217 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67218 {
67219 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67220 struct rb_node **rb_link, *rb_parent;
67221 int retval;
67222 - unsigned long charge;
67223 - struct mempolicy *pol;
67224
67225 down_write(&oldmm->mmap_sem);
67226 flush_cache_dup_mm(oldmm);
67227 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67228 mm->locked_vm = 0;
67229 mm->mmap = NULL;
67230 mm->mmap_cache = NULL;
67231 - mm->free_area_cache = oldmm->mmap_base;
67232 - mm->cached_hole_size = ~0UL;
67233 + mm->free_area_cache = oldmm->free_area_cache;
67234 + mm->cached_hole_size = oldmm->cached_hole_size;
67235 mm->map_count = 0;
67236 cpumask_clear(mm_cpumask(mm));
67237 mm->mm_rb = RB_ROOT;
67238 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67239
67240 prev = NULL;
67241 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67242 - struct file *file;
67243 -
67244 if (mpnt->vm_flags & VM_DONTCOPY) {
67245 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67246 -vma_pages(mpnt));
67247 continue;
67248 }
67249 - charge = 0;
67250 - if (mpnt->vm_flags & VM_ACCOUNT) {
67251 - unsigned long len = vma_pages(mpnt);
67252 -
67253 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67254 - goto fail_nomem;
67255 - charge = len;
67256 - }
67257 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67258 - if (!tmp)
67259 - goto fail_nomem;
67260 - *tmp = *mpnt;
67261 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67262 - pol = mpol_dup(vma_policy(mpnt));
67263 - retval = PTR_ERR(pol);
67264 - if (IS_ERR(pol))
67265 - goto fail_nomem_policy;
67266 - vma_set_policy(tmp, pol);
67267 - tmp->vm_mm = mm;
67268 - if (anon_vma_fork(tmp, mpnt))
67269 - goto fail_nomem_anon_vma_fork;
67270 - tmp->vm_flags &= ~VM_LOCKED;
67271 - tmp->vm_next = tmp->vm_prev = NULL;
67272 - file = tmp->vm_file;
67273 - if (file) {
67274 - struct inode *inode = file->f_path.dentry->d_inode;
67275 - struct address_space *mapping = file->f_mapping;
67276 -
67277 - get_file(file);
67278 - if (tmp->vm_flags & VM_DENYWRITE)
67279 - atomic_dec(&inode->i_writecount);
67280 - mutex_lock(&mapping->i_mmap_mutex);
67281 - if (tmp->vm_flags & VM_SHARED)
67282 - mapping->i_mmap_writable++;
67283 - flush_dcache_mmap_lock(mapping);
67284 - /* insert tmp into the share list, just after mpnt */
67285 - vma_prio_tree_add(tmp, mpnt);
67286 - flush_dcache_mmap_unlock(mapping);
67287 - mutex_unlock(&mapping->i_mmap_mutex);
67288 + tmp = dup_vma(mm, oldmm, mpnt);
67289 + if (!tmp) {
67290 + retval = -ENOMEM;
67291 + goto out;
67292 }
67293
67294 /*
67295 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67296 if (retval)
67297 goto out;
67298
67299 - if (file)
67300 + if (tmp->vm_file)
67301 uprobe_mmap(tmp);
67302 }
67303 +
67304 +#ifdef CONFIG_PAX_SEGMEXEC
67305 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67306 + struct vm_area_struct *mpnt_m;
67307 +
67308 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67309 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67310 +
67311 + if (!mpnt->vm_mirror)
67312 + continue;
67313 +
67314 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67315 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67316 + mpnt->vm_mirror = mpnt_m;
67317 + } else {
67318 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67319 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67320 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67321 + mpnt->vm_mirror->vm_mirror = mpnt;
67322 + }
67323 + }
67324 + BUG_ON(mpnt_m);
67325 + }
67326 +#endif
67327 +
67328 /* a new mm has just been created */
67329 arch_dup_mmap(oldmm, mm);
67330 retval = 0;
67331 @@ -466,14 +519,6 @@ out:
67332 flush_tlb_mm(oldmm);
67333 up_write(&oldmm->mmap_sem);
67334 return retval;
67335 -fail_nomem_anon_vma_fork:
67336 - mpol_put(pol);
67337 -fail_nomem_policy:
67338 - kmem_cache_free(vm_area_cachep, tmp);
67339 -fail_nomem:
67340 - retval = -ENOMEM;
67341 - vm_unacct_memory(charge);
67342 - goto out;
67343 }
67344
67345 static inline int mm_alloc_pgd(struct mm_struct *mm)
67346 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67347 return ERR_PTR(err);
67348
67349 mm = get_task_mm(task);
67350 - if (mm && mm != current->mm &&
67351 - !ptrace_may_access(task, mode)) {
67352 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67353 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67354 mmput(mm);
67355 mm = ERR_PTR(-EACCES);
67356 }
67357 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67358 spin_unlock(&fs->lock);
67359 return -EAGAIN;
67360 }
67361 - fs->users++;
67362 + atomic_inc(&fs->users);
67363 spin_unlock(&fs->lock);
67364 return 0;
67365 }
67366 tsk->fs = copy_fs_struct(fs);
67367 if (!tsk->fs)
67368 return -ENOMEM;
67369 + /* Carry through gr_chroot_dentry and is_chrooted instead
67370 + of recomputing it here. Already copied when the task struct
67371 + is duplicated. This allows pivot_root to not be treated as
67372 + a chroot
67373 + */
67374 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67375 +
67376 return 0;
67377 }
67378
67379 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67380 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67381 #endif
67382 retval = -EAGAIN;
67383 +
67384 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67385 +
67386 if (atomic_read(&p->real_cred->user->processes) >=
67387 task_rlimit(p, RLIMIT_NPROC)) {
67388 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67389 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67390 /* Need tasklist lock for parent etc handling! */
67391 write_lock_irq(&tasklist_lock);
67392
67393 + /* synchronizes with gr_set_acls() */
67394 + gr_copy_label(p);
67395 +
67396 /* CLONE_PARENT re-uses the old parent */
67397 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67398 p->real_parent = current->real_parent;
67399 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67400 bad_fork_free:
67401 free_task(p);
67402 fork_out:
67403 + gr_log_forkfail(retval);
67404 +
67405 return ERR_PTR(retval);
67406 }
67407
67408 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67409 if (clone_flags & CLONE_PARENT_SETTID)
67410 put_user(nr, parent_tidptr);
67411
67412 + gr_handle_brute_check();
67413 +
67414 if (clone_flags & CLONE_VFORK) {
67415 p->vfork_done = &vfork;
67416 init_completion(&vfork);
67417 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67418 return 0;
67419
67420 /* don't need lock here; in the worst case we'll do useless copy */
67421 - if (fs->users == 1)
67422 + if (atomic_read(&fs->users) == 1)
67423 return 0;
67424
67425 *new_fsp = copy_fs_struct(fs);
67426 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67427 fs = current->fs;
67428 spin_lock(&fs->lock);
67429 current->fs = new_fs;
67430 - if (--fs->users)
67431 + gr_set_chroot_entries(current, &current->fs->root);
67432 + if (atomic_dec_return(&fs->users))
67433 new_fs = NULL;
67434 else
67435 new_fs = fs;
67436 diff --git a/kernel/futex.c b/kernel/futex.c
67437 index 3717e7b..473c750 100644
67438 --- a/kernel/futex.c
67439 +++ b/kernel/futex.c
67440 @@ -54,6 +54,7 @@
67441 #include <linux/mount.h>
67442 #include <linux/pagemap.h>
67443 #include <linux/syscalls.h>
67444 +#include <linux/ptrace.h>
67445 #include <linux/signal.h>
67446 #include <linux/export.h>
67447 #include <linux/magic.h>
67448 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67449 struct page *page, *page_head;
67450 int err, ro = 0;
67451
67452 +#ifdef CONFIG_PAX_SEGMEXEC
67453 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67454 + return -EFAULT;
67455 +#endif
67456 +
67457 /*
67458 * The futex address must be "naturally" aligned.
67459 */
67460 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67461 {
67462 u32 curval;
67463 int i;
67464 + mm_segment_t oldfs;
67465
67466 /*
67467 * This will fail and we want it. Some arch implementations do
67468 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67469 * implementation, the non-functional ones will return
67470 * -ENOSYS.
67471 */
67472 + oldfs = get_fs();
67473 + set_fs(USER_DS);
67474 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67475 futex_cmpxchg_enabled = 1;
67476 + set_fs(oldfs);
67477
67478 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67479 plist_head_init(&futex_queues[i].chain);
67480 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67481 index 9b22d03..6295b62 100644
67482 --- a/kernel/gcov/base.c
67483 +++ b/kernel/gcov/base.c
67484 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67485 }
67486
67487 #ifdef CONFIG_MODULES
67488 -static inline int within(void *addr, void *start, unsigned long size)
67489 -{
67490 - return ((addr >= start) && (addr < start + size));
67491 -}
67492 -
67493 /* Update list and generate events when modules are unloaded. */
67494 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67495 void *data)
67496 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67497 prev = NULL;
67498 /* Remove entries located in module from linked list. */
67499 for (info = gcov_info_head; info; info = info->next) {
67500 - if (within(info, mod->module_core, mod->core_size)) {
67501 + if (within_module_core_rw((unsigned long)info, mod)) {
67502 if (prev)
67503 prev->next = info->next;
67504 else
67505 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67506 index 6db7a5e..25b6648 100644
67507 --- a/kernel/hrtimer.c
67508 +++ b/kernel/hrtimer.c
67509 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67510 local_irq_restore(flags);
67511 }
67512
67513 -static void run_hrtimer_softirq(struct softirq_action *h)
67514 +static void run_hrtimer_softirq(void)
67515 {
67516 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67517
67518 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67519 index 4304919..408c4c0 100644
67520 --- a/kernel/jump_label.c
67521 +++ b/kernel/jump_label.c
67522 @@ -13,6 +13,7 @@
67523 #include <linux/sort.h>
67524 #include <linux/err.h>
67525 #include <linux/static_key.h>
67526 +#include <linux/mm.h>
67527
67528 #ifdef HAVE_JUMP_LABEL
67529
67530 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67531
67532 size = (((unsigned long)stop - (unsigned long)start)
67533 / sizeof(struct jump_entry));
67534 + pax_open_kernel();
67535 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67536 + pax_close_kernel();
67537 }
67538
67539 static void jump_label_update(struct static_key *key, int enable);
67540 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67541 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67542 struct jump_entry *iter;
67543
67544 + pax_open_kernel();
67545 for (iter = iter_start; iter < iter_stop; iter++) {
67546 if (within_module_init(iter->code, mod))
67547 iter->code = 0;
67548 }
67549 + pax_close_kernel();
67550 }
67551
67552 static int
67553 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67554 index 2169fee..45c017a 100644
67555 --- a/kernel/kallsyms.c
67556 +++ b/kernel/kallsyms.c
67557 @@ -11,6 +11,9 @@
67558 * Changed the compression method from stem compression to "table lookup"
67559 * compression (see scripts/kallsyms.c for a more complete description)
67560 */
67561 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67562 +#define __INCLUDED_BY_HIDESYM 1
67563 +#endif
67564 #include <linux/kallsyms.h>
67565 #include <linux/module.h>
67566 #include <linux/init.h>
67567 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67568
67569 static inline int is_kernel_inittext(unsigned long addr)
67570 {
67571 + if (system_state != SYSTEM_BOOTING)
67572 + return 0;
67573 +
67574 if (addr >= (unsigned long)_sinittext
67575 && addr <= (unsigned long)_einittext)
67576 return 1;
67577 return 0;
67578 }
67579
67580 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67581 +#ifdef CONFIG_MODULES
67582 +static inline int is_module_text(unsigned long addr)
67583 +{
67584 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67585 + return 1;
67586 +
67587 + addr = ktla_ktva(addr);
67588 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67589 +}
67590 +#else
67591 +static inline int is_module_text(unsigned long addr)
67592 +{
67593 + return 0;
67594 +}
67595 +#endif
67596 +#endif
67597 +
67598 static inline int is_kernel_text(unsigned long addr)
67599 {
67600 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67601 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67602
67603 static inline int is_kernel(unsigned long addr)
67604 {
67605 +
67606 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67607 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67608 + return 1;
67609 +
67610 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67611 +#else
67612 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67613 +#endif
67614 +
67615 return 1;
67616 return in_gate_area_no_mm(addr);
67617 }
67618
67619 static int is_ksym_addr(unsigned long addr)
67620 {
67621 +
67622 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67623 + if (is_module_text(addr))
67624 + return 0;
67625 +#endif
67626 +
67627 if (all_var)
67628 return is_kernel(addr);
67629
67630 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67631
67632 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67633 {
67634 - iter->name[0] = '\0';
67635 iter->nameoff = get_symbol_offset(new_pos);
67636 iter->pos = new_pos;
67637 }
67638 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67639 {
67640 struct kallsym_iter *iter = m->private;
67641
67642 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67643 + if (current_uid())
67644 + return 0;
67645 +#endif
67646 +
67647 /* Some debugging symbols have no name. Ignore them. */
67648 if (!iter->name[0])
67649 return 0;
67650 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67651 */
67652 type = iter->exported ? toupper(iter->type) :
67653 tolower(iter->type);
67654 +
67655 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67656 type, iter->name, iter->module_name);
67657 } else
67658 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67659 struct kallsym_iter *iter;
67660 int ret;
67661
67662 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67663 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67664 if (!iter)
67665 return -ENOMEM;
67666 reset_iter(iter, 0);
67667 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67668 index 30b7b22..c726387 100644
67669 --- a/kernel/kcmp.c
67670 +++ b/kernel/kcmp.c
67671 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67672 struct task_struct *task1, *task2;
67673 int ret;
67674
67675 +#ifdef CONFIG_GRKERNSEC
67676 + return -ENOSYS;
67677 +#endif
67678 +
67679 rcu_read_lock();
67680
67681 /*
67682 diff --git a/kernel/kexec.c b/kernel/kexec.c
67683 index 0668d58..591b6fc 100644
67684 --- a/kernel/kexec.c
67685 +++ b/kernel/kexec.c
67686 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67687 unsigned long flags)
67688 {
67689 struct compat_kexec_segment in;
67690 - struct kexec_segment out, __user *ksegments;
67691 + struct kexec_segment out;
67692 + struct kexec_segment __user *ksegments;
67693 unsigned long i, result;
67694
67695 /* Don't allow clients that don't understand the native
67696 diff --git a/kernel/kmod.c b/kernel/kmod.c
67697 index 6f99aea..eb6e3a0 100644
67698 --- a/kernel/kmod.c
67699 +++ b/kernel/kmod.c
67700 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67701 kfree(info->argv);
67702 }
67703
67704 -static int call_modprobe(char *module_name, int wait)
67705 +static int call_modprobe(char *module_name, char *module_param, int wait)
67706 {
67707 static char *envp[] = {
67708 "HOME=/",
67709 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67710 NULL
67711 };
67712
67713 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67714 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67715 if (!argv)
67716 goto out;
67717
67718 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67719 argv[1] = "-q";
67720 argv[2] = "--";
67721 argv[3] = module_name; /* check free_modprobe_argv() */
67722 - argv[4] = NULL;
67723 + argv[4] = module_param;
67724 + argv[5] = NULL;
67725
67726 return call_usermodehelper_fns(modprobe_path, argv, envp,
67727 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67728 @@ -119,9 +120,8 @@ out:
67729 * If module auto-loading support is disabled then this function
67730 * becomes a no-operation.
67731 */
67732 -int __request_module(bool wait, const char *fmt, ...)
67733 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67734 {
67735 - va_list args;
67736 char module_name[MODULE_NAME_LEN];
67737 unsigned int max_modprobes;
67738 int ret;
67739 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67740 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67741 static int kmod_loop_msg;
67742
67743 - va_start(args, fmt);
67744 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67745 - va_end(args);
67746 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67747 if (ret >= MODULE_NAME_LEN)
67748 return -ENAMETOOLONG;
67749
67750 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67751 if (ret)
67752 return ret;
67753
67754 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67755 + if (!current_uid()) {
67756 + /* hack to workaround consolekit/udisks stupidity */
67757 + read_lock(&tasklist_lock);
67758 + if (!strcmp(current->comm, "mount") &&
67759 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67760 + read_unlock(&tasklist_lock);
67761 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67762 + return -EPERM;
67763 + }
67764 + read_unlock(&tasklist_lock);
67765 + }
67766 +#endif
67767 +
67768 /* If modprobe needs a service that is in a module, we get a recursive
67769 * loop. Limit the number of running kmod threads to max_threads/2 or
67770 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67771 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67772
67773 trace_module_request(module_name, wait, _RET_IP_);
67774
67775 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67776 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67777
67778 atomic_dec(&kmod_concurrent);
67779 return ret;
67780 }
67781 +
67782 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67783 +{
67784 + va_list args;
67785 + int ret;
67786 +
67787 + va_start(args, fmt);
67788 + ret = ____request_module(wait, module_param, fmt, args);
67789 + va_end(args);
67790 +
67791 + return ret;
67792 +}
67793 +
67794 +int __request_module(bool wait, const char *fmt, ...)
67795 +{
67796 + va_list args;
67797 + int ret;
67798 +
67799 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67800 + if (current_uid()) {
67801 + char module_param[MODULE_NAME_LEN];
67802 +
67803 + memset(module_param, 0, sizeof(module_param));
67804 +
67805 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67806 +
67807 + va_start(args, fmt);
67808 + ret = ____request_module(wait, module_param, fmt, args);
67809 + va_end(args);
67810 +
67811 + return ret;
67812 + }
67813 +#endif
67814 +
67815 + va_start(args, fmt);
67816 + ret = ____request_module(wait, NULL, fmt, args);
67817 + va_end(args);
67818 +
67819 + return ret;
67820 +}
67821 +
67822 EXPORT_SYMBOL(__request_module);
67823 #endif /* CONFIG_MODULES */
67824
67825 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
67826 *
67827 * Thus the __user pointer cast is valid here.
67828 */
67829 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67830 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67831
67832 /*
67833 * If ret is 0, either ____call_usermodehelper failed and the
67834 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67835 index c62b854..6fc810d 100644
67836 --- a/kernel/kprobes.c
67837 +++ b/kernel/kprobes.c
67838 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67839 * kernel image and loaded module images reside. This is required
67840 * so x86_64 can correctly handle the %rip-relative fixups.
67841 */
67842 - kip->insns = module_alloc(PAGE_SIZE);
67843 + kip->insns = module_alloc_exec(PAGE_SIZE);
67844 if (!kip->insns) {
67845 kfree(kip);
67846 return NULL;
67847 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67848 */
67849 if (!list_is_singular(&kip->list)) {
67850 list_del(&kip->list);
67851 - module_free(NULL, kip->insns);
67852 + module_free_exec(NULL, kip->insns);
67853 kfree(kip);
67854 }
67855 return 1;
67856 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67857 {
67858 int i, err = 0;
67859 unsigned long offset = 0, size = 0;
67860 - char *modname, namebuf[128];
67861 + char *modname, namebuf[KSYM_NAME_LEN];
67862 const char *symbol_name;
67863 void *addr;
67864 struct kprobe_blackpoint *kb;
67865 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
67866 kprobe_type = "k";
67867
67868 if (sym)
67869 - seq_printf(pi, "%p %s %s+0x%x %s ",
67870 + seq_printf(pi, "%pK %s %s+0x%x %s ",
67871 p->addr, kprobe_type, sym, offset,
67872 (modname ? modname : " "));
67873 else
67874 - seq_printf(pi, "%p %s %p ",
67875 + seq_printf(pi, "%pK %s %pK ",
67876 p->addr, kprobe_type, p->addr);
67877
67878 if (!pp)
67879 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67880 const char *sym = NULL;
67881 unsigned int i = *(loff_t *) v;
67882 unsigned long offset = 0;
67883 - char *modname, namebuf[128];
67884 + char *modname, namebuf[KSYM_NAME_LEN];
67885
67886 head = &kprobe_table[i];
67887 preempt_disable();
67888 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67889 index 4e316e1..5501eef 100644
67890 --- a/kernel/ksysfs.c
67891 +++ b/kernel/ksysfs.c
67892 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67893 {
67894 if (count+1 > UEVENT_HELPER_PATH_LEN)
67895 return -ENOENT;
67896 + if (!capable(CAP_SYS_ADMIN))
67897 + return -EPERM;
67898 memcpy(uevent_helper, buf, count);
67899 uevent_helper[count] = '\0';
67900 if (count && uevent_helper[count-1] == '\n')
67901 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67902 index ea9ee45..67ebc8f 100644
67903 --- a/kernel/lockdep.c
67904 +++ b/kernel/lockdep.c
67905 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67906 end = (unsigned long) &_end,
67907 addr = (unsigned long) obj;
67908
67909 +#ifdef CONFIG_PAX_KERNEXEC
67910 + start = ktla_ktva(start);
67911 +#endif
67912 +
67913 /*
67914 * static variable?
67915 */
67916 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67917 if (!static_obj(lock->key)) {
67918 debug_locks_off();
67919 printk("INFO: trying to register non-static key.\n");
67920 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67921 printk("the code is fine but needs lockdep annotation.\n");
67922 printk("turning off the locking correctness validator.\n");
67923 dump_stack();
67924 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67925 if (!class)
67926 return 0;
67927 }
67928 - atomic_inc((atomic_t *)&class->ops);
67929 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67930 if (very_verbose(class)) {
67931 printk("\nacquire class [%p] %s", class->key, class->name);
67932 if (class->name_version > 1)
67933 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67934 index 91c32a0..7b88d63 100644
67935 --- a/kernel/lockdep_proc.c
67936 +++ b/kernel/lockdep_proc.c
67937 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67938
67939 static void print_name(struct seq_file *m, struct lock_class *class)
67940 {
67941 - char str[128];
67942 + char str[KSYM_NAME_LEN];
67943 const char *name = class->name;
67944
67945 if (!name) {
67946 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
67947 return 0;
67948 }
67949
67950 - seq_printf(m, "%p", class->key);
67951 + seq_printf(m, "%pK", class->key);
67952 #ifdef CONFIG_DEBUG_LOCKDEP
67953 seq_printf(m, " OPS:%8ld", class->ops);
67954 #endif
67955 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
67956
67957 list_for_each_entry(entry, &class->locks_after, entry) {
67958 if (entry->distance == 1) {
67959 - seq_printf(m, " -> [%p] ", entry->class->key);
67960 + seq_printf(m, " -> [%pK] ", entry->class->key);
67961 print_name(m, entry->class);
67962 seq_puts(m, "\n");
67963 }
67964 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
67965 if (!class->key)
67966 continue;
67967
67968 - seq_printf(m, "[%p] ", class->key);
67969 + seq_printf(m, "[%pK] ", class->key);
67970 print_name(m, class);
67971 seq_puts(m, "\n");
67972 }
67973 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67974 if (!i)
67975 seq_line(m, '-', 40-namelen, namelen);
67976
67977 - snprintf(ip, sizeof(ip), "[<%p>]",
67978 + snprintf(ip, sizeof(ip), "[<%pK>]",
67979 (void *)class->contention_point[i]);
67980 seq_printf(m, "%40s %14lu %29s %pS\n",
67981 name, stats->contention_point[i],
67982 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67983 if (!i)
67984 seq_line(m, '-', 40-namelen, namelen);
67985
67986 - snprintf(ip, sizeof(ip), "[<%p>]",
67987 + snprintf(ip, sizeof(ip), "[<%pK>]",
67988 (void *)class->contending_point[i]);
67989 seq_printf(m, "%40s %14lu %29s %pS\n",
67990 name, stats->contending_point[i],
67991 diff --git a/kernel/module.c b/kernel/module.c
67992 index 9ad9ee9..de7a157 100644
67993 --- a/kernel/module.c
67994 +++ b/kernel/module.c
67995 @@ -58,6 +58,7 @@
67996 #include <linux/jump_label.h>
67997 #include <linux/pfn.h>
67998 #include <linux/bsearch.h>
67999 +#include <linux/grsecurity.h>
68000
68001 #define CREATE_TRACE_POINTS
68002 #include <trace/events/module.h>
68003 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68004
68005 /* Bounds of module allocation, for speeding __module_address.
68006 * Protected by module_mutex. */
68007 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68008 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68009 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68010
68011 int register_module_notifier(struct notifier_block * nb)
68012 {
68013 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68014 return true;
68015
68016 list_for_each_entry_rcu(mod, &modules, list) {
68017 - struct symsearch arr[] = {
68018 + struct symsearch modarr[] = {
68019 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68020 NOT_GPL_ONLY, false },
68021 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68022 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68023 #endif
68024 };
68025
68026 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68027 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68028 return true;
68029 }
68030 return false;
68031 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68032 static int percpu_modalloc(struct module *mod,
68033 unsigned long size, unsigned long align)
68034 {
68035 - if (align > PAGE_SIZE) {
68036 + if (align-1 >= PAGE_SIZE) {
68037 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68038 mod->name, align, PAGE_SIZE);
68039 align = PAGE_SIZE;
68040 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68041 static ssize_t show_coresize(struct module_attribute *mattr,
68042 struct module_kobject *mk, char *buffer)
68043 {
68044 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68045 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68046 }
68047
68048 static struct module_attribute modinfo_coresize =
68049 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68050 static ssize_t show_initsize(struct module_attribute *mattr,
68051 struct module_kobject *mk, char *buffer)
68052 {
68053 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68054 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68055 }
68056
68057 static struct module_attribute modinfo_initsize =
68058 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68059 */
68060 #ifdef CONFIG_SYSFS
68061
68062 -#ifdef CONFIG_KALLSYMS
68063 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68064 static inline bool sect_empty(const Elf_Shdr *sect)
68065 {
68066 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68067 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68068
68069 static void unset_module_core_ro_nx(struct module *mod)
68070 {
68071 - set_page_attributes(mod->module_core + mod->core_text_size,
68072 - mod->module_core + mod->core_size,
68073 + set_page_attributes(mod->module_core_rw,
68074 + mod->module_core_rw + mod->core_size_rw,
68075 set_memory_x);
68076 - set_page_attributes(mod->module_core,
68077 - mod->module_core + mod->core_ro_size,
68078 + set_page_attributes(mod->module_core_rx,
68079 + mod->module_core_rx + mod->core_size_rx,
68080 set_memory_rw);
68081 }
68082
68083 static void unset_module_init_ro_nx(struct module *mod)
68084 {
68085 - set_page_attributes(mod->module_init + mod->init_text_size,
68086 - mod->module_init + mod->init_size,
68087 + set_page_attributes(mod->module_init_rw,
68088 + mod->module_init_rw + mod->init_size_rw,
68089 set_memory_x);
68090 - set_page_attributes(mod->module_init,
68091 - mod->module_init + mod->init_ro_size,
68092 + set_page_attributes(mod->module_init_rx,
68093 + mod->module_init_rx + mod->init_size_rx,
68094 set_memory_rw);
68095 }
68096
68097 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68098
68099 mutex_lock(&module_mutex);
68100 list_for_each_entry_rcu(mod, &modules, list) {
68101 - if ((mod->module_core) && (mod->core_text_size)) {
68102 - set_page_attributes(mod->module_core,
68103 - mod->module_core + mod->core_text_size,
68104 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68105 + set_page_attributes(mod->module_core_rx,
68106 + mod->module_core_rx + mod->core_size_rx,
68107 set_memory_rw);
68108 }
68109 - if ((mod->module_init) && (mod->init_text_size)) {
68110 - set_page_attributes(mod->module_init,
68111 - mod->module_init + mod->init_text_size,
68112 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68113 + set_page_attributes(mod->module_init_rx,
68114 + mod->module_init_rx + mod->init_size_rx,
68115 set_memory_rw);
68116 }
68117 }
68118 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68119
68120 mutex_lock(&module_mutex);
68121 list_for_each_entry_rcu(mod, &modules, list) {
68122 - if ((mod->module_core) && (mod->core_text_size)) {
68123 - set_page_attributes(mod->module_core,
68124 - mod->module_core + mod->core_text_size,
68125 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68126 + set_page_attributes(mod->module_core_rx,
68127 + mod->module_core_rx + mod->core_size_rx,
68128 set_memory_ro);
68129 }
68130 - if ((mod->module_init) && (mod->init_text_size)) {
68131 - set_page_attributes(mod->module_init,
68132 - mod->module_init + mod->init_text_size,
68133 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68134 + set_page_attributes(mod->module_init_rx,
68135 + mod->module_init_rx + mod->init_size_rx,
68136 set_memory_ro);
68137 }
68138 }
68139 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68140
68141 /* This may be NULL, but that's OK */
68142 unset_module_init_ro_nx(mod);
68143 - module_free(mod, mod->module_init);
68144 + module_free(mod, mod->module_init_rw);
68145 + module_free_exec(mod, mod->module_init_rx);
68146 kfree(mod->args);
68147 percpu_modfree(mod);
68148
68149 /* Free lock-classes: */
68150 - lockdep_free_key_range(mod->module_core, mod->core_size);
68151 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68152 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68153
68154 /* Finally, free the core (containing the module structure) */
68155 unset_module_core_ro_nx(mod);
68156 - module_free(mod, mod->module_core);
68157 + module_free_exec(mod, mod->module_core_rx);
68158 + module_free(mod, mod->module_core_rw);
68159
68160 #ifdef CONFIG_MPU
68161 update_protections(current->mm);
68162 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68163 int ret = 0;
68164 const struct kernel_symbol *ksym;
68165
68166 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68167 + int is_fs_load = 0;
68168 + int register_filesystem_found = 0;
68169 + char *p;
68170 +
68171 + p = strstr(mod->args, "grsec_modharden_fs");
68172 + if (p) {
68173 + char *endptr = p + strlen("grsec_modharden_fs");
68174 + /* copy \0 as well */
68175 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68176 + is_fs_load = 1;
68177 + }
68178 +#endif
68179 +
68180 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68181 const char *name = info->strtab + sym[i].st_name;
68182
68183 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68184 + /* it's a real shame this will never get ripped and copied
68185 + upstream! ;(
68186 + */
68187 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68188 + register_filesystem_found = 1;
68189 +#endif
68190 +
68191 switch (sym[i].st_shndx) {
68192 case SHN_COMMON:
68193 /* We compiled with -fno-common. These are not
68194 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68195 ksym = resolve_symbol_wait(mod, info, name);
68196 /* Ok if resolved. */
68197 if (ksym && !IS_ERR(ksym)) {
68198 + pax_open_kernel();
68199 sym[i].st_value = ksym->value;
68200 + pax_close_kernel();
68201 break;
68202 }
68203
68204 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68205 secbase = (unsigned long)mod_percpu(mod);
68206 else
68207 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68208 + pax_open_kernel();
68209 sym[i].st_value += secbase;
68210 + pax_close_kernel();
68211 break;
68212 }
68213 }
68214
68215 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68216 + if (is_fs_load && !register_filesystem_found) {
68217 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68218 + ret = -EPERM;
68219 + }
68220 +#endif
68221 +
68222 return ret;
68223 }
68224
68225 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68226 || s->sh_entsize != ~0UL
68227 || strstarts(sname, ".init"))
68228 continue;
68229 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68230 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68231 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68232 + else
68233 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68234 pr_debug("\t%s\n", sname);
68235 }
68236 - switch (m) {
68237 - case 0: /* executable */
68238 - mod->core_size = debug_align(mod->core_size);
68239 - mod->core_text_size = mod->core_size;
68240 - break;
68241 - case 1: /* RO: text and ro-data */
68242 - mod->core_size = debug_align(mod->core_size);
68243 - mod->core_ro_size = mod->core_size;
68244 - break;
68245 - case 3: /* whole core */
68246 - mod->core_size = debug_align(mod->core_size);
68247 - break;
68248 - }
68249 }
68250
68251 pr_debug("Init section allocation order:\n");
68252 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68253 || s->sh_entsize != ~0UL
68254 || !strstarts(sname, ".init"))
68255 continue;
68256 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68257 - | INIT_OFFSET_MASK);
68258 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68259 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68260 + else
68261 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68262 + s->sh_entsize |= INIT_OFFSET_MASK;
68263 pr_debug("\t%s\n", sname);
68264 }
68265 - switch (m) {
68266 - case 0: /* executable */
68267 - mod->init_size = debug_align(mod->init_size);
68268 - mod->init_text_size = mod->init_size;
68269 - break;
68270 - case 1: /* RO: text and ro-data */
68271 - mod->init_size = debug_align(mod->init_size);
68272 - mod->init_ro_size = mod->init_size;
68273 - break;
68274 - case 3: /* whole init */
68275 - mod->init_size = debug_align(mod->init_size);
68276 - break;
68277 - }
68278 }
68279 }
68280
68281 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68282
68283 /* Put symbol section at end of init part of module. */
68284 symsect->sh_flags |= SHF_ALLOC;
68285 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68286 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68287 info->index.sym) | INIT_OFFSET_MASK;
68288 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68289
68290 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68291 }
68292
68293 /* Append room for core symbols at end of core part. */
68294 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68295 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68296 - mod->core_size += strtab_size;
68297 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68298 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68299 + mod->core_size_rx += strtab_size;
68300
68301 /* Put string table section at end of init part of module. */
68302 strsect->sh_flags |= SHF_ALLOC;
68303 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68304 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68305 info->index.str) | INIT_OFFSET_MASK;
68306 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68307 }
68308 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68309 /* Make sure we get permanent strtab: don't use info->strtab. */
68310 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68311
68312 + pax_open_kernel();
68313 +
68314 /* Set types up while we still have access to sections. */
68315 for (i = 0; i < mod->num_symtab; i++)
68316 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68317
68318 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68319 - mod->core_strtab = s = mod->module_core + info->stroffs;
68320 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68321 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68322 src = mod->symtab;
68323 *dst = *src;
68324 *s++ = 0;
68325 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68326 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68327 }
68328 mod->core_num_syms = ndst;
68329 +
68330 + pax_close_kernel();
68331 }
68332 #else
68333 static inline void layout_symtab(struct module *mod, struct load_info *info)
68334 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68335 return size == 0 ? NULL : vmalloc_exec(size);
68336 }
68337
68338 -static void *module_alloc_update_bounds(unsigned long size)
68339 +static void *module_alloc_update_bounds_rw(unsigned long size)
68340 {
68341 void *ret = module_alloc(size);
68342
68343 if (ret) {
68344 mutex_lock(&module_mutex);
68345 /* Update module bounds. */
68346 - if ((unsigned long)ret < module_addr_min)
68347 - module_addr_min = (unsigned long)ret;
68348 - if ((unsigned long)ret + size > module_addr_max)
68349 - module_addr_max = (unsigned long)ret + size;
68350 + if ((unsigned long)ret < module_addr_min_rw)
68351 + module_addr_min_rw = (unsigned long)ret;
68352 + if ((unsigned long)ret + size > module_addr_max_rw)
68353 + module_addr_max_rw = (unsigned long)ret + size;
68354 + mutex_unlock(&module_mutex);
68355 + }
68356 + return ret;
68357 +}
68358 +
68359 +static void *module_alloc_update_bounds_rx(unsigned long size)
68360 +{
68361 + void *ret = module_alloc_exec(size);
68362 +
68363 + if (ret) {
68364 + mutex_lock(&module_mutex);
68365 + /* Update module bounds. */
68366 + if ((unsigned long)ret < module_addr_min_rx)
68367 + module_addr_min_rx = (unsigned long)ret;
68368 + if ((unsigned long)ret + size > module_addr_max_rx)
68369 + module_addr_max_rx = (unsigned long)ret + size;
68370 mutex_unlock(&module_mutex);
68371 }
68372 return ret;
68373 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68374 static int check_modinfo(struct module *mod, struct load_info *info)
68375 {
68376 const char *modmagic = get_modinfo(info, "vermagic");
68377 + const char *license = get_modinfo(info, "license");
68378 int err;
68379
68380 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68381 + if (!license || !license_is_gpl_compatible(license))
68382 + return -ENOEXEC;
68383 +#endif
68384 +
68385 /* This is allowed: modprobe --force will invalidate it. */
68386 if (!modmagic) {
68387 err = try_to_force_load(mod, "bad vermagic");
68388 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68389 }
68390
68391 /* Set up license info based on the info section */
68392 - set_license(mod, get_modinfo(info, "license"));
68393 + set_license(mod, license);
68394
68395 return 0;
68396 }
68397 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68398 void *ptr;
68399
68400 /* Do the allocs. */
68401 - ptr = module_alloc_update_bounds(mod->core_size);
68402 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68403 /*
68404 * The pointer to this block is stored in the module structure
68405 * which is inside the block. Just mark it as not being a
68406 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68407 if (!ptr)
68408 return -ENOMEM;
68409
68410 - memset(ptr, 0, mod->core_size);
68411 - mod->module_core = ptr;
68412 + memset(ptr, 0, mod->core_size_rw);
68413 + mod->module_core_rw = ptr;
68414
68415 - ptr = module_alloc_update_bounds(mod->init_size);
68416 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68417 /*
68418 * The pointer to this block is stored in the module structure
68419 * which is inside the block. This block doesn't need to be
68420 * scanned as it contains data and code that will be freed
68421 * after the module is initialized.
68422 */
68423 - kmemleak_ignore(ptr);
68424 - if (!ptr && mod->init_size) {
68425 - module_free(mod, mod->module_core);
68426 + kmemleak_not_leak(ptr);
68427 + if (!ptr && mod->init_size_rw) {
68428 + module_free(mod, mod->module_core_rw);
68429 return -ENOMEM;
68430 }
68431 - memset(ptr, 0, mod->init_size);
68432 - mod->module_init = ptr;
68433 + memset(ptr, 0, mod->init_size_rw);
68434 + mod->module_init_rw = ptr;
68435 +
68436 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68437 + kmemleak_not_leak(ptr);
68438 + if (!ptr) {
68439 + module_free(mod, mod->module_init_rw);
68440 + module_free(mod, mod->module_core_rw);
68441 + return -ENOMEM;
68442 + }
68443 +
68444 + pax_open_kernel();
68445 + memset(ptr, 0, mod->core_size_rx);
68446 + pax_close_kernel();
68447 + mod->module_core_rx = ptr;
68448 +
68449 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68450 + kmemleak_not_leak(ptr);
68451 + if (!ptr && mod->init_size_rx) {
68452 + module_free_exec(mod, mod->module_core_rx);
68453 + module_free(mod, mod->module_init_rw);
68454 + module_free(mod, mod->module_core_rw);
68455 + return -ENOMEM;
68456 + }
68457 +
68458 + pax_open_kernel();
68459 + memset(ptr, 0, mod->init_size_rx);
68460 + pax_close_kernel();
68461 + mod->module_init_rx = ptr;
68462
68463 /* Transfer each section which specifies SHF_ALLOC */
68464 pr_debug("final section addresses:\n");
68465 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68466 if (!(shdr->sh_flags & SHF_ALLOC))
68467 continue;
68468
68469 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68470 - dest = mod->module_init
68471 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68472 - else
68473 - dest = mod->module_core + shdr->sh_entsize;
68474 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68475 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68476 + dest = mod->module_init_rw
68477 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68478 + else
68479 + dest = mod->module_init_rx
68480 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68481 + } else {
68482 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68483 + dest = mod->module_core_rw + shdr->sh_entsize;
68484 + else
68485 + dest = mod->module_core_rx + shdr->sh_entsize;
68486 + }
68487 +
68488 + if (shdr->sh_type != SHT_NOBITS) {
68489 +
68490 +#ifdef CONFIG_PAX_KERNEXEC
68491 +#ifdef CONFIG_X86_64
68492 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68493 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68494 +#endif
68495 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68496 + pax_open_kernel();
68497 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68498 + pax_close_kernel();
68499 + } else
68500 +#endif
68501
68502 - if (shdr->sh_type != SHT_NOBITS)
68503 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68504 + }
68505 /* Update sh_addr to point to copy in image. */
68506 - shdr->sh_addr = (unsigned long)dest;
68507 +
68508 +#ifdef CONFIG_PAX_KERNEXEC
68509 + if (shdr->sh_flags & SHF_EXECINSTR)
68510 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68511 + else
68512 +#endif
68513 +
68514 + shdr->sh_addr = (unsigned long)dest;
68515 pr_debug("\t0x%lx %s\n",
68516 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68517 }
68518 @@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68519 * Do it before processing of module parameters, so the module
68520 * can provide parameter accessor functions of its own.
68521 */
68522 - if (mod->module_init)
68523 - flush_icache_range((unsigned long)mod->module_init,
68524 - (unsigned long)mod->module_init
68525 - + mod->init_size);
68526 - flush_icache_range((unsigned long)mod->module_core,
68527 - (unsigned long)mod->module_core + mod->core_size);
68528 + if (mod->module_init_rx)
68529 + flush_icache_range((unsigned long)mod->module_init_rx,
68530 + (unsigned long)mod->module_init_rx
68531 + + mod->init_size_rx);
68532 + flush_icache_range((unsigned long)mod->module_core_rx,
68533 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68534
68535 set_fs(old_fs);
68536 }
68537 @@ -2838,8 +2938,10 @@ out:
68538 static void module_deallocate(struct module *mod, struct load_info *info)
68539 {
68540 percpu_modfree(mod);
68541 - module_free(mod, mod->module_init);
68542 - module_free(mod, mod->module_core);
68543 + module_free_exec(mod, mod->module_init_rx);
68544 + module_free_exec(mod, mod->module_core_rx);
68545 + module_free(mod, mod->module_init_rw);
68546 + module_free(mod, mod->module_core_rw);
68547 }
68548
68549 int __weak module_finalize(const Elf_Ehdr *hdr,
68550 @@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68551 static int post_relocation(struct module *mod, const struct load_info *info)
68552 {
68553 /* Sort exception table now relocations are done. */
68554 + pax_open_kernel();
68555 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68556 + pax_close_kernel();
68557
68558 /* Copy relocated percpu area over. */
68559 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68560 @@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68561 if (err)
68562 goto free_unload;
68563
68564 + /* Now copy in args */
68565 + mod->args = strndup_user(uargs, ~0UL >> 1);
68566 + if (IS_ERR(mod->args)) {
68567 + err = PTR_ERR(mod->args);
68568 + goto free_unload;
68569 + }
68570 +
68571 /* Set up MODINFO_ATTR fields */
68572 setup_modinfo(mod, &info);
68573
68574 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68575 + {
68576 + char *p, *p2;
68577 +
68578 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68579 + 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);
68580 + err = -EPERM;
68581 + goto free_modinfo;
68582 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68583 + p += strlen("grsec_modharden_normal");
68584 + p2 = strstr(p, "_");
68585 + if (p2) {
68586 + *p2 = '\0';
68587 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68588 + *p2 = '_';
68589 + }
68590 + err = -EPERM;
68591 + goto free_modinfo;
68592 + }
68593 + }
68594 +#endif
68595 +
68596 /* Fix up syms, so that st_value is a pointer to location. */
68597 err = simplify_symbols(mod, &info);
68598 if (err < 0)
68599 @@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68600
68601 flush_module_icache(mod);
68602
68603 - /* Now copy in args */
68604 - mod->args = strndup_user(uargs, ~0UL >> 1);
68605 - if (IS_ERR(mod->args)) {
68606 - err = PTR_ERR(mod->args);
68607 - goto free_arch_cleanup;
68608 - }
68609 -
68610 /* Mark state as coming so strong_try_module_get() ignores us. */
68611 mod->state = MODULE_STATE_COMING;
68612
68613 @@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68614 unlock:
68615 mutex_unlock(&module_mutex);
68616 synchronize_sched();
68617 - kfree(mod->args);
68618 - free_arch_cleanup:
68619 module_arch_cleanup(mod);
68620 free_modinfo:
68621 free_modinfo(mod);
68622 + kfree(mod->args);
68623 free_unload:
68624 module_unload_free(mod);
68625 free_module:
68626 @@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68627 MODULE_STATE_COMING, mod);
68628
68629 /* Set RO and NX regions for core */
68630 - set_section_ro_nx(mod->module_core,
68631 - mod->core_text_size,
68632 - mod->core_ro_size,
68633 - mod->core_size);
68634 + set_section_ro_nx(mod->module_core_rx,
68635 + mod->core_size_rx,
68636 + mod->core_size_rx,
68637 + mod->core_size_rx);
68638
68639 /* Set RO and NX regions for init */
68640 - set_section_ro_nx(mod->module_init,
68641 - mod->init_text_size,
68642 - mod->init_ro_size,
68643 - mod->init_size);
68644 + set_section_ro_nx(mod->module_init_rx,
68645 + mod->init_size_rx,
68646 + mod->init_size_rx,
68647 + mod->init_size_rx);
68648
68649 do_mod_ctors(mod);
68650 /* Start the module */
68651 @@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68652 mod->strtab = mod->core_strtab;
68653 #endif
68654 unset_module_init_ro_nx(mod);
68655 - module_free(mod, mod->module_init);
68656 - mod->module_init = NULL;
68657 - mod->init_size = 0;
68658 - mod->init_ro_size = 0;
68659 - mod->init_text_size = 0;
68660 + module_free(mod, mod->module_init_rw);
68661 + module_free_exec(mod, mod->module_init_rx);
68662 + mod->module_init_rw = NULL;
68663 + mod->module_init_rx = NULL;
68664 + mod->init_size_rw = 0;
68665 + mod->init_size_rx = 0;
68666 mutex_unlock(&module_mutex);
68667
68668 return 0;
68669 @@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68670 unsigned long nextval;
68671
68672 /* At worse, next value is at end of module */
68673 - if (within_module_init(addr, mod))
68674 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68675 + if (within_module_init_rx(addr, mod))
68676 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68677 + else if (within_module_init_rw(addr, mod))
68678 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68679 + else if (within_module_core_rx(addr, mod))
68680 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68681 + else if (within_module_core_rw(addr, mod))
68682 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68683 else
68684 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68685 + return NULL;
68686
68687 /* Scan for closest preceding symbol, and next symbol. (ELF
68688 starts real symbols at 1). */
68689 @@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68690 char buf[8];
68691
68692 seq_printf(m, "%s %u",
68693 - mod->name, mod->init_size + mod->core_size);
68694 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68695 print_unload_info(m, mod);
68696
68697 /* Informative for users. */
68698 @@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68699 mod->state == MODULE_STATE_COMING ? "Loading":
68700 "Live");
68701 /* Used by oprofile and other similar tools. */
68702 - seq_printf(m, " 0x%pK", mod->module_core);
68703 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68704
68705 /* Taints info */
68706 if (mod->taints)
68707 @@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68708
68709 static int __init proc_modules_init(void)
68710 {
68711 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68712 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68713 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68714 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68715 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68716 +#else
68717 proc_create("modules", 0, NULL, &proc_modules_operations);
68718 +#endif
68719 +#else
68720 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68721 +#endif
68722 return 0;
68723 }
68724 module_init(proc_modules_init);
68725 @@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68726 {
68727 struct module *mod;
68728
68729 - if (addr < module_addr_min || addr > module_addr_max)
68730 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68731 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68732 return NULL;
68733
68734 list_for_each_entry_rcu(mod, &modules, list)
68735 - if (within_module_core(addr, mod)
68736 - || within_module_init(addr, mod))
68737 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68738 return mod;
68739 return NULL;
68740 }
68741 @@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68742 */
68743 struct module *__module_text_address(unsigned long addr)
68744 {
68745 - struct module *mod = __module_address(addr);
68746 + struct module *mod;
68747 +
68748 +#ifdef CONFIG_X86_32
68749 + addr = ktla_ktva(addr);
68750 +#endif
68751 +
68752 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68753 + return NULL;
68754 +
68755 + mod = __module_address(addr);
68756 +
68757 if (mod) {
68758 /* Make sure it's within the text section. */
68759 - if (!within(addr, mod->module_init, mod->init_text_size)
68760 - && !within(addr, mod->module_core, mod->core_text_size))
68761 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68762 mod = NULL;
68763 }
68764 return mod;
68765 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68766 index 7e3443f..b2a1e6b 100644
68767 --- a/kernel/mutex-debug.c
68768 +++ b/kernel/mutex-debug.c
68769 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68770 }
68771
68772 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68773 - struct thread_info *ti)
68774 + struct task_struct *task)
68775 {
68776 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68777
68778 /* Mark the current thread as blocked on the lock: */
68779 - ti->task->blocked_on = waiter;
68780 + task->blocked_on = waiter;
68781 }
68782
68783 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68784 - struct thread_info *ti)
68785 + struct task_struct *task)
68786 {
68787 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68788 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68789 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68790 - ti->task->blocked_on = NULL;
68791 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68792 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68793 + task->blocked_on = NULL;
68794
68795 list_del_init(&waiter->list);
68796 waiter->task = NULL;
68797 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68798 index 0799fd3..d06ae3b 100644
68799 --- a/kernel/mutex-debug.h
68800 +++ b/kernel/mutex-debug.h
68801 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68802 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68803 extern void debug_mutex_add_waiter(struct mutex *lock,
68804 struct mutex_waiter *waiter,
68805 - struct thread_info *ti);
68806 + struct task_struct *task);
68807 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68808 - struct thread_info *ti);
68809 + struct task_struct *task);
68810 extern void debug_mutex_unlock(struct mutex *lock);
68811 extern void debug_mutex_init(struct mutex *lock, const char *name,
68812 struct lock_class_key *key);
68813 diff --git a/kernel/mutex.c b/kernel/mutex.c
68814 index a307cc9..27fd2e9 100644
68815 --- a/kernel/mutex.c
68816 +++ b/kernel/mutex.c
68817 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68818 spin_lock_mutex(&lock->wait_lock, flags);
68819
68820 debug_mutex_lock_common(lock, &waiter);
68821 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68822 + debug_mutex_add_waiter(lock, &waiter, task);
68823
68824 /* add waiting tasks to the end of the waitqueue (FIFO): */
68825 list_add_tail(&waiter.list, &lock->wait_list);
68826 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68827 * TASK_UNINTERRUPTIBLE case.)
68828 */
68829 if (unlikely(signal_pending_state(state, task))) {
68830 - mutex_remove_waiter(lock, &waiter,
68831 - task_thread_info(task));
68832 + mutex_remove_waiter(lock, &waiter, task);
68833 mutex_release(&lock->dep_map, 1, ip);
68834 spin_unlock_mutex(&lock->wait_lock, flags);
68835
68836 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68837 done:
68838 lock_acquired(&lock->dep_map, ip);
68839 /* got the lock - rejoice! */
68840 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68841 + mutex_remove_waiter(lock, &waiter, task);
68842 mutex_set_owner(lock);
68843
68844 /* set it to 0 if there are no waiters left: */
68845 diff --git a/kernel/panic.c b/kernel/panic.c
68846 index e1b2822..5edc1d9 100644
68847 --- a/kernel/panic.c
68848 +++ b/kernel/panic.c
68849 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68850 const char *board;
68851
68852 printk(KERN_WARNING "------------[ cut here ]------------\n");
68853 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68854 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68855 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68856 if (board)
68857 printk(KERN_WARNING "Hardware name: %s\n", board);
68858 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68859 */
68860 void __stack_chk_fail(void)
68861 {
68862 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68863 + dump_stack();
68864 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68865 __builtin_return_address(0));
68866 }
68867 EXPORT_SYMBOL(__stack_chk_fail);
68868 diff --git a/kernel/pid.c b/kernel/pid.c
68869 index e86b291a..e8b0fb5 100644
68870 --- a/kernel/pid.c
68871 +++ b/kernel/pid.c
68872 @@ -33,6 +33,7 @@
68873 #include <linux/rculist.h>
68874 #include <linux/bootmem.h>
68875 #include <linux/hash.h>
68876 +#include <linux/security.h>
68877 #include <linux/pid_namespace.h>
68878 #include <linux/init_task.h>
68879 #include <linux/syscalls.h>
68880 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68881
68882 int pid_max = PID_MAX_DEFAULT;
68883
68884 -#define RESERVED_PIDS 300
68885 +#define RESERVED_PIDS 500
68886
68887 int pid_max_min = RESERVED_PIDS + 1;
68888 int pid_max_max = PID_MAX_LIMIT;
68889 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68890 */
68891 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68892 {
68893 + struct task_struct *task;
68894 +
68895 rcu_lockdep_assert(rcu_read_lock_held(),
68896 "find_task_by_pid_ns() needs rcu_read_lock()"
68897 " protection");
68898 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68899 +
68900 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68901 +
68902 + if (gr_pid_is_chrooted(task))
68903 + return NULL;
68904 +
68905 + return task;
68906 }
68907
68908 struct task_struct *find_task_by_vpid(pid_t vnr)
68909 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68910 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68911 }
68912
68913 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68914 +{
68915 + rcu_lockdep_assert(rcu_read_lock_held(),
68916 + "find_task_by_pid_ns() needs rcu_read_lock()"
68917 + " protection");
68918 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68919 +}
68920 +
68921 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68922 {
68923 struct pid *pid;
68924 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68925 index 125cb67..a4d1c30 100644
68926 --- a/kernel/posix-cpu-timers.c
68927 +++ b/kernel/posix-cpu-timers.c
68928 @@ -6,6 +6,7 @@
68929 #include <linux/posix-timers.h>
68930 #include <linux/errno.h>
68931 #include <linux/math64.h>
68932 +#include <linux/security.h>
68933 #include <asm/uaccess.h>
68934 #include <linux/kernel_stat.h>
68935 #include <trace/events/timer.h>
68936 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68937
68938 static __init int init_posix_cpu_timers(void)
68939 {
68940 - struct k_clock process = {
68941 + static struct k_clock process = {
68942 .clock_getres = process_cpu_clock_getres,
68943 .clock_get = process_cpu_clock_get,
68944 .timer_create = process_cpu_timer_create,
68945 .nsleep = process_cpu_nsleep,
68946 .nsleep_restart = process_cpu_nsleep_restart,
68947 };
68948 - struct k_clock thread = {
68949 + static struct k_clock thread = {
68950 .clock_getres = thread_cpu_clock_getres,
68951 .clock_get = thread_cpu_clock_get,
68952 .timer_create = thread_cpu_timer_create,
68953 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68954 index 69185ae..cc2847a 100644
68955 --- a/kernel/posix-timers.c
68956 +++ b/kernel/posix-timers.c
68957 @@ -43,6 +43,7 @@
68958 #include <linux/idr.h>
68959 #include <linux/posix-clock.h>
68960 #include <linux/posix-timers.h>
68961 +#include <linux/grsecurity.h>
68962 #include <linux/syscalls.h>
68963 #include <linux/wait.h>
68964 #include <linux/workqueue.h>
68965 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68966 * which we beg off on and pass to do_sys_settimeofday().
68967 */
68968
68969 -static struct k_clock posix_clocks[MAX_CLOCKS];
68970 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68971
68972 /*
68973 * These ones are defined below.
68974 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68975 */
68976 static __init int init_posix_timers(void)
68977 {
68978 - struct k_clock clock_realtime = {
68979 + static struct k_clock clock_realtime = {
68980 .clock_getres = hrtimer_get_res,
68981 .clock_get = posix_clock_realtime_get,
68982 .clock_set = posix_clock_realtime_set,
68983 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68984 .timer_get = common_timer_get,
68985 .timer_del = common_timer_del,
68986 };
68987 - struct k_clock clock_monotonic = {
68988 + static struct k_clock clock_monotonic = {
68989 .clock_getres = hrtimer_get_res,
68990 .clock_get = posix_ktime_get_ts,
68991 .nsleep = common_nsleep,
68992 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68993 .timer_get = common_timer_get,
68994 .timer_del = common_timer_del,
68995 };
68996 - struct k_clock clock_monotonic_raw = {
68997 + static struct k_clock clock_monotonic_raw = {
68998 .clock_getres = hrtimer_get_res,
68999 .clock_get = posix_get_monotonic_raw,
69000 };
69001 - struct k_clock clock_realtime_coarse = {
69002 + static struct k_clock clock_realtime_coarse = {
69003 .clock_getres = posix_get_coarse_res,
69004 .clock_get = posix_get_realtime_coarse,
69005 };
69006 - struct k_clock clock_monotonic_coarse = {
69007 + static struct k_clock clock_monotonic_coarse = {
69008 .clock_getres = posix_get_coarse_res,
69009 .clock_get = posix_get_monotonic_coarse,
69010 };
69011 - struct k_clock clock_boottime = {
69012 + static struct k_clock clock_boottime = {
69013 .clock_getres = hrtimer_get_res,
69014 .clock_get = posix_get_boottime,
69015 .nsleep = common_nsleep,
69016 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69017 return;
69018 }
69019
69020 - posix_clocks[clock_id] = *new_clock;
69021 + posix_clocks[clock_id] = new_clock;
69022 }
69023 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69024
69025 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69026 return (id & CLOCKFD_MASK) == CLOCKFD ?
69027 &clock_posix_dynamic : &clock_posix_cpu;
69028
69029 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69030 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69031 return NULL;
69032 - return &posix_clocks[id];
69033 + return posix_clocks[id];
69034 }
69035
69036 static int common_timer_create(struct k_itimer *new_timer)
69037 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69038 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69039 return -EFAULT;
69040
69041 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69042 + have their clock_set fptr set to a nosettime dummy function
69043 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69044 + call common_clock_set, which calls do_sys_settimeofday, which
69045 + we hook
69046 + */
69047 +
69048 return kc->clock_set(which_clock, &new_tp);
69049 }
69050
69051 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69052 index d523593..68197a4 100644
69053 --- a/kernel/power/poweroff.c
69054 +++ b/kernel/power/poweroff.c
69055 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69056 .enable_mask = SYSRQ_ENABLE_BOOT,
69057 };
69058
69059 -static int pm_sysrq_init(void)
69060 +static int __init pm_sysrq_init(void)
69061 {
69062 register_sysrq_key('o', &sysrq_poweroff_op);
69063 return 0;
69064 diff --git a/kernel/power/process.c b/kernel/power/process.c
69065 index 19db29f..33b52b6 100644
69066 --- a/kernel/power/process.c
69067 +++ b/kernel/power/process.c
69068 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69069 u64 elapsed_csecs64;
69070 unsigned int elapsed_csecs;
69071 bool wakeup = false;
69072 + bool timedout = false;
69073
69074 do_gettimeofday(&start);
69075
69076 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69077
69078 while (true) {
69079 todo = 0;
69080 + if (time_after(jiffies, end_time))
69081 + timedout = true;
69082 read_lock(&tasklist_lock);
69083 do_each_thread(g, p) {
69084 if (p == current || !freeze_task(p))
69085 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69086 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69087 * transition can't race with task state testing here.
69088 */
69089 - if (!task_is_stopped_or_traced(p) &&
69090 - !freezer_should_skip(p))
69091 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69092 todo++;
69093 + if (timedout) {
69094 + printk(KERN_ERR "Task refusing to freeze:\n");
69095 + sched_show_task(p);
69096 + }
69097 + }
69098 } while_each_thread(g, p);
69099 read_unlock(&tasklist_lock);
69100
69101 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69102 todo += wq_busy;
69103 }
69104
69105 - if (!todo || time_after(jiffies, end_time))
69106 + if (!todo || timedout)
69107 break;
69108
69109 if (pm_wakeup_pending()) {
69110 diff --git a/kernel/printk.c b/kernel/printk.c
69111 index 66a2ea3..10f3a01 100644
69112 --- a/kernel/printk.c
69113 +++ b/kernel/printk.c
69114 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69115 if (from_file && type != SYSLOG_ACTION_OPEN)
69116 return 0;
69117
69118 +#ifdef CONFIG_GRKERNSEC_DMESG
69119 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69120 + return -EPERM;
69121 +#endif
69122 +
69123 if (syslog_action_restricted(type)) {
69124 if (capable(CAP_SYSLOG))
69125 return 0;
69126 diff --git a/kernel/profile.c b/kernel/profile.c
69127 index 76b8e77..a2930e8 100644
69128 --- a/kernel/profile.c
69129 +++ b/kernel/profile.c
69130 @@ -39,7 +39,7 @@ struct profile_hit {
69131 /* Oprofile timer tick hook */
69132 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69133
69134 -static atomic_t *prof_buffer;
69135 +static atomic_unchecked_t *prof_buffer;
69136 static unsigned long prof_len, prof_shift;
69137
69138 int prof_on __read_mostly;
69139 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69140 hits[i].pc = 0;
69141 continue;
69142 }
69143 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69144 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69145 hits[i].hits = hits[i].pc = 0;
69146 }
69147 }
69148 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69149 * Add the current hit(s) and flush the write-queue out
69150 * to the global buffer:
69151 */
69152 - atomic_add(nr_hits, &prof_buffer[pc]);
69153 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69154 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69155 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69156 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69157 hits[i].pc = hits[i].hits = 0;
69158 }
69159 out:
69160 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69161 {
69162 unsigned long pc;
69163 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69164 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69165 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69166 }
69167 #endif /* !CONFIG_SMP */
69168
69169 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69170 return -EFAULT;
69171 buf++; p++; count--; read++;
69172 }
69173 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69174 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69175 if (copy_to_user(buf, (void *)pnt, count))
69176 return -EFAULT;
69177 read += count;
69178 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69179 }
69180 #endif
69181 profile_discard_flip_buffers();
69182 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69183 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69184 return count;
69185 }
69186
69187 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69188 index a232bb5..2a65ef9 100644
69189 --- a/kernel/ptrace.c
69190 +++ b/kernel/ptrace.c
69191 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69192
69193 if (seize)
69194 flags |= PT_SEIZED;
69195 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69196 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69197 flags |= PT_PTRACE_CAP;
69198 task->ptrace = flags;
69199
69200 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69201 break;
69202 return -EIO;
69203 }
69204 - if (copy_to_user(dst, buf, retval))
69205 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69206 return -EFAULT;
69207 copied += retval;
69208 src += retval;
69209 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69210 bool seized = child->ptrace & PT_SEIZED;
69211 int ret = -EIO;
69212 siginfo_t siginfo, *si;
69213 - void __user *datavp = (void __user *) data;
69214 + void __user *datavp = (__force void __user *) data;
69215 unsigned long __user *datalp = datavp;
69216 unsigned long flags;
69217
69218 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69219 goto out;
69220 }
69221
69222 + if (gr_handle_ptrace(child, request)) {
69223 + ret = -EPERM;
69224 + goto out_put_task_struct;
69225 + }
69226 +
69227 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69228 ret = ptrace_attach(child, request, addr, data);
69229 /*
69230 * Some architectures need to do book-keeping after
69231 * a ptrace attach.
69232 */
69233 - if (!ret)
69234 + if (!ret) {
69235 arch_ptrace_attach(child);
69236 + gr_audit_ptrace(child);
69237 + }
69238 goto out_put_task_struct;
69239 }
69240
69241 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69242 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69243 if (copied != sizeof(tmp))
69244 return -EIO;
69245 - return put_user(tmp, (unsigned long __user *)data);
69246 + return put_user(tmp, (__force unsigned long __user *)data);
69247 }
69248
69249 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69250 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69251 goto out;
69252 }
69253
69254 + if (gr_handle_ptrace(child, request)) {
69255 + ret = -EPERM;
69256 + goto out_put_task_struct;
69257 + }
69258 +
69259 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69260 ret = ptrace_attach(child, request, addr, data);
69261 /*
69262 * Some architectures need to do book-keeping after
69263 * a ptrace attach.
69264 */
69265 - if (!ret)
69266 + if (!ret) {
69267 arch_ptrace_attach(child);
69268 + gr_audit_ptrace(child);
69269 + }
69270 goto out_put_task_struct;
69271 }
69272
69273 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69274 index 547b1fe..65e874e 100644
69275 --- a/kernel/rcutiny.c
69276 +++ b/kernel/rcutiny.c
69277 @@ -46,7 +46,7 @@
69278 struct rcu_ctrlblk;
69279 static void invoke_rcu_callbacks(void);
69280 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69281 -static void rcu_process_callbacks(struct softirq_action *unused);
69282 +static void rcu_process_callbacks(void);
69283 static void __call_rcu(struct rcu_head *head,
69284 void (*func)(struct rcu_head *rcu),
69285 struct rcu_ctrlblk *rcp);
69286 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69287 rcu_is_callbacks_kthread()));
69288 }
69289
69290 -static void rcu_process_callbacks(struct softirq_action *unused)
69291 +static void rcu_process_callbacks(void)
69292 {
69293 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69294 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69295 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69296 index 918fd1e..85089bb 100644
69297 --- a/kernel/rcutiny_plugin.h
69298 +++ b/kernel/rcutiny_plugin.h
69299 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69300 have_rcu_kthread_work = morework;
69301 local_irq_restore(flags);
69302 if (work)
69303 - rcu_process_callbacks(NULL);
69304 + rcu_process_callbacks();
69305 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69306 }
69307
69308 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69309 index 25b1503..1988a74 100644
69310 --- a/kernel/rcutorture.c
69311 +++ b/kernel/rcutorture.c
69312 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69313 { 0 };
69314 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69315 { 0 };
69316 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69317 -static atomic_t n_rcu_torture_alloc;
69318 -static atomic_t n_rcu_torture_alloc_fail;
69319 -static atomic_t n_rcu_torture_free;
69320 -static atomic_t n_rcu_torture_mberror;
69321 -static atomic_t n_rcu_torture_error;
69322 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69323 +static atomic_unchecked_t n_rcu_torture_alloc;
69324 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69325 +static atomic_unchecked_t n_rcu_torture_free;
69326 +static atomic_unchecked_t n_rcu_torture_mberror;
69327 +static atomic_unchecked_t n_rcu_torture_error;
69328 static long n_rcu_torture_barrier_error;
69329 static long n_rcu_torture_boost_ktrerror;
69330 static long n_rcu_torture_boost_rterror;
69331 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69332
69333 spin_lock_bh(&rcu_torture_lock);
69334 if (list_empty(&rcu_torture_freelist)) {
69335 - atomic_inc(&n_rcu_torture_alloc_fail);
69336 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69337 spin_unlock_bh(&rcu_torture_lock);
69338 return NULL;
69339 }
69340 - atomic_inc(&n_rcu_torture_alloc);
69341 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69342 p = rcu_torture_freelist.next;
69343 list_del_init(p);
69344 spin_unlock_bh(&rcu_torture_lock);
69345 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69346 static void
69347 rcu_torture_free(struct rcu_torture *p)
69348 {
69349 - atomic_inc(&n_rcu_torture_free);
69350 + atomic_inc_unchecked(&n_rcu_torture_free);
69351 spin_lock_bh(&rcu_torture_lock);
69352 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69353 spin_unlock_bh(&rcu_torture_lock);
69354 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69355 i = rp->rtort_pipe_count;
69356 if (i > RCU_TORTURE_PIPE_LEN)
69357 i = RCU_TORTURE_PIPE_LEN;
69358 - atomic_inc(&rcu_torture_wcount[i]);
69359 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69360 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69361 rp->rtort_mbtest = 0;
69362 rcu_torture_free(rp);
69363 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69364 i = rp->rtort_pipe_count;
69365 if (i > RCU_TORTURE_PIPE_LEN)
69366 i = RCU_TORTURE_PIPE_LEN;
69367 - atomic_inc(&rcu_torture_wcount[i]);
69368 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69369 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69370 rp->rtort_mbtest = 0;
69371 list_del(&rp->rtort_free);
69372 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69373 i = old_rp->rtort_pipe_count;
69374 if (i > RCU_TORTURE_PIPE_LEN)
69375 i = RCU_TORTURE_PIPE_LEN;
69376 - atomic_inc(&rcu_torture_wcount[i]);
69377 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69378 old_rp->rtort_pipe_count++;
69379 cur_ops->deferred_free(old_rp);
69380 }
69381 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69382 }
69383 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69384 if (p->rtort_mbtest == 0)
69385 - atomic_inc(&n_rcu_torture_mberror);
69386 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69387 spin_lock(&rand_lock);
69388 cur_ops->read_delay(&rand);
69389 n_rcu_torture_timers++;
69390 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69391 }
69392 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69393 if (p->rtort_mbtest == 0)
69394 - atomic_inc(&n_rcu_torture_mberror);
69395 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69396 cur_ops->read_delay(&rand);
69397 preempt_disable();
69398 pipe_count = p->rtort_pipe_count;
69399 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69400 rcu_torture_current,
69401 rcu_torture_current_version,
69402 list_empty(&rcu_torture_freelist),
69403 - atomic_read(&n_rcu_torture_alloc),
69404 - atomic_read(&n_rcu_torture_alloc_fail),
69405 - atomic_read(&n_rcu_torture_free));
69406 + atomic_read_unchecked(&n_rcu_torture_alloc),
69407 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69408 + atomic_read_unchecked(&n_rcu_torture_free));
69409 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69410 - atomic_read(&n_rcu_torture_mberror),
69411 + atomic_read_unchecked(&n_rcu_torture_mberror),
69412 n_rcu_torture_boost_ktrerror,
69413 n_rcu_torture_boost_rterror);
69414 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69415 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69416 n_barrier_attempts,
69417 n_rcu_torture_barrier_error);
69418 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69419 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69420 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69421 n_rcu_torture_barrier_error != 0 ||
69422 n_rcu_torture_boost_ktrerror != 0 ||
69423 n_rcu_torture_boost_rterror != 0 ||
69424 n_rcu_torture_boost_failure != 0 ||
69425 i > 1) {
69426 cnt += sprintf(&page[cnt], "!!! ");
69427 - atomic_inc(&n_rcu_torture_error);
69428 + atomic_inc_unchecked(&n_rcu_torture_error);
69429 WARN_ON_ONCE(1);
69430 }
69431 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69432 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69433 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69434 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69435 cnt += sprintf(&page[cnt], " %d",
69436 - atomic_read(&rcu_torture_wcount[i]));
69437 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69438 }
69439 cnt += sprintf(&page[cnt], "\n");
69440 if (cur_ops->stats)
69441 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69442
69443 if (cur_ops->cleanup)
69444 cur_ops->cleanup();
69445 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69446 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69447 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69448 else if (n_online_successes != n_online_attempts ||
69449 n_offline_successes != n_offline_attempts)
69450 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69451
69452 rcu_torture_current = NULL;
69453 rcu_torture_current_version = 0;
69454 - atomic_set(&n_rcu_torture_alloc, 0);
69455 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69456 - atomic_set(&n_rcu_torture_free, 0);
69457 - atomic_set(&n_rcu_torture_mberror, 0);
69458 - atomic_set(&n_rcu_torture_error, 0);
69459 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69460 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69461 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69462 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69463 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69464 n_rcu_torture_barrier_error = 0;
69465 n_rcu_torture_boost_ktrerror = 0;
69466 n_rcu_torture_boost_rterror = 0;
69467 n_rcu_torture_boost_failure = 0;
69468 n_rcu_torture_boosts = 0;
69469 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69470 - atomic_set(&rcu_torture_wcount[i], 0);
69471 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69472 for_each_possible_cpu(cpu) {
69473 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69474 per_cpu(rcu_torture_count, cpu)[i] = 0;
69475 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69476 index f7bcd9e..8973e14 100644
69477 --- a/kernel/rcutree.c
69478 +++ b/kernel/rcutree.c
69479 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69480 rcu_prepare_for_idle(smp_processor_id());
69481 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69482 smp_mb__before_atomic_inc(); /* See above. */
69483 - atomic_inc(&rdtp->dynticks);
69484 + atomic_inc_unchecked(&rdtp->dynticks);
69485 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69486 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69487 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69488
69489 /*
69490 * The idle task is not permitted to enter the idle loop while
69491 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69492 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69493 {
69494 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69495 - atomic_inc(&rdtp->dynticks);
69496 + atomic_inc_unchecked(&rdtp->dynticks);
69497 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69498 smp_mb__after_atomic_inc(); /* See above. */
69499 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69500 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69501 rcu_cleanup_after_idle(smp_processor_id());
69502 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69503 if (!is_idle_task(current)) {
69504 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69505 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69506
69507 if (rdtp->dynticks_nmi_nesting == 0 &&
69508 - (atomic_read(&rdtp->dynticks) & 0x1))
69509 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69510 return;
69511 rdtp->dynticks_nmi_nesting++;
69512 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69513 - atomic_inc(&rdtp->dynticks);
69514 + atomic_inc_unchecked(&rdtp->dynticks);
69515 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69516 smp_mb__after_atomic_inc(); /* See above. */
69517 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69518 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69519 }
69520
69521 /**
69522 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69523 return;
69524 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69525 smp_mb__before_atomic_inc(); /* See above. */
69526 - atomic_inc(&rdtp->dynticks);
69527 + atomic_inc_unchecked(&rdtp->dynticks);
69528 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69529 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69530 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69531 }
69532
69533 /**
69534 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69535 int ret;
69536
69537 preempt_disable();
69538 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69539 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69540 preempt_enable();
69541 return ret;
69542 }
69543 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69544 */
69545 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69546 {
69547 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69548 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69549 return (rdp->dynticks_snap & 0x1) == 0;
69550 }
69551
69552 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69553 unsigned int curr;
69554 unsigned int snap;
69555
69556 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69557 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69558 snap = (unsigned int)rdp->dynticks_snap;
69559
69560 /*
69561 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69562 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69563 */
69564 if (till_stall_check < 3) {
69565 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69566 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69567 till_stall_check = 3;
69568 } else if (till_stall_check > 300) {
69569 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69570 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69571 till_stall_check = 300;
69572 }
69573 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69574 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69575 rsp->qlen += rdp->qlen;
69576 rdp->n_cbs_orphaned += rdp->qlen;
69577 rdp->qlen_lazy = 0;
69578 - ACCESS_ONCE(rdp->qlen) = 0;
69579 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69580 }
69581
69582 /*
69583 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69584 }
69585 smp_mb(); /* List handling before counting for rcu_barrier(). */
69586 rdp->qlen_lazy -= count_lazy;
69587 - ACCESS_ONCE(rdp->qlen) -= count;
69588 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69589 rdp->n_cbs_invoked += count;
69590
69591 /* Reinstate batch limit if we have worked down the excess. */
69592 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69593 /*
69594 * Do RCU core processing for the current CPU.
69595 */
69596 -static void rcu_process_callbacks(struct softirq_action *unused)
69597 +static void rcu_process_callbacks(void)
69598 {
69599 struct rcu_state *rsp;
69600
69601 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69602 rdp = this_cpu_ptr(rsp->rda);
69603
69604 /* Add the callback to our list. */
69605 - ACCESS_ONCE(rdp->qlen)++;
69606 + ACCESS_ONCE_RW(rdp->qlen)++;
69607 if (lazy)
69608 rdp->qlen_lazy++;
69609 else
69610 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69611 }
69612 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69613
69614 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69615 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69616 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69617 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69618
69619 static int synchronize_sched_expedited_cpu_stop(void *data)
69620 {
69621 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69622 int firstsnap, s, snap, trycount = 0;
69623
69624 /* Note that atomic_inc_return() implies full memory barrier. */
69625 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69626 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69627 get_online_cpus();
69628 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69629
69630 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69631 }
69632
69633 /* Check to see if someone else did our work for us. */
69634 - s = atomic_read(&sync_sched_expedited_done);
69635 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69636 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69637 smp_mb(); /* ensure test happens before caller kfree */
69638 return;
69639 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69640 * grace period works for us.
69641 */
69642 get_online_cpus();
69643 - snap = atomic_read(&sync_sched_expedited_started);
69644 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69645 smp_mb(); /* ensure read is before try_stop_cpus(). */
69646 }
69647
69648 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69649 * than we did beat us to the punch.
69650 */
69651 do {
69652 - s = atomic_read(&sync_sched_expedited_done);
69653 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69654 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69655 smp_mb(); /* ensure test happens before caller kfree */
69656 break;
69657 }
69658 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69659 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69660
69661 put_online_cpus();
69662 }
69663 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69664 * ACCESS_ONCE() to prevent the compiler from speculating
69665 * the increment to precede the early-exit check.
69666 */
69667 - ACCESS_ONCE(rsp->n_barrier_done)++;
69668 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69669 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69670 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69671 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69672 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69673
69674 /* Increment ->n_barrier_done to prevent duplicate work. */
69675 smp_mb(); /* Keep increment after above mechanism. */
69676 - ACCESS_ONCE(rsp->n_barrier_done)++;
69677 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69678 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69679 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69680 smp_mb(); /* Keep increment before caller's subsequent code. */
69681 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69682 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69683 init_callback_list(rdp);
69684 rdp->qlen_lazy = 0;
69685 - ACCESS_ONCE(rdp->qlen) = 0;
69686 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69687 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69688 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69689 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69690 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69691 rdp->cpu = cpu;
69692 rdp->rsp = rsp;
69693 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69694 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69695 rdp->n_force_qs_snap = rsp->n_force_qs;
69696 rdp->blimit = blimit;
69697 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69698 - atomic_set(&rdp->dynticks->dynticks,
69699 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69700 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69701 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69702 rcu_prepare_for_idle_init(cpu);
69703 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69704
69705 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69706 index 4d29169..d104a3c 100644
69707 --- a/kernel/rcutree.h
69708 +++ b/kernel/rcutree.h
69709 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69710 long long dynticks_nesting; /* Track irq/process nesting level. */
69711 /* Process level is worth LLONG_MAX/2. */
69712 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69713 - atomic_t dynticks; /* Even value for idle, else odd. */
69714 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69715 #ifdef CONFIG_RCU_FAST_NO_HZ
69716 int dyntick_drain; /* Prepare-for-idle state variable. */
69717 unsigned long dyntick_holdoff;
69718 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69719 index 7f3244c..417d606 100644
69720 --- a/kernel/rcutree_plugin.h
69721 +++ b/kernel/rcutree_plugin.h
69722 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69723
69724 /* Clean up and exit. */
69725 smp_mb(); /* ensure expedited GP seen before counter increment. */
69726 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69727 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69728 unlock_mb_ret:
69729 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69730 mb_ret:
69731 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69732 index abffb48..cbfa6d3 100644
69733 --- a/kernel/rcutree_trace.c
69734 +++ b/kernel/rcutree_trace.c
69735 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69736 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69737 rdp->qs_pending);
69738 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69739 - atomic_read(&rdp->dynticks->dynticks),
69740 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69741 rdp->dynticks->dynticks_nesting,
69742 rdp->dynticks->dynticks_nmi_nesting,
69743 rdp->dynticks_fqs);
69744 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69745 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69746 rdp->qs_pending);
69747 seq_printf(m, ",%d,%llx,%d,%lu",
69748 - atomic_read(&rdp->dynticks->dynticks),
69749 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69750 rdp->dynticks->dynticks_nesting,
69751 rdp->dynticks->dynticks_nmi_nesting,
69752 rdp->dynticks_fqs);
69753 diff --git a/kernel/resource.c b/kernel/resource.c
69754 index 34d4588..10baa6a 100644
69755 --- a/kernel/resource.c
69756 +++ b/kernel/resource.c
69757 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69758
69759 static int __init ioresources_init(void)
69760 {
69761 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69762 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69763 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69764 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69765 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69766 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69767 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69768 +#endif
69769 +#else
69770 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69771 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69772 +#endif
69773 return 0;
69774 }
69775 __initcall(ioresources_init);
69776 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69777 index 98ec494..4241d6d 100644
69778 --- a/kernel/rtmutex-tester.c
69779 +++ b/kernel/rtmutex-tester.c
69780 @@ -20,7 +20,7 @@
69781 #define MAX_RT_TEST_MUTEXES 8
69782
69783 static spinlock_t rttest_lock;
69784 -static atomic_t rttest_event;
69785 +static atomic_unchecked_t rttest_event;
69786
69787 struct test_thread_data {
69788 int opcode;
69789 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69790
69791 case RTTEST_LOCKCONT:
69792 td->mutexes[td->opdata] = 1;
69793 - td->event = atomic_add_return(1, &rttest_event);
69794 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69795 return 0;
69796
69797 case RTTEST_RESET:
69798 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69799 return 0;
69800
69801 case RTTEST_RESETEVENT:
69802 - atomic_set(&rttest_event, 0);
69803 + atomic_set_unchecked(&rttest_event, 0);
69804 return 0;
69805
69806 default:
69807 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69808 return ret;
69809
69810 td->mutexes[id] = 1;
69811 - td->event = atomic_add_return(1, &rttest_event);
69812 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69813 rt_mutex_lock(&mutexes[id]);
69814 - td->event = atomic_add_return(1, &rttest_event);
69815 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69816 td->mutexes[id] = 4;
69817 return 0;
69818
69819 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69820 return ret;
69821
69822 td->mutexes[id] = 1;
69823 - td->event = atomic_add_return(1, &rttest_event);
69824 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69825 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69826 - td->event = atomic_add_return(1, &rttest_event);
69827 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69828 td->mutexes[id] = ret ? 0 : 4;
69829 return ret ? -EINTR : 0;
69830
69831 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69832 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69833 return ret;
69834
69835 - td->event = atomic_add_return(1, &rttest_event);
69836 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69837 rt_mutex_unlock(&mutexes[id]);
69838 - td->event = atomic_add_return(1, &rttest_event);
69839 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69840 td->mutexes[id] = 0;
69841 return 0;
69842
69843 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69844 break;
69845
69846 td->mutexes[dat] = 2;
69847 - td->event = atomic_add_return(1, &rttest_event);
69848 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69849 break;
69850
69851 default:
69852 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69853 return;
69854
69855 td->mutexes[dat] = 3;
69856 - td->event = atomic_add_return(1, &rttest_event);
69857 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69858 break;
69859
69860 case RTTEST_LOCKNOWAIT:
69861 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69862 return;
69863
69864 td->mutexes[dat] = 1;
69865 - td->event = atomic_add_return(1, &rttest_event);
69866 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69867 return;
69868
69869 default:
69870 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69871 index 0984a21..939f183 100644
69872 --- a/kernel/sched/auto_group.c
69873 +++ b/kernel/sched/auto_group.c
69874 @@ -11,7 +11,7 @@
69875
69876 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69877 static struct autogroup autogroup_default;
69878 -static atomic_t autogroup_seq_nr;
69879 +static atomic_unchecked_t autogroup_seq_nr;
69880
69881 void __init autogroup_init(struct task_struct *init_task)
69882 {
69883 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69884
69885 kref_init(&ag->kref);
69886 init_rwsem(&ag->lock);
69887 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69888 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69889 ag->tg = tg;
69890 #ifdef CONFIG_RT_GROUP_SCHED
69891 /*
69892 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69893 index 1a48cdb..d3949ff 100644
69894 --- a/kernel/sched/core.c
69895 +++ b/kernel/sched/core.c
69896 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69897 /* convert nice value [19,-20] to rlimit style value [1,40] */
69898 int nice_rlim = 20 - nice;
69899
69900 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69901 +
69902 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69903 capable(CAP_SYS_NICE));
69904 }
69905 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69906 if (nice > 19)
69907 nice = 19;
69908
69909 - if (increment < 0 && !can_nice(current, nice))
69910 + if (increment < 0 && (!can_nice(current, nice) ||
69911 + gr_handle_chroot_nice()))
69912 return -EPERM;
69913
69914 retval = security_task_setnice(current, nice);
69915 @@ -4290,6 +4293,7 @@ recheck:
69916 unsigned long rlim_rtprio =
69917 task_rlimit(p, RLIMIT_RTPRIO);
69918
69919 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69920 /* can't set/change the rt policy */
69921 if (policy != p->policy && !rlim_rtprio)
69922 return -EPERM;
69923 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69924 index 96e2b18..bb31eec 100644
69925 --- a/kernel/sched/fair.c
69926 +++ b/kernel/sched/fair.c
69927 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69928 * run_rebalance_domains is triggered when needed from the scheduler tick.
69929 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69930 */
69931 -static void run_rebalance_domains(struct softirq_action *h)
69932 +static void run_rebalance_domains(void)
69933 {
69934 int this_cpu = smp_processor_id();
69935 struct rq *this_rq = cpu_rq(this_cpu);
69936 diff --git a/kernel/signal.c b/kernel/signal.c
69937 index be4f856..453401c 100644
69938 --- a/kernel/signal.c
69939 +++ b/kernel/signal.c
69940 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69941
69942 int print_fatal_signals __read_mostly;
69943
69944 -static void __user *sig_handler(struct task_struct *t, int sig)
69945 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69946 {
69947 return t->sighand->action[sig - 1].sa.sa_handler;
69948 }
69949
69950 -static int sig_handler_ignored(void __user *handler, int sig)
69951 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69952 {
69953 /* Is it explicitly or implicitly ignored? */
69954 return handler == SIG_IGN ||
69955 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69956
69957 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69958 {
69959 - void __user *handler;
69960 + __sighandler_t handler;
69961
69962 handler = sig_handler(t, sig);
69963
69964 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69965 atomic_inc(&user->sigpending);
69966 rcu_read_unlock();
69967
69968 + if (!override_rlimit)
69969 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69970 +
69971 if (override_rlimit ||
69972 atomic_read(&user->sigpending) <=
69973 task_rlimit(t, RLIMIT_SIGPENDING)) {
69974 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69975
69976 int unhandled_signal(struct task_struct *tsk, int sig)
69977 {
69978 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69979 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69980 if (is_global_init(tsk))
69981 return 1;
69982 if (handler != SIG_IGN && handler != SIG_DFL)
69983 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69984 }
69985 }
69986
69987 + /* allow glibc communication via tgkill to other threads in our
69988 + thread group */
69989 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69990 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69991 + && gr_handle_signal(t, sig))
69992 + return -EPERM;
69993 +
69994 return security_task_kill(t, info, sig, 0);
69995 }
69996
69997 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69998 return send_signal(sig, info, p, 1);
69999 }
70000
70001 -static int
70002 +int
70003 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70004 {
70005 return send_signal(sig, info, t, 0);
70006 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70007 unsigned long int flags;
70008 int ret, blocked, ignored;
70009 struct k_sigaction *action;
70010 + int is_unhandled = 0;
70011
70012 spin_lock_irqsave(&t->sighand->siglock, flags);
70013 action = &t->sighand->action[sig-1];
70014 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70015 }
70016 if (action->sa.sa_handler == SIG_DFL)
70017 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70018 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70019 + is_unhandled = 1;
70020 ret = specific_send_sig_info(sig, info, t);
70021 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70022
70023 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70024 + normal operation */
70025 + if (is_unhandled) {
70026 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70027 + gr_handle_crash(t, sig);
70028 + }
70029 +
70030 return ret;
70031 }
70032
70033 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70034 ret = check_kill_permission(sig, info, p);
70035 rcu_read_unlock();
70036
70037 - if (!ret && sig)
70038 + if (!ret && sig) {
70039 ret = do_send_sig_info(sig, info, p, true);
70040 + if (!ret)
70041 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70042 + }
70043
70044 return ret;
70045 }
70046 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70047 int error = -ESRCH;
70048
70049 rcu_read_lock();
70050 - p = find_task_by_vpid(pid);
70051 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70052 + /* allow glibc communication via tgkill to other threads in our
70053 + thread group */
70054 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70055 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70056 + p = find_task_by_vpid_unrestricted(pid);
70057 + else
70058 +#endif
70059 + p = find_task_by_vpid(pid);
70060 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70061 error = check_kill_permission(sig, info, p);
70062 /*
70063 diff --git a/kernel/softirq.c b/kernel/softirq.c
70064 index b73e681..645ab62 100644
70065 --- a/kernel/softirq.c
70066 +++ b/kernel/softirq.c
70067 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70068
70069 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70070
70071 -char *softirq_to_name[NR_SOFTIRQS] = {
70072 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70073 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70074 "TASKLET", "SCHED", "HRTIMER", "RCU"
70075 };
70076 @@ -243,7 +243,7 @@ restart:
70077 kstat_incr_softirqs_this_cpu(vec_nr);
70078
70079 trace_softirq_entry(vec_nr);
70080 - h->action(h);
70081 + h->action();
70082 trace_softirq_exit(vec_nr);
70083 if (unlikely(prev_count != preempt_count())) {
70084 printk(KERN_ERR "huh, entered softirq %u %s %p"
70085 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70086 or_softirq_pending(1UL << nr);
70087 }
70088
70089 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70090 +void open_softirq(int nr, void (*action)(void))
70091 {
70092 - softirq_vec[nr].action = action;
70093 + pax_open_kernel();
70094 + *(void **)&softirq_vec[nr].action = action;
70095 + pax_close_kernel();
70096 }
70097
70098 /*
70099 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70100
70101 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70102
70103 -static void tasklet_action(struct softirq_action *a)
70104 +static void tasklet_action(void)
70105 {
70106 struct tasklet_struct *list;
70107
70108 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70109 }
70110 }
70111
70112 -static void tasklet_hi_action(struct softirq_action *a)
70113 +static void tasklet_hi_action(void)
70114 {
70115 struct tasklet_struct *list;
70116
70117 diff --git a/kernel/srcu.c b/kernel/srcu.c
70118 index 2095be3..9a5b89d 100644
70119 --- a/kernel/srcu.c
70120 +++ b/kernel/srcu.c
70121 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70122 preempt_disable();
70123 idx = rcu_dereference_index_check(sp->completed,
70124 rcu_read_lock_sched_held()) & 0x1;
70125 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70126 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70127 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70128 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70129 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70130 preempt_enable();
70131 return idx;
70132 }
70133 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70134 {
70135 preempt_disable();
70136 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70137 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70138 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70139 preempt_enable();
70140 }
70141 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70142 diff --git a/kernel/sys.c b/kernel/sys.c
70143 index 6fab59a..4ad079b 100644
70144 --- a/kernel/sys.c
70145 +++ b/kernel/sys.c
70146 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70147 error = -EACCES;
70148 goto out;
70149 }
70150 +
70151 + if (gr_handle_chroot_setpriority(p, niceval)) {
70152 + error = -EACCES;
70153 + goto out;
70154 + }
70155 +
70156 no_nice = security_task_setnice(p, niceval);
70157 if (no_nice) {
70158 error = no_nice;
70159 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70160 goto error;
70161 }
70162
70163 + if (gr_check_group_change(new->gid, new->egid, -1))
70164 + goto error;
70165 +
70166 if (rgid != (gid_t) -1 ||
70167 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70168 new->sgid = new->egid;
70169 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70170 old = current_cred();
70171
70172 retval = -EPERM;
70173 +
70174 + if (gr_check_group_change(kgid, kgid, kgid))
70175 + goto error;
70176 +
70177 if (nsown_capable(CAP_SETGID))
70178 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70179 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70180 @@ -647,7 +660,7 @@ error:
70181 /*
70182 * change the user struct in a credentials set to match the new UID
70183 */
70184 -static int set_user(struct cred *new)
70185 +int set_user(struct cred *new)
70186 {
70187 struct user_struct *new_user;
70188
70189 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70190 goto error;
70191 }
70192
70193 + if (gr_check_user_change(new->uid, new->euid, -1))
70194 + goto error;
70195 +
70196 if (!uid_eq(new->uid, old->uid)) {
70197 retval = set_user(new);
70198 if (retval < 0)
70199 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70200 old = current_cred();
70201
70202 retval = -EPERM;
70203 +
70204 + if (gr_check_crash_uid(kuid))
70205 + goto error;
70206 + if (gr_check_user_change(kuid, kuid, kuid))
70207 + goto error;
70208 +
70209 if (nsown_capable(CAP_SETUID)) {
70210 new->suid = new->uid = kuid;
70211 if (!uid_eq(kuid, old->uid)) {
70212 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70213 goto error;
70214 }
70215
70216 + if (gr_check_user_change(kruid, keuid, -1))
70217 + goto error;
70218 +
70219 if (ruid != (uid_t) -1) {
70220 new->uid = kruid;
70221 if (!uid_eq(kruid, old->uid)) {
70222 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70223 goto error;
70224 }
70225
70226 + if (gr_check_group_change(krgid, kegid, -1))
70227 + goto error;
70228 +
70229 if (rgid != (gid_t) -1)
70230 new->gid = krgid;
70231 if (egid != (gid_t) -1)
70232 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70233 if (!uid_valid(kuid))
70234 return old_fsuid;
70235
70236 + if (gr_check_user_change(-1, -1, kuid))
70237 + goto error;
70238 +
70239 new = prepare_creds();
70240 if (!new)
70241 return old_fsuid;
70242 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70243 }
70244 }
70245
70246 +error:
70247 abort_creds(new);
70248 return old_fsuid;
70249
70250 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70251 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70252 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70253 nsown_capable(CAP_SETGID)) {
70254 + if (gr_check_group_change(-1, -1, kgid))
70255 + goto error;
70256 +
70257 if (!gid_eq(kgid, old->fsgid)) {
70258 new->fsgid = kgid;
70259 goto change_okay;
70260 }
70261 }
70262
70263 +error:
70264 abort_creds(new);
70265 return old_fsgid;
70266
70267 @@ -1265,13 +1301,13 @@ DECLARE_RWSEM(uts_sem);
70268 * Work around broken programs that cannot handle "Linux 3.0".
70269 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
70270 */
70271 -static int override_release(char __user *release, int len)
70272 +static int override_release(char __user *release, size_t len)
70273 {
70274 int ret = 0;
70275 - char buf[65];
70276
70277 if (current->personality & UNAME26) {
70278 - char *rest = UTS_RELEASE;
70279 + char buf[65] = { 0 };
70280 + const char *rest = UTS_RELEASE;
70281 int ndots = 0;
70282 unsigned v;
70283
70284 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
70285 rest++;
70286 }
70287 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
70288 + if (sizeof buf < len)
70289 + len = sizeof buf;
70290 snprintf(buf, len, "2.6.%u%s", v, rest);
70291 + buf[len - 1] = 0;
70292 ret = copy_to_user(release, buf, len);
70293 }
70294 return ret;
70295 @@ -1338,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70296 return -EFAULT;
70297
70298 down_read(&uts_sem);
70299 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70300 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70301 __OLD_UTS_LEN);
70302 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70303 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70304 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70305 __OLD_UTS_LEN);
70306 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70307 - error |= __copy_to_user(&name->release, &utsname()->release,
70308 + error |= __copy_to_user(name->release, &utsname()->release,
70309 __OLD_UTS_LEN);
70310 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70311 - error |= __copy_to_user(&name->version, &utsname()->version,
70312 + error |= __copy_to_user(name->version, &utsname()->version,
70313 __OLD_UTS_LEN);
70314 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70315 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70316 + error |= __copy_to_user(name->machine, &utsname()->machine,
70317 __OLD_UTS_LEN);
70318 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70319 up_read(&uts_sem);
70320 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70321 error = get_dumpable(me->mm);
70322 break;
70323 case PR_SET_DUMPABLE:
70324 - if (arg2 < 0 || arg2 > 1) {
70325 + if (arg2 > 1) {
70326 error = -EINVAL;
70327 break;
70328 }
70329 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70330 index 87174ef..68cbb82 100644
70331 --- a/kernel/sysctl.c
70332 +++ b/kernel/sysctl.c
70333 @@ -92,7 +92,6 @@
70334
70335
70336 #if defined(CONFIG_SYSCTL)
70337 -
70338 /* External variables not in a header file. */
70339 extern int sysctl_overcommit_memory;
70340 extern int sysctl_overcommit_ratio;
70341 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70342 void __user *buffer, size_t *lenp, loff_t *ppos);
70343 #endif
70344
70345 -#ifdef CONFIG_PRINTK
70346 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70347 void __user *buffer, size_t *lenp, loff_t *ppos);
70348 -#endif
70349
70350 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70351 void __user *buffer, size_t *lenp, loff_t *ppos);
70352 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70353
70354 #endif
70355
70356 +extern struct ctl_table grsecurity_table[];
70357 +
70358 static struct ctl_table kern_table[];
70359 static struct ctl_table vm_table[];
70360 static struct ctl_table fs_table[];
70361 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70362 int sysctl_legacy_va_layout;
70363 #endif
70364
70365 +#ifdef CONFIG_PAX_SOFTMODE
70366 +static ctl_table pax_table[] = {
70367 + {
70368 + .procname = "softmode",
70369 + .data = &pax_softmode,
70370 + .maxlen = sizeof(unsigned int),
70371 + .mode = 0600,
70372 + .proc_handler = &proc_dointvec,
70373 + },
70374 +
70375 + { }
70376 +};
70377 +#endif
70378 +
70379 /* The default sysctl tables: */
70380
70381 static struct ctl_table sysctl_base_table[] = {
70382 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70383 #endif
70384
70385 static struct ctl_table kern_table[] = {
70386 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70387 + {
70388 + .procname = "grsecurity",
70389 + .mode = 0500,
70390 + .child = grsecurity_table,
70391 + },
70392 +#endif
70393 +
70394 +#ifdef CONFIG_PAX_SOFTMODE
70395 + {
70396 + .procname = "pax",
70397 + .mode = 0500,
70398 + .child = pax_table,
70399 + },
70400 +#endif
70401 +
70402 {
70403 .procname = "sched_child_runs_first",
70404 .data = &sysctl_sched_child_runs_first,
70405 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70406 .data = &modprobe_path,
70407 .maxlen = KMOD_PATH_LEN,
70408 .mode = 0644,
70409 - .proc_handler = proc_dostring,
70410 + .proc_handler = proc_dostring_modpriv,
70411 },
70412 {
70413 .procname = "modules_disabled",
70414 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70415 .extra1 = &zero,
70416 .extra2 = &one,
70417 },
70418 +#endif
70419 {
70420 .procname = "kptr_restrict",
70421 .data = &kptr_restrict,
70422 .maxlen = sizeof(int),
70423 .mode = 0644,
70424 .proc_handler = proc_dointvec_minmax_sysadmin,
70425 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70426 + .extra1 = &two,
70427 +#else
70428 .extra1 = &zero,
70429 +#endif
70430 .extra2 = &two,
70431 },
70432 -#endif
70433 {
70434 .procname = "ngroups_max",
70435 .data = &ngroups_max,
70436 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70437 .proc_handler = proc_dointvec_minmax,
70438 .extra1 = &zero,
70439 },
70440 + {
70441 + .procname = "heap_stack_gap",
70442 + .data = &sysctl_heap_stack_gap,
70443 + .maxlen = sizeof(sysctl_heap_stack_gap),
70444 + .mode = 0644,
70445 + .proc_handler = proc_doulongvec_minmax,
70446 + },
70447 #else
70448 {
70449 .procname = "nr_trim_pages",
70450 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70451 buffer, lenp, ppos);
70452 }
70453
70454 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70455 + void __user *buffer, size_t *lenp, loff_t *ppos)
70456 +{
70457 + if (write && !capable(CAP_SYS_MODULE))
70458 + return -EPERM;
70459 +
70460 + return _proc_do_string(table->data, table->maxlen, write,
70461 + buffer, lenp, ppos);
70462 +}
70463 +
70464 static size_t proc_skip_spaces(char **buf)
70465 {
70466 size_t ret;
70467 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70468 len = strlen(tmp);
70469 if (len > *size)
70470 len = *size;
70471 + if (len > sizeof(tmp))
70472 + len = sizeof(tmp);
70473 if (copy_to_user(*buf, tmp, len))
70474 return -EFAULT;
70475 *size -= len;
70476 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70477 return err;
70478 }
70479
70480 -#ifdef CONFIG_PRINTK
70481 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70482 void __user *buffer, size_t *lenp, loff_t *ppos)
70483 {
70484 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70485
70486 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70487 }
70488 -#endif
70489
70490 struct do_proc_dointvec_minmax_conv_param {
70491 int *min;
70492 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70493 *i = val;
70494 } else {
70495 val = convdiv * (*i) / convmul;
70496 - if (!first)
70497 + if (!first) {
70498 err = proc_put_char(&buffer, &left, '\t');
70499 + if (err)
70500 + break;
70501 + }
70502 err = proc_put_long(&buffer, &left, val, false);
70503 if (err)
70504 break;
70505 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70506 return -ENOSYS;
70507 }
70508
70509 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70510 + void __user *buffer, size_t *lenp, loff_t *ppos)
70511 +{
70512 + return -ENOSYS;
70513 +}
70514 +
70515 int proc_dointvec(struct ctl_table *table, int write,
70516 void __user *buffer, size_t *lenp, loff_t *ppos)
70517 {
70518 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70519 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70520 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70521 EXPORT_SYMBOL(proc_dostring);
70522 +EXPORT_SYMBOL(proc_dostring_modpriv);
70523 EXPORT_SYMBOL(proc_doulongvec_minmax);
70524 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70525 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70526 index 65bdcf1..21eb831 100644
70527 --- a/kernel/sysctl_binary.c
70528 +++ b/kernel/sysctl_binary.c
70529 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70530 int i;
70531
70532 set_fs(KERNEL_DS);
70533 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70534 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70535 set_fs(old_fs);
70536 if (result < 0)
70537 goto out_kfree;
70538 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70539 }
70540
70541 set_fs(KERNEL_DS);
70542 - result = vfs_write(file, buffer, str - buffer, &pos);
70543 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70544 set_fs(old_fs);
70545 if (result < 0)
70546 goto out_kfree;
70547 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70548 int i;
70549
70550 set_fs(KERNEL_DS);
70551 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70552 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70553 set_fs(old_fs);
70554 if (result < 0)
70555 goto out_kfree;
70556 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70557 }
70558
70559 set_fs(KERNEL_DS);
70560 - result = vfs_write(file, buffer, str - buffer, &pos);
70561 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70562 set_fs(old_fs);
70563 if (result < 0)
70564 goto out_kfree;
70565 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70566 int i;
70567
70568 set_fs(KERNEL_DS);
70569 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70570 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70571 set_fs(old_fs);
70572 if (result < 0)
70573 goto out;
70574 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70575 __le16 dnaddr;
70576
70577 set_fs(KERNEL_DS);
70578 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70579 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70580 set_fs(old_fs);
70581 if (result < 0)
70582 goto out;
70583 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70584 le16_to_cpu(dnaddr) & 0x3ff);
70585
70586 set_fs(KERNEL_DS);
70587 - result = vfs_write(file, buf, len, &pos);
70588 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70589 set_fs(old_fs);
70590 if (result < 0)
70591 goto out;
70592 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70593 index d0a3279..db0ad99 100644
70594 --- a/kernel/taskstats.c
70595 +++ b/kernel/taskstats.c
70596 @@ -27,9 +27,12 @@
70597 #include <linux/cgroup.h>
70598 #include <linux/fs.h>
70599 #include <linux/file.h>
70600 +#include <linux/grsecurity.h>
70601 #include <net/genetlink.h>
70602 #include <linux/atomic.h>
70603
70604 +extern int gr_is_taskstats_denied(int pid);
70605 +
70606 /*
70607 * Maximum length of a cpumask that can be specified in
70608 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70609 @@ -561,6 +564,9 @@ err:
70610
70611 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70612 {
70613 + if (gr_is_taskstats_denied(current->pid))
70614 + return -EACCES;
70615 +
70616 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70617 return cmd_attr_register_cpumask(info);
70618 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70619 diff --git a/kernel/time.c b/kernel/time.c
70620 index ba744cf..267b7c5 100644
70621 --- a/kernel/time.c
70622 +++ b/kernel/time.c
70623 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70624 return error;
70625
70626 if (tz) {
70627 + /* we log in do_settimeofday called below, so don't log twice
70628 + */
70629 + if (!tv)
70630 + gr_log_timechange();
70631 +
70632 sys_tz = *tz;
70633 update_vsyscall_tz();
70634 if (firsttime) {
70635 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70636 index aa27d39..34d221c 100644
70637 --- a/kernel/time/alarmtimer.c
70638 +++ b/kernel/time/alarmtimer.c
70639 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70640 struct platform_device *pdev;
70641 int error = 0;
70642 int i;
70643 - struct k_clock alarm_clock = {
70644 + static struct k_clock alarm_clock = {
70645 .clock_getres = alarm_clock_getres,
70646 .clock_get = alarm_clock_get,
70647 .timer_create = alarm_timer_create,
70648 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70649 index f113755..ec24223 100644
70650 --- a/kernel/time/tick-broadcast.c
70651 +++ b/kernel/time/tick-broadcast.c
70652 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70653 * then clear the broadcast bit.
70654 */
70655 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70656 - int cpu = smp_processor_id();
70657 + cpu = smp_processor_id();
70658
70659 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70660 tick_broadcast_clear_oneshot(cpu);
70661 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70662 index f791637..00051de 100644
70663 --- a/kernel/time/timekeeping.c
70664 +++ b/kernel/time/timekeeping.c
70665 @@ -14,6 +14,7 @@
70666 #include <linux/init.h>
70667 #include <linux/mm.h>
70668 #include <linux/sched.h>
70669 +#include <linux/grsecurity.h>
70670 #include <linux/syscore_ops.h>
70671 #include <linux/clocksource.h>
70672 #include <linux/jiffies.h>
70673 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70674 if (!timespec_valid_strict(tv))
70675 return -EINVAL;
70676
70677 + gr_log_timechange();
70678 +
70679 write_seqlock_irqsave(&tk->lock, flags);
70680
70681 timekeeping_forward_now(tk);
70682 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70683 index af5a7e9..715611a 100644
70684 --- a/kernel/time/timer_list.c
70685 +++ b/kernel/time/timer_list.c
70686 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70687
70688 static void print_name_offset(struct seq_file *m, void *sym)
70689 {
70690 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70691 + SEQ_printf(m, "<%p>", NULL);
70692 +#else
70693 char symname[KSYM_NAME_LEN];
70694
70695 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70696 SEQ_printf(m, "<%pK>", sym);
70697 else
70698 SEQ_printf(m, "%s", symname);
70699 +#endif
70700 }
70701
70702 static void
70703 @@ -112,7 +116,11 @@ next_one:
70704 static void
70705 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70706 {
70707 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70708 + SEQ_printf(m, " .base: %p\n", NULL);
70709 +#else
70710 SEQ_printf(m, " .base: %pK\n", base);
70711 +#endif
70712 SEQ_printf(m, " .index: %d\n",
70713 base->index);
70714 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70715 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70716 {
70717 struct proc_dir_entry *pe;
70718
70719 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70720 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70721 +#else
70722 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70723 +#endif
70724 if (!pe)
70725 return -ENOMEM;
70726 return 0;
70727 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70728 index 0b537f2..40d6c20 100644
70729 --- a/kernel/time/timer_stats.c
70730 +++ b/kernel/time/timer_stats.c
70731 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70732 static unsigned long nr_entries;
70733 static struct entry entries[MAX_ENTRIES];
70734
70735 -static atomic_t overflow_count;
70736 +static atomic_unchecked_t overflow_count;
70737
70738 /*
70739 * The entries are in a hash-table, for fast lookup:
70740 @@ -140,7 +140,7 @@ static void reset_entries(void)
70741 nr_entries = 0;
70742 memset(entries, 0, sizeof(entries));
70743 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70744 - atomic_set(&overflow_count, 0);
70745 + atomic_set_unchecked(&overflow_count, 0);
70746 }
70747
70748 static struct entry *alloc_entry(void)
70749 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70750 if (likely(entry))
70751 entry->count++;
70752 else
70753 - atomic_inc(&overflow_count);
70754 + atomic_inc_unchecked(&overflow_count);
70755
70756 out_unlock:
70757 raw_spin_unlock_irqrestore(lock, flags);
70758 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70759
70760 static void print_name_offset(struct seq_file *m, unsigned long addr)
70761 {
70762 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70763 + seq_printf(m, "<%p>", NULL);
70764 +#else
70765 char symname[KSYM_NAME_LEN];
70766
70767 if (lookup_symbol_name(addr, symname) < 0)
70768 - seq_printf(m, "<%p>", (void *)addr);
70769 + seq_printf(m, "<%pK>", (void *)addr);
70770 else
70771 seq_printf(m, "%s", symname);
70772 +#endif
70773 }
70774
70775 static int tstats_show(struct seq_file *m, void *v)
70776 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70777
70778 seq_puts(m, "Timer Stats Version: v0.2\n");
70779 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70780 - if (atomic_read(&overflow_count))
70781 + if (atomic_read_unchecked(&overflow_count))
70782 seq_printf(m, "Overflow: %d entries\n",
70783 - atomic_read(&overflow_count));
70784 + atomic_read_unchecked(&overflow_count));
70785
70786 for (i = 0; i < nr_entries; i++) {
70787 entry = entries + i;
70788 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70789 {
70790 struct proc_dir_entry *pe;
70791
70792 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70793 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70794 +#else
70795 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70796 +#endif
70797 if (!pe)
70798 return -ENOMEM;
70799 return 0;
70800 diff --git a/kernel/timer.c b/kernel/timer.c
70801 index 46ef2b1..ad081f144 100644
70802 --- a/kernel/timer.c
70803 +++ b/kernel/timer.c
70804 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
70805 /*
70806 * This function runs timers and the timer-tq in bottom half context.
70807 */
70808 -static void run_timer_softirq(struct softirq_action *h)
70809 +static void run_timer_softirq(void)
70810 {
70811 struct tvec_base *base = __this_cpu_read(tvec_bases);
70812
70813 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70814 index c0bd030..62a1927 100644
70815 --- a/kernel/trace/blktrace.c
70816 +++ b/kernel/trace/blktrace.c
70817 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70818 struct blk_trace *bt = filp->private_data;
70819 char buf[16];
70820
70821 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70822 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70823
70824 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70825 }
70826 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70827 return 1;
70828
70829 bt = buf->chan->private_data;
70830 - atomic_inc(&bt->dropped);
70831 + atomic_inc_unchecked(&bt->dropped);
70832 return 0;
70833 }
70834
70835 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70836
70837 bt->dir = dir;
70838 bt->dev = dev;
70839 - atomic_set(&bt->dropped, 0);
70840 + atomic_set_unchecked(&bt->dropped, 0);
70841
70842 ret = -EIO;
70843 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70844 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70845 index b4f20fb..483c5fa 100644
70846 --- a/kernel/trace/ftrace.c
70847 +++ b/kernel/trace/ftrace.c
70848 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70849 if (unlikely(ftrace_disabled))
70850 return 0;
70851
70852 + ret = ftrace_arch_code_modify_prepare();
70853 + FTRACE_WARN_ON(ret);
70854 + if (ret)
70855 + return 0;
70856 +
70857 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70858 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70859 if (ret) {
70860 ftrace_bug(ret, ip);
70861 - return 0;
70862 }
70863 - return 1;
70864 + return ret ? 0 : 1;
70865 }
70866
70867 /*
70868 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70869
70870 int
70871 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70872 - void *data)
70873 + void *data)
70874 {
70875 struct ftrace_func_probe *entry;
70876 struct ftrace_page *pg;
70877 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70878 if (!count)
70879 return 0;
70880
70881 + pax_open_kernel();
70882 sort(start, count, sizeof(*start),
70883 ftrace_cmp_ips, ftrace_swap_ips);
70884 + pax_close_kernel();
70885
70886 start_pg = ftrace_allocate_pages(count);
70887 if (!start_pg)
70888 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70889 index 5c38c81..88012af 100644
70890 --- a/kernel/trace/trace.c
70891 +++ b/kernel/trace/trace.c
70892 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70893 };
70894 #endif
70895
70896 -static struct dentry *d_tracer;
70897 -
70898 struct dentry *tracing_init_dentry(void)
70899 {
70900 + static struct dentry *d_tracer;
70901 static int once;
70902
70903 if (d_tracer)
70904 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
70905 return d_tracer;
70906 }
70907
70908 -static struct dentry *d_percpu;
70909 -
70910 struct dentry *tracing_dentry_percpu(void)
70911 {
70912 + static struct dentry *d_percpu;
70913 static int once;
70914 struct dentry *d_tracer;
70915
70916 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70917 index 29111da..d190fe2 100644
70918 --- a/kernel/trace/trace_events.c
70919 +++ b/kernel/trace/trace_events.c
70920 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70921 struct ftrace_module_file_ops {
70922 struct list_head list;
70923 struct module *mod;
70924 - struct file_operations id;
70925 - struct file_operations enable;
70926 - struct file_operations format;
70927 - struct file_operations filter;
70928 };
70929
70930 static struct ftrace_module_file_ops *
70931 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70932
70933 file_ops->mod = mod;
70934
70935 - file_ops->id = ftrace_event_id_fops;
70936 - file_ops->id.owner = mod;
70937 -
70938 - file_ops->enable = ftrace_enable_fops;
70939 - file_ops->enable.owner = mod;
70940 -
70941 - file_ops->filter = ftrace_event_filter_fops;
70942 - file_ops->filter.owner = mod;
70943 -
70944 - file_ops->format = ftrace_event_format_fops;
70945 - file_ops->format.owner = mod;
70946 + pax_open_kernel();
70947 + *(void **)&mod->trace_id.owner = mod;
70948 + *(void **)&mod->trace_enable.owner = mod;
70949 + *(void **)&mod->trace_filter.owner = mod;
70950 + *(void **)&mod->trace_format.owner = mod;
70951 + pax_close_kernel();
70952
70953 list_add(&file_ops->list, &ftrace_module_file_list);
70954
70955 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70956
70957 for_each_event(call, start, end) {
70958 __trace_add_event_call(*call, mod,
70959 - &file_ops->id, &file_ops->enable,
70960 - &file_ops->filter, &file_ops->format);
70961 + &mod->trace_id, &mod->trace_enable,
70962 + &mod->trace_filter, &mod->trace_format);
70963 }
70964 }
70965
70966 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70967 index fd3c8aa..5f324a6 100644
70968 --- a/kernel/trace/trace_mmiotrace.c
70969 +++ b/kernel/trace/trace_mmiotrace.c
70970 @@ -24,7 +24,7 @@ struct header_iter {
70971 static struct trace_array *mmio_trace_array;
70972 static bool overrun_detected;
70973 static unsigned long prev_overruns;
70974 -static atomic_t dropped_count;
70975 +static atomic_unchecked_t dropped_count;
70976
70977 static void mmio_reset_data(struct trace_array *tr)
70978 {
70979 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70980
70981 static unsigned long count_overruns(struct trace_iterator *iter)
70982 {
70983 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70984 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70985 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70986
70987 if (over > prev_overruns)
70988 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70989 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70990 sizeof(*entry), 0, pc);
70991 if (!event) {
70992 - atomic_inc(&dropped_count);
70993 + atomic_inc_unchecked(&dropped_count);
70994 return;
70995 }
70996 entry = ring_buffer_event_data(event);
70997 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70998 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70999 sizeof(*entry), 0, pc);
71000 if (!event) {
71001 - atomic_inc(&dropped_count);
71002 + atomic_inc_unchecked(&dropped_count);
71003 return;
71004 }
71005 entry = ring_buffer_event_data(event);
71006 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71007 index 123b189..97b81f5 100644
71008 --- a/kernel/trace/trace_output.c
71009 +++ b/kernel/trace/trace_output.c
71010 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71011
71012 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71013 if (!IS_ERR(p)) {
71014 - p = mangle_path(s->buffer + s->len, p, "\n");
71015 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71016 if (p) {
71017 s->len = p - s->buffer;
71018 return 1;
71019 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71020 index d4545f4..a9010a1 100644
71021 --- a/kernel/trace/trace_stack.c
71022 +++ b/kernel/trace/trace_stack.c
71023 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71024 return;
71025
71026 /* we do not handle interrupt stacks yet */
71027 - if (!object_is_on_stack(&this_size))
71028 + if (!object_starts_on_stack(&this_size))
71029 return;
71030
71031 local_irq_save(flags);
71032 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71033 index 872bd6d..31601a2 100644
71034 --- a/kernel/workqueue.c
71035 +++ b/kernel/workqueue.c
71036 @@ -1422,7 +1422,7 @@ retry:
71037 /* morph UNBOUND to REBIND atomically */
71038 worker_flags &= ~WORKER_UNBOUND;
71039 worker_flags |= WORKER_REBIND;
71040 - ACCESS_ONCE(worker->flags) = worker_flags;
71041 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71042
71043 idle_rebind.cnt++;
71044 worker->idle_rebind = &idle_rebind;
71045 @@ -1448,7 +1448,7 @@ retry:
71046 /* morph UNBOUND to REBIND atomically */
71047 worker_flags &= ~WORKER_UNBOUND;
71048 worker_flags |= WORKER_REBIND;
71049 - ACCESS_ONCE(worker->flags) = worker_flags;
71050 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71051
71052 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71053 work_data_bits(rebind_work)))
71054 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71055 index 2403a63..5c4be4c 100644
71056 --- a/lib/Kconfig.debug
71057 +++ b/lib/Kconfig.debug
71058 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71059 depends on DEBUG_KERNEL
71060 depends on STACKTRACE_SUPPORT
71061 depends on PROC_FS
71062 + depends on !GRKERNSEC_HIDESYM
71063 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71064 select KALLSYMS
71065 select KALLSYMS_ALL
71066 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71067
71068 config PROVIDE_OHCI1394_DMA_INIT
71069 bool "Remote debugging over FireWire early on boot"
71070 - depends on PCI && X86
71071 + depends on PCI && X86 && !GRKERNSEC
71072 help
71073 If you want to debug problems which hang or crash the kernel early
71074 on boot and the crashing machine has a FireWire port, you can use
71075 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71076
71077 config FIREWIRE_OHCI_REMOTE_DMA
71078 bool "Remote debugging over FireWire with firewire-ohci"
71079 - depends on FIREWIRE_OHCI
71080 + depends on FIREWIRE_OHCI && !GRKERNSEC
71081 help
71082 This option lets you use the FireWire bus for remote debugging
71083 with help of the firewire-ohci driver. It enables unfiltered
71084 diff --git a/lib/bitmap.c b/lib/bitmap.c
71085 index 06fdfa1..97c5c7d 100644
71086 --- a/lib/bitmap.c
71087 +++ b/lib/bitmap.c
71088 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71089 {
71090 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71091 u32 chunk;
71092 - const char __user __force *ubuf = (const char __user __force *)buf;
71093 + const char __user *ubuf = (const char __force_user *)buf;
71094
71095 bitmap_zero(maskp, nmaskbits);
71096
71097 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71098 {
71099 if (!access_ok(VERIFY_READ, ubuf, ulen))
71100 return -EFAULT;
71101 - return __bitmap_parse((const char __force *)ubuf,
71102 + return __bitmap_parse((const char __force_kernel *)ubuf,
71103 ulen, 1, maskp, nmaskbits);
71104
71105 }
71106 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71107 {
71108 unsigned a, b;
71109 int c, old_c, totaldigits;
71110 - const char __user __force *ubuf = (const char __user __force *)buf;
71111 + const char __user *ubuf = (const char __force_user *)buf;
71112 int exp_digit, in_range;
71113
71114 totaldigits = c = 0;
71115 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71116 {
71117 if (!access_ok(VERIFY_READ, ubuf, ulen))
71118 return -EFAULT;
71119 - return __bitmap_parselist((const char __force *)ubuf,
71120 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71121 ulen, 1, maskp, nmaskbits);
71122 }
71123 EXPORT_SYMBOL(bitmap_parselist_user);
71124 diff --git a/lib/bug.c b/lib/bug.c
71125 index a28c141..2bd3d95 100644
71126 --- a/lib/bug.c
71127 +++ b/lib/bug.c
71128 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71129 return BUG_TRAP_TYPE_NONE;
71130
71131 bug = find_bug(bugaddr);
71132 + if (!bug)
71133 + return BUG_TRAP_TYPE_NONE;
71134
71135 file = NULL;
71136 line = 0;
71137 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71138 index d11808c..dc2d6f8 100644
71139 --- a/lib/debugobjects.c
71140 +++ b/lib/debugobjects.c
71141 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71142 if (limit > 4)
71143 return;
71144
71145 - is_on_stack = object_is_on_stack(addr);
71146 + is_on_stack = object_starts_on_stack(addr);
71147 if (is_on_stack == onstack)
71148 return;
71149
71150 diff --git a/lib/devres.c b/lib/devres.c
71151 index 80b9c76..9e32279 100644
71152 --- a/lib/devres.c
71153 +++ b/lib/devres.c
71154 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71155 void devm_iounmap(struct device *dev, void __iomem *addr)
71156 {
71157 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71158 - (void *)addr));
71159 + (void __force *)addr));
71160 iounmap(addr);
71161 }
71162 EXPORT_SYMBOL(devm_iounmap);
71163 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71164 {
71165 ioport_unmap(addr);
71166 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71167 - devm_ioport_map_match, (void *)addr));
71168 + devm_ioport_map_match, (void __force *)addr));
71169 }
71170 EXPORT_SYMBOL(devm_ioport_unmap);
71171
71172 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71173 index 66ce414..6f0a0dd 100644
71174 --- a/lib/dma-debug.c
71175 +++ b/lib/dma-debug.c
71176 @@ -924,7 +924,7 @@ out:
71177
71178 static void check_for_stack(struct device *dev, void *addr)
71179 {
71180 - if (object_is_on_stack(addr))
71181 + if (object_starts_on_stack(addr))
71182 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71183 "stack [addr=%p]\n", addr);
71184 }
71185 diff --git a/lib/inflate.c b/lib/inflate.c
71186 index 013a761..c28f3fc 100644
71187 --- a/lib/inflate.c
71188 +++ b/lib/inflate.c
71189 @@ -269,7 +269,7 @@ static void free(void *where)
71190 malloc_ptr = free_mem_ptr;
71191 }
71192 #else
71193 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71194 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71195 #define free(a) kfree(a)
71196 #endif
71197
71198 diff --git a/lib/ioremap.c b/lib/ioremap.c
71199 index 0c9216c..863bd89 100644
71200 --- a/lib/ioremap.c
71201 +++ b/lib/ioremap.c
71202 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71203 unsigned long next;
71204
71205 phys_addr -= addr;
71206 - pmd = pmd_alloc(&init_mm, pud, addr);
71207 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71208 if (!pmd)
71209 return -ENOMEM;
71210 do {
71211 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71212 unsigned long next;
71213
71214 phys_addr -= addr;
71215 - pud = pud_alloc(&init_mm, pgd, addr);
71216 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71217 if (!pud)
71218 return -ENOMEM;
71219 do {
71220 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71221 index bd2bea9..6b3c95e 100644
71222 --- a/lib/is_single_threaded.c
71223 +++ b/lib/is_single_threaded.c
71224 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71225 struct task_struct *p, *t;
71226 bool ret;
71227
71228 + if (!mm)
71229 + return true;
71230 +
71231 if (atomic_read(&task->signal->live) != 1)
71232 return false;
71233
71234 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71235 index e796429..6e38f9f 100644
71236 --- a/lib/radix-tree.c
71237 +++ b/lib/radix-tree.c
71238 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71239 int nr;
71240 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71241 };
71242 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71243 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71244
71245 static inline void *ptr_to_indirect(void *ptr)
71246 {
71247 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71248 index 0e33754..50a0e63 100644
71249 --- a/lib/vsprintf.c
71250 +++ b/lib/vsprintf.c
71251 @@ -16,6 +16,9 @@
71252 * - scnprintf and vscnprintf
71253 */
71254
71255 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71256 +#define __INCLUDED_BY_HIDESYM 1
71257 +#endif
71258 #include <stdarg.h>
71259 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71260 #include <linux/types.h>
71261 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71262 char sym[KSYM_SYMBOL_LEN];
71263 if (ext == 'B')
71264 sprint_backtrace(sym, value);
71265 - else if (ext != 'f' && ext != 's')
71266 + else if (ext != 'f' && ext != 's' && ext != 'a')
71267 sprint_symbol(sym, value);
71268 else
71269 sprint_symbol_no_offset(sym, value);
71270 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71271 return number(buf, end, *(const netdev_features_t *)addr, spec);
71272 }
71273
71274 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71275 +int kptr_restrict __read_mostly = 2;
71276 +#else
71277 int kptr_restrict __read_mostly;
71278 +#endif
71279
71280 /*
71281 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71282 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71283 * - 'S' For symbolic direct pointers with offset
71284 * - 's' For symbolic direct pointers without offset
71285 * - 'B' For backtraced symbolic direct pointers with offset
71286 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71287 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71288 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71289 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71290 * - 'M' For a 6-byte MAC address, it prints the address in the
71291 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71292
71293 if (!ptr && *fmt != 'K') {
71294 /*
71295 - * Print (null) with the same width as a pointer so it makes
71296 + * Print (nil) with the same width as a pointer so it makes
71297 * tabular output look nice.
71298 */
71299 if (spec.field_width == -1)
71300 spec.field_width = default_width;
71301 - return string(buf, end, "(null)", spec);
71302 + return string(buf, end, "(nil)", spec);
71303 }
71304
71305 switch (*fmt) {
71306 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71307 /* Fallthrough */
71308 case 'S':
71309 case 's':
71310 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71311 + break;
71312 +#else
71313 + return symbol_string(buf, end, ptr, spec, *fmt);
71314 +#endif
71315 + case 'A':
71316 + case 'a':
71317 case 'B':
71318 return symbol_string(buf, end, ptr, spec, *fmt);
71319 case 'R':
71320 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71321 va_end(va);
71322 return buf;
71323 }
71324 + case 'P':
71325 + break;
71326 case 'K':
71327 /*
71328 * %pK cannot be used in IRQ context because its test
71329 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71330 }
71331 break;
71332 }
71333 +
71334 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71335 + /* 'P' = approved pointers to copy to userland,
71336 + as in the /proc/kallsyms case, as we make it display nothing
71337 + for non-root users, and the real contents for root users
71338 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71339 + above
71340 + */
71341 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71342 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71343 + dump_stack();
71344 + ptr = NULL;
71345 + }
71346 +#endif
71347 +
71348 spec.flags |= SMALL;
71349 if (spec.field_width == -1) {
71350 spec.field_width = default_width;
71351 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71352 typeof(type) value; \
71353 if (sizeof(type) == 8) { \
71354 args = PTR_ALIGN(args, sizeof(u32)); \
71355 - *(u32 *)&value = *(u32 *)args; \
71356 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71357 + *(u32 *)&value = *(const u32 *)args; \
71358 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71359 } else { \
71360 args = PTR_ALIGN(args, sizeof(type)); \
71361 - value = *(typeof(type) *)args; \
71362 + value = *(const typeof(type) *)args; \
71363 } \
71364 args += sizeof(type); \
71365 value; \
71366 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71367 case FORMAT_TYPE_STR: {
71368 const char *str_arg = args;
71369 args += strlen(str_arg) + 1;
71370 - str = string(str, end, (char *)str_arg, spec);
71371 + str = string(str, end, str_arg, spec);
71372 break;
71373 }
71374
71375 diff --git a/localversion-grsec b/localversion-grsec
71376 new file mode 100644
71377 index 0000000..7cd6065
71378 --- /dev/null
71379 +++ b/localversion-grsec
71380 @@ -0,0 +1 @@
71381 +-grsec
71382 diff --git a/mm/Kconfig b/mm/Kconfig
71383 index d5c8019..f513038 100644
71384 --- a/mm/Kconfig
71385 +++ b/mm/Kconfig
71386 @@ -251,10 +251,10 @@ config KSM
71387 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71388
71389 config DEFAULT_MMAP_MIN_ADDR
71390 - int "Low address space to protect from user allocation"
71391 + int "Low address space to protect from user allocation"
71392 depends on MMU
71393 - default 4096
71394 - help
71395 + default 65536
71396 + help
71397 This is the portion of low virtual memory which should be protected
71398 from userspace allocation. Keeping a user from writing to low pages
71399 can help reduce the impact of kernel NULL pointer bugs.
71400 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71401
71402 config HWPOISON_INJECT
71403 tristate "HWPoison pages injector"
71404 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71405 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71406 select PROC_PAGE_MONITOR
71407
71408 config NOMMU_INITIAL_TRIM_EXCESS
71409 diff --git a/mm/filemap.c b/mm/filemap.c
71410 index 3843445..4fe6833 100644
71411 --- a/mm/filemap.c
71412 +++ b/mm/filemap.c
71413 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71414 struct address_space *mapping = file->f_mapping;
71415
71416 if (!mapping->a_ops->readpage)
71417 - return -ENOEXEC;
71418 + return -ENODEV;
71419 file_accessed(file);
71420 vma->vm_ops = &generic_file_vm_ops;
71421 vma->vm_flags |= VM_CAN_NONLINEAR;
71422 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71423 *pos = i_size_read(inode);
71424
71425 if (limit != RLIM_INFINITY) {
71426 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71427 if (*pos >= limit) {
71428 send_sig(SIGXFSZ, current, 0);
71429 return -EFBIG;
71430 diff --git a/mm/fremap.c b/mm/fremap.c
71431 index 9ed4fd4..c42648d 100644
71432 --- a/mm/fremap.c
71433 +++ b/mm/fremap.c
71434 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71435 retry:
71436 vma = find_vma(mm, start);
71437
71438 +#ifdef CONFIG_PAX_SEGMEXEC
71439 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71440 + goto out;
71441 +#endif
71442 +
71443 /*
71444 * Make sure the vma is shared, that it supports prefaulting,
71445 * and that the remapped range is valid and fully within
71446 diff --git a/mm/highmem.c b/mm/highmem.c
71447 index d517cd1..006a1c5 100644
71448 --- a/mm/highmem.c
71449 +++ b/mm/highmem.c
71450 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71451 * So no dangers, even with speculative execution.
71452 */
71453 page = pte_page(pkmap_page_table[i]);
71454 + pax_open_kernel();
71455 pte_clear(&init_mm, (unsigned long)page_address(page),
71456 &pkmap_page_table[i]);
71457 -
71458 + pax_close_kernel();
71459 set_page_address(page, NULL);
71460 need_flush = 1;
71461 }
71462 @@ -198,9 +199,11 @@ start:
71463 }
71464 }
71465 vaddr = PKMAP_ADDR(last_pkmap_nr);
71466 +
71467 + pax_open_kernel();
71468 set_pte_at(&init_mm, vaddr,
71469 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71470 -
71471 + pax_close_kernel();
71472 pkmap_count[last_pkmap_nr] = 1;
71473 set_page_address(page, (void *)vaddr);
71474
71475 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71476 index 141dbb6..ebff057 100644
71477 --- a/mm/huge_memory.c
71478 +++ b/mm/huge_memory.c
71479 @@ -735,7 +735,7 @@ out:
71480 * run pte_offset_map on the pmd, if an huge pmd could
71481 * materialize from under us from a different thread.
71482 */
71483 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71484 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71485 return VM_FAULT_OOM;
71486 /* if an huge pmd materialized from under us just retry later */
71487 if (unlikely(pmd_trans_huge(*pmd)))
71488 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71489 index 3adceaf..dccfea3 100644
71490 --- a/mm/hugetlb.c
71491 +++ b/mm/hugetlb.c
71492 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71493 return 1;
71494 }
71495
71496 +#ifdef CONFIG_PAX_SEGMEXEC
71497 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71498 +{
71499 + struct mm_struct *mm = vma->vm_mm;
71500 + struct vm_area_struct *vma_m;
71501 + unsigned long address_m;
71502 + pte_t *ptep_m;
71503 +
71504 + vma_m = pax_find_mirror_vma(vma);
71505 + if (!vma_m)
71506 + return;
71507 +
71508 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71509 + address_m = address + SEGMEXEC_TASK_SIZE;
71510 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71511 + get_page(page_m);
71512 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71513 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71514 +}
71515 +#endif
71516 +
71517 /*
71518 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71519 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71520 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71521 make_huge_pte(vma, new_page, 1));
71522 page_remove_rmap(old_page);
71523 hugepage_add_new_anon_rmap(new_page, vma, address);
71524 +
71525 +#ifdef CONFIG_PAX_SEGMEXEC
71526 + pax_mirror_huge_pte(vma, address, new_page);
71527 +#endif
71528 +
71529 /* Make the old page be freed below */
71530 new_page = old_page;
71531 mmu_notifier_invalidate_range_end(mm,
71532 @@ -2786,6 +2812,10 @@ retry:
71533 && (vma->vm_flags & VM_SHARED)));
71534 set_huge_pte_at(mm, address, ptep, new_pte);
71535
71536 +#ifdef CONFIG_PAX_SEGMEXEC
71537 + pax_mirror_huge_pte(vma, address, page);
71538 +#endif
71539 +
71540 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71541 /* Optimization, do the COW without a second fault */
71542 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71543 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71544 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71545 struct hstate *h = hstate_vma(vma);
71546
71547 +#ifdef CONFIG_PAX_SEGMEXEC
71548 + struct vm_area_struct *vma_m;
71549 +#endif
71550 +
71551 address &= huge_page_mask(h);
71552
71553 ptep = huge_pte_offset(mm, address);
71554 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71555 VM_FAULT_SET_HINDEX(hstate_index(h));
71556 }
71557
71558 +#ifdef CONFIG_PAX_SEGMEXEC
71559 + vma_m = pax_find_mirror_vma(vma);
71560 + if (vma_m) {
71561 + unsigned long address_m;
71562 +
71563 + if (vma->vm_start > vma_m->vm_start) {
71564 + address_m = address;
71565 + address -= SEGMEXEC_TASK_SIZE;
71566 + vma = vma_m;
71567 + h = hstate_vma(vma);
71568 + } else
71569 + address_m = address + SEGMEXEC_TASK_SIZE;
71570 +
71571 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71572 + return VM_FAULT_OOM;
71573 + address_m &= HPAGE_MASK;
71574 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71575 + }
71576 +#endif
71577 +
71578 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71579 if (!ptep)
71580 return VM_FAULT_OOM;
71581 diff --git a/mm/internal.h b/mm/internal.h
71582 index b8c91b3..93e95a3 100644
71583 --- a/mm/internal.h
71584 +++ b/mm/internal.h
71585 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71586 * in mm/page_alloc.c
71587 */
71588 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71589 +extern void free_compound_page(struct page *page);
71590 extern void prep_compound_page(struct page *page, unsigned long order);
71591 #ifdef CONFIG_MEMORY_FAILURE
71592 extern bool is_free_buddy_page(struct page *page);
71593 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71594 index 45eb621..6ccd8ea 100644
71595 --- a/mm/kmemleak.c
71596 +++ b/mm/kmemleak.c
71597 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71598
71599 for (i = 0; i < object->trace_len; i++) {
71600 void *ptr = (void *)object->trace[i];
71601 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71602 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71603 }
71604 }
71605
71606 diff --git a/mm/maccess.c b/mm/maccess.c
71607 index d53adf9..03a24bf 100644
71608 --- a/mm/maccess.c
71609 +++ b/mm/maccess.c
71610 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71611 set_fs(KERNEL_DS);
71612 pagefault_disable();
71613 ret = __copy_from_user_inatomic(dst,
71614 - (__force const void __user *)src, size);
71615 + (const void __force_user *)src, size);
71616 pagefault_enable();
71617 set_fs(old_fs);
71618
71619 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71620
71621 set_fs(KERNEL_DS);
71622 pagefault_disable();
71623 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71624 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71625 pagefault_enable();
71626 set_fs(old_fs);
71627
71628 diff --git a/mm/madvise.c b/mm/madvise.c
71629 index 14d260f..b2a80fd 100644
71630 --- a/mm/madvise.c
71631 +++ b/mm/madvise.c
71632 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71633 pgoff_t pgoff;
71634 unsigned long new_flags = vma->vm_flags;
71635
71636 +#ifdef CONFIG_PAX_SEGMEXEC
71637 + struct vm_area_struct *vma_m;
71638 +#endif
71639 +
71640 switch (behavior) {
71641 case MADV_NORMAL:
71642 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71643 @@ -119,6 +123,13 @@ success:
71644 /*
71645 * vm_flags is protected by the mmap_sem held in write mode.
71646 */
71647 +
71648 +#ifdef CONFIG_PAX_SEGMEXEC
71649 + vma_m = pax_find_mirror_vma(vma);
71650 + if (vma_m)
71651 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71652 +#endif
71653 +
71654 vma->vm_flags = new_flags;
71655
71656 out:
71657 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71658 struct vm_area_struct ** prev,
71659 unsigned long start, unsigned long end)
71660 {
71661 +
71662 +#ifdef CONFIG_PAX_SEGMEXEC
71663 + struct vm_area_struct *vma_m;
71664 +#endif
71665 +
71666 *prev = vma;
71667 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71668 return -EINVAL;
71669 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71670 zap_page_range(vma, start, end - start, &details);
71671 } else
71672 zap_page_range(vma, start, end - start, NULL);
71673 +
71674 +#ifdef CONFIG_PAX_SEGMEXEC
71675 + vma_m = pax_find_mirror_vma(vma);
71676 + if (vma_m) {
71677 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71678 + struct zap_details details = {
71679 + .nonlinear_vma = vma_m,
71680 + .last_index = ULONG_MAX,
71681 + };
71682 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71683 + } else
71684 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71685 + }
71686 +#endif
71687 +
71688 return 0;
71689 }
71690
71691 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71692 if (end < start)
71693 goto out;
71694
71695 +#ifdef CONFIG_PAX_SEGMEXEC
71696 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71697 + if (end > SEGMEXEC_TASK_SIZE)
71698 + goto out;
71699 + } else
71700 +#endif
71701 +
71702 + if (end > TASK_SIZE)
71703 + goto out;
71704 +
71705 error = 0;
71706 if (end == start)
71707 goto out;
71708 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71709 index a6e2141..eaf5aad 100644
71710 --- a/mm/memory-failure.c
71711 +++ b/mm/memory-failure.c
71712 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71713
71714 int sysctl_memory_failure_recovery __read_mostly = 1;
71715
71716 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71717 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71718
71719 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71720
71721 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71722 pfn, t->comm, t->pid);
71723 si.si_signo = SIGBUS;
71724 si.si_errno = 0;
71725 - si.si_addr = (void *)addr;
71726 + si.si_addr = (void __user *)addr;
71727 #ifdef __ARCH_SI_TRAPNO
71728 si.si_trapno = trapno;
71729 #endif
71730 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71731 }
71732
71733 nr_pages = 1 << compound_trans_order(hpage);
71734 - atomic_long_add(nr_pages, &mce_bad_pages);
71735 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71736
71737 /*
71738 * We need/can do nothing about count=0 pages.
71739 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71740 if (!PageHWPoison(hpage)
71741 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71742 || (p != hpage && TestSetPageHWPoison(hpage))) {
71743 - atomic_long_sub(nr_pages, &mce_bad_pages);
71744 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71745 return 0;
71746 }
71747 set_page_hwpoison_huge_page(hpage);
71748 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71749 }
71750 if (hwpoison_filter(p)) {
71751 if (TestClearPageHWPoison(p))
71752 - atomic_long_sub(nr_pages, &mce_bad_pages);
71753 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71754 unlock_page(hpage);
71755 put_page(hpage);
71756 return 0;
71757 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71758 return 0;
71759 }
71760 if (TestClearPageHWPoison(p))
71761 - atomic_long_sub(nr_pages, &mce_bad_pages);
71762 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71763 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71764 return 0;
71765 }
71766 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71767 */
71768 if (TestClearPageHWPoison(page)) {
71769 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71770 - atomic_long_sub(nr_pages, &mce_bad_pages);
71771 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71772 freeit = 1;
71773 if (PageHuge(page))
71774 clear_page_hwpoison_huge_page(page);
71775 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71776 }
71777 done:
71778 if (!PageHWPoison(hpage))
71779 - atomic_long_add(1 << compound_trans_order(hpage),
71780 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71781 &mce_bad_pages);
71782 set_page_hwpoison_huge_page(hpage);
71783 dequeue_hwpoisoned_huge_page(hpage);
71784 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71785 return ret;
71786
71787 done:
71788 - atomic_long_add(1, &mce_bad_pages);
71789 + atomic_long_add_unchecked(1, &mce_bad_pages);
71790 SetPageHWPoison(page);
71791 /* keep elevated page count for bad page */
71792 return ret;
71793 diff --git a/mm/memory.c b/mm/memory.c
71794 index 5736170..8e04800 100644
71795 --- a/mm/memory.c
71796 +++ b/mm/memory.c
71797 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71798 free_pte_range(tlb, pmd, addr);
71799 } while (pmd++, addr = next, addr != end);
71800
71801 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71802 start &= PUD_MASK;
71803 if (start < floor)
71804 return;
71805 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71806 pmd = pmd_offset(pud, start);
71807 pud_clear(pud);
71808 pmd_free_tlb(tlb, pmd, start);
71809 +#endif
71810 +
71811 }
71812
71813 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71814 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71815 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71816 } while (pud++, addr = next, addr != end);
71817
71818 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71819 start &= PGDIR_MASK;
71820 if (start < floor)
71821 return;
71822 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71823 pud = pud_offset(pgd, start);
71824 pgd_clear(pgd);
71825 pud_free_tlb(tlb, pud, start);
71826 +#endif
71827 +
71828 }
71829
71830 /*
71831 @@ -1614,12 +1620,6 @@ no_page_table:
71832 return page;
71833 }
71834
71835 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71836 -{
71837 - return stack_guard_page_start(vma, addr) ||
71838 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71839 -}
71840 -
71841 /**
71842 * __get_user_pages() - pin user pages in memory
71843 * @tsk: task_struct of target task
71844 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71845 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71846 i = 0;
71847
71848 - do {
71849 + while (nr_pages) {
71850 struct vm_area_struct *vma;
71851
71852 - vma = find_extend_vma(mm, start);
71853 + vma = find_vma(mm, start);
71854 if (!vma && in_gate_area(mm, start)) {
71855 unsigned long pg = start & PAGE_MASK;
71856 pgd_t *pgd;
71857 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71858 goto next_page;
71859 }
71860
71861 - if (!vma ||
71862 + if (!vma || start < vma->vm_start ||
71863 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71864 !(vm_flags & vma->vm_flags))
71865 return i ? : -EFAULT;
71866 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71867 int ret;
71868 unsigned int fault_flags = 0;
71869
71870 - /* For mlock, just skip the stack guard page. */
71871 - if (foll_flags & FOLL_MLOCK) {
71872 - if (stack_guard_page(vma, start))
71873 - goto next_page;
71874 - }
71875 if (foll_flags & FOLL_WRITE)
71876 fault_flags |= FAULT_FLAG_WRITE;
71877 if (nonblocking)
71878 @@ -1848,7 +1843,7 @@ next_page:
71879 start += PAGE_SIZE;
71880 nr_pages--;
71881 } while (nr_pages && start < vma->vm_end);
71882 - } while (nr_pages);
71883 + }
71884 return i;
71885 }
71886 EXPORT_SYMBOL(__get_user_pages);
71887 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71888 page_add_file_rmap(page);
71889 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71890
71891 +#ifdef CONFIG_PAX_SEGMEXEC
71892 + pax_mirror_file_pte(vma, addr, page, ptl);
71893 +#endif
71894 +
71895 retval = 0;
71896 pte_unmap_unlock(pte, ptl);
71897 return retval;
71898 @@ -2089,10 +2088,22 @@ out:
71899 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71900 struct page *page)
71901 {
71902 +
71903 +#ifdef CONFIG_PAX_SEGMEXEC
71904 + struct vm_area_struct *vma_m;
71905 +#endif
71906 +
71907 if (addr < vma->vm_start || addr >= vma->vm_end)
71908 return -EFAULT;
71909 if (!page_count(page))
71910 return -EINVAL;
71911 +
71912 +#ifdef CONFIG_PAX_SEGMEXEC
71913 + vma_m = pax_find_mirror_vma(vma);
71914 + if (vma_m)
71915 + vma_m->vm_flags |= VM_INSERTPAGE;
71916 +#endif
71917 +
71918 vma->vm_flags |= VM_INSERTPAGE;
71919 return insert_page(vma, addr, page, vma->vm_page_prot);
71920 }
71921 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71922 unsigned long pfn)
71923 {
71924 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71925 + BUG_ON(vma->vm_mirror);
71926
71927 if (addr < vma->vm_start || addr >= vma->vm_end)
71928 return -EFAULT;
71929 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71930
71931 BUG_ON(pud_huge(*pud));
71932
71933 - pmd = pmd_alloc(mm, pud, addr);
71934 + pmd = (mm == &init_mm) ?
71935 + pmd_alloc_kernel(mm, pud, addr) :
71936 + pmd_alloc(mm, pud, addr);
71937 if (!pmd)
71938 return -ENOMEM;
71939 do {
71940 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71941 unsigned long next;
71942 int err;
71943
71944 - pud = pud_alloc(mm, pgd, addr);
71945 + pud = (mm == &init_mm) ?
71946 + pud_alloc_kernel(mm, pgd, addr) :
71947 + pud_alloc(mm, pgd, addr);
71948 if (!pud)
71949 return -ENOMEM;
71950 do {
71951 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71952 copy_user_highpage(dst, src, va, vma);
71953 }
71954
71955 +#ifdef CONFIG_PAX_SEGMEXEC
71956 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71957 +{
71958 + struct mm_struct *mm = vma->vm_mm;
71959 + spinlock_t *ptl;
71960 + pte_t *pte, entry;
71961 +
71962 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71963 + entry = *pte;
71964 + if (!pte_present(entry)) {
71965 + if (!pte_none(entry)) {
71966 + BUG_ON(pte_file(entry));
71967 + free_swap_and_cache(pte_to_swp_entry(entry));
71968 + pte_clear_not_present_full(mm, address, pte, 0);
71969 + }
71970 + } else {
71971 + struct page *page;
71972 +
71973 + flush_cache_page(vma, address, pte_pfn(entry));
71974 + entry = ptep_clear_flush(vma, address, pte);
71975 + BUG_ON(pte_dirty(entry));
71976 + page = vm_normal_page(vma, address, entry);
71977 + if (page) {
71978 + update_hiwater_rss(mm);
71979 + if (PageAnon(page))
71980 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71981 + else
71982 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71983 + page_remove_rmap(page);
71984 + page_cache_release(page);
71985 + }
71986 + }
71987 + pte_unmap_unlock(pte, ptl);
71988 +}
71989 +
71990 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71991 + *
71992 + * the ptl of the lower mapped page is held on entry and is not released on exit
71993 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71994 + */
71995 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71996 +{
71997 + struct mm_struct *mm = vma->vm_mm;
71998 + unsigned long address_m;
71999 + spinlock_t *ptl_m;
72000 + struct vm_area_struct *vma_m;
72001 + pmd_t *pmd_m;
72002 + pte_t *pte_m, entry_m;
72003 +
72004 + BUG_ON(!page_m || !PageAnon(page_m));
72005 +
72006 + vma_m = pax_find_mirror_vma(vma);
72007 + if (!vma_m)
72008 + return;
72009 +
72010 + BUG_ON(!PageLocked(page_m));
72011 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72012 + address_m = address + SEGMEXEC_TASK_SIZE;
72013 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72014 + pte_m = pte_offset_map(pmd_m, address_m);
72015 + ptl_m = pte_lockptr(mm, pmd_m);
72016 + if (ptl != ptl_m) {
72017 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72018 + if (!pte_none(*pte_m))
72019 + goto out;
72020 + }
72021 +
72022 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72023 + page_cache_get(page_m);
72024 + page_add_anon_rmap(page_m, vma_m, address_m);
72025 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72026 + set_pte_at(mm, address_m, pte_m, entry_m);
72027 + update_mmu_cache(vma_m, address_m, entry_m);
72028 +out:
72029 + if (ptl != ptl_m)
72030 + spin_unlock(ptl_m);
72031 + pte_unmap(pte_m);
72032 + unlock_page(page_m);
72033 +}
72034 +
72035 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72036 +{
72037 + struct mm_struct *mm = vma->vm_mm;
72038 + unsigned long address_m;
72039 + spinlock_t *ptl_m;
72040 + struct vm_area_struct *vma_m;
72041 + pmd_t *pmd_m;
72042 + pte_t *pte_m, entry_m;
72043 +
72044 + BUG_ON(!page_m || PageAnon(page_m));
72045 +
72046 + vma_m = pax_find_mirror_vma(vma);
72047 + if (!vma_m)
72048 + return;
72049 +
72050 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72051 + address_m = address + SEGMEXEC_TASK_SIZE;
72052 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72053 + pte_m = pte_offset_map(pmd_m, address_m);
72054 + ptl_m = pte_lockptr(mm, pmd_m);
72055 + if (ptl != ptl_m) {
72056 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72057 + if (!pte_none(*pte_m))
72058 + goto out;
72059 + }
72060 +
72061 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72062 + page_cache_get(page_m);
72063 + page_add_file_rmap(page_m);
72064 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72065 + set_pte_at(mm, address_m, pte_m, entry_m);
72066 + update_mmu_cache(vma_m, address_m, entry_m);
72067 +out:
72068 + if (ptl != ptl_m)
72069 + spin_unlock(ptl_m);
72070 + pte_unmap(pte_m);
72071 +}
72072 +
72073 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72074 +{
72075 + struct mm_struct *mm = vma->vm_mm;
72076 + unsigned long address_m;
72077 + spinlock_t *ptl_m;
72078 + struct vm_area_struct *vma_m;
72079 + pmd_t *pmd_m;
72080 + pte_t *pte_m, entry_m;
72081 +
72082 + vma_m = pax_find_mirror_vma(vma);
72083 + if (!vma_m)
72084 + return;
72085 +
72086 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72087 + address_m = address + SEGMEXEC_TASK_SIZE;
72088 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72089 + pte_m = pte_offset_map(pmd_m, address_m);
72090 + ptl_m = pte_lockptr(mm, pmd_m);
72091 + if (ptl != ptl_m) {
72092 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72093 + if (!pte_none(*pte_m))
72094 + goto out;
72095 + }
72096 +
72097 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72098 + set_pte_at(mm, address_m, pte_m, entry_m);
72099 +out:
72100 + if (ptl != ptl_m)
72101 + spin_unlock(ptl_m);
72102 + pte_unmap(pte_m);
72103 +}
72104 +
72105 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72106 +{
72107 + struct page *page_m;
72108 + pte_t entry;
72109 +
72110 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72111 + goto out;
72112 +
72113 + entry = *pte;
72114 + page_m = vm_normal_page(vma, address, entry);
72115 + if (!page_m)
72116 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72117 + else if (PageAnon(page_m)) {
72118 + if (pax_find_mirror_vma(vma)) {
72119 + pte_unmap_unlock(pte, ptl);
72120 + lock_page(page_m);
72121 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72122 + if (pte_same(entry, *pte))
72123 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72124 + else
72125 + unlock_page(page_m);
72126 + }
72127 + } else
72128 + pax_mirror_file_pte(vma, address, page_m, ptl);
72129 +
72130 +out:
72131 + pte_unmap_unlock(pte, ptl);
72132 +}
72133 +#endif
72134 +
72135 /*
72136 * This routine handles present pages, when users try to write
72137 * to a shared page. It is done by copying the page to a new address
72138 @@ -2703,6 +2899,12 @@ gotten:
72139 */
72140 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72141 if (likely(pte_same(*page_table, orig_pte))) {
72142 +
72143 +#ifdef CONFIG_PAX_SEGMEXEC
72144 + if (pax_find_mirror_vma(vma))
72145 + BUG_ON(!trylock_page(new_page));
72146 +#endif
72147 +
72148 if (old_page) {
72149 if (!PageAnon(old_page)) {
72150 dec_mm_counter_fast(mm, MM_FILEPAGES);
72151 @@ -2754,6 +2956,10 @@ gotten:
72152 page_remove_rmap(old_page);
72153 }
72154
72155 +#ifdef CONFIG_PAX_SEGMEXEC
72156 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72157 +#endif
72158 +
72159 /* Free the old page.. */
72160 new_page = old_page;
72161 ret |= VM_FAULT_WRITE;
72162 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72163 swap_free(entry);
72164 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72165 try_to_free_swap(page);
72166 +
72167 +#ifdef CONFIG_PAX_SEGMEXEC
72168 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72169 +#endif
72170 +
72171 unlock_page(page);
72172 if (swapcache) {
72173 /*
72174 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72175
72176 /* No need to invalidate - it was non-present before */
72177 update_mmu_cache(vma, address, page_table);
72178 +
72179 +#ifdef CONFIG_PAX_SEGMEXEC
72180 + pax_mirror_anon_pte(vma, address, page, ptl);
72181 +#endif
72182 +
72183 unlock:
72184 pte_unmap_unlock(page_table, ptl);
72185 out:
72186 @@ -3075,40 +3291,6 @@ out_release:
72187 }
72188
72189 /*
72190 - * This is like a special single-page "expand_{down|up}wards()",
72191 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72192 - * doesn't hit another vma.
72193 - */
72194 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72195 -{
72196 - address &= PAGE_MASK;
72197 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72198 - struct vm_area_struct *prev = vma->vm_prev;
72199 -
72200 - /*
72201 - * Is there a mapping abutting this one below?
72202 - *
72203 - * That's only ok if it's the same stack mapping
72204 - * that has gotten split..
72205 - */
72206 - if (prev && prev->vm_end == address)
72207 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72208 -
72209 - expand_downwards(vma, address - PAGE_SIZE);
72210 - }
72211 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72212 - struct vm_area_struct *next = vma->vm_next;
72213 -
72214 - /* As VM_GROWSDOWN but s/below/above/ */
72215 - if (next && next->vm_start == address + PAGE_SIZE)
72216 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72217 -
72218 - expand_upwards(vma, address + PAGE_SIZE);
72219 - }
72220 - return 0;
72221 -}
72222 -
72223 -/*
72224 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72225 * but allow concurrent faults), and pte mapped but not yet locked.
72226 * We return with mmap_sem still held, but pte unmapped and unlocked.
72227 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72228 unsigned long address, pte_t *page_table, pmd_t *pmd,
72229 unsigned int flags)
72230 {
72231 - struct page *page;
72232 + struct page *page = NULL;
72233 spinlock_t *ptl;
72234 pte_t entry;
72235
72236 - pte_unmap(page_table);
72237 -
72238 - /* Check if we need to add a guard page to the stack */
72239 - if (check_stack_guard_page(vma, address) < 0)
72240 - return VM_FAULT_SIGBUS;
72241 -
72242 - /* Use the zero-page for reads */
72243 if (!(flags & FAULT_FLAG_WRITE)) {
72244 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72245 vma->vm_page_prot));
72246 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72247 + ptl = pte_lockptr(mm, pmd);
72248 + spin_lock(ptl);
72249 if (!pte_none(*page_table))
72250 goto unlock;
72251 goto setpte;
72252 }
72253
72254 /* Allocate our own private page. */
72255 + pte_unmap(page_table);
72256 +
72257 if (unlikely(anon_vma_prepare(vma)))
72258 goto oom;
72259 page = alloc_zeroed_user_highpage_movable(vma, address);
72260 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72261 if (!pte_none(*page_table))
72262 goto release;
72263
72264 +#ifdef CONFIG_PAX_SEGMEXEC
72265 + if (pax_find_mirror_vma(vma))
72266 + BUG_ON(!trylock_page(page));
72267 +#endif
72268 +
72269 inc_mm_counter_fast(mm, MM_ANONPAGES);
72270 page_add_new_anon_rmap(page, vma, address);
72271 setpte:
72272 @@ -3163,6 +3346,12 @@ setpte:
72273
72274 /* No need to invalidate - it was non-present before */
72275 update_mmu_cache(vma, address, page_table);
72276 +
72277 +#ifdef CONFIG_PAX_SEGMEXEC
72278 + if (page)
72279 + pax_mirror_anon_pte(vma, address, page, ptl);
72280 +#endif
72281 +
72282 unlock:
72283 pte_unmap_unlock(page_table, ptl);
72284 return 0;
72285 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72286 */
72287 /* Only go through if we didn't race with anybody else... */
72288 if (likely(pte_same(*page_table, orig_pte))) {
72289 +
72290 +#ifdef CONFIG_PAX_SEGMEXEC
72291 + if (anon && pax_find_mirror_vma(vma))
72292 + BUG_ON(!trylock_page(page));
72293 +#endif
72294 +
72295 flush_icache_page(vma, page);
72296 entry = mk_pte(page, vma->vm_page_prot);
72297 if (flags & FAULT_FLAG_WRITE)
72298 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72299
72300 /* no need to invalidate: a not-present page won't be cached */
72301 update_mmu_cache(vma, address, page_table);
72302 +
72303 +#ifdef CONFIG_PAX_SEGMEXEC
72304 + if (anon)
72305 + pax_mirror_anon_pte(vma, address, page, ptl);
72306 + else
72307 + pax_mirror_file_pte(vma, address, page, ptl);
72308 +#endif
72309 +
72310 } else {
72311 if (cow_page)
72312 mem_cgroup_uncharge_page(cow_page);
72313 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72314 if (flags & FAULT_FLAG_WRITE)
72315 flush_tlb_fix_spurious_fault(vma, address);
72316 }
72317 +
72318 +#ifdef CONFIG_PAX_SEGMEXEC
72319 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72320 + return 0;
72321 +#endif
72322 +
72323 unlock:
72324 pte_unmap_unlock(pte, ptl);
72325 return 0;
72326 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72327 pmd_t *pmd;
72328 pte_t *pte;
72329
72330 +#ifdef CONFIG_PAX_SEGMEXEC
72331 + struct vm_area_struct *vma_m;
72332 +#endif
72333 +
72334 __set_current_state(TASK_RUNNING);
72335
72336 count_vm_event(PGFAULT);
72337 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72338 if (unlikely(is_vm_hugetlb_page(vma)))
72339 return hugetlb_fault(mm, vma, address, flags);
72340
72341 +#ifdef CONFIG_PAX_SEGMEXEC
72342 + vma_m = pax_find_mirror_vma(vma);
72343 + if (vma_m) {
72344 + unsigned long address_m;
72345 + pgd_t *pgd_m;
72346 + pud_t *pud_m;
72347 + pmd_t *pmd_m;
72348 +
72349 + if (vma->vm_start > vma_m->vm_start) {
72350 + address_m = address;
72351 + address -= SEGMEXEC_TASK_SIZE;
72352 + vma = vma_m;
72353 + } else
72354 + address_m = address + SEGMEXEC_TASK_SIZE;
72355 +
72356 + pgd_m = pgd_offset(mm, address_m);
72357 + pud_m = pud_alloc(mm, pgd_m, address_m);
72358 + if (!pud_m)
72359 + return VM_FAULT_OOM;
72360 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72361 + if (!pmd_m)
72362 + return VM_FAULT_OOM;
72363 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72364 + return VM_FAULT_OOM;
72365 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72366 + }
72367 +#endif
72368 +
72369 retry:
72370 pgd = pgd_offset(mm, address);
72371 pud = pud_alloc(mm, pgd, address);
72372 @@ -3547,7 +3788,7 @@ retry:
72373 * run pte_offset_map on the pmd, if an huge pmd could
72374 * materialize from under us from a different thread.
72375 */
72376 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72377 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72378 return VM_FAULT_OOM;
72379 /* if an huge pmd materialized from under us just retry later */
72380 if (unlikely(pmd_trans_huge(*pmd)))
72381 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72382 spin_unlock(&mm->page_table_lock);
72383 return 0;
72384 }
72385 +
72386 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72387 +{
72388 + pud_t *new = pud_alloc_one(mm, address);
72389 + if (!new)
72390 + return -ENOMEM;
72391 +
72392 + smp_wmb(); /* See comment in __pte_alloc */
72393 +
72394 + spin_lock(&mm->page_table_lock);
72395 + if (pgd_present(*pgd)) /* Another has populated it */
72396 + pud_free(mm, new);
72397 + else
72398 + pgd_populate_kernel(mm, pgd, new);
72399 + spin_unlock(&mm->page_table_lock);
72400 + return 0;
72401 +}
72402 #endif /* __PAGETABLE_PUD_FOLDED */
72403
72404 #ifndef __PAGETABLE_PMD_FOLDED
72405 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72406 spin_unlock(&mm->page_table_lock);
72407 return 0;
72408 }
72409 +
72410 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72411 +{
72412 + pmd_t *new = pmd_alloc_one(mm, address);
72413 + if (!new)
72414 + return -ENOMEM;
72415 +
72416 + smp_wmb(); /* See comment in __pte_alloc */
72417 +
72418 + spin_lock(&mm->page_table_lock);
72419 +#ifndef __ARCH_HAS_4LEVEL_HACK
72420 + if (pud_present(*pud)) /* Another has populated it */
72421 + pmd_free(mm, new);
72422 + else
72423 + pud_populate_kernel(mm, pud, new);
72424 +#else
72425 + if (pgd_present(*pud)) /* Another has populated it */
72426 + pmd_free(mm, new);
72427 + else
72428 + pgd_populate_kernel(mm, pud, new);
72429 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72430 + spin_unlock(&mm->page_table_lock);
72431 + return 0;
72432 +}
72433 #endif /* __PAGETABLE_PMD_FOLDED */
72434
72435 int make_pages_present(unsigned long addr, unsigned long end)
72436 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72437 gate_vma.vm_start = FIXADDR_USER_START;
72438 gate_vma.vm_end = FIXADDR_USER_END;
72439 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72440 - gate_vma.vm_page_prot = __P101;
72441 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72442
72443 return 0;
72444 }
72445 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72446 index 3d64b36..dbab433 100644
72447 --- a/mm/mempolicy.c
72448 +++ b/mm/mempolicy.c
72449 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72450 unsigned long vmstart;
72451 unsigned long vmend;
72452
72453 +#ifdef CONFIG_PAX_SEGMEXEC
72454 + struct vm_area_struct *vma_m;
72455 +#endif
72456 +
72457 vma = find_vma(mm, start);
72458 if (!vma || vma->vm_start > start)
72459 return -EFAULT;
72460 @@ -691,9 +695,18 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72461 if (err)
72462 goto out;
72463 }
72464 +
72465 err = vma_replace_policy(vma, new_pol);
72466 if (err)
72467 goto out;
72468 +
72469 +#ifdef CONFIG_PAX_SEGMEXEC
72470 + vma_m = pax_find_mirror_vma(vma);
72471 + err = vma_replace_policy(vma_m, new_pol);
72472 + if (err)
72473 + goto out;
72474 +#endif
72475 +
72476 }
72477
72478 out:
72479 @@ -1147,6 +1160,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72480
72481 if (end < start)
72482 return -EINVAL;
72483 +
72484 +#ifdef CONFIG_PAX_SEGMEXEC
72485 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72486 + if (end > SEGMEXEC_TASK_SIZE)
72487 + return -EINVAL;
72488 + } else
72489 +#endif
72490 +
72491 + if (end > TASK_SIZE)
72492 + return -EINVAL;
72493 +
72494 if (end == start)
72495 return 0;
72496
72497 @@ -1370,8 +1394,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72498 */
72499 tcred = __task_cred(task);
72500 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72501 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72502 - !capable(CAP_SYS_NICE)) {
72503 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72504 rcu_read_unlock();
72505 err = -EPERM;
72506 goto out_put;
72507 @@ -1402,6 +1425,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72508 goto out;
72509 }
72510
72511 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72512 + if (mm != current->mm &&
72513 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72514 + mmput(mm);
72515 + err = -EPERM;
72516 + goto out;
72517 + }
72518 +#endif
72519 +
72520 err = do_migrate_pages(mm, old, new,
72521 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72522
72523 diff --git a/mm/migrate.c b/mm/migrate.c
72524 index 77ed2d7..317d528 100644
72525 --- a/mm/migrate.c
72526 +++ b/mm/migrate.c
72527 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72528 */
72529 tcred = __task_cred(task);
72530 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72531 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72532 - !capable(CAP_SYS_NICE)) {
72533 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72534 rcu_read_unlock();
72535 err = -EPERM;
72536 goto out;
72537 diff --git a/mm/mlock.c b/mm/mlock.c
72538 index ef726e8..cd7f1ec 100644
72539 --- a/mm/mlock.c
72540 +++ b/mm/mlock.c
72541 @@ -13,6 +13,7 @@
72542 #include <linux/pagemap.h>
72543 #include <linux/mempolicy.h>
72544 #include <linux/syscalls.h>
72545 +#include <linux/security.h>
72546 #include <linux/sched.h>
72547 #include <linux/export.h>
72548 #include <linux/rmap.h>
72549 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72550 {
72551 unsigned long nstart, end, tmp;
72552 struct vm_area_struct * vma, * prev;
72553 - int error;
72554 + int error = 0;
72555
72556 VM_BUG_ON(start & ~PAGE_MASK);
72557 VM_BUG_ON(len != PAGE_ALIGN(len));
72558 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72559 return -EINVAL;
72560 if (end == start)
72561 return 0;
72562 + if (end > TASK_SIZE)
72563 + return -EINVAL;
72564 +
72565 vma = find_vma(current->mm, start);
72566 if (!vma || vma->vm_start > start)
72567 return -ENOMEM;
72568 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72569 for (nstart = start ; ; ) {
72570 vm_flags_t newflags;
72571
72572 +#ifdef CONFIG_PAX_SEGMEXEC
72573 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72574 + break;
72575 +#endif
72576 +
72577 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72578
72579 newflags = vma->vm_flags | VM_LOCKED;
72580 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72581 lock_limit >>= PAGE_SHIFT;
72582
72583 /* check against resource limits */
72584 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72585 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72586 error = do_mlock(start, len, 1);
72587 up_write(&current->mm->mmap_sem);
72588 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72589 static int do_mlockall(int flags)
72590 {
72591 struct vm_area_struct * vma, * prev = NULL;
72592 - unsigned int def_flags = 0;
72593
72594 if (flags & MCL_FUTURE)
72595 - def_flags = VM_LOCKED;
72596 - current->mm->def_flags = def_flags;
72597 + current->mm->def_flags |= VM_LOCKED;
72598 + else
72599 + current->mm->def_flags &= ~VM_LOCKED;
72600 if (flags == MCL_FUTURE)
72601 goto out;
72602
72603 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72604 vm_flags_t newflags;
72605
72606 +#ifdef CONFIG_PAX_SEGMEXEC
72607 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72608 + break;
72609 +#endif
72610 +
72611 + BUG_ON(vma->vm_end > TASK_SIZE);
72612 newflags = vma->vm_flags | VM_LOCKED;
72613 if (!(flags & MCL_CURRENT))
72614 newflags &= ~VM_LOCKED;
72615 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72616 lock_limit >>= PAGE_SHIFT;
72617
72618 ret = -ENOMEM;
72619 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72620 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72621 capable(CAP_IPC_LOCK))
72622 ret = do_mlockall(flags);
72623 diff --git a/mm/mmap.c b/mm/mmap.c
72624 index ae18a48..86cf99e 100644
72625 --- a/mm/mmap.c
72626 +++ b/mm/mmap.c
72627 @@ -47,6 +47,16 @@
72628 #define arch_rebalance_pgtables(addr, len) (addr)
72629 #endif
72630
72631 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72632 +{
72633 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72634 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72635 + up_read(&mm->mmap_sem);
72636 + BUG();
72637 + }
72638 +#endif
72639 +}
72640 +
72641 static void unmap_region(struct mm_struct *mm,
72642 struct vm_area_struct *vma, struct vm_area_struct *prev,
72643 unsigned long start, unsigned long end);
72644 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72645 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72646 *
72647 */
72648 -pgprot_t protection_map[16] = {
72649 +pgprot_t protection_map[16] __read_only = {
72650 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72651 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72652 };
72653
72654 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72655 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72656 {
72657 - return __pgprot(pgprot_val(protection_map[vm_flags &
72658 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72659 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72660 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72661 +
72662 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72663 + if (!(__supported_pte_mask & _PAGE_NX) &&
72664 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72665 + (vm_flags & (VM_READ | VM_WRITE)))
72666 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72667 +#endif
72668 +
72669 + return prot;
72670 }
72671 EXPORT_SYMBOL(vm_get_page_prot);
72672
72673 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72674 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72675 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72676 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72677 /*
72678 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72679 * other variables. It can be updated by several CPUs frequently.
72680 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72681 struct vm_area_struct *next = vma->vm_next;
72682
72683 might_sleep();
72684 + BUG_ON(vma->vm_mirror);
72685 if (vma->vm_ops && vma->vm_ops->close)
72686 vma->vm_ops->close(vma);
72687 if (vma->vm_file) {
72688 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72689 * not page aligned -Ram Gupta
72690 */
72691 rlim = rlimit(RLIMIT_DATA);
72692 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72693 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72694 (mm->end_data - mm->start_data) > rlim)
72695 goto out;
72696 @@ -708,6 +730,12 @@ static int
72697 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72698 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72699 {
72700 +
72701 +#ifdef CONFIG_PAX_SEGMEXEC
72702 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72703 + return 0;
72704 +#endif
72705 +
72706 if (is_mergeable_vma(vma, file, vm_flags) &&
72707 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72708 if (vma->vm_pgoff == vm_pgoff)
72709 @@ -727,6 +755,12 @@ static int
72710 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72711 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72712 {
72713 +
72714 +#ifdef CONFIG_PAX_SEGMEXEC
72715 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72716 + return 0;
72717 +#endif
72718 +
72719 if (is_mergeable_vma(vma, file, vm_flags) &&
72720 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72721 pgoff_t vm_pglen;
72722 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72723 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72724 struct vm_area_struct *prev, unsigned long addr,
72725 unsigned long end, unsigned long vm_flags,
72726 - struct anon_vma *anon_vma, struct file *file,
72727 + struct anon_vma *anon_vma, struct file *file,
72728 pgoff_t pgoff, struct mempolicy *policy)
72729 {
72730 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72731 struct vm_area_struct *area, *next;
72732 int err;
72733
72734 +#ifdef CONFIG_PAX_SEGMEXEC
72735 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72736 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72737 +
72738 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72739 +#endif
72740 +
72741 /*
72742 * We later require that vma->vm_flags == vm_flags,
72743 * so this tests vma->vm_flags & VM_SPECIAL, too.
72744 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72745 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72746 next = next->vm_next;
72747
72748 +#ifdef CONFIG_PAX_SEGMEXEC
72749 + if (prev)
72750 + prev_m = pax_find_mirror_vma(prev);
72751 + if (area)
72752 + area_m = pax_find_mirror_vma(area);
72753 + if (next)
72754 + next_m = pax_find_mirror_vma(next);
72755 +#endif
72756 +
72757 /*
72758 * Can it merge with the predecessor?
72759 */
72760 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72761 /* cases 1, 6 */
72762 err = vma_adjust(prev, prev->vm_start,
72763 next->vm_end, prev->vm_pgoff, NULL);
72764 - } else /* cases 2, 5, 7 */
72765 +
72766 +#ifdef CONFIG_PAX_SEGMEXEC
72767 + if (!err && prev_m)
72768 + err = vma_adjust(prev_m, prev_m->vm_start,
72769 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72770 +#endif
72771 +
72772 + } else { /* cases 2, 5, 7 */
72773 err = vma_adjust(prev, prev->vm_start,
72774 end, prev->vm_pgoff, NULL);
72775 +
72776 +#ifdef CONFIG_PAX_SEGMEXEC
72777 + if (!err && prev_m)
72778 + err = vma_adjust(prev_m, prev_m->vm_start,
72779 + end_m, prev_m->vm_pgoff, NULL);
72780 +#endif
72781 +
72782 + }
72783 if (err)
72784 return NULL;
72785 khugepaged_enter_vma_merge(prev);
72786 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72787 mpol_equal(policy, vma_policy(next)) &&
72788 can_vma_merge_before(next, vm_flags,
72789 anon_vma, file, pgoff+pglen)) {
72790 - if (prev && addr < prev->vm_end) /* case 4 */
72791 + if (prev && addr < prev->vm_end) { /* case 4 */
72792 err = vma_adjust(prev, prev->vm_start,
72793 addr, prev->vm_pgoff, NULL);
72794 - else /* cases 3, 8 */
72795 +
72796 +#ifdef CONFIG_PAX_SEGMEXEC
72797 + if (!err && prev_m)
72798 + err = vma_adjust(prev_m, prev_m->vm_start,
72799 + addr_m, prev_m->vm_pgoff, NULL);
72800 +#endif
72801 +
72802 + } else { /* cases 3, 8 */
72803 err = vma_adjust(area, addr, next->vm_end,
72804 next->vm_pgoff - pglen, NULL);
72805 +
72806 +#ifdef CONFIG_PAX_SEGMEXEC
72807 + if (!err && area_m)
72808 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72809 + next_m->vm_pgoff - pglen, NULL);
72810 +#endif
72811 +
72812 + }
72813 if (err)
72814 return NULL;
72815 khugepaged_enter_vma_merge(area);
72816 @@ -940,16 +1020,13 @@ none:
72817 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72818 struct file *file, long pages)
72819 {
72820 - const unsigned long stack_flags
72821 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72822 -
72823 mm->total_vm += pages;
72824
72825 if (file) {
72826 mm->shared_vm += pages;
72827 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72828 mm->exec_vm += pages;
72829 - } else if (flags & stack_flags)
72830 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72831 mm->stack_vm += pages;
72832 if (flags & (VM_RESERVED|VM_IO))
72833 mm->reserved_vm += pages;
72834 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72835 * (the exception is when the underlying filesystem is noexec
72836 * mounted, in which case we dont add PROT_EXEC.)
72837 */
72838 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72839 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72840 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72841 prot |= PROT_EXEC;
72842
72843 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72844 /* Obtain the address to map to. we verify (or select) it and ensure
72845 * that it represents a valid section of the address space.
72846 */
72847 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72848 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72849 if (addr & ~PAGE_MASK)
72850 return addr;
72851
72852 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72853 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72854 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72855
72856 +#ifdef CONFIG_PAX_MPROTECT
72857 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72858 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72859 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72860 + gr_log_rwxmmap(file);
72861 +
72862 +#ifdef CONFIG_PAX_EMUPLT
72863 + vm_flags &= ~VM_EXEC;
72864 +#else
72865 + return -EPERM;
72866 +#endif
72867 +
72868 + }
72869 +
72870 + if (!(vm_flags & VM_EXEC))
72871 + vm_flags &= ~VM_MAYEXEC;
72872 +#else
72873 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72874 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72875 +#endif
72876 + else
72877 + vm_flags &= ~VM_MAYWRITE;
72878 + }
72879 +#endif
72880 +
72881 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72882 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72883 + vm_flags &= ~VM_PAGEEXEC;
72884 +#endif
72885 +
72886 if (flags & MAP_LOCKED)
72887 if (!can_do_mlock())
72888 return -EPERM;
72889 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72890 locked += mm->locked_vm;
72891 lock_limit = rlimit(RLIMIT_MEMLOCK);
72892 lock_limit >>= PAGE_SHIFT;
72893 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72894 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72895 return -EAGAIN;
72896 }
72897 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72898 }
72899 }
72900
72901 + if (!gr_acl_handle_mmap(file, prot))
72902 + return -EACCES;
72903 +
72904 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72905 }
72906
72907 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72908 vm_flags_t vm_flags = vma->vm_flags;
72909
72910 /* If it was private or non-writable, the write bit is already clear */
72911 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72912 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72913 return 0;
72914
72915 /* The backer wishes to know when pages are first written to? */
72916 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72917 unsigned long charged = 0;
72918 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72919
72920 +#ifdef CONFIG_PAX_SEGMEXEC
72921 + struct vm_area_struct *vma_m = NULL;
72922 +#endif
72923 +
72924 + /*
72925 + * mm->mmap_sem is required to protect against another thread
72926 + * changing the mappings in case we sleep.
72927 + */
72928 + verify_mm_writelocked(mm);
72929 +
72930 /* Clear old maps */
72931 error = -ENOMEM;
72932 -munmap_back:
72933 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72934 if (vma && vma->vm_start < addr + len) {
72935 if (do_munmap(mm, addr, len))
72936 return -ENOMEM;
72937 - goto munmap_back;
72938 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72939 + BUG_ON(vma && vma->vm_start < addr + len);
72940 }
72941
72942 /* Check against address space limit. */
72943 @@ -1282,6 +1403,16 @@ munmap_back:
72944 goto unacct_error;
72945 }
72946
72947 +#ifdef CONFIG_PAX_SEGMEXEC
72948 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72949 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72950 + if (!vma_m) {
72951 + error = -ENOMEM;
72952 + goto free_vma;
72953 + }
72954 + }
72955 +#endif
72956 +
72957 vma->vm_mm = mm;
72958 vma->vm_start = addr;
72959 vma->vm_end = addr + len;
72960 @@ -1306,6 +1437,19 @@ munmap_back:
72961 error = file->f_op->mmap(file, vma);
72962 if (error)
72963 goto unmap_and_free_vma;
72964 +
72965 +#ifdef CONFIG_PAX_SEGMEXEC
72966 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72967 + added_exe_file_vma(mm);
72968 +#endif
72969 +
72970 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72971 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72972 + vma->vm_flags |= VM_PAGEEXEC;
72973 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72974 + }
72975 +#endif
72976 +
72977 if (vm_flags & VM_EXECUTABLE)
72978 added_exe_file_vma(mm);
72979
72980 @@ -1343,6 +1487,11 @@ munmap_back:
72981 vma_link(mm, vma, prev, rb_link, rb_parent);
72982 file = vma->vm_file;
72983
72984 +#ifdef CONFIG_PAX_SEGMEXEC
72985 + if (vma_m)
72986 + BUG_ON(pax_mirror_vma(vma_m, vma));
72987 +#endif
72988 +
72989 /* Once vma denies write, undo our temporary denial count */
72990 if (correct_wcount)
72991 atomic_inc(&inode->i_writecount);
72992 @@ -1350,6 +1499,7 @@ out:
72993 perf_event_mmap(vma);
72994
72995 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72996 + track_exec_limit(mm, addr, addr + len, vm_flags);
72997 if (vm_flags & VM_LOCKED) {
72998 if (!mlock_vma_pages_range(vma, addr, addr + len))
72999 mm->locked_vm += (len >> PAGE_SHIFT);
73000 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73001 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73002 charged = 0;
73003 free_vma:
73004 +
73005 +#ifdef CONFIG_PAX_SEGMEXEC
73006 + if (vma_m)
73007 + kmem_cache_free(vm_area_cachep, vma_m);
73008 +#endif
73009 +
73010 kmem_cache_free(vm_area_cachep, vma);
73011 unacct_error:
73012 if (charged)
73013 @@ -1378,6 +1534,44 @@ unacct_error:
73014 return error;
73015 }
73016
73017 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73018 +{
73019 + if (!vma) {
73020 +#ifdef CONFIG_STACK_GROWSUP
73021 + if (addr > sysctl_heap_stack_gap)
73022 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73023 + else
73024 + vma = find_vma(current->mm, 0);
73025 + if (vma && (vma->vm_flags & VM_GROWSUP))
73026 + return false;
73027 +#endif
73028 + return true;
73029 + }
73030 +
73031 + if (addr + len > vma->vm_start)
73032 + return false;
73033 +
73034 + if (vma->vm_flags & VM_GROWSDOWN)
73035 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73036 +#ifdef CONFIG_STACK_GROWSUP
73037 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73038 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73039 +#endif
73040 +
73041 + return true;
73042 +}
73043 +
73044 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73045 +{
73046 + if (vma->vm_start < len)
73047 + return -ENOMEM;
73048 + if (!(vma->vm_flags & VM_GROWSDOWN))
73049 + return vma->vm_start - len;
73050 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73051 + return vma->vm_start - len - sysctl_heap_stack_gap;
73052 + return -ENOMEM;
73053 +}
73054 +
73055 /* Get an address range which is currently unmapped.
73056 * For shmat() with addr=0.
73057 *
73058 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73059 if (flags & MAP_FIXED)
73060 return addr;
73061
73062 +#ifdef CONFIG_PAX_RANDMMAP
73063 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73064 +#endif
73065 +
73066 if (addr) {
73067 addr = PAGE_ALIGN(addr);
73068 - vma = find_vma(mm, addr);
73069 - if (TASK_SIZE - len >= addr &&
73070 - (!vma || addr + len <= vma->vm_start))
73071 - return addr;
73072 + if (TASK_SIZE - len >= addr) {
73073 + vma = find_vma(mm, addr);
73074 + if (check_heap_stack_gap(vma, addr, len))
73075 + return addr;
73076 + }
73077 }
73078 if (len > mm->cached_hole_size) {
73079 - start_addr = addr = mm->free_area_cache;
73080 + start_addr = addr = mm->free_area_cache;
73081 } else {
73082 - start_addr = addr = TASK_UNMAPPED_BASE;
73083 - mm->cached_hole_size = 0;
73084 + start_addr = addr = mm->mmap_base;
73085 + mm->cached_hole_size = 0;
73086 }
73087
73088 full_search:
73089 @@ -1426,34 +1625,40 @@ full_search:
73090 * Start a new search - just in case we missed
73091 * some holes.
73092 */
73093 - if (start_addr != TASK_UNMAPPED_BASE) {
73094 - addr = TASK_UNMAPPED_BASE;
73095 - start_addr = addr;
73096 + if (start_addr != mm->mmap_base) {
73097 + start_addr = addr = mm->mmap_base;
73098 mm->cached_hole_size = 0;
73099 goto full_search;
73100 }
73101 return -ENOMEM;
73102 }
73103 - if (!vma || addr + len <= vma->vm_start) {
73104 - /*
73105 - * Remember the place where we stopped the search:
73106 - */
73107 - mm->free_area_cache = addr + len;
73108 - return addr;
73109 - }
73110 + if (check_heap_stack_gap(vma, addr, len))
73111 + break;
73112 if (addr + mm->cached_hole_size < vma->vm_start)
73113 mm->cached_hole_size = vma->vm_start - addr;
73114 addr = vma->vm_end;
73115 }
73116 +
73117 + /*
73118 + * Remember the place where we stopped the search:
73119 + */
73120 + mm->free_area_cache = addr + len;
73121 + return addr;
73122 }
73123 #endif
73124
73125 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73126 {
73127 +
73128 +#ifdef CONFIG_PAX_SEGMEXEC
73129 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73130 + return;
73131 +#endif
73132 +
73133 /*
73134 * Is this a new hole at the lowest possible address?
73135 */
73136 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73137 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73138 mm->free_area_cache = addr;
73139 }
73140
73141 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73142 {
73143 struct vm_area_struct *vma;
73144 struct mm_struct *mm = current->mm;
73145 - unsigned long addr = addr0, start_addr;
73146 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73147
73148 /* requested length too big for entire address space */
73149 if (len > TASK_SIZE)
73150 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73151 if (flags & MAP_FIXED)
73152 return addr;
73153
73154 +#ifdef CONFIG_PAX_RANDMMAP
73155 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73156 +#endif
73157 +
73158 /* requesting a specific address */
73159 if (addr) {
73160 addr = PAGE_ALIGN(addr);
73161 - vma = find_vma(mm, addr);
73162 - if (TASK_SIZE - len >= addr &&
73163 - (!vma || addr + len <= vma->vm_start))
73164 - return addr;
73165 + if (TASK_SIZE - len >= addr) {
73166 + vma = find_vma(mm, addr);
73167 + if (check_heap_stack_gap(vma, addr, len))
73168 + return addr;
73169 + }
73170 }
73171
73172 /* check if free_area_cache is useful for us */
73173 @@ -1508,7 +1718,7 @@ try_again:
73174 * return with success:
73175 */
73176 vma = find_vma(mm, addr);
73177 - if (!vma || addr+len <= vma->vm_start)
73178 + if (check_heap_stack_gap(vma, addr, len))
73179 /* remember the address as a hint for next time */
73180 return (mm->free_area_cache = addr);
73181
73182 @@ -1517,8 +1727,8 @@ try_again:
73183 mm->cached_hole_size = vma->vm_start - addr;
73184
73185 /* try just below the current vma->vm_start */
73186 - addr = vma->vm_start-len;
73187 - } while (len < vma->vm_start);
73188 + addr = skip_heap_stack_gap(vma, len);
73189 + } while (!IS_ERR_VALUE(addr));
73190
73191 fail:
73192 /*
73193 @@ -1541,13 +1751,21 @@ fail:
73194 * can happen with large stack limits and large mmap()
73195 * allocations.
73196 */
73197 + mm->mmap_base = TASK_UNMAPPED_BASE;
73198 +
73199 +#ifdef CONFIG_PAX_RANDMMAP
73200 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73201 + mm->mmap_base += mm->delta_mmap;
73202 +#endif
73203 +
73204 + mm->free_area_cache = mm->mmap_base;
73205 mm->cached_hole_size = ~0UL;
73206 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73207 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73208 /*
73209 * Restore the topdown base:
73210 */
73211 - mm->free_area_cache = mm->mmap_base;
73212 + mm->mmap_base = base;
73213 + mm->free_area_cache = base;
73214 mm->cached_hole_size = ~0UL;
73215
73216 return addr;
73217 @@ -1556,6 +1774,12 @@ fail:
73218
73219 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73220 {
73221 +
73222 +#ifdef CONFIG_PAX_SEGMEXEC
73223 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73224 + return;
73225 +#endif
73226 +
73227 /*
73228 * Is this a new hole at the highest possible address?
73229 */
73230 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73231 mm->free_area_cache = addr;
73232
73233 /* dont allow allocations above current base */
73234 - if (mm->free_area_cache > mm->mmap_base)
73235 + if (mm->free_area_cache > mm->mmap_base) {
73236 mm->free_area_cache = mm->mmap_base;
73237 + mm->cached_hole_size = ~0UL;
73238 + }
73239 }
73240
73241 unsigned long
73242 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73243 return vma;
73244 }
73245
73246 +#ifdef CONFIG_PAX_SEGMEXEC
73247 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73248 +{
73249 + struct vm_area_struct *vma_m;
73250 +
73251 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73252 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73253 + BUG_ON(vma->vm_mirror);
73254 + return NULL;
73255 + }
73256 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73257 + vma_m = vma->vm_mirror;
73258 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73259 + BUG_ON(vma->vm_file != vma_m->vm_file);
73260 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73261 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73262 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73263 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73264 + return vma_m;
73265 +}
73266 +#endif
73267 +
73268 /*
73269 * Verify that the stack growth is acceptable and
73270 * update accounting. This is shared with both the
73271 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73272 return -ENOMEM;
73273
73274 /* Stack limit test */
73275 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73276 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73277 return -ENOMEM;
73278
73279 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73280 locked = mm->locked_vm + grow;
73281 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73282 limit >>= PAGE_SHIFT;
73283 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73284 if (locked > limit && !capable(CAP_IPC_LOCK))
73285 return -ENOMEM;
73286 }
73287 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73288 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73289 * vma is the last one with address > vma->vm_end. Have to extend vma.
73290 */
73291 +#ifndef CONFIG_IA64
73292 +static
73293 +#endif
73294 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73295 {
73296 int error;
73297 + bool locknext;
73298
73299 if (!(vma->vm_flags & VM_GROWSUP))
73300 return -EFAULT;
73301
73302 + /* Also guard against wrapping around to address 0. */
73303 + if (address < PAGE_ALIGN(address+1))
73304 + address = PAGE_ALIGN(address+1);
73305 + else
73306 + return -ENOMEM;
73307 +
73308 /*
73309 * We must make sure the anon_vma is allocated
73310 * so that the anon_vma locking is not a noop.
73311 */
73312 if (unlikely(anon_vma_prepare(vma)))
73313 return -ENOMEM;
73314 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73315 + if (locknext && anon_vma_prepare(vma->vm_next))
73316 + return -ENOMEM;
73317 vma_lock_anon_vma(vma);
73318 + if (locknext)
73319 + vma_lock_anon_vma(vma->vm_next);
73320
73321 /*
73322 * vma->vm_start/vm_end cannot change under us because the caller
73323 * is required to hold the mmap_sem in read mode. We need the
73324 - * anon_vma lock to serialize against concurrent expand_stacks.
73325 - * Also guard against wrapping around to address 0.
73326 + * anon_vma locks to serialize against concurrent expand_stacks
73327 + * and expand_upwards.
73328 */
73329 - if (address < PAGE_ALIGN(address+4))
73330 - address = PAGE_ALIGN(address+4);
73331 - else {
73332 - vma_unlock_anon_vma(vma);
73333 - return -ENOMEM;
73334 - }
73335 error = 0;
73336
73337 /* Somebody else might have raced and expanded it already */
73338 - if (address > vma->vm_end) {
73339 + 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)
73340 + error = -ENOMEM;
73341 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73342 unsigned long size, grow;
73343
73344 size = address - vma->vm_start;
73345 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73346 }
73347 }
73348 }
73349 + if (locknext)
73350 + vma_unlock_anon_vma(vma->vm_next);
73351 vma_unlock_anon_vma(vma);
73352 khugepaged_enter_vma_merge(vma);
73353 return error;
73354 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73355 unsigned long address)
73356 {
73357 int error;
73358 + bool lockprev = false;
73359 + struct vm_area_struct *prev;
73360
73361 /*
73362 * We must make sure the anon_vma is allocated
73363 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73364 if (error)
73365 return error;
73366
73367 + prev = vma->vm_prev;
73368 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73369 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73370 +#endif
73371 + if (lockprev && anon_vma_prepare(prev))
73372 + return -ENOMEM;
73373 + if (lockprev)
73374 + vma_lock_anon_vma(prev);
73375 +
73376 vma_lock_anon_vma(vma);
73377
73378 /*
73379 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73380 */
73381
73382 /* Somebody else might have raced and expanded it already */
73383 - if (address < vma->vm_start) {
73384 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73385 + error = -ENOMEM;
73386 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73387 unsigned long size, grow;
73388
73389 +#ifdef CONFIG_PAX_SEGMEXEC
73390 + struct vm_area_struct *vma_m;
73391 +
73392 + vma_m = pax_find_mirror_vma(vma);
73393 +#endif
73394 +
73395 size = vma->vm_end - address;
73396 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73397
73398 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73399 if (!error) {
73400 vma->vm_start = address;
73401 vma->vm_pgoff -= grow;
73402 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73403 +
73404 +#ifdef CONFIG_PAX_SEGMEXEC
73405 + if (vma_m) {
73406 + vma_m->vm_start -= grow << PAGE_SHIFT;
73407 + vma_m->vm_pgoff -= grow;
73408 + }
73409 +#endif
73410 +
73411 perf_event_mmap(vma);
73412 }
73413 }
73414 }
73415 vma_unlock_anon_vma(vma);
73416 + if (lockprev)
73417 + vma_unlock_anon_vma(prev);
73418 khugepaged_enter_vma_merge(vma);
73419 return error;
73420 }
73421 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73422 do {
73423 long nrpages = vma_pages(vma);
73424
73425 +#ifdef CONFIG_PAX_SEGMEXEC
73426 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73427 + vma = remove_vma(vma);
73428 + continue;
73429 + }
73430 +#endif
73431 +
73432 if (vma->vm_flags & VM_ACCOUNT)
73433 nr_accounted += nrpages;
73434 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73435 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73436 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73437 vma->vm_prev = NULL;
73438 do {
73439 +
73440 +#ifdef CONFIG_PAX_SEGMEXEC
73441 + if (vma->vm_mirror) {
73442 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73443 + vma->vm_mirror->vm_mirror = NULL;
73444 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73445 + vma->vm_mirror = NULL;
73446 + }
73447 +#endif
73448 +
73449 rb_erase(&vma->vm_rb, &mm->mm_rb);
73450 mm->map_count--;
73451 tail_vma = vma;
73452 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73453 struct vm_area_struct *new;
73454 int err = -ENOMEM;
73455
73456 +#ifdef CONFIG_PAX_SEGMEXEC
73457 + struct vm_area_struct *vma_m, *new_m = NULL;
73458 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73459 +#endif
73460 +
73461 if (is_vm_hugetlb_page(vma) && (addr &
73462 ~(huge_page_mask(hstate_vma(vma)))))
73463 return -EINVAL;
73464
73465 +#ifdef CONFIG_PAX_SEGMEXEC
73466 + vma_m = pax_find_mirror_vma(vma);
73467 +#endif
73468 +
73469 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73470 if (!new)
73471 goto out_err;
73472
73473 +#ifdef CONFIG_PAX_SEGMEXEC
73474 + if (vma_m) {
73475 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73476 + if (!new_m) {
73477 + kmem_cache_free(vm_area_cachep, new);
73478 + goto out_err;
73479 + }
73480 + }
73481 +#endif
73482 +
73483 /* most fields are the same, copy all, and then fixup */
73484 *new = *vma;
73485
73486 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73487 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73488 }
73489
73490 +#ifdef CONFIG_PAX_SEGMEXEC
73491 + if (vma_m) {
73492 + *new_m = *vma_m;
73493 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73494 + new_m->vm_mirror = new;
73495 + new->vm_mirror = new_m;
73496 +
73497 + if (new_below)
73498 + new_m->vm_end = addr_m;
73499 + else {
73500 + new_m->vm_start = addr_m;
73501 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73502 + }
73503 + }
73504 +#endif
73505 +
73506 pol = mpol_dup(vma_policy(vma));
73507 if (IS_ERR(pol)) {
73508 err = PTR_ERR(pol);
73509 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73510 else
73511 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73512
73513 +#ifdef CONFIG_PAX_SEGMEXEC
73514 + if (!err && vma_m) {
73515 + if (anon_vma_clone(new_m, vma_m))
73516 + goto out_free_mpol;
73517 +
73518 + mpol_get(pol);
73519 + vma_set_policy(new_m, pol);
73520 +
73521 + if (new_m->vm_file) {
73522 + get_file(new_m->vm_file);
73523 + if (vma_m->vm_flags & VM_EXECUTABLE)
73524 + added_exe_file_vma(mm);
73525 + }
73526 +
73527 + if (new_m->vm_ops && new_m->vm_ops->open)
73528 + new_m->vm_ops->open(new_m);
73529 +
73530 + if (new_below)
73531 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73532 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73533 + else
73534 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73535 +
73536 + if (err) {
73537 + if (new_m->vm_ops && new_m->vm_ops->close)
73538 + new_m->vm_ops->close(new_m);
73539 + if (new_m->vm_file) {
73540 + if (vma_m->vm_flags & VM_EXECUTABLE)
73541 + removed_exe_file_vma(mm);
73542 + fput(new_m->vm_file);
73543 + }
73544 + mpol_put(pol);
73545 + }
73546 + }
73547 +#endif
73548 +
73549 /* Success. */
73550 if (!err)
73551 return 0;
73552 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73553 removed_exe_file_vma(mm);
73554 fput(new->vm_file);
73555 }
73556 - unlink_anon_vmas(new);
73557 out_free_mpol:
73558 mpol_put(pol);
73559 out_free_vma:
73560 +
73561 +#ifdef CONFIG_PAX_SEGMEXEC
73562 + if (new_m) {
73563 + unlink_anon_vmas(new_m);
73564 + kmem_cache_free(vm_area_cachep, new_m);
73565 + }
73566 +#endif
73567 +
73568 + unlink_anon_vmas(new);
73569 kmem_cache_free(vm_area_cachep, new);
73570 out_err:
73571 return err;
73572 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73573 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73574 unsigned long addr, int new_below)
73575 {
73576 +
73577 +#ifdef CONFIG_PAX_SEGMEXEC
73578 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73579 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73580 + if (mm->map_count >= sysctl_max_map_count-1)
73581 + return -ENOMEM;
73582 + } else
73583 +#endif
73584 +
73585 if (mm->map_count >= sysctl_max_map_count)
73586 return -ENOMEM;
73587
73588 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73589 * work. This now handles partial unmappings.
73590 * Jeremy Fitzhardinge <jeremy@goop.org>
73591 */
73592 +#ifdef CONFIG_PAX_SEGMEXEC
73593 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73594 {
73595 + int ret = __do_munmap(mm, start, len);
73596 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73597 + return ret;
73598 +
73599 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73600 +}
73601 +
73602 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73603 +#else
73604 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73605 +#endif
73606 +{
73607 unsigned long end;
73608 struct vm_area_struct *vma, *prev, *last;
73609
73610 + /*
73611 + * mm->mmap_sem is required to protect against another thread
73612 + * changing the mappings in case we sleep.
73613 + */
73614 + verify_mm_writelocked(mm);
73615 +
73616 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73617 return -EINVAL;
73618
73619 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73620 /* Fix up all other VM information */
73621 remove_vma_list(mm, vma);
73622
73623 + track_exec_limit(mm, start, end, 0UL);
73624 +
73625 return 0;
73626 }
73627
73628 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73629 int ret;
73630 struct mm_struct *mm = current->mm;
73631
73632 +
73633 +#ifdef CONFIG_PAX_SEGMEXEC
73634 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73635 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73636 + return -EINVAL;
73637 +#endif
73638 +
73639 down_write(&mm->mmap_sem);
73640 ret = do_munmap(mm, start, len);
73641 up_write(&mm->mmap_sem);
73642 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73643 return vm_munmap(addr, len);
73644 }
73645
73646 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73647 -{
73648 -#ifdef CONFIG_DEBUG_VM
73649 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73650 - WARN_ON(1);
73651 - up_read(&mm->mmap_sem);
73652 - }
73653 -#endif
73654 -}
73655 -
73656 /*
73657 * this is really a simplified "do_mmap". it only handles
73658 * anonymous maps. eventually we may be able to do some
73659 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73660 struct rb_node ** rb_link, * rb_parent;
73661 pgoff_t pgoff = addr >> PAGE_SHIFT;
73662 int error;
73663 + unsigned long charged;
73664
73665 len = PAGE_ALIGN(len);
73666 if (!len)
73667 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73668
73669 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73670
73671 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73672 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73673 + flags &= ~VM_EXEC;
73674 +
73675 +#ifdef CONFIG_PAX_MPROTECT
73676 + if (mm->pax_flags & MF_PAX_MPROTECT)
73677 + flags &= ~VM_MAYEXEC;
73678 +#endif
73679 +
73680 + }
73681 +#endif
73682 +
73683 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73684 if (error & ~PAGE_MASK)
73685 return error;
73686
73687 + charged = len >> PAGE_SHIFT;
73688 +
73689 /*
73690 * mlock MCL_FUTURE?
73691 */
73692 if (mm->def_flags & VM_LOCKED) {
73693 unsigned long locked, lock_limit;
73694 - locked = len >> PAGE_SHIFT;
73695 + locked = charged;
73696 locked += mm->locked_vm;
73697 lock_limit = rlimit(RLIMIT_MEMLOCK);
73698 lock_limit >>= PAGE_SHIFT;
73699 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73700 /*
73701 * Clear old maps. this also does some error checking for us
73702 */
73703 - munmap_back:
73704 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73705 if (vma && vma->vm_start < addr + len) {
73706 if (do_munmap(mm, addr, len))
73707 return -ENOMEM;
73708 - goto munmap_back;
73709 - }
73710 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73711 + BUG_ON(vma && vma->vm_start < addr + len);
73712 + }
73713
73714 /* Check against address space limits *after* clearing old maps... */
73715 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73716 + if (!may_expand_vm(mm, charged))
73717 return -ENOMEM;
73718
73719 if (mm->map_count > sysctl_max_map_count)
73720 return -ENOMEM;
73721
73722 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73723 + if (security_vm_enough_memory_mm(mm, charged))
73724 return -ENOMEM;
73725
73726 /* Can we just expand an old private anonymous mapping? */
73727 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73728 */
73729 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73730 if (!vma) {
73731 - vm_unacct_memory(len >> PAGE_SHIFT);
73732 + vm_unacct_memory(charged);
73733 return -ENOMEM;
73734 }
73735
73736 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73737 vma_link(mm, vma, prev, rb_link, rb_parent);
73738 out:
73739 perf_event_mmap(vma);
73740 - mm->total_vm += len >> PAGE_SHIFT;
73741 + mm->total_vm += charged;
73742 if (flags & VM_LOCKED) {
73743 if (!mlock_vma_pages_range(vma, addr, addr + len))
73744 - mm->locked_vm += (len >> PAGE_SHIFT);
73745 + mm->locked_vm += charged;
73746 }
73747 + track_exec_limit(mm, addr, addr + len, flags);
73748 return addr;
73749 }
73750
73751 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73752 while (vma) {
73753 if (vma->vm_flags & VM_ACCOUNT)
73754 nr_accounted += vma_pages(vma);
73755 + vma->vm_mirror = NULL;
73756 vma = remove_vma(vma);
73757 }
73758 vm_unacct_memory(nr_accounted);
73759 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73760 struct vm_area_struct * __vma, * prev;
73761 struct rb_node ** rb_link, * rb_parent;
73762
73763 +#ifdef CONFIG_PAX_SEGMEXEC
73764 + struct vm_area_struct *vma_m = NULL;
73765 +#endif
73766 +
73767 + if (security_mmap_addr(vma->vm_start))
73768 + return -EPERM;
73769 +
73770 /*
73771 * The vm_pgoff of a purely anonymous vma should be irrelevant
73772 * until its first write fault, when page's anon_vma and index
73773 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73774 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73775 return -ENOMEM;
73776
73777 +#ifdef CONFIG_PAX_SEGMEXEC
73778 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73779 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73780 + if (!vma_m)
73781 + return -ENOMEM;
73782 + }
73783 +#endif
73784 +
73785 vma_link(mm, vma, prev, rb_link, rb_parent);
73786 +
73787 +#ifdef CONFIG_PAX_SEGMEXEC
73788 + if (vma_m)
73789 + BUG_ON(pax_mirror_vma(vma_m, vma));
73790 +#endif
73791 +
73792 return 0;
73793 }
73794
73795 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73796 struct mempolicy *pol;
73797 bool faulted_in_anon_vma = true;
73798
73799 + BUG_ON(vma->vm_mirror);
73800 +
73801 /*
73802 * If anonymous vma has not yet been faulted, update new pgoff
73803 * to match new location, to increase its chance of merging.
73804 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73805 return NULL;
73806 }
73807
73808 +#ifdef CONFIG_PAX_SEGMEXEC
73809 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73810 +{
73811 + struct vm_area_struct *prev_m;
73812 + struct rb_node **rb_link_m, *rb_parent_m;
73813 + struct mempolicy *pol_m;
73814 +
73815 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73816 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73817 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73818 + *vma_m = *vma;
73819 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73820 + if (anon_vma_clone(vma_m, vma))
73821 + return -ENOMEM;
73822 + pol_m = vma_policy(vma_m);
73823 + mpol_get(pol_m);
73824 + vma_set_policy(vma_m, pol_m);
73825 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73826 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73827 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73828 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73829 + if (vma_m->vm_file)
73830 + get_file(vma_m->vm_file);
73831 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73832 + vma_m->vm_ops->open(vma_m);
73833 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73834 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73835 + vma_m->vm_mirror = vma;
73836 + vma->vm_mirror = vma_m;
73837 + return 0;
73838 +}
73839 +#endif
73840 +
73841 /*
73842 * Return true if the calling process may expand its vm space by the passed
73843 * number of pages
73844 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73845
73846 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73847
73848 +#ifdef CONFIG_PAX_RANDMMAP
73849 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73850 + cur -= mm->brk_gap;
73851 +#endif
73852 +
73853 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73854 if (cur + npages > lim)
73855 return 0;
73856 return 1;
73857 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
73858 vma->vm_start = addr;
73859 vma->vm_end = addr + len;
73860
73861 +#ifdef CONFIG_PAX_MPROTECT
73862 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73863 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73864 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73865 + return -EPERM;
73866 + if (!(vm_flags & VM_EXEC))
73867 + vm_flags &= ~VM_MAYEXEC;
73868 +#else
73869 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73870 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73871 +#endif
73872 + else
73873 + vm_flags &= ~VM_MAYWRITE;
73874 + }
73875 +#endif
73876 +
73877 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73878 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73879
73880 diff --git a/mm/mprotect.c b/mm/mprotect.c
73881 index a409926..8b32e6d 100644
73882 --- a/mm/mprotect.c
73883 +++ b/mm/mprotect.c
73884 @@ -23,10 +23,17 @@
73885 #include <linux/mmu_notifier.h>
73886 #include <linux/migrate.h>
73887 #include <linux/perf_event.h>
73888 +
73889 +#ifdef CONFIG_PAX_MPROTECT
73890 +#include <linux/elf.h>
73891 +#include <linux/binfmts.h>
73892 +#endif
73893 +
73894 #include <asm/uaccess.h>
73895 #include <asm/pgtable.h>
73896 #include <asm/cacheflush.h>
73897 #include <asm/tlbflush.h>
73898 +#include <asm/mmu_context.h>
73899
73900 #ifndef pgprot_modify
73901 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73902 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73903 flush_tlb_range(vma, start, end);
73904 }
73905
73906 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73907 +/* called while holding the mmap semaphor for writing except stack expansion */
73908 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73909 +{
73910 + unsigned long oldlimit, newlimit = 0UL;
73911 +
73912 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73913 + return;
73914 +
73915 + spin_lock(&mm->page_table_lock);
73916 + oldlimit = mm->context.user_cs_limit;
73917 + if ((prot & VM_EXEC) && oldlimit < end)
73918 + /* USER_CS limit moved up */
73919 + newlimit = end;
73920 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73921 + /* USER_CS limit moved down */
73922 + newlimit = start;
73923 +
73924 + if (newlimit) {
73925 + mm->context.user_cs_limit = newlimit;
73926 +
73927 +#ifdef CONFIG_SMP
73928 + wmb();
73929 + cpus_clear(mm->context.cpu_user_cs_mask);
73930 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73931 +#endif
73932 +
73933 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73934 + }
73935 + spin_unlock(&mm->page_table_lock);
73936 + if (newlimit == end) {
73937 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73938 +
73939 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73940 + if (is_vm_hugetlb_page(vma))
73941 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73942 + else
73943 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73944 + }
73945 +}
73946 +#endif
73947 +
73948 int
73949 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73950 unsigned long start, unsigned long end, unsigned long newflags)
73951 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73952 int error;
73953 int dirty_accountable = 0;
73954
73955 +#ifdef CONFIG_PAX_SEGMEXEC
73956 + struct vm_area_struct *vma_m = NULL;
73957 + unsigned long start_m, end_m;
73958 +
73959 + start_m = start + SEGMEXEC_TASK_SIZE;
73960 + end_m = end + SEGMEXEC_TASK_SIZE;
73961 +#endif
73962 +
73963 if (newflags == oldflags) {
73964 *pprev = vma;
73965 return 0;
73966 }
73967
73968 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73969 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73970 +
73971 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73972 + return -ENOMEM;
73973 +
73974 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73975 + return -ENOMEM;
73976 + }
73977 +
73978 /*
73979 * If we make a private mapping writable we increase our commit;
73980 * but (without finer accounting) cannot reduce our commit if we
73981 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73982 }
73983 }
73984
73985 +#ifdef CONFIG_PAX_SEGMEXEC
73986 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73987 + if (start != vma->vm_start) {
73988 + error = split_vma(mm, vma, start, 1);
73989 + if (error)
73990 + goto fail;
73991 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73992 + *pprev = (*pprev)->vm_next;
73993 + }
73994 +
73995 + if (end != vma->vm_end) {
73996 + error = split_vma(mm, vma, end, 0);
73997 + if (error)
73998 + goto fail;
73999 + }
74000 +
74001 + if (pax_find_mirror_vma(vma)) {
74002 + error = __do_munmap(mm, start_m, end_m - start_m);
74003 + if (error)
74004 + goto fail;
74005 + } else {
74006 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74007 + if (!vma_m) {
74008 + error = -ENOMEM;
74009 + goto fail;
74010 + }
74011 + vma->vm_flags = newflags;
74012 + error = pax_mirror_vma(vma_m, vma);
74013 + if (error) {
74014 + vma->vm_flags = oldflags;
74015 + goto fail;
74016 + }
74017 + }
74018 + }
74019 +#endif
74020 +
74021 /*
74022 * First try to merge with previous and/or next vma.
74023 */
74024 @@ -204,9 +307,21 @@ success:
74025 * vm_flags and vm_page_prot are protected by the mmap_sem
74026 * held in write mode.
74027 */
74028 +
74029 +#ifdef CONFIG_PAX_SEGMEXEC
74030 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74031 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74032 +#endif
74033 +
74034 vma->vm_flags = newflags;
74035 +
74036 +#ifdef CONFIG_PAX_MPROTECT
74037 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74038 + mm->binfmt->handle_mprotect(vma, newflags);
74039 +#endif
74040 +
74041 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74042 - vm_get_page_prot(newflags));
74043 + vm_get_page_prot(vma->vm_flags));
74044
74045 if (vma_wants_writenotify(vma)) {
74046 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74047 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74048 end = start + len;
74049 if (end <= start)
74050 return -ENOMEM;
74051 +
74052 +#ifdef CONFIG_PAX_SEGMEXEC
74053 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74054 + if (end > SEGMEXEC_TASK_SIZE)
74055 + return -EINVAL;
74056 + } else
74057 +#endif
74058 +
74059 + if (end > TASK_SIZE)
74060 + return -EINVAL;
74061 +
74062 if (!arch_validate_prot(prot))
74063 return -EINVAL;
74064
74065 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74066 /*
74067 * Does the application expect PROT_READ to imply PROT_EXEC:
74068 */
74069 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74070 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74071 prot |= PROT_EXEC;
74072
74073 vm_flags = calc_vm_prot_bits(prot);
74074 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74075 if (start > vma->vm_start)
74076 prev = vma;
74077
74078 +#ifdef CONFIG_PAX_MPROTECT
74079 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74080 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74081 +#endif
74082 +
74083 for (nstart = start ; ; ) {
74084 unsigned long newflags;
74085
74086 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74087
74088 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74089 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74090 + if (prot & (PROT_WRITE | PROT_EXEC))
74091 + gr_log_rwxmprotect(vma->vm_file);
74092 +
74093 + error = -EACCES;
74094 + goto out;
74095 + }
74096 +
74097 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74098 error = -EACCES;
74099 goto out;
74100 }
74101 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74102 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74103 if (error)
74104 goto out;
74105 +
74106 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74107 +
74108 nstart = tmp;
74109
74110 if (nstart < prev->vm_end)
74111 diff --git a/mm/mremap.c b/mm/mremap.c
74112 index cc06d0e..40b5d18 100644
74113 --- a/mm/mremap.c
74114 +++ b/mm/mremap.c
74115 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74116 continue;
74117 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74118 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74119 +
74120 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74121 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74122 + pte = pte_exprotect(pte);
74123 +#endif
74124 +
74125 set_pte_at(mm, new_addr, new_pte, pte);
74126 }
74127
74128 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74129 if (is_vm_hugetlb_page(vma))
74130 goto Einval;
74131
74132 +#ifdef CONFIG_PAX_SEGMEXEC
74133 + if (pax_find_mirror_vma(vma))
74134 + goto Einval;
74135 +#endif
74136 +
74137 /* We can't remap across vm area boundaries */
74138 if (old_len > vma->vm_end - addr)
74139 goto Efault;
74140 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74141 unsigned long ret = -EINVAL;
74142 unsigned long charged = 0;
74143 unsigned long map_flags;
74144 + unsigned long pax_task_size = TASK_SIZE;
74145
74146 if (new_addr & ~PAGE_MASK)
74147 goto out;
74148
74149 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74150 +#ifdef CONFIG_PAX_SEGMEXEC
74151 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74152 + pax_task_size = SEGMEXEC_TASK_SIZE;
74153 +#endif
74154 +
74155 + pax_task_size -= PAGE_SIZE;
74156 +
74157 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74158 goto out;
74159
74160 /* Check if the location we're moving into overlaps the
74161 * old location at all, and fail if it does.
74162 */
74163 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74164 - goto out;
74165 -
74166 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74167 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74168 goto out;
74169
74170 ret = do_munmap(mm, new_addr, new_len);
74171 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74172 struct vm_area_struct *vma;
74173 unsigned long ret = -EINVAL;
74174 unsigned long charged = 0;
74175 + unsigned long pax_task_size = TASK_SIZE;
74176
74177 down_write(&current->mm->mmap_sem);
74178
74179 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74180 if (!new_len)
74181 goto out;
74182
74183 +#ifdef CONFIG_PAX_SEGMEXEC
74184 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74185 + pax_task_size = SEGMEXEC_TASK_SIZE;
74186 +#endif
74187 +
74188 + pax_task_size -= PAGE_SIZE;
74189 +
74190 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74191 + old_len > pax_task_size || addr > pax_task_size-old_len)
74192 + goto out;
74193 +
74194 if (flags & MREMAP_FIXED) {
74195 if (flags & MREMAP_MAYMOVE)
74196 ret = mremap_to(addr, old_len, new_addr, new_len);
74197 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74198 addr + new_len);
74199 }
74200 ret = addr;
74201 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74202 goto out;
74203 }
74204 }
74205 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74206 goto out;
74207 }
74208
74209 + map_flags = vma->vm_flags;
74210 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74211 + if (!(ret & ~PAGE_MASK)) {
74212 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74213 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74214 + }
74215 }
74216 out:
74217 if (ret & ~PAGE_MASK)
74218 diff --git a/mm/nommu.c b/mm/nommu.c
74219 index d4b0c10..ed421b5 100644
74220 --- a/mm/nommu.c
74221 +++ b/mm/nommu.c
74222 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74223 int sysctl_overcommit_ratio = 50; /* default is 50% */
74224 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74225 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74226 -int heap_stack_gap = 0;
74227
74228 atomic_long_t mmap_pages_allocated;
74229
74230 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74231 EXPORT_SYMBOL(find_vma);
74232
74233 /*
74234 - * find a VMA
74235 - * - we don't extend stack VMAs under NOMMU conditions
74236 - */
74237 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74238 -{
74239 - return find_vma(mm, addr);
74240 -}
74241 -
74242 -/*
74243 * expand a stack to a given address
74244 * - not supported under NOMMU conditions
74245 */
74246 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74247
74248 /* most fields are the same, copy all, and then fixup */
74249 *new = *vma;
74250 + INIT_LIST_HEAD(&new->anon_vma_chain);
74251 *region = *vma->vm_region;
74252 new->vm_region = region;
74253
74254 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74255 index c13ea75..081ab2c 100644
74256 --- a/mm/page_alloc.c
74257 +++ b/mm/page_alloc.c
74258 @@ -340,7 +340,7 @@ out:
74259 * This usage means that zero-order pages may not be compound.
74260 */
74261
74262 -static void free_compound_page(struct page *page)
74263 +void free_compound_page(struct page *page)
74264 {
74265 __free_pages_ok(page, compound_order(page));
74266 }
74267 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74268 int i;
74269 int bad = 0;
74270
74271 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74272 + unsigned long index = 1UL << order;
74273 +#endif
74274 +
74275 trace_mm_page_free(page, order);
74276 kmemcheck_free_shadow(page, order);
74277
74278 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74279 debug_check_no_obj_freed(page_address(page),
74280 PAGE_SIZE << order);
74281 }
74282 +
74283 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74284 + for (; index; --index)
74285 + sanitize_highpage(page + index - 1);
74286 +#endif
74287 +
74288 arch_free_page(page, order);
74289 kernel_map_pages(page, 1 << order, 0);
74290
74291 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74292 arch_alloc_page(page, order);
74293 kernel_map_pages(page, 1 << order, 1);
74294
74295 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74296 if (gfp_flags & __GFP_ZERO)
74297 prep_zero_page(page, order, gfp_flags);
74298 +#endif
74299
74300 if (order && (gfp_flags & __GFP_COMP))
74301 prep_compound_page(page, order);
74302 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74303 unsigned long pfn;
74304
74305 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74306 +#ifdef CONFIG_X86_32
74307 + /* boot failures in VMware 8 on 32bit vanilla since
74308 + this change */
74309 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74310 +#else
74311 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74312 +#endif
74313 return 1;
74314 }
74315 return 0;
74316 diff --git a/mm/percpu.c b/mm/percpu.c
74317 index bb4be74..a43ea85 100644
74318 --- a/mm/percpu.c
74319 +++ b/mm/percpu.c
74320 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74321 static unsigned int pcpu_high_unit_cpu __read_mostly;
74322
74323 /* the address of the first chunk which starts with the kernel static area */
74324 -void *pcpu_base_addr __read_mostly;
74325 +void *pcpu_base_addr __read_only;
74326 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74327
74328 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74329 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74330 index 926b466..b23df53 100644
74331 --- a/mm/process_vm_access.c
74332 +++ b/mm/process_vm_access.c
74333 @@ -13,6 +13,7 @@
74334 #include <linux/uio.h>
74335 #include <linux/sched.h>
74336 #include <linux/highmem.h>
74337 +#include <linux/security.h>
74338 #include <linux/ptrace.h>
74339 #include <linux/slab.h>
74340 #include <linux/syscalls.h>
74341 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74342 size_t iov_l_curr_offset = 0;
74343 ssize_t iov_len;
74344
74345 + return -ENOSYS; // PaX: until properly audited
74346 +
74347 /*
74348 * Work out how many pages of struct pages we're going to need
74349 * when eventually calling get_user_pages
74350 */
74351 for (i = 0; i < riovcnt; i++) {
74352 iov_len = rvec[i].iov_len;
74353 - if (iov_len > 0) {
74354 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74355 - + iov_len)
74356 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74357 - / PAGE_SIZE + 1;
74358 - nr_pages = max(nr_pages, nr_pages_iov);
74359 - }
74360 + if (iov_len <= 0)
74361 + continue;
74362 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74363 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74364 + nr_pages = max(nr_pages, nr_pages_iov);
74365 }
74366
74367 if (nr_pages == 0)
74368 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74369 goto free_proc_pages;
74370 }
74371
74372 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74373 + rc = -EPERM;
74374 + goto put_task_struct;
74375 + }
74376 +
74377 mm = mm_access(task, PTRACE_MODE_ATTACH);
74378 if (!mm || IS_ERR(mm)) {
74379 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74380 diff --git a/mm/rmap.c b/mm/rmap.c
74381 index 0f3b7cd..c5652b6 100644
74382 --- a/mm/rmap.c
74383 +++ b/mm/rmap.c
74384 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74385 struct anon_vma *anon_vma = vma->anon_vma;
74386 struct anon_vma_chain *avc;
74387
74388 +#ifdef CONFIG_PAX_SEGMEXEC
74389 + struct anon_vma_chain *avc_m = NULL;
74390 +#endif
74391 +
74392 might_sleep();
74393 if (unlikely(!anon_vma)) {
74394 struct mm_struct *mm = vma->vm_mm;
74395 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74396 if (!avc)
74397 goto out_enomem;
74398
74399 +#ifdef CONFIG_PAX_SEGMEXEC
74400 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74401 + if (!avc_m)
74402 + goto out_enomem_free_avc;
74403 +#endif
74404 +
74405 anon_vma = find_mergeable_anon_vma(vma);
74406 allocated = NULL;
74407 if (!anon_vma) {
74408 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74409 /* page_table_lock to protect against threads */
74410 spin_lock(&mm->page_table_lock);
74411 if (likely(!vma->anon_vma)) {
74412 +
74413 +#ifdef CONFIG_PAX_SEGMEXEC
74414 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74415 +
74416 + if (vma_m) {
74417 + BUG_ON(vma_m->anon_vma);
74418 + vma_m->anon_vma = anon_vma;
74419 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74420 + avc_m = NULL;
74421 + }
74422 +#endif
74423 +
74424 vma->anon_vma = anon_vma;
74425 anon_vma_chain_link(vma, avc, anon_vma);
74426 allocated = NULL;
74427 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74428
74429 if (unlikely(allocated))
74430 put_anon_vma(allocated);
74431 +
74432 +#ifdef CONFIG_PAX_SEGMEXEC
74433 + if (unlikely(avc_m))
74434 + anon_vma_chain_free(avc_m);
74435 +#endif
74436 +
74437 if (unlikely(avc))
74438 anon_vma_chain_free(avc);
74439 }
74440 return 0;
74441
74442 out_enomem_free_avc:
74443 +
74444 +#ifdef CONFIG_PAX_SEGMEXEC
74445 + if (avc_m)
74446 + anon_vma_chain_free(avc_m);
74447 +#endif
74448 +
74449 anon_vma_chain_free(avc);
74450 out_enomem:
74451 return -ENOMEM;
74452 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74453 * Attach the anon_vmas from src to dst.
74454 * Returns 0 on success, -ENOMEM on failure.
74455 */
74456 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74457 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74458 {
74459 struct anon_vma_chain *avc, *pavc;
74460 struct anon_vma *root = NULL;
74461 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74462 * the corresponding VMA in the parent process is attached to.
74463 * Returns 0 on success, non-zero on failure.
74464 */
74465 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74466 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74467 {
74468 struct anon_vma_chain *avc;
74469 struct anon_vma *anon_vma;
74470 diff --git a/mm/shmem.c b/mm/shmem.c
74471 index d2eeca1..3f160be 100644
74472 --- a/mm/shmem.c
74473 +++ b/mm/shmem.c
74474 @@ -31,7 +31,7 @@
74475 #include <linux/export.h>
74476 #include <linux/swap.h>
74477
74478 -static struct vfsmount *shm_mnt;
74479 +struct vfsmount *shm_mnt;
74480
74481 #ifdef CONFIG_SHMEM
74482 /*
74483 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74484 #define BOGO_DIRENT_SIZE 20
74485
74486 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74487 -#define SHORT_SYMLINK_LEN 128
74488 +#define SHORT_SYMLINK_LEN 64
74489
74490 struct shmem_xattr {
74491 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74492 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74493 int err = -ENOMEM;
74494
74495 /* Round up to L1_CACHE_BYTES to resist false sharing */
74496 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74497 - L1_CACHE_BYTES), GFP_KERNEL);
74498 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74499 if (!sbinfo)
74500 return -ENOMEM;
74501
74502 diff --git a/mm/slab.c b/mm/slab.c
74503 index d066037..5bb78d9 100644
74504 --- a/mm/slab.c
74505 +++ b/mm/slab.c
74506 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74507
74508 /* Legal flag mask for kmem_cache_create(). */
74509 #if DEBUG
74510 -# define CREATE_MASK (SLAB_RED_ZONE | \
74511 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74512 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74513 SLAB_CACHE_DMA | \
74514 SLAB_STORE_USER | \
74515 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74516 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74517 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74518 #else
74519 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74520 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74521 SLAB_CACHE_DMA | \
74522 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74523 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74524 @@ -322,7 +322,7 @@ struct kmem_list3 {
74525 * Need this for bootstrapping a per node allocator.
74526 */
74527 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74528 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74529 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74530 #define CACHE_CACHE 0
74531 #define SIZE_AC MAX_NUMNODES
74532 #define SIZE_L3 (2 * MAX_NUMNODES)
74533 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74534 if ((x)->max_freeable < i) \
74535 (x)->max_freeable = i; \
74536 } while (0)
74537 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74538 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74539 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74540 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74541 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74542 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74543 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74544 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74545 #else
74546 #define STATS_INC_ACTIVE(x) do { } while (0)
74547 #define STATS_DEC_ACTIVE(x) do { } while (0)
74548 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74549 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74550 */
74551 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74552 - const struct slab *slab, void *obj)
74553 + const struct slab *slab, const void *obj)
74554 {
74555 u32 offset = (obj - slab->s_mem);
74556 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74557 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74558 struct cache_names {
74559 char *name;
74560 char *name_dma;
74561 + char *name_usercopy;
74562 };
74563
74564 static struct cache_names __initdata cache_names[] = {
74565 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74566 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74567 #include <linux/kmalloc_sizes.h>
74568 - {NULL,}
74569 + {NULL}
74570 #undef CACHE
74571 };
74572
74573 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74574 if (unlikely(gfpflags & GFP_DMA))
74575 return csizep->cs_dmacachep;
74576 #endif
74577 +
74578 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74579 + if (unlikely(gfpflags & GFP_USERCOPY))
74580 + return csizep->cs_usercopycachep;
74581 +#endif
74582 +
74583 return csizep->cs_cachep;
74584 }
74585
74586 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74587 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74588 sizes[INDEX_AC].cs_size,
74589 ARCH_KMALLOC_MINALIGN,
74590 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74591 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74592 NULL);
74593
74594 if (INDEX_AC != INDEX_L3) {
74595 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74596 __kmem_cache_create(names[INDEX_L3].name,
74597 sizes[INDEX_L3].cs_size,
74598 ARCH_KMALLOC_MINALIGN,
74599 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74600 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74601 NULL);
74602 }
74603
74604 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74605 sizes->cs_cachep = __kmem_cache_create(names->name,
74606 sizes->cs_size,
74607 ARCH_KMALLOC_MINALIGN,
74608 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74609 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74610 NULL);
74611 }
74612 #ifdef CONFIG_ZONE_DMA
74613 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74614 SLAB_PANIC,
74615 NULL);
74616 #endif
74617 +
74618 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74619 + sizes->cs_usercopycachep = kmem_cache_create(
74620 + names->name_usercopy,
74621 + sizes->cs_size,
74622 + ARCH_KMALLOC_MINALIGN,
74623 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74624 + NULL);
74625 +#endif
74626 +
74627 sizes++;
74628 names++;
74629 }
74630 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74631 }
74632 /* cpu stats */
74633 {
74634 - unsigned long allochit = atomic_read(&cachep->allochit);
74635 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74636 - unsigned long freehit = atomic_read(&cachep->freehit);
74637 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74638 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74639 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74640 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74641 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74642
74643 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74644 allochit, allocmiss, freehit, freemiss);
74645 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74646 {
74647 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74648 #ifdef CONFIG_DEBUG_SLAB_LEAK
74649 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74650 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74651 #endif
74652 return 0;
74653 }
74654 module_init(slab_proc_init);
74655 #endif
74656
74657 +bool is_usercopy_object(const void *ptr)
74658 +{
74659 + struct page *page;
74660 + struct kmem_cache *cachep;
74661 +
74662 + if (ZERO_OR_NULL_PTR(ptr))
74663 + return false;
74664 +
74665 + if (!slab_is_available())
74666 + return false;
74667 +
74668 + if (!virt_addr_valid(ptr))
74669 + return false;
74670 +
74671 + page = virt_to_head_page(ptr);
74672 +
74673 + if (!PageSlab(page))
74674 + return false;
74675 +
74676 + cachep = page_get_cache(page);
74677 + return cachep->flags & SLAB_USERCOPY;
74678 +}
74679 +
74680 +#ifdef CONFIG_PAX_USERCOPY
74681 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74682 +{
74683 + struct page *page;
74684 + struct kmem_cache *cachep;
74685 + struct slab *slabp;
74686 + unsigned int objnr;
74687 + unsigned long offset;
74688 +
74689 + if (ZERO_OR_NULL_PTR(ptr))
74690 + return "<null>";
74691 +
74692 + if (!virt_addr_valid(ptr))
74693 + return NULL;
74694 +
74695 + page = virt_to_head_page(ptr);
74696 +
74697 + if (!PageSlab(page))
74698 + return NULL;
74699 +
74700 + cachep = page_get_cache(page);
74701 + if (!(cachep->flags & SLAB_USERCOPY))
74702 + return cachep->name;
74703 +
74704 + slabp = page->slab_page;
74705 + objnr = obj_to_index(cachep, slabp, ptr);
74706 + BUG_ON(objnr >= cachep->num);
74707 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74708 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74709 + return NULL;
74710 +
74711 + return cachep->name;
74712 +}
74713 +#endif
74714 +
74715 /**
74716 * ksize - get the actual amount of memory allocated for a given object
74717 * @objp: Pointer to the object
74718 diff --git a/mm/slob.c b/mm/slob.c
74719 index 45d4ca7..88943c1 100644
74720 --- a/mm/slob.c
74721 +++ b/mm/slob.c
74722 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74723 /*
74724 * Return the size of a slob block.
74725 */
74726 -static slobidx_t slob_units(slob_t *s)
74727 +static slobidx_t slob_units(const slob_t *s)
74728 {
74729 if (s->units > 0)
74730 return s->units;
74731 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74732 /*
74733 * Return the next free slob block pointer after this one.
74734 */
74735 -static slob_t *slob_next(slob_t *s)
74736 +static slob_t *slob_next(const slob_t *s)
74737 {
74738 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74739 slobidx_t next;
74740 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74741 /*
74742 * Returns true if s is the last free block in its page.
74743 */
74744 -static int slob_last(slob_t *s)
74745 +static int slob_last(const slob_t *s)
74746 {
74747 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74748 }
74749
74750 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74751 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74752 {
74753 - void *page;
74754 + struct page *page;
74755
74756 #ifdef CONFIG_NUMA
74757 if (node != -1)
74758 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74759 if (!page)
74760 return NULL;
74761
74762 - return page_address(page);
74763 + __SetPageSlab(page);
74764 + return page;
74765 }
74766
74767 -static void slob_free_pages(void *b, int order)
74768 +static void slob_free_pages(struct page *sp, int order)
74769 {
74770 if (current->reclaim_state)
74771 current->reclaim_state->reclaimed_slab += 1 << order;
74772 - free_pages((unsigned long)b, order);
74773 + __ClearPageSlab(sp);
74774 + reset_page_mapcount(sp);
74775 + sp->private = 0;
74776 + __free_pages(sp, order);
74777 }
74778
74779 /*
74780 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74781
74782 /* Not enough space: must allocate a new page */
74783 if (!b) {
74784 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74785 - if (!b)
74786 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74787 + if (!sp)
74788 return NULL;
74789 - sp = virt_to_page(b);
74790 - __SetPageSlab(sp);
74791 + b = page_address(sp);
74792
74793 spin_lock_irqsave(&slob_lock, flags);
74794 sp->units = SLOB_UNITS(PAGE_SIZE);
74795 sp->freelist = b;
74796 + sp->private = 0;
74797 INIT_LIST_HEAD(&sp->list);
74798 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74799 set_slob_page_free(sp, slob_list);
74800 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74801 if (slob_page_free(sp))
74802 clear_slob_page_free(sp);
74803 spin_unlock_irqrestore(&slob_lock, flags);
74804 - __ClearPageSlab(sp);
74805 - reset_page_mapcount(sp);
74806 - slob_free_pages(b, 0);
74807 + slob_free_pages(sp, 0);
74808 return;
74809 }
74810
74811 @@ -425,11 +427,10 @@ out:
74812 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74813 */
74814
74815 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74816 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74817 {
74818 - unsigned int *m;
74819 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74820 - void *ret;
74821 + slob_t *m;
74822 + void *ret = NULL;
74823
74824 gfp &= gfp_allowed_mask;
74825
74826 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74827
74828 if (!m)
74829 return NULL;
74830 - *m = size;
74831 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74832 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74833 + m[0].units = size;
74834 + m[1].units = align;
74835 ret = (void *)m + align;
74836
74837 trace_kmalloc_node(_RET_IP_, ret,
74838 size, size + align, gfp, node);
74839 } else {
74840 unsigned int order = get_order(size);
74841 + struct page *page;
74842
74843 if (likely(order))
74844 gfp |= __GFP_COMP;
74845 - ret = slob_new_pages(gfp, order, node);
74846 - if (ret) {
74847 - struct page *page;
74848 - page = virt_to_page(ret);
74849 + page = slob_new_pages(gfp, order, node);
74850 + if (page) {
74851 + ret = page_address(page);
74852 page->private = size;
74853 }
74854
74855 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74856 size, PAGE_SIZE << order, gfp, node);
74857 }
74858
74859 - kmemleak_alloc(ret, size, 1, gfp);
74860 + return ret;
74861 +}
74862 +
74863 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74864 +{
74865 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74866 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74867 +
74868 + if (!ZERO_OR_NULL_PTR(ret))
74869 + kmemleak_alloc(ret, size, 1, gfp);
74870 return ret;
74871 }
74872 EXPORT_SYMBOL(__kmalloc_node);
74873 @@ -480,15 +493,91 @@ void kfree(const void *block)
74874 kmemleak_free(block);
74875
74876 sp = virt_to_page(block);
74877 - if (PageSlab(sp)) {
74878 + VM_BUG_ON(!PageSlab(sp));
74879 + if (!sp->private) {
74880 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74881 - unsigned int *m = (unsigned int *)(block - align);
74882 - slob_free(m, *m + align);
74883 - } else
74884 + slob_t *m = (slob_t *)(block - align);
74885 + slob_free(m, m[0].units + align);
74886 + } else {
74887 + __ClearPageSlab(sp);
74888 + reset_page_mapcount(sp);
74889 + sp->private = 0;
74890 put_page(sp);
74891 + }
74892 }
74893 EXPORT_SYMBOL(kfree);
74894
74895 +bool is_usercopy_object(const void *ptr)
74896 +{
74897 + if (!slab_is_available())
74898 + return false;
74899 +
74900 + // PAX: TODO
74901 +
74902 + return false;
74903 +}
74904 +
74905 +#ifdef CONFIG_PAX_USERCOPY
74906 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74907 +{
74908 + struct page *page;
74909 + const slob_t *free;
74910 + const void *base;
74911 + unsigned long flags;
74912 +
74913 + if (ZERO_OR_NULL_PTR(ptr))
74914 + return "<null>";
74915 +
74916 + if (!virt_addr_valid(ptr))
74917 + return NULL;
74918 +
74919 + page = virt_to_head_page(ptr);
74920 + if (!PageSlab(page))
74921 + return NULL;
74922 +
74923 + if (page->private) {
74924 + base = page;
74925 + if (base <= ptr && n <= page->private - (ptr - base))
74926 + return NULL;
74927 + return "<slob>";
74928 + }
74929 +
74930 + /* some tricky double walking to find the chunk */
74931 + spin_lock_irqsave(&slob_lock, flags);
74932 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74933 + free = page->freelist;
74934 +
74935 + while (!slob_last(free) && (void *)free <= ptr) {
74936 + base = free + slob_units(free);
74937 + free = slob_next(free);
74938 + }
74939 +
74940 + while (base < (void *)free) {
74941 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74942 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74943 + int offset;
74944 +
74945 + if (ptr < base + align)
74946 + break;
74947 +
74948 + offset = ptr - base - align;
74949 + if (offset >= m) {
74950 + base += size;
74951 + continue;
74952 + }
74953 +
74954 + if (n > m - offset)
74955 + break;
74956 +
74957 + spin_unlock_irqrestore(&slob_lock, flags);
74958 + return NULL;
74959 + }
74960 +
74961 + spin_unlock_irqrestore(&slob_lock, flags);
74962 + return "<slob>";
74963 +}
74964 +#endif
74965 +
74966 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74967 size_t ksize(const void *block)
74968 {
74969 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
74970 return 0;
74971
74972 sp = virt_to_page(block);
74973 - if (PageSlab(sp)) {
74974 + VM_BUG_ON(!PageSlab(sp));
74975 + if (!sp->private) {
74976 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74977 - unsigned int *m = (unsigned int *)(block - align);
74978 - return SLOB_UNITS(*m) * SLOB_UNIT;
74979 + slob_t *m = (slob_t *)(block - align);
74980 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74981 } else
74982 return sp->private;
74983 }
74984 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
74985 {
74986 struct kmem_cache *c;
74987
74988 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74989 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74990 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74991 +#else
74992 c = slob_alloc(sizeof(struct kmem_cache),
74993 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74994 +#endif
74995
74996 if (c) {
74997 c->name = name;
74998 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
74999
75000 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75001 {
75002 - void *b;
75003 + void *b = NULL;
75004
75005 flags &= gfp_allowed_mask;
75006
75007 lockdep_trace_alloc(flags);
75008
75009 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75010 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75011 +#else
75012 if (c->size < PAGE_SIZE) {
75013 b = slob_alloc(c->size, flags, c->align, node);
75014 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75015 SLOB_UNITS(c->size) * SLOB_UNIT,
75016 flags, node);
75017 } else {
75018 - b = slob_new_pages(flags, get_order(c->size), node);
75019 + struct page *sp;
75020 +
75021 + sp = slob_new_pages(flags, get_order(c->size), node);
75022 + if (sp) {
75023 + b = page_address(sp);
75024 + sp->private = c->size;
75025 + }
75026 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75027 PAGE_SIZE << get_order(c->size),
75028 flags, node);
75029 }
75030 +#endif
75031
75032 if (c->ctor)
75033 c->ctor(b);
75034 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75035
75036 static void __kmem_cache_free(void *b, int size)
75037 {
75038 - if (size < PAGE_SIZE)
75039 + struct page *sp;
75040 +
75041 + sp = virt_to_page(b);
75042 + BUG_ON(!PageSlab(sp));
75043 + if (!sp->private)
75044 slob_free(b, size);
75045 else
75046 - slob_free_pages(b, get_order(size));
75047 + slob_free_pages(sp, get_order(size));
75048 }
75049
75050 static void kmem_rcu_free(struct rcu_head *head)
75051 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75052
75053 void kmem_cache_free(struct kmem_cache *c, void *b)
75054 {
75055 + int size = c->size;
75056 +
75057 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75058 + if (size + c->align < PAGE_SIZE) {
75059 + size += c->align;
75060 + b -= c->align;
75061 + }
75062 +#endif
75063 +
75064 kmemleak_free_recursive(b, c->flags);
75065 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75066 struct slob_rcu *slob_rcu;
75067 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75068 - slob_rcu->size = c->size;
75069 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75070 + slob_rcu->size = size;
75071 call_rcu(&slob_rcu->head, kmem_rcu_free);
75072 } else {
75073 - __kmem_cache_free(b, c->size);
75074 + __kmem_cache_free(b, size);
75075 }
75076
75077 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75078 + trace_kfree(_RET_IP_, b);
75079 +#else
75080 trace_kmem_cache_free(_RET_IP_, b);
75081 +#endif
75082 +
75083 }
75084 EXPORT_SYMBOL(kmem_cache_free);
75085
75086 diff --git a/mm/slub.c b/mm/slub.c
75087 index 2fdd96f..1e2f893 100644
75088 --- a/mm/slub.c
75089 +++ b/mm/slub.c
75090 @@ -201,7 +201,7 @@ struct track {
75091
75092 enum track_item { TRACK_ALLOC, TRACK_FREE };
75093
75094 -#ifdef CONFIG_SYSFS
75095 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75096 static int sysfs_slab_add(struct kmem_cache *);
75097 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75098 static void sysfs_slab_remove(struct kmem_cache *);
75099 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75100 if (!t->addr)
75101 return;
75102
75103 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75104 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75105 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75106 #ifdef CONFIG_STACKTRACE
75107 {
75108 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75109
75110 page = virt_to_head_page(x);
75111
75112 + BUG_ON(!PageSlab(page));
75113 +
75114 slab_free(s, page, x, _RET_IP_);
75115
75116 trace_kmem_cache_free(_RET_IP_, x);
75117 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75118 * Merge control. If this is set then no merging of slab caches will occur.
75119 * (Could be removed. This was introduced to pacify the merge skeptics.)
75120 */
75121 -static int slub_nomerge;
75122 +static int slub_nomerge = 1;
75123
75124 /*
75125 * Calculate the order of allocation given an slab object size.
75126 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75127 else
75128 s->cpu_partial = 30;
75129
75130 - s->refcount = 1;
75131 + atomic_set(&s->refcount, 1);
75132 #ifdef CONFIG_NUMA
75133 s->remote_node_defrag_ratio = 1000;
75134 #endif
75135 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75136 void kmem_cache_destroy(struct kmem_cache *s)
75137 {
75138 mutex_lock(&slab_mutex);
75139 - s->refcount--;
75140 - if (!s->refcount) {
75141 + if (atomic_dec_and_test(&s->refcount)) {
75142 list_del(&s->list);
75143 mutex_unlock(&slab_mutex);
75144 if (kmem_cache_close(s)) {
75145 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75146 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75147 #endif
75148
75149 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75150 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75151 +#endif
75152 +
75153 static int __init setup_slub_min_order(char *str)
75154 {
75155 get_option(&str, &slub_min_order);
75156 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75157 return kmalloc_dma_caches[index];
75158
75159 #endif
75160 +
75161 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75162 + if (flags & SLAB_USERCOPY)
75163 + return kmalloc_usercopy_caches[index];
75164 +
75165 +#endif
75166 +
75167 return kmalloc_caches[index];
75168 }
75169
75170 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75171 EXPORT_SYMBOL(__kmalloc_node);
75172 #endif
75173
75174 +bool is_usercopy_object(const void *ptr)
75175 +{
75176 + struct page *page;
75177 + struct kmem_cache *s;
75178 +
75179 + if (ZERO_OR_NULL_PTR(ptr))
75180 + return false;
75181 +
75182 + if (!slab_is_available())
75183 + return false;
75184 +
75185 + if (!virt_addr_valid(ptr))
75186 + return false;
75187 +
75188 + page = virt_to_head_page(ptr);
75189 +
75190 + if (!PageSlab(page))
75191 + return false;
75192 +
75193 + s = page->slab;
75194 + return s->flags & SLAB_USERCOPY;
75195 +}
75196 +
75197 +#ifdef CONFIG_PAX_USERCOPY
75198 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75199 +{
75200 + struct page *page;
75201 + struct kmem_cache *s;
75202 + unsigned long offset;
75203 +
75204 + if (ZERO_OR_NULL_PTR(ptr))
75205 + return "<null>";
75206 +
75207 + if (!virt_addr_valid(ptr))
75208 + return NULL;
75209 +
75210 + page = virt_to_head_page(ptr);
75211 +
75212 + if (!PageSlab(page))
75213 + return NULL;
75214 +
75215 + s = page->slab;
75216 + if (!(s->flags & SLAB_USERCOPY))
75217 + return s->name;
75218 +
75219 + offset = (ptr - page_address(page)) % s->size;
75220 + if (offset <= s->object_size && n <= s->object_size - offset)
75221 + return NULL;
75222 +
75223 + return s->name;
75224 +}
75225 +#endif
75226 +
75227 size_t ksize(const void *object)
75228 {
75229 struct page *page;
75230 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75231 int node;
75232
75233 list_add(&s->list, &slab_caches);
75234 - s->refcount = -1;
75235 + atomic_set(&s->refcount, -1);
75236
75237 for_each_node_state(node, N_NORMAL_MEMORY) {
75238 struct kmem_cache_node *n = get_node(s, node);
75239 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75240
75241 /* Caches that are not of the two-to-the-power-of size */
75242 if (KMALLOC_MIN_SIZE <= 32) {
75243 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75244 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75245 caches++;
75246 }
75247
75248 if (KMALLOC_MIN_SIZE <= 64) {
75249 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75250 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75251 caches++;
75252 }
75253
75254 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75255 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75256 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75257 caches++;
75258 }
75259
75260 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75261 }
75262 }
75263 #endif
75264 +
75265 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75266 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75267 + struct kmem_cache *s = kmalloc_caches[i];
75268 +
75269 + if (s && s->size) {
75270 + char *name = kasprintf(GFP_NOWAIT,
75271 + "usercopy-kmalloc-%d", s->object_size);
75272 +
75273 + BUG_ON(!name);
75274 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75275 + s->object_size, SLAB_USERCOPY);
75276 + }
75277 + }
75278 +#endif
75279 +
75280 printk(KERN_INFO
75281 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75282 " CPUs=%d, Nodes=%d\n",
75283 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75284 /*
75285 * We may have set a slab to be unmergeable during bootstrap.
75286 */
75287 - if (s->refcount < 0)
75288 + if (atomic_read(&s->refcount) < 0)
75289 return 1;
75290
75291 return 0;
75292 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75293
75294 s = find_mergeable(size, align, flags, name, ctor);
75295 if (s) {
75296 - s->refcount++;
75297 + atomic_inc(&s->refcount);
75298 /*
75299 * Adjust the object sizes so that we clear
75300 * the complete object on kzalloc.
75301 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75302 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75303
75304 if (sysfs_slab_alias(s, name)) {
75305 - s->refcount--;
75306 + atomic_dec(&s->refcount);
75307 return NULL;
75308 }
75309 return s;
75310 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75311 }
75312 #endif
75313
75314 -#ifdef CONFIG_SYSFS
75315 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75316 static int count_inuse(struct page *page)
75317 {
75318 return page->inuse;
75319 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75320 validate_slab_cache(kmalloc_caches[9]);
75321 }
75322 #else
75323 -#ifdef CONFIG_SYSFS
75324 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75325 static void resiliency_test(void) {};
75326 #endif
75327 #endif
75328
75329 -#ifdef CONFIG_SYSFS
75330 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75331 enum slab_stat_type {
75332 SL_ALL, /* All slabs */
75333 SL_PARTIAL, /* Only partially allocated slabs */
75334 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75335
75336 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75337 {
75338 - return sprintf(buf, "%d\n", s->refcount - 1);
75339 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75340 }
75341 SLAB_ATTR_RO(aliases);
75342
75343 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75344 return name;
75345 }
75346
75347 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75348 static int sysfs_slab_add(struct kmem_cache *s)
75349 {
75350 int err;
75351 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75352 kobject_del(&s->kobj);
75353 kobject_put(&s->kobj);
75354 }
75355 +#endif
75356
75357 /*
75358 * Need to buffer aliases during bootup until sysfs becomes
75359 @@ -5354,6 +5437,7 @@ struct saved_alias {
75360
75361 static struct saved_alias *alias_list;
75362
75363 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75364 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75365 {
75366 struct saved_alias *al;
75367 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75368 alias_list = al;
75369 return 0;
75370 }
75371 +#endif
75372
75373 static int __init slab_sysfs_init(void)
75374 {
75375 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75376 index 1b7e22a..3fcd4f3 100644
75377 --- a/mm/sparse-vmemmap.c
75378 +++ b/mm/sparse-vmemmap.c
75379 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75380 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75381 if (!p)
75382 return NULL;
75383 - pud_populate(&init_mm, pud, p);
75384 + pud_populate_kernel(&init_mm, pud, p);
75385 }
75386 return pud;
75387 }
75388 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75389 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75390 if (!p)
75391 return NULL;
75392 - pgd_populate(&init_mm, pgd, p);
75393 + pgd_populate_kernel(&init_mm, pgd, p);
75394 }
75395 return pgd;
75396 }
75397 diff --git a/mm/swap.c b/mm/swap.c
75398 index 7782588..228c784 100644
75399 --- a/mm/swap.c
75400 +++ b/mm/swap.c
75401 @@ -30,6 +30,7 @@
75402 #include <linux/backing-dev.h>
75403 #include <linux/memcontrol.h>
75404 #include <linux/gfp.h>
75405 +#include <linux/hugetlb.h>
75406
75407 #include "internal.h"
75408
75409 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75410
75411 __page_cache_release(page);
75412 dtor = get_compound_page_dtor(page);
75413 + if (!PageHuge(page))
75414 + BUG_ON(dtor != free_compound_page);
75415 (*dtor)(page);
75416 }
75417
75418 diff --git a/mm/swapfile.c b/mm/swapfile.c
75419 index 14e254c..a6af32c 100644
75420 --- a/mm/swapfile.c
75421 +++ b/mm/swapfile.c
75422 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75423
75424 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75425 /* Activity counter to indicate that a swapon or swapoff has occurred */
75426 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75427 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75428
75429 static inline unsigned char swap_count(unsigned char ent)
75430 {
75431 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75432 }
75433 filp_close(swap_file, NULL);
75434 err = 0;
75435 - atomic_inc(&proc_poll_event);
75436 + atomic_inc_unchecked(&proc_poll_event);
75437 wake_up_interruptible(&proc_poll_wait);
75438
75439 out_dput:
75440 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75441
75442 poll_wait(file, &proc_poll_wait, wait);
75443
75444 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75445 - seq->poll_event = atomic_read(&proc_poll_event);
75446 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75447 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75448 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75449 }
75450
75451 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75452 return ret;
75453
75454 seq = file->private_data;
75455 - seq->poll_event = atomic_read(&proc_poll_event);
75456 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75457 return 0;
75458 }
75459
75460 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75461 (frontswap_map) ? "FS" : "");
75462
75463 mutex_unlock(&swapon_mutex);
75464 - atomic_inc(&proc_poll_event);
75465 + atomic_inc_unchecked(&proc_poll_event);
75466 wake_up_interruptible(&proc_poll_wait);
75467
75468 if (S_ISREG(inode->i_mode))
75469 diff --git a/mm/util.c b/mm/util.c
75470 index 8c7265a..c96d884 100644
75471 --- a/mm/util.c
75472 +++ b/mm/util.c
75473 @@ -285,6 +285,12 @@ done:
75474 void arch_pick_mmap_layout(struct mm_struct *mm)
75475 {
75476 mm->mmap_base = TASK_UNMAPPED_BASE;
75477 +
75478 +#ifdef CONFIG_PAX_RANDMMAP
75479 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75480 + mm->mmap_base += mm->delta_mmap;
75481 +#endif
75482 +
75483 mm->get_unmapped_area = arch_get_unmapped_area;
75484 mm->unmap_area = arch_unmap_area;
75485 }
75486 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75487 index 2bb90b1..ed47e53 100644
75488 --- a/mm/vmalloc.c
75489 +++ b/mm/vmalloc.c
75490 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75491
75492 pte = pte_offset_kernel(pmd, addr);
75493 do {
75494 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75495 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75496 +
75497 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75498 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75499 + BUG_ON(!pte_exec(*pte));
75500 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75501 + continue;
75502 + }
75503 +#endif
75504 +
75505 + {
75506 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75507 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75508 + }
75509 } while (pte++, addr += PAGE_SIZE, addr != end);
75510 }
75511
75512 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75513 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75514 {
75515 pte_t *pte;
75516 + int ret = -ENOMEM;
75517
75518 /*
75519 * nr is a running index into the array which helps higher level
75520 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75521 pte = pte_alloc_kernel(pmd, addr);
75522 if (!pte)
75523 return -ENOMEM;
75524 +
75525 + pax_open_kernel();
75526 do {
75527 struct page *page = pages[*nr];
75528
75529 - if (WARN_ON(!pte_none(*pte)))
75530 - return -EBUSY;
75531 - if (WARN_ON(!page))
75532 - return -ENOMEM;
75533 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75534 + if (pgprot_val(prot) & _PAGE_NX)
75535 +#endif
75536 +
75537 + if (WARN_ON(!pte_none(*pte))) {
75538 + ret = -EBUSY;
75539 + goto out;
75540 + }
75541 + if (WARN_ON(!page)) {
75542 + ret = -ENOMEM;
75543 + goto out;
75544 + }
75545 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75546 (*nr)++;
75547 } while (pte++, addr += PAGE_SIZE, addr != end);
75548 - return 0;
75549 + ret = 0;
75550 +out:
75551 + pax_close_kernel();
75552 + return ret;
75553 }
75554
75555 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75556 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75557 pmd_t *pmd;
75558 unsigned long next;
75559
75560 - pmd = pmd_alloc(&init_mm, pud, addr);
75561 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75562 if (!pmd)
75563 return -ENOMEM;
75564 do {
75565 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75566 pud_t *pud;
75567 unsigned long next;
75568
75569 - pud = pud_alloc(&init_mm, pgd, addr);
75570 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75571 if (!pud)
75572 return -ENOMEM;
75573 do {
75574 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75575 * and fall back on vmalloc() if that fails. Others
75576 * just put it in the vmalloc space.
75577 */
75578 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75579 +#ifdef CONFIG_MODULES
75580 +#ifdef MODULES_VADDR
75581 unsigned long addr = (unsigned long)x;
75582 if (addr >= MODULES_VADDR && addr < MODULES_END)
75583 return 1;
75584 #endif
75585 +
75586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75587 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75588 + return 1;
75589 +#endif
75590 +
75591 +#endif
75592 +
75593 return is_vmalloc_addr(x);
75594 }
75595
75596 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75597
75598 if (!pgd_none(*pgd)) {
75599 pud_t *pud = pud_offset(pgd, addr);
75600 +#ifdef CONFIG_X86
75601 + if (!pud_large(*pud))
75602 +#endif
75603 if (!pud_none(*pud)) {
75604 pmd_t *pmd = pmd_offset(pud, addr);
75605 +#ifdef CONFIG_X86
75606 + if (!pmd_large(*pmd))
75607 +#endif
75608 if (!pmd_none(*pmd)) {
75609 pte_t *ptep, pte;
75610
75611 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75612 * Allocate a region of KVA of the specified size and alignment, within the
75613 * vstart and vend.
75614 */
75615 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75616 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75617 unsigned long align,
75618 unsigned long vstart, unsigned long vend,
75619 int node, gfp_t gfp_mask)
75620 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75621 struct vm_struct *area;
75622
75623 BUG_ON(in_interrupt());
75624 +
75625 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75626 + if (flags & VM_KERNEXEC) {
75627 + if (start != VMALLOC_START || end != VMALLOC_END)
75628 + return NULL;
75629 + start = (unsigned long)MODULES_EXEC_VADDR;
75630 + end = (unsigned long)MODULES_EXEC_END;
75631 + }
75632 +#endif
75633 +
75634 if (flags & VM_IOREMAP) {
75635 int bit = fls(size);
75636
75637 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75638 if (count > totalram_pages)
75639 return NULL;
75640
75641 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75642 + if (!(pgprot_val(prot) & _PAGE_NX))
75643 + flags |= VM_KERNEXEC;
75644 +#endif
75645 +
75646 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75647 __builtin_return_address(0));
75648 if (!area)
75649 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75650 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75651 goto fail;
75652
75653 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75654 + if (!(pgprot_val(prot) & _PAGE_NX))
75655 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75656 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75657 + else
75658 +#endif
75659 +
75660 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75661 start, end, node, gfp_mask, caller);
75662 if (!area)
75663 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75664 * For tight control over page level allocator and protection flags
75665 * use __vmalloc() instead.
75666 */
75667 -
75668 void *vmalloc_exec(unsigned long size)
75669 {
75670 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75671 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75672 -1, __builtin_return_address(0));
75673 }
75674
75675 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75676 unsigned long uaddr = vma->vm_start;
75677 unsigned long usize = vma->vm_end - vma->vm_start;
75678
75679 + BUG_ON(vma->vm_mirror);
75680 +
75681 if ((PAGE_SIZE-1) & (unsigned long)addr)
75682 return -EINVAL;
75683
75684 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75685 {
75686 struct vm_struct *v = p;
75687
75688 - seq_printf(m, "0x%p-0x%p %7ld",
75689 + seq_printf(m, "0x%pK-0x%pK %7ld",
75690 v->addr, v->addr + v->size, v->size);
75691
75692 if (v->caller)
75693 diff --git a/mm/vmstat.c b/mm/vmstat.c
75694 index df7a674..8b4a4f3 100644
75695 --- a/mm/vmstat.c
75696 +++ b/mm/vmstat.c
75697 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75698 *
75699 * vm_stat contains the global counters
75700 */
75701 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75702 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75703 EXPORT_SYMBOL(vm_stat);
75704
75705 #ifdef CONFIG_SMP
75706 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75707 v = p->vm_stat_diff[i];
75708 p->vm_stat_diff[i] = 0;
75709 local_irq_restore(flags);
75710 - atomic_long_add(v, &zone->vm_stat[i]);
75711 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75712 global_diff[i] += v;
75713 #ifdef CONFIG_NUMA
75714 /* 3 seconds idle till flush */
75715 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75716
75717 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75718 if (global_diff[i])
75719 - atomic_long_add(global_diff[i], &vm_stat[i]);
75720 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75721 }
75722
75723 #endif
75724 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75725 start_cpu_timer(cpu);
75726 #endif
75727 #ifdef CONFIG_PROC_FS
75728 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75729 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75730 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75731 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75732 + {
75733 + mode_t gr_mode = S_IRUGO;
75734 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75735 + gr_mode = S_IRUSR;
75736 +#endif
75737 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75738 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75739 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75740 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75741 +#else
75742 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75743 +#endif
75744 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75745 + }
75746 #endif
75747 return 0;
75748 }
75749 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75750 index 9096bcb..43ed7bb 100644
75751 --- a/net/8021q/vlan.c
75752 +++ b/net/8021q/vlan.c
75753 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75754 err = -EPERM;
75755 if (!capable(CAP_NET_ADMIN))
75756 break;
75757 - if ((args.u.name_type >= 0) &&
75758 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75759 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75760 struct vlan_net *vn;
75761
75762 vn = net_generic(net, vlan_net_id);
75763 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75764 index 6449bae..8c1f454 100644
75765 --- a/net/9p/trans_fd.c
75766 +++ b/net/9p/trans_fd.c
75767 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75768 oldfs = get_fs();
75769 set_fs(get_ds());
75770 /* The cast to a user pointer is valid due to the set_fs() */
75771 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75772 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75773 set_fs(oldfs);
75774
75775 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75776 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75777 index 876fbe8..8bbea9f 100644
75778 --- a/net/atm/atm_misc.c
75779 +++ b/net/atm/atm_misc.c
75780 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75781 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75782 return 1;
75783 atm_return(vcc, truesize);
75784 - atomic_inc(&vcc->stats->rx_drop);
75785 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75786 return 0;
75787 }
75788 EXPORT_SYMBOL(atm_charge);
75789 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75790 }
75791 }
75792 atm_return(vcc, guess);
75793 - atomic_inc(&vcc->stats->rx_drop);
75794 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75795 return NULL;
75796 }
75797 EXPORT_SYMBOL(atm_alloc_charge);
75798 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75799
75800 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75801 {
75802 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75803 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75804 __SONET_ITEMS
75805 #undef __HANDLE_ITEM
75806 }
75807 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75808
75809 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75810 {
75811 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75812 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75813 __SONET_ITEMS
75814 #undef __HANDLE_ITEM
75815 }
75816 diff --git a/net/atm/lec.h b/net/atm/lec.h
75817 index a86aff9..3a0d6f6 100644
75818 --- a/net/atm/lec.h
75819 +++ b/net/atm/lec.h
75820 @@ -48,7 +48,7 @@ struct lane2_ops {
75821 const u8 *tlvs, u32 sizeoftlvs);
75822 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75823 const u8 *tlvs, u32 sizeoftlvs);
75824 -};
75825 +} __no_const;
75826
75827 /*
75828 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75829 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75830 index 0919a88..a23d54e 100644
75831 --- a/net/atm/mpc.h
75832 +++ b/net/atm/mpc.h
75833 @@ -33,7 +33,7 @@ struct mpoa_client {
75834 struct mpc_parameters parameters; /* parameters for this client */
75835
75836 const struct net_device_ops *old_ops;
75837 - struct net_device_ops new_ops;
75838 + net_device_ops_no_const new_ops;
75839 };
75840
75841
75842 diff --git a/net/atm/proc.c b/net/atm/proc.c
75843 index 0d020de..011c7bb 100644
75844 --- a/net/atm/proc.c
75845 +++ b/net/atm/proc.c
75846 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75847 const struct k_atm_aal_stats *stats)
75848 {
75849 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75850 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75851 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75852 - atomic_read(&stats->rx_drop));
75853 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75854 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75855 + atomic_read_unchecked(&stats->rx_drop));
75856 }
75857
75858 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75859 diff --git a/net/atm/resources.c b/net/atm/resources.c
75860 index 23f45ce..c748f1a 100644
75861 --- a/net/atm/resources.c
75862 +++ b/net/atm/resources.c
75863 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75864 static void copy_aal_stats(struct k_atm_aal_stats *from,
75865 struct atm_aal_stats *to)
75866 {
75867 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75868 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75869 __AAL_STAT_ITEMS
75870 #undef __HANDLE_ITEM
75871 }
75872 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75873 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75874 struct atm_aal_stats *to)
75875 {
75876 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75877 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75878 __AAL_STAT_ITEMS
75879 #undef __HANDLE_ITEM
75880 }
75881 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75882 index 469daab..9fc7f8d 100644
75883 --- a/net/batman-adv/bat_iv_ogm.c
75884 +++ b/net/batman-adv/bat_iv_ogm.c
75885 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
75886
75887 /* randomize initial seqno to avoid collision */
75888 get_random_bytes(&random_seqno, sizeof(random_seqno));
75889 - atomic_set(&hard_iface->seqno, random_seqno);
75890 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75891
75892 hard_iface->packet_len = BATADV_OGM_HLEN;
75893 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75894 @@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
75895 "Sending own" :
75896 "Forwarding"));
75897 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
75898 - "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75899 + "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75900 fwd_str, (packet_num > 0 ? "aggregated " : ""),
75901 batadv_ogm_packet->orig,
75902 ntohl(batadv_ogm_packet->seqno),
75903 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
75904
75905 /* change sequence number to network order */
75906 batadv_ogm_packet->seqno =
75907 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75908 - atomic_inc(&hard_iface->seqno);
75909 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75910 + atomic_inc_unchecked(&hard_iface->seqno);
75911
75912 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75913 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
75914 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
75915 return;
75916
75917 /* could be changed by schedule_own_packet() */
75918 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75919 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75920
75921 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
75922 has_directlink_flag = 1;
75923 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75924 index 282bf6e..4b2603d 100644
75925 --- a/net/batman-adv/hard-interface.c
75926 +++ b/net/batman-adv/hard-interface.c
75927 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
75928 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75929 dev_add_pack(&hard_iface->batman_adv_ptype);
75930
75931 - atomic_set(&hard_iface->frag_seqno, 1);
75932 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75933 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
75934 hard_iface->net_dev->name);
75935
75936 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
75937 /* This can't be called via a bat_priv callback because
75938 * we have no bat_priv yet.
75939 */
75940 - atomic_set(&hard_iface->seqno, 1);
75941 + atomic_set_unchecked(&hard_iface->seqno, 1);
75942 hard_iface->packet_buff = NULL;
75943
75944 return hard_iface;
75945 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75946 index 21c5357..768be1a 100644
75947 --- a/net/batman-adv/soft-interface.c
75948 +++ b/net/batman-adv/soft-interface.c
75949 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
75950
75951 /* set broadcast sequence number */
75952 bcast_packet->seqno =
75953 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75954 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75955
75956 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
75957
75958 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
75959 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
75960
75961 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
75962 - atomic_set(&bat_priv->bcast_seqno, 1);
75963 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75964 atomic_set(&bat_priv->ttvn, 0);
75965 atomic_set(&bat_priv->tt_local_changes, 0);
75966 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75967 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75968 index 12635fd..d99d837 100644
75969 --- a/net/batman-adv/types.h
75970 +++ b/net/batman-adv/types.h
75971 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
75972 int16_t if_num;
75973 char if_status;
75974 struct net_device *net_dev;
75975 - atomic_t seqno;
75976 - atomic_t frag_seqno;
75977 + atomic_unchecked_t seqno;
75978 + atomic_unchecked_t frag_seqno;
75979 unsigned char *packet_buff;
75980 int packet_len;
75981 struct kobject *hardif_obj;
75982 @@ -176,7 +176,7 @@ struct batadv_priv {
75983 atomic_t orig_interval; /* uint */
75984 atomic_t hop_penalty; /* uint */
75985 atomic_t log_level; /* uint */
75986 - atomic_t bcast_seqno;
75987 + atomic_unchecked_t bcast_seqno;
75988 atomic_t bcast_queue_left;
75989 atomic_t batman_queue_left;
75990 atomic_t ttvn; /* translation table version number */
75991 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75992 index 0016464..0ef3e53 100644
75993 --- a/net/batman-adv/unicast.c
75994 +++ b/net/batman-adv/unicast.c
75995 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
75996 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
75997 frag2->flags = large_tail;
75998
75999 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76000 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76001 frag1->seqno = htons(seqno - 1);
76002 frag2->seqno = htons(seqno);
76003
76004 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76005 index d5ace1e..231c4bf 100644
76006 --- a/net/bluetooth/hci_sock.c
76007 +++ b/net/bluetooth/hci_sock.c
76008 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76009 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76010 }
76011
76012 - len = min_t(unsigned int, len, sizeof(uf));
76013 + len = min((size_t)len, sizeof(uf));
76014 if (copy_from_user(&uf, optval, len)) {
76015 err = -EFAULT;
76016 break;
76017 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76018 index 38c00f1..e9d566e 100644
76019 --- a/net/bluetooth/l2cap_core.c
76020 +++ b/net/bluetooth/l2cap_core.c
76021 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76022 break;
76023
76024 case L2CAP_CONF_RFC:
76025 - if (olen == sizeof(rfc))
76026 - memcpy(&rfc, (void *)val, olen);
76027 + if (olen != sizeof(rfc))
76028 + break;
76029 +
76030 + memcpy(&rfc, (void *)val, olen);
76031
76032 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76033 rfc.mode != chan->mode)
76034 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76035 index 34bbe1c..451c19b 100644
76036 --- a/net/bluetooth/l2cap_sock.c
76037 +++ b/net/bluetooth/l2cap_sock.c
76038 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76039 struct sock *sk = sock->sk;
76040 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76041 struct l2cap_options opts;
76042 - int len, err = 0;
76043 + int err = 0;
76044 + size_t len = optlen;
76045 u32 opt;
76046
76047 BT_DBG("sk %p", sk);
76048 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76049 opts.max_tx = chan->max_tx;
76050 opts.txwin_size = chan->tx_win;
76051
76052 - len = min_t(unsigned int, sizeof(opts), optlen);
76053 + len = min(sizeof(opts), len);
76054 if (copy_from_user((char *) &opts, optval, len)) {
76055 err = -EFAULT;
76056 break;
76057 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76058 struct bt_security sec;
76059 struct bt_power pwr;
76060 struct l2cap_conn *conn;
76061 - int len, err = 0;
76062 + int err = 0;
76063 + size_t len = optlen;
76064 u32 opt;
76065
76066 BT_DBG("sk %p", sk);
76067 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76068
76069 sec.level = BT_SECURITY_LOW;
76070
76071 - len = min_t(unsigned int, sizeof(sec), optlen);
76072 + len = min(sizeof(sec), len);
76073 if (copy_from_user((char *) &sec, optval, len)) {
76074 err = -EFAULT;
76075 break;
76076 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76077
76078 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76079
76080 - len = min_t(unsigned int, sizeof(pwr), optlen);
76081 + len = min(sizeof(pwr), len);
76082 if (copy_from_user((char *) &pwr, optval, len)) {
76083 err = -EFAULT;
76084 break;
76085 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76086 index 1a17850..65a3129 100644
76087 --- a/net/bluetooth/rfcomm/sock.c
76088 +++ b/net/bluetooth/rfcomm/sock.c
76089 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76090 struct sock *sk = sock->sk;
76091 struct bt_security sec;
76092 int err = 0;
76093 - size_t len;
76094 + size_t len = optlen;
76095 u32 opt;
76096
76097 BT_DBG("sk %p", sk);
76098 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76099
76100 sec.level = BT_SECURITY_LOW;
76101
76102 - len = min_t(unsigned int, sizeof(sec), optlen);
76103 + len = min(sizeof(sec), len);
76104 if (copy_from_user((char *) &sec, optval, len)) {
76105 err = -EFAULT;
76106 break;
76107 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76108 index 56f1823..da44330 100644
76109 --- a/net/bluetooth/rfcomm/tty.c
76110 +++ b/net/bluetooth/rfcomm/tty.c
76111 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76112 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76113
76114 spin_lock_irqsave(&dev->port.lock, flags);
76115 - if (dev->port.count > 0) {
76116 + if (atomic_read(&dev->port.count) > 0) {
76117 spin_unlock_irqrestore(&dev->port.lock, flags);
76118 return;
76119 }
76120 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76121 return -ENODEV;
76122
76123 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76124 - dev->channel, dev->port.count);
76125 + dev->channel, atomic_read(&dev->port.count));
76126
76127 spin_lock_irqsave(&dev->port.lock, flags);
76128 - if (++dev->port.count > 1) {
76129 + if (atomic_inc_return(&dev->port.count) > 1) {
76130 spin_unlock_irqrestore(&dev->port.lock, flags);
76131 return 0;
76132 }
76133 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76134 return;
76135
76136 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76137 - dev->port.count);
76138 + atomic_read(&dev->port.count));
76139
76140 spin_lock_irqsave(&dev->port.lock, flags);
76141 - if (!--dev->port.count) {
76142 + if (!atomic_dec_return(&dev->port.count)) {
76143 spin_unlock_irqrestore(&dev->port.lock, flags);
76144 if (dev->tty_dev->parent)
76145 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76146 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76147 index 5fe2ff3..121d696 100644
76148 --- a/net/bridge/netfilter/ebtables.c
76149 +++ b/net/bridge/netfilter/ebtables.c
76150 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76151 tmp.valid_hooks = t->table->valid_hooks;
76152 }
76153 mutex_unlock(&ebt_mutex);
76154 - if (copy_to_user(user, &tmp, *len) != 0){
76155 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76156 BUGPRINT("c2u Didn't work\n");
76157 ret = -EFAULT;
76158 break;
76159 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76160 goto out;
76161 tmp.valid_hooks = t->valid_hooks;
76162
76163 - if (copy_to_user(user, &tmp, *len) != 0) {
76164 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76165 ret = -EFAULT;
76166 break;
76167 }
76168 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76169 tmp.entries_size = t->table->entries_size;
76170 tmp.valid_hooks = t->table->valid_hooks;
76171
76172 - if (copy_to_user(user, &tmp, *len) != 0) {
76173 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76174 ret = -EFAULT;
76175 break;
76176 }
76177 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76178 index 44f270f..1f5602d 100644
76179 --- a/net/caif/cfctrl.c
76180 +++ b/net/caif/cfctrl.c
76181 @@ -10,6 +10,7 @@
76182 #include <linux/spinlock.h>
76183 #include <linux/slab.h>
76184 #include <linux/pkt_sched.h>
76185 +#include <linux/sched.h>
76186 #include <net/caif/caif_layer.h>
76187 #include <net/caif/cfpkt.h>
76188 #include <net/caif/cfctrl.h>
76189 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76190 memset(&dev_info, 0, sizeof(dev_info));
76191 dev_info.id = 0xff;
76192 cfsrvl_init(&this->serv, 0, &dev_info, false);
76193 - atomic_set(&this->req_seq_no, 1);
76194 - atomic_set(&this->rsp_seq_no, 1);
76195 + atomic_set_unchecked(&this->req_seq_no, 1);
76196 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76197 this->serv.layer.receive = cfctrl_recv;
76198 sprintf(this->serv.layer.name, "ctrl");
76199 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76200 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76201 struct cfctrl_request_info *req)
76202 {
76203 spin_lock_bh(&ctrl->info_list_lock);
76204 - atomic_inc(&ctrl->req_seq_no);
76205 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76206 + atomic_inc_unchecked(&ctrl->req_seq_no);
76207 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76208 list_add_tail(&req->list, &ctrl->list);
76209 spin_unlock_bh(&ctrl->info_list_lock);
76210 }
76211 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76212 if (p != first)
76213 pr_warn("Requests are not received in order\n");
76214
76215 - atomic_set(&ctrl->rsp_seq_no,
76216 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76217 p->sequence_no);
76218 list_del(&p->list);
76219 goto out;
76220 diff --git a/net/can/gw.c b/net/can/gw.c
76221 index b54d5e6..91c3b25 100644
76222 --- a/net/can/gw.c
76223 +++ b/net/can/gw.c
76224 @@ -96,7 +96,7 @@ struct cf_mod {
76225 struct {
76226 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76227 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76228 - } csumfunc;
76229 + } __no_const csumfunc;
76230 };
76231
76232
76233 diff --git a/net/compat.c b/net/compat.c
76234 index 74ed1d7..3695bd9 100644
76235 --- a/net/compat.c
76236 +++ b/net/compat.c
76237 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76238 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76239 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76240 return -EFAULT;
76241 - kmsg->msg_name = compat_ptr(tmp1);
76242 - kmsg->msg_iov = compat_ptr(tmp2);
76243 - kmsg->msg_control = compat_ptr(tmp3);
76244 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76245 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76246 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76247 return 0;
76248 }
76249
76250 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76251
76252 if (kern_msg->msg_namelen) {
76253 if (mode == VERIFY_READ) {
76254 - int err = move_addr_to_kernel(kern_msg->msg_name,
76255 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76256 kern_msg->msg_namelen,
76257 kern_address);
76258 if (err < 0)
76259 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76260 kern_msg->msg_name = NULL;
76261
76262 tot_len = iov_from_user_compat_to_kern(kern_iov,
76263 - (struct compat_iovec __user *)kern_msg->msg_iov,
76264 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76265 kern_msg->msg_iovlen);
76266 if (tot_len >= 0)
76267 kern_msg->msg_iov = kern_iov;
76268 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76269
76270 #define CMSG_COMPAT_FIRSTHDR(msg) \
76271 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76272 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76273 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76274 (struct compat_cmsghdr __user *)NULL)
76275
76276 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76277 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76278 (ucmlen) <= (unsigned long) \
76279 ((mhdr)->msg_controllen - \
76280 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76281 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76282
76283 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76284 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76285 {
76286 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76287 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76288 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76289 msg->msg_controllen)
76290 return NULL;
76291 return (struct compat_cmsghdr __user *)ptr;
76292 @@ -219,7 +219,7 @@ Efault:
76293
76294 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76295 {
76296 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76297 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76298 struct compat_cmsghdr cmhdr;
76299 struct compat_timeval ctv;
76300 struct compat_timespec cts[3];
76301 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76302
76303 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76304 {
76305 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76306 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76307 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76308 int fdnum = scm->fp->count;
76309 struct file **fp = scm->fp->fp;
76310 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76311 return -EFAULT;
76312 old_fs = get_fs();
76313 set_fs(KERNEL_DS);
76314 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76315 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76316 set_fs(old_fs);
76317
76318 return err;
76319 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76320 len = sizeof(ktime);
76321 old_fs = get_fs();
76322 set_fs(KERNEL_DS);
76323 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76324 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76325 set_fs(old_fs);
76326
76327 if (!err) {
76328 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76329 case MCAST_JOIN_GROUP:
76330 case MCAST_LEAVE_GROUP:
76331 {
76332 - struct compat_group_req __user *gr32 = (void *)optval;
76333 + struct compat_group_req __user *gr32 = (void __user *)optval;
76334 struct group_req __user *kgr =
76335 compat_alloc_user_space(sizeof(struct group_req));
76336 u32 interface;
76337 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76338 case MCAST_BLOCK_SOURCE:
76339 case MCAST_UNBLOCK_SOURCE:
76340 {
76341 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76342 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76343 struct group_source_req __user *kgsr = compat_alloc_user_space(
76344 sizeof(struct group_source_req));
76345 u32 interface;
76346 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76347 }
76348 case MCAST_MSFILTER:
76349 {
76350 - struct compat_group_filter __user *gf32 = (void *)optval;
76351 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76352 struct group_filter __user *kgf;
76353 u32 interface, fmode, numsrc;
76354
76355 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76356 char __user *optval, int __user *optlen,
76357 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76358 {
76359 - struct compat_group_filter __user *gf32 = (void *)optval;
76360 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76361 struct group_filter __user *kgf;
76362 int __user *koptlen;
76363 u32 interface, fmode, numsrc;
76364 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76365
76366 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76367 return -EINVAL;
76368 - if (copy_from_user(a, args, nas[call]))
76369 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76370 return -EFAULT;
76371 a0 = a[0];
76372 a1 = a[1];
76373 diff --git a/net/core/datagram.c b/net/core/datagram.c
76374 index 0337e2b..47914a0 100644
76375 --- a/net/core/datagram.c
76376 +++ b/net/core/datagram.c
76377 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76378 }
76379
76380 kfree_skb(skb);
76381 - atomic_inc(&sk->sk_drops);
76382 + atomic_inc_unchecked(&sk->sk_drops);
76383 sk_mem_reclaim_partial(sk);
76384
76385 return err;
76386 diff --git a/net/core/dev.c b/net/core/dev.c
76387 index 89e33a5..16d9d25 100644
76388 --- a/net/core/dev.c
76389 +++ b/net/core/dev.c
76390 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76391 if (no_module && capable(CAP_NET_ADMIN))
76392 no_module = request_module("netdev-%s", name);
76393 if (no_module && capable(CAP_SYS_MODULE)) {
76394 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76395 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76396 +#else
76397 if (!request_module("%s", name))
76398 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76399 name);
76400 +#endif
76401 }
76402 }
76403 EXPORT_SYMBOL(dev_load);
76404 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76405 {
76406 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76407 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76408 - atomic_long_inc(&dev->rx_dropped);
76409 + atomic_long_inc_unchecked(&dev->rx_dropped);
76410 kfree_skb(skb);
76411 return NET_RX_DROP;
76412 }
76413 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76414 nf_reset(skb);
76415
76416 if (unlikely(!is_skb_forwardable(dev, skb))) {
76417 - atomic_long_inc(&dev->rx_dropped);
76418 + atomic_long_inc_unchecked(&dev->rx_dropped);
76419 kfree_skb(skb);
76420 return NET_RX_DROP;
76421 }
76422 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76423
76424 struct dev_gso_cb {
76425 void (*destructor)(struct sk_buff *skb);
76426 -};
76427 +} __no_const;
76428
76429 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76430
76431 @@ -2928,7 +2932,7 @@ enqueue:
76432
76433 local_irq_restore(flags);
76434
76435 - atomic_long_inc(&skb->dev->rx_dropped);
76436 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76437 kfree_skb(skb);
76438 return NET_RX_DROP;
76439 }
76440 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76441 }
76442 EXPORT_SYMBOL(netif_rx_ni);
76443
76444 -static void net_tx_action(struct softirq_action *h)
76445 +static void net_tx_action(void)
76446 {
76447 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76448
76449 @@ -3328,7 +3332,7 @@ ncls:
76450 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76451 } else {
76452 drop:
76453 - atomic_long_inc(&skb->dev->rx_dropped);
76454 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76455 kfree_skb(skb);
76456 /* Jamal, now you will not able to escape explaining
76457 * me how you were going to use this. :-)
76458 @@ -3895,7 +3899,7 @@ void netif_napi_del(struct napi_struct *napi)
76459 }
76460 EXPORT_SYMBOL(netif_napi_del);
76461
76462 -static void net_rx_action(struct softirq_action *h)
76463 +static void net_rx_action(void)
76464 {
76465 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76466 unsigned long time_limit = jiffies + 2;
76467 @@ -4365,8 +4369,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76468 else
76469 seq_printf(seq, "%04x", ntohs(pt->type));
76470
76471 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76472 + seq_printf(seq, " %-8s %p\n",
76473 + pt->dev ? pt->dev->name : "", NULL);
76474 +#else
76475 seq_printf(seq, " %-8s %pF\n",
76476 pt->dev ? pt->dev->name : "", pt->func);
76477 +#endif
76478 }
76479
76480 return 0;
76481 @@ -5919,7 +5928,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76482 } else {
76483 netdev_stats_to_stats64(storage, &dev->stats);
76484 }
76485 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76486 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76487 return storage;
76488 }
76489 EXPORT_SYMBOL(dev_get_stats);
76490 diff --git a/net/core/flow.c b/net/core/flow.c
76491 index e318c7e..168b1d0 100644
76492 --- a/net/core/flow.c
76493 +++ b/net/core/flow.c
76494 @@ -61,7 +61,7 @@ struct flow_cache {
76495 struct timer_list rnd_timer;
76496 };
76497
76498 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76499 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76500 EXPORT_SYMBOL(flow_cache_genid);
76501 static struct flow_cache flow_cache_global;
76502 static struct kmem_cache *flow_cachep __read_mostly;
76503 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76504
76505 static int flow_entry_valid(struct flow_cache_entry *fle)
76506 {
76507 - if (atomic_read(&flow_cache_genid) != fle->genid)
76508 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76509 return 0;
76510 if (fle->object && !fle->object->ops->check(fle->object))
76511 return 0;
76512 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76513 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76514 fcp->hash_count++;
76515 }
76516 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76517 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76518 flo = fle->object;
76519 if (!flo)
76520 goto ret_object;
76521 @@ -280,7 +280,7 @@ nocache:
76522 }
76523 flo = resolver(net, key, family, dir, flo, ctx);
76524 if (fle) {
76525 - fle->genid = atomic_read(&flow_cache_genid);
76526 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76527 if (!IS_ERR(flo))
76528 fle->object = flo;
76529 else
76530 diff --git a/net/core/iovec.c b/net/core/iovec.c
76531 index 7e7aeb0..2a998cb 100644
76532 --- a/net/core/iovec.c
76533 +++ b/net/core/iovec.c
76534 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76535 if (m->msg_namelen) {
76536 if (mode == VERIFY_READ) {
76537 void __user *namep;
76538 - namep = (void __user __force *) m->msg_name;
76539 + namep = (void __force_user *) m->msg_name;
76540 err = move_addr_to_kernel(namep, m->msg_namelen,
76541 address);
76542 if (err < 0)
76543 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76544 }
76545
76546 size = m->msg_iovlen * sizeof(struct iovec);
76547 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76548 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76549 return -EFAULT;
76550
76551 m->msg_iov = iov;
76552 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76553 index 2c5a0a0..a45f90c 100644
76554 --- a/net/core/rtnetlink.c
76555 +++ b/net/core/rtnetlink.c
76556 @@ -58,7 +58,7 @@ struct rtnl_link {
76557 rtnl_doit_func doit;
76558 rtnl_dumpit_func dumpit;
76559 rtnl_calcit_func calcit;
76560 -};
76561 +} __no_const;
76562
76563 static DEFINE_MUTEX(rtnl_mutex);
76564
76565 diff --git a/net/core/scm.c b/net/core/scm.c
76566 index 040cebe..5b1e312 100644
76567 --- a/net/core/scm.c
76568 +++ b/net/core/scm.c
76569 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76570 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76571 {
76572 struct cmsghdr __user *cm
76573 - = (__force struct cmsghdr __user *)msg->msg_control;
76574 + = (struct cmsghdr __force_user *)msg->msg_control;
76575 struct cmsghdr cmhdr;
76576 int cmlen = CMSG_LEN(len);
76577 int err;
76578 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76579 err = -EFAULT;
76580 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76581 goto out;
76582 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76583 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76584 goto out;
76585 cmlen = CMSG_SPACE(len);
76586 if (msg->msg_controllen < cmlen)
76587 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76588 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76589 {
76590 struct cmsghdr __user *cm
76591 - = (__force struct cmsghdr __user*)msg->msg_control;
76592 + = (struct cmsghdr __force_user *)msg->msg_control;
76593
76594 int fdmax = 0;
76595 int fdnum = scm->fp->count;
76596 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76597 if (fdnum < fdmax)
76598 fdmax = fdnum;
76599
76600 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76601 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76602 i++, cmfptr++)
76603 {
76604 struct socket *sock;
76605 diff --git a/net/core/sock.c b/net/core/sock.c
76606 index a6000fb..d4aee72 100644
76607 --- a/net/core/sock.c
76608 +++ b/net/core/sock.c
76609 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76610 struct sk_buff_head *list = &sk->sk_receive_queue;
76611
76612 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76613 - atomic_inc(&sk->sk_drops);
76614 + atomic_inc_unchecked(&sk->sk_drops);
76615 trace_sock_rcvqueue_full(sk, skb);
76616 return -ENOMEM;
76617 }
76618 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76619 return err;
76620
76621 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76622 - atomic_inc(&sk->sk_drops);
76623 + atomic_inc_unchecked(&sk->sk_drops);
76624 return -ENOBUFS;
76625 }
76626
76627 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76628 skb_dst_force(skb);
76629
76630 spin_lock_irqsave(&list->lock, flags);
76631 - skb->dropcount = atomic_read(&sk->sk_drops);
76632 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76633 __skb_queue_tail(list, skb);
76634 spin_unlock_irqrestore(&list->lock, flags);
76635
76636 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76637 skb->dev = NULL;
76638
76639 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76640 - atomic_inc(&sk->sk_drops);
76641 + atomic_inc_unchecked(&sk->sk_drops);
76642 goto discard_and_relse;
76643 }
76644 if (nested)
76645 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76646 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76647 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76648 bh_unlock_sock(sk);
76649 - atomic_inc(&sk->sk_drops);
76650 + atomic_inc_unchecked(&sk->sk_drops);
76651 goto discard_and_relse;
76652 }
76653
76654 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76655 struct timeval tm;
76656 } v;
76657
76658 - int lv = sizeof(int);
76659 - int len;
76660 + unsigned int lv = sizeof(int);
76661 + unsigned int len;
76662
76663 if (get_user(len, optlen))
76664 return -EFAULT;
76665 - if (len < 0)
76666 + if (len > INT_MAX)
76667 return -EINVAL;
76668
76669 memset(&v, 0, sizeof(v));
76670 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76671
76672 case SO_PEERNAME:
76673 {
76674 - char address[128];
76675 + char address[_K_SS_MAXSIZE];
76676
76677 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76678 return -ENOTCONN;
76679 - if (lv < len)
76680 + if (lv < len || sizeof address < len)
76681 return -EINVAL;
76682 if (copy_to_user(optval, address, len))
76683 return -EFAULT;
76684 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76685
76686 if (len > lv)
76687 len = lv;
76688 - if (copy_to_user(optval, &v, len))
76689 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76690 return -EFAULT;
76691 lenout:
76692 if (put_user(len, optlen))
76693 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76694 */
76695 smp_wmb();
76696 atomic_set(&sk->sk_refcnt, 1);
76697 - atomic_set(&sk->sk_drops, 0);
76698 + atomic_set_unchecked(&sk->sk_drops, 0);
76699 }
76700 EXPORT_SYMBOL(sock_init_data);
76701
76702 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76703 index 9d8755e..26de8bc 100644
76704 --- a/net/core/sock_diag.c
76705 +++ b/net/core/sock_diag.c
76706 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76707
76708 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76709 {
76710 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76711 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76712 cookie[1] != INET_DIAG_NOCOOKIE) &&
76713 ((u32)(unsigned long)sk != cookie[0] ||
76714 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76715 return -ESTALE;
76716 else
76717 +#endif
76718 return 0;
76719 }
76720 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76721
76722 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76723 {
76724 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76725 + cookie[0] = 0;
76726 + cookie[1] = 0;
76727 +#else
76728 cookie[0] = (u32)(unsigned long)sk;
76729 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76730 +#endif
76731 }
76732 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76733
76734 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76735 index a55eecc..dd8428c 100644
76736 --- a/net/decnet/sysctl_net_decnet.c
76737 +++ b/net/decnet/sysctl_net_decnet.c
76738 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76739
76740 if (len > *lenp) len = *lenp;
76741
76742 - if (copy_to_user(buffer, addr, len))
76743 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76744 return -EFAULT;
76745
76746 *lenp = len;
76747 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76748
76749 if (len > *lenp) len = *lenp;
76750
76751 - if (copy_to_user(buffer, devname, len))
76752 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76753 return -EFAULT;
76754
76755 *lenp = len;
76756 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76757 index 8e2b475..7263d89 100644
76758 --- a/net/ipv4/fib_frontend.c
76759 +++ b/net/ipv4/fib_frontend.c
76760 @@ -1019,12 +1019,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76761 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76762 fib_sync_up(dev);
76763 #endif
76764 - atomic_inc(&net->ipv4.dev_addr_genid);
76765 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76766 rt_cache_flush(dev_net(dev));
76767 break;
76768 case NETDEV_DOWN:
76769 fib_del_ifaddr(ifa, NULL);
76770 - atomic_inc(&net->ipv4.dev_addr_genid);
76771 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76772 if (ifa->ifa_dev->ifa_list == NULL) {
76773 /* Last address was deleted from this interface.
76774 * Disable IP.
76775 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76776 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76777 fib_sync_up(dev);
76778 #endif
76779 - atomic_inc(&net->ipv4.dev_addr_genid);
76780 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76781 rt_cache_flush(dev_net(dev));
76782 break;
76783 case NETDEV_DOWN:
76784 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76785 index a747100..c5c8de1 100644
76786 --- a/net/ipv4/fib_semantics.c
76787 +++ b/net/ipv4/fib_semantics.c
76788 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76789 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76790 nh->nh_gw,
76791 nh->nh_parent->fib_scope);
76792 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76793 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76794
76795 return nh->nh_saddr;
76796 }
76797 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76798 index 7880af9..70f92a3 100644
76799 --- a/net/ipv4/inet_hashtables.c
76800 +++ b/net/ipv4/inet_hashtables.c
76801 @@ -18,12 +18,15 @@
76802 #include <linux/sched.h>
76803 #include <linux/slab.h>
76804 #include <linux/wait.h>
76805 +#include <linux/security.h>
76806
76807 #include <net/inet_connection_sock.h>
76808 #include <net/inet_hashtables.h>
76809 #include <net/secure_seq.h>
76810 #include <net/ip.h>
76811
76812 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76813 +
76814 /*
76815 * Allocate and initialize a new local port bind bucket.
76816 * The bindhash mutex for snum's hash chain must be held here.
76817 @@ -530,6 +533,8 @@ ok:
76818 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76819 spin_unlock(&head->lock);
76820
76821 + gr_update_task_in_ip_table(current, inet_sk(sk));
76822 +
76823 if (tw) {
76824 inet_twsk_deschedule(tw, death_row);
76825 while (twrefcnt) {
76826 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76827 index c7527f6..d8bba61 100644
76828 --- a/net/ipv4/inetpeer.c
76829 +++ b/net/ipv4/inetpeer.c
76830 @@ -503,8 +503,8 @@ relookup:
76831 if (p) {
76832 p->daddr = *daddr;
76833 atomic_set(&p->refcnt, 1);
76834 - atomic_set(&p->rid, 0);
76835 - atomic_set(&p->ip_id_count,
76836 + atomic_set_unchecked(&p->rid, 0);
76837 + atomic_set_unchecked(&p->ip_id_count,
76838 (daddr->family == AF_INET) ?
76839 secure_ip_id(daddr->addr.a4) :
76840 secure_ipv6_id(daddr->addr.a6));
76841 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76842 index 8d07c97..d0812ef 100644
76843 --- a/net/ipv4/ip_fragment.c
76844 +++ b/net/ipv4/ip_fragment.c
76845 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76846 return 0;
76847
76848 start = qp->rid;
76849 - end = atomic_inc_return(&peer->rid);
76850 + end = atomic_inc_return_unchecked(&peer->rid);
76851 qp->rid = end;
76852
76853 rc = qp->q.fragments && (end - start) > max;
76854 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76855 index 5eea4a8..49819c2 100644
76856 --- a/net/ipv4/ip_sockglue.c
76857 +++ b/net/ipv4/ip_sockglue.c
76858 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76859 len = min_t(unsigned int, len, opt->optlen);
76860 if (put_user(len, optlen))
76861 return -EFAULT;
76862 - if (copy_to_user(optval, opt->__data, len))
76863 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76864 + copy_to_user(optval, opt->__data, len))
76865 return -EFAULT;
76866 return 0;
76867 }
76868 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76869 if (sk->sk_type != SOCK_STREAM)
76870 return -ENOPROTOOPT;
76871
76872 - msg.msg_control = optval;
76873 + msg.msg_control = (void __force_kernel *)optval;
76874 msg.msg_controllen = len;
76875 msg.msg_flags = flags;
76876
76877 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76878 index 67e8a6b..386764d 100644
76879 --- a/net/ipv4/ipconfig.c
76880 +++ b/net/ipv4/ipconfig.c
76881 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76882
76883 mm_segment_t oldfs = get_fs();
76884 set_fs(get_ds());
76885 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76886 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76887 set_fs(oldfs);
76888 return res;
76889 }
76890 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76891
76892 mm_segment_t oldfs = get_fs();
76893 set_fs(get_ds());
76894 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76895 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76896 set_fs(oldfs);
76897 return res;
76898 }
76899 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76900
76901 mm_segment_t oldfs = get_fs();
76902 set_fs(get_ds());
76903 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76904 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76905 set_fs(oldfs);
76906 return res;
76907 }
76908 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76909 index 97e61ea..cac1bbb 100644
76910 --- a/net/ipv4/netfilter/arp_tables.c
76911 +++ b/net/ipv4/netfilter/arp_tables.c
76912 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
76913 #endif
76914
76915 static int get_info(struct net *net, void __user *user,
76916 - const int *len, int compat)
76917 + int len, int compat)
76918 {
76919 char name[XT_TABLE_MAXNAMELEN];
76920 struct xt_table *t;
76921 int ret;
76922
76923 - if (*len != sizeof(struct arpt_getinfo)) {
76924 - duprintf("length %u != %Zu\n", *len,
76925 + if (len != sizeof(struct arpt_getinfo)) {
76926 + duprintf("length %u != %Zu\n", len,
76927 sizeof(struct arpt_getinfo));
76928 return -EINVAL;
76929 }
76930 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
76931 info.size = private->size;
76932 strcpy(info.name, name);
76933
76934 - if (copy_to_user(user, &info, *len) != 0)
76935 + if (copy_to_user(user, &info, len) != 0)
76936 ret = -EFAULT;
76937 else
76938 ret = 0;
76939 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
76940
76941 switch (cmd) {
76942 case ARPT_SO_GET_INFO:
76943 - ret = get_info(sock_net(sk), user, len, 1);
76944 + ret = get_info(sock_net(sk), user, *len, 1);
76945 break;
76946 case ARPT_SO_GET_ENTRIES:
76947 ret = compat_get_entries(sock_net(sk), user, len);
76948 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
76949
76950 switch (cmd) {
76951 case ARPT_SO_GET_INFO:
76952 - ret = get_info(sock_net(sk), user, len, 0);
76953 + ret = get_info(sock_net(sk), user, *len, 0);
76954 break;
76955
76956 case ARPT_SO_GET_ENTRIES:
76957 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76958 index 170b1fd..6105b91 100644
76959 --- a/net/ipv4/netfilter/ip_tables.c
76960 +++ b/net/ipv4/netfilter/ip_tables.c
76961 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
76962 #endif
76963
76964 static int get_info(struct net *net, void __user *user,
76965 - const int *len, int compat)
76966 + int len, int compat)
76967 {
76968 char name[XT_TABLE_MAXNAMELEN];
76969 struct xt_table *t;
76970 int ret;
76971
76972 - if (*len != sizeof(struct ipt_getinfo)) {
76973 - duprintf("length %u != %zu\n", *len,
76974 + if (len != sizeof(struct ipt_getinfo)) {
76975 + duprintf("length %u != %zu\n", len,
76976 sizeof(struct ipt_getinfo));
76977 return -EINVAL;
76978 }
76979 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
76980 info.size = private->size;
76981 strcpy(info.name, name);
76982
76983 - if (copy_to_user(user, &info, *len) != 0)
76984 + if (copy_to_user(user, &info, len) != 0)
76985 ret = -EFAULT;
76986 else
76987 ret = 0;
76988 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76989
76990 switch (cmd) {
76991 case IPT_SO_GET_INFO:
76992 - ret = get_info(sock_net(sk), user, len, 1);
76993 + ret = get_info(sock_net(sk), user, *len, 1);
76994 break;
76995 case IPT_SO_GET_ENTRIES:
76996 ret = compat_get_entries(sock_net(sk), user, len);
76997 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76998
76999 switch (cmd) {
77000 case IPT_SO_GET_INFO:
77001 - ret = get_info(sock_net(sk), user, len, 0);
77002 + ret = get_info(sock_net(sk), user, *len, 0);
77003 break;
77004
77005 case IPT_SO_GET_ENTRIES:
77006 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77007 index 6232d47..6b88607 100644
77008 --- a/net/ipv4/ping.c
77009 +++ b/net/ipv4/ping.c
77010 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77011 sk_rmem_alloc_get(sp),
77012 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77013 atomic_read(&sp->sk_refcnt), sp,
77014 - atomic_read(&sp->sk_drops), len);
77015 + atomic_read_unchecked(&sp->sk_drops), len);
77016 }
77017
77018 static int ping_seq_show(struct seq_file *seq, void *v)
77019 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77020 index d23c657..cb69cc2 100644
77021 --- a/net/ipv4/raw.c
77022 +++ b/net/ipv4/raw.c
77023 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77024 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77025 {
77026 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77027 - atomic_inc(&sk->sk_drops);
77028 + atomic_inc_unchecked(&sk->sk_drops);
77029 kfree_skb(skb);
77030 return NET_RX_DROP;
77031 }
77032 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77033
77034 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77035 {
77036 + struct icmp_filter filter;
77037 +
77038 if (optlen > sizeof(struct icmp_filter))
77039 optlen = sizeof(struct icmp_filter);
77040 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77041 + if (copy_from_user(&filter, optval, optlen))
77042 return -EFAULT;
77043 + raw_sk(sk)->filter = filter;
77044 return 0;
77045 }
77046
77047 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77048 {
77049 int len, ret = -EFAULT;
77050 + struct icmp_filter filter;
77051
77052 if (get_user(len, optlen))
77053 goto out;
77054 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77055 if (len > sizeof(struct icmp_filter))
77056 len = sizeof(struct icmp_filter);
77057 ret = -EFAULT;
77058 - if (put_user(len, optlen) ||
77059 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77060 + filter = raw_sk(sk)->filter;
77061 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77062 goto out;
77063 ret = 0;
77064 out: return ret;
77065 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77066 sk_wmem_alloc_get(sp),
77067 sk_rmem_alloc_get(sp),
77068 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77069 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77070 + atomic_read(&sp->sk_refcnt),
77071 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77072 + NULL,
77073 +#else
77074 + sp,
77075 +#endif
77076 + atomic_read_unchecked(&sp->sk_drops));
77077 }
77078
77079 static int raw_seq_show(struct seq_file *seq, void *v)
77080 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77081 index fd9af60..dca4e54 100644
77082 --- a/net/ipv4/route.c
77083 +++ b/net/ipv4/route.c
77084 @@ -2501,7 +2501,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77085
77086 static __net_init int rt_genid_init(struct net *net)
77087 {
77088 - atomic_set(&net->rt_genid, 0);
77089 + atomic_set_unchecked(&net->rt_genid, 0);
77090 get_random_bytes(&net->ipv4.dev_addr_genid,
77091 sizeof(net->ipv4.dev_addr_genid));
77092 return 0;
77093 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77094 index d377f48..c2211ed 100644
77095 --- a/net/ipv4/tcp_input.c
77096 +++ b/net/ipv4/tcp_input.c
77097 @@ -4728,7 +4728,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77098 * simplifies code)
77099 */
77100 static void
77101 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77102 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77103 struct sk_buff *head, struct sk_buff *tail,
77104 u32 start, u32 end)
77105 {
77106 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77107 index 00a748d..e6d546b 100644
77108 --- a/net/ipv4/tcp_ipv4.c
77109 +++ b/net/ipv4/tcp_ipv4.c
77110 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77111 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77112
77113
77114 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77115 +extern int grsec_enable_blackhole;
77116 +#endif
77117 +
77118 #ifdef CONFIG_TCP_MD5SIG
77119 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77120 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77121 @@ -1663,6 +1667,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77122 return 0;
77123
77124 reset:
77125 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77126 + if (!grsec_enable_blackhole)
77127 +#endif
77128 tcp_v4_send_reset(rsk, skb);
77129 discard:
77130 kfree_skb(skb);
77131 @@ -1763,12 +1770,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77132 TCP_SKB_CB(skb)->sacked = 0;
77133
77134 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77135 - if (!sk)
77136 + if (!sk) {
77137 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77138 + ret = 1;
77139 +#endif
77140 goto no_tcp_socket;
77141 -
77142 + }
77143 process:
77144 - if (sk->sk_state == TCP_TIME_WAIT)
77145 + if (sk->sk_state == TCP_TIME_WAIT) {
77146 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77147 + ret = 2;
77148 +#endif
77149 goto do_time_wait;
77150 + }
77151
77152 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77153 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77154 @@ -1819,6 +1833,10 @@ no_tcp_socket:
77155 bad_packet:
77156 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77157 } else {
77158 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77159 + if (!grsec_enable_blackhole || (ret == 1 &&
77160 + (skb->dev->flags & IFF_LOOPBACK)))
77161 +#endif
77162 tcp_v4_send_reset(NULL, skb);
77163 }
77164
77165 @@ -2414,7 +2432,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77166 0, /* non standard timer */
77167 0, /* open_requests have no inode */
77168 atomic_read(&sk->sk_refcnt),
77169 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77170 + NULL,
77171 +#else
77172 req,
77173 +#endif
77174 len);
77175 }
77176
77177 @@ -2464,7 +2486,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77178 sock_i_uid(sk),
77179 icsk->icsk_probes_out,
77180 sock_i_ino(sk),
77181 - atomic_read(&sk->sk_refcnt), sk,
77182 + atomic_read(&sk->sk_refcnt),
77183 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77184 + NULL,
77185 +#else
77186 + sk,
77187 +#endif
77188 jiffies_to_clock_t(icsk->icsk_rto),
77189 jiffies_to_clock_t(icsk->icsk_ack.ato),
77190 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77191 @@ -2492,7 +2519,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77192 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77193 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77194 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77195 - atomic_read(&tw->tw_refcnt), tw, len);
77196 + atomic_read(&tw->tw_refcnt),
77197 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77198 + NULL,
77199 +#else
77200 + tw,
77201 +#endif
77202 + len);
77203 }
77204
77205 #define TMPSZ 150
77206 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77207 index 6ff7f10..38de56e 100644
77208 --- a/net/ipv4/tcp_minisocks.c
77209 +++ b/net/ipv4/tcp_minisocks.c
77210 @@ -27,6 +27,10 @@
77211 #include <net/inet_common.h>
77212 #include <net/xfrm.h>
77213
77214 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77215 +extern int grsec_enable_blackhole;
77216 +#endif
77217 +
77218 int sysctl_tcp_syncookies __read_mostly = 1;
77219 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77220
77221 @@ -707,6 +711,10 @@ listen_overflow:
77222
77223 embryonic_reset:
77224 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77225 +
77226 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77227 + if (!grsec_enable_blackhole)
77228 +#endif
77229 if (!(flg & TCP_FLAG_RST))
77230 req->rsk_ops->send_reset(sk, skb);
77231
77232 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77233 index 4526fe6..1a34e43 100644
77234 --- a/net/ipv4/tcp_probe.c
77235 +++ b/net/ipv4/tcp_probe.c
77236 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77237 if (cnt + width >= len)
77238 break;
77239
77240 - if (copy_to_user(buf + cnt, tbuf, width))
77241 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77242 return -EFAULT;
77243 cnt += width;
77244 }
77245 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77246 index b774a03..3873efe 100644
77247 --- a/net/ipv4/tcp_timer.c
77248 +++ b/net/ipv4/tcp_timer.c
77249 @@ -22,6 +22,10 @@
77250 #include <linux/gfp.h>
77251 #include <net/tcp.h>
77252
77253 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77254 +extern int grsec_lastack_retries;
77255 +#endif
77256 +
77257 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77258 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77259 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77260 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77261 }
77262 }
77263
77264 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77265 + if ((sk->sk_state == TCP_LAST_ACK) &&
77266 + (grsec_lastack_retries > 0) &&
77267 + (grsec_lastack_retries < retry_until))
77268 + retry_until = grsec_lastack_retries;
77269 +#endif
77270 +
77271 if (retransmits_timed_out(sk, retry_until,
77272 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77273 /* Has it gone just too far? */
77274 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77275 index 2814f66..fa2b223 100644
77276 --- a/net/ipv4/udp.c
77277 +++ b/net/ipv4/udp.c
77278 @@ -87,6 +87,7 @@
77279 #include <linux/types.h>
77280 #include <linux/fcntl.h>
77281 #include <linux/module.h>
77282 +#include <linux/security.h>
77283 #include <linux/socket.h>
77284 #include <linux/sockios.h>
77285 #include <linux/igmp.h>
77286 @@ -111,6 +112,10 @@
77287 #include <trace/events/skb.h>
77288 #include "udp_impl.h"
77289
77290 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77291 +extern int grsec_enable_blackhole;
77292 +#endif
77293 +
77294 struct udp_table udp_table __read_mostly;
77295 EXPORT_SYMBOL(udp_table);
77296
77297 @@ -569,6 +574,9 @@ found:
77298 return s;
77299 }
77300
77301 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77302 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77303 +
77304 /*
77305 * This routine is called by the ICMP module when it gets some
77306 * sort of error condition. If err < 0 then the socket should
77307 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77308 dport = usin->sin_port;
77309 if (dport == 0)
77310 return -EINVAL;
77311 +
77312 + err = gr_search_udp_sendmsg(sk, usin);
77313 + if (err)
77314 + return err;
77315 } else {
77316 if (sk->sk_state != TCP_ESTABLISHED)
77317 return -EDESTADDRREQ;
77318 +
77319 + err = gr_search_udp_sendmsg(sk, NULL);
77320 + if (err)
77321 + return err;
77322 +
77323 daddr = inet->inet_daddr;
77324 dport = inet->inet_dport;
77325 /* Open fast path for connected socket.
77326 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77327 udp_lib_checksum_complete(skb)) {
77328 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77329 IS_UDPLITE(sk));
77330 - atomic_inc(&sk->sk_drops);
77331 + atomic_inc_unchecked(&sk->sk_drops);
77332 __skb_unlink(skb, rcvq);
77333 __skb_queue_tail(&list_kill, skb);
77334 }
77335 @@ -1194,6 +1211,10 @@ try_again:
77336 if (!skb)
77337 goto out;
77338
77339 + err = gr_search_udp_recvmsg(sk, skb);
77340 + if (err)
77341 + goto out_free;
77342 +
77343 ulen = skb->len - sizeof(struct udphdr);
77344 copied = len;
77345 if (copied > ulen)
77346 @@ -1227,7 +1248,7 @@ try_again:
77347 if (unlikely(err)) {
77348 trace_kfree_skb(skb, udp_recvmsg);
77349 if (!peeked) {
77350 - atomic_inc(&sk->sk_drops);
77351 + atomic_inc_unchecked(&sk->sk_drops);
77352 UDP_INC_STATS_USER(sock_net(sk),
77353 UDP_MIB_INERRORS, is_udplite);
77354 }
77355 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77356
77357 drop:
77358 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77359 - atomic_inc(&sk->sk_drops);
77360 + atomic_inc_unchecked(&sk->sk_drops);
77361 kfree_skb(skb);
77362 return -1;
77363 }
77364 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77365 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77366
77367 if (!skb1) {
77368 - atomic_inc(&sk->sk_drops);
77369 + atomic_inc_unchecked(&sk->sk_drops);
77370 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77371 IS_UDPLITE(sk));
77372 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77373 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77374 goto csum_error;
77375
77376 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77377 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77378 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77379 +#endif
77380 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77381
77382 /*
77383 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77384 sk_wmem_alloc_get(sp),
77385 sk_rmem_alloc_get(sp),
77386 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77387 - atomic_read(&sp->sk_refcnt), sp,
77388 - atomic_read(&sp->sk_drops), len);
77389 + atomic_read(&sp->sk_refcnt),
77390 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77391 + NULL,
77392 +#else
77393 + sp,
77394 +#endif
77395 + atomic_read_unchecked(&sp->sk_drops), len);
77396 }
77397
77398 int udp4_seq_show(struct seq_file *seq, void *v)
77399 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77400 index ea3e9af..b60262e 100644
77401 --- a/net/ipv6/addrconf.c
77402 +++ b/net/ipv6/addrconf.c
77403 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77404 p.iph.ihl = 5;
77405 p.iph.protocol = IPPROTO_IPV6;
77406 p.iph.ttl = 64;
77407 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77408 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77409
77410 if (ops->ndo_do_ioctl) {
77411 mm_segment_t oldfs = get_fs();
77412 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77413 index ba6d13d..6899122 100644
77414 --- a/net/ipv6/ipv6_sockglue.c
77415 +++ b/net/ipv6/ipv6_sockglue.c
77416 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77417 if (sk->sk_type != SOCK_STREAM)
77418 return -ENOPROTOOPT;
77419
77420 - msg.msg_control = optval;
77421 + msg.msg_control = (void __force_kernel *)optval;
77422 msg.msg_controllen = len;
77423 msg.msg_flags = flags;
77424
77425 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77426 index d7cb045..8c0ded6 100644
77427 --- a/net/ipv6/netfilter/ip6_tables.c
77428 +++ b/net/ipv6/netfilter/ip6_tables.c
77429 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77430 #endif
77431
77432 static int get_info(struct net *net, void __user *user,
77433 - const int *len, int compat)
77434 + int len, int compat)
77435 {
77436 char name[XT_TABLE_MAXNAMELEN];
77437 struct xt_table *t;
77438 int ret;
77439
77440 - if (*len != sizeof(struct ip6t_getinfo)) {
77441 - duprintf("length %u != %zu\n", *len,
77442 + if (len != sizeof(struct ip6t_getinfo)) {
77443 + duprintf("length %u != %zu\n", len,
77444 sizeof(struct ip6t_getinfo));
77445 return -EINVAL;
77446 }
77447 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77448 info.size = private->size;
77449 strcpy(info.name, name);
77450
77451 - if (copy_to_user(user, &info, *len) != 0)
77452 + if (copy_to_user(user, &info, len) != 0)
77453 ret = -EFAULT;
77454 else
77455 ret = 0;
77456 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77457
77458 switch (cmd) {
77459 case IP6T_SO_GET_INFO:
77460 - ret = get_info(sock_net(sk), user, len, 1);
77461 + ret = get_info(sock_net(sk), user, *len, 1);
77462 break;
77463 case IP6T_SO_GET_ENTRIES:
77464 ret = compat_get_entries(sock_net(sk), user, len);
77465 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77466
77467 switch (cmd) {
77468 case IP6T_SO_GET_INFO:
77469 - ret = get_info(sock_net(sk), user, len, 0);
77470 + ret = get_info(sock_net(sk), user, *len, 0);
77471 break;
77472
77473 case IP6T_SO_GET_ENTRIES:
77474 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77475 index 4a5f78b..3f22ebe 100644
77476 --- a/net/ipv6/raw.c
77477 +++ b/net/ipv6/raw.c
77478 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77479 {
77480 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77481 skb_checksum_complete(skb)) {
77482 - atomic_inc(&sk->sk_drops);
77483 + atomic_inc_unchecked(&sk->sk_drops);
77484 kfree_skb(skb);
77485 return NET_RX_DROP;
77486 }
77487 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77488 struct raw6_sock *rp = raw6_sk(sk);
77489
77490 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77491 - atomic_inc(&sk->sk_drops);
77492 + atomic_inc_unchecked(&sk->sk_drops);
77493 kfree_skb(skb);
77494 return NET_RX_DROP;
77495 }
77496 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77497
77498 if (inet->hdrincl) {
77499 if (skb_checksum_complete(skb)) {
77500 - atomic_inc(&sk->sk_drops);
77501 + atomic_inc_unchecked(&sk->sk_drops);
77502 kfree_skb(skb);
77503 return NET_RX_DROP;
77504 }
77505 @@ -604,7 +604,7 @@ out:
77506 return err;
77507 }
77508
77509 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77510 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77511 struct flowi6 *fl6, struct dst_entry **dstp,
77512 unsigned int flags)
77513 {
77514 @@ -916,12 +916,15 @@ do_confirm:
77515 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77516 char __user *optval, int optlen)
77517 {
77518 + struct icmp6_filter filter;
77519 +
77520 switch (optname) {
77521 case ICMPV6_FILTER:
77522 if (optlen > sizeof(struct icmp6_filter))
77523 optlen = sizeof(struct icmp6_filter);
77524 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77525 + if (copy_from_user(&filter, optval, optlen))
77526 return -EFAULT;
77527 + raw6_sk(sk)->filter = filter;
77528 return 0;
77529 default:
77530 return -ENOPROTOOPT;
77531 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77532 char __user *optval, int __user *optlen)
77533 {
77534 int len;
77535 + struct icmp6_filter filter;
77536
77537 switch (optname) {
77538 case ICMPV6_FILTER:
77539 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77540 len = sizeof(struct icmp6_filter);
77541 if (put_user(len, optlen))
77542 return -EFAULT;
77543 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77544 + filter = raw6_sk(sk)->filter;
77545 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77546 return -EFAULT;
77547 return 0;
77548 default:
77549 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77550 0, 0L, 0,
77551 sock_i_uid(sp), 0,
77552 sock_i_ino(sp),
77553 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77554 + atomic_read(&sp->sk_refcnt),
77555 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77556 + NULL,
77557 +#else
77558 + sp,
77559 +#endif
77560 + atomic_read_unchecked(&sp->sk_drops));
77561 }
77562
77563 static int raw6_seq_show(struct seq_file *seq, void *v)
77564 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77565 index acd32e3..f73f8f7 100644
77566 --- a/net/ipv6/tcp_ipv6.c
77567 +++ b/net/ipv6/tcp_ipv6.c
77568 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77569 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77570 }
77571
77572 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77573 +extern int grsec_enable_blackhole;
77574 +#endif
77575 +
77576 static void tcp_v6_hash(struct sock *sk)
77577 {
77578 if (sk->sk_state != TCP_CLOSE) {
77579 @@ -1510,6 +1514,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77580 return 0;
77581
77582 reset:
77583 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77584 + if (!grsec_enable_blackhole)
77585 +#endif
77586 tcp_v6_send_reset(sk, skb);
77587 discard:
77588 if (opt_skb)
77589 @@ -1591,12 +1598,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77590 TCP_SKB_CB(skb)->sacked = 0;
77591
77592 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77593 - if (!sk)
77594 + if (!sk) {
77595 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77596 + ret = 1;
77597 +#endif
77598 goto no_tcp_socket;
77599 + }
77600
77601 process:
77602 - if (sk->sk_state == TCP_TIME_WAIT)
77603 + if (sk->sk_state == TCP_TIME_WAIT) {
77604 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77605 + ret = 2;
77606 +#endif
77607 goto do_time_wait;
77608 + }
77609
77610 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77611 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77612 @@ -1645,6 +1660,10 @@ no_tcp_socket:
77613 bad_packet:
77614 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77615 } else {
77616 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77617 + if (!grsec_enable_blackhole || (ret == 1 &&
77618 + (skb->dev->flags & IFF_LOOPBACK)))
77619 +#endif
77620 tcp_v6_send_reset(NULL, skb);
77621 }
77622
77623 @@ -1856,7 +1875,13 @@ static void get_openreq6(struct seq_file *seq,
77624 uid,
77625 0, /* non standard timer */
77626 0, /* open_requests have no inode */
77627 - 0, req);
77628 + 0,
77629 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77630 + NULL
77631 +#else
77632 + req
77633 +#endif
77634 + );
77635 }
77636
77637 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77638 @@ -1906,7 +1931,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77639 sock_i_uid(sp),
77640 icsk->icsk_probes_out,
77641 sock_i_ino(sp),
77642 - atomic_read(&sp->sk_refcnt), sp,
77643 + atomic_read(&sp->sk_refcnt),
77644 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77645 + NULL,
77646 +#else
77647 + sp,
77648 +#endif
77649 jiffies_to_clock_t(icsk->icsk_rto),
77650 jiffies_to_clock_t(icsk->icsk_ack.ato),
77651 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77652 @@ -1941,7 +1971,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77653 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77654 tw->tw_substate, 0, 0,
77655 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77656 - atomic_read(&tw->tw_refcnt), tw);
77657 + atomic_read(&tw->tw_refcnt),
77658 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77659 + NULL
77660 +#else
77661 + tw
77662 +#endif
77663 + );
77664 }
77665
77666 static int tcp6_seq_show(struct seq_file *seq, void *v)
77667 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77668 index 07e2bfe..328dae8 100644
77669 --- a/net/ipv6/udp.c
77670 +++ b/net/ipv6/udp.c
77671 @@ -51,6 +51,10 @@
77672 #include <trace/events/skb.h>
77673 #include "udp_impl.h"
77674
77675 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77676 +extern int grsec_enable_blackhole;
77677 +#endif
77678 +
77679 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77680 {
77681 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77682 @@ -395,7 +399,7 @@ try_again:
77683 if (unlikely(err)) {
77684 trace_kfree_skb(skb, udpv6_recvmsg);
77685 if (!peeked) {
77686 - atomic_inc(&sk->sk_drops);
77687 + atomic_inc_unchecked(&sk->sk_drops);
77688 if (is_udp4)
77689 UDP_INC_STATS_USER(sock_net(sk),
77690 UDP_MIB_INERRORS,
77691 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77692 return rc;
77693 drop:
77694 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77695 - atomic_inc(&sk->sk_drops);
77696 + atomic_inc_unchecked(&sk->sk_drops);
77697 kfree_skb(skb);
77698 return -1;
77699 }
77700 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77701 if (likely(skb1 == NULL))
77702 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77703 if (!skb1) {
77704 - atomic_inc(&sk->sk_drops);
77705 + atomic_inc_unchecked(&sk->sk_drops);
77706 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77707 IS_UDPLITE(sk));
77708 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77709 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77710 goto discard;
77711
77712 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77713 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77714 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77715 +#endif
77716 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77717
77718 kfree_skb(skb);
77719 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77720 0, 0L, 0,
77721 sock_i_uid(sp), 0,
77722 sock_i_ino(sp),
77723 - atomic_read(&sp->sk_refcnt), sp,
77724 - atomic_read(&sp->sk_drops));
77725 + atomic_read(&sp->sk_refcnt),
77726 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77727 + NULL,
77728 +#else
77729 + sp,
77730 +#endif
77731 + atomic_read_unchecked(&sp->sk_drops));
77732 }
77733
77734 int udp6_seq_show(struct seq_file *seq, void *v)
77735 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77736 index 6b9d5a0..4dffaf1 100644
77737 --- a/net/irda/ircomm/ircomm_tty.c
77738 +++ b/net/irda/ircomm/ircomm_tty.c
77739 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77740 add_wait_queue(&self->open_wait, &wait);
77741
77742 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77743 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77744 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77745
77746 /* As far as I can see, we protect open_count - Jean II */
77747 spin_lock_irqsave(&self->spinlock, flags);
77748 if (!tty_hung_up_p(filp)) {
77749 extra_count = 1;
77750 - self->open_count--;
77751 + local_dec(&self->open_count);
77752 }
77753 spin_unlock_irqrestore(&self->spinlock, flags);
77754 - self->blocked_open++;
77755 + local_inc(&self->blocked_open);
77756
77757 while (1) {
77758 if (tty->termios->c_cflag & CBAUD) {
77759 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77760 }
77761
77762 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77763 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77764 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77765
77766 schedule();
77767 }
77768 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77769 if (extra_count) {
77770 /* ++ is not atomic, so this should be protected - Jean II */
77771 spin_lock_irqsave(&self->spinlock, flags);
77772 - self->open_count++;
77773 + local_inc(&self->open_count);
77774 spin_unlock_irqrestore(&self->spinlock, flags);
77775 }
77776 - self->blocked_open--;
77777 + local_dec(&self->blocked_open);
77778
77779 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77780 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77781 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77782
77783 if (!retval)
77784 self->flags |= ASYNC_NORMAL_ACTIVE;
77785 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77786 }
77787 /* ++ is not atomic, so this should be protected - Jean II */
77788 spin_lock_irqsave(&self->spinlock, flags);
77789 - self->open_count++;
77790 + local_inc(&self->open_count);
77791
77792 tty->driver_data = self;
77793 self->tty = tty;
77794 spin_unlock_irqrestore(&self->spinlock, flags);
77795
77796 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77797 - self->line, self->open_count);
77798 + self->line, local_read(&self->open_count));
77799
77800 /* Not really used by us, but lets do it anyway */
77801 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77802 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77803 return;
77804 }
77805
77806 - if ((tty->count == 1) && (self->open_count != 1)) {
77807 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77808 /*
77809 * Uh, oh. tty->count is 1, which means that the tty
77810 * structure will be freed. state->count should always
77811 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77812 */
77813 IRDA_DEBUG(0, "%s(), bad serial port count; "
77814 "tty->count is 1, state->count is %d\n", __func__ ,
77815 - self->open_count);
77816 - self->open_count = 1;
77817 + local_read(&self->open_count));
77818 + local_set(&self->open_count, 1);
77819 }
77820
77821 - if (--self->open_count < 0) {
77822 + if (local_dec_return(&self->open_count) < 0) {
77823 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77824 - __func__, self->line, self->open_count);
77825 - self->open_count = 0;
77826 + __func__, self->line, local_read(&self->open_count));
77827 + local_set(&self->open_count, 0);
77828 }
77829 - if (self->open_count) {
77830 + if (local_read(&self->open_count)) {
77831 spin_unlock_irqrestore(&self->spinlock, flags);
77832
77833 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77834 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77835 tty->closing = 0;
77836 self->tty = NULL;
77837
77838 - if (self->blocked_open) {
77839 + if (local_read(&self->blocked_open)) {
77840 if (self->close_delay)
77841 schedule_timeout_interruptible(self->close_delay);
77842 wake_up_interruptible(&self->open_wait);
77843 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77844 spin_lock_irqsave(&self->spinlock, flags);
77845 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77846 self->tty = NULL;
77847 - self->open_count = 0;
77848 + local_set(&self->open_count, 0);
77849 spin_unlock_irqrestore(&self->spinlock, flags);
77850
77851 wake_up_interruptible(&self->open_wait);
77852 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77853 seq_putc(m, '\n');
77854
77855 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77856 - seq_printf(m, "Open count: %d\n", self->open_count);
77857 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77858 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77859 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77860
77861 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77862 index cd6f7a9..e63fe89 100644
77863 --- a/net/iucv/af_iucv.c
77864 +++ b/net/iucv/af_iucv.c
77865 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77866
77867 write_lock_bh(&iucv_sk_list.lock);
77868
77869 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77870 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77871 while (__iucv_get_sock_by_name(name)) {
77872 sprintf(name, "%08x",
77873 - atomic_inc_return(&iucv_sk_list.autobind_name));
77874 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77875 }
77876
77877 write_unlock_bh(&iucv_sk_list.lock);
77878 diff --git a/net/key/af_key.c b/net/key/af_key.c
77879 index 34e4185..8823368 100644
77880 --- a/net/key/af_key.c
77881 +++ b/net/key/af_key.c
77882 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77883 static u32 get_acqseq(void)
77884 {
77885 u32 res;
77886 - static atomic_t acqseq;
77887 + static atomic_unchecked_t acqseq;
77888
77889 do {
77890 - res = atomic_inc_return(&acqseq);
77891 + res = atomic_inc_return_unchecked(&acqseq);
77892 } while (!res);
77893 return res;
77894 }
77895 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77896 index bb61f77..3788d63 100644
77897 --- a/net/mac80211/ieee80211_i.h
77898 +++ b/net/mac80211/ieee80211_i.h
77899 @@ -28,6 +28,7 @@
77900 #include <net/ieee80211_radiotap.h>
77901 #include <net/cfg80211.h>
77902 #include <net/mac80211.h>
77903 +#include <asm/local.h>
77904 #include "key.h"
77905 #include "sta_info.h"
77906 #include "debug.h"
77907 @@ -840,7 +841,7 @@ struct ieee80211_local {
77908 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77909 spinlock_t queue_stop_reason_lock;
77910
77911 - int open_count;
77912 + local_t open_count;
77913 int monitors, cooked_mntrs;
77914 /* number of interfaces with corresponding FIF_ flags */
77915 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77916 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77917 index bfb57dc..77c4b81 100644
77918 --- a/net/mac80211/iface.c
77919 +++ b/net/mac80211/iface.c
77920 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77921 break;
77922 }
77923
77924 - if (local->open_count == 0) {
77925 + if (local_read(&local->open_count) == 0) {
77926 res = drv_start(local);
77927 if (res)
77928 goto err_del_bss;
77929 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77930 break;
77931 }
77932
77933 - if (local->monitors == 0 && local->open_count == 0) {
77934 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77935 res = ieee80211_add_virtual_monitor(local);
77936 if (res)
77937 goto err_stop;
77938 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77939 mutex_unlock(&local->mtx);
77940
77941 if (coming_up)
77942 - local->open_count++;
77943 + local_inc(&local->open_count);
77944
77945 if (hw_reconf_flags)
77946 ieee80211_hw_config(local, hw_reconf_flags);
77947 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77948 err_del_interface:
77949 drv_remove_interface(local, sdata);
77950 err_stop:
77951 - if (!local->open_count)
77952 + if (!local_read(&local->open_count))
77953 drv_stop(local);
77954 err_del_bss:
77955 sdata->bss = NULL;
77956 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77957 }
77958
77959 if (going_down)
77960 - local->open_count--;
77961 + local_dec(&local->open_count);
77962
77963 switch (sdata->vif.type) {
77964 case NL80211_IFTYPE_AP_VLAN:
77965 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77966
77967 ieee80211_recalc_ps(local, -1);
77968
77969 - if (local->open_count == 0) {
77970 + if (local_read(&local->open_count) == 0) {
77971 if (local->ops->napi_poll)
77972 napi_disable(&local->napi);
77973 ieee80211_clear_tx_pending(local);
77974 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77975 }
77976 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77977
77978 - if (local->monitors == local->open_count && local->monitors > 0)
77979 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77980 ieee80211_add_virtual_monitor(local);
77981 }
77982
77983 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77984 index c26e231..8916637 100644
77985 --- a/net/mac80211/main.c
77986 +++ b/net/mac80211/main.c
77987 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77988 local->hw.conf.power_level = power;
77989 }
77990
77991 - if (changed && local->open_count) {
77992 + if (changed && local_read(&local->open_count)) {
77993 ret = drv_config(local, changed);
77994 /*
77995 * Goal:
77996 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77997 index 5c572e7..ecf75ce 100644
77998 --- a/net/mac80211/pm.c
77999 +++ b/net/mac80211/pm.c
78000 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78001 struct ieee80211_sub_if_data *sdata;
78002 struct sta_info *sta;
78003
78004 - if (!local->open_count)
78005 + if (!local_read(&local->open_count))
78006 goto suspend;
78007
78008 ieee80211_scan_cancel(local);
78009 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78010 cancel_work_sync(&local->dynamic_ps_enable_work);
78011 del_timer_sync(&local->dynamic_ps_timer);
78012
78013 - local->wowlan = wowlan && local->open_count;
78014 + local->wowlan = wowlan && local_read(&local->open_count);
78015 if (local->wowlan) {
78016 int err = drv_suspend(local, wowlan);
78017 if (err < 0) {
78018 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78019 drv_remove_interface(local, sdata);
78020
78021 /* stop hardware - this must stop RX */
78022 - if (local->open_count)
78023 + if (local_read(&local->open_count))
78024 ieee80211_stop_device(local);
78025
78026 suspend:
78027 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78028 index 3313c11..bec9f17 100644
78029 --- a/net/mac80211/rate.c
78030 +++ b/net/mac80211/rate.c
78031 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78032
78033 ASSERT_RTNL();
78034
78035 - if (local->open_count)
78036 + if (local_read(&local->open_count))
78037 return -EBUSY;
78038
78039 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78040 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78041 index c97a065..ff61928 100644
78042 --- a/net/mac80211/rc80211_pid_debugfs.c
78043 +++ b/net/mac80211/rc80211_pid_debugfs.c
78044 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78045
78046 spin_unlock_irqrestore(&events->lock, status);
78047
78048 - if (copy_to_user(buf, pb, p))
78049 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78050 return -EFAULT;
78051
78052 return p;
78053 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78054 index 39b82fe..5469ef4 100644
78055 --- a/net/mac80211/util.c
78056 +++ b/net/mac80211/util.c
78057 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78058 }
78059 #endif
78060 /* everything else happens only if HW was up & running */
78061 - if (!local->open_count)
78062 + if (!local_read(&local->open_count))
78063 goto wake_up;
78064
78065 /*
78066 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78067 index c19b214..471fad1 100644
78068 --- a/net/netfilter/Kconfig
78069 +++ b/net/netfilter/Kconfig
78070 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78071
78072 To compile it as a module, choose M here. If unsure, say N.
78073
78074 +config NETFILTER_XT_MATCH_GRADM
78075 + tristate '"gradm" match support'
78076 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78077 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78078 + ---help---
78079 + The gradm match allows to match on grsecurity RBAC being enabled.
78080 + It is useful when iptables rules are applied early on bootup to
78081 + prevent connections to the machine (except from a trusted host)
78082 + while the RBAC system is disabled.
78083 +
78084 config NETFILTER_XT_MATCH_HASHLIMIT
78085 tristate '"hashlimit" match support'
78086 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78087 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78088 index 1c5160f..145ae21 100644
78089 --- a/net/netfilter/Makefile
78090 +++ b/net/netfilter/Makefile
78091 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78092 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78093 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78094 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78095 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78096 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78097 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78098 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78099 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78100 index 1548df9..98ad9b4 100644
78101 --- a/net/netfilter/ipvs/ip_vs_conn.c
78102 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78103 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78104 /* Increase the refcnt counter of the dest */
78105 atomic_inc(&dest->refcnt);
78106
78107 - conn_flags = atomic_read(&dest->conn_flags);
78108 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78109 if (cp->protocol != IPPROTO_UDP)
78110 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78111 flags = cp->flags;
78112 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78113 atomic_set(&cp->refcnt, 1);
78114
78115 atomic_set(&cp->n_control, 0);
78116 - atomic_set(&cp->in_pkts, 0);
78117 + atomic_set_unchecked(&cp->in_pkts, 0);
78118
78119 atomic_inc(&ipvs->conn_count);
78120 if (flags & IP_VS_CONN_F_NO_CPORT)
78121 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78122
78123 /* Don't drop the entry if its number of incoming packets is not
78124 located in [0, 8] */
78125 - i = atomic_read(&cp->in_pkts);
78126 + i = atomic_read_unchecked(&cp->in_pkts);
78127 if (i > 8 || i < 0) return 0;
78128
78129 if (!todrop_rate[i]) return 0;
78130 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78131 index b54ecce..fc5f6cf 100644
78132 --- a/net/netfilter/ipvs/ip_vs_core.c
78133 +++ b/net/netfilter/ipvs/ip_vs_core.c
78134 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78135 ret = cp->packet_xmit(skb, cp, pd->pp);
78136 /* do not touch skb anymore */
78137
78138 - atomic_inc(&cp->in_pkts);
78139 + atomic_inc_unchecked(&cp->in_pkts);
78140 ip_vs_conn_put(cp);
78141 return ret;
78142 }
78143 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78144 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78145 pkts = sysctl_sync_threshold(ipvs);
78146 else
78147 - pkts = atomic_add_return(1, &cp->in_pkts);
78148 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78149
78150 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78151 ip_vs_sync_conn(net, cp, pkts);
78152 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78153 index f51013c..c99ee52 100644
78154 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78155 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78156 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78157 ip_vs_rs_hash(ipvs, dest);
78158 write_unlock_bh(&ipvs->rs_lock);
78159 }
78160 - atomic_set(&dest->conn_flags, conn_flags);
78161 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78162
78163 /* bind the service */
78164 if (!dest->svc) {
78165 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78166 " %-7s %-6d %-10d %-10d\n",
78167 &dest->addr.in6,
78168 ntohs(dest->port),
78169 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78170 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78171 atomic_read(&dest->weight),
78172 atomic_read(&dest->activeconns),
78173 atomic_read(&dest->inactconns));
78174 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78175 "%-7s %-6d %-10d %-10d\n",
78176 ntohl(dest->addr.ip),
78177 ntohs(dest->port),
78178 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78179 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78180 atomic_read(&dest->weight),
78181 atomic_read(&dest->activeconns),
78182 atomic_read(&dest->inactconns));
78183 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78184
78185 entry.addr = dest->addr.ip;
78186 entry.port = dest->port;
78187 - entry.conn_flags = atomic_read(&dest->conn_flags);
78188 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78189 entry.weight = atomic_read(&dest->weight);
78190 entry.u_threshold = dest->u_threshold;
78191 entry.l_threshold = dest->l_threshold;
78192 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78193 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78194 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78195 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78196 - (atomic_read(&dest->conn_flags) &
78197 + (atomic_read_unchecked(&dest->conn_flags) &
78198 IP_VS_CONN_F_FWD_MASK)) ||
78199 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78200 atomic_read(&dest->weight)) ||
78201 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78202 index effa10c..9058928 100644
78203 --- a/net/netfilter/ipvs/ip_vs_sync.c
78204 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78205 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78206 cp = cp->control;
78207 if (cp) {
78208 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78209 - pkts = atomic_add_return(1, &cp->in_pkts);
78210 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78211 else
78212 pkts = sysctl_sync_threshold(ipvs);
78213 ip_vs_sync_conn(net, cp->control, pkts);
78214 @@ -758,7 +758,7 @@ control:
78215 if (!cp)
78216 return;
78217 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78218 - pkts = atomic_add_return(1, &cp->in_pkts);
78219 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78220 else
78221 pkts = sysctl_sync_threshold(ipvs);
78222 goto sloop;
78223 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78224
78225 if (opt)
78226 memcpy(&cp->in_seq, opt, sizeof(*opt));
78227 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78228 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78229 cp->state = state;
78230 cp->old_state = cp->state;
78231 /*
78232 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78233 index 65b616a..760a66b 100644
78234 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78235 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78236 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78237 else
78238 rc = NF_ACCEPT;
78239 /* do not touch skb anymore */
78240 - atomic_inc(&cp->in_pkts);
78241 + atomic_inc_unchecked(&cp->in_pkts);
78242 goto out;
78243 }
78244
78245 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78246 else
78247 rc = NF_ACCEPT;
78248 /* do not touch skb anymore */
78249 - atomic_inc(&cp->in_pkts);
78250 + atomic_inc_unchecked(&cp->in_pkts);
78251 goto out;
78252 }
78253
78254 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78255 index 2ceec64..a5b8a61 100644
78256 --- a/net/netfilter/nf_conntrack_core.c
78257 +++ b/net/netfilter/nf_conntrack_core.c
78258 @@ -1529,6 +1529,10 @@ err_extend:
78259 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78260 #define DYING_NULLS_VAL ((1<<30)+1)
78261
78262 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78263 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78264 +#endif
78265 +
78266 static int nf_conntrack_init_net(struct net *net)
78267 {
78268 int ret;
78269 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78270 goto err_stat;
78271 }
78272
78273 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78274 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78275 +#else
78276 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78277 +#endif
78278 if (!net->ct.slabname) {
78279 ret = -ENOMEM;
78280 goto err_slabname;
78281 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78282 index 5cfb5be..217c6d8 100644
78283 --- a/net/netfilter/nfnetlink_log.c
78284 +++ b/net/netfilter/nfnetlink_log.c
78285 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78286 };
78287
78288 static DEFINE_SPINLOCK(instances_lock);
78289 -static atomic_t global_seq;
78290 +static atomic_unchecked_t global_seq;
78291
78292 #define INSTANCE_BUCKETS 16
78293 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78294 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78295 /* global sequence number */
78296 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78297 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78298 - htonl(atomic_inc_return(&global_seq))))
78299 + htonl(atomic_inc_return_unchecked(&global_seq))))
78300 goto nla_put_failure;
78301
78302 if (data_len) {
78303 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78304 new file mode 100644
78305 index 0000000..6905327
78306 --- /dev/null
78307 +++ b/net/netfilter/xt_gradm.c
78308 @@ -0,0 +1,51 @@
78309 +/*
78310 + * gradm match for netfilter
78311 + * Copyright © Zbigniew Krzystolik, 2010
78312 + *
78313 + * This program is free software; you can redistribute it and/or modify
78314 + * it under the terms of the GNU General Public License; either version
78315 + * 2 or 3 as published by the Free Software Foundation.
78316 + */
78317 +#include <linux/module.h>
78318 +#include <linux/moduleparam.h>
78319 +#include <linux/skbuff.h>
78320 +#include <linux/netfilter/x_tables.h>
78321 +#include <linux/grsecurity.h>
78322 +#include <linux/netfilter/xt_gradm.h>
78323 +
78324 +static bool
78325 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78326 +{
78327 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78328 + bool retval = false;
78329 + if (gr_acl_is_enabled())
78330 + retval = true;
78331 + return retval ^ info->invflags;
78332 +}
78333 +
78334 +static struct xt_match gradm_mt_reg __read_mostly = {
78335 + .name = "gradm",
78336 + .revision = 0,
78337 + .family = NFPROTO_UNSPEC,
78338 + .match = gradm_mt,
78339 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78340 + .me = THIS_MODULE,
78341 +};
78342 +
78343 +static int __init gradm_mt_init(void)
78344 +{
78345 + return xt_register_match(&gradm_mt_reg);
78346 +}
78347 +
78348 +static void __exit gradm_mt_exit(void)
78349 +{
78350 + xt_unregister_match(&gradm_mt_reg);
78351 +}
78352 +
78353 +module_init(gradm_mt_init);
78354 +module_exit(gradm_mt_exit);
78355 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78356 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78357 +MODULE_LICENSE("GPL");
78358 +MODULE_ALIAS("ipt_gradm");
78359 +MODULE_ALIAS("ip6t_gradm");
78360 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78361 index 4fe4fb4..87a89e5 100644
78362 --- a/net/netfilter/xt_statistic.c
78363 +++ b/net/netfilter/xt_statistic.c
78364 @@ -19,7 +19,7 @@
78365 #include <linux/module.h>
78366
78367 struct xt_statistic_priv {
78368 - atomic_t count;
78369 + atomic_unchecked_t count;
78370 } ____cacheline_aligned_in_smp;
78371
78372 MODULE_LICENSE("GPL");
78373 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78374 break;
78375 case XT_STATISTIC_MODE_NTH:
78376 do {
78377 - oval = atomic_read(&info->master->count);
78378 + oval = atomic_read_unchecked(&info->master->count);
78379 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78380 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78381 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78382 if (nval == 0)
78383 ret = !ret;
78384 break;
78385 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78386 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78387 if (info->master == NULL)
78388 return -ENOMEM;
78389 - atomic_set(&info->master->count, info->u.nth.count);
78390 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78391
78392 return 0;
78393 }
78394 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78395 index 5270238..5d37fbc 100644
78396 --- a/net/netlink/af_netlink.c
78397 +++ b/net/netlink/af_netlink.c
78398 @@ -767,7 +767,7 @@ static void netlink_overrun(struct sock *sk)
78399 sk->sk_error_report(sk);
78400 }
78401 }
78402 - atomic_inc(&sk->sk_drops);
78403 + atomic_inc_unchecked(&sk->sk_drops);
78404 }
78405
78406 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78407 @@ -2046,7 +2046,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78408 sk_wmem_alloc_get(s),
78409 nlk->cb,
78410 atomic_read(&s->sk_refcnt),
78411 - atomic_read(&s->sk_drops),
78412 + atomic_read_unchecked(&s->sk_drops),
78413 sock_i_ino(s)
78414 );
78415
78416 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78417 index 7261eb8..44e8ac6 100644
78418 --- a/net/netrom/af_netrom.c
78419 +++ b/net/netrom/af_netrom.c
78420 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78421 struct sock *sk = sock->sk;
78422 struct nr_sock *nr = nr_sk(sk);
78423
78424 + memset(sax, 0, sizeof(*sax));
78425 lock_sock(sk);
78426 if (peer != 0) {
78427 if (sk->sk_state != TCP_ESTABLISHED) {
78428 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78429 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78430 } else {
78431 sax->fsa_ax25.sax25_family = AF_NETROM;
78432 - sax->fsa_ax25.sax25_ndigis = 0;
78433 sax->fsa_ax25.sax25_call = nr->source_addr;
78434 *uaddr_len = sizeof(struct sockaddr_ax25);
78435 }
78436 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78437 index c5c9e2a..4814ab1 100644
78438 --- a/net/packet/af_packet.c
78439 +++ b/net/packet/af_packet.c
78440 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78441
78442 spin_lock(&sk->sk_receive_queue.lock);
78443 po->stats.tp_packets++;
78444 - skb->dropcount = atomic_read(&sk->sk_drops);
78445 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78446 __skb_queue_tail(&sk->sk_receive_queue, skb);
78447 spin_unlock(&sk->sk_receive_queue.lock);
78448 sk->sk_data_ready(sk, skb->len);
78449 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78450 drop_n_acct:
78451 spin_lock(&sk->sk_receive_queue.lock);
78452 po->stats.tp_drops++;
78453 - atomic_inc(&sk->sk_drops);
78454 + atomic_inc_unchecked(&sk->sk_drops);
78455 spin_unlock(&sk->sk_receive_queue.lock);
78456
78457 drop_n_restore:
78458 @@ -2642,6 +2642,7 @@ out:
78459
78460 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78461 {
78462 + struct sock_extended_err ee;
78463 struct sock_exterr_skb *serr;
78464 struct sk_buff *skb, *skb2;
78465 int copied, err;
78466 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78467 sock_recv_timestamp(msg, sk, skb);
78468
78469 serr = SKB_EXT_ERR(skb);
78470 + ee = serr->ee;
78471 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78472 - sizeof(serr->ee), &serr->ee);
78473 + sizeof ee, &ee);
78474
78475 msg->msg_flags |= MSG_ERRQUEUE;
78476 err = copied;
78477 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78478 case PACKET_HDRLEN:
78479 if (len > sizeof(int))
78480 len = sizeof(int);
78481 - if (copy_from_user(&val, optval, len))
78482 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78483 return -EFAULT;
78484 switch (val) {
78485 case TPACKET_V1:
78486 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78487 len = lv;
78488 if (put_user(len, optlen))
78489 return -EFAULT;
78490 - if (copy_to_user(optval, data, len))
78491 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78492 return -EFAULT;
78493 return 0;
78494 }
78495 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78496 index 5a940db..f0b9c12 100644
78497 --- a/net/phonet/af_phonet.c
78498 +++ b/net/phonet/af_phonet.c
78499 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78500 {
78501 struct phonet_protocol *pp;
78502
78503 - if (protocol >= PHONET_NPROTO)
78504 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78505 return NULL;
78506
78507 rcu_read_lock();
78508 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78509 {
78510 int err = 0;
78511
78512 - if (protocol >= PHONET_NPROTO)
78513 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78514 return -EINVAL;
78515
78516 err = proto_register(pp->prot, 1);
78517 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78518 index 576f22c..bc7a71b 100644
78519 --- a/net/phonet/pep.c
78520 +++ b/net/phonet/pep.c
78521 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78522
78523 case PNS_PEP_CTRL_REQ:
78524 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78525 - atomic_inc(&sk->sk_drops);
78526 + atomic_inc_unchecked(&sk->sk_drops);
78527 break;
78528 }
78529 __skb_pull(skb, 4);
78530 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78531 }
78532
78533 if (pn->rx_credits == 0) {
78534 - atomic_inc(&sk->sk_drops);
78535 + atomic_inc_unchecked(&sk->sk_drops);
78536 err = -ENOBUFS;
78537 break;
78538 }
78539 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78540 }
78541
78542 if (pn->rx_credits == 0) {
78543 - atomic_inc(&sk->sk_drops);
78544 + atomic_inc_unchecked(&sk->sk_drops);
78545 err = NET_RX_DROP;
78546 break;
78547 }
78548 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78549 index 0acc943..c727611 100644
78550 --- a/net/phonet/socket.c
78551 +++ b/net/phonet/socket.c
78552 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78553 pn->resource, sk->sk_state,
78554 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78555 sock_i_uid(sk), sock_i_ino(sk),
78556 - atomic_read(&sk->sk_refcnt), sk,
78557 - atomic_read(&sk->sk_drops), &len);
78558 + atomic_read(&sk->sk_refcnt),
78559 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78560 + NULL,
78561 +#else
78562 + sk,
78563 +#endif
78564 + atomic_read_unchecked(&sk->sk_drops), &len);
78565 }
78566 seq_printf(seq, "%*s\n", 127 - len, "");
78567 return 0;
78568 diff --git a/net/rds/cong.c b/net/rds/cong.c
78569 index e5b65ac..f3b6fb7 100644
78570 --- a/net/rds/cong.c
78571 +++ b/net/rds/cong.c
78572 @@ -78,7 +78,7 @@
78573 * finds that the saved generation number is smaller than the global generation
78574 * number, it wakes up the process.
78575 */
78576 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78577 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78578
78579 /*
78580 * Congestion monitoring
78581 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78582 rdsdebug("waking map %p for %pI4\n",
78583 map, &map->m_addr);
78584 rds_stats_inc(s_cong_update_received);
78585 - atomic_inc(&rds_cong_generation);
78586 + atomic_inc_unchecked(&rds_cong_generation);
78587 if (waitqueue_active(&map->m_waitq))
78588 wake_up(&map->m_waitq);
78589 if (waitqueue_active(&rds_poll_waitq))
78590 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78591
78592 int rds_cong_updated_since(unsigned long *recent)
78593 {
78594 - unsigned long gen = atomic_read(&rds_cong_generation);
78595 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78596
78597 if (likely(*recent == gen))
78598 return 0;
78599 diff --git a/net/rds/ib.h b/net/rds/ib.h
78600 index 8d2b3d5..227ec5b 100644
78601 --- a/net/rds/ib.h
78602 +++ b/net/rds/ib.h
78603 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78604 /* sending acks */
78605 unsigned long i_ack_flags;
78606 #ifdef KERNEL_HAS_ATOMIC64
78607 - atomic64_t i_ack_next; /* next ACK to send */
78608 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78609 #else
78610 spinlock_t i_ack_lock; /* protect i_ack_next */
78611 u64 i_ack_next; /* next ACK to send */
78612 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78613 index a1e1162..265e129 100644
78614 --- a/net/rds/ib_cm.c
78615 +++ b/net/rds/ib_cm.c
78616 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78617 /* Clear the ACK state */
78618 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78619 #ifdef KERNEL_HAS_ATOMIC64
78620 - atomic64_set(&ic->i_ack_next, 0);
78621 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78622 #else
78623 ic->i_ack_next = 0;
78624 #endif
78625 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78626 index 8d19491..05a3e65 100644
78627 --- a/net/rds/ib_recv.c
78628 +++ b/net/rds/ib_recv.c
78629 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78630 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78631 int ack_required)
78632 {
78633 - atomic64_set(&ic->i_ack_next, seq);
78634 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78635 if (ack_required) {
78636 smp_mb__before_clear_bit();
78637 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78638 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78639 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78640 smp_mb__after_clear_bit();
78641
78642 - return atomic64_read(&ic->i_ack_next);
78643 + return atomic64_read_unchecked(&ic->i_ack_next);
78644 }
78645 #endif
78646
78647 diff --git a/net/rds/iw.h b/net/rds/iw.h
78648 index 04ce3b1..48119a6 100644
78649 --- a/net/rds/iw.h
78650 +++ b/net/rds/iw.h
78651 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78652 /* sending acks */
78653 unsigned long i_ack_flags;
78654 #ifdef KERNEL_HAS_ATOMIC64
78655 - atomic64_t i_ack_next; /* next ACK to send */
78656 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78657 #else
78658 spinlock_t i_ack_lock; /* protect i_ack_next */
78659 u64 i_ack_next; /* next ACK to send */
78660 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78661 index a91e1db..cf3053f 100644
78662 --- a/net/rds/iw_cm.c
78663 +++ b/net/rds/iw_cm.c
78664 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78665 /* Clear the ACK state */
78666 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78667 #ifdef KERNEL_HAS_ATOMIC64
78668 - atomic64_set(&ic->i_ack_next, 0);
78669 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78670 #else
78671 ic->i_ack_next = 0;
78672 #endif
78673 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78674 index 4503335..db566b4 100644
78675 --- a/net/rds/iw_recv.c
78676 +++ b/net/rds/iw_recv.c
78677 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78678 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78679 int ack_required)
78680 {
78681 - atomic64_set(&ic->i_ack_next, seq);
78682 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78683 if (ack_required) {
78684 smp_mb__before_clear_bit();
78685 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78686 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78687 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78688 smp_mb__after_clear_bit();
78689
78690 - return atomic64_read(&ic->i_ack_next);
78691 + return atomic64_read_unchecked(&ic->i_ack_next);
78692 }
78693 #endif
78694
78695 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78696 index edac9ef..16bcb98 100644
78697 --- a/net/rds/tcp.c
78698 +++ b/net/rds/tcp.c
78699 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78700 int val = 1;
78701
78702 set_fs(KERNEL_DS);
78703 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78704 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78705 sizeof(val));
78706 set_fs(oldfs);
78707 }
78708 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78709 index 1b4fd68..2234175 100644
78710 --- a/net/rds/tcp_send.c
78711 +++ b/net/rds/tcp_send.c
78712 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78713
78714 oldfs = get_fs();
78715 set_fs(KERNEL_DS);
78716 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78717 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78718 sizeof(val));
78719 set_fs(oldfs);
78720 }
78721 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78722 index 05996d0..5a1dfe0 100644
78723 --- a/net/rxrpc/af_rxrpc.c
78724 +++ b/net/rxrpc/af_rxrpc.c
78725 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78726 __be32 rxrpc_epoch;
78727
78728 /* current debugging ID */
78729 -atomic_t rxrpc_debug_id;
78730 +atomic_unchecked_t rxrpc_debug_id;
78731
78732 /* count of skbs currently in use */
78733 atomic_t rxrpc_n_skbs;
78734 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78735 index e4d9cbc..b229649 100644
78736 --- a/net/rxrpc/ar-ack.c
78737 +++ b/net/rxrpc/ar-ack.c
78738 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78739
78740 _enter("{%d,%d,%d,%d},",
78741 call->acks_hard, call->acks_unacked,
78742 - atomic_read(&call->sequence),
78743 + atomic_read_unchecked(&call->sequence),
78744 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78745
78746 stop = 0;
78747 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78748
78749 /* each Tx packet has a new serial number */
78750 sp->hdr.serial =
78751 - htonl(atomic_inc_return(&call->conn->serial));
78752 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78753
78754 hdr = (struct rxrpc_header *) txb->head;
78755 hdr->serial = sp->hdr.serial;
78756 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78757 */
78758 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78759 {
78760 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78761 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78762 }
78763
78764 /*
78765 @@ -629,7 +629,7 @@ process_further:
78766
78767 latest = ntohl(sp->hdr.serial);
78768 hard = ntohl(ack.firstPacket);
78769 - tx = atomic_read(&call->sequence);
78770 + tx = atomic_read_unchecked(&call->sequence);
78771
78772 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78773 latest,
78774 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78775 goto maybe_reschedule;
78776
78777 send_ACK_with_skew:
78778 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78779 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78780 ntohl(ack.serial));
78781 send_ACK:
78782 mtu = call->conn->trans->peer->if_mtu;
78783 @@ -1173,7 +1173,7 @@ send_ACK:
78784 ackinfo.rxMTU = htonl(5692);
78785 ackinfo.jumbo_max = htonl(4);
78786
78787 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78788 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78789 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78790 ntohl(hdr.serial),
78791 ntohs(ack.maxSkew),
78792 @@ -1191,7 +1191,7 @@ send_ACK:
78793 send_message:
78794 _debug("send message");
78795
78796 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78797 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78798 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78799 send_message_2:
78800
78801 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78802 index a3bbb36..3341fb9 100644
78803 --- a/net/rxrpc/ar-call.c
78804 +++ b/net/rxrpc/ar-call.c
78805 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78806 spin_lock_init(&call->lock);
78807 rwlock_init(&call->state_lock);
78808 atomic_set(&call->usage, 1);
78809 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78810 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78811 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78812
78813 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78814 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78815 index 4106ca9..a338d7a 100644
78816 --- a/net/rxrpc/ar-connection.c
78817 +++ b/net/rxrpc/ar-connection.c
78818 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78819 rwlock_init(&conn->lock);
78820 spin_lock_init(&conn->state_lock);
78821 atomic_set(&conn->usage, 1);
78822 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78823 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78824 conn->avail_calls = RXRPC_MAXCALLS;
78825 conn->size_align = 4;
78826 conn->header_size = sizeof(struct rxrpc_header);
78827 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78828 index e7ed43a..6afa140 100644
78829 --- a/net/rxrpc/ar-connevent.c
78830 +++ b/net/rxrpc/ar-connevent.c
78831 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78832
78833 len = iov[0].iov_len + iov[1].iov_len;
78834
78835 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78836 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78837 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78838
78839 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78840 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78841 index 529572f..c758ca7 100644
78842 --- a/net/rxrpc/ar-input.c
78843 +++ b/net/rxrpc/ar-input.c
78844 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78845 /* track the latest serial number on this connection for ACK packet
78846 * information */
78847 serial = ntohl(sp->hdr.serial);
78848 - hi_serial = atomic_read(&call->conn->hi_serial);
78849 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78850 while (serial > hi_serial)
78851 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78852 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78853 serial);
78854
78855 /* request ACK generation for any ACK or DATA packet that requests
78856 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78857 index a693aca..81e7293 100644
78858 --- a/net/rxrpc/ar-internal.h
78859 +++ b/net/rxrpc/ar-internal.h
78860 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78861 int error; /* error code for local abort */
78862 int debug_id; /* debug ID for printks */
78863 unsigned int call_counter; /* call ID counter */
78864 - atomic_t serial; /* packet serial number counter */
78865 - atomic_t hi_serial; /* highest serial number received */
78866 + atomic_unchecked_t serial; /* packet serial number counter */
78867 + atomic_unchecked_t hi_serial; /* highest serial number received */
78868 u8 avail_calls; /* number of calls available */
78869 u8 size_align; /* data size alignment (for security) */
78870 u8 header_size; /* rxrpc + security header size */
78871 @@ -346,7 +346,7 @@ struct rxrpc_call {
78872 spinlock_t lock;
78873 rwlock_t state_lock; /* lock for state transition */
78874 atomic_t usage;
78875 - atomic_t sequence; /* Tx data packet sequence counter */
78876 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78877 u32 abort_code; /* local/remote abort code */
78878 enum { /* current state of call */
78879 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78880 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78881 */
78882 extern atomic_t rxrpc_n_skbs;
78883 extern __be32 rxrpc_epoch;
78884 -extern atomic_t rxrpc_debug_id;
78885 +extern atomic_unchecked_t rxrpc_debug_id;
78886 extern struct workqueue_struct *rxrpc_workqueue;
78887
78888 /*
78889 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78890 index 87f7135..74d3703 100644
78891 --- a/net/rxrpc/ar-local.c
78892 +++ b/net/rxrpc/ar-local.c
78893 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78894 spin_lock_init(&local->lock);
78895 rwlock_init(&local->services_lock);
78896 atomic_set(&local->usage, 1);
78897 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78898 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78899 memcpy(&local->srx, srx, sizeof(*srx));
78900 }
78901
78902 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78903 index e1ac183..b43e10e 100644
78904 --- a/net/rxrpc/ar-output.c
78905 +++ b/net/rxrpc/ar-output.c
78906 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78907 sp->hdr.cid = call->cid;
78908 sp->hdr.callNumber = call->call_id;
78909 sp->hdr.seq =
78910 - htonl(atomic_inc_return(&call->sequence));
78911 + htonl(atomic_inc_return_unchecked(&call->sequence));
78912 sp->hdr.serial =
78913 - htonl(atomic_inc_return(&conn->serial));
78914 + htonl(atomic_inc_return_unchecked(&conn->serial));
78915 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78916 sp->hdr.userStatus = 0;
78917 sp->hdr.securityIndex = conn->security_ix;
78918 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78919 index bebaa43..2644591 100644
78920 --- a/net/rxrpc/ar-peer.c
78921 +++ b/net/rxrpc/ar-peer.c
78922 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78923 INIT_LIST_HEAD(&peer->error_targets);
78924 spin_lock_init(&peer->lock);
78925 atomic_set(&peer->usage, 1);
78926 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78927 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78928 memcpy(&peer->srx, srx, sizeof(*srx));
78929
78930 rxrpc_assess_MTU_size(peer);
78931 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78932 index 38047f7..9f48511 100644
78933 --- a/net/rxrpc/ar-proc.c
78934 +++ b/net/rxrpc/ar-proc.c
78935 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78936 atomic_read(&conn->usage),
78937 rxrpc_conn_states[conn->state],
78938 key_serial(conn->key),
78939 - atomic_read(&conn->serial),
78940 - atomic_read(&conn->hi_serial));
78941 + atomic_read_unchecked(&conn->serial),
78942 + atomic_read_unchecked(&conn->hi_serial));
78943
78944 return 0;
78945 }
78946 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78947 index 92df566..87ec1bf 100644
78948 --- a/net/rxrpc/ar-transport.c
78949 +++ b/net/rxrpc/ar-transport.c
78950 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78951 spin_lock_init(&trans->client_lock);
78952 rwlock_init(&trans->conn_lock);
78953 atomic_set(&trans->usage, 1);
78954 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78955 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78956
78957 if (peer->srx.transport.family == AF_INET) {
78958 switch (peer->srx.transport_type) {
78959 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78960 index f226709..0e735a8 100644
78961 --- a/net/rxrpc/rxkad.c
78962 +++ b/net/rxrpc/rxkad.c
78963 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78964
78965 len = iov[0].iov_len + iov[1].iov_len;
78966
78967 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78968 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78969 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78970
78971 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78972 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78973
78974 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78975
78976 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78977 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78978 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78979
78980 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78981 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78982 index 1e2eee8..ce3967e 100644
78983 --- a/net/sctp/proc.c
78984 +++ b/net/sctp/proc.c
78985 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78986 seq_printf(seq,
78987 "%8pK %8pK %-3d %-3d %-2d %-4d "
78988 "%4d %8d %8d %7d %5lu %-5d %5d ",
78989 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78990 + assoc, sk,
78991 + sctp_sk(sk)->type, sk->sk_state,
78992 assoc->state, hash,
78993 assoc->assoc_id,
78994 assoc->sndbuf_used,
78995 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78996 index 5e25981..dbda919 100644
78997 --- a/net/sctp/socket.c
78998 +++ b/net/sctp/socket.c
78999 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79000 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79001 if (space_left < addrlen)
79002 return -ENOMEM;
79003 + if (addrlen > sizeof(temp) || addrlen < 0)
79004 + return -EFAULT;
79005 if (copy_to_user(to, &temp, addrlen))
79006 return -EFAULT;
79007 to += addrlen;
79008 diff --git a/net/socket.c b/net/socket.c
79009 index edc3c4a..4b4e4a8 100644
79010 --- a/net/socket.c
79011 +++ b/net/socket.c
79012 @@ -88,6 +88,7 @@
79013 #include <linux/nsproxy.h>
79014 #include <linux/magic.h>
79015 #include <linux/slab.h>
79016 +#include <linux/in.h>
79017
79018 #include <asm/uaccess.h>
79019 #include <asm/unistd.h>
79020 @@ -105,6 +106,8 @@
79021 #include <linux/sockios.h>
79022 #include <linux/atalk.h>
79023
79024 +#include <linux/grsock.h>
79025 +
79026 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79027 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79028 unsigned long nr_segs, loff_t pos);
79029 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79030 &sockfs_dentry_operations, SOCKFS_MAGIC);
79031 }
79032
79033 -static struct vfsmount *sock_mnt __read_mostly;
79034 +struct vfsmount *sock_mnt __read_mostly;
79035
79036 static struct file_system_type sock_fs_type = {
79037 .name = "sockfs",
79038 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79039 return -EAFNOSUPPORT;
79040 if (type < 0 || type >= SOCK_MAX)
79041 return -EINVAL;
79042 + if (protocol < 0)
79043 + return -EINVAL;
79044
79045 /* Compatibility.
79046
79047 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79048 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79049 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79050
79051 + if(!gr_search_socket(family, type, protocol)) {
79052 + retval = -EACCES;
79053 + goto out;
79054 + }
79055 +
79056 + if (gr_handle_sock_all(family, type, protocol)) {
79057 + retval = -EACCES;
79058 + goto out;
79059 + }
79060 +
79061 retval = sock_create(family, type, protocol, &sock);
79062 if (retval < 0)
79063 goto out;
79064 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79065 if (sock) {
79066 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79067 if (err >= 0) {
79068 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79069 + err = -EACCES;
79070 + goto error;
79071 + }
79072 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79073 + if (err)
79074 + goto error;
79075 +
79076 err = security_socket_bind(sock,
79077 (struct sockaddr *)&address,
79078 addrlen);
79079 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79080 (struct sockaddr *)
79081 &address, addrlen);
79082 }
79083 +error:
79084 fput_light(sock->file, fput_needed);
79085 }
79086 return err;
79087 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79088 if ((unsigned int)backlog > somaxconn)
79089 backlog = somaxconn;
79090
79091 + if (gr_handle_sock_server_other(sock->sk)) {
79092 + err = -EPERM;
79093 + goto error;
79094 + }
79095 +
79096 + err = gr_search_listen(sock);
79097 + if (err)
79098 + goto error;
79099 +
79100 err = security_socket_listen(sock, backlog);
79101 if (!err)
79102 err = sock->ops->listen(sock, backlog);
79103
79104 +error:
79105 fput_light(sock->file, fput_needed);
79106 }
79107 return err;
79108 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79109 newsock->type = sock->type;
79110 newsock->ops = sock->ops;
79111
79112 + if (gr_handle_sock_server_other(sock->sk)) {
79113 + err = -EPERM;
79114 + sock_release(newsock);
79115 + goto out_put;
79116 + }
79117 +
79118 + err = gr_search_accept(sock);
79119 + if (err) {
79120 + sock_release(newsock);
79121 + goto out_put;
79122 + }
79123 +
79124 /*
79125 * We don't need try_module_get here, as the listening socket (sock)
79126 * has the protocol module (sock->ops->owner) held.
79127 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79128 fd_install(newfd, newfile);
79129 err = newfd;
79130
79131 + gr_attach_curr_ip(newsock->sk);
79132 +
79133 out_put:
79134 fput_light(sock->file, fput_needed);
79135 out:
79136 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79137 int, addrlen)
79138 {
79139 struct socket *sock;
79140 + struct sockaddr *sck;
79141 struct sockaddr_storage address;
79142 int err, fput_needed;
79143
79144 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79145 if (err < 0)
79146 goto out_put;
79147
79148 + sck = (struct sockaddr *)&address;
79149 +
79150 + if (gr_handle_sock_client(sck)) {
79151 + err = -EACCES;
79152 + goto out_put;
79153 + }
79154 +
79155 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79156 + if (err)
79157 + goto out_put;
79158 +
79159 err =
79160 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79161 if (err)
79162 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79163 * checking falls down on this.
79164 */
79165 if (copy_from_user(ctl_buf,
79166 - (void __user __force *)msg_sys->msg_control,
79167 + (void __force_user *)msg_sys->msg_control,
79168 ctl_len))
79169 goto out_freectl;
79170 msg_sys->msg_control = ctl_buf;
79171 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79172 * kernel msghdr to use the kernel address space)
79173 */
79174
79175 - uaddr = (__force void __user *)msg_sys->msg_name;
79176 + uaddr = (void __force_user *)msg_sys->msg_name;
79177 uaddr_len = COMPAT_NAMELEN(msg);
79178 if (MSG_CMSG_COMPAT & flags) {
79179 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79180 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79181 }
79182
79183 ifr = compat_alloc_user_space(buf_size);
79184 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79185 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79186
79187 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79188 return -EFAULT;
79189 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79190 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79191
79192 if (copy_in_user(rxnfc, compat_rxnfc,
79193 - (void *)(&rxnfc->fs.m_ext + 1) -
79194 - (void *)rxnfc) ||
79195 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79196 + (void __user *)rxnfc) ||
79197 copy_in_user(&rxnfc->fs.ring_cookie,
79198 &compat_rxnfc->fs.ring_cookie,
79199 - (void *)(&rxnfc->fs.location + 1) -
79200 - (void *)&rxnfc->fs.ring_cookie) ||
79201 + (void __user *)(&rxnfc->fs.location + 1) -
79202 + (void __user *)&rxnfc->fs.ring_cookie) ||
79203 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79204 sizeof(rxnfc->rule_cnt)))
79205 return -EFAULT;
79206 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79207
79208 if (convert_out) {
79209 if (copy_in_user(compat_rxnfc, rxnfc,
79210 - (const void *)(&rxnfc->fs.m_ext + 1) -
79211 - (const void *)rxnfc) ||
79212 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79213 + (const void __user *)rxnfc) ||
79214 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79215 &rxnfc->fs.ring_cookie,
79216 - (const void *)(&rxnfc->fs.location + 1) -
79217 - (const void *)&rxnfc->fs.ring_cookie) ||
79218 + (const void __user *)(&rxnfc->fs.location + 1) -
79219 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79220 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79221 sizeof(rxnfc->rule_cnt)))
79222 return -EFAULT;
79223 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79224 old_fs = get_fs();
79225 set_fs(KERNEL_DS);
79226 err = dev_ioctl(net, cmd,
79227 - (struct ifreq __user __force *) &kifr);
79228 + (struct ifreq __force_user *) &kifr);
79229 set_fs(old_fs);
79230
79231 return err;
79232 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79233
79234 old_fs = get_fs();
79235 set_fs(KERNEL_DS);
79236 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79237 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79238 set_fs(old_fs);
79239
79240 if (cmd == SIOCGIFMAP && !err) {
79241 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79242 ret |= __get_user(rtdev, &(ur4->rt_dev));
79243 if (rtdev) {
79244 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79245 - r4.rt_dev = (char __user __force *)devname;
79246 + r4.rt_dev = (char __force_user *)devname;
79247 devname[15] = 0;
79248 } else
79249 r4.rt_dev = NULL;
79250 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79251 int __user *uoptlen;
79252 int err;
79253
79254 - uoptval = (char __user __force *) optval;
79255 - uoptlen = (int __user __force *) optlen;
79256 + uoptval = (char __force_user *) optval;
79257 + uoptlen = (int __force_user *) optlen;
79258
79259 set_fs(KERNEL_DS);
79260 if (level == SOL_SOCKET)
79261 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79262 char __user *uoptval;
79263 int err;
79264
79265 - uoptval = (char __user __force *) optval;
79266 + uoptval = (char __force_user *) optval;
79267
79268 set_fs(KERNEL_DS);
79269 if (level == SOL_SOCKET)
79270 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79271 index 128494e..775d0e0 100644
79272 --- a/net/sunrpc/sched.c
79273 +++ b/net/sunrpc/sched.c
79274 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79275 #ifdef RPC_DEBUG
79276 static void rpc_task_set_debuginfo(struct rpc_task *task)
79277 {
79278 - static atomic_t rpc_pid;
79279 + static atomic_unchecked_t rpc_pid;
79280
79281 - task->tk_pid = atomic_inc_return(&rpc_pid);
79282 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79283 }
79284 #else
79285 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79286 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79287 index 8343737..677025e 100644
79288 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79289 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79290 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79291 static unsigned int min_max_inline = 4096;
79292 static unsigned int max_max_inline = 65536;
79293
79294 -atomic_t rdma_stat_recv;
79295 -atomic_t rdma_stat_read;
79296 -atomic_t rdma_stat_write;
79297 -atomic_t rdma_stat_sq_starve;
79298 -atomic_t rdma_stat_rq_starve;
79299 -atomic_t rdma_stat_rq_poll;
79300 -atomic_t rdma_stat_rq_prod;
79301 -atomic_t rdma_stat_sq_poll;
79302 -atomic_t rdma_stat_sq_prod;
79303 +atomic_unchecked_t rdma_stat_recv;
79304 +atomic_unchecked_t rdma_stat_read;
79305 +atomic_unchecked_t rdma_stat_write;
79306 +atomic_unchecked_t rdma_stat_sq_starve;
79307 +atomic_unchecked_t rdma_stat_rq_starve;
79308 +atomic_unchecked_t rdma_stat_rq_poll;
79309 +atomic_unchecked_t rdma_stat_rq_prod;
79310 +atomic_unchecked_t rdma_stat_sq_poll;
79311 +atomic_unchecked_t rdma_stat_sq_prod;
79312
79313 /* Temporary NFS request map and context caches */
79314 struct kmem_cache *svc_rdma_map_cachep;
79315 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79316 len -= *ppos;
79317 if (len > *lenp)
79318 len = *lenp;
79319 - if (len && copy_to_user(buffer, str_buf, len))
79320 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79321 return -EFAULT;
79322 *lenp = len;
79323 *ppos += len;
79324 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79325 {
79326 .procname = "rdma_stat_read",
79327 .data = &rdma_stat_read,
79328 - .maxlen = sizeof(atomic_t),
79329 + .maxlen = sizeof(atomic_unchecked_t),
79330 .mode = 0644,
79331 .proc_handler = read_reset_stat,
79332 },
79333 {
79334 .procname = "rdma_stat_recv",
79335 .data = &rdma_stat_recv,
79336 - .maxlen = sizeof(atomic_t),
79337 + .maxlen = sizeof(atomic_unchecked_t),
79338 .mode = 0644,
79339 .proc_handler = read_reset_stat,
79340 },
79341 {
79342 .procname = "rdma_stat_write",
79343 .data = &rdma_stat_write,
79344 - .maxlen = sizeof(atomic_t),
79345 + .maxlen = sizeof(atomic_unchecked_t),
79346 .mode = 0644,
79347 .proc_handler = read_reset_stat,
79348 },
79349 {
79350 .procname = "rdma_stat_sq_starve",
79351 .data = &rdma_stat_sq_starve,
79352 - .maxlen = sizeof(atomic_t),
79353 + .maxlen = sizeof(atomic_unchecked_t),
79354 .mode = 0644,
79355 .proc_handler = read_reset_stat,
79356 },
79357 {
79358 .procname = "rdma_stat_rq_starve",
79359 .data = &rdma_stat_rq_starve,
79360 - .maxlen = sizeof(atomic_t),
79361 + .maxlen = sizeof(atomic_unchecked_t),
79362 .mode = 0644,
79363 .proc_handler = read_reset_stat,
79364 },
79365 {
79366 .procname = "rdma_stat_rq_poll",
79367 .data = &rdma_stat_rq_poll,
79368 - .maxlen = sizeof(atomic_t),
79369 + .maxlen = sizeof(atomic_unchecked_t),
79370 .mode = 0644,
79371 .proc_handler = read_reset_stat,
79372 },
79373 {
79374 .procname = "rdma_stat_rq_prod",
79375 .data = &rdma_stat_rq_prod,
79376 - .maxlen = sizeof(atomic_t),
79377 + .maxlen = sizeof(atomic_unchecked_t),
79378 .mode = 0644,
79379 .proc_handler = read_reset_stat,
79380 },
79381 {
79382 .procname = "rdma_stat_sq_poll",
79383 .data = &rdma_stat_sq_poll,
79384 - .maxlen = sizeof(atomic_t),
79385 + .maxlen = sizeof(atomic_unchecked_t),
79386 .mode = 0644,
79387 .proc_handler = read_reset_stat,
79388 },
79389 {
79390 .procname = "rdma_stat_sq_prod",
79391 .data = &rdma_stat_sq_prod,
79392 - .maxlen = sizeof(atomic_t),
79393 + .maxlen = sizeof(atomic_unchecked_t),
79394 .mode = 0644,
79395 .proc_handler = read_reset_stat,
79396 },
79397 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79398 index 41cb63b..c4a1489 100644
79399 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79400 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79401 @@ -501,7 +501,7 @@ next_sge:
79402 svc_rdma_put_context(ctxt, 0);
79403 goto out;
79404 }
79405 - atomic_inc(&rdma_stat_read);
79406 + atomic_inc_unchecked(&rdma_stat_read);
79407
79408 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79409 chl_map->ch[ch_no].count -= read_wr.num_sge;
79410 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79411 dto_q);
79412 list_del_init(&ctxt->dto_q);
79413 } else {
79414 - atomic_inc(&rdma_stat_rq_starve);
79415 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79416 clear_bit(XPT_DATA, &xprt->xpt_flags);
79417 ctxt = NULL;
79418 }
79419 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79420 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79421 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79422 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79423 - atomic_inc(&rdma_stat_recv);
79424 + atomic_inc_unchecked(&rdma_stat_recv);
79425
79426 /* Build up the XDR from the receive buffers. */
79427 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79428 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79429 index 42eb7ba..c887c45 100644
79430 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79431 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79432 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79433 write_wr.wr.rdma.remote_addr = to;
79434
79435 /* Post It */
79436 - atomic_inc(&rdma_stat_write);
79437 + atomic_inc_unchecked(&rdma_stat_write);
79438 if (svc_rdma_send(xprt, &write_wr))
79439 goto err;
79440 return 0;
79441 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79442 index 73b428b..5f3f8f3 100644
79443 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79444 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79445 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79446 return;
79447
79448 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79449 - atomic_inc(&rdma_stat_rq_poll);
79450 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79451
79452 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79453 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79454 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79455 }
79456
79457 if (ctxt)
79458 - atomic_inc(&rdma_stat_rq_prod);
79459 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79460
79461 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79462 /*
79463 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79464 return;
79465
79466 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79467 - atomic_inc(&rdma_stat_sq_poll);
79468 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79469 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79470 if (wc.status != IB_WC_SUCCESS)
79471 /* Close the transport */
79472 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79473 }
79474
79475 if (ctxt)
79476 - atomic_inc(&rdma_stat_sq_prod);
79477 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79478 }
79479
79480 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79481 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79482 spin_lock_bh(&xprt->sc_lock);
79483 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79484 spin_unlock_bh(&xprt->sc_lock);
79485 - atomic_inc(&rdma_stat_sq_starve);
79486 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79487
79488 /* See if we can opportunistically reap SQ WR to make room */
79489 sq_cq_reap(xprt);
79490 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79491 index e3a6e37..be2ea77 100644
79492 --- a/net/sysctl_net.c
79493 +++ b/net/sysctl_net.c
79494 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79495 struct ctl_table *table)
79496 {
79497 /* Allow network administrator to have same access as root. */
79498 - if (capable(CAP_NET_ADMIN)) {
79499 + if (capable_nolog(CAP_NET_ADMIN)) {
79500 int mode = (table->mode >> 6) & 7;
79501 return (mode << 6) | (mode << 3) | mode;
79502 }
79503 diff --git a/net/tipc/link.c b/net/tipc/link.c
79504 index 1c1e615..113e0ae 100644
79505 --- a/net/tipc/link.c
79506 +++ b/net/tipc/link.c
79507 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79508 struct tipc_msg fragm_hdr;
79509 struct sk_buff *buf, *buf_chain, *prev;
79510 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79511 - const unchar *sect_crs;
79512 + const unchar __user *sect_crs;
79513 int curr_sect;
79514 u32 fragm_no;
79515
79516 @@ -1212,7 +1212,7 @@ again:
79517
79518 if (!sect_rest) {
79519 sect_rest = msg_sect[++curr_sect].iov_len;
79520 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79521 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79522 }
79523
79524 if (sect_rest < fragm_rest)
79525 @@ -1231,7 +1231,7 @@ error:
79526 }
79527 } else
79528 skb_copy_to_linear_data_offset(buf, fragm_crs,
79529 - sect_crs, sz);
79530 + (const void __force_kernel *)sect_crs, sz);
79531 sect_crs += sz;
79532 sect_rest -= sz;
79533 fragm_crs += sz;
79534 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79535 index f2db8a8..9245aa4 100644
79536 --- a/net/tipc/msg.c
79537 +++ b/net/tipc/msg.c
79538 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79539 msg_sect[cnt].iov_len);
79540 else
79541 skb_copy_to_linear_data_offset(*buf, pos,
79542 - msg_sect[cnt].iov_base,
79543 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79544 msg_sect[cnt].iov_len);
79545 pos += msg_sect[cnt].iov_len;
79546 }
79547 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79548 index 5ed5965..90abe34 100644
79549 --- a/net/tipc/subscr.c
79550 +++ b/net/tipc/subscr.c
79551 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79552 {
79553 struct iovec msg_sect;
79554
79555 - msg_sect.iov_base = (void *)&sub->evt;
79556 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79557 msg_sect.iov_len = sizeof(struct tipc_event);
79558
79559 sub->evt.event = htohl(event, sub->swap);
79560 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79561 index c5ee4ff..e905948 100644
79562 --- a/net/unix/af_unix.c
79563 +++ b/net/unix/af_unix.c
79564 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79565 err = -ECONNREFUSED;
79566 if (!S_ISSOCK(inode->i_mode))
79567 goto put_fail;
79568 +
79569 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79570 + err = -EACCES;
79571 + goto put_fail;
79572 + }
79573 +
79574 u = unix_find_socket_byinode(inode);
79575 if (!u)
79576 goto put_fail;
79577 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79578 if (u) {
79579 struct dentry *dentry;
79580 dentry = unix_sk(u)->path.dentry;
79581 +
79582 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79583 + err = -EPERM;
79584 + sock_put(u);
79585 + goto fail;
79586 + }
79587 +
79588 if (dentry)
79589 touch_atime(&unix_sk(u)->path);
79590 } else
79591 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79592 */
79593 err = security_path_mknod(&path, dentry, mode, 0);
79594 if (!err) {
79595 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79596 + err = -EACCES;
79597 + goto out;
79598 + }
79599 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79600 if (!err) {
79601 res->mnt = mntget(path.mnt);
79602 res->dentry = dget(dentry);
79603 + gr_handle_create(dentry, path.mnt);
79604 }
79605 }
79606 +out:
79607 done_path_create(&path, dentry);
79608 return err;
79609 }
79610 diff --git a/net/wireless/core.h b/net/wireless/core.h
79611 index bc7430b..35349de 100644
79612 --- a/net/wireless/core.h
79613 +++ b/net/wireless/core.h
79614 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79615 struct mutex mtx;
79616
79617 /* rfkill support */
79618 - struct rfkill_ops rfkill_ops;
79619 + rfkill_ops_no_const rfkill_ops;
79620 struct rfkill *rfkill;
79621 struct work_struct rfkill_sync;
79622
79623 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79624 index b0eb7aa..7d73e82 100644
79625 --- a/net/wireless/wext-core.c
79626 +++ b/net/wireless/wext-core.c
79627 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79628 */
79629
79630 /* Support for very large requests */
79631 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79632 - (user_length > descr->max_tokens)) {
79633 + if (user_length > descr->max_tokens) {
79634 /* Allow userspace to GET more than max so
79635 * we can support any size GET requests.
79636 * There is still a limit : -ENOMEM.
79637 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79638 }
79639 }
79640
79641 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79642 - /*
79643 - * If this is a GET, but not NOMAX, it means that the extra
79644 - * data is not bounded by userspace, but by max_tokens. Thus
79645 - * set the length to max_tokens. This matches the extra data
79646 - * allocation.
79647 - * The driver should fill it with the number of tokens it
79648 - * provided, and it may check iwp->length rather than having
79649 - * knowledge of max_tokens. If the driver doesn't change the
79650 - * iwp->length, this ioctl just copies back max_token tokens
79651 - * filled with zeroes. Hopefully the driver isn't claiming
79652 - * them to be valid data.
79653 - */
79654 - iwp->length = descr->max_tokens;
79655 - }
79656 -
79657 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79658
79659 iwp->length += essid_compat;
79660 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79661 index 387848e..a6667a2 100644
79662 --- a/net/xfrm/xfrm_policy.c
79663 +++ b/net/xfrm/xfrm_policy.c
79664 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79665 {
79666 policy->walk.dead = 1;
79667
79668 - atomic_inc(&policy->genid);
79669 + atomic_inc_unchecked(&policy->genid);
79670
79671 if (del_timer(&policy->timer))
79672 xfrm_pol_put(policy);
79673 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79674 hlist_add_head(&policy->bydst, chain);
79675 xfrm_pol_hold(policy);
79676 net->xfrm.policy_count[dir]++;
79677 - atomic_inc(&flow_cache_genid);
79678 + atomic_inc_unchecked(&flow_cache_genid);
79679 rt_genid_bump(net);
79680 if (delpol)
79681 __xfrm_policy_unlink(delpol, dir);
79682 @@ -1533,7 +1533,7 @@ free_dst:
79683 goto out;
79684 }
79685
79686 -static int inline
79687 +static inline int
79688 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79689 {
79690 if (!*target) {
79691 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79692 return 0;
79693 }
79694
79695 -static int inline
79696 +static inline int
79697 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79698 {
79699 #ifdef CONFIG_XFRM_SUB_POLICY
79700 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79701 #endif
79702 }
79703
79704 -static int inline
79705 +static inline int
79706 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79707 {
79708 #ifdef CONFIG_XFRM_SUB_POLICY
79709 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79710
79711 xdst->num_pols = num_pols;
79712 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79713 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79714 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79715
79716 return xdst;
79717 }
79718 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79719 if (xdst->xfrm_genid != dst->xfrm->genid)
79720 return 0;
79721 if (xdst->num_pols > 0 &&
79722 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79723 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79724 return 0;
79725
79726 mtu = dst_mtu(dst->child);
79727 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79728 sizeof(pol->xfrm_vec[i].saddr));
79729 pol->xfrm_vec[i].encap_family = mp->new_family;
79730 /* flush bundles */
79731 - atomic_inc(&pol->genid);
79732 + atomic_inc_unchecked(&pol->genid);
79733 }
79734 }
79735
79736 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79737 index ff1720d..ed8475e 100644
79738 --- a/scripts/Makefile.build
79739 +++ b/scripts/Makefile.build
79740 @@ -111,7 +111,7 @@ endif
79741 endif
79742
79743 # Do not include host rules unless needed
79744 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79745 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
79746 include scripts/Makefile.host
79747 endif
79748
79749 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79750 index 686cb0d..9d653bf 100644
79751 --- a/scripts/Makefile.clean
79752 +++ b/scripts/Makefile.clean
79753 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79754 __clean-files := $(extra-y) $(always) \
79755 $(targets) $(clean-files) \
79756 $(host-progs) \
79757 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79758 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79759 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79760
79761 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79762
79763 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79764 index 1ac414f..38575f7 100644
79765 --- a/scripts/Makefile.host
79766 +++ b/scripts/Makefile.host
79767 @@ -31,6 +31,8 @@
79768 # Note: Shared libraries consisting of C++ files are not supported
79769
79770 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79771 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79772 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
79773
79774 # C code
79775 # Executables compiled from a single .c file
79776 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79777 # Shared libaries (only .c supported)
79778 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79779 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79780 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79781 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
79782 # Remove .so files from "xxx-objs"
79783 host-cobjs := $(filter-out %.so,$(host-cobjs))
79784 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
79785
79786 -#Object (.o) files used by the shared libaries
79787 +# Object (.o) files used by the shared libaries
79788 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
79789 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
79790
79791 # output directory for programs/.o files
79792 # hostprogs-y := tools/build may have been specified. Retrieve directory
79793 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
79794 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
79795 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
79796 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
79797 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
79798 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
79799 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
79800 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
79801
79802 obj-dirs += $(host-objdirs)
79803 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
79804 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
79805 $(call if_changed_dep,host-cshobjs)
79806
79807 +# Compile .c file, create position independent .o file
79808 +# host-cxxshobjs -> .o
79809 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
79810 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
79811 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
79812 + $(call if_changed_dep,host-cxxshobjs)
79813 +
79814 # Link a shared library, based on position independent .o files
79815 # *.o -> .so shared library (host-cshlib)
79816 quiet_cmd_host-cshlib = HOSTLLD -shared $@
79817 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
79818 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
79819 $(call if_changed,host-cshlib)
79820
79821 +# Link a shared library, based on position independent .o files
79822 +# *.o -> .so shared library (host-cxxshlib)
79823 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
79824 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
79825 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
79826 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
79827 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
79828 + $(call if_changed,host-cxxshlib)
79829 +
79830 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
79831 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
79832 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
79833
79834 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79835 index cb1f50c..cef2a7c 100644
79836 --- a/scripts/basic/fixdep.c
79837 +++ b/scripts/basic/fixdep.c
79838 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79839 /*
79840 * Lookup a value in the configuration string.
79841 */
79842 -static int is_defined_config(const char *name, int len, unsigned int hash)
79843 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79844 {
79845 struct item *aux;
79846
79847 @@ -211,10 +211,10 @@ static void clear_config(void)
79848 /*
79849 * Record the use of a CONFIG_* word.
79850 */
79851 -static void use_config(const char *m, int slen)
79852 +static void use_config(const char *m, unsigned int slen)
79853 {
79854 unsigned int hash = strhash(m, slen);
79855 - int c, i;
79856 + unsigned int c, i;
79857
79858 if (is_defined_config(m, slen, hash))
79859 return;
79860 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79861
79862 static void parse_config_file(const char *map, size_t len)
79863 {
79864 - const int *end = (const int *) (map + len);
79865 + const unsigned int *end = (const unsigned int *) (map + len);
79866 /* start at +1, so that p can never be < map */
79867 - const int *m = (const int *) map + 1;
79868 + const unsigned int *m = (const unsigned int *) map + 1;
79869 const char *p, *q;
79870
79871 for (; m < end; m++) {
79872 @@ -406,7 +406,7 @@ static void print_deps(void)
79873 static void traps(void)
79874 {
79875 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79876 - int *p = (int *)test;
79877 + unsigned int *p = (unsigned int *)test;
79878
79879 if (*p != INT_CONF) {
79880 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79881 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79882 new file mode 100644
79883 index 0000000..008ac1a
79884 --- /dev/null
79885 +++ b/scripts/gcc-plugin.sh
79886 @@ -0,0 +1,17 @@
79887 +#!/bin/bash
79888 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
79889 +#include "gcc-plugin.h"
79890 +#include "tree.h"
79891 +#include "tm.h"
79892 +#include "rtl.h"
79893 +#ifdef ENABLE_BUILD_WITH_CXX
79894 +#warning $2
79895 +#else
79896 +#warning $1
79897 +#endif
79898 +EOF`
79899 +if [ $? -eq 0 ]
79900 +then
79901 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
79902 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
79903 +fi
79904 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
79905 index b3d907e..a4782ab 100644
79906 --- a/scripts/link-vmlinux.sh
79907 +++ b/scripts/link-vmlinux.sh
79908 @@ -152,7 +152,7 @@ else
79909 fi;
79910
79911 # final build of init/
79912 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
79913 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
79914
79915 kallsymso=""
79916 kallsyms_vmlinux=""
79917 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79918 index 7ed6864..b6e90e6 100644
79919 --- a/scripts/mod/file2alias.c
79920 +++ b/scripts/mod/file2alias.c
79921 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79922 unsigned long size, unsigned long id_size,
79923 void *symval)
79924 {
79925 - int i;
79926 + unsigned int i;
79927
79928 if (size % id_size || size < id_size) {
79929 if (cross_build != 0)
79930 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79931 /* USB is special because the bcdDevice can be matched against a numeric range */
79932 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
79933 static void do_usb_entry(struct usb_device_id *id,
79934 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79935 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79936 unsigned char range_lo, unsigned char range_hi,
79937 unsigned char max, struct module *mod)
79938 {
79939 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79940 {
79941 unsigned int devlo, devhi;
79942 unsigned char chi, clo, max;
79943 - int ndigits;
79944 + unsigned int ndigits;
79945
79946 id->match_flags = TO_NATIVE(id->match_flags);
79947 id->idVendor = TO_NATIVE(id->idVendor);
79948 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79949 for (i = 0; i < count; i++) {
79950 const char *id = (char *)devs[i].id;
79951 char acpi_id[sizeof(devs[0].id)];
79952 - int j;
79953 + unsigned int j;
79954
79955 buf_printf(&mod->dev_table_buf,
79956 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79957 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79958
79959 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79960 const char *id = (char *)card->devs[j].id;
79961 - int i2, j2;
79962 + unsigned int i2, j2;
79963 int dup = 0;
79964
79965 if (!id[0])
79966 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79967 /* add an individual alias for every device entry */
79968 if (!dup) {
79969 char acpi_id[sizeof(card->devs[0].id)];
79970 - int k;
79971 + unsigned int k;
79972
79973 buf_printf(&mod->dev_table_buf,
79974 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79975 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79976 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79977 char *alias)
79978 {
79979 - int i, j;
79980 + unsigned int i, j;
79981
79982 sprintf(alias, "dmi*");
79983
79984 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79985 index 68e9f5e..ac7759b 100644
79986 --- a/scripts/mod/modpost.c
79987 +++ b/scripts/mod/modpost.c
79988 @@ -930,6 +930,7 @@ enum mismatch {
79989 ANY_INIT_TO_ANY_EXIT,
79990 ANY_EXIT_TO_ANY_INIT,
79991 EXPORT_TO_INIT_EXIT,
79992 + DATA_TO_TEXT
79993 };
79994
79995 struct sectioncheck {
79996 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
79997 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79998 .mismatch = EXPORT_TO_INIT_EXIT,
79999 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80000 +},
80001 +/* Do not reference code from writable data */
80002 +{
80003 + .fromsec = { DATA_SECTIONS, NULL },
80004 + .tosec = { TEXT_SECTIONS, NULL },
80005 + .mismatch = DATA_TO_TEXT
80006 }
80007 };
80008
80009 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80010 continue;
80011 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80012 continue;
80013 - if (sym->st_value == addr)
80014 - return sym;
80015 /* Find a symbol nearby - addr are maybe negative */
80016 d = sym->st_value - addr;
80017 + if (d == 0)
80018 + return sym;
80019 if (d < 0)
80020 d = addr - sym->st_value;
80021 if (d < distance) {
80022 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80023 tosym, prl_to, prl_to, tosym);
80024 free(prl_to);
80025 break;
80026 + case DATA_TO_TEXT:
80027 +#if 0
80028 + fprintf(stderr,
80029 + "The %s %s:%s references\n"
80030 + "the %s %s:%s%s\n",
80031 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80032 +#endif
80033 + break;
80034 }
80035 fprintf(stderr, "\n");
80036 }
80037 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80038 static void check_sec_ref(struct module *mod, const char *modname,
80039 struct elf_info *elf)
80040 {
80041 - int i;
80042 + unsigned int i;
80043 Elf_Shdr *sechdrs = elf->sechdrs;
80044
80045 /* Walk through all sections */
80046 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80047 va_end(ap);
80048 }
80049
80050 -void buf_write(struct buffer *buf, const char *s, int len)
80051 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80052 {
80053 if (buf->size - buf->pos < len) {
80054 buf->size += len + SZ;
80055 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80056 if (fstat(fileno(file), &st) < 0)
80057 goto close_write;
80058
80059 - if (st.st_size != b->pos)
80060 + if (st.st_size != (off_t)b->pos)
80061 goto close_write;
80062
80063 tmp = NOFAIL(malloc(b->pos));
80064 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80065 index 51207e4..f7d603d 100644
80066 --- a/scripts/mod/modpost.h
80067 +++ b/scripts/mod/modpost.h
80068 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80069
80070 struct buffer {
80071 char *p;
80072 - int pos;
80073 - int size;
80074 + unsigned int pos;
80075 + unsigned int size;
80076 };
80077
80078 void __attribute__((format(printf, 2, 3)))
80079 buf_printf(struct buffer *buf, const char *fmt, ...);
80080
80081 void
80082 -buf_write(struct buffer *buf, const char *s, int len);
80083 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80084
80085 struct module {
80086 struct module *next;
80087 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80088 index 9dfcd6d..099068e 100644
80089 --- a/scripts/mod/sumversion.c
80090 +++ b/scripts/mod/sumversion.c
80091 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80092 goto out;
80093 }
80094
80095 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80096 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80097 warn("writing sum in %s failed: %s\n",
80098 filename, strerror(errno));
80099 goto out;
80100 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80101 index 5c11312..72742b5 100644
80102 --- a/scripts/pnmtologo.c
80103 +++ b/scripts/pnmtologo.c
80104 @@ -237,14 +237,14 @@ static void write_header(void)
80105 fprintf(out, " * Linux logo %s\n", logoname);
80106 fputs(" */\n\n", out);
80107 fputs("#include <linux/linux_logo.h>\n\n", out);
80108 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80109 + fprintf(out, "static unsigned char %s_data[] = {\n",
80110 logoname);
80111 }
80112
80113 static void write_footer(void)
80114 {
80115 fputs("\n};\n\n", out);
80116 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80117 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80118 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80119 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80120 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80121 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80122 fputs("\n};\n\n", out);
80123
80124 /* write logo clut */
80125 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80126 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80127 logoname);
80128 write_hex_cnt = 0;
80129 for (i = 0; i < logo_clutsize; i++) {
80130 diff --git a/security/Kconfig b/security/Kconfig
80131 index e9c6ac7..e7feb0d 100644
80132 --- a/security/Kconfig
80133 +++ b/security/Kconfig
80134 @@ -4,6 +4,896 @@
80135
80136 menu "Security options"
80137
80138 +menu "Grsecurity"
80139 +
80140 + config ARCH_TRACK_EXEC_LIMIT
80141 + bool
80142 +
80143 + config PAX_KERNEXEC_PLUGIN
80144 + bool
80145 +
80146 + config PAX_PER_CPU_PGD
80147 + bool
80148 +
80149 + config TASK_SIZE_MAX_SHIFT
80150 + int
80151 + depends on X86_64
80152 + default 47 if !PAX_PER_CPU_PGD
80153 + default 42 if PAX_PER_CPU_PGD
80154 +
80155 + config PAX_ENABLE_PAE
80156 + bool
80157 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80158 +
80159 + config PAX_USERCOPY_SLABS
80160 + bool
80161 +
80162 +config GRKERNSEC
80163 + bool "Grsecurity"
80164 + select CRYPTO
80165 + select CRYPTO_SHA256
80166 + select PROC_FS
80167 + select STOP_MACHINE
80168 + help
80169 + If you say Y here, you will be able to configure many features
80170 + that will enhance the security of your system. It is highly
80171 + recommended that you say Y here and read through the help
80172 + for each option so that you fully understand the features and
80173 + can evaluate their usefulness for your machine.
80174 +
80175 +choice
80176 + prompt "Configuration Method"
80177 + depends on GRKERNSEC
80178 + default GRKERNSEC_CONFIG_CUSTOM
80179 + help
80180 +
80181 +config GRKERNSEC_CONFIG_AUTO
80182 + bool "Automatic"
80183 + help
80184 + If you choose this configuration method, you'll be able to answer a small
80185 + number of simple questions about how you plan to use this kernel.
80186 + The settings of grsecurity and PaX will be automatically configured for
80187 + the highest commonly-used settings within the provided constraints.
80188 +
80189 + If you require additional configuration, custom changes can still be made
80190 + from the "custom configuration" menu.
80191 +
80192 +config GRKERNSEC_CONFIG_CUSTOM
80193 + bool "Custom"
80194 + help
80195 + If you choose this configuration method, you'll be able to configure all
80196 + grsecurity and PaX settings manually. Via this method, no options are
80197 + automatically enabled.
80198 +
80199 +endchoice
80200 +
80201 +choice
80202 + prompt "Usage Type"
80203 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80204 + default GRKERNSEC_CONFIG_SERVER
80205 + help
80206 +
80207 +config GRKERNSEC_CONFIG_SERVER
80208 + bool "Server"
80209 + help
80210 + Choose this option if you plan to use this kernel on a server.
80211 +
80212 +config GRKERNSEC_CONFIG_DESKTOP
80213 + bool "Desktop"
80214 + help
80215 + Choose this option if you plan to use this kernel on a desktop.
80216 +
80217 +endchoice
80218 +
80219 +choice
80220 + prompt "Virtualization Type"
80221 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80222 + default GRKERNSEC_CONFIG_VIRT_NONE
80223 + help
80224 +
80225 +config GRKERNSEC_CONFIG_VIRT_NONE
80226 + bool "None"
80227 + help
80228 + Choose this option if this kernel will be run on bare metal.
80229 +
80230 +config GRKERNSEC_CONFIG_VIRT_GUEST
80231 + bool "Guest"
80232 + help
80233 + Choose this option if this kernel will be run as a VM guest.
80234 +
80235 +config GRKERNSEC_CONFIG_VIRT_HOST
80236 + bool "Host"
80237 + help
80238 + Choose this option if this kernel will be run as a VM host.
80239 +
80240 +endchoice
80241 +
80242 +choice
80243 + prompt "Virtualization Hardware"
80244 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80245 + help
80246 +
80247 +config GRKERNSEC_CONFIG_VIRT_EPT
80248 + bool "EPT/RVI Processor Support"
80249 + depends on X86
80250 + help
80251 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80252 + hardware virtualization. This allows for additional kernel hardening protections
80253 + to operate without additional performance impact.
80254 +
80255 + To see if your Intel processor supports EPT, see:
80256 + http://ark.intel.com/Products/VirtualizationTechnology
80257 + (Most Core i3/5/7 support EPT)
80258 +
80259 + To see if your AMD processor supports RVI, see:
80260 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80261 +
80262 +config GRKERNSEC_CONFIG_VIRT_SOFT
80263 + bool "First-gen/No Hardware Virtualization"
80264 + help
80265 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80266 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80267 +
80268 +endchoice
80269 +
80270 +choice
80271 + prompt "Virtualization Software"
80272 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80273 + help
80274 +
80275 +config GRKERNSEC_CONFIG_VIRT_XEN
80276 + bool "Xen"
80277 + help
80278 + Choose this option if this kernel is running as a Xen guest or host.
80279 +
80280 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80281 + bool "VMWare"
80282 + help
80283 + Choose this option if this kernel is running as a VMWare guest or host.
80284 +
80285 +config GRKERNSEC_CONFIG_VIRT_KVM
80286 + bool "KVM"
80287 + help
80288 + Choose this option if this kernel is running as a KVM guest or host.
80289 +
80290 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80291 + bool "VirtualBox"
80292 + help
80293 + Choose this option if this kernel is running as a VirtualBox guest or host.
80294 +
80295 +endchoice
80296 +
80297 +choice
80298 + prompt "Required Priorities"
80299 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80300 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80301 + help
80302 +
80303 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80304 + bool "Performance"
80305 + help
80306 + Choose this option if performance is of highest priority for this deployment
80307 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80308 + and freed memory sanitizing will be disabled.
80309 +
80310 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80311 + bool "Security"
80312 + help
80313 + Choose this option if security is of highest priority for this deployment of
80314 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80315 + be enabled for this kernel. In a worst-case scenario, these features can
80316 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80317 +
80318 +endchoice
80319 +
80320 +menu "Default Special Groups"
80321 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80322 +
80323 +config GRKERNSEC_PROC_GID
80324 + int "GID exempted from /proc restrictions"
80325 + default 1001
80326 + help
80327 + Setting this GID determines which group will be exempted from
80328 + grsecurity's /proc restrictions, allowing users of the specified
80329 + group to view network statistics and the existence of other users'
80330 + processes on the system. This GID may also be chosen at boot time
80331 + via "grsec_proc_gid=" on the kernel commandline.
80332 +
80333 +config GRKERNSEC_TPE_UNTRUSTED_GID
80334 + int "GID for TPE-untrusted users"
80335 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80336 + default 1005
80337 + help
80338 + Setting this GID determines which group untrusted users should
80339 + be added to. These users will be placed under grsecurity's Trusted Path
80340 + Execution mechanism, preventing them from executing their own binaries.
80341 + The users will only be able to execute binaries in directories owned and
80342 + writable only by the root user. If the sysctl option is enabled, a sysctl
80343 + option with name "tpe_gid" is created.
80344 +
80345 +config GRKERNSEC_TPE_TRUSTED_GID
80346 + int "GID for TPE-trusted users"
80347 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80348 + default 1005
80349 + help
80350 + Setting this GID determines what group TPE restrictions will be
80351 + *disabled* for. If the sysctl option is enabled, a sysctl option
80352 + with name "tpe_gid" is created.
80353 +
80354 +config GRKERNSEC_SYMLINKOWN_GID
80355 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80356 + depends on GRKERNSEC_CONFIG_SERVER
80357 + default 1006
80358 + help
80359 + Setting this GID determines what group kernel-enforced
80360 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80361 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80362 +
80363 +
80364 +endmenu
80365 +
80366 +menu "Customize Configuration"
80367 +depends on GRKERNSEC
80368 +
80369 +menu "PaX"
80370 +
80371 +config PAX
80372 + bool "Enable various PaX features"
80373 + default y if GRKERNSEC_CONFIG_AUTO
80374 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80375 + help
80376 + This allows you to enable various PaX features. PaX adds
80377 + intrusion prevention mechanisms to the kernel that reduce
80378 + the risks posed by exploitable memory corruption bugs.
80379 +
80380 +menu "PaX Control"
80381 + depends on PAX
80382 +
80383 +config PAX_SOFTMODE
80384 + bool 'Support soft mode'
80385 + help
80386 + Enabling this option will allow you to run PaX in soft mode, that
80387 + is, PaX features will not be enforced by default, only on executables
80388 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80389 + support as they are the only way to mark executables for soft mode use.
80390 +
80391 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80392 + line option on boot. Furthermore you can control various PaX features
80393 + at runtime via the entries in /proc/sys/kernel/pax.
80394 +
80395 +config PAX_EI_PAX
80396 + bool 'Use legacy ELF header marking'
80397 + default y if GRKERNSEC_CONFIG_AUTO
80398 + help
80399 + Enabling this option will allow you to control PaX features on
80400 + a per executable basis via the 'chpax' utility available at
80401 + http://pax.grsecurity.net/. The control flags will be read from
80402 + an otherwise reserved part of the ELF header. This marking has
80403 + numerous drawbacks (no support for soft-mode, toolchain does not
80404 + know about the non-standard use of the ELF header) therefore it
80405 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80406 + support.
80407 +
80408 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80409 + support as well, they will override the legacy EI_PAX marks.
80410 +
80411 + If you enable none of the marking options then all applications
80412 + will run with PaX enabled on them by default.
80413 +
80414 +config PAX_PT_PAX_FLAGS
80415 + bool 'Use ELF program header marking'
80416 + default y if GRKERNSEC_CONFIG_AUTO
80417 + help
80418 + Enabling this option will allow you to control PaX features on
80419 + a per executable basis via the 'paxctl' utility available at
80420 + http://pax.grsecurity.net/. The control flags will be read from
80421 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80422 + has the benefits of supporting both soft mode and being fully
80423 + integrated into the toolchain (the binutils patch is available
80424 + from http://pax.grsecurity.net).
80425 +
80426 + Note that if you enable the legacy EI_PAX marking support as well,
80427 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80428 +
80429 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80430 + must make sure that the marks are the same if a binary has both marks.
80431 +
80432 + If you enable none of the marking options then all applications
80433 + will run with PaX enabled on them by default.
80434 +
80435 +config PAX_XATTR_PAX_FLAGS
80436 + bool 'Use filesystem extended attributes marking'
80437 + default y if GRKERNSEC_CONFIG_AUTO
80438 + select CIFS_XATTR if CIFS
80439 + select EXT2_FS_XATTR if EXT2_FS
80440 + select EXT3_FS_XATTR if EXT3_FS
80441 + select EXT4_FS_XATTR if EXT4_FS
80442 + select JFFS2_FS_XATTR if JFFS2_FS
80443 + select REISERFS_FS_XATTR if REISERFS_FS
80444 + select SQUASHFS_XATTR if SQUASHFS
80445 + select TMPFS_XATTR if TMPFS
80446 + select UBIFS_FS_XATTR if UBIFS_FS
80447 + help
80448 + Enabling this option will allow you to control PaX features on
80449 + a per executable basis via the 'setfattr' utility. The control
80450 + flags will be read from the user.pax.flags extended attribute of
80451 + the file. This marking has the benefit of supporting binary-only
80452 + applications that self-check themselves (e.g., skype) and would
80453 + not tolerate chpax/paxctl changes. The main drawback is that
80454 + extended attributes are not supported by some filesystems (e.g.,
80455 + isofs, udf, vfat) so copying files through such filesystems will
80456 + lose the extended attributes and these PaX markings.
80457 +
80458 + Note that if you enable the legacy EI_PAX marking support as well,
80459 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80460 +
80461 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80462 + must make sure that the marks are the same if a binary has both marks.
80463 +
80464 + If you enable none of the marking options then all applications
80465 + will run with PaX enabled on them by default.
80466 +
80467 +choice
80468 + prompt 'MAC system integration'
80469 + default PAX_HAVE_ACL_FLAGS
80470 + help
80471 + Mandatory Access Control systems have the option of controlling
80472 + PaX flags on a per executable basis, choose the method supported
80473 + by your particular system.
80474 +
80475 + - "none": if your MAC system does not interact with PaX,
80476 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80477 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80478 +
80479 + NOTE: this option is for developers/integrators only.
80480 +
80481 + config PAX_NO_ACL_FLAGS
80482 + bool 'none'
80483 +
80484 + config PAX_HAVE_ACL_FLAGS
80485 + bool 'direct'
80486 +
80487 + config PAX_HOOK_ACL_FLAGS
80488 + bool 'hook'
80489 +endchoice
80490 +
80491 +endmenu
80492 +
80493 +menu "Non-executable pages"
80494 + depends on PAX
80495 +
80496 +config PAX_NOEXEC
80497 + bool "Enforce non-executable pages"
80498 + default y if GRKERNSEC_CONFIG_AUTO
80499 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80500 + help
80501 + By design some architectures do not allow for protecting memory
80502 + pages against execution or even if they do, Linux does not make
80503 + use of this feature. In practice this means that if a page is
80504 + readable (such as the stack or heap) it is also executable.
80505 +
80506 + There is a well known exploit technique that makes use of this
80507 + fact and a common programming mistake where an attacker can
80508 + introduce code of his choice somewhere in the attacked program's
80509 + memory (typically the stack or the heap) and then execute it.
80510 +
80511 + If the attacked program was running with different (typically
80512 + higher) privileges than that of the attacker, then he can elevate
80513 + his own privilege level (e.g. get a root shell, write to files for
80514 + which he does not have write access to, etc).
80515 +
80516 + Enabling this option will let you choose from various features
80517 + that prevent the injection and execution of 'foreign' code in
80518 + a program.
80519 +
80520 + This will also break programs that rely on the old behaviour and
80521 + expect that dynamically allocated memory via the malloc() family
80522 + of functions is executable (which it is not). Notable examples
80523 + are the XFree86 4.x server, the java runtime and wine.
80524 +
80525 +config PAX_PAGEEXEC
80526 + bool "Paging based non-executable pages"
80527 + default y if GRKERNSEC_CONFIG_AUTO
80528 + 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)
80529 + select S390_SWITCH_AMODE if S390
80530 + select S390_EXEC_PROTECT if S390
80531 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80532 + help
80533 + This implementation is based on the paging feature of the CPU.
80534 + On i386 without hardware non-executable bit support there is a
80535 + variable but usually low performance impact, however on Intel's
80536 + P4 core based CPUs it is very high so you should not enable this
80537 + for kernels meant to be used on such CPUs.
80538 +
80539 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80540 + with hardware non-executable bit support there is no performance
80541 + impact, on ppc the impact is negligible.
80542 +
80543 + Note that several architectures require various emulations due to
80544 + badly designed userland ABIs, this will cause a performance impact
80545 + but will disappear as soon as userland is fixed. For example, ppc
80546 + userland MUST have been built with secure-plt by a recent toolchain.
80547 +
80548 +config PAX_SEGMEXEC
80549 + bool "Segmentation based non-executable pages"
80550 + default y if GRKERNSEC_CONFIG_AUTO
80551 + depends on PAX_NOEXEC && X86_32
80552 + help
80553 + This implementation is based on the segmentation feature of the
80554 + CPU and has a very small performance impact, however applications
80555 + will be limited to a 1.5 GB address space instead of the normal
80556 + 3 GB.
80557 +
80558 +config PAX_EMUTRAMP
80559 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80560 + default y if PARISC
80561 + help
80562 + There are some programs and libraries that for one reason or
80563 + another attempt to execute special small code snippets from
80564 + non-executable memory pages. Most notable examples are the
80565 + signal handler return code generated by the kernel itself and
80566 + the GCC trampolines.
80567 +
80568 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80569 + such programs will no longer work under your kernel.
80570 +
80571 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80572 + utilities to enable trampoline emulation for the affected programs
80573 + yet still have the protection provided by the non-executable pages.
80574 +
80575 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80576 + your system will not even boot.
80577 +
80578 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80579 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80580 + for the affected files.
80581 +
80582 + NOTE: enabling this feature *may* open up a loophole in the
80583 + protection provided by non-executable pages that an attacker
80584 + could abuse. Therefore the best solution is to not have any
80585 + files on your system that would require this option. This can
80586 + be achieved by not using libc5 (which relies on the kernel
80587 + signal handler return code) and not using or rewriting programs
80588 + that make use of the nested function implementation of GCC.
80589 + Skilled users can just fix GCC itself so that it implements
80590 + nested function calls in a way that does not interfere with PaX.
80591 +
80592 +config PAX_EMUSIGRT
80593 + bool "Automatically emulate sigreturn trampolines"
80594 + depends on PAX_EMUTRAMP && PARISC
80595 + default y
80596 + help
80597 + Enabling this option will have the kernel automatically detect
80598 + and emulate signal return trampolines executing on the stack
80599 + that would otherwise lead to task termination.
80600 +
80601 + This solution is intended as a temporary one for users with
80602 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80603 + Modula-3 runtime, etc) or executables linked to such, basically
80604 + everything that does not specify its own SA_RESTORER function in
80605 + normal executable memory like glibc 2.1+ does.
80606 +
80607 + On parisc you MUST enable this option, otherwise your system will
80608 + not even boot.
80609 +
80610 + NOTE: this feature cannot be disabled on a per executable basis
80611 + and since it *does* open up a loophole in the protection provided
80612 + by non-executable pages, the best solution is to not have any
80613 + files on your system that would require this option.
80614 +
80615 +config PAX_MPROTECT
80616 + bool "Restrict mprotect()"
80617 + default y if GRKERNSEC_CONFIG_AUTO
80618 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80619 + help
80620 + Enabling this option will prevent programs from
80621 + - changing the executable status of memory pages that were
80622 + not originally created as executable,
80623 + - making read-only executable pages writable again,
80624 + - creating executable pages from anonymous memory,
80625 + - making read-only-after-relocations (RELRO) data pages writable again.
80626 +
80627 + You should say Y here to complete the protection provided by
80628 + the enforcement of non-executable pages.
80629 +
80630 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80631 + this feature on a per file basis.
80632 +
80633 +config PAX_MPROTECT_COMPAT
80634 + bool "Use legacy/compat protection demoting (read help)"
80635 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80636 + depends on PAX_MPROTECT
80637 + help
80638 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80639 + by sending the proper error code to the application. For some broken
80640 + userland, this can cause problems with Python or other applications. The
80641 + current implementation however allows for applications like clamav to
80642 + detect if JIT compilation/execution is allowed and to fall back gracefully
80643 + to an interpreter-based mode if it does not. While we encourage everyone
80644 + to use the current implementation as-is and push upstream to fix broken
80645 + userland (note that the RWX logging option can assist with this), in some
80646 + environments this may not be possible. Having to disable MPROTECT
80647 + completely on certain binaries reduces the security benefit of PaX,
80648 + so this option is provided for those environments to revert to the old
80649 + behavior.
80650 +
80651 +config PAX_ELFRELOCS
80652 + bool "Allow ELF text relocations (read help)"
80653 + depends on PAX_MPROTECT
80654 + default n
80655 + help
80656 + Non-executable pages and mprotect() restrictions are effective
80657 + in preventing the introduction of new executable code into an
80658 + attacked task's address space. There remain only two venues
80659 + for this kind of attack: if the attacker can execute already
80660 + existing code in the attacked task then he can either have it
80661 + create and mmap() a file containing his code or have it mmap()
80662 + an already existing ELF library that does not have position
80663 + independent code in it and use mprotect() on it to make it
80664 + writable and copy his code there. While protecting against
80665 + the former approach is beyond PaX, the latter can be prevented
80666 + by having only PIC ELF libraries on one's system (which do not
80667 + need to relocate their code). If you are sure this is your case,
80668 + as is the case with all modern Linux distributions, then leave
80669 + this option disabled. You should say 'n' here.
80670 +
80671 +config PAX_ETEXECRELOCS
80672 + bool "Allow ELF ET_EXEC text relocations"
80673 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80674 + select PAX_ELFRELOCS
80675 + default y
80676 + help
80677 + On some architectures there are incorrectly created applications
80678 + that require text relocations and would not work without enabling
80679 + this option. If you are an alpha, ia64 or parisc user, you should
80680 + enable this option and disable it once you have made sure that
80681 + none of your applications need it.
80682 +
80683 +config PAX_EMUPLT
80684 + bool "Automatically emulate ELF PLT"
80685 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80686 + default y
80687 + help
80688 + Enabling this option will have the kernel automatically detect
80689 + and emulate the Procedure Linkage Table entries in ELF files.
80690 + On some architectures such entries are in writable memory, and
80691 + become non-executable leading to task termination. Therefore
80692 + it is mandatory that you enable this option on alpha, parisc,
80693 + sparc and sparc64, otherwise your system would not even boot.
80694 +
80695 + NOTE: this feature *does* open up a loophole in the protection
80696 + provided by the non-executable pages, therefore the proper
80697 + solution is to modify the toolchain to produce a PLT that does
80698 + not need to be writable.
80699 +
80700 +config PAX_DLRESOLVE
80701 + bool 'Emulate old glibc resolver stub'
80702 + depends on PAX_EMUPLT && SPARC
80703 + default n
80704 + help
80705 + This option is needed if userland has an old glibc (before 2.4)
80706 + that puts a 'save' instruction into the runtime generated resolver
80707 + stub that needs special emulation.
80708 +
80709 +config PAX_KERNEXEC
80710 + bool "Enforce non-executable kernel pages"
80711 + 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))
80712 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80713 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80714 + select PAX_KERNEXEC_PLUGIN if X86_64
80715 + help
80716 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80717 + that is, enabling this option will make it harder to inject
80718 + and execute 'foreign' code in kernel memory itself.
80719 +
80720 +choice
80721 + prompt "Return Address Instrumentation Method"
80722 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80723 + depends on PAX_KERNEXEC_PLUGIN
80724 + help
80725 + Select the method used to instrument function pointer dereferences.
80726 + Note that binary modules cannot be instrumented by this approach.
80727 +
80728 + Note that the implementation requires a gcc with plugin support,
80729 + i.e., gcc 4.5 or newer. You may need to install the supporting
80730 + headers explicitly in addition to the normal gcc package.
80731 +
80732 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80733 + bool "bts"
80734 + help
80735 + This method is compatible with binary only modules but has
80736 + a higher runtime overhead.
80737 +
80738 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80739 + bool "or"
80740 + depends on !PARAVIRT
80741 + help
80742 + This method is incompatible with binary only modules but has
80743 + a lower runtime overhead.
80744 +endchoice
80745 +
80746 +config PAX_KERNEXEC_PLUGIN_METHOD
80747 + string
80748 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80749 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80750 + default ""
80751 +
80752 +config PAX_KERNEXEC_MODULE_TEXT
80753 + int "Minimum amount of memory reserved for module code"
80754 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
80755 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80756 + depends on PAX_KERNEXEC && X86_32 && MODULES
80757 + help
80758 + Due to implementation details the kernel must reserve a fixed
80759 + amount of memory for module code at compile time that cannot be
80760 + changed at runtime. Here you can specify the minimum amount
80761 + in MB that will be reserved. Due to the same implementation
80762 + details this size will always be rounded up to the next 2/4 MB
80763 + boundary (depends on PAE) so the actually available memory for
80764 + module code will usually be more than this minimum.
80765 +
80766 + The default 4 MB should be enough for most users but if you have
80767 + an excessive number of modules (e.g., most distribution configs
80768 + compile many drivers as modules) or use huge modules such as
80769 + nvidia's kernel driver, you will need to adjust this amount.
80770 + A good rule of thumb is to look at your currently loaded kernel
80771 + modules and add up their sizes.
80772 +
80773 +endmenu
80774 +
80775 +menu "Address Space Layout Randomization"
80776 + depends on PAX
80777 +
80778 +config PAX_ASLR
80779 + bool "Address Space Layout Randomization"
80780 + default y if GRKERNSEC_CONFIG_AUTO
80781 + help
80782 + Many if not most exploit techniques rely on the knowledge of
80783 + certain addresses in the attacked program. The following options
80784 + will allow the kernel to apply a certain amount of randomization
80785 + to specific parts of the program thereby forcing an attacker to
80786 + guess them in most cases. Any failed guess will most likely crash
80787 + the attacked program which allows the kernel to detect such attempts
80788 + and react on them. PaX itself provides no reaction mechanisms,
80789 + instead it is strongly encouraged that you make use of Nergal's
80790 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80791 + (http://www.grsecurity.net/) built-in crash detection features or
80792 + develop one yourself.
80793 +
80794 + By saying Y here you can choose to randomize the following areas:
80795 + - top of the task's kernel stack
80796 + - top of the task's userland stack
80797 + - base address for mmap() requests that do not specify one
80798 + (this includes all libraries)
80799 + - base address of the main executable
80800 +
80801 + It is strongly recommended to say Y here as address space layout
80802 + randomization has negligible impact on performance yet it provides
80803 + a very effective protection.
80804 +
80805 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80806 + this feature on a per file basis.
80807 +
80808 +config PAX_RANDKSTACK
80809 + bool "Randomize kernel stack base"
80810 + default y if GRKERNSEC_CONFIG_AUTO
80811 + depends on X86_TSC && X86
80812 + help
80813 + By saying Y here the kernel will randomize every task's kernel
80814 + stack on every system call. This will not only force an attacker
80815 + to guess it but also prevent him from making use of possible
80816 + leaked information about it.
80817 +
80818 + Since the kernel stack is a rather scarce resource, randomization
80819 + may cause unexpected stack overflows, therefore you should very
80820 + carefully test your system. Note that once enabled in the kernel
80821 + configuration, this feature cannot be disabled on a per file basis.
80822 +
80823 +config PAX_RANDUSTACK
80824 + bool "Randomize user stack base"
80825 + default y if GRKERNSEC_CONFIG_AUTO
80826 + depends on PAX_ASLR
80827 + help
80828 + By saying Y here the kernel will randomize every task's userland
80829 + stack. The randomization is done in two steps where the second
80830 + one may apply a big amount of shift to the top of the stack and
80831 + cause problems for programs that want to use lots of memory (more
80832 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80833 + For this reason the second step can be controlled by 'chpax' or
80834 + 'paxctl' on a per file basis.
80835 +
80836 +config PAX_RANDMMAP
80837 + bool "Randomize mmap() base"
80838 + default y if GRKERNSEC_CONFIG_AUTO
80839 + depends on PAX_ASLR
80840 + help
80841 + By saying Y here the kernel will use a randomized base address for
80842 + mmap() requests that do not specify one themselves. As a result
80843 + all dynamically loaded libraries will appear at random addresses
80844 + and therefore be harder to exploit by a technique where an attacker
80845 + attempts to execute library code for his purposes (e.g. spawn a
80846 + shell from an exploited program that is running at an elevated
80847 + privilege level).
80848 +
80849 + Furthermore, if a program is relinked as a dynamic ELF file, its
80850 + base address will be randomized as well, completing the full
80851 + randomization of the address space layout. Attacking such programs
80852 + becomes a guess game. You can find an example of doing this at
80853 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80854 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80855 +
80856 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80857 + feature on a per file basis.
80858 +
80859 +endmenu
80860 +
80861 +menu "Miscellaneous hardening features"
80862 +
80863 +config PAX_MEMORY_SANITIZE
80864 + bool "Sanitize all freed memory"
80865 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80866 + depends on !HIBERNATION
80867 + help
80868 + By saying Y here the kernel will erase memory pages as soon as they
80869 + are freed. This in turn reduces the lifetime of data stored in the
80870 + pages, making it less likely that sensitive information such as
80871 + passwords, cryptographic secrets, etc stay in memory for too long.
80872 +
80873 + This is especially useful for programs whose runtime is short, long
80874 + lived processes and the kernel itself benefit from this as long as
80875 + they operate on whole memory pages and ensure timely freeing of pages
80876 + that may hold sensitive information.
80877 +
80878 + The tradeoff is performance impact, on a single CPU system kernel
80879 + compilation sees a 3% slowdown, other systems and workloads may vary
80880 + and you are advised to test this feature on your expected workload
80881 + before deploying it.
80882 +
80883 + Note that this feature does not protect data stored in live pages,
80884 + e.g., process memory swapped to disk may stay there for a long time.
80885 +
80886 +config PAX_MEMORY_STACKLEAK
80887 + bool "Sanitize kernel stack"
80888 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80889 + depends on X86
80890 + help
80891 + By saying Y here the kernel will erase the kernel stack before it
80892 + returns from a system call. This in turn reduces the information
80893 + that a kernel stack leak bug can reveal.
80894 +
80895 + Note that such a bug can still leak information that was put on
80896 + the stack by the current system call (the one eventually triggering
80897 + the bug) but traces of earlier system calls on the kernel stack
80898 + cannot leak anymore.
80899 +
80900 + The tradeoff is performance impact: on a single CPU system kernel
80901 + compilation sees a 1% slowdown, other systems and workloads may vary
80902 + and you are advised to test this feature on your expected workload
80903 + before deploying it.
80904 +
80905 + Note that the full feature requires a gcc with plugin support,
80906 + i.e., gcc 4.5 or newer. You may need to install the supporting
80907 + headers explicitly in addition to the normal gcc package. Using
80908 + older gcc versions means that functions with large enough stack
80909 + frames may leave uninitialized memory behind that may be exposed
80910 + to a later syscall leaking the stack.
80911 +
80912 +config PAX_MEMORY_UDEREF
80913 + bool "Prevent invalid userland pointer dereference"
80914 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
80915 + depends on X86 && !UML_X86 && !XEN
80916 + select PAX_PER_CPU_PGD if X86_64
80917 + help
80918 + By saying Y here the kernel will be prevented from dereferencing
80919 + userland pointers in contexts where the kernel expects only kernel
80920 + pointers. This is both a useful runtime debugging feature and a
80921 + security measure that prevents exploiting a class of kernel bugs.
80922 +
80923 + The tradeoff is that some virtualization solutions may experience
80924 + a huge slowdown and therefore you should not enable this feature
80925 + for kernels meant to run in such environments. Whether a given VM
80926 + solution is affected or not is best determined by simply trying it
80927 + out, the performance impact will be obvious right on boot as this
80928 + mechanism engages from very early on. A good rule of thumb is that
80929 + VMs running on CPUs without hardware virtualization support (i.e.,
80930 + the majority of IA-32 CPUs) will likely experience the slowdown.
80931 +
80932 +config PAX_REFCOUNT
80933 + bool "Prevent various kernel object reference counter overflows"
80934 + default y if GRKERNSEC_CONFIG_AUTO
80935 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80936 + help
80937 + By saying Y here the kernel will detect and prevent overflowing
80938 + various (but not all) kinds of object reference counters. Such
80939 + overflows can normally occur due to bugs only and are often, if
80940 + not always, exploitable.
80941 +
80942 + The tradeoff is that data structures protected by an overflowed
80943 + refcount will never be freed and therefore will leak memory. Note
80944 + that this leak also happens even without this protection but in
80945 + that case the overflow can eventually trigger the freeing of the
80946 + data structure while it is still being used elsewhere, resulting
80947 + in the exploitable situation that this feature prevents.
80948 +
80949 + Since this has a negligible performance impact, you should enable
80950 + this feature.
80951 +
80952 +config PAX_USERCOPY
80953 + bool "Harden heap object copies between kernel and userland"
80954 + default y if GRKERNSEC_CONFIG_AUTO
80955 + depends on X86 || PPC || SPARC || ARM
80956 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80957 + select PAX_USERCOPY_SLABS
80958 + help
80959 + By saying Y here the kernel will enforce the size of heap objects
80960 + when they are copied in either direction between the kernel and
80961 + userland, even if only a part of the heap object is copied.
80962 +
80963 + Specifically, this checking prevents information leaking from the
80964 + kernel heap during kernel to userland copies (if the kernel heap
80965 + object is otherwise fully initialized) and prevents kernel heap
80966 + overflows during userland to kernel copies.
80967 +
80968 + Note that the current implementation provides the strictest bounds
80969 + checks for the SLUB allocator.
80970 +
80971 + Enabling this option also enables per-slab cache protection against
80972 + data in a given cache being copied into/out of via userland
80973 + accessors. Though the whitelist of regions will be reduced over
80974 + time, it notably protects important data structures like task structs.
80975 +
80976 + If frame pointers are enabled on x86, this option will also restrict
80977 + copies into and out of the kernel stack to local variables within a
80978 + single frame.
80979 +
80980 + Since this has a negligible performance impact, you should enable
80981 + this feature.
80982 +
80983 +config PAX_SIZE_OVERFLOW
80984 + bool "Prevent various integer overflows in function size parameters"
80985 + default y if GRKERNSEC_CONFIG_AUTO
80986 + depends on X86
80987 + help
80988 + By saying Y here the kernel recomputes expressions of function
80989 + arguments marked by a size_overflow attribute with double integer
80990 + precision (DImode/TImode for 32/64 bit integer types).
80991 +
80992 + The recomputed argument is checked against TYPE_MAX and an event
80993 + is logged on overflow and the triggering process is killed.
80994 +
80995 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
80996 +
80997 + Note that the implementation requires a gcc with plugin support,
80998 + i.e., gcc 4.5 or newer. You may need to install the supporting
80999 + headers explicitly in addition to the normal gcc package.
81000 +
81001 +config PAX_LATENT_ENTROPY
81002 + bool "Generate some entropy during boot"
81003 + default y if GRKERNSEC_CONFIG_AUTO
81004 + help
81005 + By saying Y here the kernel will instrument early boot code to
81006 + extract some entropy from both original and artificially created
81007 + program state. This will help especially embedded systems where
81008 + there is little 'natural' source of entropy normally. The cost
81009 + is some slowdown of the boot process.
81010 +
81011 + Note that the implementation requires a gcc with plugin support,
81012 + i.e., gcc 4.5 or newer. You may need to install the supporting
81013 + headers explicitly in addition to the normal gcc package.
81014 +
81015 + Note that entropy extracted this way is not cryptographically
81016 + secure!
81017 +
81018 +endmenu
81019 +
81020 +endmenu
81021 +
81022 +source grsecurity/Kconfig
81023 +
81024 +endmenu
81025 +
81026 +endmenu
81027 +
81028 source security/keys/Kconfig
81029
81030 config SECURITY_DMESG_RESTRICT
81031 @@ -103,7 +993,7 @@ config INTEL_TXT
81032 config LSM_MMAP_MIN_ADDR
81033 int "Low address space for LSM to protect from user allocation"
81034 depends on SECURITY && SECURITY_SELINUX
81035 - default 32768 if ARM
81036 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81037 default 65536
81038 help
81039 This is the portion of low virtual memory which should be protected
81040 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81041 index 8ea39aa..8569ac5 100644
81042 --- a/security/apparmor/lsm.c
81043 +++ b/security/apparmor/lsm.c
81044 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81045 return error;
81046 }
81047
81048 -static struct security_operations apparmor_ops = {
81049 +static struct security_operations apparmor_ops __read_only = {
81050 .name = "apparmor",
81051
81052 .ptrace_access_check = apparmor_ptrace_access_check,
81053 diff --git a/security/commoncap.c b/security/commoncap.c
81054 index 6dbae46..d5611fd 100644
81055 --- a/security/commoncap.c
81056 +++ b/security/commoncap.c
81057 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81058 return 0;
81059 }
81060
81061 +/* returns:
81062 + 1 for suid privilege
81063 + 2 for sgid privilege
81064 + 3 for fscap privilege
81065 +*/
81066 +int is_privileged_binary(const struct dentry *dentry)
81067 +{
81068 + struct cpu_vfs_cap_data capdata;
81069 + struct inode *inode = dentry->d_inode;
81070 +
81071 + if (!inode || S_ISDIR(inode->i_mode))
81072 + return 0;
81073 +
81074 + if (inode->i_mode & S_ISUID)
81075 + return 1;
81076 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81077 + return 2;
81078 +
81079 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81080 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81081 + return 3;
81082 + }
81083 +
81084 + return 0;
81085 +}
81086 +
81087 /*
81088 * Attempt to get the on-exec apply capability sets for an executable file from
81089 * its xattrs and, if present, apply them to the proposed credentials being
81090 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81091 const struct cred *cred = current_cred();
81092 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81093
81094 + if (gr_acl_enable_at_secure())
81095 + return 1;
81096 +
81097 if (!uid_eq(cred->uid, root_uid)) {
81098 if (bprm->cap_effective)
81099 return 1;
81100 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81101 index e7c99fd..5b2fa24 100644
81102 --- a/security/integrity/ima/ima.h
81103 +++ b/security/integrity/ima/ima.h
81104 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81105 extern spinlock_t ima_queue_lock;
81106
81107 struct ima_h_table {
81108 - atomic_long_t len; /* number of stored measurements in the list */
81109 - atomic_long_t violations;
81110 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81111 + atomic_long_unchecked_t violations;
81112 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81113 };
81114 extern struct ima_h_table ima_htable;
81115 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81116 index 032ff03..c428a74 100644
81117 --- a/security/integrity/ima/ima_api.c
81118 +++ b/security/integrity/ima/ima_api.c
81119 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81120 int result;
81121
81122 /* can overflow, only indicator */
81123 - atomic_long_inc(&ima_htable.violations);
81124 + atomic_long_inc_unchecked(&ima_htable.violations);
81125
81126 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81127 if (!entry) {
81128 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81129 index 38477c9..87a60c7 100644
81130 --- a/security/integrity/ima/ima_fs.c
81131 +++ b/security/integrity/ima/ima_fs.c
81132 @@ -28,12 +28,12 @@
81133 static int valid_policy = 1;
81134 #define TMPBUFLEN 12
81135 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81136 - loff_t *ppos, atomic_long_t *val)
81137 + loff_t *ppos, atomic_long_unchecked_t *val)
81138 {
81139 char tmpbuf[TMPBUFLEN];
81140 ssize_t len;
81141
81142 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81143 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81144 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81145 }
81146
81147 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81148 index 55a6271..ad829c3 100644
81149 --- a/security/integrity/ima/ima_queue.c
81150 +++ b/security/integrity/ima/ima_queue.c
81151 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81152 INIT_LIST_HEAD(&qe->later);
81153 list_add_tail_rcu(&qe->later, &ima_measurements);
81154
81155 - atomic_long_inc(&ima_htable.len);
81156 + atomic_long_inc_unchecked(&ima_htable.len);
81157 key = ima_hash_key(entry->digest);
81158 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81159 return 0;
81160 diff --git a/security/keys/compat.c b/security/keys/compat.c
81161 index 1c26176..64a1ba2 100644
81162 --- a/security/keys/compat.c
81163 +++ b/security/keys/compat.c
81164 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81165 if (ret == 0)
81166 goto no_payload_free;
81167
81168 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81169 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81170
81171 if (iov != iovstack)
81172 kfree(iov);
81173 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81174 index 3364fbf..1f10f31 100644
81175 --- a/security/keys/keyctl.c
81176 +++ b/security/keys/keyctl.c
81177 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81178 /*
81179 * Copy the iovec data from userspace
81180 */
81181 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81182 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81183 unsigned ioc)
81184 {
81185 for (; ioc > 0; ioc--) {
81186 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81187 * If successful, 0 will be returned.
81188 */
81189 long keyctl_instantiate_key_common(key_serial_t id,
81190 - const struct iovec *payload_iov,
81191 + const struct iovec __user *payload_iov,
81192 unsigned ioc,
81193 size_t plen,
81194 key_serial_t ringid)
81195 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81196 [0].iov_len = plen
81197 };
81198
81199 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81200 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81201 }
81202
81203 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81204 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81205 if (ret == 0)
81206 goto no_payload_free;
81207
81208 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81209 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81210
81211 if (iov != iovstack)
81212 kfree(iov);
81213 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81214 index 81e7852..2b2ecc3 100644
81215 --- a/security/keys/keyring.c
81216 +++ b/security/keys/keyring.c
81217 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81218 ret = -EFAULT;
81219
81220 for (loop = 0; loop < klist->nkeys; loop++) {
81221 + key_serial_t serial;
81222 key = rcu_deref_link_locked(klist, loop,
81223 keyring);
81224 + serial = key->serial;
81225
81226 tmp = sizeof(key_serial_t);
81227 if (tmp > buflen)
81228 tmp = buflen;
81229
81230 - if (copy_to_user(buffer,
81231 - &key->serial,
81232 - tmp) != 0)
81233 + if (copy_to_user(buffer, &serial, tmp))
81234 goto error;
81235
81236 buflen -= tmp;
81237 diff --git a/security/min_addr.c b/security/min_addr.c
81238 index f728728..6457a0c 100644
81239 --- a/security/min_addr.c
81240 +++ b/security/min_addr.c
81241 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81242 */
81243 static void update_mmap_min_addr(void)
81244 {
81245 +#ifndef SPARC
81246 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81247 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81248 mmap_min_addr = dac_mmap_min_addr;
81249 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81250 #else
81251 mmap_min_addr = dac_mmap_min_addr;
81252 #endif
81253 +#endif
81254 }
81255
81256 /*
81257 diff --git a/security/security.c b/security/security.c
81258 index 860aeb3..45765c0 100644
81259 --- a/security/security.c
81260 +++ b/security/security.c
81261 @@ -20,6 +20,7 @@
81262 #include <linux/ima.h>
81263 #include <linux/evm.h>
81264 #include <linux/fsnotify.h>
81265 +#include <linux/mm.h>
81266 #include <linux/mman.h>
81267 #include <linux/mount.h>
81268 #include <linux/personality.h>
81269 @@ -32,8 +33,8 @@
81270 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81271 CONFIG_DEFAULT_SECURITY;
81272
81273 -static struct security_operations *security_ops;
81274 -static struct security_operations default_security_ops = {
81275 +static struct security_operations *security_ops __read_only;
81276 +static struct security_operations default_security_ops __read_only = {
81277 .name = "default",
81278 };
81279
81280 @@ -74,7 +75,9 @@ int __init security_init(void)
81281
81282 void reset_security_ops(void)
81283 {
81284 + pax_open_kernel();
81285 security_ops = &default_security_ops;
81286 + pax_close_kernel();
81287 }
81288
81289 /* Save user chosen LSM */
81290 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81291 index 6c77f63..7496c76 100644
81292 --- a/security/selinux/hooks.c
81293 +++ b/security/selinux/hooks.c
81294 @@ -95,8 +95,6 @@
81295
81296 #define NUM_SEL_MNT_OPTS 5
81297
81298 -extern struct security_operations *security_ops;
81299 -
81300 /* SECMARK reference count */
81301 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81302
81303 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81304
81305 #endif
81306
81307 -static struct security_operations selinux_ops = {
81308 +static struct security_operations selinux_ops __read_only = {
81309 .name = "selinux",
81310
81311 .ptrace_access_check = selinux_ptrace_access_check,
81312 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81313 index 65f67cb..3f141ef 100644
81314 --- a/security/selinux/include/xfrm.h
81315 +++ b/security/selinux/include/xfrm.h
81316 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81317
81318 static inline void selinux_xfrm_notify_policyload(void)
81319 {
81320 - atomic_inc(&flow_cache_genid);
81321 + atomic_inc_unchecked(&flow_cache_genid);
81322 rt_genid_bump(&init_net);
81323 }
81324 #else
81325 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81326 index 8221514..5c4775f 100644
81327 --- a/security/smack/smack_lsm.c
81328 +++ b/security/smack/smack_lsm.c
81329 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81330 return 0;
81331 }
81332
81333 -struct security_operations smack_ops = {
81334 +struct security_operations smack_ops __read_only = {
81335 .name = "smack",
81336
81337 .ptrace_access_check = smack_ptrace_access_check,
81338 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81339 index c2d04a5..e6a1aeb 100644
81340 --- a/security/tomoyo/tomoyo.c
81341 +++ b/security/tomoyo/tomoyo.c
81342 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81343 * tomoyo_security_ops is a "struct security_operations" which is used for
81344 * registering TOMOYO.
81345 */
81346 -static struct security_operations tomoyo_security_ops = {
81347 +static struct security_operations tomoyo_security_ops __read_only = {
81348 .name = "tomoyo",
81349 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81350 .cred_prepare = tomoyo_cred_prepare,
81351 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81352 index 51d6709..1f3dbe2 100644
81353 --- a/security/yama/Kconfig
81354 +++ b/security/yama/Kconfig
81355 @@ -1,6 +1,6 @@
81356 config SECURITY_YAMA
81357 bool "Yama support"
81358 - depends on SECURITY
81359 + depends on SECURITY && !GRKERNSEC
81360 select SECURITYFS
81361 select SECURITY_PATH
81362 default n
81363 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81364 index 4cedc69..e59d8a3 100644
81365 --- a/sound/aoa/codecs/onyx.c
81366 +++ b/sound/aoa/codecs/onyx.c
81367 @@ -54,7 +54,7 @@ struct onyx {
81368 spdif_locked:1,
81369 analog_locked:1,
81370 original_mute:2;
81371 - int open_count;
81372 + local_t open_count;
81373 struct codec_info *codec_info;
81374
81375 /* mutex serializes concurrent access to the device
81376 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81377 struct onyx *onyx = cii->codec_data;
81378
81379 mutex_lock(&onyx->mutex);
81380 - onyx->open_count++;
81381 + local_inc(&onyx->open_count);
81382 mutex_unlock(&onyx->mutex);
81383
81384 return 0;
81385 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81386 struct onyx *onyx = cii->codec_data;
81387
81388 mutex_lock(&onyx->mutex);
81389 - onyx->open_count--;
81390 - if (!onyx->open_count)
81391 + if (local_dec_and_test(&onyx->open_count))
81392 onyx->spdif_locked = onyx->analog_locked = 0;
81393 mutex_unlock(&onyx->mutex);
81394
81395 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81396 index ffd2025..df062c9 100644
81397 --- a/sound/aoa/codecs/onyx.h
81398 +++ b/sound/aoa/codecs/onyx.h
81399 @@ -11,6 +11,7 @@
81400 #include <linux/i2c.h>
81401 #include <asm/pmac_low_i2c.h>
81402 #include <asm/prom.h>
81403 +#include <asm/local.h>
81404
81405 /* PCM3052 register definitions */
81406
81407 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81408 index 08fde00..0bf641a 100644
81409 --- a/sound/core/oss/pcm_oss.c
81410 +++ b/sound/core/oss/pcm_oss.c
81411 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81412 if (in_kernel) {
81413 mm_segment_t fs;
81414 fs = snd_enter_user();
81415 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81416 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81417 snd_leave_user(fs);
81418 } else {
81419 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81420 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81421 }
81422 if (ret != -EPIPE && ret != -ESTRPIPE)
81423 break;
81424 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81425 if (in_kernel) {
81426 mm_segment_t fs;
81427 fs = snd_enter_user();
81428 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81429 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81430 snd_leave_user(fs);
81431 } else {
81432 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81433 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81434 }
81435 if (ret == -EPIPE) {
81436 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81437 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81438 struct snd_pcm_plugin_channel *channels;
81439 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81440 if (!in_kernel) {
81441 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81442 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81443 return -EFAULT;
81444 buf = runtime->oss.buffer;
81445 }
81446 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81447 }
81448 } else {
81449 tmp = snd_pcm_oss_write2(substream,
81450 - (const char __force *)buf,
81451 + (const char __force_kernel *)buf,
81452 runtime->oss.period_bytes, 0);
81453 if (tmp <= 0)
81454 goto err;
81455 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81456 struct snd_pcm_runtime *runtime = substream->runtime;
81457 snd_pcm_sframes_t frames, frames1;
81458 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81459 - char __user *final_dst = (char __force __user *)buf;
81460 + char __user *final_dst = (char __force_user *)buf;
81461 if (runtime->oss.plugin_first) {
81462 struct snd_pcm_plugin_channel *channels;
81463 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81464 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81465 xfer += tmp;
81466 runtime->oss.buffer_used -= tmp;
81467 } else {
81468 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81469 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81470 runtime->oss.period_bytes, 0);
81471 if (tmp <= 0)
81472 goto err;
81473 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81474 size1);
81475 size1 /= runtime->channels; /* frames */
81476 fs = snd_enter_user();
81477 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81478 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81479 snd_leave_user(fs);
81480 }
81481 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81482 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81483 index 91cdf94..4085161 100644
81484 --- a/sound/core/pcm_compat.c
81485 +++ b/sound/core/pcm_compat.c
81486 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81487 int err;
81488
81489 fs = snd_enter_user();
81490 - err = snd_pcm_delay(substream, &delay);
81491 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81492 snd_leave_user(fs);
81493 if (err < 0)
81494 return err;
81495 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81496 index 53b5ada..2db94c8 100644
81497 --- a/sound/core/pcm_native.c
81498 +++ b/sound/core/pcm_native.c
81499 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81500 switch (substream->stream) {
81501 case SNDRV_PCM_STREAM_PLAYBACK:
81502 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81503 - (void __user *)arg);
81504 + (void __force_user *)arg);
81505 break;
81506 case SNDRV_PCM_STREAM_CAPTURE:
81507 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81508 - (void __user *)arg);
81509 + (void __force_user *)arg);
81510 break;
81511 default:
81512 result = -EINVAL;
81513 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81514 index 5cf8d65..912a79c 100644
81515 --- a/sound/core/seq/seq_device.c
81516 +++ b/sound/core/seq/seq_device.c
81517 @@ -64,7 +64,7 @@ struct ops_list {
81518 int argsize; /* argument size */
81519
81520 /* operators */
81521 - struct snd_seq_dev_ops ops;
81522 + struct snd_seq_dev_ops *ops;
81523
81524 /* registred devices */
81525 struct list_head dev_list; /* list of devices */
81526 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81527
81528 mutex_lock(&ops->reg_mutex);
81529 /* copy driver operators */
81530 - ops->ops = *entry;
81531 + ops->ops = entry;
81532 ops->driver |= DRIVER_LOADED;
81533 ops->argsize = argsize;
81534
81535 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81536 dev->name, ops->id, ops->argsize, dev->argsize);
81537 return -EINVAL;
81538 }
81539 - if (ops->ops.init_device(dev) >= 0) {
81540 + if (ops->ops->init_device(dev) >= 0) {
81541 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81542 ops->num_init_devices++;
81543 } else {
81544 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81545 dev->name, ops->id, ops->argsize, dev->argsize);
81546 return -EINVAL;
81547 }
81548 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81549 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81550 dev->status = SNDRV_SEQ_DEVICE_FREE;
81551 dev->driver_data = NULL;
81552 ops->num_init_devices--;
81553 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81554 index 2d5514b..3afae9c 100644
81555 --- a/sound/drivers/mts64.c
81556 +++ b/sound/drivers/mts64.c
81557 @@ -29,6 +29,7 @@
81558 #include <sound/initval.h>
81559 #include <sound/rawmidi.h>
81560 #include <sound/control.h>
81561 +#include <asm/local.h>
81562
81563 #define CARD_NAME "Miditerminal 4140"
81564 #define DRIVER_NAME "MTS64"
81565 @@ -67,7 +68,7 @@ struct mts64 {
81566 struct pardevice *pardev;
81567 int pardev_claimed;
81568
81569 - int open_count;
81570 + local_t open_count;
81571 int current_midi_output_port;
81572 int current_midi_input_port;
81573 u8 mode[MTS64_NUM_INPUT_PORTS];
81574 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81575 {
81576 struct mts64 *mts = substream->rmidi->private_data;
81577
81578 - if (mts->open_count == 0) {
81579 + if (local_read(&mts->open_count) == 0) {
81580 /* We don't need a spinlock here, because this is just called
81581 if the device has not been opened before.
81582 So there aren't any IRQs from the device */
81583 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81584
81585 msleep(50);
81586 }
81587 - ++(mts->open_count);
81588 + local_inc(&mts->open_count);
81589
81590 return 0;
81591 }
81592 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81593 struct mts64 *mts = substream->rmidi->private_data;
81594 unsigned long flags;
81595
81596 - --(mts->open_count);
81597 - if (mts->open_count == 0) {
81598 + if (local_dec_return(&mts->open_count) == 0) {
81599 /* We need the spinlock_irqsave here because we can still
81600 have IRQs at this point */
81601 spin_lock_irqsave(&mts->lock, flags);
81602 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81603
81604 msleep(500);
81605
81606 - } else if (mts->open_count < 0)
81607 - mts->open_count = 0;
81608 + } else if (local_read(&mts->open_count) < 0)
81609 + local_set(&mts->open_count, 0);
81610
81611 return 0;
81612 }
81613 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81614 index b953fb4..1999c01 100644
81615 --- a/sound/drivers/opl4/opl4_lib.c
81616 +++ b/sound/drivers/opl4/opl4_lib.c
81617 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81618 MODULE_DESCRIPTION("OPL4 driver");
81619 MODULE_LICENSE("GPL");
81620
81621 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81622 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81623 {
81624 int timeout = 10;
81625 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81626 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81627 index 8364855..59f2e2b 100644
81628 --- a/sound/drivers/portman2x4.c
81629 +++ b/sound/drivers/portman2x4.c
81630 @@ -48,6 +48,7 @@
81631 #include <sound/initval.h>
81632 #include <sound/rawmidi.h>
81633 #include <sound/control.h>
81634 +#include <asm/local.h>
81635
81636 #define CARD_NAME "Portman 2x4"
81637 #define DRIVER_NAME "portman"
81638 @@ -85,7 +86,7 @@ struct portman {
81639 struct pardevice *pardev;
81640 int pardev_claimed;
81641
81642 - int open_count;
81643 + local_t open_count;
81644 int mode[PORTMAN_NUM_INPUT_PORTS];
81645 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81646 };
81647 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81648 index ea995af..f1bfa37 100644
81649 --- a/sound/firewire/amdtp.c
81650 +++ b/sound/firewire/amdtp.c
81651 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81652 ptr = s->pcm_buffer_pointer + data_blocks;
81653 if (ptr >= pcm->runtime->buffer_size)
81654 ptr -= pcm->runtime->buffer_size;
81655 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81656 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81657
81658 s->pcm_period_pointer += data_blocks;
81659 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81660 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
81661 */
81662 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81663 {
81664 - ACCESS_ONCE(s->source_node_id_field) =
81665 + ACCESS_ONCE_RW(s->source_node_id_field) =
81666 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81667 }
81668 EXPORT_SYMBOL(amdtp_out_stream_update);
81669 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81670 index b680c5e..061b7a0 100644
81671 --- a/sound/firewire/amdtp.h
81672 +++ b/sound/firewire/amdtp.h
81673 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
81674 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81675 struct snd_pcm_substream *pcm)
81676 {
81677 - ACCESS_ONCE(s->pcm) = pcm;
81678 + ACCESS_ONCE_RW(s->pcm) = pcm;
81679 }
81680
81681 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
81682 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81683 index d428ffe..751ef78 100644
81684 --- a/sound/firewire/isight.c
81685 +++ b/sound/firewire/isight.c
81686 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81687 ptr += count;
81688 if (ptr >= runtime->buffer_size)
81689 ptr -= runtime->buffer_size;
81690 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81691 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81692
81693 isight->period_counter += count;
81694 if (isight->period_counter >= runtime->period_size) {
81695 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81696 if (err < 0)
81697 return err;
81698
81699 - ACCESS_ONCE(isight->pcm_active) = true;
81700 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81701
81702 return 0;
81703 }
81704 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81705 {
81706 struct isight *isight = substream->private_data;
81707
81708 - ACCESS_ONCE(isight->pcm_active) = false;
81709 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81710
81711 mutex_lock(&isight->mutex);
81712 isight_stop_streaming(isight);
81713 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81714
81715 switch (cmd) {
81716 case SNDRV_PCM_TRIGGER_START:
81717 - ACCESS_ONCE(isight->pcm_running) = true;
81718 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81719 break;
81720 case SNDRV_PCM_TRIGGER_STOP:
81721 - ACCESS_ONCE(isight->pcm_running) = false;
81722 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81723 break;
81724 default:
81725 return -EINVAL;
81726 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81727 index 7bd5e33..1fcab12 100644
81728 --- a/sound/isa/cmi8330.c
81729 +++ b/sound/isa/cmi8330.c
81730 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81731
81732 struct snd_pcm *pcm;
81733 struct snd_cmi8330_stream {
81734 - struct snd_pcm_ops ops;
81735 + snd_pcm_ops_no_const ops;
81736 snd_pcm_open_callback_t open;
81737 void *private_data; /* sb or wss */
81738 } streams[2];
81739 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81740 index b2b3c01..e1c1e1f 100644
81741 --- a/sound/oss/sb_audio.c
81742 +++ b/sound/oss/sb_audio.c
81743 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
81744 buf16 = (signed short *)(localbuf + localoffs);
81745 while (c)
81746 {
81747 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81748 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81749 if (copy_from_user(lbuf8,
81750 userbuf+useroffs + p,
81751 locallen))
81752 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81753 index 7d8803a..559f8d0 100644
81754 --- a/sound/oss/swarm_cs4297a.c
81755 +++ b/sound/oss/swarm_cs4297a.c
81756 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
81757 {
81758 struct cs4297a_state *s;
81759 u32 pwr, id;
81760 - mm_segment_t fs;
81761 int rval;
81762 #ifndef CONFIG_BCM_CS4297A_CSWARM
81763 u64 cfg;
81764 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
81765 if (!rval) {
81766 char *sb1250_duart_present;
81767
81768 +#if 0
81769 + mm_segment_t fs;
81770 fs = get_fs();
81771 set_fs(KERNEL_DS);
81772 -#if 0
81773 val = SOUND_MASK_LINE;
81774 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81775 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81776 val = initvol[i].vol;
81777 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81778 }
81779 + set_fs(fs);
81780 // cs4297a_write_ac97(s, 0x18, 0x0808);
81781 #else
81782 // cs4297a_write_ac97(s, 0x5e, 0x180);
81783 cs4297a_write_ac97(s, 0x02, 0x0808);
81784 cs4297a_write_ac97(s, 0x18, 0x0808);
81785 #endif
81786 - set_fs(fs);
81787
81788 list_add(&s->list, &cs4297a_devs);
81789
81790 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81791 index e5a7e19..4049063 100644
81792 --- a/sound/pci/hda/hda_codec.h
81793 +++ b/sound/pci/hda/hda_codec.h
81794 @@ -614,7 +614,7 @@ struct hda_bus_ops {
81795 /* notify power-up/down from codec to controller */
81796 void (*pm_notify)(struct hda_bus *bus);
81797 #endif
81798 -};
81799 +} __no_const;
81800
81801 /* template to pass to the bus constructor */
81802 struct hda_bus_template {
81803 @@ -714,6 +714,7 @@ struct hda_codec_ops {
81804 #endif
81805 void (*reboot_notify)(struct hda_codec *codec);
81806 };
81807 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81808
81809 /* record for amp information cache */
81810 struct hda_cache_head {
81811 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
81812 struct snd_pcm_substream *substream);
81813 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81814 struct snd_pcm_substream *substream);
81815 -};
81816 +} __no_const;
81817
81818 /* PCM information for each substream */
81819 struct hda_pcm_stream {
81820 @@ -802,7 +803,7 @@ struct hda_codec {
81821 const char *modelname; /* model name for preset */
81822
81823 /* set by patch */
81824 - struct hda_codec_ops patch_ops;
81825 + hda_codec_ops_no_const patch_ops;
81826
81827 /* PCM to create, set by patch_ops.build_pcms callback */
81828 unsigned int num_pcms;
81829 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81830 index 0da778a..bc38b84 100644
81831 --- a/sound/pci/ice1712/ice1712.h
81832 +++ b/sound/pci/ice1712/ice1712.h
81833 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81834 unsigned int mask_flags; /* total mask bits */
81835 struct snd_akm4xxx_ops {
81836 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81837 - } ops;
81838 + } __no_const ops;
81839 };
81840
81841 struct snd_ice1712_spdif {
81842 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81843 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81844 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81845 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81846 - } ops;
81847 + } __no_const ops;
81848 };
81849
81850
81851 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
81852 index bddc405..2c0733c 100644
81853 --- a/sound/pci/ymfpci/ymfpci.h
81854 +++ b/sound/pci/ymfpci/ymfpci.h
81855 @@ -358,7 +358,7 @@ struct snd_ymfpci {
81856 spinlock_t reg_lock;
81857 spinlock_t voice_lock;
81858 wait_queue_head_t interrupt_sleep;
81859 - atomic_t interrupt_sleep_count;
81860 + atomic_unchecked_t interrupt_sleep_count;
81861 struct snd_info_entry *proc_entry;
81862 const struct firmware *dsp_microcode;
81863 const struct firmware *controller_microcode;
81864 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81865 index 62b2363..ee77972 100644
81866 --- a/sound/pci/ymfpci/ymfpci_main.c
81867 +++ b/sound/pci/ymfpci/ymfpci_main.c
81868 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81869 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81870 break;
81871 }
81872 - if (atomic_read(&chip->interrupt_sleep_count)) {
81873 - atomic_set(&chip->interrupt_sleep_count, 0);
81874 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81875 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81876 wake_up(&chip->interrupt_sleep);
81877 }
81878 __end:
81879 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81880 continue;
81881 init_waitqueue_entry(&wait, current);
81882 add_wait_queue(&chip->interrupt_sleep, &wait);
81883 - atomic_inc(&chip->interrupt_sleep_count);
81884 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81885 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81886 remove_wait_queue(&chip->interrupt_sleep, &wait);
81887 }
81888 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81889 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81890 spin_unlock(&chip->reg_lock);
81891
81892 - if (atomic_read(&chip->interrupt_sleep_count)) {
81893 - atomic_set(&chip->interrupt_sleep_count, 0);
81894 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81895 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81896 wake_up(&chip->interrupt_sleep);
81897 }
81898 }
81899 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81900 spin_lock_init(&chip->reg_lock);
81901 spin_lock_init(&chip->voice_lock);
81902 init_waitqueue_head(&chip->interrupt_sleep);
81903 - atomic_set(&chip->interrupt_sleep_count, 0);
81904 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81905 chip->card = card;
81906 chip->pci = pci;
81907 chip->irq = -1;
81908 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
81909 new file mode 100644
81910 index 0000000..50f2f2f
81911 --- /dev/null
81912 +++ b/tools/gcc/.gitignore
81913 @@ -0,0 +1 @@
81914 +size_overflow_hash.h
81915 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81916 new file mode 100644
81917 index 0000000..1d09b7e
81918 --- /dev/null
81919 +++ b/tools/gcc/Makefile
81920 @@ -0,0 +1,43 @@
81921 +#CC := gcc
81922 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81923 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81924 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81925 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81926 +
81927 +ifeq ($(PLUGINCC),$(HOSTCC))
81928 +HOSTLIBS := hostlibs
81929 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81930 +else
81931 +HOSTLIBS := hostcxxlibs
81932 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
81933 +endif
81934 +
81935 +$(HOSTLIBS)-y := constify_plugin.so
81936 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81937 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81938 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81939 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81940 +$(HOSTLIBS)-y += colorize_plugin.so
81941 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81942 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
81943 +
81944 +always := $($(HOSTLIBS)-y)
81945 +
81946 +constify_plugin-objs := constify_plugin.o
81947 +stackleak_plugin-objs := stackleak_plugin.o
81948 +kallocstat_plugin-objs := kallocstat_plugin.o
81949 +kernexec_plugin-objs := kernexec_plugin.o
81950 +checker_plugin-objs := checker_plugin.o
81951 +colorize_plugin-objs := colorize_plugin.o
81952 +size_overflow_plugin-objs := size_overflow_plugin.o
81953 +latent_entropy_plugin-objs := latent_entropy_plugin.o
81954 +
81955 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
81956 +
81957 +quiet_cmd_build_size_overflow_hash = GENHASH $@
81958 + cmd_build_size_overflow_hash = \
81959 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
81960 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
81961 + $(call if_changed,build_size_overflow_hash)
81962 +
81963 +targets += size_overflow_hash.h
81964 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81965 new file mode 100644
81966 index 0000000..d41b5af
81967 --- /dev/null
81968 +++ b/tools/gcc/checker_plugin.c
81969 @@ -0,0 +1,171 @@
81970 +/*
81971 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81972 + * Licensed under the GPL v2
81973 + *
81974 + * Note: the choice of the license means that the compilation process is
81975 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81976 + * but for the kernel it doesn't matter since it doesn't link against
81977 + * any of the gcc libraries
81978 + *
81979 + * gcc plugin to implement various sparse (source code checker) features
81980 + *
81981 + * TODO:
81982 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81983 + *
81984 + * BUGS:
81985 + * - none known
81986 + */
81987 +#include "gcc-plugin.h"
81988 +#include "config.h"
81989 +#include "system.h"
81990 +#include "coretypes.h"
81991 +#include "tree.h"
81992 +#include "tree-pass.h"
81993 +#include "flags.h"
81994 +#include "intl.h"
81995 +#include "toplev.h"
81996 +#include "plugin.h"
81997 +//#include "expr.h" where are you...
81998 +#include "diagnostic.h"
81999 +#include "plugin-version.h"
82000 +#include "tm.h"
82001 +#include "function.h"
82002 +#include "basic-block.h"
82003 +#include "gimple.h"
82004 +#include "rtl.h"
82005 +#include "emit-rtl.h"
82006 +#include "tree-flow.h"
82007 +#include "target.h"
82008 +
82009 +extern void c_register_addr_space (const char *str, addr_space_t as);
82010 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82011 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82012 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82013 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82014 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82015 +
82016 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82017 +extern rtx emit_move_insn(rtx x, rtx y);
82018 +
82019 +int plugin_is_GPL_compatible;
82020 +
82021 +static struct plugin_info checker_plugin_info = {
82022 + .version = "201111150100",
82023 +};
82024 +
82025 +#define ADDR_SPACE_KERNEL 0
82026 +#define ADDR_SPACE_FORCE_KERNEL 1
82027 +#define ADDR_SPACE_USER 2
82028 +#define ADDR_SPACE_FORCE_USER 3
82029 +#define ADDR_SPACE_IOMEM 0
82030 +#define ADDR_SPACE_FORCE_IOMEM 0
82031 +#define ADDR_SPACE_PERCPU 0
82032 +#define ADDR_SPACE_FORCE_PERCPU 0
82033 +#define ADDR_SPACE_RCU 0
82034 +#define ADDR_SPACE_FORCE_RCU 0
82035 +
82036 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82037 +{
82038 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82039 +}
82040 +
82041 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82042 +{
82043 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82044 +}
82045 +
82046 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82047 +{
82048 + return default_addr_space_valid_pointer_mode(mode, as);
82049 +}
82050 +
82051 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82052 +{
82053 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82054 +}
82055 +
82056 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82057 +{
82058 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82059 +}
82060 +
82061 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82062 +{
82063 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82064 + return true;
82065 +
82066 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82067 + return true;
82068 +
82069 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82070 + return true;
82071 +
82072 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82073 + return true;
82074 +
82075 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82076 + return true;
82077 +
82078 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82079 + return true;
82080 +
82081 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82082 + return true;
82083 +
82084 + return subset == superset;
82085 +}
82086 +
82087 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82088 +{
82089 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82090 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82091 +
82092 + return op;
82093 +}
82094 +
82095 +static void register_checker_address_spaces(void *event_data, void *data)
82096 +{
82097 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82098 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82099 + c_register_addr_space("__user", ADDR_SPACE_USER);
82100 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82101 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82102 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82103 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82104 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82105 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82106 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82107 +
82108 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82109 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82110 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82111 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82112 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82113 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82114 + targetm.addr_space.convert = checker_addr_space_convert;
82115 +}
82116 +
82117 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82118 +{
82119 + const char * const plugin_name = plugin_info->base_name;
82120 + const int argc = plugin_info->argc;
82121 + const struct plugin_argument * const argv = plugin_info->argv;
82122 + int i;
82123 +
82124 + if (!plugin_default_version_check(version, &gcc_version)) {
82125 + error(G_("incompatible gcc/plugin versions"));
82126 + return 1;
82127 + }
82128 +
82129 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82130 +
82131 + for (i = 0; i < argc; ++i)
82132 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82133 +
82134 + if (TARGET_64BIT == 0)
82135 + return 0;
82136 +
82137 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82138 +
82139 + return 0;
82140 +}
82141 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82142 new file mode 100644
82143 index 0000000..846aeb0
82144 --- /dev/null
82145 +++ b/tools/gcc/colorize_plugin.c
82146 @@ -0,0 +1,148 @@
82147 +/*
82148 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82149 + * Licensed under the GPL v2
82150 + *
82151 + * Note: the choice of the license means that the compilation process is
82152 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82153 + * but for the kernel it doesn't matter since it doesn't link against
82154 + * any of the gcc libraries
82155 + *
82156 + * gcc plugin to colorize diagnostic output
82157 + *
82158 + */
82159 +
82160 +#include "gcc-plugin.h"
82161 +#include "config.h"
82162 +#include "system.h"
82163 +#include "coretypes.h"
82164 +#include "tree.h"
82165 +#include "tree-pass.h"
82166 +#include "flags.h"
82167 +#include "intl.h"
82168 +#include "toplev.h"
82169 +#include "plugin.h"
82170 +#include "diagnostic.h"
82171 +#include "plugin-version.h"
82172 +#include "tm.h"
82173 +
82174 +int plugin_is_GPL_compatible;
82175 +
82176 +static struct plugin_info colorize_plugin_info = {
82177 + .version = "201203092200",
82178 + .help = NULL,
82179 +};
82180 +
82181 +#define GREEN "\033[32m\033[2m"
82182 +#define LIGHTGREEN "\033[32m\033[1m"
82183 +#define YELLOW "\033[33m\033[2m"
82184 +#define LIGHTYELLOW "\033[33m\033[1m"
82185 +#define RED "\033[31m\033[2m"
82186 +#define LIGHTRED "\033[31m\033[1m"
82187 +#define BLUE "\033[34m\033[2m"
82188 +#define LIGHTBLUE "\033[34m\033[1m"
82189 +#define BRIGHT "\033[m\033[1m"
82190 +#define NORMAL "\033[m"
82191 +
82192 +static diagnostic_starter_fn old_starter;
82193 +static diagnostic_finalizer_fn old_finalizer;
82194 +
82195 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82196 +{
82197 + const char *color;
82198 + char *newprefix;
82199 +
82200 + switch (diagnostic->kind) {
82201 + case DK_NOTE:
82202 + color = LIGHTBLUE;
82203 + break;
82204 +
82205 + case DK_PEDWARN:
82206 + case DK_WARNING:
82207 + color = LIGHTYELLOW;
82208 + break;
82209 +
82210 + case DK_ERROR:
82211 + case DK_FATAL:
82212 + case DK_ICE:
82213 + case DK_PERMERROR:
82214 + case DK_SORRY:
82215 + color = LIGHTRED;
82216 + break;
82217 +
82218 + default:
82219 + color = NORMAL;
82220 + }
82221 +
82222 + old_starter(context, diagnostic);
82223 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82224 + return;
82225 + pp_destroy_prefix(context->printer);
82226 + pp_set_prefix(context->printer, newprefix);
82227 +}
82228 +
82229 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82230 +{
82231 + old_finalizer(context, diagnostic);
82232 +}
82233 +
82234 +static void colorize_arm(void)
82235 +{
82236 + old_starter = diagnostic_starter(global_dc);
82237 + old_finalizer = diagnostic_finalizer(global_dc);
82238 +
82239 + diagnostic_starter(global_dc) = start_colorize;
82240 + diagnostic_finalizer(global_dc) = finalize_colorize;
82241 +}
82242 +
82243 +static unsigned int execute_colorize_rearm(void)
82244 +{
82245 + if (diagnostic_starter(global_dc) == start_colorize)
82246 + return 0;
82247 +
82248 + colorize_arm();
82249 + return 0;
82250 +}
82251 +
82252 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82253 + .pass = {
82254 + .type = SIMPLE_IPA_PASS,
82255 + .name = "colorize_rearm",
82256 + .gate = NULL,
82257 + .execute = execute_colorize_rearm,
82258 + .sub = NULL,
82259 + .next = NULL,
82260 + .static_pass_number = 0,
82261 + .tv_id = TV_NONE,
82262 + .properties_required = 0,
82263 + .properties_provided = 0,
82264 + .properties_destroyed = 0,
82265 + .todo_flags_start = 0,
82266 + .todo_flags_finish = 0
82267 + }
82268 +};
82269 +
82270 +static void colorize_start_unit(void *gcc_data, void *user_data)
82271 +{
82272 + colorize_arm();
82273 +}
82274 +
82275 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82276 +{
82277 + const char * const plugin_name = plugin_info->base_name;
82278 + struct register_pass_info colorize_rearm_pass_info = {
82279 + .pass = &pass_ipa_colorize_rearm.pass,
82280 + .reference_pass_name = "*free_lang_data",
82281 + .ref_pass_instance_number = 1,
82282 + .pos_op = PASS_POS_INSERT_AFTER
82283 + };
82284 +
82285 + if (!plugin_default_version_check(version, &gcc_version)) {
82286 + error(G_("incompatible gcc/plugin versions"));
82287 + return 1;
82288 + }
82289 +
82290 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82291 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82292 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82293 + return 0;
82294 +}
82295 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82296 new file mode 100644
82297 index 0000000..92ed719
82298 --- /dev/null
82299 +++ b/tools/gcc/constify_plugin.c
82300 @@ -0,0 +1,331 @@
82301 +/*
82302 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82303 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82304 + * Licensed under the GPL v2, or (at your option) v3
82305 + *
82306 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82307 + *
82308 + * Homepage:
82309 + * http://www.grsecurity.net/~ephox/const_plugin/
82310 + *
82311 + * Usage:
82312 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82313 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82314 + */
82315 +
82316 +#include "gcc-plugin.h"
82317 +#include "config.h"
82318 +#include "system.h"
82319 +#include "coretypes.h"
82320 +#include "tree.h"
82321 +#include "tree-pass.h"
82322 +#include "flags.h"
82323 +#include "intl.h"
82324 +#include "toplev.h"
82325 +#include "plugin.h"
82326 +#include "diagnostic.h"
82327 +#include "plugin-version.h"
82328 +#include "tm.h"
82329 +#include "function.h"
82330 +#include "basic-block.h"
82331 +#include "gimple.h"
82332 +#include "rtl.h"
82333 +#include "emit-rtl.h"
82334 +#include "tree-flow.h"
82335 +
82336 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82337 +
82338 +int plugin_is_GPL_compatible;
82339 +
82340 +static struct plugin_info const_plugin_info = {
82341 + .version = "201205300030",
82342 + .help = "no-constify\tturn off constification\n",
82343 +};
82344 +
82345 +static void deconstify_tree(tree node);
82346 +
82347 +static void deconstify_type(tree type)
82348 +{
82349 + tree field;
82350 +
82351 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82352 + tree type = TREE_TYPE(field);
82353 +
82354 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82355 + continue;
82356 + if (!TYPE_READONLY(type))
82357 + continue;
82358 +
82359 + deconstify_tree(field);
82360 + }
82361 + TYPE_READONLY(type) = 0;
82362 + C_TYPE_FIELDS_READONLY(type) = 0;
82363 +}
82364 +
82365 +static void deconstify_tree(tree node)
82366 +{
82367 + tree old_type, new_type, field;
82368 +
82369 + old_type = TREE_TYPE(node);
82370 +
82371 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82372 +
82373 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82374 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82375 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82376 + DECL_FIELD_CONTEXT(field) = new_type;
82377 +
82378 + deconstify_type(new_type);
82379 +
82380 + TREE_READONLY(node) = 0;
82381 + TREE_TYPE(node) = new_type;
82382 +}
82383 +
82384 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82385 +{
82386 + tree type;
82387 +
82388 + *no_add_attrs = true;
82389 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82390 + error("%qE attribute does not apply to functions", name);
82391 + return NULL_TREE;
82392 + }
82393 +
82394 + if (TREE_CODE(*node) == VAR_DECL) {
82395 + error("%qE attribute does not apply to variables", name);
82396 + return NULL_TREE;
82397 + }
82398 +
82399 + if (TYPE_P(*node)) {
82400 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82401 + *no_add_attrs = false;
82402 + else
82403 + error("%qE attribute applies to struct and union types only", name);
82404 + return NULL_TREE;
82405 + }
82406 +
82407 + type = TREE_TYPE(*node);
82408 +
82409 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82410 + error("%qE attribute applies to struct and union types only", name);
82411 + return NULL_TREE;
82412 + }
82413 +
82414 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82415 + error("%qE attribute is already applied to the type", name);
82416 + return NULL_TREE;
82417 + }
82418 +
82419 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82420 + error("%qE attribute used on type that is not constified", name);
82421 + return NULL_TREE;
82422 + }
82423 +
82424 + if (TREE_CODE(*node) == TYPE_DECL) {
82425 + deconstify_tree(*node);
82426 + return NULL_TREE;
82427 + }
82428 +
82429 + return NULL_TREE;
82430 +}
82431 +
82432 +static void constify_type(tree type)
82433 +{
82434 + TYPE_READONLY(type) = 1;
82435 + C_TYPE_FIELDS_READONLY(type) = 1;
82436 +}
82437 +
82438 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82439 +{
82440 + *no_add_attrs = true;
82441 + if (!TYPE_P(*node)) {
82442 + error("%qE attribute applies to types only", name);
82443 + return NULL_TREE;
82444 + }
82445 +
82446 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82447 + error("%qE attribute applies to struct and union types only", name);
82448 + return NULL_TREE;
82449 + }
82450 +
82451 + *no_add_attrs = false;
82452 + constify_type(*node);
82453 + return NULL_TREE;
82454 +}
82455 +
82456 +static struct attribute_spec no_const_attr = {
82457 + .name = "no_const",
82458 + .min_length = 0,
82459 + .max_length = 0,
82460 + .decl_required = false,
82461 + .type_required = false,
82462 + .function_type_required = false,
82463 + .handler = handle_no_const_attribute,
82464 +#if BUILDING_GCC_VERSION >= 4007
82465 + .affects_type_identity = true
82466 +#endif
82467 +};
82468 +
82469 +static struct attribute_spec do_const_attr = {
82470 + .name = "do_const",
82471 + .min_length = 0,
82472 + .max_length = 0,
82473 + .decl_required = false,
82474 + .type_required = false,
82475 + .function_type_required = false,
82476 + .handler = handle_do_const_attribute,
82477 +#if BUILDING_GCC_VERSION >= 4007
82478 + .affects_type_identity = true
82479 +#endif
82480 +};
82481 +
82482 +static void register_attributes(void *event_data, void *data)
82483 +{
82484 + register_attribute(&no_const_attr);
82485 + register_attribute(&do_const_attr);
82486 +}
82487 +
82488 +static bool is_fptr(tree field)
82489 +{
82490 + tree ptr = TREE_TYPE(field);
82491 +
82492 + if (TREE_CODE(ptr) != POINTER_TYPE)
82493 + return false;
82494 +
82495 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82496 +}
82497 +
82498 +static bool walk_struct(tree node)
82499 +{
82500 + tree field;
82501 +
82502 + if (TYPE_FIELDS(node) == NULL_TREE)
82503 + return false;
82504 +
82505 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82506 + gcc_assert(!TYPE_READONLY(node));
82507 + deconstify_type(node);
82508 + return false;
82509 + }
82510 +
82511 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82512 + tree type = TREE_TYPE(field);
82513 + enum tree_code code = TREE_CODE(type);
82514 +
82515 + if (node == type)
82516 + return false;
82517 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82518 + if (!(walk_struct(type)))
82519 + return false;
82520 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82521 + return false;
82522 + }
82523 + return true;
82524 +}
82525 +
82526 +static void finish_type(void *event_data, void *data)
82527 +{
82528 + tree type = (tree)event_data;
82529 +
82530 + if (type == NULL_TREE || type == error_mark_node)
82531 + return;
82532 +
82533 + if (TYPE_READONLY(type))
82534 + return;
82535 +
82536 + if (walk_struct(type))
82537 + constify_type(type);
82538 +}
82539 +
82540 +static unsigned int check_local_variables(void);
82541 +
82542 +struct gimple_opt_pass pass_local_variable = {
82543 + {
82544 + .type = GIMPLE_PASS,
82545 + .name = "check_local_variables",
82546 + .gate = NULL,
82547 + .execute = check_local_variables,
82548 + .sub = NULL,
82549 + .next = NULL,
82550 + .static_pass_number = 0,
82551 + .tv_id = TV_NONE,
82552 + .properties_required = 0,
82553 + .properties_provided = 0,
82554 + .properties_destroyed = 0,
82555 + .todo_flags_start = 0,
82556 + .todo_flags_finish = 0
82557 + }
82558 +};
82559 +
82560 +static unsigned int check_local_variables(void)
82561 +{
82562 + tree var;
82563 + referenced_var_iterator rvi;
82564 +
82565 +#if BUILDING_GCC_VERSION == 4005
82566 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82567 +#else
82568 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82569 +#endif
82570 + tree type = TREE_TYPE(var);
82571 +
82572 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82573 + continue;
82574 +
82575 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82576 + continue;
82577 +
82578 + if (!TYPE_READONLY(type))
82579 + continue;
82580 +
82581 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82582 +// continue;
82583 +
82584 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82585 +// continue;
82586 +
82587 + if (walk_struct(type)) {
82588 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82589 + return 1;
82590 + }
82591 + }
82592 + return 0;
82593 +}
82594 +
82595 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82596 +{
82597 + const char * const plugin_name = plugin_info->base_name;
82598 + const int argc = plugin_info->argc;
82599 + const struct plugin_argument * const argv = plugin_info->argv;
82600 + int i;
82601 + bool constify = true;
82602 +
82603 + struct register_pass_info local_variable_pass_info = {
82604 + .pass = &pass_local_variable.pass,
82605 + .reference_pass_name = "*referenced_vars",
82606 + .ref_pass_instance_number = 1,
82607 + .pos_op = PASS_POS_INSERT_AFTER
82608 + };
82609 +
82610 + if (!plugin_default_version_check(version, &gcc_version)) {
82611 + error(G_("incompatible gcc/plugin versions"));
82612 + return 1;
82613 + }
82614 +
82615 + for (i = 0; i < argc; ++i) {
82616 + if (!(strcmp(argv[i].key, "no-constify"))) {
82617 + constify = false;
82618 + continue;
82619 + }
82620 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82621 + }
82622 +
82623 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82624 + if (constify) {
82625 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82626 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82627 + }
82628 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82629 +
82630 + return 0;
82631 +}
82632 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82633 new file mode 100644
82634 index 0000000..02c6bec
82635 --- /dev/null
82636 +++ b/tools/gcc/generate_size_overflow_hash.sh
82637 @@ -0,0 +1,94 @@
82638 +#!/bin/bash
82639 +
82640 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82641 +
82642 +header1="size_overflow_hash.h"
82643 +database="size_overflow_hash.data"
82644 +n=65536
82645 +
82646 +usage() {
82647 +cat <<EOF
82648 +usage: $0 options
82649 +OPTIONS:
82650 + -h|--help help
82651 + -o header file
82652 + -d database file
82653 + -n hash array size
82654 +EOF
82655 + return 0
82656 +}
82657 +
82658 +while true
82659 +do
82660 + case "$1" in
82661 + -h|--help) usage && exit 0;;
82662 + -n) n=$2; shift 2;;
82663 + -o) header1="$2"; shift 2;;
82664 + -d) database="$2"; shift 2;;
82665 + --) shift 1; break ;;
82666 + *) break ;;
82667 + esac
82668 +done
82669 +
82670 +create_defines() {
82671 + for i in `seq 1 32`
82672 + do
82673 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
82674 + done
82675 + echo >> "$header1"
82676 +}
82677 +
82678 +create_structs () {
82679 + rm -f "$header1"
82680 +
82681 + create_defines
82682 +
82683 + cat "$database" | while read data
82684 + do
82685 + data_array=($data)
82686 + struct_hash_name="${data_array[0]}"
82687 + funcn="${data_array[1]}"
82688 + params="${data_array[2]}"
82689 + next="${data_array[5]}"
82690 +
82691 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
82692 +
82693 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
82694 + echo -en "\t.param\t= " >> "$header1"
82695 + line=
82696 + for param_num in ${params//-/ };
82697 + do
82698 + line="${line}PARAM"$param_num"|"
82699 + done
82700 +
82701 + echo -e "${line%?},\n};\n" >> "$header1"
82702 + done
82703 +}
82704 +
82705 +create_headers () {
82706 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
82707 +}
82708 +
82709 +create_array_elements () {
82710 + index=0
82711 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
82712 + do
82713 + data_array=($data)
82714 + i="${data_array[3]}"
82715 + hash="${data_array[4]}"
82716 + while [[ $index -lt $i ]]
82717 + do
82718 + echo -e "\t["$index"]\t= NULL," >> "$header1"
82719 + index=$(($index + 1))
82720 + done
82721 + index=$(($index + 1))
82722 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
82723 + done
82724 + echo '};' >> $header1
82725 +}
82726 +
82727 +create_structs
82728 +create_headers
82729 +create_array_elements
82730 +
82731 +exit 0
82732 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82733 new file mode 100644
82734 index 0000000..a86e422
82735 --- /dev/null
82736 +++ b/tools/gcc/kallocstat_plugin.c
82737 @@ -0,0 +1,167 @@
82738 +/*
82739 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82740 + * Licensed under the GPL v2
82741 + *
82742 + * Note: the choice of the license means that the compilation process is
82743 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82744 + * but for the kernel it doesn't matter since it doesn't link against
82745 + * any of the gcc libraries
82746 + *
82747 + * gcc plugin to find the distribution of k*alloc sizes
82748 + *
82749 + * TODO:
82750 + *
82751 + * BUGS:
82752 + * - none known
82753 + */
82754 +#include "gcc-plugin.h"
82755 +#include "config.h"
82756 +#include "system.h"
82757 +#include "coretypes.h"
82758 +#include "tree.h"
82759 +#include "tree-pass.h"
82760 +#include "flags.h"
82761 +#include "intl.h"
82762 +#include "toplev.h"
82763 +#include "plugin.h"
82764 +//#include "expr.h" where are you...
82765 +#include "diagnostic.h"
82766 +#include "plugin-version.h"
82767 +#include "tm.h"
82768 +#include "function.h"
82769 +#include "basic-block.h"
82770 +#include "gimple.h"
82771 +#include "rtl.h"
82772 +#include "emit-rtl.h"
82773 +
82774 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82775 +
82776 +int plugin_is_GPL_compatible;
82777 +
82778 +static const char * const kalloc_functions[] = {
82779 + "__kmalloc",
82780 + "kmalloc",
82781 + "kmalloc_large",
82782 + "kmalloc_node",
82783 + "kmalloc_order",
82784 + "kmalloc_order_trace",
82785 + "kmalloc_slab",
82786 + "kzalloc",
82787 + "kzalloc_node",
82788 +};
82789 +
82790 +static struct plugin_info kallocstat_plugin_info = {
82791 + .version = "201111150100",
82792 +};
82793 +
82794 +static unsigned int execute_kallocstat(void);
82795 +
82796 +static struct gimple_opt_pass kallocstat_pass = {
82797 + .pass = {
82798 + .type = GIMPLE_PASS,
82799 + .name = "kallocstat",
82800 + .gate = NULL,
82801 + .execute = execute_kallocstat,
82802 + .sub = NULL,
82803 + .next = NULL,
82804 + .static_pass_number = 0,
82805 + .tv_id = TV_NONE,
82806 + .properties_required = 0,
82807 + .properties_provided = 0,
82808 + .properties_destroyed = 0,
82809 + .todo_flags_start = 0,
82810 + .todo_flags_finish = 0
82811 + }
82812 +};
82813 +
82814 +static bool is_kalloc(const char *fnname)
82815 +{
82816 + size_t i;
82817 +
82818 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82819 + if (!strcmp(fnname, kalloc_functions[i]))
82820 + return true;
82821 + return false;
82822 +}
82823 +
82824 +static unsigned int execute_kallocstat(void)
82825 +{
82826 + basic_block bb;
82827 +
82828 + // 1. loop through BBs and GIMPLE statements
82829 + FOR_EACH_BB(bb) {
82830 + gimple_stmt_iterator gsi;
82831 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82832 + // gimple match:
82833 + tree fndecl, size;
82834 + gimple call_stmt;
82835 + const char *fnname;
82836 +
82837 + // is it a call
82838 + call_stmt = gsi_stmt(gsi);
82839 + if (!is_gimple_call(call_stmt))
82840 + continue;
82841 + fndecl = gimple_call_fndecl(call_stmt);
82842 + if (fndecl == NULL_TREE)
82843 + continue;
82844 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82845 + continue;
82846 +
82847 + // is it a call to k*alloc
82848 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82849 + if (!is_kalloc(fnname))
82850 + continue;
82851 +
82852 + // is the size arg the result of a simple const assignment
82853 + size = gimple_call_arg(call_stmt, 0);
82854 + while (true) {
82855 + gimple def_stmt;
82856 + expanded_location xloc;
82857 + size_t size_val;
82858 +
82859 + if (TREE_CODE(size) != SSA_NAME)
82860 + break;
82861 + def_stmt = SSA_NAME_DEF_STMT(size);
82862 + if (!def_stmt || !is_gimple_assign(def_stmt))
82863 + break;
82864 + if (gimple_num_ops(def_stmt) != 2)
82865 + break;
82866 + size = gimple_assign_rhs1(def_stmt);
82867 + if (!TREE_CONSTANT(size))
82868 + continue;
82869 + xloc = expand_location(gimple_location(def_stmt));
82870 + if (!xloc.file)
82871 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82872 + size_val = TREE_INT_CST_LOW(size);
82873 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82874 + break;
82875 + }
82876 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82877 +//debug_tree(gimple_call_fn(call_stmt));
82878 +//print_node(stderr, "pax", fndecl, 4);
82879 + }
82880 + }
82881 +
82882 + return 0;
82883 +}
82884 +
82885 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82886 +{
82887 + const char * const plugin_name = plugin_info->base_name;
82888 + struct register_pass_info kallocstat_pass_info = {
82889 + .pass = &kallocstat_pass.pass,
82890 + .reference_pass_name = "ssa",
82891 + .ref_pass_instance_number = 1,
82892 + .pos_op = PASS_POS_INSERT_AFTER
82893 + };
82894 +
82895 + if (!plugin_default_version_check(version, &gcc_version)) {
82896 + error(G_("incompatible gcc/plugin versions"));
82897 + return 1;
82898 + }
82899 +
82900 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82901 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82902 +
82903 + return 0;
82904 +}
82905 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82906 new file mode 100644
82907 index 0000000..98011fa
82908 --- /dev/null
82909 +++ b/tools/gcc/kernexec_plugin.c
82910 @@ -0,0 +1,427 @@
82911 +/*
82912 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82913 + * Licensed under the GPL v2
82914 + *
82915 + * Note: the choice of the license means that the compilation process is
82916 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82917 + * but for the kernel it doesn't matter since it doesn't link against
82918 + * any of the gcc libraries
82919 + *
82920 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82921 + *
82922 + * TODO:
82923 + *
82924 + * BUGS:
82925 + * - none known
82926 + */
82927 +#include "gcc-plugin.h"
82928 +#include "config.h"
82929 +#include "system.h"
82930 +#include "coretypes.h"
82931 +#include "tree.h"
82932 +#include "tree-pass.h"
82933 +#include "flags.h"
82934 +#include "intl.h"
82935 +#include "toplev.h"
82936 +#include "plugin.h"
82937 +//#include "expr.h" where are you...
82938 +#include "diagnostic.h"
82939 +#include "plugin-version.h"
82940 +#include "tm.h"
82941 +#include "function.h"
82942 +#include "basic-block.h"
82943 +#include "gimple.h"
82944 +#include "rtl.h"
82945 +#include "emit-rtl.h"
82946 +#include "tree-flow.h"
82947 +
82948 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82949 +extern rtx emit_move_insn(rtx x, rtx y);
82950 +
82951 +int plugin_is_GPL_compatible;
82952 +
82953 +static struct plugin_info kernexec_plugin_info = {
82954 + .version = "201111291120",
82955 + .help = "method=[bts|or]\tinstrumentation method\n"
82956 +};
82957 +
82958 +static unsigned int execute_kernexec_reload(void);
82959 +static unsigned int execute_kernexec_fptr(void);
82960 +static unsigned int execute_kernexec_retaddr(void);
82961 +static bool kernexec_cmodel_check(void);
82962 +
82963 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82964 +static void (*kernexec_instrument_retaddr)(rtx);
82965 +
82966 +static struct gimple_opt_pass kernexec_reload_pass = {
82967 + .pass = {
82968 + .type = GIMPLE_PASS,
82969 + .name = "kernexec_reload",
82970 + .gate = kernexec_cmodel_check,
82971 + .execute = execute_kernexec_reload,
82972 + .sub = NULL,
82973 + .next = NULL,
82974 + .static_pass_number = 0,
82975 + .tv_id = TV_NONE,
82976 + .properties_required = 0,
82977 + .properties_provided = 0,
82978 + .properties_destroyed = 0,
82979 + .todo_flags_start = 0,
82980 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82981 + }
82982 +};
82983 +
82984 +static struct gimple_opt_pass kernexec_fptr_pass = {
82985 + .pass = {
82986 + .type = GIMPLE_PASS,
82987 + .name = "kernexec_fptr",
82988 + .gate = kernexec_cmodel_check,
82989 + .execute = execute_kernexec_fptr,
82990 + .sub = NULL,
82991 + .next = NULL,
82992 + .static_pass_number = 0,
82993 + .tv_id = TV_NONE,
82994 + .properties_required = 0,
82995 + .properties_provided = 0,
82996 + .properties_destroyed = 0,
82997 + .todo_flags_start = 0,
82998 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82999 + }
83000 +};
83001 +
83002 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83003 + .pass = {
83004 + .type = RTL_PASS,
83005 + .name = "kernexec_retaddr",
83006 + .gate = kernexec_cmodel_check,
83007 + .execute = execute_kernexec_retaddr,
83008 + .sub = NULL,
83009 + .next = NULL,
83010 + .static_pass_number = 0,
83011 + .tv_id = TV_NONE,
83012 + .properties_required = 0,
83013 + .properties_provided = 0,
83014 + .properties_destroyed = 0,
83015 + .todo_flags_start = 0,
83016 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83017 + }
83018 +};
83019 +
83020 +static bool kernexec_cmodel_check(void)
83021 +{
83022 + tree section;
83023 +
83024 + if (ix86_cmodel != CM_KERNEL)
83025 + return false;
83026 +
83027 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83028 + if (!section || !TREE_VALUE(section))
83029 + return true;
83030 +
83031 + section = TREE_VALUE(TREE_VALUE(section));
83032 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83033 + return true;
83034 +
83035 + return false;
83036 +}
83037 +
83038 +/*
83039 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83040 + */
83041 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83042 +{
83043 + gimple asm_movabs_stmt;
83044 +
83045 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83046 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83047 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83048 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83049 + update_stmt(asm_movabs_stmt);
83050 +}
83051 +
83052 +/*
83053 + * find all asm() stmts that clobber r10 and add a reload of r10
83054 + */
83055 +static unsigned int execute_kernexec_reload(void)
83056 +{
83057 + basic_block bb;
83058 +
83059 + // 1. loop through BBs and GIMPLE statements
83060 + FOR_EACH_BB(bb) {
83061 + gimple_stmt_iterator gsi;
83062 +
83063 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83064 + // gimple match: __asm__ ("" : : : "r10");
83065 + gimple asm_stmt;
83066 + size_t nclobbers;
83067 +
83068 + // is it an asm ...
83069 + asm_stmt = gsi_stmt(gsi);
83070 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83071 + continue;
83072 +
83073 + // ... clobbering r10
83074 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83075 + while (nclobbers--) {
83076 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83077 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83078 + continue;
83079 + kernexec_reload_fptr_mask(&gsi);
83080 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83081 + break;
83082 + }
83083 + }
83084 + }
83085 +
83086 + return 0;
83087 +}
83088 +
83089 +/*
83090 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83091 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83092 + */
83093 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83094 +{
83095 + gimple assign_intptr, assign_new_fptr, call_stmt;
83096 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83097 +
83098 + call_stmt = gsi_stmt(*gsi);
83099 + old_fptr = gimple_call_fn(call_stmt);
83100 +
83101 + // create temporary unsigned long variable used for bitops and cast fptr to it
83102 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83103 + add_referenced_var(intptr);
83104 + mark_sym_for_renaming(intptr);
83105 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83106 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83107 + update_stmt(assign_intptr);
83108 +
83109 + // apply logical or to temporary unsigned long and bitmask
83110 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83111 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83112 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83113 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83114 + update_stmt(assign_intptr);
83115 +
83116 + // cast temporary unsigned long back to a temporary fptr variable
83117 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83118 + add_referenced_var(new_fptr);
83119 + mark_sym_for_renaming(new_fptr);
83120 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83121 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83122 + update_stmt(assign_new_fptr);
83123 +
83124 + // replace call stmt fn with the new fptr
83125 + gimple_call_set_fn(call_stmt, new_fptr);
83126 + update_stmt(call_stmt);
83127 +}
83128 +
83129 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83130 +{
83131 + gimple asm_or_stmt, call_stmt;
83132 + tree old_fptr, new_fptr, input, output;
83133 + VEC(tree, gc) *inputs = NULL;
83134 + VEC(tree, gc) *outputs = NULL;
83135 +
83136 + call_stmt = gsi_stmt(*gsi);
83137 + old_fptr = gimple_call_fn(call_stmt);
83138 +
83139 + // create temporary fptr variable
83140 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83141 + add_referenced_var(new_fptr);
83142 + mark_sym_for_renaming(new_fptr);
83143 +
83144 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83145 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83146 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83147 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83148 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83149 + VEC_safe_push(tree, gc, inputs, input);
83150 + VEC_safe_push(tree, gc, outputs, output);
83151 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83152 + gimple_asm_set_volatile(asm_or_stmt, true);
83153 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83154 + update_stmt(asm_or_stmt);
83155 +
83156 + // replace call stmt fn with the new fptr
83157 + gimple_call_set_fn(call_stmt, new_fptr);
83158 + update_stmt(call_stmt);
83159 +}
83160 +
83161 +/*
83162 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83163 + */
83164 +static unsigned int execute_kernexec_fptr(void)
83165 +{
83166 + basic_block bb;
83167 +
83168 + // 1. loop through BBs and GIMPLE statements
83169 + FOR_EACH_BB(bb) {
83170 + gimple_stmt_iterator gsi;
83171 +
83172 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83173 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83174 + tree fn;
83175 + gimple call_stmt;
83176 +
83177 + // is it a call ...
83178 + call_stmt = gsi_stmt(gsi);
83179 + if (!is_gimple_call(call_stmt))
83180 + continue;
83181 + fn = gimple_call_fn(call_stmt);
83182 + if (TREE_CODE(fn) == ADDR_EXPR)
83183 + continue;
83184 + if (TREE_CODE(fn) != SSA_NAME)
83185 + gcc_unreachable();
83186 +
83187 + // ... through a function pointer
83188 + fn = SSA_NAME_VAR(fn);
83189 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83190 + continue;
83191 + fn = TREE_TYPE(fn);
83192 + if (TREE_CODE(fn) != POINTER_TYPE)
83193 + continue;
83194 + fn = TREE_TYPE(fn);
83195 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83196 + continue;
83197 +
83198 + kernexec_instrument_fptr(&gsi);
83199 +
83200 +//debug_tree(gimple_call_fn(call_stmt));
83201 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83202 + }
83203 + }
83204 +
83205 + return 0;
83206 +}
83207 +
83208 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83209 +static void kernexec_instrument_retaddr_bts(rtx insn)
83210 +{
83211 + rtx btsq;
83212 + rtvec argvec, constraintvec, labelvec;
83213 + int line;
83214 +
83215 + // create asm volatile("btsq $63,(%%rsp)":::)
83216 + argvec = rtvec_alloc(0);
83217 + constraintvec = rtvec_alloc(0);
83218 + labelvec = rtvec_alloc(0);
83219 + line = expand_location(RTL_LOCATION(insn)).line;
83220 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83221 + MEM_VOLATILE_P(btsq) = 1;
83222 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83223 + emit_insn_before(btsq, insn);
83224 +}
83225 +
83226 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83227 +static void kernexec_instrument_retaddr_or(rtx insn)
83228 +{
83229 + rtx orq;
83230 + rtvec argvec, constraintvec, labelvec;
83231 + int line;
83232 +
83233 + // create asm volatile("orq %%r10,(%%rsp)":::)
83234 + argvec = rtvec_alloc(0);
83235 + constraintvec = rtvec_alloc(0);
83236 + labelvec = rtvec_alloc(0);
83237 + line = expand_location(RTL_LOCATION(insn)).line;
83238 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83239 + MEM_VOLATILE_P(orq) = 1;
83240 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83241 + emit_insn_before(orq, insn);
83242 +}
83243 +
83244 +/*
83245 + * find all asm level function returns and forcibly set the highest bit of the return address
83246 + */
83247 +static unsigned int execute_kernexec_retaddr(void)
83248 +{
83249 + rtx insn;
83250 +
83251 + // 1. find function returns
83252 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83253 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83254 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83255 + rtx body;
83256 +
83257 + // is it a retn
83258 + if (!JUMP_P(insn))
83259 + continue;
83260 + body = PATTERN(insn);
83261 + if (GET_CODE(body) == PARALLEL)
83262 + body = XVECEXP(body, 0, 0);
83263 + if (GET_CODE(body) != RETURN)
83264 + continue;
83265 + kernexec_instrument_retaddr(insn);
83266 + }
83267 +
83268 +// print_simple_rtl(stderr, get_insns());
83269 +// print_rtl(stderr, get_insns());
83270 +
83271 + return 0;
83272 +}
83273 +
83274 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83275 +{
83276 + const char * const plugin_name = plugin_info->base_name;
83277 + const int argc = plugin_info->argc;
83278 + const struct plugin_argument * const argv = plugin_info->argv;
83279 + int i;
83280 + struct register_pass_info kernexec_reload_pass_info = {
83281 + .pass = &kernexec_reload_pass.pass,
83282 + .reference_pass_name = "ssa",
83283 + .ref_pass_instance_number = 1,
83284 + .pos_op = PASS_POS_INSERT_AFTER
83285 + };
83286 + struct register_pass_info kernexec_fptr_pass_info = {
83287 + .pass = &kernexec_fptr_pass.pass,
83288 + .reference_pass_name = "ssa",
83289 + .ref_pass_instance_number = 1,
83290 + .pos_op = PASS_POS_INSERT_AFTER
83291 + };
83292 + struct register_pass_info kernexec_retaddr_pass_info = {
83293 + .pass = &kernexec_retaddr_pass.pass,
83294 + .reference_pass_name = "pro_and_epilogue",
83295 + .ref_pass_instance_number = 1,
83296 + .pos_op = PASS_POS_INSERT_AFTER
83297 + };
83298 +
83299 + if (!plugin_default_version_check(version, &gcc_version)) {
83300 + error(G_("incompatible gcc/plugin versions"));
83301 + return 1;
83302 + }
83303 +
83304 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83305 +
83306 + if (TARGET_64BIT == 0)
83307 + return 0;
83308 +
83309 + for (i = 0; i < argc; ++i) {
83310 + if (!strcmp(argv[i].key, "method")) {
83311 + if (!argv[i].value) {
83312 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83313 + continue;
83314 + }
83315 + if (!strcmp(argv[i].value, "bts")) {
83316 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83317 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83318 + } else if (!strcmp(argv[i].value, "or")) {
83319 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83320 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83321 + fix_register("r10", 1, 1);
83322 + } else
83323 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83324 + continue;
83325 + }
83326 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83327 + }
83328 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83329 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83330 +
83331 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83332 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83333 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83334 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83335 +
83336 + return 0;
83337 +}
83338 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83339 new file mode 100644
83340 index 0000000..b8008f7
83341 --- /dev/null
83342 +++ b/tools/gcc/latent_entropy_plugin.c
83343 @@ -0,0 +1,295 @@
83344 +/*
83345 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83346 + * Licensed under the GPL v2
83347 + *
83348 + * Note: the choice of the license means that the compilation process is
83349 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83350 + * but for the kernel it doesn't matter since it doesn't link against
83351 + * any of the gcc libraries
83352 + *
83353 + * gcc plugin to help generate a little bit of entropy from program state,
83354 + * used during boot in the kernel
83355 + *
83356 + * TODO:
83357 + * - add ipa pass to identify not explicitly marked candidate functions
83358 + * - mix in more program state (function arguments/return values, loop variables, etc)
83359 + * - more instrumentation control via attribute parameters
83360 + *
83361 + * BUGS:
83362 + * - LTO needs -flto-partition=none for now
83363 + */
83364 +#include "gcc-plugin.h"
83365 +#include "config.h"
83366 +#include "system.h"
83367 +#include "coretypes.h"
83368 +#include "tree.h"
83369 +#include "tree-pass.h"
83370 +#include "flags.h"
83371 +#include "intl.h"
83372 +#include "toplev.h"
83373 +#include "plugin.h"
83374 +//#include "expr.h" where are you...
83375 +#include "diagnostic.h"
83376 +#include "plugin-version.h"
83377 +#include "tm.h"
83378 +#include "function.h"
83379 +#include "basic-block.h"
83380 +#include "gimple.h"
83381 +#include "rtl.h"
83382 +#include "emit-rtl.h"
83383 +#include "tree-flow.h"
83384 +
83385 +int plugin_is_GPL_compatible;
83386 +
83387 +static tree latent_entropy_decl;
83388 +
83389 +static struct plugin_info latent_entropy_plugin_info = {
83390 + .version = "201207271820",
83391 + .help = NULL
83392 +};
83393 +
83394 +static unsigned int execute_latent_entropy(void);
83395 +static bool gate_latent_entropy(void);
83396 +
83397 +static struct gimple_opt_pass latent_entropy_pass = {
83398 + .pass = {
83399 + .type = GIMPLE_PASS,
83400 + .name = "latent_entropy",
83401 + .gate = gate_latent_entropy,
83402 + .execute = execute_latent_entropy,
83403 + .sub = NULL,
83404 + .next = NULL,
83405 + .static_pass_number = 0,
83406 + .tv_id = TV_NONE,
83407 + .properties_required = PROP_gimple_leh | PROP_cfg,
83408 + .properties_provided = 0,
83409 + .properties_destroyed = 0,
83410 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83411 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83412 + }
83413 +};
83414 +
83415 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83416 +{
83417 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83418 + *no_add_attrs = true;
83419 + error("%qE attribute only applies to functions", name);
83420 + }
83421 + return NULL_TREE;
83422 +}
83423 +
83424 +static struct attribute_spec latent_entropy_attr = {
83425 + .name = "latent_entropy",
83426 + .min_length = 0,
83427 + .max_length = 0,
83428 + .decl_required = true,
83429 + .type_required = false,
83430 + .function_type_required = false,
83431 + .handler = handle_latent_entropy_attribute,
83432 +#if BUILDING_GCC_VERSION >= 4007
83433 + .affects_type_identity = false
83434 +#endif
83435 +};
83436 +
83437 +static void register_attributes(void *event_data, void *data)
83438 +{
83439 + register_attribute(&latent_entropy_attr);
83440 +}
83441 +
83442 +static bool gate_latent_entropy(void)
83443 +{
83444 + tree latent_entropy_attr;
83445 +
83446 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83447 + return latent_entropy_attr != NULL_TREE;
83448 +}
83449 +
83450 +static unsigned HOST_WIDE_INT seed;
83451 +static unsigned HOST_WIDE_INT get_random_const(void)
83452 +{
83453 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83454 + return seed;
83455 +}
83456 +
83457 +static enum tree_code get_op(tree *rhs)
83458 +{
83459 + static enum tree_code op;
83460 + unsigned HOST_WIDE_INT random_const;
83461 +
83462 + random_const = get_random_const();
83463 +
83464 + switch (op) {
83465 + case BIT_XOR_EXPR:
83466 + op = PLUS_EXPR;
83467 + break;
83468 +
83469 + case PLUS_EXPR:
83470 + if (rhs) {
83471 + op = LROTATE_EXPR;
83472 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83473 + break;
83474 + }
83475 +
83476 + case LROTATE_EXPR:
83477 + default:
83478 + op = BIT_XOR_EXPR;
83479 + break;
83480 + }
83481 + if (rhs)
83482 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83483 + return op;
83484 +}
83485 +
83486 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83487 +{
83488 + gimple_stmt_iterator gsi;
83489 + gimple assign;
83490 + tree addxorrol, rhs;
83491 + enum tree_code op;
83492 +
83493 + op = get_op(&rhs);
83494 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83495 + assign = gimple_build_assign(local_entropy, addxorrol);
83496 + find_referenced_vars_in(assign);
83497 +//debug_bb(bb);
83498 + gsi = gsi_after_labels(bb);
83499 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83500 + update_stmt(assign);
83501 +}
83502 +
83503 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83504 +{
83505 + gimple_stmt_iterator gsi;
83506 + gimple assign;
83507 + tree addxorrol, temp;
83508 +
83509 + // 1. create temporary copy of latent_entropy
83510 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83511 + add_referenced_var(temp);
83512 + mark_sym_for_renaming(temp);
83513 +
83514 + // 2. read...
83515 + assign = gimple_build_assign(temp, latent_entropy_decl);
83516 + find_referenced_vars_in(assign);
83517 + gsi = gsi_after_labels(bb);
83518 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83519 + update_stmt(assign);
83520 +
83521 + // 3. ...modify...
83522 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83523 + assign = gimple_build_assign(temp, addxorrol);
83524 + find_referenced_vars_in(assign);
83525 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83526 + update_stmt(assign);
83527 +
83528 + // 4. ...write latent_entropy
83529 + assign = gimple_build_assign(latent_entropy_decl, temp);
83530 + find_referenced_vars_in(assign);
83531 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83532 + update_stmt(assign);
83533 +}
83534 +
83535 +static unsigned int execute_latent_entropy(void)
83536 +{
83537 + basic_block bb;
83538 + gimple assign;
83539 + gimple_stmt_iterator gsi;
83540 + tree local_entropy;
83541 +
83542 + if (!latent_entropy_decl) {
83543 + struct varpool_node *node;
83544 +
83545 + for (node = varpool_nodes; node; node = node->next) {
83546 + tree var = node->decl;
83547 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83548 + continue;
83549 + latent_entropy_decl = var;
83550 +// debug_tree(var);
83551 + break;
83552 + }
83553 + if (!latent_entropy_decl) {
83554 +// debug_tree(current_function_decl);
83555 + return 0;
83556 + }
83557 + }
83558 +
83559 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83560 +
83561 + // 1. create local entropy variable
83562 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83563 + add_referenced_var(local_entropy);
83564 + mark_sym_for_renaming(local_entropy);
83565 +
83566 + // 2. initialize local entropy variable
83567 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83568 + if (dom_info_available_p(CDI_DOMINATORS))
83569 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83570 + gsi = gsi_start_bb(bb);
83571 +
83572 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83573 +// gimple_set_location(assign, loc);
83574 + find_referenced_vars_in(assign);
83575 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83576 + update_stmt(assign);
83577 + bb = bb->next_bb;
83578 +
83579 + // 3. instrument each BB with an operation on the local entropy variable
83580 + while (bb != EXIT_BLOCK_PTR) {
83581 + perturb_local_entropy(bb, local_entropy);
83582 + bb = bb->next_bb;
83583 + };
83584 +
83585 + // 4. mix local entropy into the global entropy variable
83586 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83587 + return 0;
83588 +}
83589 +
83590 +static void start_unit_callback(void *gcc_data, void *user_data)
83591 +{
83592 +#if BUILDING_GCC_VERSION >= 4007
83593 + seed = get_random_seed(false);
83594 +#else
83595 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83596 + seed *= seed;
83597 +#endif
83598 +
83599 + if (in_lto_p)
83600 + return;
83601 +
83602 + // extern u64 latent_entropy
83603 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83604 +
83605 + TREE_STATIC(latent_entropy_decl) = 1;
83606 + TREE_PUBLIC(latent_entropy_decl) = 1;
83607 + TREE_USED(latent_entropy_decl) = 1;
83608 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83609 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83610 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83611 + DECL_INITIAL(latent_entropy_decl) = NULL;
83612 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83613 +// varpool_finalize_decl(latent_entropy_decl);
83614 +// varpool_mark_needed_node(latent_entropy_decl);
83615 +}
83616 +
83617 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83618 +{
83619 + const char * const plugin_name = plugin_info->base_name;
83620 + struct register_pass_info latent_entropy_pass_info = {
83621 + .pass = &latent_entropy_pass.pass,
83622 + .reference_pass_name = "optimized",
83623 + .ref_pass_instance_number = 1,
83624 + .pos_op = PASS_POS_INSERT_BEFORE
83625 + };
83626 +
83627 + if (!plugin_default_version_check(version, &gcc_version)) {
83628 + error(G_("incompatible gcc/plugin versions"));
83629 + return 1;
83630 + }
83631 +
83632 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83633 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83634 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83635 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83636 +
83637 + return 0;
83638 +}
83639 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83640 new file mode 100644
83641 index 0000000..9332f17
83642 --- /dev/null
83643 +++ b/tools/gcc/size_overflow_hash.data
83644 @@ -0,0 +1,3597 @@
83645 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
83646 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
83647 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
83648 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
83649 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
83650 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
83651 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
83652 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
83653 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
83654 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
83655 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
83656 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
83657 +_000014_hash kmemdup 2 64015 _000014_hash NULL
83658 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
83659 +_000016_hash memdup_user 2 59590 _000016_hash NULL
83660 +_000017_hash module_alloc 1 63630 _000017_hash NULL
83661 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
83662 +_000019_hash read_kcore 3 63488 _000019_hash NULL
83663 +_000020_hash read_ldt 2 47570 _000020_hash NULL
83664 +_000021_hash read_zero 3 19366 _000021_hash NULL
83665 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
83666 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
83667 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
83668 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
83669 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
83670 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
83671 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
83672 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
83673 +_000031_hash adu_write 3 30487 _000031_hash NULL
83674 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
83675 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
83676 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
83677 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
83678 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
83679 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
83680 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
83681 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
83682 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
83683 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
83684 +_000044_hash alloc_context 1 3194 _000044_hash NULL
83685 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
83686 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
83687 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
83688 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
83689 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
83690 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
83691 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
83692 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
83693 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
83694 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
83695 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
83696 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
83697 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
83698 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
83699 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
83700 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
83701 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
83702 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
83703 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
83704 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
83705 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
83706 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
83707 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
83708 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
83709 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
83710 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
83711 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
83712 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
83713 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
83714 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
83715 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
83716 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
83717 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
83718 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
83719 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
83720 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
83721 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
83722 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
83723 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
83724 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
83725 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
83726 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
83727 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
83728 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
83729 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
83730 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
83731 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
83732 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
83733 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
83734 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
83735 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
83736 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
83737 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
83738 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
83739 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
83740 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
83741 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
83742 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
83743 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
83744 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
83745 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
83746 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
83747 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
83748 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
83749 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
83750 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
83751 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
83752 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
83753 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
83754 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
83755 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
83756 +_000122_hash change_xattr 5 61390 _000122_hash NULL
83757 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
83758 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
83759 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
83760 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
83761 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
83762 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
83763 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
83764 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
83765 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
83766 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
83767 +_000133_hash cmm_write 3 2896 _000133_hash NULL
83768 +_000134_hash cm_write 3 36858 _000134_hash NULL
83769 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
83770 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
83771 +_000137_hash command_file_write 3 31318 _000137_hash NULL
83772 +_000138_hash command_write 3 58841 _000138_hash NULL
83773 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
83774 +_000140_hash concat_writev 3 21451 _000140_hash NULL
83775 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
83776 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
83777 +_000143_hash copy_items 6 50140 _000143_hash NULL
83778 +_000144_hash copy_macs 4 45534 _000144_hash NULL
83779 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
83780 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
83781 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
83782 +_000148_hash cosa_write 3 1774 _000148_hash NULL
83783 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
83784 +_000150_hash create_entry 2 33479 _000150_hash NULL
83785 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
83786 +_000153_hash create_xattr 5 54106 _000153_hash NULL
83787 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
83788 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
83789 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
83790 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
83791 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
83792 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
83793 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
83794 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
83795 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
83796 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
83797 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
83798 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
83799 +_000168_hash dev_config 3 8506 _000168_hash NULL
83800 +_000169_hash device_write 3 45156 _000169_hash NULL
83801 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
83802 +_000171_hash devres_alloc 2 551 _000171_hash NULL
83803 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
83804 +_000173_hash direct_entry 3 38836 _000173_hash NULL
83805 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
83806 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
83807 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
83808 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
83809 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
83810 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
83811 +_000180_hash dm_read 3 15674 _000180_hash NULL
83812 +_000181_hash dm_write 3 2513 _000181_hash NULL
83813 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
83814 +_000183_hash dns_query 3 9676 _000183_hash NULL
83815 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
83816 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
83817 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
83818 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
83819 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
83820 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
83821 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
83822 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
83823 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
83824 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
83825 +_000194_hash dsp_write 2 46218 _000194_hash NULL
83826 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
83827 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
83828 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
83829 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
83830 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
83831 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
83832 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
83833 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
83834 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
83835 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
83836 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
83837 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
83838 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
83839 +_000208_hash ep_read 3 58813 _000208_hash NULL
83840 +_000209_hash ep_write 3 59008 _000209_hash NULL
83841 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
83842 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
83843 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
83844 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
83845 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
83846 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
83847 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
83848 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
83849 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
83850 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
83851 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
83852 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
83853 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
83854 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
83855 +_000225_hash fl_create 5 56435 _000225_hash NULL
83856 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
83857 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
83858 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
83859 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
83860 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
83861 +_000231_hash get_arg 3 5694 _000231_hash NULL
83862 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
83863 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
83864 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
83865 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
83866 +_000236_hash get_registers 3 26187 _000236_hash NULL
83867 +_000237_hash get_scq 2 10897 _000237_hash NULL
83868 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
83869 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
83870 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
83871 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
83872 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
83873 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
83874 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
83875 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
83876 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
83877 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
83878 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
83879 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
83880 +_000250_hash handle_request 9 10024 _000250_hash NULL
83881 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
83882 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
83883 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
83884 +_000254_hash heap_init 2 49617 _000254_hash NULL
83885 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
83886 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
83887 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
83888 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
83889 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
83890 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
83891 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
83892 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
83893 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
83894 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
83895 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
83896 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
83897 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
83898 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
83899 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
83900 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
83901 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
83902 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
83903 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
83904 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
83905 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
83906 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
83907 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
83908 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
83909 +_000279_hash if_write 3 51756 _000279_hash NULL
83910 +_000280_hash ilo_write 3 64378 _000280_hash NULL
83911 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
83912 +_000282_hash init_data_container 1 60709 _000282_hash NULL
83913 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
83914 +_000284_hash insert_dent 7 65034 _000284_hash NULL
83915 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
83916 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
83917 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
83918 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
83919 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
83920 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
83921 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
83922 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
83923 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
83924 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
83925 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
83926 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
83927 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
83928 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
83929 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
83930 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
83931 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
83932 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
83933 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
83934 +_000304_hash isdn_read 3 50021 _000304_hash NULL
83935 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
83936 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
83937 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
83938 +_000308_hash iso_callback 3 43208 _000308_hash NULL
83939 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
83940 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
83941 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
83942 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
83943 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
83944 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
83945 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
83946 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
83947 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
83948 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
83949 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
83950 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
83951 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
83952 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
83953 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
83954 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
83955 +_000328_hash kone_receive 4 4690 _000328_hash NULL
83956 +_000329_hash kone_send 4 63435 _000329_hash NULL
83957 +_000330_hash krealloc 2 14908 _000330_hash NULL
83958 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
83959 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
83960 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
83961 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
83962 +_000335_hash kzalloc 1 54740 _000335_hash NULL
83963 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
83964 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
83965 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
83966 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
83967 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
83968 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
83969 +_000342_hash __lgread 4 31668 _000342_hash NULL
83970 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
83971 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
83972 +_000345_hash listxattr 3 12769 _000345_hash NULL
83973 +_000346_hash load_msg 2 95 _000346_hash NULL
83974 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
83975 +_000348_hash lp_write 3 9511 _000348_hash NULL
83976 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
83977 +_000350_hash mce_write 3 26201 _000350_hash NULL
83978 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
83979 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
83980 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
83981 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
83982 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
83983 +_000357_hash mem_rw 3 22085 _000357_hash NULL
83984 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
83985 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
83986 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
83987 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
83988 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
83989 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
83990 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
83991 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
83992 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
83993 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
83994 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
83995 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
83996 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
83997 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
83998 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
83999 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84000 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84001 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84002 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84003 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84004 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84005 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84006 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84007 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84008 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84009 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84010 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84011 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84012 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84013 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84014 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84015 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84016 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84017 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84018 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84019 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84020 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84021 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84022 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84023 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84024 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84025 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84026 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84027 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84028 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84029 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84030 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84031 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84032 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84033 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84034 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84035 +_000415_hash parse_command 2 37079 _000415_hash NULL
84036 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84037 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84038 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84039 +_000419_hash pg_write 3 40766 _000419_hash NULL
84040 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84041 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84042 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84043 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84044 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84045 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84046 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84047 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84048 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84049 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84050 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84051 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84052 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84053 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84054 +_000434_hash pp_read 3 33210 _000434_hash NULL
84055 +_000435_hash pp_write 3 39554 _000435_hash NULL
84056 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84057 +_000437_hash printer_write 3 60276 _000437_hash NULL
84058 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84059 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84060 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84061 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84062 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84063 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84064 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84065 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84066 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84067 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84068 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84069 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84070 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84071 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84072 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84073 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84074 +_000456_hash pt_write 3 40159 _000456_hash NULL
84075 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84076 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84077 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84078 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84079 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84080 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84081 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84082 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84083 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84084 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84085 +_000467_hash read 3 9397 _000467_hash NULL
84086 +_000468_hash read_buf 2 20469 _000468_hash NULL
84087 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84088 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84089 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84090 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84091 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84092 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84093 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84094 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84095 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84096 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84097 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84098 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84099 +_000481_hash revalidate 2 19043 _000481_hash NULL
84100 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84101 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84102 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84103 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84104 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84105 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84106 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84107 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84108 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84109 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84110 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84111 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84112 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84113 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84114 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84115 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84116 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84117 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84118 +_000500_hash savemem 3 58129 _000500_hash NULL
84119 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84120 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84121 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84122 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84123 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84124 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84125 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84126 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84127 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84128 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84129 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84130 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84131 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84132 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84133 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84134 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84135 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84136 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84137 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84138 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84139 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84140 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84141 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84142 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84143 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84144 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84145 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84146 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84147 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84148 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84149 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84150 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84151 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84152 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84153 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84154 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84155 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84156 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84157 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84158 +_000542_hash set_registers 3 53582 _000542_hash NULL
84159 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84160 +_000544_hash setup_req 3 5848 _000544_hash NULL
84161 +_000545_hash setxattr 4 37006 _000545_hash NULL
84162 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84163 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84164 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84165 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84166 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84167 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84168 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84169 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84170 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84171 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84172 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84173 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84174 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84175 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84176 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84177 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84178 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84179 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84180 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84181 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84182 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84183 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84184 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84185 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84186 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84187 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84188 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84189 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84190 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84191 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84192 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84193 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84194 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84195 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84196 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84197 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84198 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84199 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84200 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84201 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84202 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84203 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84204 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84205 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84206 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84207 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84208 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84209 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84210 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84211 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84212 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84213 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84214 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84215 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84216 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84217 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84218 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84219 +_000606_hash tower_write 3 8580 _000606_hash NULL
84220 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84221 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84222 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84223 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84224 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84225 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84226 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84227 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84228 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84229 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84230 +_000617_hash uea_request 4 47613 _000617_hash NULL
84231 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84232 +_000619_hash uio_write 3 43202 _000619_hash NULL
84233 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84234 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84235 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84236 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84237 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84238 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84239 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84240 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84241 +_000629_hash user_update 3 41332 _000629_hash NULL
84242 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84243 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84244 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84245 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84246 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84247 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84248 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84249 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84250 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84251 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84252 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84253 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84254 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84255 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84256 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84257 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84258 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84259 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84260 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84261 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84262 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84263 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84264 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84265 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84266 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84267 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84268 +_000659_hash write 3 62671 _000659_hash NULL
84269 +_000660_hash write_flush 3 50803 _000660_hash NULL
84270 +_000661_hash write_rio 3 54837 _000661_hash NULL
84271 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84272 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84273 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84274 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84275 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84276 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84277 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84278 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84279 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84280 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84281 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84282 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84283 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84284 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84285 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84286 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84287 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84288 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84289 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84290 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84291 +_000684_hash addtgt 3 54703 _000684_hash NULL
84292 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84293 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84294 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84295 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84296 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84297 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84298 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84299 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84300 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84301 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84302 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84303 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84304 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84305 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84306 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84307 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84308 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84309 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84310 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84311 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84312 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84313 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84314 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84315 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84316 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84317 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84318 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84319 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84320 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84321 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84322 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84323 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84324 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84325 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84326 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84327 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84328 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84329 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84330 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84331 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84332 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84333 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84334 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84335 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84336 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84337 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84338 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84339 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84340 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84341 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84342 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84343 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84344 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84345 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84346 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84347 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84348 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84349 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84350 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84351 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84352 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84353 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84354 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84355 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84356 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84357 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84358 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84359 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84360 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84361 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84362 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84363 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84364 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84365 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84366 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84367 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84368 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84369 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84370 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84371 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84372 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84373 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84374 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84375 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84376 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84377 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84378 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84379 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84380 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84381 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84382 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84383 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84384 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84385 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84386 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84387 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84388 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84389 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84390 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84391 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84392 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84393 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84394 +_000799_hash construct_key 3 11329 _000799_hash NULL
84395 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84396 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84397 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84398 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84399 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84400 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84401 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84402 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84403 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84404 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84405 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84406 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84407 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84408 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84409 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84410 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84411 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84412 +_000819_hash depth_write 3 3021 _000819_hash NULL
84413 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84414 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84415 +_000822_hash dev_write 3 7708 _000822_hash NULL
84416 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84417 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84418 +_000825_hash disconnect 4 32521 _000825_hash NULL
84419 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84420 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84421 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84422 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84423 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84424 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84425 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84426 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84427 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84428 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84429 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84430 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84431 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84432 +_000840_hash do_sync 1 9604 _000840_hash NULL
84433 +_000841_hash dup_array 3 33551 _000841_hash NULL
84434 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84435 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84436 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84437 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84438 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84439 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84440 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84441 +_000849_hash enable_write 3 30456 _000849_hash NULL
84442 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84443 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84444 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84445 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84446 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84447 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84448 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84449 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84450 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84451 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84452 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84453 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84454 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84455 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84456 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84457 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84458 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84459 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84460 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84461 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84462 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84463 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84464 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84465 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84466 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84467 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84468 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84469 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84470 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84471 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84472 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84473 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84474 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84475 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84476 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84477 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84478 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84479 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84480 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84481 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84482 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84483 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84484 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84485 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84486 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84487 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84488 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84489 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84490 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84491 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84492 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84493 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84494 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84495 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84496 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84497 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84498 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84499 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84500 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84501 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84502 +_000915_hash init_q 4 132 _000915_hash NULL
84503 +_000916_hash init_state 2 60165 _000916_hash NULL
84504 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84505 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84506 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84507 +_000920_hash interfaces 2 38859 _000920_hash NULL
84508 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84509 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84510 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84511 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84512 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84513 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84514 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84515 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84516 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84517 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84518 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84519 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84520 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84521 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84522 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84523 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84524 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84525 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84526 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84527 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84528 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84529 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84530 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84531 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84532 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84533 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84534 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84535 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84536 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84537 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84538 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84539 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84540 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84541 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84542 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84543 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84544 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84545 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84546 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84547 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84548 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84549 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84550 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84551 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84552 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84553 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84554 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84555 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84556 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84557 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84558 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84559 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84560 +_000977_hash lc_create 3 48662 _000977_hash NULL
84561 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84562 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84563 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84564 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84565 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84566 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84567 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84568 +_000985_hash mem_read 3 57631 _000985_hash NULL
84569 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84570 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84571 +_000988_hash mem_write 3 22232 _000988_hash NULL
84572 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84573 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84574 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84575 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84576 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84577 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84578 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84579 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84580 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84581 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84582 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84583 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84584 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84585 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84586 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84587 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84588 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84589 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84590 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84591 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84592 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84593 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84594 +_001014_hash new_dir 3 31919 _001014_hash NULL
84595 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84596 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84597 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84598 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84599 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84600 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
84601 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
84602 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
84603 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
84604 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
84605 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
84606 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
84607 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
84608 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
84609 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
84610 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
84611 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
84612 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
84613 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
84614 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
84615 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
84616 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
84617 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
84618 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
84619 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
84620 +_001046_hash osst_write 3 31581 _001046_hash NULL
84621 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
84622 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
84623 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
84624 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
84625 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
84626 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
84627 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
84628 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
84629 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
84630 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
84631 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
84632 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
84633 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
84634 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
84635 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
84636 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
84637 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
84638 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
84639 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
84640 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
84641 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
84642 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
84643 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
84644 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
84645 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
84646 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
84647 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
84648 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
84649 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
84650 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
84651 +_001083_hash proc_write 3 51003 _001083_hash NULL
84652 +_001084_hash profile_load 3 58267 _001084_hash NULL
84653 +_001085_hash profile_remove 3 8556 _001085_hash NULL
84654 +_001086_hash profile_replace 3 14652 _001086_hash NULL
84655 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
84656 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
84657 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
84658 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
84659 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
84660 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
84661 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
84662 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
84663 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
84664 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
84665 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
84666 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
84667 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
84668 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
84669 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
84670 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
84671 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
84672 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
84673 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
84674 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
84675 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
84676 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
84677 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
84678 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
84679 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
84680 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
84681 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
84682 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
84683 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
84684 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
84685 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
84686 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
84687 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
84688 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
84689 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
84690 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
84691 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
84692 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
84693 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
84694 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
84695 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
84696 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
84697 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
84698 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
84699 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
84700 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
84701 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
84702 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
84703 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
84704 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
84705 +_001139_hash self_check_write 5 50856 _001139_hash NULL
84706 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
84707 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
84708 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
84709 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
84710 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
84711 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
84712 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
84713 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
84714 +_001148_hash set_connectable 4 56458 _001148_hash NULL
84715 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
84716 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
84717 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
84718 +_001152_hash setkey 3 14987 _001152_hash NULL
84719 +_001153_hash set_le 4 30581 _001153_hash NULL
84720 +_001154_hash set_link_security 4 4502 _001154_hash NULL
84721 +_001155_hash set_local_name 4 55757 _001155_hash NULL
84722 +_001156_hash set_powered 4 12129 _001156_hash NULL
84723 +_001157_hash set_ssp 4 62411 _001157_hash NULL
84724 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
84725 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
84726 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
84727 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
84728 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
84729 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
84730 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
84731 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
84732 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
84733 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
84734 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
84735 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
84736 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
84737 +_001174_hash skb_pad 2 17302 _001174_hash NULL
84738 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
84739 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
84740 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
84741 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
84742 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
84743 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
84744 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
84745 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
84746 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
84747 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
84748 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
84749 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
84750 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
84751 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
84752 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
84753 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
84754 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
84755 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
84756 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
84757 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
84758 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
84759 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
84760 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
84761 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
84762 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
84763 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
84764 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
84765 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
84766 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
84767 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
84768 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
84769 +_001208_hash sound_write 3 5102 _001208_hash NULL
84770 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
84771 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
84772 +_001213_hash spidev_message 3 5518 _001213_hash NULL
84773 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
84774 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
84775 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
84776 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
84777 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
84778 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
84779 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
84780 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
84781 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
84782 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
84783 +_001227_hash st_write 3 16874 _001227_hash NULL
84784 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
84785 +_001229_hash symtab_init 2 61050 _001229_hash NULL
84786 +_001230_hash sys_bind 3 10799 _001230_hash NULL
84787 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
84788 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
84789 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
84790 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
84791 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
84792 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
84793 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
84794 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
84795 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
84796 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
84797 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
84798 +_001242_hash sys_select 1 38827 _001242_hash NULL
84799 +_001243_hash sys_semop 3 39457 _001243_hash NULL
84800 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
84801 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
84802 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
84803 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
84804 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
84805 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
84806 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
84807 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
84808 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
84809 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
84810 +_001254_hash timeout_write 3 50991 _001254_hash NULL
84811 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
84812 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
84813 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
84814 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
84815 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
84816 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
84817 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
84818 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
84819 +_001264_hash tty_write 3 5494 _001264_hash NULL
84820 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
84821 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
84822 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
84823 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
84824 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
84825 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
84826 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
84827 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
84828 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
84829 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
84830 +_001277_hash vhci_write 3 2224 _001277_hash NULL
84831 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
84832 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
84833 +_001281_hash vmalloc 1 15464 _001281_hash NULL
84834 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
84835 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
84836 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
84837 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
84838 +_001286_hash vzalloc 1 47421 _001286_hash NULL
84839 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
84840 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
84841 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
84842 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
84843 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
84844 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
84845 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
84846 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
84847 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
84848 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
84849 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
84850 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
84851 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
84852 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
84853 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
84854 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
84855 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
84856 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
84857 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
84858 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
84859 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
84860 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
84861 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
84862 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
84863 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
84864 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
84865 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
84866 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
84867 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
84868 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
84869 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
84870 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
84871 +_001319_hash add_child 4 45201 _001319_hash NULL
84872 +_001320_hash add_port 2 54941 _001320_hash NULL
84873 +_001321_hash adu_read 3 24177 _001321_hash NULL
84874 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
84875 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
84876 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
84877 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
84878 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
84879 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
84880 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
84881 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
84882 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
84883 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
84884 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
84885 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
84886 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
84887 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
84888 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
84889 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
84890 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
84891 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
84892 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
84893 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
84894 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
84895 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
84896 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
84897 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
84898 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
84899 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
84900 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
84901 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
84902 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
84903 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
84904 +_001356_hash async_setkey 3 35521 _001356_hash NULL
84905 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
84906 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
84907 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
84908 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
84909 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
84910 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
84911 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
84912 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
84913 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
84914 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
84915 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
84916 +_001370_hash ax25_output 2 22736 _001370_hash NULL
84917 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
84918 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
84919 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
84920 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
84921 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
84922 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
84923 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
84924 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
84925 +_001380_hash bm_init 2 13529 _001380_hash NULL
84926 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
84927 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
84928 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
84929 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
84930 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
84931 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
84932 +_001387_hash cache_read 3 24790 _001387_hash NULL
84933 +_001388_hash cache_write 3 13589 _001388_hash NULL
84934 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
84935 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
84936 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
84937 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
84938 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
84939 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
84940 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
84941 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
84942 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
84943 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
84944 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
84945 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
84946 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
84947 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
84948 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
84949 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
84950 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
84951 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
84952 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
84953 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
84954 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
84955 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
84956 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
84957 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
84958 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
84959 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
84960 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
84961 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
84962 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
84963 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
84964 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
84965 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
84966 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
84967 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
84968 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
84969 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
84970 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
84971 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
84972 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
84973 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
84974 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
84975 +_001435_hash do_readlink 2 43518 _001435_hash NULL
84976 +_001436_hash __do_replace 5 37227 _001436_hash NULL
84977 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
84978 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
84979 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
84980 +_001440_hash dump_midi 3 51040 _001440_hash NULL
84981 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
84982 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
84983 +_001443_hash ep0_read 3 38095 _001443_hash NULL
84984 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
84985 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
84986 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
84987 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
84988 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
84989 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
84990 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
84991 +_001451_hash filldir 3 55137 _001451_hash NULL
84992 +_001452_hash filldir64 3 46469 _001452_hash NULL
84993 +_001453_hash find_skb 2 20431 _001453_hash NULL
84994 +_001454_hash from_buffer 3 18625 _001454_hash NULL
84995 +_001455_hash fsm_init 2 16134 _001455_hash NULL
84996 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
84997 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
84998 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
84999 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85000 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85001 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85002 +_001462_hash get_packet 3 41914 _001462_hash NULL
85003 +_001463_hash get_packet 3 5747 _001463_hash NULL
85004 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85005 +_001465_hash get_skb 2 63008 _001465_hash NULL
85006 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85007 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85008 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85009 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85010 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85011 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85012 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85013 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85014 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85015 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85016 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85017 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85018 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85019 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85020 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85021 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85022 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85023 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85024 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85025 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85026 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85027 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85028 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85029 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85030 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85031 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85032 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85033 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85034 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85035 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85036 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85037 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85038 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85039 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85040 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85041 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85042 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85043 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85044 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85045 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85046 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85047 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85048 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85049 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85050 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85051 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85052 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85053 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85054 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85055 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85056 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85057 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85058 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85059 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85060 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85061 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85062 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85063 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85064 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85065 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85066 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85067 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85068 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85069 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85070 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85071 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85072 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85073 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85074 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85075 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85076 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85077 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85078 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85079 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85080 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85081 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85082 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85083 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85084 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85085 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85086 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85087 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85088 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85089 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85090 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85091 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85092 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85093 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85094 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85095 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85096 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85097 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85098 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85099 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85100 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85101 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85102 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85103 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85104 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85105 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85106 +_001575_hash new_skb 1 21148 _001575_hash NULL
85107 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85108 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85109 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85110 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85111 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85112 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85113 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85114 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85115 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85116 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85117 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85118 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85119 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85120 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85121 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85122 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85123 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85124 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85125 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85126 +_001599_hash override_release 2 52032 _001599_hash NULL
85127 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85128 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85129 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85130 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85131 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85132 +_001605_hash pg_read 3 17276 _001605_hash NULL
85133 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85134 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85135 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85136 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85137 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85138 +_001611_hash printer_read 3 54851 _001611_hash NULL
85139 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85140 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85141 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85142 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85143 +_001616_hash pt_read 3 49136 _001616_hash NULL
85144 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85145 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85146 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85147 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85148 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85149 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85150 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85151 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85152 +_001625_hash read_flush 3 43851 _001625_hash NULL
85153 +_001626_hash read_profile 3 27859 _001626_hash NULL
85154 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85155 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85156 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85157 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85158 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85159 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85160 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85161 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85162 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85163 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85164 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85165 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85166 +_001640_hash rx 4 57944 _001640_hash NULL
85167 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85168 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85169 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85170 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85171 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85172 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85173 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85174 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85175 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85176 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85177 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85178 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85179 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85180 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85181 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85182 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85183 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85184 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85185 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85186 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85187 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85188 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85189 +_001663_hash send_command 4 10832 _001663_hash NULL
85190 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85191 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85192 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85193 +_001667_hash set_arg 3 42824 _001667_hash NULL
85194 +_001668_hash sg_read 3 25799 _001668_hash NULL
85195 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85196 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85197 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85198 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85199 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85200 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85201 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85202 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85203 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85204 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85205 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85206 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85207 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85208 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85209 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85210 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85211 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85212 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85213 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85214 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85215 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85216 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85217 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85218 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85219 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85220 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85221 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85222 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85223 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85224 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85225 +_001704_hash store_msg 3 56417 _001704_hash NULL
85226 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85227 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85228 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85229 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85230 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85231 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85232 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85233 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85234 +_001713_hash syslog_print 2 307 _001713_hash NULL
85235 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85236 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85237 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85238 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85239 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85240 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85241 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85242 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85243 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85244 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85245 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85246 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85247 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85248 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85249 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85250 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85251 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85252 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85253 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85254 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85255 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85256 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85257 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85258 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85259 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85260 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85261 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85262 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85263 +_001746_hash uio_read 3 49300 _001746_hash NULL
85264 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85265 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85266 +_001749_hash unlink1 3 63059 _001749_hash NULL
85267 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85268 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85269 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85270 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85271 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85272 +_001756_hash user_read 3 51881 _001756_hash NULL
85273 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85274 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85275 +_001759_hash venus_create 4 20555 _001759_hash NULL
85276 +_001760_hash venus_link 5 32165 _001760_hash NULL
85277 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85278 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85279 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85280 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85281 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85282 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85283 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85284 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85285 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85286 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85287 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85288 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85289 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85290 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85291 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85292 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85293 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85294 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85295 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85296 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85297 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85298 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85299 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85300 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85301 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85302 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85303 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85304 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85305 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85306 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85307 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85308 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85309 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85310 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85311 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85312 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85313 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85314 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85315 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85316 +_001803_hash add_partition 2 55588 _001803_hash NULL
85317 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85318 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85319 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85320 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85321 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85322 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85323 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85324 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85325 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85326 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85327 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85328 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85329 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85330 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85331 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85332 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85333 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85334 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85335 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85336 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85337 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85338 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85339 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85340 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85341 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85342 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85343 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85344 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85345 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85346 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85347 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85348 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85349 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85350 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85351 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85352 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85353 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85354 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85355 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85356 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85357 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85358 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85359 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85360 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85361 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85362 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85363 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85364 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85365 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85366 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85367 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85368 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85369 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85370 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85371 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85372 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85373 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85374 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85375 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85376 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85377 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85378 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85379 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85380 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85381 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85382 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85383 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85384 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85385 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85386 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85387 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85388 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85389 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85390 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85391 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85392 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85393 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85394 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85395 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85396 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85397 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85398 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85399 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85400 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85401 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85402 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85403 +_001892_hash check_header 2 56930 _001892_hash NULL
85404 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85405 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85406 +_001895_hash console_store 4 36007 _001895_hash NULL
85407 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85408 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85409 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85410 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85411 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85412 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85413 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85414 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85415 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85416 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85417 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85418 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85419 +_001912_hash debug_output 3 18575 _001912_hash NULL
85420 +_001913_hash debug_read 3 19322 _001913_hash NULL
85421 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85422 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85423 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85424 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85425 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85426 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85427 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85428 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85429 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85430 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85431 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85432 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85433 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85434 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85435 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85436 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85437 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85438 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85439 +_001933_hash filter_read 3 61692 _001933_hash NULL
85440 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85441 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85442 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85443 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85444 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85445 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85446 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85447 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85448 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85449 +_001943_hash handle_response 5 55951 _001943_hash NULL
85450 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85451 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85452 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85453 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85454 +_001948_hash help 4 14971 _001948_hash NULL
85455 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85456 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85457 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85458 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85459 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85460 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85461 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85462 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85463 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85464 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85465 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85466 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85467 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85468 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85469 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85470 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85471 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85472 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85473 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85474 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85475 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85476 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85477 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85478 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85479 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85480 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85481 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85482 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85483 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85484 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85485 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85486 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85487 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85488 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85489 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85490 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85491 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85492 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85493 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85494 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85495 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85496 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85497 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85498 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85499 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85500 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85501 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85502 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85503 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85504 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85505 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85506 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85507 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85508 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85509 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85510 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85511 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85512 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85513 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85514 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85515 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85516 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85517 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85518 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85519 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85520 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85521 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85522 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85523 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85524 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85525 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85526 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85527 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85528 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85529 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85530 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85531 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85532 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85533 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85534 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85535 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85536 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85537 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85538 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85539 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85540 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85541 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85542 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85543 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85544 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85545 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85546 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85547 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85548 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85549 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85550 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85551 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85552 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85553 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85554 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85555 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85556 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85557 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85558 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85559 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85560 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85561 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85562 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85563 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85564 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85565 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85566 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85567 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85568 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85569 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85570 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85571 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85572 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85573 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85574 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85575 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85576 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85577 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85578 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85579 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85580 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85581 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85582 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85583 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85584 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85585 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85586 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85587 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85588 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85589 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85590 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85591 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85592 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85593 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85594 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85595 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85596 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85597 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85598 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85599 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85600 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
85601 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
85602 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
85603 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
85604 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
85605 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
85606 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
85607 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
85608 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
85609 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
85610 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
85611 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
85612 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
85613 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
85614 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
85615 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
85616 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
85617 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
85618 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
85619 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
85620 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
85621 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
85622 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
85623 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
85624 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
85625 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
85626 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
85627 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
85628 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
85629 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
85630 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
85631 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
85632 +_002136_hash osst_read 3 40237 _002136_hash NULL
85633 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
85634 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
85635 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
85636 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
85637 +_002143_hash page_readlink 3 23346 _002143_hash NULL
85638 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
85639 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
85640 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
85641 +_002148_hash pep_reply 5 50582 _002148_hash NULL
85642 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
85643 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
85644 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
85645 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
85646 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
85647 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
85648 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
85649 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
85650 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
85651 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
85652 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
85653 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
85654 +_002161_hash proc_read 3 43614 _002161_hash NULL
85655 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
85656 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
85657 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
85658 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
85659 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
85660 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
85661 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
85662 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
85663 +_002170_hash queues_read 3 24877 _002170_hash NULL
85664 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
85665 +_002172_hash rcname_read 3 25919 _002172_hash NULL
85666 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
85667 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
85668 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
85669 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
85670 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
85671 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
85672 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
85673 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
85674 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
85675 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
85676 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
85677 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
85678 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
85679 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
85680 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
85681 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
85682 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
85683 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
85684 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
85685 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
85686 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
85687 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
85688 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
85689 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
85690 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
85691 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
85692 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
85693 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
85694 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
85695 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
85696 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
85697 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
85698 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
85699 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
85700 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
85701 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
85702 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
85703 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
85704 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
85705 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
85706 +_002213_hash receive_packet 2 12367 _002213_hash NULL
85707 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
85708 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
85709 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
85710 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
85711 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
85712 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
85713 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
85714 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
85715 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
85716 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
85717 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
85718 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
85719 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
85720 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
85721 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
85722 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
85723 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
85724 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
85725 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
85726 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
85727 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
85728 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
85729 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
85730 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
85731 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
85732 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
85733 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
85734 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
85735 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
85736 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
85737 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
85738 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
85739 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
85740 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
85741 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
85742 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
85743 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
85744 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
85745 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
85746 +_002254_hash send_msg 4 37323 _002254_hash NULL
85747 +_002255_hash send_packet 4 52960 _002255_hash NULL
85748 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
85749 +_002257_hash sge_rx 3 50594 _002257_hash NULL
85750 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
85751 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
85752 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
85753 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
85754 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
85755 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
85756 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
85757 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
85758 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
85759 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
85760 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
85761 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
85762 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
85763 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
85764 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
85765 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
85766 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
85767 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
85768 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
85769 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
85770 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
85771 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
85772 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
85773 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
85774 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
85775 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
85776 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
85777 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
85778 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
85779 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
85780 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
85781 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
85782 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
85783 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
85784 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
85785 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
85786 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
85787 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
85788 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
85789 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
85790 +_002306_hash st_read 3 51251 _002306_hash NULL
85791 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
85792 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
85793 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
85794 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
85795 +_002311_hash sys_readv 3 50664 _002311_hash NULL
85796 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
85797 +_002313_hash sys_writev 3 28384 _002313_hash NULL
85798 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
85799 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
85800 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
85801 +_002317_hash teiup_create 3 43201 _002317_hash NULL
85802 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
85803 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
85804 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
85805 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
85806 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
85807 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
85808 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
85809 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
85810 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
85811 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
85812 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
85813 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
85814 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
85815 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
85816 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
85817 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
85818 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
85819 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
85820 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
85821 +_002341_hash um_idi_read 3 850 _002341_hash NULL
85822 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
85823 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
85824 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
85825 +_002345_hash use_pool 2 64607 _002345_hash NULL
85826 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
85827 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
85828 +_002348_hash vhci_read 3 47878 _002348_hash NULL
85829 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
85830 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
85831 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
85832 +_002353_hash waiters_read 3 40902 _002353_hash NULL
85833 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
85834 +_002355_hash write_pbl 4 59583 _002355_hash NULL
85835 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
85836 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
85837 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
85838 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
85839 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
85840 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
85841 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
85842 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
85843 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
85844 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
85845 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
85846 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
85847 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
85848 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
85849 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
85850 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
85851 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
85852 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
85853 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
85854 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
85855 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
85856 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
85857 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
85858 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
85859 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
85860 +_002382_hash bioset_create 1 5580 _002382_hash NULL
85861 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
85862 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
85863 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
85864 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
85865 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
85866 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
85867 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
85868 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
85869 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
85870 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
85871 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
85872 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
85873 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
85874 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
85875 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
85876 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
85877 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
85878 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
85879 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
85880 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
85881 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
85882 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
85883 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
85884 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
85885 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
85886 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
85887 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
85888 +_002411_hash depth_read 3 31112 _002411_hash NULL
85889 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
85890 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
85891 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
85892 +_002415_hash divas_write 3 63901 _002415_hash NULL
85893 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
85894 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
85895 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
85896 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
85897 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
85898 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
85899 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
85900 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
85901 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
85902 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
85903 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
85904 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
85905 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
85906 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
85907 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
85908 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
85909 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
85910 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
85911 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
85912 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
85913 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
85914 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
85915 +_002439_hash got_frame 2 16028 _002439_hash NULL
85916 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
85917 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
85918 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
85919 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
85920 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
85921 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
85922 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
85923 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
85924 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
85925 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
85926 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
85927 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
85928 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
85929 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
85930 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
85931 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
85932 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
85933 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
85934 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
85935 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
85936 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
85937 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
85938 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
85939 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
85940 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
85941 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
85942 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
85943 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
85944 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
85945 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
85946 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
85947 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
85948 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
85949 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
85950 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
85951 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
85952 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
85953 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
85954 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
85955 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
85956 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
85957 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
85958 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
85959 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
85960 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
85961 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
85962 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
85963 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
85964 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
85965 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
85966 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
85967 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
85968 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
85969 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
85970 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
85971 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
85972 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
85973 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
85974 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
85975 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
85976 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
85977 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
85978 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
85979 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
85980 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
85981 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
85982 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
85983 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
85984 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
85985 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
85986 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
85987 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
85988 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
85989 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
85990 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
85991 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
85992 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
85993 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
85994 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
85995 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
85996 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
85997 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
85998 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
85999 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86000 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86001 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86002 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86003 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86004 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86005 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86006 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86007 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86008 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86009 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86010 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86011 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86012 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86013 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86014 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86015 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86016 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86017 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86018 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86019 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86020 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86021 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86022 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86023 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86024 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86025 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86026 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86027 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86028 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86029 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86030 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86031 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86032 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86033 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86034 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86035 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86036 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86037 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86038 +_002570_hash map_addr 6 4666 _002570_hash NULL
86039 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86040 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86041 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86042 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86043 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86044 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86045 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86046 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86047 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86048 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86049 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86050 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86051 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86052 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86053 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86054 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86055 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86056 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86057 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86058 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86059 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86060 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86061 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86062 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86063 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86064 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86065 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86066 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86067 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86068 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86069 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86070 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86071 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86072 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86073 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86074 +_002612_hash power_read 3 15939 _002612_hash NULL
86075 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86076 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86077 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86078 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86079 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86080 +_002618_hash prison_create 1 43623 _002618_hash NULL
86081 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86082 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86083 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86084 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86085 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86086 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86087 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86088 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86089 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86090 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86091 +_002629_hash read_dma 3 55086 _002629_hash NULL
86092 +_002630_hash read_fifo 3 826 _002630_hash NULL
86093 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86094 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86095 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86096 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86097 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86098 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86099 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86100 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86101 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86102 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86103 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86104 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86105 +_002644_hash rx_data 4 60442 _002644_hash NULL
86106 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86107 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86108 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86109 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86110 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86111 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86112 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86113 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86114 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86115 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86116 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86117 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86118 +_002658_hash send_stream 4 3397 _002658_hash NULL
86119 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86120 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86121 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86122 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86123 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86124 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86125 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86126 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86127 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86128 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86129 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86130 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86131 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86132 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86133 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86134 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86135 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86136 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86137 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86138 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86139 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86140 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86141 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86142 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86143 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86144 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86145 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86146 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86147 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86148 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86149 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86150 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86151 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86152 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86153 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86154 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86155 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86156 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86157 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86158 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86159 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86160 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86161 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86162 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86163 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86164 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86165 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86166 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86167 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86168 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86169 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86170 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86171 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86172 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86173 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86174 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86175 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86176 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86177 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86178 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86179 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86180 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86181 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86182 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86183 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86184 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86185 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86186 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86187 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86188 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86189 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86190 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86191 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86192 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86193 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86194 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86195 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86196 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86197 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86198 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86199 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86200 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86201 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86202 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86203 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86204 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86205 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86206 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86207 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86208 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86209 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86210 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86211 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86212 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86213 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86214 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86215 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86216 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86217 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86218 +_002770_hash push_rx 3 28939 _002770_hash NULL
86219 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86220 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86221 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86222 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86223 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86224 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86225 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86226 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86227 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86228 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86229 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86230 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86231 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86232 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86233 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86234 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86235 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86236 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86237 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86238 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86239 +_002794_hash write_leb 5 36957 _002794_hash NULL
86240 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86241 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86242 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86243 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86244 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86245 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86246 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86247 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86248 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86249 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86250 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86251 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86252 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86253 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86254 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86255 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86256 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86257 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86258 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86259 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86260 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86261 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86262 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86263 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86264 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86265 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86266 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86267 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86268 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86269 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86270 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86271 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86272 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86273 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86274 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86275 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86276 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86277 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86278 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86279 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86280 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86281 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86282 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86283 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86284 +_002846_hash recover_head 3 17904 _002846_hash NULL
86285 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86286 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86287 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86288 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86289 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86290 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86291 +_002853_hash write_head 4 30481 _002853_hash NULL
86292 +_002854_hash write_node 4 33121 _002854_hash NULL
86293 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86294 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86295 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86296 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86297 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86298 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86299 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86300 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86301 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86302 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86303 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86304 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86305 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86306 +_002869_hash create_log 2 8225 _002869_hash NULL
86307 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86308 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86309 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86310 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86311 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86312 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86313 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86314 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86315 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86316 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86317 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86318 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86319 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86320 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86321 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86322 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86323 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86324 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86325 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86326 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86327 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86328 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86329 +_002893_hash _malloc 1 54077 _002893_hash NULL
86330 +_002894_hash mei_read 3 6507 _002894_hash NULL
86331 +_002895_hash mei_write 3 4005 _002895_hash NULL
86332 +_002896_hash msg_set 3 51725 _002896_hash NULL
86333 +_002897_hash newpart 6 47485 _002897_hash NULL
86334 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86335 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86336 +_002900_hash packet_came 3 18072 _002900_hash NULL
86337 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86338 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86339 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86340 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86341 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86342 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86343 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86344 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86345 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86346 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86347 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86348 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86349 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86350 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86351 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86352 +_002923_hash sep_read 3 17161 _002923_hash NULL
86353 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86354 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86355 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86356 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86357 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86358 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86359 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86360 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86361 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86362 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86363 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86364 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86365 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86366 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86367 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86368 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86369 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86370 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86371 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86372 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86373 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86374 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86375 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86376 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86377 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86378 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86379 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86380 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86381 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86382 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86383 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86384 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86385 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86386 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86387 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86388 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86389 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86390 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86391 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86392 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86393 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86394 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86395 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86396 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86397 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86398 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86399 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86400 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86401 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86402 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86403 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86404 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86405 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86406 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86407 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86408 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86409 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86410 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86411 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86412 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86413 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86414 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86415 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86416 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86417 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86418 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86419 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86420 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86421 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86422 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86423 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86424 +_003003_hash flash_read 3 57843 _003003_hash NULL
86425 +_003004_hash flash_write 3 62354 _003004_hash NULL
86426 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86427 +_003006_hash gather_array 3 56641 _003006_hash NULL
86428 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86429 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86430 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86431 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86432 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86433 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86434 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86435 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86436 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86437 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86438 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86439 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86440 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86441 +_003021_hash options_write 3 47243 _003021_hash NULL
86442 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86443 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86444 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86445 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86446 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86447 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86448 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86449 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86450 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86451 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86452 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86453 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86454 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86455 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86456 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86457 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86458 +_003038_hash split 2 11691 _003038_hash NULL
86459 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86460 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86461 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86462 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86463 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86464 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86465 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86466 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86467 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86468 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86469 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86470 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86471 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86472 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86473 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86474 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86475 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86476 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86477 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86478 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86479 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86480 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86481 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86482 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86483 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86484 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86485 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86486 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86487 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86488 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86489 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86490 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86491 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86492 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86493 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86494 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86495 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86496 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86497 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86498 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86499 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86500 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86501 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86502 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86503 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86504 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86505 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86506 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86507 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86508 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86509 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86510 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86511 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86512 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86513 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86514 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86515 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86516 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86517 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86518 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86519 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86520 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86521 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86522 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86523 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86524 +_003108_hash conf_read 3 55786 _003108_hash NULL
86525 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86526 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86527 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86528 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86529 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86530 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86531 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86532 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86533 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86534 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86535 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86536 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86537 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86538 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86539 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86540 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86541 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86542 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86543 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86544 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86545 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86546 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86547 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86548 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86549 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86550 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86551 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86552 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86553 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86554 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86555 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86556 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86557 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86558 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86559 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86560 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86561 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86562 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86563 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86564 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86565 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86566 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86567 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86568 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86569 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86570 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86571 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86572 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86573 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86574 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86575 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86576 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86577 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86578 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86579 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86580 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86581 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86582 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86583 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86584 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86585 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86586 +_003175_hash get_info 3 55681 _003175_hash NULL
86587 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86588 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86589 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86590 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86591 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86592 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86593 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86594 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86595 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86596 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86597 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86598 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86599 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86600 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
86601 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
86602 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
86603 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
86604 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
86605 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
86606 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
86607 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
86608 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
86609 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
86610 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
86611 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
86612 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
86613 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
86614 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
86615 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
86616 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
86617 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
86618 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
86619 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
86620 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
86621 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
86622 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
86623 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
86624 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
86625 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
86626 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
86627 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
86628 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
86629 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
86630 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
86631 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
86632 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
86633 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
86634 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
86635 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
86636 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
86637 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
86638 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
86639 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
86640 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
86641 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
86642 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
86643 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
86644 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
86645 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
86646 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
86647 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
86648 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
86649 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
86650 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
86651 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
86652 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
86653 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
86654 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
86655 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
86656 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
86657 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
86658 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
86659 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
86660 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
86661 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
86662 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
86663 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
86664 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
86665 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
86666 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
86667 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
86668 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
86669 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
86670 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
86671 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
86672 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
86673 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
86674 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
86675 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
86676 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
86677 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
86678 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
86679 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
86680 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
86681 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
86682 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
86683 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
86684 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
86685 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
86686 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
86687 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
86688 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
86689 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
86690 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
86691 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
86692 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
86693 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
86694 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
86695 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
86696 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
86697 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
86698 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
86699 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
86700 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
86701 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
86702 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
86703 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
86704 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
86705 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
86706 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
86707 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
86708 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
86709 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
86710 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
86711 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
86712 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
86713 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
86714 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
86715 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
86716 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
86717 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
86718 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
86719 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
86720 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
86721 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
86722 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
86723 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
86724 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
86725 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
86726 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
86727 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
86728 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
86729 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
86730 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
86731 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
86732 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
86733 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
86734 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
86735 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
86736 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
86737 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
86738 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
86739 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
86740 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
86741 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
86742 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
86743 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
86744 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
86745 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
86746 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
86747 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
86748 +_003340_hash alloc_private 2 22399 _003340_hash NULL
86749 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
86750 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
86751 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
86752 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
86753 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
86754 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
86755 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
86756 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
86757 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
86758 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
86759 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
86760 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
86761 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
86762 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
86763 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
86764 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
86765 +_003359_hash comedi_read 3 13199 _003359_hash NULL
86766 +_003360_hash comedi_write 3 47926 _003360_hash NULL
86767 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
86768 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
86769 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
86770 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
86771 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
86772 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
86773 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
86774 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
86775 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
86776 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
86777 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
86778 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
86779 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
86780 +_003377_hash dev_read 3 56369 _003377_hash NULL
86781 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
86782 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
86783 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
86784 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
86785 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
86786 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
86787 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
86788 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
86789 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
86790 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
86791 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
86792 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
86793 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
86794 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
86795 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
86796 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
86797 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
86798 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
86799 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
86800 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
86801 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
86802 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
86803 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
86804 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
86805 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
86806 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
86807 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
86808 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
86809 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
86810 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
86811 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
86812 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
86813 +_003412_hash fb_read 3 33506 _003412_hash NULL
86814 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
86815 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
86816 +_003415_hash fb_write 3 46924 _003415_hash NULL
86817 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
86818 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
86819 +_003418_hash fops_read 3 40672 _003418_hash NULL
86820 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
86821 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
86822 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
86823 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
86824 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
86825 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
86826 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
86827 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
86828 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
86829 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
86830 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
86831 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
86832 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
86833 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
86834 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
86835 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
86836 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
86837 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
86838 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
86839 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
86840 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
86841 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
86842 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
86843 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
86844 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
86845 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
86846 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
86847 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
86848 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
86849 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
86850 +_003451_hash lirc_write 3 20604 _003451_hash NULL
86851 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
86852 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
86853 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
86854 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
86855 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
86856 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
86857 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
86858 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
86859 +_003461_hash mmio_read 4 40348 _003461_hash NULL
86860 +_003462_hash netlink_send 5 38434 _003462_hash NULL
86861 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
86862 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
86863 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
86864 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
86865 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
86866 +_003468_hash odev_update 2 50169 _003468_hash NULL
86867 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
86868 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
86869 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
86870 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
86871 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
86872 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
86873 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
86874 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
86875 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
86876 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
86877 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
86878 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
86879 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
86880 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
86881 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
86882 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
86883 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
86884 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
86885 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
86886 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
86887 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
86888 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
86889 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
86890 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
86891 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
86892 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
86893 +_003497_hash play_iframe 3 8219 _003497_hash NULL
86894 +_003498_hash probes_write 3 29711 _003498_hash NULL
86895 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
86896 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
86897 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
86898 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
86899 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
86900 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
86901 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
86902 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
86903 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
86904 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
86905 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
86906 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
86907 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
86908 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
86909 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
86910 +_003514_hash qc_capture 3 19298 _003514_hash NULL
86911 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
86912 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
86913 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
86914 +_003518_hash Realloc 2 34961 _003518_hash NULL
86915 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
86916 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
86917 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
86918 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
86919 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
86920 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
86921 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
86922 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
86923 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
86924 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
86925 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
86926 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
86927 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
86928 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
86929 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
86930 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
86931 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
86932 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
86933 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
86934 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
86935 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
86936 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
86937 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
86938 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
86939 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
86940 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
86941 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
86942 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
86943 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
86944 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
86945 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
86946 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
86947 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
86948 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
86949 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
86950 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
86951 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
86952 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
86953 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
86954 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
86955 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
86956 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
86957 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
86958 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
86959 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
86960 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
86961 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
86962 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
86963 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
86964 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
86965 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
86966 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
86967 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
86968 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
86969 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
86970 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
86971 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
86972 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
86973 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
86974 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
86975 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
86976 +_003584_hash ts_read 3 44687 _003584_hash NULL
86977 +_003585_hash ts_write 3 64336 _003585_hash NULL
86978 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
86979 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
86980 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
86981 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
86982 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
86983 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
86984 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
86985 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
86986 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
86987 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
86988 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
86989 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
86990 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
86991 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
86992 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
86993 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
86994 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
86995 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
86996 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
86997 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
86998 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
86999 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87000 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87001 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87002 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87003 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87004 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87005 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87006 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87007 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87008 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87009 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87010 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87011 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87012 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87013 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87014 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87015 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87016 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87017 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87018 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87019 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87020 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87021 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87022 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87023 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87024 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87025 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87026 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87027 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87028 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87029 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87030 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87031 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87032 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87033 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87034 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87035 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87036 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87037 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87038 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87039 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87040 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87041 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87042 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87043 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87044 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87045 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87046 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87047 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87048 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87049 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87050 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87051 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87052 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87053 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87054 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87055 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87056 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87057 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87058 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87059 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87060 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87061 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87062 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87063 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87064 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87065 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87066 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87067 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87068 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87069 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87070 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87071 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87072 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87073 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87074 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87075 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87076 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87077 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87078 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87079 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87080 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87081 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87082 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87083 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87084 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87085 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87086 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87087 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87088 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87089 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87090 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87091 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87092 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87093 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87094 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87095 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87096 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87097 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87098 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87099 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87100 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87101 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87102 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87103 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87104 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87105 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87106 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87107 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87108 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87109 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87110 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87111 +_003729_hash vmap 2 15025 _003729_hash NULL
87112 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87113 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87114 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87115 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87116 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87117 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87118 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87119 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87120 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87121 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87122 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87123 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87124 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87125 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87126 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87127 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87128 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87129 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87130 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87131 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87132 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87133 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87134 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87135 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87136 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87137 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87138 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87139 +_003766_hash video_read 3 28148 _003766_hash NULL
87140 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87141 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87142 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87143 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87144 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87145 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87146 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87147 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87148 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87149 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87150 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87151 +_003783_hash do_test 1 15766 _003783_hash NULL
87152 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87153 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87154 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87155 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87156 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87157 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87158 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87159 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87160 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87161 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87162 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87163 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87164 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87165 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87166 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87167 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87168 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87169 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87170 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87171 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87172 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87173 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87174 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87175 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87176 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87177 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87178 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87179 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87180 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87181 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87182 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87183 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87184 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87185 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87186 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87187 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87188 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87189 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87190 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87191 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87192 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87193 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87194 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87195 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87196 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87197 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87198 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87199 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87200 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87201 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87202 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87203 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87204 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87205 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87206 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87207 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87208 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87209 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87210 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87211 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87212 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87213 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87214 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87215 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87216 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87217 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87218 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87219 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87220 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87221 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87222 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87223 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87224 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87225 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87226 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87227 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87228 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87229 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87230 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87231 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87232 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87233 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87234 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87235 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87236 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87237 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87238 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87239 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87240 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87241 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87242 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87243 new file mode 100644
87244 index 0000000..244559e
87245 --- /dev/null
87246 +++ b/tools/gcc/size_overflow_plugin.c
87247 @@ -0,0 +1,1879 @@
87248 +/*
87249 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87250 + * Licensed under the GPL v2, or (at your option) v3
87251 + *
87252 + * Homepage:
87253 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87254 + *
87255 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87256 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87257 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87258 + *
87259 + * Usage:
87260 + * $ 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
87261 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87262 + */
87263 +
87264 +#include "gcc-plugin.h"
87265 +#include "config.h"
87266 +#include "system.h"
87267 +#include "coretypes.h"
87268 +#include "tree.h"
87269 +#include "tree-pass.h"
87270 +#include "intl.h"
87271 +#include "plugin-version.h"
87272 +#include "tm.h"
87273 +#include "toplev.h"
87274 +#include "function.h"
87275 +#include "tree-flow.h"
87276 +#include "plugin.h"
87277 +#include "gimple.h"
87278 +#include "c-common.h"
87279 +#include "diagnostic.h"
87280 +#include "cfgloop.h"
87281 +
87282 +#if BUILDING_GCC_VERSION >= 4007
87283 +#include "c-tree.h"
87284 +#else
87285 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87286 +#endif
87287 +
87288 +struct size_overflow_hash {
87289 + const struct size_overflow_hash * const next;
87290 + const char * const name;
87291 + const unsigned int param;
87292 +};
87293 +
87294 +#include "size_overflow_hash.h"
87295 +
87296 +enum marked {
87297 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87298 +};
87299 +
87300 +#define __unused __attribute__((__unused__))
87301 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87302 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87303 +#define BEFORE_STMT true
87304 +#define AFTER_STMT false
87305 +#define CREATE_NEW_VAR NULL_TREE
87306 +#define CODES_LIMIT 32
87307 +#define MAX_PARAM 32
87308 +#define MY_STMT GF_PLF_1
87309 +#define NO_CAST_CHECK GF_PLF_2
87310 +
87311 +#if BUILDING_GCC_VERSION == 4005
87312 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87313 +#endif
87314 +
87315 +int plugin_is_GPL_compatible;
87316 +void debug_gimple_stmt(gimple gs);
87317 +
87318 +static tree expand(struct pointer_set_t *visited, tree lhs);
87319 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87320 +static tree report_size_overflow_decl;
87321 +static const_tree const_char_ptr_type_node;
87322 +static unsigned int handle_function(void);
87323 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87324 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87325 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87326 +
87327 +static struct plugin_info size_overflow_plugin_info = {
87328 + .version = "20120930beta",
87329 + .help = "no-size-overflow\tturn off size overflow checking\n",
87330 +};
87331 +
87332 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87333 +{
87334 + unsigned int arg_count;
87335 + enum tree_code code = TREE_CODE(*node);
87336 +
87337 + switch (code) {
87338 + case FUNCTION_DECL:
87339 + arg_count = type_num_arguments(TREE_TYPE(*node));
87340 + break;
87341 + case FUNCTION_TYPE:
87342 + case METHOD_TYPE:
87343 + arg_count = type_num_arguments(*node);
87344 + break;
87345 + default:
87346 + *no_add_attrs = true;
87347 + error("%s: %qE attribute only applies to functions", __func__, name);
87348 + return NULL_TREE;
87349 + }
87350 +
87351 + for (; args; args = TREE_CHAIN(args)) {
87352 + tree position = TREE_VALUE(args);
87353 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87354 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87355 + *no_add_attrs = true;
87356 + }
87357 + }
87358 + return NULL_TREE;
87359 +}
87360 +
87361 +static const char* get_asm_name(tree node)
87362 +{
87363 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87364 +}
87365 +
87366 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87367 +{
87368 + unsigned int arg_count, arg_num;
87369 + enum tree_code code = TREE_CODE(*node);
87370 +
87371 + switch (code) {
87372 + case FUNCTION_DECL:
87373 + arg_count = type_num_arguments(TREE_TYPE(*node));
87374 + break;
87375 + case FUNCTION_TYPE:
87376 + case METHOD_TYPE:
87377 + arg_count = type_num_arguments(*node);
87378 + break;
87379 + case FIELD_DECL:
87380 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87381 + if (arg_num != 0) {
87382 + *no_add_attrs = true;
87383 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87384 + }
87385 + return NULL_TREE;
87386 + default:
87387 + *no_add_attrs = true;
87388 + error("%qE attribute only applies to functions", name);
87389 + return NULL_TREE;
87390 + }
87391 +
87392 + for (; args; args = TREE_CHAIN(args)) {
87393 + tree position = TREE_VALUE(args);
87394 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87395 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87396 + *no_add_attrs = true;
87397 + }
87398 + }
87399 + return NULL_TREE;
87400 +}
87401 +
87402 +static struct attribute_spec size_overflow_attr = {
87403 + .name = "size_overflow",
87404 + .min_length = 1,
87405 + .max_length = -1,
87406 + .decl_required = true,
87407 + .type_required = false,
87408 + .function_type_required = false,
87409 + .handler = handle_size_overflow_attribute,
87410 +#if BUILDING_GCC_VERSION >= 4007
87411 + .affects_type_identity = false
87412 +#endif
87413 +};
87414 +
87415 +static struct attribute_spec intentional_overflow_attr = {
87416 + .name = "intentional_overflow",
87417 + .min_length = 1,
87418 + .max_length = -1,
87419 + .decl_required = true,
87420 + .type_required = false,
87421 + .function_type_required = false,
87422 + .handler = handle_intentional_overflow_attribute,
87423 +#if BUILDING_GCC_VERSION >= 4007
87424 + .affects_type_identity = false
87425 +#endif
87426 +};
87427 +
87428 +static void register_attributes(void __unused *event_data, void __unused *data)
87429 +{
87430 + register_attribute(&size_overflow_attr);
87431 + register_attribute(&intentional_overflow_attr);
87432 +}
87433 +
87434 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87435 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87436 +{
87437 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87438 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87439 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87440 +
87441 + unsigned int m = 0x57559429;
87442 + unsigned int n = 0x5052acdb;
87443 + const unsigned int *key4 = (const unsigned int *)key;
87444 + unsigned int h = len;
87445 + unsigned int k = len + seed + n;
87446 + unsigned long long p;
87447 +
87448 + while (len >= 8) {
87449 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87450 + len -= 8;
87451 + }
87452 + if (len >= 4) {
87453 + cwmixb(key4[0]) key4 += 1;
87454 + len -= 4;
87455 + }
87456 + if (len)
87457 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87458 + cwmixb(h ^ (k + n));
87459 + return k ^ h;
87460 +
87461 +#undef cwfold
87462 +#undef cwmixa
87463 +#undef cwmixb
87464 +}
87465 +
87466 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87467 +{
87468 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87469 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87470 + return fn ^ codes;
87471 +}
87472 +
87473 +static inline tree get_original_function_decl(tree fndecl)
87474 +{
87475 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87476 + return DECL_ABSTRACT_ORIGIN(fndecl);
87477 + return fndecl;
87478 +}
87479 +
87480 +static inline gimple get_def_stmt(const_tree node)
87481 +{
87482 + gcc_assert(node != NULL_TREE);
87483 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87484 + return SSA_NAME_DEF_STMT(node);
87485 +}
87486 +
87487 +static unsigned char get_tree_code(const_tree type)
87488 +{
87489 + switch (TREE_CODE(type)) {
87490 + case ARRAY_TYPE:
87491 + return 0;
87492 + case BOOLEAN_TYPE:
87493 + return 1;
87494 + case ENUMERAL_TYPE:
87495 + return 2;
87496 + case FUNCTION_TYPE:
87497 + return 3;
87498 + case INTEGER_TYPE:
87499 + return 4;
87500 + case POINTER_TYPE:
87501 + return 5;
87502 + case RECORD_TYPE:
87503 + return 6;
87504 + case UNION_TYPE:
87505 + return 7;
87506 + case VOID_TYPE:
87507 + return 8;
87508 + case REAL_TYPE:
87509 + return 9;
87510 + case VECTOR_TYPE:
87511 + return 10;
87512 + case REFERENCE_TYPE:
87513 + return 11;
87514 + case OFFSET_TYPE:
87515 + return 12;
87516 + case COMPLEX_TYPE:
87517 + return 13;
87518 + default:
87519 + debug_tree((tree)type);
87520 + gcc_unreachable();
87521 + }
87522 +}
87523 +
87524 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87525 +{
87526 + gcc_assert(type != NULL_TREE);
87527 +
87528 + while (type && len < CODES_LIMIT) {
87529 + tree_codes[len] = get_tree_code(type);
87530 + len++;
87531 + type = TREE_TYPE(type);
87532 + }
87533 + return len;
87534 +}
87535 +
87536 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87537 +{
87538 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87539 + enum tree_code code = TREE_CODE(type);
87540 + size_t len = 0;
87541 +
87542 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87543 +
87544 + arg = TYPE_ARG_TYPES(type);
87545 + // skip builtins __builtin_constant_p
87546 + if (!arg && DECL_BUILT_IN(fndecl))
87547 + return 0;
87548 +
87549 + if (TREE_CODE_CLASS(code) == tcc_type)
87550 + result = type;
87551 + else
87552 + result = DECL_RESULT(fndecl);
87553 +
87554 + gcc_assert(result != NULL_TREE);
87555 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87556 +
87557 + if (arg == NULL_TREE) {
87558 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87559 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87560 + if (arg_field == NULL_TREE)
87561 + return 0;
87562 + arg = TREE_TYPE(arg_field);
87563 + len = add_type_codes(arg, tree_codes, len);
87564 + gcc_assert(len != 0);
87565 + return len;
87566 + }
87567 +
87568 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87569 + while (arg && len < CODES_LIMIT) {
87570 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87571 + arg = TREE_CHAIN(arg);
87572 + }
87573 +
87574 + gcc_assert(len != 0);
87575 + return len;
87576 +}
87577 +
87578 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87579 +{
87580 + unsigned int hash;
87581 + const struct size_overflow_hash *entry;
87582 + unsigned char tree_codes[CODES_LIMIT];
87583 + size_t len;
87584 + const char *func_name = get_asm_name(fndecl);
87585 +
87586 + len = get_function_decl(fndecl, tree_codes);
87587 + if (len == 0)
87588 + return NULL;
87589 +
87590 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87591 +
87592 + entry = size_overflow_hash[hash];
87593 + while (entry) {
87594 + if (!strcmp(entry->name, func_name))
87595 + return entry;
87596 + entry = entry->next;
87597 + }
87598 +
87599 + return NULL;
87600 +}
87601 +
87602 +static void check_arg_type(const_tree arg)
87603 +{
87604 + const_tree type = TREE_TYPE(arg);
87605 + enum tree_code code = TREE_CODE(type);
87606 +
87607 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
87608 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
87609 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
87610 +}
87611 +
87612 +static int find_arg_number(const_tree arg, tree func)
87613 +{
87614 + tree var;
87615 + unsigned int argnum = 1;
87616 +
87617 + if (TREE_CODE(arg) == SSA_NAME)
87618 + arg = SSA_NAME_VAR(arg);
87619 +
87620 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
87621 + if (strcmp(NAME(arg), NAME(var))) {
87622 + argnum++;
87623 + continue;
87624 + }
87625 + check_arg_type(var);
87626 + return argnum;
87627 + }
87628 + gcc_unreachable();
87629 +}
87630 +
87631 +static tree create_new_var(tree type)
87632 +{
87633 + tree new_var = create_tmp_var(type, "cicus");
87634 +
87635 + add_referenced_var(new_var);
87636 + mark_sym_for_renaming(new_var);
87637 + return new_var;
87638 +}
87639 +
87640 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
87641 +{
87642 + gimple assign;
87643 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87644 + tree type = TREE_TYPE(rhs1);
87645 + tree lhs = create_new_var(type);
87646 +
87647 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
87648 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87649 +
87650 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87651 + update_stmt(assign);
87652 + gimple_set_plf(assign, MY_STMT, true);
87653 + return assign;
87654 +}
87655 +
87656 +static bool is_bool(const_tree node)
87657 +{
87658 + const_tree type;
87659 +
87660 + if (node == NULL_TREE)
87661 + return false;
87662 +
87663 + type = TREE_TYPE(node);
87664 + if (!INTEGRAL_TYPE_P(type))
87665 + return false;
87666 + if (TREE_CODE(type) == BOOLEAN_TYPE)
87667 + return true;
87668 + if (TYPE_PRECISION(type) == 1)
87669 + return true;
87670 + return false;
87671 +}
87672 +
87673 +static tree cast_a_tree(tree type, tree var)
87674 +{
87675 + gcc_assert(type != NULL_TREE);
87676 + gcc_assert(var != NULL_TREE);
87677 + gcc_assert(fold_convertible_p(type, var));
87678 +
87679 + return fold_convert(type, var);
87680 +}
87681 +
87682 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
87683 +{
87684 + gimple assign;
87685 +
87686 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
87687 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
87688 + gcc_unreachable();
87689 +
87690 + if (lhs == CREATE_NEW_VAR)
87691 + lhs = create_new_var(dst_type);
87692 +
87693 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
87694 +
87695 + if (!gsi_end_p(*gsi)) {
87696 + location_t loc = gimple_location(gsi_stmt(*gsi));
87697 + gimple_set_location(assign, loc);
87698 + }
87699 +
87700 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87701 +
87702 + if (before)
87703 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
87704 + else
87705 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
87706 + update_stmt(assign);
87707 + gimple_set_plf(assign, MY_STMT, true);
87708 +
87709 + return assign;
87710 +}
87711 +
87712 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
87713 +{
87714 + const_gimple assign;
87715 + gimple_stmt_iterator gsi;
87716 +
87717 + if (new_rhs1 == NULL_TREE)
87718 + return NULL_TREE;
87719 +
87720 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
87721 + gsi = gsi_for_stmt(stmt);
87722 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
87723 + return gimple_get_lhs(assign);
87724 + }
87725 + return new_rhs1;
87726 +}
87727 +
87728 +static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, gimple stmt, const_tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
87729 +{
87730 + tree size_overflow_type = get_size_overflow_type(stmt, node);
87731 +
87732 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87733 +
87734 + if (new_rhs2 != NULL_TREE)
87735 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
87736 +
87737 + if (new_rhs3 != NULL_TREE)
87738 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
87739 +
87740 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
87741 +}
87742 +
87743 +
87744 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
87745 +{
87746 + tree size_overflow_type, lhs;
87747 + gimple stmt;
87748 + gimple_stmt_iterator gsi;
87749 +
87750 + if (rhs1 == NULL_TREE) {
87751 + debug_gimple_stmt(oldstmt);
87752 + error("%s: rhs1 is NULL_TREE", __func__);
87753 + gcc_unreachable();
87754 + }
87755 +
87756 + if (gimple_code(oldstmt) == GIMPLE_ASM)
87757 + lhs = rhs1;
87758 + else
87759 + lhs = gimple_get_lhs(oldstmt);
87760 +
87761 + gsi = gsi_for_stmt(oldstmt);
87762 + pointer_set_insert(visited, oldstmt);
87763 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
87764 + basic_block next_bb, cur_bb;
87765 + const_edge e;
87766 +
87767 + gcc_assert(before == false);
87768 + gcc_assert(stmt_can_throw_internal(oldstmt));
87769 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
87770 + gcc_assert(!gsi_end_p(gsi));
87771 +
87772 + cur_bb = gimple_bb(oldstmt);
87773 + next_bb = cur_bb->next_bb;
87774 + e = find_edge(cur_bb, next_bb);
87775 + gcc_assert(e != NULL);
87776 + gcc_assert(e->flags & EDGE_FALLTHRU);
87777 +
87778 + gsi = gsi_after_labels(next_bb);
87779 + gcc_assert(!gsi_end_p(gsi));
87780 +
87781 + before = true;
87782 + oldstmt = gsi_stmt(gsi);
87783 + }
87784 +
87785 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
87786 +
87787 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
87788 + gimple_set_plf(stmt, MY_STMT, true);
87789 + return gimple_get_lhs(stmt);
87790 +}
87791 +
87792 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
87793 +{
87794 + gimple stmt;
87795 + gimple_stmt_iterator gsi;
87796 + tree new_var, lhs = gimple_get_lhs(oldstmt);
87797 +
87798 + if (gimple_plf(oldstmt, MY_STMT))
87799 + return lhs;
87800 +
87801 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
87802 + rhs1 = gimple_assign_rhs1(oldstmt);
87803 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
87804 + }
87805 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
87806 + rhs2 = gimple_assign_rhs2(oldstmt);
87807 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
87808 + }
87809 +
87810 + stmt = gimple_copy(oldstmt);
87811 + gimple_set_location(stmt, gimple_location(oldstmt));
87812 + gimple_set_plf(stmt, MY_STMT, true);
87813 +
87814 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
87815 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
87816 +
87817 + if (is_bool(lhs))
87818 + new_var = SSA_NAME_VAR(lhs);
87819 + else
87820 + new_var = create_new_var(size_overflow_type);
87821 + new_var = make_ssa_name(new_var, stmt);
87822 + gimple_set_lhs(stmt, new_var);
87823 +
87824 + if (rhs1 != NULL_TREE) {
87825 + if (!gimple_assign_cast_p(oldstmt))
87826 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
87827 + gimple_assign_set_rhs1(stmt, rhs1);
87828 + }
87829 +
87830 + if (rhs2 != NULL_TREE)
87831 + gimple_assign_set_rhs2(stmt, rhs2);
87832 +#if BUILDING_GCC_VERSION >= 4007
87833 + if (rhs3 != NULL_TREE)
87834 + gimple_assign_set_rhs3(stmt, rhs3);
87835 +#endif
87836 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
87837 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
87838 +
87839 + gsi = gsi_for_stmt(oldstmt);
87840 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
87841 + update_stmt(stmt);
87842 + pointer_set_insert(visited, oldstmt);
87843 + return gimple_get_lhs(stmt);
87844 +}
87845 +
87846 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
87847 +{
87848 + basic_block bb;
87849 + gimple phi;
87850 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
87851 +
87852 + bb = gsi_bb(gsi);
87853 +
87854 + phi = create_phi_node(result, bb);
87855 + gsi = gsi_last(phi_nodes(bb));
87856 + gsi_remove(&gsi, false);
87857 +
87858 + gsi = gsi_for_stmt(oldstmt);
87859 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
87860 + gimple_set_bb(phi, bb);
87861 + gimple_set_plf(phi, MY_STMT, true);
87862 + return phi;
87863 +}
87864 +
87865 +static basic_block create_a_first_bb(void)
87866 +{
87867 + basic_block first_bb;
87868 +
87869 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87870 + if (dom_info_available_p(CDI_DOMINATORS))
87871 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
87872 + return first_bb;
87873 +}
87874 +
87875 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
87876 +{
87877 + basic_block bb;
87878 + const_gimple newstmt;
87879 + gimple_stmt_iterator gsi;
87880 + bool before = BEFORE_STMT;
87881 +
87882 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
87883 + gsi = gsi_for_stmt(get_def_stmt(arg));
87884 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
87885 + return gimple_get_lhs(newstmt);
87886 + }
87887 +
87888 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
87889 + gsi = gsi_after_labels(bb);
87890 + if (bb->index == 0) {
87891 + bb = create_a_first_bb();
87892 + gsi = gsi_start_bb(bb);
87893 + }
87894 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
87895 + return gimple_get_lhs(newstmt);
87896 +}
87897 +
87898 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
87899 +{
87900 + gimple newstmt;
87901 + gimple_stmt_iterator gsi;
87902 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
87903 + gimple def_newstmt = get_def_stmt(new_rhs);
87904 +
87905 + gsi_insert = gsi_insert_after;
87906 + gsi = gsi_for_stmt(def_newstmt);
87907 +
87908 + switch (gimple_code(get_def_stmt(arg))) {
87909 + case GIMPLE_PHI:
87910 + newstmt = gimple_build_assign(new_var, new_rhs);
87911 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
87912 + gsi_insert = gsi_insert_before;
87913 + break;
87914 + case GIMPLE_ASM:
87915 + case GIMPLE_CALL:
87916 + newstmt = gimple_build_assign(new_var, new_rhs);
87917 + break;
87918 + case GIMPLE_ASSIGN:
87919 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
87920 + break;
87921 + default:
87922 + /* unknown gimple_code (handle_build_new_phi_arg) */
87923 + gcc_unreachable();
87924 + }
87925 +
87926 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
87927 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
87928 + gimple_set_plf(newstmt, MY_STMT, true);
87929 + update_stmt(newstmt);
87930 + return newstmt;
87931 +}
87932 +
87933 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
87934 +{
87935 + const_gimple newstmt;
87936 + gimple def_stmt;
87937 + tree new_rhs;
87938 +
87939 + new_rhs = expand(visited, arg);
87940 + if (new_rhs == NULL_TREE)
87941 + return NULL_TREE;
87942 +
87943 + def_stmt = get_def_stmt(new_rhs);
87944 + if (gimple_code(def_stmt) == GIMPLE_NOP)
87945 + return NULL_TREE;
87946 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
87947 +
87948 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
87949 + return gimple_get_lhs(newstmt);
87950 +}
87951 +
87952 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
87953 +{
87954 + gimple phi, oldstmt = get_def_stmt(orig_result);
87955 + tree new_result, size_overflow_type;
87956 + unsigned int i;
87957 + unsigned int n = gimple_phi_num_args(oldstmt);
87958 +
87959 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
87960 +
87961 + new_result = create_new_var(size_overflow_type);
87962 +
87963 + pointer_set_insert(visited, oldstmt);
87964 + phi = overflow_create_phi_node(oldstmt, new_result);
87965 + for (i = 0; i < n; i++) {
87966 + tree arg, lhs;
87967 +
87968 + arg = gimple_phi_arg_def(oldstmt, i);
87969 + if (is_gimple_constant(arg))
87970 + arg = cast_a_tree(size_overflow_type, arg);
87971 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
87972 + if (lhs == NULL_TREE)
87973 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
87974 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
87975 + }
87976 +
87977 + update_stmt(phi);
87978 + return gimple_phi_result(phi);
87979 +}
87980 +
87981 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
87982 +{
87983 + const_gimple assign;
87984 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87985 + tree origtype = TREE_TYPE(orig_rhs);
87986 +
87987 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
87988 +
87989 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87990 + return gimple_get_lhs(assign);
87991 +}
87992 +
87993 +static void change_rhs1(gimple stmt, tree new_rhs1)
87994 +{
87995 + tree assign_rhs;
87996 + const_tree rhs = gimple_assign_rhs1(stmt);
87997 +
87998 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
87999 + gimple_assign_set_rhs1(stmt, assign_rhs);
88000 + update_stmt(stmt);
88001 +}
88002 +
88003 +static bool check_mode_type(const_gimple stmt)
88004 +{
88005 + const_tree lhs = gimple_get_lhs(stmt);
88006 + const_tree lhs_type = TREE_TYPE(lhs);
88007 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88008 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88009 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88010 +
88011 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88012 + return false;
88013 +
88014 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88015 + return false;
88016 +
88017 + return true;
88018 +}
88019 +
88020 +static bool check_undefined_integer_operation(const_gimple stmt)
88021 +{
88022 + const_gimple def_stmt;
88023 + const_tree lhs = gimple_get_lhs(stmt);
88024 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88025 + const_tree rhs1_type = TREE_TYPE(rhs1);
88026 + const_tree lhs_type = TREE_TYPE(lhs);
88027 +
88028 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88029 + return false;
88030 +
88031 + def_stmt = get_def_stmt(rhs1);
88032 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88033 + return false;
88034 +
88035 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88036 + return false;
88037 + return true;
88038 +}
88039 +
88040 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88041 +{
88042 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88043 + enum machine_mode lhs_mode, rhs_mode;
88044 + gimple def_stmt = get_def_stmt(no_const_rhs);
88045 +
88046 + if (!gimple_assign_cast_p(def_stmt))
88047 + return false;
88048 +
88049 + rhs1 = gimple_assign_rhs1(def_stmt);
88050 + lhs = gimple_get_lhs(def_stmt);
88051 + rhs1_type = TREE_TYPE(rhs1);
88052 + lhs_type = TREE_TYPE(lhs);
88053 + rhs_mode = TYPE_MODE(rhs1_type);
88054 + lhs_mode = TYPE_MODE(lhs_type);
88055 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88056 + return false;
88057 +
88058 + return true;
88059 +}
88060 +
88061 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88062 +{
88063 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88064 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88065 + const_tree rhs1_type = TREE_TYPE(rhs1);
88066 + const_tree lhs_type = TREE_TYPE(lhs);
88067 +
88068 + new_rhs1 = expand(visited, rhs1);
88069 +
88070 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88071 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88072 +
88073 + if (gimple_plf(stmt, MY_STMT))
88074 + return lhs;
88075 +
88076 + if (gimple_plf(stmt, NO_CAST_CHECK))
88077 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88078 +
88079 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88080 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88081 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88082 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88083 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88084 + }
88085 +
88086 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88087 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88088 +
88089 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88090 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88091 +
88092 + change_rhs1(stmt, new_rhs1);
88093 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88094 +
88095 + rhs1 = gimple_assign_rhs1(stmt);
88096 + rhs1_type = TREE_TYPE(rhs1);
88097 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88098 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88099 +
88100 + if (!check_mode_type(stmt))
88101 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88102 +
88103 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88104 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88105 +
88106 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88107 +
88108 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88109 +}
88110 +
88111 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88112 +{
88113 + gimple def_stmt = get_def_stmt(lhs);
88114 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88115 +
88116 + if (is_gimple_constant(rhs1))
88117 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88118 +
88119 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88120 + switch (TREE_CODE(rhs1)) {
88121 + case SSA_NAME:
88122 + return handle_unary_rhs(visited, def_stmt);
88123 + case ARRAY_REF:
88124 + case BIT_FIELD_REF:
88125 + case ADDR_EXPR:
88126 + case COMPONENT_REF:
88127 + case INDIRECT_REF:
88128 +#if BUILDING_GCC_VERSION >= 4006
88129 + case MEM_REF:
88130 +#endif
88131 + case PARM_DECL:
88132 + case TARGET_MEM_REF:
88133 + case VAR_DECL:
88134 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88135 +
88136 + default:
88137 + debug_gimple_stmt(def_stmt);
88138 + debug_tree(rhs1);
88139 + gcc_unreachable();
88140 + }
88141 +}
88142 +
88143 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88144 +{
88145 + gimple cond_stmt;
88146 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88147 +
88148 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88149 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88150 + update_stmt(cond_stmt);
88151 +}
88152 +
88153 +static tree create_string_param(tree string)
88154 +{
88155 + tree i_type, a_type;
88156 + const int length = TREE_STRING_LENGTH(string);
88157 +
88158 + gcc_assert(length > 0);
88159 +
88160 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88161 + a_type = build_array_type(char_type_node, i_type);
88162 +
88163 + TREE_TYPE(string) = a_type;
88164 + TREE_CONSTANT(string) = 1;
88165 + TREE_READONLY(string) = 1;
88166 +
88167 + return build1(ADDR_EXPR, ptr_type_node, string);
88168 +}
88169 +
88170 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88171 +{
88172 + gimple func_stmt;
88173 + const_gimple def_stmt;
88174 + const_tree loc_line;
88175 + tree loc_file, ssa_name, current_func;
88176 + expanded_location xloc;
88177 + char ssa_name_buf[256];
88178 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88179 +
88180 + def_stmt = get_def_stmt(arg);
88181 + xloc = expand_location(gimple_location(def_stmt));
88182 +
88183 + if (!gimple_has_location(def_stmt)) {
88184 + xloc = expand_location(gimple_location(stmt));
88185 + if (!gimple_has_location(stmt))
88186 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88187 + }
88188 +
88189 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88190 +
88191 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88192 + loc_file = create_string_param(loc_file);
88193 +
88194 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88195 + current_func = create_string_param(current_func);
88196 +
88197 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88198 + ssa_name = build_string(256, ssa_name_buf);
88199 + ssa_name = create_string_param(ssa_name);
88200 +
88201 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88202 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88203 +
88204 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88205 +}
88206 +
88207 +static void __unused print_the_code_insertions(const_gimple stmt)
88208 +{
88209 + location_t loc = gimple_location(stmt);
88210 +
88211 + inform(loc, "Integer size_overflow check applied here.");
88212 +}
88213 +
88214 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88215 +{
88216 + basic_block cond_bb, join_bb, bb_true;
88217 + edge e;
88218 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88219 +
88220 + cond_bb = gimple_bb(stmt);
88221 + if (before)
88222 + gsi_prev(&gsi);
88223 + if (gsi_end_p(gsi))
88224 + e = split_block_after_labels(cond_bb);
88225 + else
88226 + e = split_block(cond_bb, gsi_stmt(gsi));
88227 + cond_bb = e->src;
88228 + join_bb = e->dest;
88229 + e->flags = EDGE_FALSE_VALUE;
88230 + e->probability = REG_BR_PROB_BASE;
88231 +
88232 + bb_true = create_empty_bb(cond_bb);
88233 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88234 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88235 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88236 +
88237 + if (dom_info_available_p(CDI_DOMINATORS)) {
88238 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88239 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88240 + }
88241 +
88242 + if (current_loops != NULL) {
88243 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88244 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88245 + }
88246 +
88247 + insert_cond(cond_bb, arg, cond_code, type_value);
88248 + insert_cond_result(bb_true, stmt, arg, min);
88249 +
88250 +// print_the_code_insertions(stmt);
88251 +}
88252 +
88253 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88254 +{
88255 + const_tree rhs_type = TREE_TYPE(rhs);
88256 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88257 +
88258 + gcc_assert(rhs_type != NULL_TREE);
88259 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88260 + return;
88261 +
88262 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88263 +
88264 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88265 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88266 +
88267 + gcc_assert(!TREE_OVERFLOW(type_max));
88268 +
88269 + cast_rhs_type = TREE_TYPE(cast_rhs);
88270 + type_max_type = TREE_TYPE(type_max);
88271 + type_min_type = TREE_TYPE(type_min);
88272 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88273 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88274 +
88275 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88276 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88277 +}
88278 +
88279 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88280 +{
88281 + gimple change_rhs_def_stmt;
88282 + tree lhs = gimple_get_lhs(def_stmt);
88283 + tree lhs_type = TREE_TYPE(lhs);
88284 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88285 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88286 +
88287 + if (change_rhs == NULL_TREE)
88288 + return get_size_overflow_type(def_stmt, lhs);
88289 +
88290 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88291 +
88292 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88293 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88294 +
88295 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88296 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88297 +
88298 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88299 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88300 +
88301 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88302 + debug_gimple_stmt(def_stmt);
88303 + gcc_unreachable();
88304 + }
88305 +
88306 + return get_size_overflow_type(def_stmt, lhs);
88307 +}
88308 +
88309 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88310 +{
88311 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88312 + return false;
88313 + if (!is_gimple_constant(rhs))
88314 + return false;
88315 + return true;
88316 +}
88317 +
88318 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88319 +{
88320 + gimple def_stmt;
88321 +
88322 + def_stmt = get_def_stmt(new_rhs);
88323 + // get_size_overflow_type
88324 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88325 + gcc_assert(gimple_assign_cast_p(def_stmt));
88326 + return gimple_assign_rhs1(def_stmt);
88327 +}
88328 +
88329 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88330 +{
88331 + gimple_stmt_iterator gsi;
88332 + const_gimple cast_stmt;
88333 + gimple def_stmt;
88334 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88335 +
88336 + if (mode != TImode && mode != DImode) {
88337 + def_stmt = get_def_stmt(new_rhs);
88338 + gcc_assert(gimple_assign_cast_p(def_stmt));
88339 + new_rhs = gimple_assign_rhs1(def_stmt);
88340 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88341 + }
88342 +
88343 + gcc_assert(mode == TImode || mode == DImode);
88344 +
88345 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88346 + return new_rhs;
88347 +
88348 + gsi = gsi_for_stmt(stmt);
88349 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88350 + new_rhs = gimple_get_lhs(cast_stmt);
88351 +
88352 + if (mode == DImode)
88353 + return new_rhs;
88354 +
88355 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88356 +
88357 + return new_rhs;
88358 +}
88359 +
88360 +static bool is_an_integer_trunction(const_gimple stmt)
88361 +{
88362 + gimple rhs1_def_stmt, rhs2_def_stmt;
88363 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88364 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88365 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88366 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88367 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88368 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88369 +
88370 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88371 + return false;
88372 +
88373 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88374 +
88375 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88376 + return false;
88377 +
88378 + rhs1_def_stmt = get_def_stmt(rhs1);
88379 + rhs2_def_stmt = get_def_stmt(rhs2);
88380 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88381 + return false;
88382 +
88383 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88384 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88385 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88386 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88387 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88388 + return false;
88389 +
88390 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88391 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88392 + return true;
88393 +}
88394 +
88395 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88396 +{
88397 + tree new_rhs1, new_rhs2;
88398 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88399 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88400 + gimple assign, stmt = get_def_stmt(lhs);
88401 + tree rhs1 = gimple_assign_rhs1(stmt);
88402 + tree rhs2 = gimple_assign_rhs2(stmt);
88403 +
88404 + if (!is_an_integer_trunction(stmt))
88405 + return NULL_TREE;
88406 +
88407 + new_rhs1 = expand(visited, rhs1);
88408 + new_rhs2 = expand(visited, rhs2);
88409 +
88410 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88411 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88412 +
88413 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88414 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88415 +
88416 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88417 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88418 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88419 + }
88420 +
88421 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88422 + new_lhs = gimple_get_lhs(assign);
88423 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88424 +
88425 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88426 +}
88427 +
88428 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88429 +{
88430 + const_gimple def_stmt;
88431 +
88432 + if (TREE_CODE(rhs) != SSA_NAME)
88433 + return false;
88434 +
88435 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88436 + return false;
88437 +
88438 + def_stmt = get_def_stmt(rhs);
88439 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88440 + return false;
88441 +
88442 + return true;
88443 +}
88444 +
88445 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88446 +{
88447 + tree new_rhs, size_overflow_type, orig_rhs;
88448 + void (*gimple_assign_set_rhs)(gimple, tree);
88449 + tree rhs1 = gimple_assign_rhs1(stmt);
88450 + tree rhs2 = gimple_assign_rhs2(stmt);
88451 + tree lhs = gimple_get_lhs(stmt);
88452 +
88453 + if (change_rhs == NULL_TREE)
88454 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88455 +
88456 + if (new_rhs2 == NULL_TREE) {
88457 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88458 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88459 + orig_rhs = rhs1;
88460 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88461 + } else {
88462 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88463 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88464 + orig_rhs = rhs2;
88465 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88466 + }
88467 +
88468 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88469 +
88470 + if (check_overflow)
88471 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88472 +
88473 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88474 + gimple_assign_set_rhs(stmt, new_rhs);
88475 + update_stmt(stmt);
88476 +
88477 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88478 +}
88479 +
88480 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88481 +{
88482 + tree rhs1, rhs2, new_lhs;
88483 + gimple def_stmt = get_def_stmt(lhs);
88484 + tree new_rhs1 = NULL_TREE;
88485 + tree new_rhs2 = NULL_TREE;
88486 +
88487 + rhs1 = gimple_assign_rhs1(def_stmt);
88488 + rhs2 = gimple_assign_rhs2(def_stmt);
88489 +
88490 + /* no DImode/TImode division in the 32/64 bit kernel */
88491 + switch (gimple_assign_rhs_code(def_stmt)) {
88492 + case RDIV_EXPR:
88493 + case TRUNC_DIV_EXPR:
88494 + case CEIL_DIV_EXPR:
88495 + case FLOOR_DIV_EXPR:
88496 + case ROUND_DIV_EXPR:
88497 + case TRUNC_MOD_EXPR:
88498 + case CEIL_MOD_EXPR:
88499 + case FLOOR_MOD_EXPR:
88500 + case ROUND_MOD_EXPR:
88501 + case EXACT_DIV_EXPR:
88502 + case POINTER_PLUS_EXPR:
88503 + case BIT_AND_EXPR:
88504 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88505 + default:
88506 + break;
88507 + }
88508 +
88509 + new_lhs = handle_integer_truncation(visited, lhs);
88510 + if (new_lhs != NULL_TREE)
88511 + return new_lhs;
88512 +
88513 + if (TREE_CODE(rhs1) == SSA_NAME)
88514 + new_rhs1 = expand(visited, rhs1);
88515 + if (TREE_CODE(rhs2) == SSA_NAME)
88516 + new_rhs2 = expand(visited, rhs2);
88517 +
88518 + if (is_a_neg_overflow(def_stmt, rhs2))
88519 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88520 + if (is_a_neg_overflow(def_stmt, rhs1))
88521 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88522 +
88523 + if (is_a_constant_overflow(def_stmt, rhs2))
88524 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88525 + if (is_a_constant_overflow(def_stmt, rhs1))
88526 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88527 +
88528 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88529 +}
88530 +
88531 +#if BUILDING_GCC_VERSION >= 4007
88532 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88533 +{
88534 + if (is_gimple_constant(rhs))
88535 + return cast_a_tree(size_overflow_type, rhs);
88536 + if (TREE_CODE(rhs) != SSA_NAME)
88537 + return NULL_TREE;
88538 + return expand(visited, rhs);
88539 +}
88540 +
88541 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88542 +{
88543 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88544 + gimple def_stmt = get_def_stmt(lhs);
88545 +
88546 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88547 +
88548 + rhs1 = gimple_assign_rhs1(def_stmt);
88549 + rhs2 = gimple_assign_rhs2(def_stmt);
88550 + rhs3 = gimple_assign_rhs3(def_stmt);
88551 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88552 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88553 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88554 +
88555 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88556 +}
88557 +#endif
88558 +
88559 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88560 +{
88561 + const_tree type;
88562 +
88563 + gcc_assert(node != NULL_TREE);
88564 +
88565 + type = TREE_TYPE(node);
88566 +
88567 + if (gimple_plf(stmt, MY_STMT))
88568 + return TREE_TYPE(node);
88569 +
88570 + switch (TYPE_MODE(type)) {
88571 + case QImode:
88572 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88573 + case HImode:
88574 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88575 + case SImode:
88576 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88577 + case DImode:
88578 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88579 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88580 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88581 + default:
88582 + debug_tree((tree)node);
88583 + error("%s: unsupported gcc configuration.", __func__);
88584 + gcc_unreachable();
88585 + }
88586 +}
88587 +
88588 +static tree expand_visited(gimple def_stmt)
88589 +{
88590 + const_gimple next_stmt;
88591 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88592 +
88593 + gsi_next(&gsi);
88594 + next_stmt = gsi_stmt(gsi);
88595 +
88596 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88597 +
88598 + switch (gimple_code(next_stmt)) {
88599 + case GIMPLE_ASSIGN:
88600 + return gimple_get_lhs(next_stmt);
88601 + case GIMPLE_PHI:
88602 + return gimple_phi_result(next_stmt);
88603 + case GIMPLE_CALL:
88604 + return gimple_call_lhs(next_stmt);
88605 + default:
88606 + return NULL_TREE;
88607 + }
88608 +}
88609 +
88610 +static tree expand(struct pointer_set_t *visited, tree lhs)
88611 +{
88612 + gimple def_stmt;
88613 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
88614 +
88615 + if (is_gimple_constant(lhs))
88616 + return NULL_TREE;
88617 +
88618 + if (TREE_CODE(lhs) == ADDR_EXPR)
88619 + return NULL_TREE;
88620 +
88621 + if (code == REAL_TYPE)
88622 + return NULL_TREE;
88623 +
88624 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
88625 +
88626 +
88627 + def_stmt = get_def_stmt(lhs);
88628 +
88629 + if (!def_stmt)
88630 + return NULL_TREE;
88631 +
88632 + if (gimple_plf(def_stmt, MY_STMT))
88633 + return lhs;
88634 +
88635 + if (pointer_set_contains(visited, def_stmt))
88636 + return expand_visited(def_stmt);
88637 +
88638 + switch (gimple_code(def_stmt)) {
88639 + case GIMPLE_NOP:
88640 + return NULL_TREE;
88641 + case GIMPLE_PHI:
88642 + return build_new_phi(visited, lhs);
88643 + case GIMPLE_CALL:
88644 + case GIMPLE_ASM:
88645 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88646 + case GIMPLE_ASSIGN:
88647 + switch (gimple_num_ops(def_stmt)) {
88648 + case 2:
88649 + return handle_unary_ops(visited, lhs);
88650 + case 3:
88651 + return handle_binary_ops(visited, lhs);
88652 +#if BUILDING_GCC_VERSION >= 4007
88653 + case 4:
88654 + return handle_ternary_ops(visited, lhs);
88655 +#endif
88656 + }
88657 + default:
88658 + debug_gimple_stmt(def_stmt);
88659 + error("%s: unknown gimple code", __func__);
88660 + gcc_unreachable();
88661 + }
88662 +}
88663 +
88664 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
88665 +{
88666 + const_gimple assign;
88667 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88668 + tree origtype = TREE_TYPE(origarg);
88669 +
88670 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
88671 +
88672 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88673 +
88674 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
88675 + update_stmt(stmt);
88676 +}
88677 +
88678 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
88679 +{
88680 + const char *origid;
88681 + tree arg;
88682 + const_tree origarg;
88683 +
88684 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
88685 + return true;
88686 +
88687 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
88688 + while (origarg && *argnum) {
88689 + (*argnum)--;
88690 + origarg = TREE_CHAIN(origarg);
88691 + }
88692 +
88693 + gcc_assert(*argnum == 0);
88694 +
88695 + gcc_assert(origarg != NULL_TREE);
88696 + origid = NAME(origarg);
88697 + *argnum = 0;
88698 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
88699 + if (!strcmp(origid, NAME(arg)))
88700 + return true;
88701 + (*argnum)++;
88702 + }
88703 + return false;
88704 +}
88705 +
88706 +static bool skip_types(const_tree var)
88707 +{
88708 + switch (TREE_CODE(var)) {
88709 + case ADDR_EXPR:
88710 +#if BUILDING_GCC_VERSION >= 4006
88711 + case MEM_REF:
88712 +#endif
88713 + case ARRAY_REF:
88714 + case BIT_FIELD_REF:
88715 + case INDIRECT_REF:
88716 + case TARGET_MEM_REF:
88717 + case VAR_DECL:
88718 + return true;
88719 + default:
88720 + break;
88721 + }
88722 + return false;
88723 +}
88724 +
88725 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
88726 +{
88727 + gimple phi = get_def_stmt(result);
88728 + unsigned int i, n = gimple_phi_num_args(phi);
88729 +
88730 + if (!phi)
88731 + return false;
88732 +
88733 + pointer_set_insert(visited, phi);
88734 + for (i = 0; i < n; i++) {
88735 + const_tree arg = gimple_phi_arg_def(phi, i);
88736 + if (pre_expand(visited, arg))
88737 + return true;
88738 + }
88739 + return false;
88740 +}
88741 +
88742 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
88743 +{
88744 + gimple def_stmt = get_def_stmt(lhs);
88745 + const_tree rhs;
88746 +
88747 + if (!def_stmt)
88748 + return false;
88749 +
88750 + rhs = gimple_assign_rhs1(def_stmt);
88751 + if (pre_expand(visited, rhs))
88752 + return true;
88753 + return false;
88754 +}
88755 +
88756 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
88757 +{
88758 + bool rhs1_found, rhs2_found;
88759 + gimple def_stmt = get_def_stmt(lhs);
88760 + const_tree rhs1, rhs2;
88761 +
88762 + if (!def_stmt)
88763 + return false;
88764 +
88765 + rhs1 = gimple_assign_rhs1(def_stmt);
88766 + rhs2 = gimple_assign_rhs2(def_stmt);
88767 + rhs1_found = pre_expand(visited, rhs1);
88768 + rhs2_found = pre_expand(visited, rhs2);
88769 +
88770 + return rhs1_found || rhs2_found;
88771 +}
88772 +
88773 +static const_tree search_field_decl(const_tree comp_ref)
88774 +{
88775 + const_tree field = NULL_TREE;
88776 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
88777 +
88778 + for (i = 0; i < len; i++) {
88779 + field = TREE_OPERAND(comp_ref, i);
88780 + if (TREE_CODE(field) == FIELD_DECL)
88781 + break;
88782 + }
88783 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
88784 + return field;
88785 +}
88786 +
88787 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
88788 +{
88789 + const_tree attr, p;
88790 +
88791 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
88792 + if (!attr || !TREE_VALUE(attr))
88793 + return MARKED_NO;
88794 +
88795 + p = TREE_VALUE(attr);
88796 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
88797 + return MARKED_NOT_INTENTIONAL;
88798 +
88799 + do {
88800 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
88801 + return MARKED_YES;
88802 + p = TREE_CHAIN(p);
88803 + } while (p);
88804 +
88805 + return MARKED_NO;
88806 +}
88807 +
88808 +static void print_missing_msg(tree func, unsigned int argnum)
88809 +{
88810 + unsigned int new_hash;
88811 + size_t len;
88812 + unsigned char tree_codes[CODES_LIMIT];
88813 + location_t loc = DECL_SOURCE_LOCATION(func);
88814 + const char *curfunc = get_asm_name(func);
88815 +
88816 + len = get_function_decl(func, tree_codes);
88817 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
88818 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
88819 +}
88820 +
88821 +static unsigned int search_missing_attribute(const_tree arg)
88822 +{
88823 + const_tree type = TREE_TYPE(arg);
88824 + tree func = get_original_function_decl(current_function_decl);
88825 + unsigned int argnum;
88826 + const struct size_overflow_hash *hash;
88827 +
88828 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
88829 +
88830 + if (TREE_CODE(type) == POINTER_TYPE)
88831 + return 0;
88832 +
88833 + argnum = find_arg_number(arg, func);
88834 + if (argnum == 0)
88835 + return 0;
88836 +
88837 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
88838 + return argnum;
88839 +
88840 + hash = get_function_hash(func);
88841 + if (!hash || !(hash->param & (1U << argnum))) {
88842 + print_missing_msg(func, argnum);
88843 + return 0;
88844 + }
88845 + return argnum;
88846 +}
88847 +
88848 +static bool is_already_marked(const_tree lhs)
88849 +{
88850 + unsigned int argnum;
88851 + const_tree fndecl;
88852 +
88853 + argnum = search_missing_attribute(lhs);
88854 + fndecl = get_original_function_decl(current_function_decl);
88855 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
88856 + return true;
88857 + return false;
88858 +}
88859 +
88860 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
88861 +{
88862 + const_gimple def_stmt;
88863 +
88864 + if (is_gimple_constant(lhs))
88865 + return false;
88866 +
88867 + if (skip_types(lhs))
88868 + return false;
88869 +
88870 + if (TREE_CODE(lhs) == PARM_DECL)
88871 + return is_already_marked(lhs);
88872 +
88873 + if (TREE_CODE(lhs) == COMPONENT_REF) {
88874 + const_tree field, attr;
88875 +
88876 + field = search_field_decl(lhs);
88877 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
88878 + if (!attr || !TREE_VALUE(attr))
88879 + return false;
88880 + return true;
88881 + }
88882 +
88883 + def_stmt = get_def_stmt(lhs);
88884 +
88885 + if (!def_stmt)
88886 + return false;
88887 +
88888 + if (pointer_set_contains(visited, def_stmt))
88889 + return false;
88890 +
88891 + switch (gimple_code(def_stmt)) {
88892 + case GIMPLE_NOP:
88893 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
88894 + return is_already_marked(lhs);
88895 + return false;
88896 + case GIMPLE_PHI:
88897 + return walk_phi(visited, lhs);
88898 + case GIMPLE_CALL:
88899 + case GIMPLE_ASM:
88900 + return false;
88901 + case GIMPLE_ASSIGN:
88902 + switch (gimple_num_ops(def_stmt)) {
88903 + case 2:
88904 + return walk_unary_ops(visited, lhs);
88905 + case 3:
88906 + return walk_binary_ops(visited, lhs);
88907 + }
88908 + default:
88909 + debug_gimple_stmt((gimple)def_stmt);
88910 + error("%s: unknown gimple code", __func__);
88911 + gcc_unreachable();
88912 + }
88913 +}
88914 +
88915 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
88916 +{
88917 + struct pointer_set_t *visited;
88918 + bool is_found;
88919 + enum marked is_marked;
88920 + location_t loc;
88921 +
88922 + visited = pointer_set_create();
88923 + is_found = pre_expand(visited, arg);
88924 + pointer_set_destroy(visited);
88925 +
88926 + is_marked = mark_status(fndecl, argnum + 1);
88927 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
88928 + return true;
88929 +
88930 + if (is_found) {
88931 + loc = DECL_SOURCE_LOCATION(fndecl);
88932 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
88933 + return true;
88934 + }
88935 + return false;
88936 +}
88937 +
88938 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
88939 +{
88940 + struct pointer_set_t *visited;
88941 + tree arg, newarg;
88942 + bool match;
88943 +
88944 + match = get_function_arg(&argnum, fndecl);
88945 + if (!match)
88946 + return;
88947 + gcc_assert(gimple_call_num_args(stmt) > argnum);
88948 + arg = gimple_call_arg(stmt, argnum);
88949 + if (arg == NULL_TREE)
88950 + return;
88951 +
88952 + if (is_gimple_constant(arg))
88953 + return;
88954 +
88955 + if (search_attributes(fndecl, arg, argnum))
88956 + return;
88957 +
88958 + if (TREE_CODE(arg) != SSA_NAME)
88959 + return;
88960 +
88961 + check_arg_type(arg);
88962 +
88963 + visited = pointer_set_create();
88964 + newarg = expand(visited, arg);
88965 + pointer_set_destroy(visited);
88966 +
88967 + if (newarg == NULL_TREE)
88968 + return;
88969 +
88970 + change_function_arg(stmt, arg, argnum, newarg);
88971 +
88972 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
88973 +}
88974 +
88975 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
88976 +{
88977 + tree p = TREE_VALUE(attr);
88978 + do {
88979 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
88980 + p = TREE_CHAIN(p);
88981 + } while (p);
88982 +}
88983 +
88984 +static void handle_function_by_hash(gimple stmt, tree fndecl)
88985 +{
88986 + tree orig_fndecl;
88987 + unsigned int num;
88988 + const struct size_overflow_hash *hash;
88989 +
88990 + orig_fndecl = get_original_function_decl(fndecl);
88991 + if (C_DECL_IMPLICIT(orig_fndecl))
88992 + return;
88993 + hash = get_function_hash(orig_fndecl);
88994 + if (!hash)
88995 + return;
88996 +
88997 + for (num = 1; num <= MAX_PARAM; num++)
88998 + if (hash->param & (1U << num))
88999 + handle_function_arg(stmt, fndecl, num - 1);
89000 +}
89001 +
89002 +static void set_plf_false(void)
89003 +{
89004 + basic_block bb;
89005 +
89006 + FOR_ALL_BB(bb) {
89007 + gimple_stmt_iterator si;
89008 +
89009 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89010 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89011 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89012 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89013 + }
89014 +}
89015 +
89016 +static unsigned int handle_function(void)
89017 +{
89018 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89019 +
89020 + set_plf_false();
89021 +
89022 + do {
89023 + gimple_stmt_iterator gsi;
89024 + next = bb->next_bb;
89025 +
89026 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89027 + tree fndecl, attr;
89028 + gimple stmt = gsi_stmt(gsi);
89029 +
89030 + if (!(is_gimple_call(stmt)))
89031 + continue;
89032 + fndecl = gimple_call_fndecl(stmt);
89033 + if (fndecl == NULL_TREE)
89034 + continue;
89035 + if (gimple_call_num_args(stmt) == 0)
89036 + continue;
89037 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89038 + if (!attr || !TREE_VALUE(attr))
89039 + handle_function_by_hash(stmt, fndecl);
89040 + else
89041 + handle_function_by_attribute(stmt, attr, fndecl);
89042 + gsi = gsi_for_stmt(stmt);
89043 + next = gimple_bb(stmt)->next_bb;
89044 + }
89045 + bb = next;
89046 + } while (bb);
89047 + return 0;
89048 +}
89049 +
89050 +static struct gimple_opt_pass size_overflow_pass = {
89051 + .pass = {
89052 + .type = GIMPLE_PASS,
89053 + .name = "size_overflow",
89054 + .gate = NULL,
89055 + .execute = handle_function,
89056 + .sub = NULL,
89057 + .next = NULL,
89058 + .static_pass_number = 0,
89059 + .tv_id = TV_NONE,
89060 + .properties_required = PROP_cfg | PROP_referenced_vars,
89061 + .properties_provided = 0,
89062 + .properties_destroyed = 0,
89063 + .todo_flags_start = 0,
89064 + .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
89065 + }
89066 +};
89067 +
89068 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89069 +{
89070 + tree fntype;
89071 +
89072 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89073 +
89074 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89075 + fntype = build_function_type_list(void_type_node,
89076 + const_char_ptr_type_node,
89077 + unsigned_type_node,
89078 + const_char_ptr_type_node,
89079 + const_char_ptr_type_node,
89080 + NULL_TREE);
89081 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89082 +
89083 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89084 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89085 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89086 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89087 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89088 +}
89089 +
89090 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89091 +{
89092 + int i;
89093 + const char * const plugin_name = plugin_info->base_name;
89094 + const int argc = plugin_info->argc;
89095 + const struct plugin_argument * const argv = plugin_info->argv;
89096 + bool enable = true;
89097 +
89098 + struct register_pass_info size_overflow_pass_info = {
89099 + .pass = &size_overflow_pass.pass,
89100 + .reference_pass_name = "ssa",
89101 + .ref_pass_instance_number = 1,
89102 + .pos_op = PASS_POS_INSERT_AFTER
89103 + };
89104 +
89105 + if (!plugin_default_version_check(version, &gcc_version)) {
89106 + error(G_("incompatible gcc/plugin versions"));
89107 + return 1;
89108 + }
89109 +
89110 + for (i = 0; i < argc; ++i) {
89111 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89112 + enable = false;
89113 + continue;
89114 + }
89115 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89116 + }
89117 +
89118 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89119 + if (enable) {
89120 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89121 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89122 + }
89123 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89124 +
89125 + return 0;
89126 +}
89127 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89128 new file mode 100644
89129 index 0000000..38d2014
89130 --- /dev/null
89131 +++ b/tools/gcc/stackleak_plugin.c
89132 @@ -0,0 +1,313 @@
89133 +/*
89134 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89135 + * Licensed under the GPL v2
89136 + *
89137 + * Note: the choice of the license means that the compilation process is
89138 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89139 + * but for the kernel it doesn't matter since it doesn't link against
89140 + * any of the gcc libraries
89141 + *
89142 + * gcc plugin to help implement various PaX features
89143 + *
89144 + * - track lowest stack pointer
89145 + *
89146 + * TODO:
89147 + * - initialize all local variables
89148 + *
89149 + * BUGS:
89150 + * - none known
89151 + */
89152 +#include "gcc-plugin.h"
89153 +#include "config.h"
89154 +#include "system.h"
89155 +#include "coretypes.h"
89156 +#include "tree.h"
89157 +#include "tree-pass.h"
89158 +#include "flags.h"
89159 +#include "intl.h"
89160 +#include "toplev.h"
89161 +#include "plugin.h"
89162 +//#include "expr.h" where are you...
89163 +#include "diagnostic.h"
89164 +#include "plugin-version.h"
89165 +#include "tm.h"
89166 +#include "function.h"
89167 +#include "basic-block.h"
89168 +#include "gimple.h"
89169 +#include "rtl.h"
89170 +#include "emit-rtl.h"
89171 +
89172 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89173 +
89174 +int plugin_is_GPL_compatible;
89175 +
89176 +static int track_frame_size = -1;
89177 +static const char track_function[] = "pax_track_stack";
89178 +static const char check_function[] = "pax_check_alloca";
89179 +static bool init_locals;
89180 +
89181 +static struct plugin_info stackleak_plugin_info = {
89182 + .version = "201203140940",
89183 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89184 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89185 +};
89186 +
89187 +static bool gate_stackleak_track_stack(void);
89188 +static unsigned int execute_stackleak_tree_instrument(void);
89189 +static unsigned int execute_stackleak_final(void);
89190 +
89191 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89192 + .pass = {
89193 + .type = GIMPLE_PASS,
89194 + .name = "stackleak_tree_instrument",
89195 + .gate = gate_stackleak_track_stack,
89196 + .execute = execute_stackleak_tree_instrument,
89197 + .sub = NULL,
89198 + .next = NULL,
89199 + .static_pass_number = 0,
89200 + .tv_id = TV_NONE,
89201 + .properties_required = PROP_gimple_leh | PROP_cfg,
89202 + .properties_provided = 0,
89203 + .properties_destroyed = 0,
89204 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89205 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89206 + }
89207 +};
89208 +
89209 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89210 + .pass = {
89211 + .type = RTL_PASS,
89212 + .name = "stackleak_final",
89213 + .gate = gate_stackleak_track_stack,
89214 + .execute = execute_stackleak_final,
89215 + .sub = NULL,
89216 + .next = NULL,
89217 + .static_pass_number = 0,
89218 + .tv_id = TV_NONE,
89219 + .properties_required = 0,
89220 + .properties_provided = 0,
89221 + .properties_destroyed = 0,
89222 + .todo_flags_start = 0,
89223 + .todo_flags_finish = TODO_dump_func
89224 + }
89225 +};
89226 +
89227 +static bool gate_stackleak_track_stack(void)
89228 +{
89229 + return track_frame_size >= 0;
89230 +}
89231 +
89232 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89233 +{
89234 + gimple check_alloca;
89235 + tree fntype, fndecl, alloca_size;
89236 +
89237 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89238 + fndecl = build_fn_decl(check_function, fntype);
89239 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89240 +
89241 + // insert call to void pax_check_alloca(unsigned long size)
89242 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89243 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89244 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89245 +}
89246 +
89247 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89248 +{
89249 + gimple track_stack;
89250 + tree fntype, fndecl;
89251 +
89252 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89253 + fndecl = build_fn_decl(track_function, fntype);
89254 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89255 +
89256 + // insert call to void pax_track_stack(void)
89257 + track_stack = gimple_build_call(fndecl, 0);
89258 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89259 +}
89260 +
89261 +#if BUILDING_GCC_VERSION == 4005
89262 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89263 +{
89264 + tree fndecl;
89265 +
89266 + if (!is_gimple_call(stmt))
89267 + return false;
89268 + fndecl = gimple_call_fndecl(stmt);
89269 + if (!fndecl)
89270 + return false;
89271 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89272 + return false;
89273 +// print_node(stderr, "pax", fndecl, 4);
89274 + return DECL_FUNCTION_CODE(fndecl) == code;
89275 +}
89276 +#endif
89277 +
89278 +static bool is_alloca(gimple stmt)
89279 +{
89280 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89281 + return true;
89282 +
89283 +#if BUILDING_GCC_VERSION >= 4007
89284 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89285 + return true;
89286 +#endif
89287 +
89288 + return false;
89289 +}
89290 +
89291 +static unsigned int execute_stackleak_tree_instrument(void)
89292 +{
89293 + basic_block bb, entry_bb;
89294 + bool prologue_instrumented = false, is_leaf = true;
89295 +
89296 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89297 +
89298 + // 1. loop through BBs and GIMPLE statements
89299 + FOR_EACH_BB(bb) {
89300 + gimple_stmt_iterator gsi;
89301 +
89302 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89303 + gimple stmt;
89304 +
89305 + stmt = gsi_stmt(gsi);
89306 +
89307 + if (is_gimple_call(stmt))
89308 + is_leaf = false;
89309 +
89310 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89311 + if (!is_alloca(stmt))
89312 + continue;
89313 +
89314 + // 2. insert stack overflow check before each __builtin_alloca call
89315 + stackleak_check_alloca(&gsi);
89316 +
89317 + // 3. insert track call after each __builtin_alloca call
89318 + stackleak_add_instrumentation(&gsi);
89319 + if (bb == entry_bb)
89320 + prologue_instrumented = true;
89321 + }
89322 + }
89323 +
89324 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89325 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89326 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89327 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89328 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89329 + return 0;
89330 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89331 + return 0;
89332 +
89333 + // 4. insert track call at the beginning
89334 + if (!prologue_instrumented) {
89335 + gimple_stmt_iterator gsi;
89336 +
89337 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89338 + if (dom_info_available_p(CDI_DOMINATORS))
89339 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89340 + gsi = gsi_start_bb(bb);
89341 + stackleak_add_instrumentation(&gsi);
89342 + }
89343 +
89344 + return 0;
89345 +}
89346 +
89347 +static unsigned int execute_stackleak_final(void)
89348 +{
89349 + rtx insn;
89350 +
89351 + if (cfun->calls_alloca)
89352 + return 0;
89353 +
89354 + // keep calls only if function frame is big enough
89355 + if (get_frame_size() >= track_frame_size)
89356 + return 0;
89357 +
89358 + // 1. find pax_track_stack calls
89359 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89360 + // 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))
89361 + rtx body;
89362 +
89363 + if (!CALL_P(insn))
89364 + continue;
89365 + body = PATTERN(insn);
89366 + if (GET_CODE(body) != CALL)
89367 + continue;
89368 + body = XEXP(body, 0);
89369 + if (GET_CODE(body) != MEM)
89370 + continue;
89371 + body = XEXP(body, 0);
89372 + if (GET_CODE(body) != SYMBOL_REF)
89373 + continue;
89374 + if (strcmp(XSTR(body, 0), track_function))
89375 + continue;
89376 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89377 + // 2. delete call
89378 + insn = delete_insn_and_edges(insn);
89379 +#if BUILDING_GCC_VERSION >= 4007
89380 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89381 + insn = delete_insn_and_edges(insn);
89382 +#endif
89383 + }
89384 +
89385 +// print_simple_rtl(stderr, get_insns());
89386 +// print_rtl(stderr, get_insns());
89387 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89388 +
89389 + return 0;
89390 +}
89391 +
89392 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89393 +{
89394 + const char * const plugin_name = plugin_info->base_name;
89395 + const int argc = plugin_info->argc;
89396 + const struct plugin_argument * const argv = plugin_info->argv;
89397 + int i;
89398 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89399 + .pass = &stackleak_tree_instrument_pass.pass,
89400 +// .reference_pass_name = "tree_profile",
89401 + .reference_pass_name = "optimized",
89402 + .ref_pass_instance_number = 1,
89403 + .pos_op = PASS_POS_INSERT_BEFORE
89404 + };
89405 + struct register_pass_info stackleak_final_pass_info = {
89406 + .pass = &stackleak_final_rtl_opt_pass.pass,
89407 + .reference_pass_name = "final",
89408 + .ref_pass_instance_number = 1,
89409 + .pos_op = PASS_POS_INSERT_BEFORE
89410 + };
89411 +
89412 + if (!plugin_default_version_check(version, &gcc_version)) {
89413 + error(G_("incompatible gcc/plugin versions"));
89414 + return 1;
89415 + }
89416 +
89417 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89418 +
89419 + for (i = 0; i < argc; ++i) {
89420 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89421 + if (!argv[i].value) {
89422 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89423 + continue;
89424 + }
89425 + track_frame_size = atoi(argv[i].value);
89426 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89427 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89428 + continue;
89429 + }
89430 + if (!strcmp(argv[i].key, "initialize-locals")) {
89431 + if (argv[i].value) {
89432 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89433 + continue;
89434 + }
89435 + init_locals = true;
89436 + continue;
89437 + }
89438 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89439 + }
89440 +
89441 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89442 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89443 +
89444 + return 0;
89445 +}
89446 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89447 index 6789d78..4afd019e 100644
89448 --- a/tools/perf/util/include/asm/alternative-asm.h
89449 +++ b/tools/perf/util/include/asm/alternative-asm.h
89450 @@ -5,4 +5,7 @@
89451
89452 #define altinstruction_entry #
89453
89454 + .macro pax_force_retaddr rip=0, reload=0
89455 + .endm
89456 +
89457 #endif
89458 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
89459 index af0f22f..9a7d479 100644
89460 --- a/usr/gen_init_cpio.c
89461 +++ b/usr/gen_init_cpio.c
89462 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
89463 int retval;
89464 int rc = -1;
89465 int namesize;
89466 - int i;
89467 + unsigned int i;
89468
89469 mode |= S_IFREG;
89470
89471 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
89472 *env_var = *expanded = '\0';
89473 strncat(env_var, start + 2, end - start - 2);
89474 strncat(expanded, new_location, start - new_location);
89475 - strncat(expanded, getenv(env_var), PATH_MAX);
89476 - strncat(expanded, end + 1, PATH_MAX);
89477 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
89478 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
89479 strncpy(new_location, expanded, PATH_MAX);
89480 + new_location[PATH_MAX] = 0;
89481 } else
89482 break;
89483 }
89484 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89485 index d617f69..6b445d2 100644
89486 --- a/virt/kvm/kvm_main.c
89487 +++ b/virt/kvm/kvm_main.c
89488 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89489
89490 static cpumask_var_t cpus_hardware_enabled;
89491 static int kvm_usage_count = 0;
89492 -static atomic_t hardware_enable_failed;
89493 +static atomic_unchecked_t hardware_enable_failed;
89494
89495 struct kmem_cache *kvm_vcpu_cache;
89496 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89497 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89498 /* We can read the guest memory with __xxx_user() later on. */
89499 if (user_alloc &&
89500 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89501 - !access_ok(VERIFY_WRITE,
89502 + !__access_ok(VERIFY_WRITE,
89503 (void __user *)(unsigned long)mem->userspace_addr,
89504 mem->memory_size)))
89505 goto out;
89506 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89507
89508 if (r) {
89509 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89510 - atomic_inc(&hardware_enable_failed);
89511 + atomic_inc_unchecked(&hardware_enable_failed);
89512 printk(KERN_INFO "kvm: enabling virtualization on "
89513 "CPU%d failed\n", cpu);
89514 }
89515 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89516
89517 kvm_usage_count++;
89518 if (kvm_usage_count == 1) {
89519 - atomic_set(&hardware_enable_failed, 0);
89520 + atomic_set_unchecked(&hardware_enable_failed, 0);
89521 on_each_cpu(hardware_enable_nolock, NULL, 1);
89522
89523 - if (atomic_read(&hardware_enable_failed)) {
89524 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89525 hardware_disable_all_nolock();
89526 r = -EBUSY;
89527 }
89528 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89529 kvm_arch_vcpu_put(vcpu);
89530 }
89531
89532 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89533 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89534 struct module *module)
89535 {
89536 int r;
89537 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89538 if (!vcpu_align)
89539 vcpu_align = __alignof__(struct kvm_vcpu);
89540 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89541 - 0, NULL);
89542 + SLAB_USERCOPY, NULL);
89543 if (!kvm_vcpu_cache) {
89544 r = -ENOMEM;
89545 goto out_free_3;
89546 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89547 if (r)
89548 goto out_free;
89549
89550 - kvm_chardev_ops.owner = module;
89551 - kvm_vm_fops.owner = module;
89552 - kvm_vcpu_fops.owner = module;
89553 + pax_open_kernel();
89554 + *(void **)&kvm_chardev_ops.owner = module;
89555 + *(void **)&kvm_vm_fops.owner = module;
89556 + *(void **)&kvm_vcpu_fops.owner = module;
89557 + pax_close_kernel();
89558
89559 r = misc_register(&kvm_dev);
89560 if (r) {