]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.4-201210291446.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.4-201210291446.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 dcf132a..db194e3 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 7f5f65d..3308382 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 @@ -218,7 +218,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), %g0
5995 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5996 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
5997
5998 2:
5999 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6000 index a5785ea..405c5f7 100644
6001 --- a/arch/sparc/kernel/traps_32.c
6002 +++ b/arch/sparc/kernel/traps_32.c
6003 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6004 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6005 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6006
6007 +extern void gr_handle_kernel_exploit(void);
6008 +
6009 void die_if_kernel(char *str, struct pt_regs *regs)
6010 {
6011 static int die_counter;
6012 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6013 count++ < 30 &&
6014 (((unsigned long) rw) >= PAGE_OFFSET) &&
6015 !(((unsigned long) rw) & 0x7)) {
6016 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6017 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6018 (void *) rw->ins[7]);
6019 rw = (struct reg_window32 *)rw->ins[6];
6020 }
6021 }
6022 printk("Instruction DUMP:");
6023 instruction_dump ((unsigned long *) regs->pc);
6024 - if(regs->psr & PSR_PS)
6025 + if(regs->psr & PSR_PS) {
6026 + gr_handle_kernel_exploit();
6027 do_exit(SIGKILL);
6028 + }
6029 do_exit(SIGSEGV);
6030 }
6031
6032 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6033 index 3b05e66..6ea2917 100644
6034 --- a/arch/sparc/kernel/traps_64.c
6035 +++ b/arch/sparc/kernel/traps_64.c
6036 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6037 i + 1,
6038 p->trapstack[i].tstate, p->trapstack[i].tpc,
6039 p->trapstack[i].tnpc, p->trapstack[i].tt);
6040 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6041 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6042 }
6043 }
6044
6045 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6046
6047 lvl -= 0x100;
6048 if (regs->tstate & TSTATE_PRIV) {
6049 +
6050 +#ifdef CONFIG_PAX_REFCOUNT
6051 + if (lvl == 6)
6052 + pax_report_refcount_overflow(regs);
6053 +#endif
6054 +
6055 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6056 die_if_kernel(buffer, regs);
6057 }
6058 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6059 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6060 {
6061 char buffer[32];
6062 -
6063 +
6064 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6065 0, lvl, SIGTRAP) == NOTIFY_STOP)
6066 return;
6067
6068 +#ifdef CONFIG_PAX_REFCOUNT
6069 + if (lvl == 6)
6070 + pax_report_refcount_overflow(regs);
6071 +#endif
6072 +
6073 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6074
6075 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6076 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6077 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6078 printk("%s" "ERROR(%d): ",
6079 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6080 - printk("TPC<%pS>\n", (void *) regs->tpc);
6081 + printk("TPC<%pA>\n", (void *) regs->tpc);
6082 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6083 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6084 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6085 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6086 smp_processor_id(),
6087 (type & 0x1) ? 'I' : 'D',
6088 regs->tpc);
6089 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6090 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6091 panic("Irrecoverable Cheetah+ parity error.");
6092 }
6093
6094 @@ -1756,7 +1767,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_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6099 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6100 }
6101
6102 struct sun4v_error_entry {
6103 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6104
6105 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6106 regs->tpc, tl);
6107 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6108 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6109 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6110 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6111 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6112 (void *) regs->u_regs[UREG_I7]);
6113 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6114 "pte[%lx] error[%lx]\n",
6115 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6116
6117 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6118 regs->tpc, tl);
6119 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6120 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6121 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6122 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6123 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6124 (void *) regs->u_regs[UREG_I7]);
6125 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6126 "pte[%lx] error[%lx]\n",
6127 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6128 fp = (unsigned long)sf->fp + STACK_BIAS;
6129 }
6130
6131 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6132 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6133 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6134 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6135 int index = tsk->curr_ret_stack;
6136 if (tsk->ret_stack && index >= graph) {
6137 pc = tsk->ret_stack[index - graph].ret;
6138 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6139 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6140 graph++;
6141 }
6142 }
6143 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6144 return (struct reg_window *) (fp + STACK_BIAS);
6145 }
6146
6147 +extern void gr_handle_kernel_exploit(void);
6148 +
6149 void die_if_kernel(char *str, struct pt_regs *regs)
6150 {
6151 static int die_counter;
6152 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6153 while (rw &&
6154 count++ < 30 &&
6155 kstack_valid(tp, (unsigned long) rw)) {
6156 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6157 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6158 (void *) rw->ins[7]);
6159
6160 rw = kernel_stack_up(rw);
6161 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6162 }
6163 user_instruction_dump ((unsigned int __user *) regs->tpc);
6164 }
6165 - if (regs->tstate & TSTATE_PRIV)
6166 + if (regs->tstate & TSTATE_PRIV) {
6167 + gr_handle_kernel_exploit();
6168 do_exit(SIGKILL);
6169 + }
6170 do_exit(SIGSEGV);
6171 }
6172 EXPORT_SYMBOL(die_if_kernel);
6173 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6174 index f81d038..e7a4680 100644
6175 --- a/arch/sparc/kernel/unaligned_64.c
6176 +++ b/arch/sparc/kernel/unaligned_64.c
6177 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6178 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6179
6180 if (__ratelimit(&ratelimit)) {
6181 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6182 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6183 regs->tpc, (void *) regs->tpc);
6184 }
6185 }
6186 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6187 index dff4096..bd9a388 100644
6188 --- a/arch/sparc/lib/Makefile
6189 +++ b/arch/sparc/lib/Makefile
6190 @@ -2,7 +2,7 @@
6191 #
6192
6193 asflags-y := -ansi -DST_DIV0=0x02
6194 -ccflags-y := -Werror
6195 +#ccflags-y := -Werror
6196
6197 lib-$(CONFIG_SPARC32) += ashrdi3.o
6198 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6199 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6200 index 4d502da..527c48d 100644
6201 --- a/arch/sparc/lib/atomic_64.S
6202 +++ b/arch/sparc/lib/atomic_64.S
6203 @@ -17,7 +17,12 @@
6204 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6205 BACKOFF_SETUP(%o2)
6206 1: lduw [%o1], %g1
6207 - add %g1, %o0, %g7
6208 + addcc %g1, %o0, %g7
6209 +
6210 +#ifdef CONFIG_PAX_REFCOUNT
6211 + tvs %icc, 6
6212 +#endif
6213 +
6214 cas [%o1], %g1, %g7
6215 cmp %g1, %g7
6216 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6217 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6218 2: BACKOFF_SPIN(%o2, %o3, 1b)
6219 ENDPROC(atomic_add)
6220
6221 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6222 + BACKOFF_SETUP(%o2)
6223 +1: lduw [%o1], %g1
6224 + add %g1, %o0, %g7
6225 + cas [%o1], %g1, %g7
6226 + cmp %g1, %g7
6227 + bne,pn %icc, 2f
6228 + nop
6229 + retl
6230 + nop
6231 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6232 +ENDPROC(atomic_add_unchecked)
6233 +
6234 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6235 BACKOFF_SETUP(%o2)
6236 1: lduw [%o1], %g1
6237 - sub %g1, %o0, %g7
6238 + subcc %g1, %o0, %g7
6239 +
6240 +#ifdef CONFIG_PAX_REFCOUNT
6241 + tvs %icc, 6
6242 +#endif
6243 +
6244 cas [%o1], %g1, %g7
6245 cmp %g1, %g7
6246 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6247 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6248 2: BACKOFF_SPIN(%o2, %o3, 1b)
6249 ENDPROC(atomic_sub)
6250
6251 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6252 + BACKOFF_SETUP(%o2)
6253 +1: lduw [%o1], %g1
6254 + sub %g1, %o0, %g7
6255 + cas [%o1], %g1, %g7
6256 + cmp %g1, %g7
6257 + bne,pn %icc, 2f
6258 + nop
6259 + retl
6260 + nop
6261 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6262 +ENDPROC(atomic_sub_unchecked)
6263 +
6264 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6265 BACKOFF_SETUP(%o2)
6266 1: lduw [%o1], %g1
6267 - add %g1, %o0, %g7
6268 + addcc %g1, %o0, %g7
6269 +
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + tvs %icc, 6
6272 +#endif
6273 +
6274 cas [%o1], %g1, %g7
6275 cmp %g1, %g7
6276 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6277 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6278 2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 ENDPROC(atomic_add_ret)
6280
6281 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6282 + BACKOFF_SETUP(%o2)
6283 +1: lduw [%o1], %g1
6284 + addcc %g1, %o0, %g7
6285 + cas [%o1], %g1, %g7
6286 + cmp %g1, %g7
6287 + bne,pn %icc, 2f
6288 + add %g7, %o0, %g7
6289 + sra %g7, 0, %o0
6290 + retl
6291 + nop
6292 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6293 +ENDPROC(atomic_add_ret_unchecked)
6294 +
6295 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298 - sub %g1, %o0, %g7
6299 + subcc %g1, %o0, %g7
6300 +
6301 +#ifdef CONFIG_PAX_REFCOUNT
6302 + tvs %icc, 6
6303 +#endif
6304 +
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6309 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6310 BACKOFF_SETUP(%o2)
6311 1: ldx [%o1], %g1
6312 - add %g1, %o0, %g7
6313 + addcc %g1, %o0, %g7
6314 +
6315 +#ifdef CONFIG_PAX_REFCOUNT
6316 + tvs %xcc, 6
6317 +#endif
6318 +
6319 casx [%o1], %g1, %g7
6320 cmp %g1, %g7
6321 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6322 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6323 2: BACKOFF_SPIN(%o2, %o3, 1b)
6324 ENDPROC(atomic64_add)
6325
6326 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6327 + BACKOFF_SETUP(%o2)
6328 +1: ldx [%o1], %g1
6329 + addcc %g1, %o0, %g7
6330 + casx [%o1], %g1, %g7
6331 + cmp %g1, %g7
6332 + bne,pn %xcc, 2f
6333 + nop
6334 + retl
6335 + nop
6336 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6337 +ENDPROC(atomic64_add_unchecked)
6338 +
6339 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6340 BACKOFF_SETUP(%o2)
6341 1: ldx [%o1], %g1
6342 - sub %g1, %o0, %g7
6343 + subcc %g1, %o0, %g7
6344 +
6345 +#ifdef CONFIG_PAX_REFCOUNT
6346 + tvs %xcc, 6
6347 +#endif
6348 +
6349 casx [%o1], %g1, %g7
6350 cmp %g1, %g7
6351 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6352 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6353 2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 ENDPROC(atomic64_sub)
6355
6356 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6357 + BACKOFF_SETUP(%o2)
6358 +1: ldx [%o1], %g1
6359 + subcc %g1, %o0, %g7
6360 + casx [%o1], %g1, %g7
6361 + cmp %g1, %g7
6362 + bne,pn %xcc, 2f
6363 + nop
6364 + retl
6365 + nop
6366 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6367 +ENDPROC(atomic64_sub_unchecked)
6368 +
6369 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6370 BACKOFF_SETUP(%o2)
6371 1: ldx [%o1], %g1
6372 - add %g1, %o0, %g7
6373 + addcc %g1, %o0, %g7
6374 +
6375 +#ifdef CONFIG_PAX_REFCOUNT
6376 + tvs %xcc, 6
6377 +#endif
6378 +
6379 casx [%o1], %g1, %g7
6380 cmp %g1, %g7
6381 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6382 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6383 2: BACKOFF_SPIN(%o2, %o3, 1b)
6384 ENDPROC(atomic64_add_ret)
6385
6386 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6387 + BACKOFF_SETUP(%o2)
6388 +1: ldx [%o1], %g1
6389 + addcc %g1, %o0, %g7
6390 + casx [%o1], %g1, %g7
6391 + cmp %g1, %g7
6392 + bne,pn %xcc, 2f
6393 + add %g7, %o0, %g7
6394 + mov %g7, %o0
6395 + retl
6396 + nop
6397 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6398 +ENDPROC(atomic64_add_ret_unchecked)
6399 +
6400 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - sub %g1, %o0, %g7
6404 + subcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6414 index 3b31218..345c609 100644
6415 --- a/arch/sparc/lib/ksyms.c
6416 +++ b/arch/sparc/lib/ksyms.c
6417 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6418
6419 /* Atomic counter implementation. */
6420 EXPORT_SYMBOL(atomic_add);
6421 +EXPORT_SYMBOL(atomic_add_unchecked);
6422 EXPORT_SYMBOL(atomic_add_ret);
6423 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6424 EXPORT_SYMBOL(atomic_sub);
6425 +EXPORT_SYMBOL(atomic_sub_unchecked);
6426 EXPORT_SYMBOL(atomic_sub_ret);
6427 EXPORT_SYMBOL(atomic64_add);
6428 +EXPORT_SYMBOL(atomic64_add_unchecked);
6429 EXPORT_SYMBOL(atomic64_add_ret);
6430 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6431 EXPORT_SYMBOL(atomic64_sub);
6432 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6433 EXPORT_SYMBOL(atomic64_sub_ret);
6434
6435 /* Atomic bit operations. */
6436 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6437 index 30c3ecc..736f015 100644
6438 --- a/arch/sparc/mm/Makefile
6439 +++ b/arch/sparc/mm/Makefile
6440 @@ -2,7 +2,7 @@
6441 #
6442
6443 asflags-y := -ansi
6444 -ccflags-y := -Werror
6445 +#ccflags-y := -Werror
6446
6447 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6448 obj-y += fault_$(BITS).o
6449 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6450 index 77ac917..baf45db 100644
6451 --- a/arch/sparc/mm/fault_32.c
6452 +++ b/arch/sparc/mm/fault_32.c
6453 @@ -21,6 +21,9 @@
6454 #include <linux/perf_event.h>
6455 #include <linux/interrupt.h>
6456 #include <linux/kdebug.h>
6457 +#include <linux/slab.h>
6458 +#include <linux/pagemap.h>
6459 +#include <linux/compiler.h>
6460
6461 #include <asm/page.h>
6462 #include <asm/pgtable.h>
6463 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6464 return safe_compute_effective_address(regs, insn);
6465 }
6466
6467 +#ifdef CONFIG_PAX_PAGEEXEC
6468 +#ifdef CONFIG_PAX_DLRESOLVE
6469 +static void pax_emuplt_close(struct vm_area_struct *vma)
6470 +{
6471 + vma->vm_mm->call_dl_resolve = 0UL;
6472 +}
6473 +
6474 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6475 +{
6476 + unsigned int *kaddr;
6477 +
6478 + vmf->page = alloc_page(GFP_HIGHUSER);
6479 + if (!vmf->page)
6480 + return VM_FAULT_OOM;
6481 +
6482 + kaddr = kmap(vmf->page);
6483 + memset(kaddr, 0, PAGE_SIZE);
6484 + kaddr[0] = 0x9DE3BFA8U; /* save */
6485 + flush_dcache_page(vmf->page);
6486 + kunmap(vmf->page);
6487 + return VM_FAULT_MAJOR;
6488 +}
6489 +
6490 +static const struct vm_operations_struct pax_vm_ops = {
6491 + .close = pax_emuplt_close,
6492 + .fault = pax_emuplt_fault
6493 +};
6494 +
6495 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6496 +{
6497 + int ret;
6498 +
6499 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6500 + vma->vm_mm = current->mm;
6501 + vma->vm_start = addr;
6502 + vma->vm_end = addr + PAGE_SIZE;
6503 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6504 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6505 + vma->vm_ops = &pax_vm_ops;
6506 +
6507 + ret = insert_vm_struct(current->mm, vma);
6508 + if (ret)
6509 + return ret;
6510 +
6511 + ++current->mm->total_vm;
6512 + return 0;
6513 +}
6514 +#endif
6515 +
6516 +/*
6517 + * PaX: decide what to do with offenders (regs->pc = fault address)
6518 + *
6519 + * returns 1 when task should be killed
6520 + * 2 when patched PLT trampoline was detected
6521 + * 3 when unpatched PLT trampoline was detected
6522 + */
6523 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6524 +{
6525 +
6526 +#ifdef CONFIG_PAX_EMUPLT
6527 + int err;
6528 +
6529 + do { /* PaX: patched PLT emulation #1 */
6530 + unsigned int sethi1, sethi2, jmpl;
6531 +
6532 + err = get_user(sethi1, (unsigned int *)regs->pc);
6533 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6534 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6535 +
6536 + if (err)
6537 + break;
6538 +
6539 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6540 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6541 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6542 + {
6543 + unsigned int addr;
6544 +
6545 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6546 + addr = regs->u_regs[UREG_G1];
6547 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6548 + regs->pc = addr;
6549 + regs->npc = addr+4;
6550 + return 2;
6551 + }
6552 + } while (0);
6553 +
6554 + do { /* PaX: patched PLT emulation #2 */
6555 + unsigned int ba;
6556 +
6557 + err = get_user(ba, (unsigned int *)regs->pc);
6558 +
6559 + if (err)
6560 + break;
6561 +
6562 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6563 + unsigned int addr;
6564 +
6565 + if ((ba & 0xFFC00000U) == 0x30800000U)
6566 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6567 + else
6568 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6569 + regs->pc = addr;
6570 + regs->npc = addr+4;
6571 + return 2;
6572 + }
6573 + } while (0);
6574 +
6575 + do { /* PaX: patched PLT emulation #3 */
6576 + unsigned int sethi, bajmpl, nop;
6577 +
6578 + err = get_user(sethi, (unsigned int *)regs->pc);
6579 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6580 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6581 +
6582 + if (err)
6583 + break;
6584 +
6585 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6586 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6587 + nop == 0x01000000U)
6588 + {
6589 + unsigned int addr;
6590 +
6591 + addr = (sethi & 0x003FFFFFU) << 10;
6592 + regs->u_regs[UREG_G1] = addr;
6593 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6594 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6595 + else
6596 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6597 + regs->pc = addr;
6598 + regs->npc = addr+4;
6599 + return 2;
6600 + }
6601 + } while (0);
6602 +
6603 + do { /* PaX: unpatched PLT emulation step 1 */
6604 + unsigned int sethi, ba, nop;
6605 +
6606 + err = get_user(sethi, (unsigned int *)regs->pc);
6607 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6608 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6609 +
6610 + if (err)
6611 + break;
6612 +
6613 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6614 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6615 + nop == 0x01000000U)
6616 + {
6617 + unsigned int addr, save, call;
6618 +
6619 + if ((ba & 0xFFC00000U) == 0x30800000U)
6620 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6621 + else
6622 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6623 +
6624 + err = get_user(save, (unsigned int *)addr);
6625 + err |= get_user(call, (unsigned int *)(addr+4));
6626 + err |= get_user(nop, (unsigned int *)(addr+8));
6627 + if (err)
6628 + break;
6629 +
6630 +#ifdef CONFIG_PAX_DLRESOLVE
6631 + if (save == 0x9DE3BFA8U &&
6632 + (call & 0xC0000000U) == 0x40000000U &&
6633 + nop == 0x01000000U)
6634 + {
6635 + struct vm_area_struct *vma;
6636 + unsigned long call_dl_resolve;
6637 +
6638 + down_read(&current->mm->mmap_sem);
6639 + call_dl_resolve = current->mm->call_dl_resolve;
6640 + up_read(&current->mm->mmap_sem);
6641 + if (likely(call_dl_resolve))
6642 + goto emulate;
6643 +
6644 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6645 +
6646 + down_write(&current->mm->mmap_sem);
6647 + if (current->mm->call_dl_resolve) {
6648 + call_dl_resolve = current->mm->call_dl_resolve;
6649 + up_write(&current->mm->mmap_sem);
6650 + if (vma)
6651 + kmem_cache_free(vm_area_cachep, vma);
6652 + goto emulate;
6653 + }
6654 +
6655 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6656 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6657 + up_write(&current->mm->mmap_sem);
6658 + if (vma)
6659 + kmem_cache_free(vm_area_cachep, vma);
6660 + return 1;
6661 + }
6662 +
6663 + if (pax_insert_vma(vma, call_dl_resolve)) {
6664 + up_write(&current->mm->mmap_sem);
6665 + kmem_cache_free(vm_area_cachep, vma);
6666 + return 1;
6667 + }
6668 +
6669 + current->mm->call_dl_resolve = call_dl_resolve;
6670 + up_write(&current->mm->mmap_sem);
6671 +
6672 +emulate:
6673 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6674 + regs->pc = call_dl_resolve;
6675 + regs->npc = addr+4;
6676 + return 3;
6677 + }
6678 +#endif
6679 +
6680 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6681 + if ((save & 0xFFC00000U) == 0x05000000U &&
6682 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6683 + nop == 0x01000000U)
6684 + {
6685 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6686 + regs->u_regs[UREG_G2] = addr + 4;
6687 + addr = (save & 0x003FFFFFU) << 10;
6688 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6689 + regs->pc = addr;
6690 + regs->npc = addr+4;
6691 + return 3;
6692 + }
6693 + }
6694 + } while (0);
6695 +
6696 + do { /* PaX: unpatched PLT emulation step 2 */
6697 + unsigned int save, call, nop;
6698 +
6699 + err = get_user(save, (unsigned int *)(regs->pc-4));
6700 + err |= get_user(call, (unsigned int *)regs->pc);
6701 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6702 + if (err)
6703 + break;
6704 +
6705 + if (save == 0x9DE3BFA8U &&
6706 + (call & 0xC0000000U) == 0x40000000U &&
6707 + nop == 0x01000000U)
6708 + {
6709 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6710 +
6711 + regs->u_regs[UREG_RETPC] = regs->pc;
6712 + regs->pc = dl_resolve;
6713 + regs->npc = dl_resolve+4;
6714 + return 3;
6715 + }
6716 + } while (0);
6717 +#endif
6718 +
6719 + return 1;
6720 +}
6721 +
6722 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6723 +{
6724 + unsigned long i;
6725 +
6726 + printk(KERN_ERR "PAX: bytes at PC: ");
6727 + for (i = 0; i < 8; i++) {
6728 + unsigned int c;
6729 + if (get_user(c, (unsigned int *)pc+i))
6730 + printk(KERN_CONT "???????? ");
6731 + else
6732 + printk(KERN_CONT "%08x ", c);
6733 + }
6734 + printk("\n");
6735 +}
6736 +#endif
6737 +
6738 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6739 int text_fault)
6740 {
6741 @@ -230,6 +504,24 @@ good_area:
6742 if (!(vma->vm_flags & VM_WRITE))
6743 goto bad_area;
6744 } else {
6745 +
6746 +#ifdef CONFIG_PAX_PAGEEXEC
6747 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6748 + up_read(&mm->mmap_sem);
6749 + switch (pax_handle_fetch_fault(regs)) {
6750 +
6751 +#ifdef CONFIG_PAX_EMUPLT
6752 + case 2:
6753 + case 3:
6754 + return;
6755 +#endif
6756 +
6757 + }
6758 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6759 + do_group_exit(SIGKILL);
6760 + }
6761 +#endif
6762 +
6763 /* Allow reads even for write-only mappings */
6764 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6765 goto bad_area;
6766 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6767 index 1fe0429..8dd5dd5 100644
6768 --- a/arch/sparc/mm/fault_64.c
6769 +++ b/arch/sparc/mm/fault_64.c
6770 @@ -21,6 +21,9 @@
6771 #include <linux/kprobes.h>
6772 #include <linux/kdebug.h>
6773 #include <linux/percpu.h>
6774 +#include <linux/slab.h>
6775 +#include <linux/pagemap.h>
6776 +#include <linux/compiler.h>
6777
6778 #include <asm/page.h>
6779 #include <asm/pgtable.h>
6780 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6781 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6782 regs->tpc);
6783 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6784 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6785 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6786 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6787 dump_stack();
6788 unhandled_fault(regs->tpc, current, regs);
6789 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6790 show_regs(regs);
6791 }
6792
6793 +#ifdef CONFIG_PAX_PAGEEXEC
6794 +#ifdef CONFIG_PAX_DLRESOLVE
6795 +static void pax_emuplt_close(struct vm_area_struct *vma)
6796 +{
6797 + vma->vm_mm->call_dl_resolve = 0UL;
6798 +}
6799 +
6800 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6801 +{
6802 + unsigned int *kaddr;
6803 +
6804 + vmf->page = alloc_page(GFP_HIGHUSER);
6805 + if (!vmf->page)
6806 + return VM_FAULT_OOM;
6807 +
6808 + kaddr = kmap(vmf->page);
6809 + memset(kaddr, 0, PAGE_SIZE);
6810 + kaddr[0] = 0x9DE3BFA8U; /* save */
6811 + flush_dcache_page(vmf->page);
6812 + kunmap(vmf->page);
6813 + return VM_FAULT_MAJOR;
6814 +}
6815 +
6816 +static const struct vm_operations_struct pax_vm_ops = {
6817 + .close = pax_emuplt_close,
6818 + .fault = pax_emuplt_fault
6819 +};
6820 +
6821 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6822 +{
6823 + int ret;
6824 +
6825 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6826 + vma->vm_mm = current->mm;
6827 + vma->vm_start = addr;
6828 + vma->vm_end = addr + PAGE_SIZE;
6829 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6830 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6831 + vma->vm_ops = &pax_vm_ops;
6832 +
6833 + ret = insert_vm_struct(current->mm, vma);
6834 + if (ret)
6835 + return ret;
6836 +
6837 + ++current->mm->total_vm;
6838 + return 0;
6839 +}
6840 +#endif
6841 +
6842 +/*
6843 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6844 + *
6845 + * returns 1 when task should be killed
6846 + * 2 when patched PLT trampoline was detected
6847 + * 3 when unpatched PLT trampoline was detected
6848 + */
6849 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6850 +{
6851 +
6852 +#ifdef CONFIG_PAX_EMUPLT
6853 + int err;
6854 +
6855 + do { /* PaX: patched PLT emulation #1 */
6856 + unsigned int sethi1, sethi2, jmpl;
6857 +
6858 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6859 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6860 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6861 +
6862 + if (err)
6863 + break;
6864 +
6865 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6866 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6867 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6868 + {
6869 + unsigned long addr;
6870 +
6871 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6872 + addr = regs->u_regs[UREG_G1];
6873 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6874 +
6875 + if (test_thread_flag(TIF_32BIT))
6876 + addr &= 0xFFFFFFFFUL;
6877 +
6878 + regs->tpc = addr;
6879 + regs->tnpc = addr+4;
6880 + return 2;
6881 + }
6882 + } while (0);
6883 +
6884 + do { /* PaX: patched PLT emulation #2 */
6885 + unsigned int ba;
6886 +
6887 + err = get_user(ba, (unsigned int *)regs->tpc);
6888 +
6889 + if (err)
6890 + break;
6891 +
6892 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6893 + unsigned long addr;
6894 +
6895 + if ((ba & 0xFFC00000U) == 0x30800000U)
6896 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6897 + else
6898 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6899 +
6900 + if (test_thread_flag(TIF_32BIT))
6901 + addr &= 0xFFFFFFFFUL;
6902 +
6903 + regs->tpc = addr;
6904 + regs->tnpc = addr+4;
6905 + return 2;
6906 + }
6907 + } while (0);
6908 +
6909 + do { /* PaX: patched PLT emulation #3 */
6910 + unsigned int sethi, bajmpl, nop;
6911 +
6912 + err = get_user(sethi, (unsigned int *)regs->tpc);
6913 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6914 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6915 +
6916 + if (err)
6917 + break;
6918 +
6919 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6920 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6921 + nop == 0x01000000U)
6922 + {
6923 + unsigned long addr;
6924 +
6925 + addr = (sethi & 0x003FFFFFU) << 10;
6926 + regs->u_regs[UREG_G1] = addr;
6927 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6928 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6929 + else
6930 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6931 +
6932 + if (test_thread_flag(TIF_32BIT))
6933 + addr &= 0xFFFFFFFFUL;
6934 +
6935 + regs->tpc = addr;
6936 + regs->tnpc = addr+4;
6937 + return 2;
6938 + }
6939 + } while (0);
6940 +
6941 + do { /* PaX: patched PLT emulation #4 */
6942 + unsigned int sethi, mov1, call, mov2;
6943 +
6944 + err = get_user(sethi, (unsigned int *)regs->tpc);
6945 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6946 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6947 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6948 +
6949 + if (err)
6950 + break;
6951 +
6952 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6953 + mov1 == 0x8210000FU &&
6954 + (call & 0xC0000000U) == 0x40000000U &&
6955 + mov2 == 0x9E100001U)
6956 + {
6957 + unsigned long addr;
6958 +
6959 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6960 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6961 +
6962 + if (test_thread_flag(TIF_32BIT))
6963 + addr &= 0xFFFFFFFFUL;
6964 +
6965 + regs->tpc = addr;
6966 + regs->tnpc = addr+4;
6967 + return 2;
6968 + }
6969 + } while (0);
6970 +
6971 + do { /* PaX: patched PLT emulation #5 */
6972 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6973 +
6974 + err = get_user(sethi, (unsigned int *)regs->tpc);
6975 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6976 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6977 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6978 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6979 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6980 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6981 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6982 +
6983 + if (err)
6984 + break;
6985 +
6986 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6987 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6988 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6989 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6990 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6991 + sllx == 0x83287020U &&
6992 + jmpl == 0x81C04005U &&
6993 + nop == 0x01000000U)
6994 + {
6995 + unsigned long addr;
6996 +
6997 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6998 + regs->u_regs[UREG_G1] <<= 32;
6999 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7000 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7001 + regs->tpc = addr;
7002 + regs->tnpc = addr+4;
7003 + return 2;
7004 + }
7005 + } while (0);
7006 +
7007 + do { /* PaX: patched PLT emulation #6 */
7008 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7009 +
7010 + err = get_user(sethi, (unsigned int *)regs->tpc);
7011 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7012 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7013 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7014 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7015 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7016 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7017 +
7018 + if (err)
7019 + break;
7020 +
7021 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7022 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7023 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7024 + sllx == 0x83287020U &&
7025 + (or & 0xFFFFE000U) == 0x8A116000U &&
7026 + jmpl == 0x81C04005U &&
7027 + nop == 0x01000000U)
7028 + {
7029 + unsigned long addr;
7030 +
7031 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7032 + regs->u_regs[UREG_G1] <<= 32;
7033 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7034 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7035 + regs->tpc = addr;
7036 + regs->tnpc = addr+4;
7037 + return 2;
7038 + }
7039 + } while (0);
7040 +
7041 + do { /* PaX: unpatched PLT emulation step 1 */
7042 + unsigned int sethi, ba, nop;
7043 +
7044 + err = get_user(sethi, (unsigned int *)regs->tpc);
7045 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7046 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7047 +
7048 + if (err)
7049 + break;
7050 +
7051 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7052 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7053 + nop == 0x01000000U)
7054 + {
7055 + unsigned long addr;
7056 + unsigned int save, call;
7057 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7058 +
7059 + if ((ba & 0xFFC00000U) == 0x30800000U)
7060 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7061 + else
7062 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7063 +
7064 + if (test_thread_flag(TIF_32BIT))
7065 + addr &= 0xFFFFFFFFUL;
7066 +
7067 + err = get_user(save, (unsigned int *)addr);
7068 + err |= get_user(call, (unsigned int *)(addr+4));
7069 + err |= get_user(nop, (unsigned int *)(addr+8));
7070 + if (err)
7071 + break;
7072 +
7073 +#ifdef CONFIG_PAX_DLRESOLVE
7074 + if (save == 0x9DE3BFA8U &&
7075 + (call & 0xC0000000U) == 0x40000000U &&
7076 + nop == 0x01000000U)
7077 + {
7078 + struct vm_area_struct *vma;
7079 + unsigned long call_dl_resolve;
7080 +
7081 + down_read(&current->mm->mmap_sem);
7082 + call_dl_resolve = current->mm->call_dl_resolve;
7083 + up_read(&current->mm->mmap_sem);
7084 + if (likely(call_dl_resolve))
7085 + goto emulate;
7086 +
7087 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7088 +
7089 + down_write(&current->mm->mmap_sem);
7090 + if (current->mm->call_dl_resolve) {
7091 + call_dl_resolve = current->mm->call_dl_resolve;
7092 + up_write(&current->mm->mmap_sem);
7093 + if (vma)
7094 + kmem_cache_free(vm_area_cachep, vma);
7095 + goto emulate;
7096 + }
7097 +
7098 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7099 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7100 + up_write(&current->mm->mmap_sem);
7101 + if (vma)
7102 + kmem_cache_free(vm_area_cachep, vma);
7103 + return 1;
7104 + }
7105 +
7106 + if (pax_insert_vma(vma, call_dl_resolve)) {
7107 + up_write(&current->mm->mmap_sem);
7108 + kmem_cache_free(vm_area_cachep, vma);
7109 + return 1;
7110 + }
7111 +
7112 + current->mm->call_dl_resolve = call_dl_resolve;
7113 + up_write(&current->mm->mmap_sem);
7114 +
7115 +emulate:
7116 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7117 + regs->tpc = call_dl_resolve;
7118 + regs->tnpc = addr+4;
7119 + return 3;
7120 + }
7121 +#endif
7122 +
7123 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7124 + if ((save & 0xFFC00000U) == 0x05000000U &&
7125 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7126 + nop == 0x01000000U)
7127 + {
7128 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7129 + regs->u_regs[UREG_G2] = addr + 4;
7130 + addr = (save & 0x003FFFFFU) << 10;
7131 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7132 +
7133 + if (test_thread_flag(TIF_32BIT))
7134 + addr &= 0xFFFFFFFFUL;
7135 +
7136 + regs->tpc = addr;
7137 + regs->tnpc = addr+4;
7138 + return 3;
7139 + }
7140 +
7141 + /* PaX: 64-bit PLT stub */
7142 + err = get_user(sethi1, (unsigned int *)addr);
7143 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7144 + err |= get_user(or1, (unsigned int *)(addr+8));
7145 + err |= get_user(or2, (unsigned int *)(addr+12));
7146 + err |= get_user(sllx, (unsigned int *)(addr+16));
7147 + err |= get_user(add, (unsigned int *)(addr+20));
7148 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7149 + err |= get_user(nop, (unsigned int *)(addr+28));
7150 + if (err)
7151 + break;
7152 +
7153 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7154 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7155 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7156 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7157 + sllx == 0x89293020U &&
7158 + add == 0x8A010005U &&
7159 + jmpl == 0x89C14000U &&
7160 + nop == 0x01000000U)
7161 + {
7162 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7163 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7164 + regs->u_regs[UREG_G4] <<= 32;
7165 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7166 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7167 + regs->u_regs[UREG_G4] = addr + 24;
7168 + addr = regs->u_regs[UREG_G5];
7169 + regs->tpc = addr;
7170 + regs->tnpc = addr+4;
7171 + return 3;
7172 + }
7173 + }
7174 + } while (0);
7175 +
7176 +#ifdef CONFIG_PAX_DLRESOLVE
7177 + do { /* PaX: unpatched PLT emulation step 2 */
7178 + unsigned int save, call, nop;
7179 +
7180 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7181 + err |= get_user(call, (unsigned int *)regs->tpc);
7182 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7183 + if (err)
7184 + break;
7185 +
7186 + if (save == 0x9DE3BFA8U &&
7187 + (call & 0xC0000000U) == 0x40000000U &&
7188 + nop == 0x01000000U)
7189 + {
7190 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7191 +
7192 + if (test_thread_flag(TIF_32BIT))
7193 + dl_resolve &= 0xFFFFFFFFUL;
7194 +
7195 + regs->u_regs[UREG_RETPC] = regs->tpc;
7196 + regs->tpc = dl_resolve;
7197 + regs->tnpc = dl_resolve+4;
7198 + return 3;
7199 + }
7200 + } while (0);
7201 +#endif
7202 +
7203 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7204 + unsigned int sethi, ba, nop;
7205 +
7206 + err = get_user(sethi, (unsigned int *)regs->tpc);
7207 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7208 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7209 +
7210 + if (err)
7211 + break;
7212 +
7213 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7214 + (ba & 0xFFF00000U) == 0x30600000U &&
7215 + nop == 0x01000000U)
7216 + {
7217 + unsigned long addr;
7218 +
7219 + addr = (sethi & 0x003FFFFFU) << 10;
7220 + regs->u_regs[UREG_G1] = addr;
7221 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7222 +
7223 + if (test_thread_flag(TIF_32BIT))
7224 + addr &= 0xFFFFFFFFUL;
7225 +
7226 + regs->tpc = addr;
7227 + regs->tnpc = addr+4;
7228 + return 2;
7229 + }
7230 + } while (0);
7231 +
7232 +#endif
7233 +
7234 + return 1;
7235 +}
7236 +
7237 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7238 +{
7239 + unsigned long i;
7240 +
7241 + printk(KERN_ERR "PAX: bytes at PC: ");
7242 + for (i = 0; i < 8; i++) {
7243 + unsigned int c;
7244 + if (get_user(c, (unsigned int *)pc+i))
7245 + printk(KERN_CONT "???????? ");
7246 + else
7247 + printk(KERN_CONT "%08x ", c);
7248 + }
7249 + printk("\n");
7250 +}
7251 +#endif
7252 +
7253 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7254 {
7255 struct mm_struct *mm = current->mm;
7256 @@ -343,6 +806,29 @@ retry:
7257 if (!vma)
7258 goto bad_area;
7259
7260 +#ifdef CONFIG_PAX_PAGEEXEC
7261 + /* PaX: detect ITLB misses on non-exec pages */
7262 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7263 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7264 + {
7265 + if (address != regs->tpc)
7266 + goto good_area;
7267 +
7268 + up_read(&mm->mmap_sem);
7269 + switch (pax_handle_fetch_fault(regs)) {
7270 +
7271 +#ifdef CONFIG_PAX_EMUPLT
7272 + case 2:
7273 + case 3:
7274 + return;
7275 +#endif
7276 +
7277 + }
7278 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7279 + do_group_exit(SIGKILL);
7280 + }
7281 +#endif
7282 +
7283 /* Pure DTLB misses do not tell us whether the fault causing
7284 * load/store/atomic was a write or not, it only says that there
7285 * was no match. So in such a case we (carefully) read the
7286 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7287 index 07e1453..0a7d9e9 100644
7288 --- a/arch/sparc/mm/hugetlbpage.c
7289 +++ b/arch/sparc/mm/hugetlbpage.c
7290 @@ -67,7 +67,7 @@ full_search:
7291 }
7292 return -ENOMEM;
7293 }
7294 - if (likely(!vma || addr + len <= vma->vm_start)) {
7295 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7296 /*
7297 * Remember the place where we stopped the search:
7298 */
7299 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7300 /* make sure it can fit in the remaining address space */
7301 if (likely(addr > len)) {
7302 vma = find_vma(mm, addr-len);
7303 - if (!vma || addr <= vma->vm_start) {
7304 + if (check_heap_stack_gap(vma, addr - len, len)) {
7305 /* remember the address as a hint for next time */
7306 return (mm->free_area_cache = addr-len);
7307 }
7308 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7309 if (unlikely(mm->mmap_base < len))
7310 goto bottomup;
7311
7312 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7313 + addr = mm->mmap_base - len;
7314
7315 do {
7316 + addr &= HPAGE_MASK;
7317 /*
7318 * Lookup failure means no vma is above this address,
7319 * else if new region fits below vma->vm_start,
7320 * return with success:
7321 */
7322 vma = find_vma(mm, addr);
7323 - if (likely(!vma || addr+len <= vma->vm_start)) {
7324 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7325 /* remember the address as a hint for next time */
7326 return (mm->free_area_cache = addr);
7327 }
7328 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7329 mm->cached_hole_size = vma->vm_start - addr;
7330
7331 /* try just below the current vma->vm_start */
7332 - addr = (vma->vm_start-len) & HPAGE_MASK;
7333 - } while (likely(len < vma->vm_start));
7334 + addr = skip_heap_stack_gap(vma, len);
7335 + } while (!IS_ERR_VALUE(addr));
7336
7337 bottomup:
7338 /*
7339 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7340 if (addr) {
7341 addr = ALIGN(addr, HPAGE_SIZE);
7342 vma = find_vma(mm, addr);
7343 - if (task_size - len >= addr &&
7344 - (!vma || addr + len <= vma->vm_start))
7345 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7346 return addr;
7347 }
7348 if (mm->get_unmapped_area == arch_get_unmapped_area)
7349 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7350 index f4500c6..889656c 100644
7351 --- a/arch/tile/include/asm/atomic_64.h
7352 +++ b/arch/tile/include/asm/atomic_64.h
7353 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7354
7355 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7356
7357 +#define atomic64_read_unchecked(v) atomic64_read(v)
7358 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7359 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7360 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7361 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7362 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7363 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7364 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7365 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7366 +
7367 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7368 #define smp_mb__before_atomic_dec() smp_mb()
7369 #define smp_mb__after_atomic_dec() smp_mb()
7370 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7371 index a9a5299..0fce79e 100644
7372 --- a/arch/tile/include/asm/cache.h
7373 +++ b/arch/tile/include/asm/cache.h
7374 @@ -15,11 +15,12 @@
7375 #ifndef _ASM_TILE_CACHE_H
7376 #define _ASM_TILE_CACHE_H
7377
7378 +#include <linux/const.h>
7379 #include <arch/chip.h>
7380
7381 /* bytes per L1 data cache line */
7382 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7383 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7384 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7385
7386 /* bytes per L2 cache line */
7387 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7388 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7389 index 9ab078a..d6635c2 100644
7390 --- a/arch/tile/include/asm/uaccess.h
7391 +++ b/arch/tile/include/asm/uaccess.h
7392 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7393 const void __user *from,
7394 unsigned long n)
7395 {
7396 - int sz = __compiletime_object_size(to);
7397 + size_t sz = __compiletime_object_size(to);
7398
7399 - if (likely(sz == -1 || sz >= n))
7400 + if (likely(sz == (size_t)-1 || sz >= n))
7401 n = _copy_from_user(to, from, n);
7402 else
7403 copy_from_user_overflow();
7404 diff --git a/arch/um/Makefile b/arch/um/Makefile
7405 index 0970910..9f65c40 100644
7406 --- a/arch/um/Makefile
7407 +++ b/arch/um/Makefile
7408 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7409 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7410 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7411
7412 +ifdef CONSTIFY_PLUGIN
7413 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7414 +endif
7415 +
7416 #This will adjust *FLAGS accordingly to the platform.
7417 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7418
7419 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7420 index 19e1bdd..3665b77 100644
7421 --- a/arch/um/include/asm/cache.h
7422 +++ b/arch/um/include/asm/cache.h
7423 @@ -1,6 +1,7 @@
7424 #ifndef __UM_CACHE_H
7425 #define __UM_CACHE_H
7426
7427 +#include <linux/const.h>
7428
7429 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7430 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7431 @@ -12,6 +13,6 @@
7432 # define L1_CACHE_SHIFT 5
7433 #endif
7434
7435 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7436 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7437
7438 #endif
7439 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7440 index 2e0a6b1..a64d0f5 100644
7441 --- a/arch/um/include/asm/kmap_types.h
7442 +++ b/arch/um/include/asm/kmap_types.h
7443 @@ -8,6 +8,6 @@
7444
7445 /* No more #include "asm/arch/kmap_types.h" ! */
7446
7447 -#define KM_TYPE_NR 14
7448 +#define KM_TYPE_NR 15
7449
7450 #endif
7451 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7452 index 7cfc3ce..cbd1a58 100644
7453 --- a/arch/um/include/asm/page.h
7454 +++ b/arch/um/include/asm/page.h
7455 @@ -14,6 +14,9 @@
7456 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7457 #define PAGE_MASK (~(PAGE_SIZE-1))
7458
7459 +#define ktla_ktva(addr) (addr)
7460 +#define ktva_ktla(addr) (addr)
7461 +
7462 #ifndef __ASSEMBLY__
7463
7464 struct page;
7465 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7466 index 0032f92..cd151e0 100644
7467 --- a/arch/um/include/asm/pgtable-3level.h
7468 +++ b/arch/um/include/asm/pgtable-3level.h
7469 @@ -58,6 +58,7 @@
7470 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7471 #define pud_populate(mm, pud, pmd) \
7472 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7473 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7474
7475 #ifdef CONFIG_64BIT
7476 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7477 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7478 index c5f5afa..6abce4b 100644
7479 --- a/arch/um/kernel/process.c
7480 +++ b/arch/um/kernel/process.c
7481 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7482 return 2;
7483 }
7484
7485 -/*
7486 - * Only x86 and x86_64 have an arch_align_stack().
7487 - * All other arches have "#define arch_align_stack(x) (x)"
7488 - * in their asm/system.h
7489 - * As this is included in UML from asm-um/system-generic.h,
7490 - * we can use it to behave as the subarch does.
7491 - */
7492 -#ifndef arch_align_stack
7493 -unsigned long arch_align_stack(unsigned long sp)
7494 -{
7495 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7496 - sp -= get_random_int() % 8192;
7497 - return sp & ~0xf;
7498 -}
7499 -#endif
7500 -
7501 unsigned long get_wchan(struct task_struct *p)
7502 {
7503 unsigned long stack_page, sp, ip;
7504 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7505 index ad8f795..2c7eec6 100644
7506 --- a/arch/unicore32/include/asm/cache.h
7507 +++ b/arch/unicore32/include/asm/cache.h
7508 @@ -12,8 +12,10 @@
7509 #ifndef __UNICORE_CACHE_H__
7510 #define __UNICORE_CACHE_H__
7511
7512 -#define L1_CACHE_SHIFT (5)
7513 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7514 +#include <linux/const.h>
7515 +
7516 +#define L1_CACHE_SHIFT 5
7517 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7518
7519 /*
7520 * Memory returned by kmalloc() may be used for DMA, so we must make
7521 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7522 index 50a1d1f..c26369f 100644
7523 --- a/arch/x86/Kconfig
7524 +++ b/arch/x86/Kconfig
7525 @@ -220,7 +220,7 @@ config X86_HT
7526
7527 config X86_32_LAZY_GS
7528 def_bool y
7529 - depends on X86_32 && !CC_STACKPROTECTOR
7530 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7531
7532 config ARCH_HWEIGHT_CFLAGS
7533 string
7534 @@ -1049,7 +1049,7 @@ choice
7535
7536 config NOHIGHMEM
7537 bool "off"
7538 - depends on !X86_NUMAQ
7539 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7540 ---help---
7541 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7542 However, the address space of 32-bit x86 processors is only 4
7543 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7544
7545 config HIGHMEM4G
7546 bool "4GB"
7547 - depends on !X86_NUMAQ
7548 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7549 ---help---
7550 Select this if you have a 32-bit processor and between 1 and 4
7551 gigabytes of physical RAM.
7552 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7553 hex
7554 default 0xB0000000 if VMSPLIT_3G_OPT
7555 default 0x80000000 if VMSPLIT_2G
7556 - default 0x78000000 if VMSPLIT_2G_OPT
7557 + default 0x70000000 if VMSPLIT_2G_OPT
7558 default 0x40000000 if VMSPLIT_1G
7559 default 0xC0000000
7560 depends on X86_32
7561 @@ -1528,6 +1528,7 @@ config SECCOMP
7562
7563 config CC_STACKPROTECTOR
7564 bool "Enable -fstack-protector buffer overflow detection"
7565 + depends on X86_64 || !PAX_MEMORY_UDEREF
7566 ---help---
7567 This option turns on the -fstack-protector GCC feature. This
7568 feature puts, at the beginning of functions, a canary value on
7569 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7570 config PHYSICAL_START
7571 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7572 default "0x1000000"
7573 + range 0x400000 0x40000000
7574 ---help---
7575 This gives the physical address where the kernel is loaded.
7576
7577 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7578 config PHYSICAL_ALIGN
7579 hex "Alignment value to which kernel should be aligned" if X86_32
7580 default "0x1000000"
7581 + range 0x400000 0x1000000 if PAX_KERNEXEC
7582 range 0x2000 0x1000000
7583 ---help---
7584 This value puts the alignment restrictions on physical address
7585 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7586 Say N if you want to disable CPU hotplug.
7587
7588 config COMPAT_VDSO
7589 - def_bool y
7590 + def_bool n
7591 prompt "Compat VDSO support"
7592 depends on X86_32 || IA32_EMULATION
7593 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7594 ---help---
7595 Map the 32-bit VDSO to the predictable old-style address too.
7596
7597 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7598 index 706e12e..62e4feb 100644
7599 --- a/arch/x86/Kconfig.cpu
7600 +++ b/arch/x86/Kconfig.cpu
7601 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7602
7603 config X86_F00F_BUG
7604 def_bool y
7605 - depends on M586MMX || M586TSC || M586 || M486 || M386
7606 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7607
7608 config X86_INVD_BUG
7609 def_bool y
7610 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7611
7612 config X86_ALIGNMENT_16
7613 def_bool y
7614 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7615 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7616
7617 config X86_INTEL_USERCOPY
7618 def_bool y
7619 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7620 # generates cmov.
7621 config X86_CMOV
7622 def_bool y
7623 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7624 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7625
7626 config X86_MINIMUM_CPU_FAMILY
7627 int
7628 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7629 index b322f12..652d0d9 100644
7630 --- a/arch/x86/Kconfig.debug
7631 +++ b/arch/x86/Kconfig.debug
7632 @@ -84,7 +84,7 @@ config X86_PTDUMP
7633 config DEBUG_RODATA
7634 bool "Write protect kernel read-only data structures"
7635 default y
7636 - depends on DEBUG_KERNEL
7637 + depends on DEBUG_KERNEL && BROKEN
7638 ---help---
7639 Mark the kernel read-only data as write-protected in the pagetables,
7640 in order to catch accidental (and incorrect) writes to such const
7641 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7642
7643 config DEBUG_SET_MODULE_RONX
7644 bool "Set loadable kernel module data as NX and text as RO"
7645 - depends on MODULES
7646 + depends on MODULES && BROKEN
7647 ---help---
7648 This option helps catch unintended modifications to loadable
7649 kernel module's text and read-only data. It also prevents execution
7650 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7651
7652 config DEBUG_STRICT_USER_COPY_CHECKS
7653 bool "Strict copy size checks"
7654 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7655 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7656 ---help---
7657 Enabling this option turns a certain set of sanity checks for user
7658 copy operations into compile time failures.
7659 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7660 index 05afcca..b6ecb51 100644
7661 --- a/arch/x86/Makefile
7662 +++ b/arch/x86/Makefile
7663 @@ -50,6 +50,7 @@ else
7664 UTS_MACHINE := x86_64
7665 CHECKFLAGS += -D__x86_64__ -m64
7666
7667 + biarch := $(call cc-option,-m64)
7668 KBUILD_AFLAGS += -m64
7669 KBUILD_CFLAGS += -m64
7670
7671 @@ -229,3 +230,12 @@ define archhelp
7672 echo ' FDARGS="..." arguments for the booted kernel'
7673 echo ' FDINITRD=file initrd for the booted kernel'
7674 endef
7675 +
7676 +define OLD_LD
7677 +
7678 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7679 +*** Please upgrade your binutils to 2.18 or newer
7680 +endef
7681 +
7682 +archprepare:
7683 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7684 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7685 index f7535be..37db2d1 100644
7686 --- a/arch/x86/boot/Makefile
7687 +++ b/arch/x86/boot/Makefile
7688 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7689 $(call cc-option, -fno-stack-protector) \
7690 $(call cc-option, -mpreferred-stack-boundary=2)
7691 KBUILD_CFLAGS += $(call cc-option, -m32)
7692 +ifdef CONSTIFY_PLUGIN
7693 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7694 +endif
7695 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7696 GCOV_PROFILE := n
7697
7698 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7699 index 878e4b9..20537ab 100644
7700 --- a/arch/x86/boot/bitops.h
7701 +++ b/arch/x86/boot/bitops.h
7702 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7703 u8 v;
7704 const u32 *p = (const u32 *)addr;
7705
7706 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7707 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7708 return v;
7709 }
7710
7711 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7712
7713 static inline void set_bit(int nr, void *addr)
7714 {
7715 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7716 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7717 }
7718
7719 #endif /* BOOT_BITOPS_H */
7720 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7721 index 18997e5..83d9c67 100644
7722 --- a/arch/x86/boot/boot.h
7723 +++ b/arch/x86/boot/boot.h
7724 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7725 static inline u16 ds(void)
7726 {
7727 u16 seg;
7728 - asm("movw %%ds,%0" : "=rm" (seg));
7729 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7730 return seg;
7731 }
7732
7733 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7734 static inline int memcmp(const void *s1, const void *s2, size_t len)
7735 {
7736 u8 diff;
7737 - asm("repe; cmpsb; setnz %0"
7738 + asm volatile("repe; cmpsb; setnz %0"
7739 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7740 return diff;
7741 }
7742 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7743 index 8a84501..b2d165f 100644
7744 --- a/arch/x86/boot/compressed/Makefile
7745 +++ b/arch/x86/boot/compressed/Makefile
7746 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7747 KBUILD_CFLAGS += $(cflags-y)
7748 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7749 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7750 +ifdef CONSTIFY_PLUGIN
7751 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7752 +endif
7753
7754 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7755 GCOV_PROFILE := n
7756 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7757 index b3e0227..f2c02d5 100644
7758 --- a/arch/x86/boot/compressed/eboot.c
7759 +++ b/arch/x86/boot/compressed/eboot.c
7760 @@ -142,7 +142,6 @@ again:
7761 *addr = max_addr;
7762 }
7763
7764 -free_pool:
7765 efi_call_phys1(sys_table->boottime->free_pool, map);
7766
7767 fail:
7768 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7769 if (i == map_size / desc_size)
7770 status = EFI_NOT_FOUND;
7771
7772 -free_pool:
7773 efi_call_phys1(sys_table->boottime->free_pool, map);
7774 fail:
7775 return status;
7776 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7777 index aa4aaf1..6656f2f 100644
7778 --- a/arch/x86/boot/compressed/head_32.S
7779 +++ b/arch/x86/boot/compressed/head_32.S
7780 @@ -116,7 +116,7 @@ preferred_addr:
7781 notl %eax
7782 andl %eax, %ebx
7783 #else
7784 - movl $LOAD_PHYSICAL_ADDR, %ebx
7785 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7786 #endif
7787
7788 /* Target address to relocate to for decompression */
7789 @@ -202,7 +202,7 @@ relocated:
7790 * and where it was actually loaded.
7791 */
7792 movl %ebp, %ebx
7793 - subl $LOAD_PHYSICAL_ADDR, %ebx
7794 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7795 jz 2f /* Nothing to be done if loaded at compiled addr. */
7796 /*
7797 * Process relocations.
7798 @@ -210,8 +210,7 @@ relocated:
7799
7800 1: subl $4, %edi
7801 movl (%edi), %ecx
7802 - testl %ecx, %ecx
7803 - jz 2f
7804 + jecxz 2f
7805 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7806 jmp 1b
7807 2:
7808 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7809 index 2c4b171..e1fa5b1 100644
7810 --- a/arch/x86/boot/compressed/head_64.S
7811 +++ b/arch/x86/boot/compressed/head_64.S
7812 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7813 notl %eax
7814 andl %eax, %ebx
7815 #else
7816 - movl $LOAD_PHYSICAL_ADDR, %ebx
7817 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7818 #endif
7819
7820 /* Target address to relocate to for decompression */
7821 @@ -273,7 +273,7 @@ preferred_addr:
7822 notq %rax
7823 andq %rax, %rbp
7824 #else
7825 - movq $LOAD_PHYSICAL_ADDR, %rbp
7826 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7827 #endif
7828
7829 /* Target address to relocate to for decompression */
7830 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7831 index 88f7ff6..ed695dd 100644
7832 --- a/arch/x86/boot/compressed/misc.c
7833 +++ b/arch/x86/boot/compressed/misc.c
7834 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7835 case PT_LOAD:
7836 #ifdef CONFIG_RELOCATABLE
7837 dest = output;
7838 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7839 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7840 #else
7841 dest = (void *)(phdr->p_paddr);
7842 #endif
7843 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7844 error("Destination address too large");
7845 #endif
7846 #ifndef CONFIG_RELOCATABLE
7847 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7848 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7849 error("Wrong destination address");
7850 #endif
7851
7852 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7853 index 4d3ff03..e4972ff 100644
7854 --- a/arch/x86/boot/cpucheck.c
7855 +++ b/arch/x86/boot/cpucheck.c
7856 @@ -74,7 +74,7 @@ static int has_fpu(void)
7857 u16 fcw = -1, fsw = -1;
7858 u32 cr0;
7859
7860 - asm("movl %%cr0,%0" : "=r" (cr0));
7861 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7862 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7863 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7864 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7865 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7866 {
7867 u32 f0, f1;
7868
7869 - asm("pushfl ; "
7870 + asm volatile("pushfl ; "
7871 "pushfl ; "
7872 "popl %0 ; "
7873 "movl %0,%1 ; "
7874 @@ -115,7 +115,7 @@ static void get_flags(void)
7875 set_bit(X86_FEATURE_FPU, cpu.flags);
7876
7877 if (has_eflag(X86_EFLAGS_ID)) {
7878 - asm("cpuid"
7879 + asm volatile("cpuid"
7880 : "=a" (max_intel_level),
7881 "=b" (cpu_vendor[0]),
7882 "=d" (cpu_vendor[1]),
7883 @@ -124,7 +124,7 @@ static void get_flags(void)
7884
7885 if (max_intel_level >= 0x00000001 &&
7886 max_intel_level <= 0x0000ffff) {
7887 - asm("cpuid"
7888 + asm volatile("cpuid"
7889 : "=a" (tfms),
7890 "=c" (cpu.flags[4]),
7891 "=d" (cpu.flags[0])
7892 @@ -136,7 +136,7 @@ static void get_flags(void)
7893 cpu.model += ((tfms >> 16) & 0xf) << 4;
7894 }
7895
7896 - asm("cpuid"
7897 + asm volatile("cpuid"
7898 : "=a" (max_amd_level)
7899 : "a" (0x80000000)
7900 : "ebx", "ecx", "edx");
7901 @@ -144,7 +144,7 @@ static void get_flags(void)
7902 if (max_amd_level >= 0x80000001 &&
7903 max_amd_level <= 0x8000ffff) {
7904 u32 eax = 0x80000001;
7905 - asm("cpuid"
7906 + asm volatile("cpuid"
7907 : "+a" (eax),
7908 "=c" (cpu.flags[6]),
7909 "=d" (cpu.flags[1])
7910 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7911 u32 ecx = MSR_K7_HWCR;
7912 u32 eax, edx;
7913
7914 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7915 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7916 eax &= ~(1 << 15);
7917 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7918 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7919
7920 get_flags(); /* Make sure it really did something */
7921 err = check_flags();
7922 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7923 u32 ecx = MSR_VIA_FCR;
7924 u32 eax, edx;
7925
7926 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7927 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7928 eax |= (1<<1)|(1<<7);
7929 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7930 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7931
7932 set_bit(X86_FEATURE_CX8, cpu.flags);
7933 err = check_flags();
7934 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7935 u32 eax, edx;
7936 u32 level = 1;
7937
7938 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7939 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7940 - asm("cpuid"
7941 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7942 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7943 + asm volatile("cpuid"
7944 : "+a" (level), "=d" (cpu.flags[0])
7945 : : "ecx", "ebx");
7946 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7947 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7948
7949 err = check_flags();
7950 }
7951 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7952 index b4e15dd..8ac59ce 100644
7953 --- a/arch/x86/boot/header.S
7954 +++ b/arch/x86/boot/header.S
7955 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7956 # single linked list of
7957 # struct setup_data
7958
7959 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7960 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7961
7962 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7963 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7964 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7965 +#else
7966 #define VO_INIT_SIZE (VO__end - VO__text)
7967 +#endif
7968 #if ZO_INIT_SIZE > VO_INIT_SIZE
7969 #define INIT_SIZE ZO_INIT_SIZE
7970 #else
7971 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7972 index db75d07..8e6d0af 100644
7973 --- a/arch/x86/boot/memory.c
7974 +++ b/arch/x86/boot/memory.c
7975 @@ -19,7 +19,7 @@
7976
7977 static int detect_memory_e820(void)
7978 {
7979 - int count = 0;
7980 + unsigned int count = 0;
7981 struct biosregs ireg, oreg;
7982 struct e820entry *desc = boot_params.e820_map;
7983 static struct e820entry buf; /* static so it is zeroed */
7984 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7985 index 11e8c6e..fdbb1ed 100644
7986 --- a/arch/x86/boot/video-vesa.c
7987 +++ b/arch/x86/boot/video-vesa.c
7988 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7989
7990 boot_params.screen_info.vesapm_seg = oreg.es;
7991 boot_params.screen_info.vesapm_off = oreg.di;
7992 + boot_params.screen_info.vesapm_size = oreg.cx;
7993 }
7994
7995 /*
7996 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7997 index 43eda28..5ab5fdb 100644
7998 --- a/arch/x86/boot/video.c
7999 +++ b/arch/x86/boot/video.c
8000 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8001 static unsigned int get_entry(void)
8002 {
8003 char entry_buf[4];
8004 - int i, len = 0;
8005 + unsigned int i, len = 0;
8006 int key;
8007 unsigned int v;
8008
8009 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8010 index 5b577d5..3c1fed4 100644
8011 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8012 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8013 @@ -8,6 +8,8 @@
8014 * including this sentence is retained in full.
8015 */
8016
8017 +#include <asm/alternative-asm.h>
8018 +
8019 .extern crypto_ft_tab
8020 .extern crypto_it_tab
8021 .extern crypto_fl_tab
8022 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8023 je B192; \
8024 leaq 32(r9),r9;
8025
8026 +#define ret pax_force_retaddr 0, 1; ret
8027 +
8028 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8029 movq r1,r2; \
8030 movq r3,r4; \
8031 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8032 index 3470624..201259d 100644
8033 --- a/arch/x86/crypto/aesni-intel_asm.S
8034 +++ b/arch/x86/crypto/aesni-intel_asm.S
8035 @@ -31,6 +31,7 @@
8036
8037 #include <linux/linkage.h>
8038 #include <asm/inst.h>
8039 +#include <asm/alternative-asm.h>
8040
8041 #ifdef __x86_64__
8042 .data
8043 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8044 pop %r14
8045 pop %r13
8046 pop %r12
8047 + pax_force_retaddr 0, 1
8048 ret
8049 +ENDPROC(aesni_gcm_dec)
8050
8051
8052 /*****************************************************************************
8053 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8054 pop %r14
8055 pop %r13
8056 pop %r12
8057 + pax_force_retaddr 0, 1
8058 ret
8059 +ENDPROC(aesni_gcm_enc)
8060
8061 #endif
8062
8063 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8064 pxor %xmm1, %xmm0
8065 movaps %xmm0, (TKEYP)
8066 add $0x10, TKEYP
8067 + pax_force_retaddr_bts
8068 ret
8069
8070 .align 4
8071 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8072 shufps $0b01001110, %xmm2, %xmm1
8073 movaps %xmm1, 0x10(TKEYP)
8074 add $0x20, TKEYP
8075 + pax_force_retaddr_bts
8076 ret
8077
8078 .align 4
8079 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8080
8081 movaps %xmm0, (TKEYP)
8082 add $0x10, TKEYP
8083 + pax_force_retaddr_bts
8084 ret
8085
8086 .align 4
8087 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8088 pxor %xmm1, %xmm2
8089 movaps %xmm2, (TKEYP)
8090 add $0x10, TKEYP
8091 + pax_force_retaddr_bts
8092 ret
8093
8094 /*
8095 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8096 #ifndef __x86_64__
8097 popl KEYP
8098 #endif
8099 + pax_force_retaddr 0, 1
8100 ret
8101 +ENDPROC(aesni_set_key)
8102
8103 /*
8104 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8105 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8106 popl KLEN
8107 popl KEYP
8108 #endif
8109 + pax_force_retaddr 0, 1
8110 ret
8111 +ENDPROC(aesni_enc)
8112
8113 /*
8114 * _aesni_enc1: internal ABI
8115 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8116 AESENC KEY STATE
8117 movaps 0x70(TKEYP), KEY
8118 AESENCLAST KEY STATE
8119 + pax_force_retaddr_bts
8120 ret
8121
8122 /*
8123 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8124 AESENCLAST KEY STATE2
8125 AESENCLAST KEY STATE3
8126 AESENCLAST KEY STATE4
8127 + pax_force_retaddr_bts
8128 ret
8129
8130 /*
8131 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8132 popl KLEN
8133 popl KEYP
8134 #endif
8135 + pax_force_retaddr 0, 1
8136 ret
8137 +ENDPROC(aesni_dec)
8138
8139 /*
8140 * _aesni_dec1: internal ABI
8141 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8142 AESDEC KEY STATE
8143 movaps 0x70(TKEYP), KEY
8144 AESDECLAST KEY STATE
8145 + pax_force_retaddr_bts
8146 ret
8147
8148 /*
8149 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8150 AESDECLAST KEY STATE2
8151 AESDECLAST KEY STATE3
8152 AESDECLAST KEY STATE4
8153 + pax_force_retaddr_bts
8154 ret
8155
8156 /*
8157 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8158 popl KEYP
8159 popl LEN
8160 #endif
8161 + pax_force_retaddr 0, 1
8162 ret
8163 +ENDPROC(aesni_ecb_enc)
8164
8165 /*
8166 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8167 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8168 popl KEYP
8169 popl LEN
8170 #endif
8171 + pax_force_retaddr 0, 1
8172 ret
8173 +ENDPROC(aesni_ecb_dec)
8174
8175 /*
8176 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8177 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8178 popl LEN
8179 popl IVP
8180 #endif
8181 + pax_force_retaddr 0, 1
8182 ret
8183 +ENDPROC(aesni_cbc_enc)
8184
8185 /*
8186 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8187 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8188 popl LEN
8189 popl IVP
8190 #endif
8191 + pax_force_retaddr 0, 1
8192 ret
8193 +ENDPROC(aesni_cbc_dec)
8194
8195 #ifdef __x86_64__
8196 .align 16
8197 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8198 mov $1, TCTR_LOW
8199 MOVQ_R64_XMM TCTR_LOW INC
8200 MOVQ_R64_XMM CTR TCTR_LOW
8201 + pax_force_retaddr_bts
8202 ret
8203
8204 /*
8205 @@ -2554,6 +2582,7 @@ _aesni_inc:
8206 .Linc_low:
8207 movaps CTR, IV
8208 PSHUFB_XMM BSWAP_MASK IV
8209 + pax_force_retaddr_bts
8210 ret
8211
8212 /*
8213 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8214 .Lctr_enc_ret:
8215 movups IV, (IVP)
8216 .Lctr_enc_just_ret:
8217 + pax_force_retaddr 0, 1
8218 ret
8219 +ENDPROC(aesni_ctr_enc)
8220 #endif
8221 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8222 index 391d245..67f35c2 100644
8223 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8224 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8225 @@ -20,6 +20,8 @@
8226 *
8227 */
8228
8229 +#include <asm/alternative-asm.h>
8230 +
8231 .file "blowfish-x86_64-asm.S"
8232 .text
8233
8234 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8235 jnz __enc_xor;
8236
8237 write_block();
8238 + pax_force_retaddr 0, 1
8239 ret;
8240 __enc_xor:
8241 xor_block();
8242 + pax_force_retaddr 0, 1
8243 ret;
8244
8245 .align 8
8246 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8247
8248 movq %r11, %rbp;
8249
8250 + pax_force_retaddr 0, 1
8251 ret;
8252
8253 /**********************************************************************
8254 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8255
8256 popq %rbx;
8257 popq %rbp;
8258 + pax_force_retaddr 0, 1
8259 ret;
8260
8261 __enc_xor4:
8262 @@ -349,6 +355,7 @@ __enc_xor4:
8263
8264 popq %rbx;
8265 popq %rbp;
8266 + pax_force_retaddr 0, 1
8267 ret;
8268
8269 .align 8
8270 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8271 popq %rbx;
8272 popq %rbp;
8273
8274 + pax_force_retaddr 0, 1
8275 ret;
8276
8277 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8278 index 0b33743..7a56206 100644
8279 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8280 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8281 @@ -20,6 +20,8 @@
8282 *
8283 */
8284
8285 +#include <asm/alternative-asm.h>
8286 +
8287 .file "camellia-x86_64-asm_64.S"
8288 .text
8289
8290 @@ -229,12 +231,14 @@ __enc_done:
8291 enc_outunpack(mov, RT1);
8292
8293 movq RRBP, %rbp;
8294 + pax_force_retaddr 0, 1
8295 ret;
8296
8297 __enc_xor:
8298 enc_outunpack(xor, RT1);
8299
8300 movq RRBP, %rbp;
8301 + pax_force_retaddr 0, 1
8302 ret;
8303
8304 .global camellia_dec_blk;
8305 @@ -275,6 +279,7 @@ __dec_rounds16:
8306 dec_outunpack();
8307
8308 movq RRBP, %rbp;
8309 + pax_force_retaddr 0, 1
8310 ret;
8311
8312 /**********************************************************************
8313 @@ -468,6 +473,7 @@ __enc2_done:
8314
8315 movq RRBP, %rbp;
8316 popq %rbx;
8317 + pax_force_retaddr 0, 1
8318 ret;
8319
8320 __enc2_xor:
8321 @@ -475,6 +481,7 @@ __enc2_xor:
8322
8323 movq RRBP, %rbp;
8324 popq %rbx;
8325 + pax_force_retaddr 0, 1
8326 ret;
8327
8328 .global camellia_dec_blk_2way;
8329 @@ -517,4 +524,5 @@ __dec2_rounds16:
8330
8331 movq RRBP, %rbp;
8332 movq RXOR, %rbx;
8333 + pax_force_retaddr 0, 1
8334 ret;
8335 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8336 index 6214a9b..1f4fc9a 100644
8337 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8338 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8339 @@ -1,3 +1,5 @@
8340 +#include <asm/alternative-asm.h>
8341 +
8342 # enter ECRYPT_encrypt_bytes
8343 .text
8344 .p2align 5
8345 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8346 add %r11,%rsp
8347 mov %rdi,%rax
8348 mov %rsi,%rdx
8349 + pax_force_retaddr 0, 1
8350 ret
8351 # bytesatleast65:
8352 ._bytesatleast65:
8353 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8354 add %r11,%rsp
8355 mov %rdi,%rax
8356 mov %rsi,%rdx
8357 + pax_force_retaddr
8358 ret
8359 # enter ECRYPT_ivsetup
8360 .text
8361 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8362 add %r11,%rsp
8363 mov %rdi,%rax
8364 mov %rsi,%rdx
8365 + pax_force_retaddr
8366 ret
8367 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8368 index 504106b..4e50951 100644
8369 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8370 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8371 @@ -24,6 +24,8 @@
8372 *
8373 */
8374
8375 +#include <asm/alternative-asm.h>
8376 +
8377 .file "serpent-avx-x86_64-asm_64.S"
8378 .text
8379
8380 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8381 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8382 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8383
8384 + pax_force_retaddr
8385 ret;
8386
8387 __enc_xor8:
8388 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8389 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8390
8391 + pax_force_retaddr
8392 ret;
8393
8394 .align 8
8395 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8396 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8397 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8398
8399 + pax_force_retaddr
8400 ret;
8401 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8402 index 3ee1ff0..cbc568b 100644
8403 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8404 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8405 @@ -24,6 +24,8 @@
8406 *
8407 */
8408
8409 +#include <asm/alternative-asm.h>
8410 +
8411 .file "serpent-sse2-x86_64-asm_64.S"
8412 .text
8413
8414 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8415 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8416 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8417
8418 + pax_force_retaddr
8419 ret;
8420
8421 __enc_xor8:
8422 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8423 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8424
8425 + pax_force_retaddr
8426 ret;
8427
8428 .align 8
8429 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8430 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8431 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8432
8433 + pax_force_retaddr
8434 ret;
8435 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8436 index 49d6987..df66bd4 100644
8437 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8438 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8439 @@ -28,6 +28,8 @@
8440 * (at your option) any later version.
8441 */
8442
8443 +#include <asm/alternative-asm.h>
8444 +
8445 #define CTX %rdi // arg1
8446 #define BUF %rsi // arg2
8447 #define CNT %rdx // arg3
8448 @@ -104,6 +106,7 @@
8449 pop %r12
8450 pop %rbp
8451 pop %rbx
8452 + pax_force_retaddr 0, 1
8453 ret
8454
8455 .size \name, .-\name
8456 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8457 index 35f4557..16b379f 100644
8458 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8459 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8460 @@ -21,6 +21,8 @@
8461 *
8462 */
8463
8464 +#include <asm/alternative-asm.h>
8465 +
8466 .file "twofish-avx-x86_64-asm_64.S"
8467 .text
8468
8469 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8470 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8471 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8472
8473 + pax_force_retaddr
8474 ret;
8475
8476 __enc_xor8:
8477 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8478 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8479
8480 + pax_force_retaddr
8481 ret;
8482
8483 .align 8
8484 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8485 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8486 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8487
8488 + pax_force_retaddr
8489 ret;
8490 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8491 index 5b012a2..36d5364 100644
8492 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8493 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8494 @@ -20,6 +20,8 @@
8495 *
8496 */
8497
8498 +#include <asm/alternative-asm.h>
8499 +
8500 .file "twofish-x86_64-asm-3way.S"
8501 .text
8502
8503 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8504 popq %r13;
8505 popq %r14;
8506 popq %r15;
8507 + pax_force_retaddr 0, 1
8508 ret;
8509
8510 __enc_xor3:
8511 @@ -271,6 +274,7 @@ __enc_xor3:
8512 popq %r13;
8513 popq %r14;
8514 popq %r15;
8515 + pax_force_retaddr 0, 1
8516 ret;
8517
8518 .global twofish_dec_blk_3way
8519 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8520 popq %r13;
8521 popq %r14;
8522 popq %r15;
8523 + pax_force_retaddr 0, 1
8524 ret;
8525
8526 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8527 index 7bcf3fc..f53832f 100644
8528 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8529 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8530 @@ -21,6 +21,7 @@
8531 .text
8532
8533 #include <asm/asm-offsets.h>
8534 +#include <asm/alternative-asm.h>
8535
8536 #define a_offset 0
8537 #define b_offset 4
8538 @@ -268,6 +269,7 @@ twofish_enc_blk:
8539
8540 popq R1
8541 movq $1,%rax
8542 + pax_force_retaddr 0, 1
8543 ret
8544
8545 twofish_dec_blk:
8546 @@ -319,4 +321,5 @@ twofish_dec_blk:
8547
8548 popq R1
8549 movq $1,%rax
8550 + pax_force_retaddr 0, 1
8551 ret
8552 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8553 index 07b3a68..bd2a388 100644
8554 --- a/arch/x86/ia32/ia32_aout.c
8555 +++ b/arch/x86/ia32/ia32_aout.c
8556 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8557 unsigned long dump_start, dump_size;
8558 struct user32 dump;
8559
8560 + memset(&dump, 0, sizeof(dump));
8561 +
8562 fs = get_fs();
8563 set_fs(KERNEL_DS);
8564 has_dumped = 1;
8565 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8566 index 673ac9b..7a8c5df 100644
8567 --- a/arch/x86/ia32/ia32_signal.c
8568 +++ b/arch/x86/ia32/ia32_signal.c
8569 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8570 }
8571 seg = get_fs();
8572 set_fs(KERNEL_DS);
8573 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8574 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8575 set_fs(seg);
8576 if (ret >= 0 && uoss_ptr) {
8577 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8578 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8579 */
8580 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8581 size_t frame_size,
8582 - void **fpstate)
8583 + void __user **fpstate)
8584 {
8585 unsigned long sp;
8586
8587 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8588
8589 if (used_math()) {
8590 sp = sp - sig_xstate_ia32_size;
8591 - *fpstate = (struct _fpstate_ia32 *) sp;
8592 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8593 if (save_i387_xstate_ia32(*fpstate) < 0)
8594 return (void __user *) -1L;
8595 }
8596 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8597 sp -= frame_size;
8598 /* Align the stack pointer according to the i386 ABI,
8599 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8600 - sp = ((sp + 4) & -16ul) - 4;
8601 + sp = ((sp - 12) & -16ul) - 4;
8602 return (void __user *) sp;
8603 }
8604
8605 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8606 * These are actually not used anymore, but left because some
8607 * gdb versions depend on them as a marker.
8608 */
8609 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8610 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8611 } put_user_catch(err);
8612
8613 if (err)
8614 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8615 0xb8,
8616 __NR_ia32_rt_sigreturn,
8617 0x80cd,
8618 - 0,
8619 + 0
8620 };
8621
8622 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8623 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8624
8625 if (ka->sa.sa_flags & SA_RESTORER)
8626 restorer = ka->sa.sa_restorer;
8627 + else if (current->mm->context.vdso)
8628 + /* Return stub is in 32bit vsyscall page */
8629 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8630 else
8631 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8632 - rt_sigreturn);
8633 + restorer = &frame->retcode;
8634 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8635
8636 /*
8637 * Not actually used anymore, but left because some gdb
8638 * versions need it.
8639 */
8640 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8641 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8642 } put_user_catch(err);
8643
8644 if (err)
8645 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8646 index 20e5f7b..f33c779 100644
8647 --- a/arch/x86/ia32/ia32entry.S
8648 +++ b/arch/x86/ia32/ia32entry.S
8649 @@ -14,8 +14,10 @@
8650 #include <asm/segment.h>
8651 #include <asm/irqflags.h>
8652 #include <asm/asm.h>
8653 +#include <asm/pgtable.h>
8654 #include <linux/linkage.h>
8655 #include <linux/err.h>
8656 +#include <asm/alternative-asm.h>
8657
8658 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8659 #include <linux/elf-em.h>
8660 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8661 ENDPROC(native_irq_enable_sysexit)
8662 #endif
8663
8664 + .macro pax_enter_kernel_user
8665 + pax_set_fptr_mask
8666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8667 + call pax_enter_kernel_user
8668 +#endif
8669 + .endm
8670 +
8671 + .macro pax_exit_kernel_user
8672 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8673 + call pax_exit_kernel_user
8674 +#endif
8675 +#ifdef CONFIG_PAX_RANDKSTACK
8676 + pushq %rax
8677 + pushq %r11
8678 + call pax_randomize_kstack
8679 + popq %r11
8680 + popq %rax
8681 +#endif
8682 + .endm
8683 +
8684 +.macro pax_erase_kstack
8685 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8686 + call pax_erase_kstack
8687 +#endif
8688 +.endm
8689 +
8690 /*
8691 * 32bit SYSENTER instruction entry.
8692 *
8693 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8694 CFI_REGISTER rsp,rbp
8695 SWAPGS_UNSAFE_STACK
8696 movq PER_CPU_VAR(kernel_stack), %rsp
8697 - addq $(KERNEL_STACK_OFFSET),%rsp
8698 - /*
8699 - * No need to follow this irqs on/off section: the syscall
8700 - * disabled irqs, here we enable it straight after entry:
8701 - */
8702 - ENABLE_INTERRUPTS(CLBR_NONE)
8703 movl %ebp,%ebp /* zero extension */
8704 pushq_cfi $__USER32_DS
8705 /*CFI_REL_OFFSET ss,0*/
8706 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8707 CFI_REL_OFFSET rsp,0
8708 pushfq_cfi
8709 /*CFI_REL_OFFSET rflags,0*/
8710 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8711 - CFI_REGISTER rip,r10
8712 + orl $X86_EFLAGS_IF,(%rsp)
8713 + GET_THREAD_INFO(%r11)
8714 + movl TI_sysenter_return(%r11), %r11d
8715 + CFI_REGISTER rip,r11
8716 pushq_cfi $__USER32_CS
8717 /*CFI_REL_OFFSET cs,0*/
8718 movl %eax, %eax
8719 - pushq_cfi %r10
8720 + pushq_cfi %r11
8721 CFI_REL_OFFSET rip,0
8722 pushq_cfi %rax
8723 cld
8724 SAVE_ARGS 0,1,0
8725 + pax_enter_kernel_user
8726 +
8727 +#ifdef CONFIG_PAX_RANDKSTACK
8728 + pax_erase_kstack
8729 +#endif
8730 +
8731 + /*
8732 + * No need to follow this irqs on/off section: the syscall
8733 + * disabled irqs, here we enable it straight after entry:
8734 + */
8735 + ENABLE_INTERRUPTS(CLBR_NONE)
8736 /* no need to do an access_ok check here because rbp has been
8737 32bit zero extended */
8738 +
8739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8740 + mov $PAX_USER_SHADOW_BASE,%r11
8741 + add %r11,%rbp
8742 +#endif
8743 +
8744 1: movl (%rbp),%ebp
8745 _ASM_EXTABLE(1b,ia32_badarg)
8746 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8747 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8748 + GET_THREAD_INFO(%r11)
8749 + orl $TS_COMPAT,TI_status(%r11)
8750 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8751 CFI_REMEMBER_STATE
8752 jnz sysenter_tracesys
8753 cmpq $(IA32_NR_syscalls-1),%rax
8754 @@ -159,12 +201,15 @@ sysenter_do_call:
8755 sysenter_dispatch:
8756 call *ia32_sys_call_table(,%rax,8)
8757 movq %rax,RAX-ARGOFFSET(%rsp)
8758 + GET_THREAD_INFO(%r11)
8759 DISABLE_INTERRUPTS(CLBR_NONE)
8760 TRACE_IRQS_OFF
8761 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8762 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8763 jnz sysexit_audit
8764 sysexit_from_sys_call:
8765 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8766 + pax_exit_kernel_user
8767 + pax_erase_kstack
8768 + andl $~TS_COMPAT,TI_status(%r11)
8769 /* clear IF, that popfq doesn't enable interrupts early */
8770 andl $~0x200,EFLAGS-R11(%rsp)
8771 movl RIP-R11(%rsp),%edx /* User %eip */
8772 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8773 movl %eax,%esi /* 2nd arg: syscall number */
8774 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8775 call __audit_syscall_entry
8776 +
8777 + pax_erase_kstack
8778 +
8779 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8780 cmpq $(IA32_NR_syscalls-1),%rax
8781 ja ia32_badsys
8782 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8783 .endm
8784
8785 .macro auditsys_exit exit
8786 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8787 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8788 jnz ia32_ret_from_sys_call
8789 TRACE_IRQS_ON
8790 sti
8791 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8792 1: setbe %al /* 1 if error, 0 if not */
8793 movzbl %al,%edi /* zero-extend that into %edi */
8794 call __audit_syscall_exit
8795 + GET_THREAD_INFO(%r11)
8796 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8797 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8798 cli
8799 TRACE_IRQS_OFF
8800 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8801 + testl %edi,TI_flags(%r11)
8802 jz \exit
8803 CLEAR_RREGS -ARGOFFSET
8804 jmp int_with_check
8805 @@ -234,7 +283,7 @@ sysexit_audit:
8806
8807 sysenter_tracesys:
8808 #ifdef CONFIG_AUDITSYSCALL
8809 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8810 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8811 jz sysenter_auditsys
8812 #endif
8813 SAVE_REST
8814 @@ -246,6 +295,9 @@ sysenter_tracesys:
8815 RESTORE_REST
8816 cmpq $(IA32_NR_syscalls-1),%rax
8817 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8818 +
8819 + pax_erase_kstack
8820 +
8821 jmp sysenter_do_call
8822 CFI_ENDPROC
8823 ENDPROC(ia32_sysenter_target)
8824 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8825 ENTRY(ia32_cstar_target)
8826 CFI_STARTPROC32 simple
8827 CFI_SIGNAL_FRAME
8828 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8829 + CFI_DEF_CFA rsp,0
8830 CFI_REGISTER rip,rcx
8831 /*CFI_REGISTER rflags,r11*/
8832 SWAPGS_UNSAFE_STACK
8833 movl %esp,%r8d
8834 CFI_REGISTER rsp,r8
8835 movq PER_CPU_VAR(kernel_stack),%rsp
8836 + SAVE_ARGS 8*6,0,0
8837 + pax_enter_kernel_user
8838 +
8839 +#ifdef CONFIG_PAX_RANDKSTACK
8840 + pax_erase_kstack
8841 +#endif
8842 +
8843 /*
8844 * No need to follow this irqs on/off section: the syscall
8845 * disabled irqs and here we enable it straight after entry:
8846 */
8847 ENABLE_INTERRUPTS(CLBR_NONE)
8848 - SAVE_ARGS 8,0,0
8849 movl %eax,%eax /* zero extension */
8850 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8851 movq %rcx,RIP-ARGOFFSET(%rsp)
8852 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8853 /* no need to do an access_ok check here because r8 has been
8854 32bit zero extended */
8855 /* hardware stack frame is complete now */
8856 +
8857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8858 + mov $PAX_USER_SHADOW_BASE,%r11
8859 + add %r11,%r8
8860 +#endif
8861 +
8862 1: movl (%r8),%r9d
8863 _ASM_EXTABLE(1b,ia32_badarg)
8864 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8865 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8866 + GET_THREAD_INFO(%r11)
8867 + orl $TS_COMPAT,TI_status(%r11)
8868 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8869 CFI_REMEMBER_STATE
8870 jnz cstar_tracesys
8871 cmpq $IA32_NR_syscalls-1,%rax
8872 @@ -314,12 +379,15 @@ cstar_do_call:
8873 cstar_dispatch:
8874 call *ia32_sys_call_table(,%rax,8)
8875 movq %rax,RAX-ARGOFFSET(%rsp)
8876 + GET_THREAD_INFO(%r11)
8877 DISABLE_INTERRUPTS(CLBR_NONE)
8878 TRACE_IRQS_OFF
8879 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8880 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8881 jnz sysretl_audit
8882 sysretl_from_sys_call:
8883 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8884 + pax_exit_kernel_user
8885 + pax_erase_kstack
8886 + andl $~TS_COMPAT,TI_status(%r11)
8887 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8888 movl RIP-ARGOFFSET(%rsp),%ecx
8889 CFI_REGISTER rip,rcx
8890 @@ -347,7 +415,7 @@ sysretl_audit:
8891
8892 cstar_tracesys:
8893 #ifdef CONFIG_AUDITSYSCALL
8894 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8895 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8896 jz cstar_auditsys
8897 #endif
8898 xchgl %r9d,%ebp
8899 @@ -361,6 +429,9 @@ cstar_tracesys:
8900 xchgl %ebp,%r9d
8901 cmpq $(IA32_NR_syscalls-1),%rax
8902 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8903 +
8904 + pax_erase_kstack
8905 +
8906 jmp cstar_do_call
8907 END(ia32_cstar_target)
8908
8909 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8910 CFI_REL_OFFSET rip,RIP-RIP
8911 PARAVIRT_ADJUST_EXCEPTION_FRAME
8912 SWAPGS
8913 - /*
8914 - * No need to follow this irqs on/off section: the syscall
8915 - * disabled irqs and here we enable it straight after entry:
8916 - */
8917 - ENABLE_INTERRUPTS(CLBR_NONE)
8918 movl %eax,%eax
8919 pushq_cfi %rax
8920 cld
8921 /* note the registers are not zero extended to the sf.
8922 this could be a problem. */
8923 SAVE_ARGS 0,1,0
8924 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8925 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8926 + pax_enter_kernel_user
8927 +
8928 +#ifdef CONFIG_PAX_RANDKSTACK
8929 + pax_erase_kstack
8930 +#endif
8931 +
8932 + /*
8933 + * No need to follow this irqs on/off section: the syscall
8934 + * disabled irqs and here we enable it straight after entry:
8935 + */
8936 + ENABLE_INTERRUPTS(CLBR_NONE)
8937 + GET_THREAD_INFO(%r11)
8938 + orl $TS_COMPAT,TI_status(%r11)
8939 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8940 jnz ia32_tracesys
8941 cmpq $(IA32_NR_syscalls-1),%rax
8942 ja ia32_badsys
8943 @@ -436,6 +514,9 @@ ia32_tracesys:
8944 RESTORE_REST
8945 cmpq $(IA32_NR_syscalls-1),%rax
8946 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8947 +
8948 + pax_erase_kstack
8949 +
8950 jmp ia32_do_call
8951 END(ia32_syscall)
8952
8953 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8954 index 4540bec..714d913 100644
8955 --- a/arch/x86/ia32/sys_ia32.c
8956 +++ b/arch/x86/ia32/sys_ia32.c
8957 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8958 */
8959 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8960 {
8961 - typeof(ubuf->st_uid) uid = 0;
8962 - typeof(ubuf->st_gid) gid = 0;
8963 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8964 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8965 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8966 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8967 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8968 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8969 return ret;
8970 }
8971
8972 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8973 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8974 int options)
8975 {
8976 return compat_sys_wait4(pid, stat_addr, options, NULL);
8977 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8978 mm_segment_t old_fs = get_fs();
8979
8980 set_fs(KERNEL_DS);
8981 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8982 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8983 set_fs(old_fs);
8984 if (put_compat_timespec(&t, interval))
8985 return -EFAULT;
8986 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8987 mm_segment_t old_fs = get_fs();
8988
8989 set_fs(KERNEL_DS);
8990 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8991 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8992 set_fs(old_fs);
8993 if (!ret) {
8994 switch (_NSIG_WORDS) {
8995 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8996 if (copy_siginfo_from_user32(&info, uinfo))
8997 return -EFAULT;
8998 set_fs(KERNEL_DS);
8999 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9000 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9001 set_fs(old_fs);
9002 return ret;
9003 }
9004 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9005 return -EFAULT;
9006
9007 set_fs(KERNEL_DS);
9008 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9009 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9010 count);
9011 set_fs(old_fs);
9012
9013 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9014 index 952bd01..7692c6f 100644
9015 --- a/arch/x86/include/asm/alternative-asm.h
9016 +++ b/arch/x86/include/asm/alternative-asm.h
9017 @@ -15,6 +15,45 @@
9018 .endm
9019 #endif
9020
9021 +#ifdef KERNEXEC_PLUGIN
9022 + .macro pax_force_retaddr_bts rip=0
9023 + btsq $63,\rip(%rsp)
9024 + .endm
9025 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9026 + .macro pax_force_retaddr rip=0, reload=0
9027 + btsq $63,\rip(%rsp)
9028 + .endm
9029 + .macro pax_force_fptr ptr
9030 + btsq $63,\ptr
9031 + .endm
9032 + .macro pax_set_fptr_mask
9033 + .endm
9034 +#endif
9035 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9036 + .macro pax_force_retaddr rip=0, reload=0
9037 + .if \reload
9038 + pax_set_fptr_mask
9039 + .endif
9040 + orq %r10,\rip(%rsp)
9041 + .endm
9042 + .macro pax_force_fptr ptr
9043 + orq %r10,\ptr
9044 + .endm
9045 + .macro pax_set_fptr_mask
9046 + movabs $0x8000000000000000,%r10
9047 + .endm
9048 +#endif
9049 +#else
9050 + .macro pax_force_retaddr rip=0, reload=0
9051 + .endm
9052 + .macro pax_force_fptr ptr
9053 + .endm
9054 + .macro pax_force_retaddr_bts rip=0
9055 + .endm
9056 + .macro pax_set_fptr_mask
9057 + .endm
9058 +#endif
9059 +
9060 .macro altinstruction_entry orig alt feature orig_len alt_len
9061 .long \orig - .
9062 .long \alt - .
9063 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9064 index 7078068..f58bcda 100644
9065 --- a/arch/x86/include/asm/alternative.h
9066 +++ b/arch/x86/include/asm/alternative.h
9067 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9068 ".section .discard,\"aw\",@progbits\n" \
9069 DISCARD_ENTRY(1) \
9070 ".previous\n" \
9071 - ".section .altinstr_replacement, \"ax\"\n" \
9072 + ".section .altinstr_replacement, \"a\"\n" \
9073 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9074 ".previous"
9075
9076 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9077 DISCARD_ENTRY(1) \
9078 DISCARD_ENTRY(2) \
9079 ".previous\n" \
9080 - ".section .altinstr_replacement, \"ax\"\n" \
9081 + ".section .altinstr_replacement, \"a\"\n" \
9082 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9083 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9084 ".previous"
9085 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9086 index f342612..b3fe911 100644
9087 --- a/arch/x86/include/asm/apic.h
9088 +++ b/arch/x86/include/asm/apic.h
9089 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9090
9091 #ifdef CONFIG_X86_LOCAL_APIC
9092
9093 -extern unsigned int apic_verbosity;
9094 +extern int apic_verbosity;
9095 extern int local_apic_timer_c2_ok;
9096
9097 extern int disable_apic;
9098 @@ -391,7 +391,7 @@ struct apic {
9099 */
9100 int (*x86_32_numa_cpu_node)(int cpu);
9101 #endif
9102 -};
9103 +} __do_const;
9104
9105 /*
9106 * Pointer to the local APIC driver in use on this system (there's
9107 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9108 index 20370c6..a2eb9b0 100644
9109 --- a/arch/x86/include/asm/apm.h
9110 +++ b/arch/x86/include/asm/apm.h
9111 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9112 __asm__ __volatile__(APM_DO_ZERO_SEGS
9113 "pushl %%edi\n\t"
9114 "pushl %%ebp\n\t"
9115 - "lcall *%%cs:apm_bios_entry\n\t"
9116 + "lcall *%%ss:apm_bios_entry\n\t"
9117 "setc %%al\n\t"
9118 "popl %%ebp\n\t"
9119 "popl %%edi\n\t"
9120 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_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 %%bl\n\t"
9127 "popl %%ebp\n\t"
9128 "popl %%edi\n\t"
9129 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9130 index 58cb6d4..a4b806c 100644
9131 --- a/arch/x86/include/asm/atomic.h
9132 +++ b/arch/x86/include/asm/atomic.h
9133 @@ -22,7 +22,18 @@
9134 */
9135 static inline int atomic_read(const atomic_t *v)
9136 {
9137 - return (*(volatile int *)&(v)->counter);
9138 + return (*(volatile const int *)&(v)->counter);
9139 +}
9140 +
9141 +/**
9142 + * atomic_read_unchecked - read atomic variable
9143 + * @v: pointer of type atomic_unchecked_t
9144 + *
9145 + * Atomically reads the value of @v.
9146 + */
9147 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9148 +{
9149 + return (*(volatile const int *)&(v)->counter);
9150 }
9151
9152 /**
9153 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9154 }
9155
9156 /**
9157 + * atomic_set_unchecked - set atomic variable
9158 + * @v: pointer of type atomic_unchecked_t
9159 + * @i: required value
9160 + *
9161 + * Atomically sets the value of @v to @i.
9162 + */
9163 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9164 +{
9165 + v->counter = i;
9166 +}
9167 +
9168 +/**
9169 * atomic_add - add integer to atomic variable
9170 * @i: integer value to add
9171 * @v: pointer of type atomic_t
9172 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9173 */
9174 static inline void atomic_add(int i, atomic_t *v)
9175 {
9176 - asm volatile(LOCK_PREFIX "addl %1,%0"
9177 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9178 +
9179 +#ifdef CONFIG_PAX_REFCOUNT
9180 + "jno 0f\n"
9181 + LOCK_PREFIX "subl %1,%0\n"
9182 + "int $4\n0:\n"
9183 + _ASM_EXTABLE(0b, 0b)
9184 +#endif
9185 +
9186 + : "+m" (v->counter)
9187 + : "ir" (i));
9188 +}
9189 +
9190 +/**
9191 + * atomic_add_unchecked - add integer to atomic variable
9192 + * @i: integer value to add
9193 + * @v: pointer of type atomic_unchecked_t
9194 + *
9195 + * Atomically adds @i to @v.
9196 + */
9197 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9198 +{
9199 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9200 : "+m" (v->counter)
9201 : "ir" (i));
9202 }
9203 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9204 */
9205 static inline void atomic_sub(int i, atomic_t *v)
9206 {
9207 - asm volatile(LOCK_PREFIX "subl %1,%0"
9208 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9209 +
9210 +#ifdef CONFIG_PAX_REFCOUNT
9211 + "jno 0f\n"
9212 + LOCK_PREFIX "addl %1,%0\n"
9213 + "int $4\n0:\n"
9214 + _ASM_EXTABLE(0b, 0b)
9215 +#endif
9216 +
9217 + : "+m" (v->counter)
9218 + : "ir" (i));
9219 +}
9220 +
9221 +/**
9222 + * atomic_sub_unchecked - subtract integer from atomic variable
9223 + * @i: integer value to subtract
9224 + * @v: pointer of type atomic_unchecked_t
9225 + *
9226 + * Atomically subtracts @i from @v.
9227 + */
9228 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9229 +{
9230 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9231 : "+m" (v->counter)
9232 : "ir" (i));
9233 }
9234 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9235 {
9236 unsigned char c;
9237
9238 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9239 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9240 +
9241 +#ifdef CONFIG_PAX_REFCOUNT
9242 + "jno 0f\n"
9243 + LOCK_PREFIX "addl %2,%0\n"
9244 + "int $4\n0:\n"
9245 + _ASM_EXTABLE(0b, 0b)
9246 +#endif
9247 +
9248 + "sete %1\n"
9249 : "+m" (v->counter), "=qm" (c)
9250 : "ir" (i) : "memory");
9251 return c;
9252 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9253 */
9254 static inline void atomic_inc(atomic_t *v)
9255 {
9256 - asm volatile(LOCK_PREFIX "incl %0"
9257 + asm volatile(LOCK_PREFIX "incl %0\n"
9258 +
9259 +#ifdef CONFIG_PAX_REFCOUNT
9260 + "jno 0f\n"
9261 + LOCK_PREFIX "decl %0\n"
9262 + "int $4\n0:\n"
9263 + _ASM_EXTABLE(0b, 0b)
9264 +#endif
9265 +
9266 + : "+m" (v->counter));
9267 +}
9268 +
9269 +/**
9270 + * atomic_inc_unchecked - increment atomic variable
9271 + * @v: pointer of type atomic_unchecked_t
9272 + *
9273 + * Atomically increments @v by 1.
9274 + */
9275 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9276 +{
9277 + asm volatile(LOCK_PREFIX "incl %0\n"
9278 : "+m" (v->counter));
9279 }
9280
9281 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9282 */
9283 static inline void atomic_dec(atomic_t *v)
9284 {
9285 - asm volatile(LOCK_PREFIX "decl %0"
9286 + asm volatile(LOCK_PREFIX "decl %0\n"
9287 +
9288 +#ifdef CONFIG_PAX_REFCOUNT
9289 + "jno 0f\n"
9290 + LOCK_PREFIX "incl %0\n"
9291 + "int $4\n0:\n"
9292 + _ASM_EXTABLE(0b, 0b)
9293 +#endif
9294 +
9295 + : "+m" (v->counter));
9296 +}
9297 +
9298 +/**
9299 + * atomic_dec_unchecked - decrement atomic variable
9300 + * @v: pointer of type atomic_unchecked_t
9301 + *
9302 + * Atomically decrements @v by 1.
9303 + */
9304 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9305 +{
9306 + asm volatile(LOCK_PREFIX "decl %0\n"
9307 : "+m" (v->counter));
9308 }
9309
9310 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9311 {
9312 unsigned char c;
9313
9314 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9315 + asm volatile(LOCK_PREFIX "decl %0\n"
9316 +
9317 +#ifdef CONFIG_PAX_REFCOUNT
9318 + "jno 0f\n"
9319 + LOCK_PREFIX "incl %0\n"
9320 + "int $4\n0:\n"
9321 + _ASM_EXTABLE(0b, 0b)
9322 +#endif
9323 +
9324 + "sete %1\n"
9325 : "+m" (v->counter), "=qm" (c)
9326 : : "memory");
9327 return c != 0;
9328 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9329 {
9330 unsigned char c;
9331
9332 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9333 + asm volatile(LOCK_PREFIX "incl %0\n"
9334 +
9335 +#ifdef CONFIG_PAX_REFCOUNT
9336 + "jno 0f\n"
9337 + LOCK_PREFIX "decl %0\n"
9338 + "int $4\n0:\n"
9339 + _ASM_EXTABLE(0b, 0b)
9340 +#endif
9341 +
9342 + "sete %1\n"
9343 + : "+m" (v->counter), "=qm" (c)
9344 + : : "memory");
9345 + return c != 0;
9346 +}
9347 +
9348 +/**
9349 + * atomic_inc_and_test_unchecked - increment and test
9350 + * @v: pointer of type atomic_unchecked_t
9351 + *
9352 + * Atomically increments @v by 1
9353 + * and returns true if the result is zero, or false for all
9354 + * other cases.
9355 + */
9356 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9357 +{
9358 + unsigned char c;
9359 +
9360 + asm volatile(LOCK_PREFIX "incl %0\n"
9361 + "sete %1\n"
9362 : "+m" (v->counter), "=qm" (c)
9363 : : "memory");
9364 return c != 0;
9365 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9366 {
9367 unsigned char c;
9368
9369 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9370 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9371 +
9372 +#ifdef CONFIG_PAX_REFCOUNT
9373 + "jno 0f\n"
9374 + LOCK_PREFIX "subl %2,%0\n"
9375 + "int $4\n0:\n"
9376 + _ASM_EXTABLE(0b, 0b)
9377 +#endif
9378 +
9379 + "sets %1\n"
9380 : "+m" (v->counter), "=qm" (c)
9381 : "ir" (i) : "memory");
9382 return c;
9383 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9384 goto no_xadd;
9385 #endif
9386 /* Modern 486+ processor */
9387 - return i + xadd(&v->counter, i);
9388 + return i + xadd_check_overflow(&v->counter, i);
9389
9390 #ifdef CONFIG_M386
9391 no_xadd: /* Legacy 386 processor */
9392 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9393 }
9394
9395 /**
9396 + * atomic_add_return_unchecked - add integer and return
9397 + * @i: integer value to add
9398 + * @v: pointer of type atomic_unchecked_t
9399 + *
9400 + * Atomically adds @i to @v and returns @i + @v
9401 + */
9402 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9403 +{
9404 +#ifdef CONFIG_M386
9405 + int __i;
9406 + unsigned long flags;
9407 + if (unlikely(boot_cpu_data.x86 <= 3))
9408 + goto no_xadd;
9409 +#endif
9410 + /* Modern 486+ processor */
9411 + return i + xadd(&v->counter, i);
9412 +
9413 +#ifdef CONFIG_M386
9414 +no_xadd: /* Legacy 386 processor */
9415 + raw_local_irq_save(flags);
9416 + __i = atomic_read_unchecked(v);
9417 + atomic_set_unchecked(v, i + __i);
9418 + raw_local_irq_restore(flags);
9419 + return i + __i;
9420 +#endif
9421 +}
9422 +
9423 +/**
9424 * atomic_sub_return - subtract integer and return
9425 * @v: pointer of type atomic_t
9426 * @i: integer value to subtract
9427 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9428 }
9429
9430 #define atomic_inc_return(v) (atomic_add_return(1, v))
9431 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9432 +{
9433 + return atomic_add_return_unchecked(1, v);
9434 +}
9435 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9436
9437 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9438 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9439 return cmpxchg(&v->counter, old, new);
9440 }
9441
9442 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9443 +{
9444 + return cmpxchg(&v->counter, old, new);
9445 +}
9446 +
9447 static inline int atomic_xchg(atomic_t *v, int new)
9448 {
9449 return xchg(&v->counter, new);
9450 }
9451
9452 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9453 +{
9454 + return xchg(&v->counter, new);
9455 +}
9456 +
9457 /**
9458 * __atomic_add_unless - add unless the number is already a given value
9459 * @v: pointer of type atomic_t
9460 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9461 */
9462 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9463 {
9464 - int c, old;
9465 + int c, old, new;
9466 c = atomic_read(v);
9467 for (;;) {
9468 - if (unlikely(c == (u)))
9469 + if (unlikely(c == u))
9470 break;
9471 - old = atomic_cmpxchg((v), c, c + (a));
9472 +
9473 + asm volatile("addl %2,%0\n"
9474 +
9475 +#ifdef CONFIG_PAX_REFCOUNT
9476 + "jno 0f\n"
9477 + "subl %2,%0\n"
9478 + "int $4\n0:\n"
9479 + _ASM_EXTABLE(0b, 0b)
9480 +#endif
9481 +
9482 + : "=r" (new)
9483 + : "0" (c), "ir" (a));
9484 +
9485 + old = atomic_cmpxchg(v, c, new);
9486 if (likely(old == c))
9487 break;
9488 c = old;
9489 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9490 return c;
9491 }
9492
9493 +/**
9494 + * atomic_inc_not_zero_hint - increment if not null
9495 + * @v: pointer of type atomic_t
9496 + * @hint: probable value of the atomic before the increment
9497 + *
9498 + * This version of atomic_inc_not_zero() gives a hint of probable
9499 + * value of the atomic. This helps processor to not read the memory
9500 + * before doing the atomic read/modify/write cycle, lowering
9501 + * number of bus transactions on some arches.
9502 + *
9503 + * Returns: 0 if increment was not done, 1 otherwise.
9504 + */
9505 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9506 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9507 +{
9508 + int val, c = hint, new;
9509 +
9510 + /* sanity test, should be removed by compiler if hint is a constant */
9511 + if (!hint)
9512 + return __atomic_add_unless(v, 1, 0);
9513 +
9514 + do {
9515 + asm volatile("incl %0\n"
9516 +
9517 +#ifdef CONFIG_PAX_REFCOUNT
9518 + "jno 0f\n"
9519 + "decl %0\n"
9520 + "int $4\n0:\n"
9521 + _ASM_EXTABLE(0b, 0b)
9522 +#endif
9523 +
9524 + : "=r" (new)
9525 + : "0" (c));
9526 +
9527 + val = atomic_cmpxchg(v, c, new);
9528 + if (val == c)
9529 + return 1;
9530 + c = val;
9531 + } while (c);
9532 +
9533 + return 0;
9534 +}
9535
9536 /*
9537 * atomic_dec_if_positive - decrement by 1 if old value positive
9538 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9539 #endif
9540
9541 /* These are x86-specific, used by some header files */
9542 -#define atomic_clear_mask(mask, addr) \
9543 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9544 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9545 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9546 +{
9547 + asm volatile(LOCK_PREFIX "andl %1,%0"
9548 + : "+m" (v->counter)
9549 + : "r" (~(mask))
9550 + : "memory");
9551 +}
9552
9553 -#define atomic_set_mask(mask, addr) \
9554 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9555 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9556 - : "memory")
9557 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9558 +{
9559 + asm volatile(LOCK_PREFIX "andl %1,%0"
9560 + : "+m" (v->counter)
9561 + : "r" (~(mask))
9562 + : "memory");
9563 +}
9564 +
9565 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9566 +{
9567 + asm volatile(LOCK_PREFIX "orl %1,%0"
9568 + : "+m" (v->counter)
9569 + : "r" (mask)
9570 + : "memory");
9571 +}
9572 +
9573 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9574 +{
9575 + asm volatile(LOCK_PREFIX "orl %1,%0"
9576 + : "+m" (v->counter)
9577 + : "r" (mask)
9578 + : "memory");
9579 +}
9580
9581 /* Atomic operations are already serializing on x86 */
9582 #define smp_mb__before_atomic_dec() barrier()
9583 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9584 index b154de7..aadebd8 100644
9585 --- a/arch/x86/include/asm/atomic64_32.h
9586 +++ b/arch/x86/include/asm/atomic64_32.h
9587 @@ -12,6 +12,14 @@ typedef struct {
9588 u64 __aligned(8) counter;
9589 } atomic64_t;
9590
9591 +#ifdef CONFIG_PAX_REFCOUNT
9592 +typedef struct {
9593 + u64 __aligned(8) counter;
9594 +} atomic64_unchecked_t;
9595 +#else
9596 +typedef atomic64_t atomic64_unchecked_t;
9597 +#endif
9598 +
9599 #define ATOMIC64_INIT(val) { (val) }
9600
9601 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9602 @@ -37,21 +45,31 @@ typedef struct {
9603 ATOMIC64_DECL_ONE(sym##_386)
9604
9605 ATOMIC64_DECL_ONE(add_386);
9606 +ATOMIC64_DECL_ONE(add_unchecked_386);
9607 ATOMIC64_DECL_ONE(sub_386);
9608 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9609 ATOMIC64_DECL_ONE(inc_386);
9610 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9611 ATOMIC64_DECL_ONE(dec_386);
9612 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9613 #endif
9614
9615 #define alternative_atomic64(f, out, in...) \
9616 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9617
9618 ATOMIC64_DECL(read);
9619 +ATOMIC64_DECL(read_unchecked);
9620 ATOMIC64_DECL(set);
9621 +ATOMIC64_DECL(set_unchecked);
9622 ATOMIC64_DECL(xchg);
9623 ATOMIC64_DECL(add_return);
9624 +ATOMIC64_DECL(add_return_unchecked);
9625 ATOMIC64_DECL(sub_return);
9626 +ATOMIC64_DECL(sub_return_unchecked);
9627 ATOMIC64_DECL(inc_return);
9628 +ATOMIC64_DECL(inc_return_unchecked);
9629 ATOMIC64_DECL(dec_return);
9630 +ATOMIC64_DECL(dec_return_unchecked);
9631 ATOMIC64_DECL(dec_if_positive);
9632 ATOMIC64_DECL(inc_not_zero);
9633 ATOMIC64_DECL(add_unless);
9634 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9635 }
9636
9637 /**
9638 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9639 + * @p: pointer to type atomic64_unchecked_t
9640 + * @o: expected value
9641 + * @n: new value
9642 + *
9643 + * Atomically sets @v to @n if it was equal to @o and returns
9644 + * the old value.
9645 + */
9646 +
9647 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9648 +{
9649 + return cmpxchg64(&v->counter, o, n);
9650 +}
9651 +
9652 +/**
9653 * atomic64_xchg - xchg atomic64 variable
9654 * @v: pointer to type atomic64_t
9655 * @n: value to assign
9656 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9657 }
9658
9659 /**
9660 + * atomic64_set_unchecked - set atomic64 variable
9661 + * @v: pointer to type atomic64_unchecked_t
9662 + * @n: value to assign
9663 + *
9664 + * Atomically sets the value of @v to @n.
9665 + */
9666 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9667 +{
9668 + unsigned high = (unsigned)(i >> 32);
9669 + unsigned low = (unsigned)i;
9670 + alternative_atomic64(set, /* no output */,
9671 + "S" (v), "b" (low), "c" (high)
9672 + : "eax", "edx", "memory");
9673 +}
9674 +
9675 +/**
9676 * atomic64_read - read atomic64 variable
9677 * @v: pointer to type atomic64_t
9678 *
9679 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9680 }
9681
9682 /**
9683 + * atomic64_read_unchecked - read atomic64 variable
9684 + * @v: pointer to type atomic64_unchecked_t
9685 + *
9686 + * Atomically reads the value of @v and returns it.
9687 + */
9688 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9689 +{
9690 + long long r;
9691 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9692 + return r;
9693 + }
9694 +
9695 +/**
9696 * atomic64_add_return - add and return
9697 * @i: integer value to add
9698 * @v: pointer to type atomic64_t
9699 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9700 return i;
9701 }
9702
9703 +/**
9704 + * atomic64_add_return_unchecked - add and return
9705 + * @i: integer value to add
9706 + * @v: pointer to type atomic64_unchecked_t
9707 + *
9708 + * Atomically adds @i to @v and returns @i + *@v
9709 + */
9710 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9711 +{
9712 + alternative_atomic64(add_return_unchecked,
9713 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9714 + ASM_NO_INPUT_CLOBBER("memory"));
9715 + return i;
9716 +}
9717 +
9718 /*
9719 * Other variants with different arithmetic operators:
9720 */
9721 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9722 return a;
9723 }
9724
9725 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9726 +{
9727 + long long a;
9728 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9729 + "S" (v) : "memory", "ecx");
9730 + return a;
9731 +}
9732 +
9733 static inline long long atomic64_dec_return(atomic64_t *v)
9734 {
9735 long long a;
9736 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9737 }
9738
9739 /**
9740 + * atomic64_add_unchecked - add integer to atomic64 variable
9741 + * @i: integer value to add
9742 + * @v: pointer to type atomic64_unchecked_t
9743 + *
9744 + * Atomically adds @i to @v.
9745 + */
9746 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9747 +{
9748 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9749 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9750 + ASM_NO_INPUT_CLOBBER("memory"));
9751 + return i;
9752 +}
9753 +
9754 +/**
9755 * atomic64_sub - subtract the atomic64 variable
9756 * @i: integer value to subtract
9757 * @v: pointer to type atomic64_t
9758 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9759 index 0e1cbfc..5623683 100644
9760 --- a/arch/x86/include/asm/atomic64_64.h
9761 +++ b/arch/x86/include/asm/atomic64_64.h
9762 @@ -18,7 +18,19 @@
9763 */
9764 static inline long atomic64_read(const atomic64_t *v)
9765 {
9766 - return (*(volatile long *)&(v)->counter);
9767 + return (*(volatile const long *)&(v)->counter);
9768 +}
9769 +
9770 +/**
9771 + * atomic64_read_unchecked - read atomic64 variable
9772 + * @v: pointer of type atomic64_unchecked_t
9773 + *
9774 + * Atomically reads the value of @v.
9775 + * Doesn't imply a read memory barrier.
9776 + */
9777 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9778 +{
9779 + return (*(volatile const long *)&(v)->counter);
9780 }
9781
9782 /**
9783 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9784 }
9785
9786 /**
9787 + * atomic64_set_unchecked - set atomic64 variable
9788 + * @v: pointer to type atomic64_unchecked_t
9789 + * @i: required value
9790 + *
9791 + * Atomically sets the value of @v to @i.
9792 + */
9793 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9794 +{
9795 + v->counter = i;
9796 +}
9797 +
9798 +/**
9799 * atomic64_add - add integer to atomic64 variable
9800 * @i: integer value to add
9801 * @v: pointer to type atomic64_t
9802 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9803 */
9804 static inline void atomic64_add(long i, atomic64_t *v)
9805 {
9806 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9807 +
9808 +#ifdef CONFIG_PAX_REFCOUNT
9809 + "jno 0f\n"
9810 + LOCK_PREFIX "subq %1,%0\n"
9811 + "int $4\n0:\n"
9812 + _ASM_EXTABLE(0b, 0b)
9813 +#endif
9814 +
9815 + : "=m" (v->counter)
9816 + : "er" (i), "m" (v->counter));
9817 +}
9818 +
9819 +/**
9820 + * atomic64_add_unchecked - add integer to atomic64 variable
9821 + * @i: integer value to add
9822 + * @v: pointer to type atomic64_unchecked_t
9823 + *
9824 + * Atomically adds @i to @v.
9825 + */
9826 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9827 +{
9828 asm volatile(LOCK_PREFIX "addq %1,%0"
9829 : "=m" (v->counter)
9830 : "er" (i), "m" (v->counter));
9831 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9832 */
9833 static inline void atomic64_sub(long i, atomic64_t *v)
9834 {
9835 - asm volatile(LOCK_PREFIX "subq %1,%0"
9836 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9837 +
9838 +#ifdef CONFIG_PAX_REFCOUNT
9839 + "jno 0f\n"
9840 + LOCK_PREFIX "addq %1,%0\n"
9841 + "int $4\n0:\n"
9842 + _ASM_EXTABLE(0b, 0b)
9843 +#endif
9844 +
9845 + : "=m" (v->counter)
9846 + : "er" (i), "m" (v->counter));
9847 +}
9848 +
9849 +/**
9850 + * atomic64_sub_unchecked - subtract the atomic64 variable
9851 + * @i: integer value to subtract
9852 + * @v: pointer to type atomic64_unchecked_t
9853 + *
9854 + * Atomically subtracts @i from @v.
9855 + */
9856 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9857 +{
9858 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9859 : "=m" (v->counter)
9860 : "er" (i), "m" (v->counter));
9861 }
9862 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9863 {
9864 unsigned char c;
9865
9866 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9867 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9868 +
9869 +#ifdef CONFIG_PAX_REFCOUNT
9870 + "jno 0f\n"
9871 + LOCK_PREFIX "addq %2,%0\n"
9872 + "int $4\n0:\n"
9873 + _ASM_EXTABLE(0b, 0b)
9874 +#endif
9875 +
9876 + "sete %1\n"
9877 : "=m" (v->counter), "=qm" (c)
9878 : "er" (i), "m" (v->counter) : "memory");
9879 return c;
9880 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9881 */
9882 static inline void atomic64_inc(atomic64_t *v)
9883 {
9884 + asm volatile(LOCK_PREFIX "incq %0\n"
9885 +
9886 +#ifdef CONFIG_PAX_REFCOUNT
9887 + "jno 0f\n"
9888 + LOCK_PREFIX "decq %0\n"
9889 + "int $4\n0:\n"
9890 + _ASM_EXTABLE(0b, 0b)
9891 +#endif
9892 +
9893 + : "=m" (v->counter)
9894 + : "m" (v->counter));
9895 +}
9896 +
9897 +/**
9898 + * atomic64_inc_unchecked - increment atomic64 variable
9899 + * @v: pointer to type atomic64_unchecked_t
9900 + *
9901 + * Atomically increments @v by 1.
9902 + */
9903 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9904 +{
9905 asm volatile(LOCK_PREFIX "incq %0"
9906 : "=m" (v->counter)
9907 : "m" (v->counter));
9908 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9909 */
9910 static inline void atomic64_dec(atomic64_t *v)
9911 {
9912 - asm volatile(LOCK_PREFIX "decq %0"
9913 + asm volatile(LOCK_PREFIX "decq %0\n"
9914 +
9915 +#ifdef CONFIG_PAX_REFCOUNT
9916 + "jno 0f\n"
9917 + LOCK_PREFIX "incq %0\n"
9918 + "int $4\n0:\n"
9919 + _ASM_EXTABLE(0b, 0b)
9920 +#endif
9921 +
9922 + : "=m" (v->counter)
9923 + : "m" (v->counter));
9924 +}
9925 +
9926 +/**
9927 + * atomic64_dec_unchecked - decrement atomic64 variable
9928 + * @v: pointer to type atomic64_t
9929 + *
9930 + * Atomically decrements @v by 1.
9931 + */
9932 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9933 +{
9934 + asm volatile(LOCK_PREFIX "decq %0\n"
9935 : "=m" (v->counter)
9936 : "m" (v->counter));
9937 }
9938 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9939 {
9940 unsigned char c;
9941
9942 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9943 + asm volatile(LOCK_PREFIX "decq %0\n"
9944 +
9945 +#ifdef CONFIG_PAX_REFCOUNT
9946 + "jno 0f\n"
9947 + LOCK_PREFIX "incq %0\n"
9948 + "int $4\n0:\n"
9949 + _ASM_EXTABLE(0b, 0b)
9950 +#endif
9951 +
9952 + "sete %1\n"
9953 : "=m" (v->counter), "=qm" (c)
9954 : "m" (v->counter) : "memory");
9955 return c != 0;
9956 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9957 {
9958 unsigned char c;
9959
9960 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9961 + asm volatile(LOCK_PREFIX "incq %0\n"
9962 +
9963 +#ifdef CONFIG_PAX_REFCOUNT
9964 + "jno 0f\n"
9965 + LOCK_PREFIX "decq %0\n"
9966 + "int $4\n0:\n"
9967 + _ASM_EXTABLE(0b, 0b)
9968 +#endif
9969 +
9970 + "sete %1\n"
9971 : "=m" (v->counter), "=qm" (c)
9972 : "m" (v->counter) : "memory");
9973 return c != 0;
9974 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9975 {
9976 unsigned char c;
9977
9978 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9979 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9980 +
9981 +#ifdef CONFIG_PAX_REFCOUNT
9982 + "jno 0f\n"
9983 + LOCK_PREFIX "subq %2,%0\n"
9984 + "int $4\n0:\n"
9985 + _ASM_EXTABLE(0b, 0b)
9986 +#endif
9987 +
9988 + "sets %1\n"
9989 : "=m" (v->counter), "=qm" (c)
9990 : "er" (i), "m" (v->counter) : "memory");
9991 return c;
9992 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9993 */
9994 static inline long atomic64_add_return(long i, atomic64_t *v)
9995 {
9996 + return i + xadd_check_overflow(&v->counter, i);
9997 +}
9998 +
9999 +/**
10000 + * atomic64_add_return_unchecked - add and return
10001 + * @i: integer value to add
10002 + * @v: pointer to type atomic64_unchecked_t
10003 + *
10004 + * Atomically adds @i to @v and returns @i + @v
10005 + */
10006 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10007 +{
10008 return i + xadd(&v->counter, i);
10009 }
10010
10011 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10012 }
10013
10014 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10015 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10016 +{
10017 + return atomic64_add_return_unchecked(1, v);
10018 +}
10019 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10020
10021 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10022 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10023 return cmpxchg(&v->counter, old, new);
10024 }
10025
10026 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10027 +{
10028 + return cmpxchg(&v->counter, old, new);
10029 +}
10030 +
10031 static inline long atomic64_xchg(atomic64_t *v, long new)
10032 {
10033 return xchg(&v->counter, new);
10034 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10035 */
10036 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10037 {
10038 - long c, old;
10039 + long c, old, new;
10040 c = atomic64_read(v);
10041 for (;;) {
10042 - if (unlikely(c == (u)))
10043 + if (unlikely(c == u))
10044 break;
10045 - old = atomic64_cmpxchg((v), c, c + (a));
10046 +
10047 + asm volatile("add %2,%0\n"
10048 +
10049 +#ifdef CONFIG_PAX_REFCOUNT
10050 + "jno 0f\n"
10051 + "sub %2,%0\n"
10052 + "int $4\n0:\n"
10053 + _ASM_EXTABLE(0b, 0b)
10054 +#endif
10055 +
10056 + : "=r" (new)
10057 + : "0" (c), "ir" (a));
10058 +
10059 + old = atomic64_cmpxchg(v, c, new);
10060 if (likely(old == c))
10061 break;
10062 c = old;
10063 }
10064 - return c != (u);
10065 + return c != u;
10066 }
10067
10068 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10069 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10070 index 72f5009..2f8b9a9 100644
10071 --- a/arch/x86/include/asm/bitops.h
10072 +++ b/arch/x86/include/asm/bitops.h
10073 @@ -40,7 +40,7 @@
10074 * a mask operation on a byte.
10075 */
10076 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10077 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10078 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10079 #define CONST_MASK(nr) (1 << ((nr) & 7))
10080
10081 /**
10082 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10083 index b13fe63..0dab13a 100644
10084 --- a/arch/x86/include/asm/boot.h
10085 +++ b/arch/x86/include/asm/boot.h
10086 @@ -11,10 +11,15 @@
10087 #include <asm/pgtable_types.h>
10088
10089 /* Physical address where kernel should be loaded. */
10090 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10091 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10092 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10093 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10094
10095 +#ifndef __ASSEMBLY__
10096 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10097 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10098 +#endif
10099 +
10100 /* Minimum kernel alignment, as a power of two */
10101 #ifdef CONFIG_X86_64
10102 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10103 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10104 index 48f99f1..d78ebf9 100644
10105 --- a/arch/x86/include/asm/cache.h
10106 +++ b/arch/x86/include/asm/cache.h
10107 @@ -5,12 +5,13 @@
10108
10109 /* L1 cache line size */
10110 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10111 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10112 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10113
10114 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10115 +#define __read_only __attribute__((__section__(".data..read_only")))
10116
10117 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10118 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10119 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10120
10121 #ifdef CONFIG_X86_VSMP
10122 #ifdef CONFIG_SMP
10123 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10124 index 9863ee3..4a1f8e1 100644
10125 --- a/arch/x86/include/asm/cacheflush.h
10126 +++ b/arch/x86/include/asm/cacheflush.h
10127 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10128 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10129
10130 if (pg_flags == _PGMT_DEFAULT)
10131 - return -1;
10132 + return ~0UL;
10133 else if (pg_flags == _PGMT_WC)
10134 return _PAGE_CACHE_WC;
10135 else if (pg_flags == _PGMT_UC_MINUS)
10136 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10137 index 46fc474..b02b0f9 100644
10138 --- a/arch/x86/include/asm/checksum_32.h
10139 +++ b/arch/x86/include/asm/checksum_32.h
10140 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10141 int len, __wsum sum,
10142 int *src_err_ptr, int *dst_err_ptr);
10143
10144 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10145 + int len, __wsum sum,
10146 + int *src_err_ptr, int *dst_err_ptr);
10147 +
10148 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10149 + int len, __wsum sum,
10150 + int *src_err_ptr, int *dst_err_ptr);
10151 +
10152 /*
10153 * Note: when you get a NULL pointer exception here this means someone
10154 * passed in an incorrect kernel address to one of these functions.
10155 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10156 int *err_ptr)
10157 {
10158 might_sleep();
10159 - return csum_partial_copy_generic((__force void *)src, dst,
10160 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10161 len, sum, err_ptr, NULL);
10162 }
10163
10164 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10165 {
10166 might_sleep();
10167 if (access_ok(VERIFY_WRITE, dst, len))
10168 - return csum_partial_copy_generic(src, (__force void *)dst,
10169 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10170 len, sum, NULL, err_ptr);
10171
10172 if (len)
10173 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10174 index 99480e5..d81165b 100644
10175 --- a/arch/x86/include/asm/cmpxchg.h
10176 +++ b/arch/x86/include/asm/cmpxchg.h
10177 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10178 __compiletime_error("Bad argument size for cmpxchg");
10179 extern void __xadd_wrong_size(void)
10180 __compiletime_error("Bad argument size for xadd");
10181 +extern void __xadd_check_overflow_wrong_size(void)
10182 + __compiletime_error("Bad argument size for xadd_check_overflow");
10183 extern void __add_wrong_size(void)
10184 __compiletime_error("Bad argument size for add");
10185 +extern void __add_check_overflow_wrong_size(void)
10186 + __compiletime_error("Bad argument size for add_check_overflow");
10187
10188 /*
10189 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10190 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10191 __ret; \
10192 })
10193
10194 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10195 + ({ \
10196 + __typeof__ (*(ptr)) __ret = (arg); \
10197 + switch (sizeof(*(ptr))) { \
10198 + case __X86_CASE_L: \
10199 + asm volatile (lock #op "l %0, %1\n" \
10200 + "jno 0f\n" \
10201 + "mov %0,%1\n" \
10202 + "int $4\n0:\n" \
10203 + _ASM_EXTABLE(0b, 0b) \
10204 + : "+r" (__ret), "+m" (*(ptr)) \
10205 + : : "memory", "cc"); \
10206 + break; \
10207 + case __X86_CASE_Q: \
10208 + asm volatile (lock #op "q %q0, %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 + default: \
10217 + __ ## op ## _check_overflow_wrong_size(); \
10218 + } \
10219 + __ret; \
10220 + })
10221 +
10222 /*
10223 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10224 * Since this is generally used to protect other memory information, we
10225 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10226 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10227 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10228
10229 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10230 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10231 +
10232 #define __add(ptr, inc, lock) \
10233 ({ \
10234 __typeof__ (*(ptr)) __ret = (inc); \
10235 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10236 index 6b7ee5f..9d664b3 100644
10237 --- a/arch/x86/include/asm/cpufeature.h
10238 +++ b/arch/x86/include/asm/cpufeature.h
10239 @@ -202,13 +202,14 @@
10240 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10241 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10242 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10243 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10244 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10245 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10246 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10247 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10248 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10249 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10250 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10251 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10252
10253 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10254
10255 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10256 ".section .discard,\"aw\",@progbits\n"
10257 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10258 ".previous\n"
10259 - ".section .altinstr_replacement,\"ax\"\n"
10260 + ".section .altinstr_replacement,\"a\"\n"
10261 "3: movb $1,%0\n"
10262 "4:\n"
10263 ".previous\n"
10264 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10265 index 8bf1c06..f723dfd 100644
10266 --- a/arch/x86/include/asm/desc.h
10267 +++ b/arch/x86/include/asm/desc.h
10268 @@ -4,6 +4,7 @@
10269 #include <asm/desc_defs.h>
10270 #include <asm/ldt.h>
10271 #include <asm/mmu.h>
10272 +#include <asm/pgtable.h>
10273
10274 #include <linux/smp.h>
10275 #include <linux/percpu.h>
10276 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10277
10278 desc->type = (info->read_exec_only ^ 1) << 1;
10279 desc->type |= info->contents << 2;
10280 + desc->type |= info->seg_not_present ^ 1;
10281
10282 desc->s = 1;
10283 desc->dpl = 0x3;
10284 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10285 }
10286
10287 extern struct desc_ptr idt_descr;
10288 -extern gate_desc idt_table[];
10289 extern struct desc_ptr nmi_idt_descr;
10290 -extern gate_desc nmi_idt_table[];
10291 -
10292 -struct gdt_page {
10293 - struct desc_struct gdt[GDT_ENTRIES];
10294 -} __attribute__((aligned(PAGE_SIZE)));
10295 -
10296 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10297 +extern gate_desc idt_table[256];
10298 +extern gate_desc nmi_idt_table[256];
10299
10300 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10301 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10302 {
10303 - return per_cpu(gdt_page, cpu).gdt;
10304 + return cpu_gdt_table[cpu];
10305 }
10306
10307 #ifdef CONFIG_X86_64
10308 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10309 unsigned long base, unsigned dpl, unsigned flags,
10310 unsigned short seg)
10311 {
10312 - gate->a = (seg << 16) | (base & 0xffff);
10313 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10314 + gate->gate.offset_low = base;
10315 + gate->gate.seg = seg;
10316 + gate->gate.reserved = 0;
10317 + gate->gate.type = type;
10318 + gate->gate.s = 0;
10319 + gate->gate.dpl = dpl;
10320 + gate->gate.p = 1;
10321 + gate->gate.offset_high = base >> 16;
10322 }
10323
10324 #endif
10325 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10326
10327 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10328 {
10329 + pax_open_kernel();
10330 memcpy(&idt[entry], gate, sizeof(*gate));
10331 + pax_close_kernel();
10332 }
10333
10334 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10335 {
10336 + pax_open_kernel();
10337 memcpy(&ldt[entry], desc, 8);
10338 + pax_close_kernel();
10339 }
10340
10341 static inline void
10342 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10343 default: size = sizeof(*gdt); break;
10344 }
10345
10346 + pax_open_kernel();
10347 memcpy(&gdt[entry], desc, size);
10348 + pax_close_kernel();
10349 }
10350
10351 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10352 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10353
10354 static inline void native_load_tr_desc(void)
10355 {
10356 + pax_open_kernel();
10357 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10358 + pax_close_kernel();
10359 }
10360
10361 static inline void native_load_gdt(const struct desc_ptr *dtr)
10362 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10363 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10364 unsigned int i;
10365
10366 + pax_open_kernel();
10367 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10368 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10369 + pax_close_kernel();
10370 }
10371
10372 #define _LDT_empty(info) \
10373 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10374 }
10375
10376 #ifdef CONFIG_X86_64
10377 -static inline void set_nmi_gate(int gate, void *addr)
10378 +static inline void set_nmi_gate(int gate, const void *addr)
10379 {
10380 gate_desc s;
10381
10382 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10383 }
10384 #endif
10385
10386 -static inline void _set_gate(int gate, unsigned type, void *addr,
10387 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10388 unsigned dpl, unsigned ist, unsigned seg)
10389 {
10390 gate_desc s;
10391 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10392 * Pentium F0 0F bugfix can have resulted in the mapped
10393 * IDT being write-protected.
10394 */
10395 -static inline void set_intr_gate(unsigned int n, void *addr)
10396 +static inline void set_intr_gate(unsigned int n, const void *addr)
10397 {
10398 BUG_ON((unsigned)n > 0xFF);
10399 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10400 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10401 /*
10402 * This routine sets up an interrupt gate at directory privilege level 3.
10403 */
10404 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10405 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10406 {
10407 BUG_ON((unsigned)n > 0xFF);
10408 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10409 }
10410
10411 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10412 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10413 {
10414 BUG_ON((unsigned)n > 0xFF);
10415 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10416 }
10417
10418 -static inline void set_trap_gate(unsigned int n, void *addr)
10419 +static inline void set_trap_gate(unsigned int n, const void *addr)
10420 {
10421 BUG_ON((unsigned)n > 0xFF);
10422 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10423 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10424 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10425 {
10426 BUG_ON((unsigned)n > 0xFF);
10427 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10428 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10429 }
10430
10431 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10432 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10433 {
10434 BUG_ON((unsigned)n > 0xFF);
10435 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10436 }
10437
10438 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10439 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10440 {
10441 BUG_ON((unsigned)n > 0xFF);
10442 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10443 }
10444
10445 +#ifdef CONFIG_X86_32
10446 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10447 +{
10448 + struct desc_struct d;
10449 +
10450 + if (likely(limit))
10451 + limit = (limit - 1UL) >> PAGE_SHIFT;
10452 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10453 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10454 +}
10455 +#endif
10456 +
10457 #endif /* _ASM_X86_DESC_H */
10458 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10459 index 278441f..b95a174 100644
10460 --- a/arch/x86/include/asm/desc_defs.h
10461 +++ b/arch/x86/include/asm/desc_defs.h
10462 @@ -31,6 +31,12 @@ struct desc_struct {
10463 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10464 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10465 };
10466 + struct {
10467 + u16 offset_low;
10468 + u16 seg;
10469 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10470 + unsigned offset_high: 16;
10471 + } gate;
10472 };
10473 } __attribute__((packed));
10474
10475 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10476 index 3778256..c5d4fce 100644
10477 --- a/arch/x86/include/asm/e820.h
10478 +++ b/arch/x86/include/asm/e820.h
10479 @@ -69,7 +69,7 @@ struct e820map {
10480 #define ISA_START_ADDRESS 0xa0000
10481 #define ISA_END_ADDRESS 0x100000
10482
10483 -#define BIOS_BEGIN 0x000a0000
10484 +#define BIOS_BEGIN 0x000c0000
10485 #define BIOS_END 0x00100000
10486
10487 #define BIOS_ROM_BASE 0xffe00000
10488 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10489 index 5939f44..f8845f6 100644
10490 --- a/arch/x86/include/asm/elf.h
10491 +++ b/arch/x86/include/asm/elf.h
10492 @@ -243,7 +243,25 @@ extern int force_personality32;
10493 the loader. We need to make sure that it is out of the way of the program
10494 that it will "exec", and that there is sufficient room for the brk. */
10495
10496 +#ifdef CONFIG_PAX_SEGMEXEC
10497 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10498 +#else
10499 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10500 +#endif
10501 +
10502 +#ifdef CONFIG_PAX_ASLR
10503 +#ifdef CONFIG_X86_32
10504 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10505 +
10506 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10507 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10508 +#else
10509 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10510 +
10511 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10512 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10513 +#endif
10514 +#endif
10515
10516 /* This yields a mask that user programs can use to figure out what
10517 instruction set this CPU supports. This could be done in user space,
10518 @@ -296,16 +314,12 @@ do { \
10519
10520 #define ARCH_DLINFO \
10521 do { \
10522 - if (vdso_enabled) \
10523 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10524 - (unsigned long)current->mm->context.vdso); \
10525 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10526 } while (0)
10527
10528 #define ARCH_DLINFO_X32 \
10529 do { \
10530 - if (vdso_enabled) \
10531 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10532 - (unsigned long)current->mm->context.vdso); \
10533 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10534 } while (0)
10535
10536 #define AT_SYSINFO 32
10537 @@ -320,7 +334,7 @@ else \
10538
10539 #endif /* !CONFIG_X86_32 */
10540
10541 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10542 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10543
10544 #define VDSO_ENTRY \
10545 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10546 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10547 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10548 #define compat_arch_setup_additional_pages syscall32_setup_pages
10549
10550 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10551 -#define arch_randomize_brk arch_randomize_brk
10552 -
10553 /*
10554 * True on X86_32 or when emulating IA32 on X86_64
10555 */
10556 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10557 index 75ce3f4..882e801 100644
10558 --- a/arch/x86/include/asm/emergency-restart.h
10559 +++ b/arch/x86/include/asm/emergency-restart.h
10560 @@ -13,6 +13,6 @@ enum reboot_type {
10561
10562 extern enum reboot_type reboot_type;
10563
10564 -extern void machine_emergency_restart(void);
10565 +extern void machine_emergency_restart(void) __noreturn;
10566
10567 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10568 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10569 index 75f4c6d..ee3eb8f 100644
10570 --- a/arch/x86/include/asm/fpu-internal.h
10571 +++ b/arch/x86/include/asm/fpu-internal.h
10572 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10573 {
10574 int err;
10575
10576 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10577 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10578 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10579 +#endif
10580 +
10581 /* See comment in fxsave() below. */
10582 #ifdef CONFIG_AS_FXSAVEQ
10583 asm volatile("1: fxrstorq %[fx]\n\t"
10584 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10585 {
10586 int err;
10587
10588 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10589 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10590 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10591 +#endif
10592 +
10593 /*
10594 * Clear the bytes not touched by the fxsave and reserved
10595 * for the SW usage.
10596 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10597 "emms\n\t" /* clear stack tags */
10598 "fildl %P[addr]", /* set F?P to defined value */
10599 X86_FEATURE_FXSAVE_LEAK,
10600 - [addr] "m" (tsk->thread.fpu.has_fpu));
10601 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10602
10603 return fpu_restore_checking(&tsk->thread.fpu);
10604 }
10605 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10606 index 71ecbcb..bac10b7 100644
10607 --- a/arch/x86/include/asm/futex.h
10608 +++ b/arch/x86/include/asm/futex.h
10609 @@ -11,16 +11,18 @@
10610 #include <asm/processor.h>
10611
10612 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10613 + typecheck(u32 __user *, uaddr); \
10614 asm volatile("1:\t" insn "\n" \
10615 "2:\t.section .fixup,\"ax\"\n" \
10616 "3:\tmov\t%3, %1\n" \
10617 "\tjmp\t2b\n" \
10618 "\t.previous\n" \
10619 _ASM_EXTABLE(1b, 3b) \
10620 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10621 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10622 : "i" (-EFAULT), "0" (oparg), "1" (0))
10623
10624 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10625 + typecheck(u32 __user *, uaddr); \
10626 asm volatile("1:\tmovl %2, %0\n" \
10627 "\tmovl\t%0, %3\n" \
10628 "\t" insn "\n" \
10629 @@ -33,7 +35,7 @@
10630 _ASM_EXTABLE(1b, 4b) \
10631 _ASM_EXTABLE(2b, 4b) \
10632 : "=&a" (oldval), "=&r" (ret), \
10633 - "+m" (*uaddr), "=&r" (tem) \
10634 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10635 : "r" (oparg), "i" (-EFAULT), "1" (0))
10636
10637 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10638 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10639
10640 switch (op) {
10641 case FUTEX_OP_SET:
10642 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10643 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10644 break;
10645 case FUTEX_OP_ADD:
10646 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10647 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10648 uaddr, oparg);
10649 break;
10650 case FUTEX_OP_OR:
10651 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10652 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10653 return -EFAULT;
10654
10655 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10656 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10657 "2:\t.section .fixup, \"ax\"\n"
10658 "3:\tmov %3, %0\n"
10659 "\tjmp 2b\n"
10660 "\t.previous\n"
10661 _ASM_EXTABLE(1b, 3b)
10662 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10663 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10664 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10665 : "memory"
10666 );
10667 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10668 index eb92a6e..b98b2f4 100644
10669 --- a/arch/x86/include/asm/hw_irq.h
10670 +++ b/arch/x86/include/asm/hw_irq.h
10671 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10672 extern void enable_IO_APIC(void);
10673
10674 /* Statistics */
10675 -extern atomic_t irq_err_count;
10676 -extern atomic_t irq_mis_count;
10677 +extern atomic_unchecked_t irq_err_count;
10678 +extern atomic_unchecked_t irq_mis_count;
10679
10680 /* EISA */
10681 extern void eisa_set_level_irq(unsigned int irq);
10682 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10683 index d8e8eef..99f81ae 100644
10684 --- a/arch/x86/include/asm/io.h
10685 +++ b/arch/x86/include/asm/io.h
10686 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10687
10688 #include <linux/vmalloc.h>
10689
10690 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10691 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10692 +{
10693 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10694 +}
10695 +
10696 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10697 +{
10698 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10699 +}
10700 +
10701 /*
10702 * Convert a virtual cached pointer to an uncached pointer
10703 */
10704 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10705 index bba3cf8..06bc8da 100644
10706 --- a/arch/x86/include/asm/irqflags.h
10707 +++ b/arch/x86/include/asm/irqflags.h
10708 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10709 sti; \
10710 sysexit
10711
10712 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10713 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10714 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10715 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10716 +
10717 #else
10718 #define INTERRUPT_RETURN iret
10719 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10720 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10721 index 5478825..839e88c 100644
10722 --- a/arch/x86/include/asm/kprobes.h
10723 +++ b/arch/x86/include/asm/kprobes.h
10724 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10725 #define RELATIVEJUMP_SIZE 5
10726 #define RELATIVECALL_OPCODE 0xe8
10727 #define RELATIVE_ADDR_SIZE 4
10728 -#define MAX_STACK_SIZE 64
10729 -#define MIN_STACK_SIZE(ADDR) \
10730 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10731 - THREAD_SIZE - (unsigned long)(ADDR))) \
10732 - ? (MAX_STACK_SIZE) \
10733 - : (((unsigned long)current_thread_info()) + \
10734 - THREAD_SIZE - (unsigned long)(ADDR)))
10735 +#define MAX_STACK_SIZE 64UL
10736 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10737
10738 #define flush_insn_slot(p) do { } while (0)
10739
10740 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10741 index 09155d6..d2e6df9 100644
10742 --- a/arch/x86/include/asm/kvm_host.h
10743 +++ b/arch/x86/include/asm/kvm_host.h
10744 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10745 int (*check_intercept)(struct kvm_vcpu *vcpu,
10746 struct x86_instruction_info *info,
10747 enum x86_intercept_stage stage);
10748 -};
10749 +} __do_const;
10750
10751 struct kvm_arch_async_pf {
10752 u32 token;
10753 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10754 index c8bed0d..e5721fa 100644
10755 --- a/arch/x86/include/asm/local.h
10756 +++ b/arch/x86/include/asm/local.h
10757 @@ -17,26 +17,58 @@ typedef struct {
10758
10759 static inline void local_inc(local_t *l)
10760 {
10761 - asm volatile(_ASM_INC "%0"
10762 + asm volatile(_ASM_INC "%0\n"
10763 +
10764 +#ifdef CONFIG_PAX_REFCOUNT
10765 + "jno 0f\n"
10766 + _ASM_DEC "%0\n"
10767 + "int $4\n0:\n"
10768 + _ASM_EXTABLE(0b, 0b)
10769 +#endif
10770 +
10771 : "+m" (l->a.counter));
10772 }
10773
10774 static inline void local_dec(local_t *l)
10775 {
10776 - asm volatile(_ASM_DEC "%0"
10777 + asm volatile(_ASM_DEC "%0\n"
10778 +
10779 +#ifdef CONFIG_PAX_REFCOUNT
10780 + "jno 0f\n"
10781 + _ASM_INC "%0\n"
10782 + "int $4\n0:\n"
10783 + _ASM_EXTABLE(0b, 0b)
10784 +#endif
10785 +
10786 : "+m" (l->a.counter));
10787 }
10788
10789 static inline void local_add(long i, local_t *l)
10790 {
10791 - asm volatile(_ASM_ADD "%1,%0"
10792 + asm volatile(_ASM_ADD "%1,%0\n"
10793 +
10794 +#ifdef CONFIG_PAX_REFCOUNT
10795 + "jno 0f\n"
10796 + _ASM_SUB "%1,%0\n"
10797 + "int $4\n0:\n"
10798 + _ASM_EXTABLE(0b, 0b)
10799 +#endif
10800 +
10801 : "+m" (l->a.counter)
10802 : "ir" (i));
10803 }
10804
10805 static inline void local_sub(long i, local_t *l)
10806 {
10807 - asm volatile(_ASM_SUB "%1,%0"
10808 + asm volatile(_ASM_SUB "%1,%0\n"
10809 +
10810 +#ifdef CONFIG_PAX_REFCOUNT
10811 + "jno 0f\n"
10812 + _ASM_ADD "%1,%0\n"
10813 + "int $4\n0:\n"
10814 + _ASM_EXTABLE(0b, 0b)
10815 +#endif
10816 +
10817 : "+m" (l->a.counter)
10818 : "ir" (i));
10819 }
10820 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10821 {
10822 unsigned char c;
10823
10824 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10825 + asm volatile(_ASM_SUB "%2,%0\n"
10826 +
10827 +#ifdef CONFIG_PAX_REFCOUNT
10828 + "jno 0f\n"
10829 + _ASM_ADD "%2,%0\n"
10830 + "int $4\n0:\n"
10831 + _ASM_EXTABLE(0b, 0b)
10832 +#endif
10833 +
10834 + "sete %1\n"
10835 : "+m" (l->a.counter), "=qm" (c)
10836 : "ir" (i) : "memory");
10837 return c;
10838 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10839 {
10840 unsigned char c;
10841
10842 - asm volatile(_ASM_DEC "%0; sete %1"
10843 + asm volatile(_ASM_DEC "%0\n"
10844 +
10845 +#ifdef CONFIG_PAX_REFCOUNT
10846 + "jno 0f\n"
10847 + _ASM_INC "%0\n"
10848 + "int $4\n0:\n"
10849 + _ASM_EXTABLE(0b, 0b)
10850 +#endif
10851 +
10852 + "sete %1\n"
10853 : "+m" (l->a.counter), "=qm" (c)
10854 : : "memory");
10855 return c != 0;
10856 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10857 {
10858 unsigned char c;
10859
10860 - asm volatile(_ASM_INC "%0; sete %1"
10861 + asm volatile(_ASM_INC "%0\n"
10862 +
10863 +#ifdef CONFIG_PAX_REFCOUNT
10864 + "jno 0f\n"
10865 + _ASM_DEC "%0\n"
10866 + "int $4\n0:\n"
10867 + _ASM_EXTABLE(0b, 0b)
10868 +#endif
10869 +
10870 + "sete %1\n"
10871 : "+m" (l->a.counter), "=qm" (c)
10872 : : "memory");
10873 return c != 0;
10874 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10875 {
10876 unsigned char c;
10877
10878 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10879 + asm volatile(_ASM_ADD "%2,%0\n"
10880 +
10881 +#ifdef CONFIG_PAX_REFCOUNT
10882 + "jno 0f\n"
10883 + _ASM_SUB "%2,%0\n"
10884 + "int $4\n0:\n"
10885 + _ASM_EXTABLE(0b, 0b)
10886 +#endif
10887 +
10888 + "sets %1\n"
10889 : "+m" (l->a.counter), "=qm" (c)
10890 : "ir" (i) : "memory");
10891 return c;
10892 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10893 #endif
10894 /* Modern 486+ processor */
10895 __i = i;
10896 - asm volatile(_ASM_XADD "%0, %1;"
10897 + asm volatile(_ASM_XADD "%0, %1\n"
10898 +
10899 +#ifdef CONFIG_PAX_REFCOUNT
10900 + "jno 0f\n"
10901 + _ASM_MOV "%0,%1\n"
10902 + "int $4\n0:\n"
10903 + _ASM_EXTABLE(0b, 0b)
10904 +#endif
10905 +
10906 : "+r" (i), "+m" (l->a.counter)
10907 : : "memory");
10908 return i + __i;
10909 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10910 index 593e51d..fa69c9a 100644
10911 --- a/arch/x86/include/asm/mman.h
10912 +++ b/arch/x86/include/asm/mman.h
10913 @@ -5,4 +5,14 @@
10914
10915 #include <asm-generic/mman.h>
10916
10917 +#ifdef __KERNEL__
10918 +#ifndef __ASSEMBLY__
10919 +#ifdef CONFIG_X86_32
10920 +#define arch_mmap_check i386_mmap_check
10921 +int i386_mmap_check(unsigned long addr, unsigned long len,
10922 + unsigned long flags);
10923 +#endif
10924 +#endif
10925 +#endif
10926 +
10927 #endif /* _ASM_X86_MMAN_H */
10928 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10929 index 5f55e69..e20bfb1 100644
10930 --- a/arch/x86/include/asm/mmu.h
10931 +++ b/arch/x86/include/asm/mmu.h
10932 @@ -9,7 +9,7 @@
10933 * we put the segment information here.
10934 */
10935 typedef struct {
10936 - void *ldt;
10937 + struct desc_struct *ldt;
10938 int size;
10939
10940 #ifdef CONFIG_X86_64
10941 @@ -18,7 +18,19 @@ typedef struct {
10942 #endif
10943
10944 struct mutex lock;
10945 - void *vdso;
10946 + unsigned long vdso;
10947 +
10948 +#ifdef CONFIG_X86_32
10949 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10950 + unsigned long user_cs_base;
10951 + unsigned long user_cs_limit;
10952 +
10953 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10954 + cpumask_t cpu_user_cs_mask;
10955 +#endif
10956 +
10957 +#endif
10958 +#endif
10959 } mm_context_t;
10960
10961 #ifdef CONFIG_SMP
10962 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10963 index cdbf367..adb37ac 100644
10964 --- a/arch/x86/include/asm/mmu_context.h
10965 +++ b/arch/x86/include/asm/mmu_context.h
10966 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10967
10968 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10969 {
10970 +
10971 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10972 + unsigned int i;
10973 + pgd_t *pgd;
10974 +
10975 + pax_open_kernel();
10976 + pgd = get_cpu_pgd(smp_processor_id());
10977 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10978 + set_pgd_batched(pgd+i, native_make_pgd(0));
10979 + pax_close_kernel();
10980 +#endif
10981 +
10982 #ifdef CONFIG_SMP
10983 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10984 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10985 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10986 struct task_struct *tsk)
10987 {
10988 unsigned cpu = smp_processor_id();
10989 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10990 + int tlbstate = TLBSTATE_OK;
10991 +#endif
10992
10993 if (likely(prev != next)) {
10994 #ifdef CONFIG_SMP
10995 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10996 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10997 +#endif
10998 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10999 this_cpu_write(cpu_tlbstate.active_mm, next);
11000 #endif
11001 cpumask_set_cpu(cpu, mm_cpumask(next));
11002
11003 /* Re-load page tables */
11004 +#ifdef CONFIG_PAX_PER_CPU_PGD
11005 + pax_open_kernel();
11006 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11007 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11008 + pax_close_kernel();
11009 + load_cr3(get_cpu_pgd(cpu));
11010 +#else
11011 load_cr3(next->pgd);
11012 +#endif
11013
11014 /* stop flush ipis for the previous mm */
11015 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11016 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11017 */
11018 if (unlikely(prev->context.ldt != next->context.ldt))
11019 load_LDT_nolock(&next->context);
11020 - }
11021 +
11022 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11023 + if (!(__supported_pte_mask & _PAGE_NX)) {
11024 + smp_mb__before_clear_bit();
11025 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11026 + smp_mb__after_clear_bit();
11027 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11028 + }
11029 +#endif
11030 +
11031 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11032 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11033 + prev->context.user_cs_limit != next->context.user_cs_limit))
11034 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11035 #ifdef CONFIG_SMP
11036 + else if (unlikely(tlbstate != TLBSTATE_OK))
11037 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11038 +#endif
11039 +#endif
11040 +
11041 + }
11042 else {
11043 +
11044 +#ifdef CONFIG_PAX_PER_CPU_PGD
11045 + pax_open_kernel();
11046 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11047 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11048 + pax_close_kernel();
11049 + load_cr3(get_cpu_pgd(cpu));
11050 +#endif
11051 +
11052 +#ifdef CONFIG_SMP
11053 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11054 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11055
11056 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11057 * tlb flush IPI delivery. We must reload CR3
11058 * to make sure to use no freed page tables.
11059 */
11060 +
11061 +#ifndef CONFIG_PAX_PER_CPU_PGD
11062 load_cr3(next->pgd);
11063 +#endif
11064 +
11065 load_LDT_nolock(&next->context);
11066 +
11067 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11068 + if (!(__supported_pte_mask & _PAGE_NX))
11069 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11070 +#endif
11071 +
11072 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11073 +#ifdef CONFIG_PAX_PAGEEXEC
11074 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11075 +#endif
11076 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11077 +#endif
11078 +
11079 }
11080 +#endif
11081 }
11082 -#endif
11083 }
11084
11085 #define activate_mm(prev, next) \
11086 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11087 index 9eae775..c914fea 100644
11088 --- a/arch/x86/include/asm/module.h
11089 +++ b/arch/x86/include/asm/module.h
11090 @@ -5,6 +5,7 @@
11091
11092 #ifdef CONFIG_X86_64
11093 /* X86_64 does not define MODULE_PROC_FAMILY */
11094 +#define MODULE_PROC_FAMILY ""
11095 #elif defined CONFIG_M386
11096 #define MODULE_PROC_FAMILY "386 "
11097 #elif defined CONFIG_M486
11098 @@ -59,8 +60,20 @@
11099 #error unknown processor family
11100 #endif
11101
11102 -#ifdef CONFIG_X86_32
11103 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11104 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11105 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11106 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11107 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11108 +#else
11109 +#define MODULE_PAX_KERNEXEC ""
11110 #endif
11111
11112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11113 +#define MODULE_PAX_UDEREF "UDEREF "
11114 +#else
11115 +#define MODULE_PAX_UDEREF ""
11116 +#endif
11117 +
11118 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11119 +
11120 #endif /* _ASM_X86_MODULE_H */
11121 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11122 index 320f7bb..e89f8f8 100644
11123 --- a/arch/x86/include/asm/page_64_types.h
11124 +++ b/arch/x86/include/asm/page_64_types.h
11125 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11126
11127 /* duplicated to the one in bootmem.h */
11128 extern unsigned long max_pfn;
11129 -extern unsigned long phys_base;
11130 +extern const unsigned long phys_base;
11131
11132 extern unsigned long __phys_addr(unsigned long);
11133 #define __phys_reloc_hide(x) (x)
11134 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11135 index a0facf3..c017b15 100644
11136 --- a/arch/x86/include/asm/paravirt.h
11137 +++ b/arch/x86/include/asm/paravirt.h
11138 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11139 val);
11140 }
11141
11142 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11143 +{
11144 + pgdval_t val = native_pgd_val(pgd);
11145 +
11146 + if (sizeof(pgdval_t) > sizeof(long))
11147 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11148 + val, (u64)val >> 32);
11149 + else
11150 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11151 + val);
11152 +}
11153 +
11154 static inline void pgd_clear(pgd_t *pgdp)
11155 {
11156 set_pgd(pgdp, __pgd(0));
11157 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11158 pv_mmu_ops.set_fixmap(idx, phys, flags);
11159 }
11160
11161 +#ifdef CONFIG_PAX_KERNEXEC
11162 +static inline unsigned long pax_open_kernel(void)
11163 +{
11164 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11165 +}
11166 +
11167 +static inline unsigned long pax_close_kernel(void)
11168 +{
11169 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11170 +}
11171 +#else
11172 +static inline unsigned long pax_open_kernel(void) { return 0; }
11173 +static inline unsigned long pax_close_kernel(void) { return 0; }
11174 +#endif
11175 +
11176 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11177
11178 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11179 @@ -929,7 +956,7 @@ extern void default_banner(void);
11180
11181 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11182 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11183 -#define PARA_INDIRECT(addr) *%cs:addr
11184 +#define PARA_INDIRECT(addr) *%ss:addr
11185 #endif
11186
11187 #define INTERRUPT_RETURN \
11188 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11189 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11190 CLBR_NONE, \
11191 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11192 +
11193 +#define GET_CR0_INTO_RDI \
11194 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11195 + mov %rax,%rdi
11196 +
11197 +#define SET_RDI_INTO_CR0 \
11198 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11199 +
11200 +#define GET_CR3_INTO_RDI \
11201 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11202 + mov %rax,%rdi
11203 +
11204 +#define SET_RDI_INTO_CR3 \
11205 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11206 +
11207 #endif /* CONFIG_X86_32 */
11208
11209 #endif /* __ASSEMBLY__ */
11210 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11211 index 142236e..6a6b4a6 100644
11212 --- a/arch/x86/include/asm/paravirt_types.h
11213 +++ b/arch/x86/include/asm/paravirt_types.h
11214 @@ -84,20 +84,20 @@ struct pv_init_ops {
11215 */
11216 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11217 unsigned long addr, unsigned len);
11218 -};
11219 +} __no_const;
11220
11221
11222 struct pv_lazy_ops {
11223 /* Set deferred update mode, used for batching operations. */
11224 void (*enter)(void);
11225 void (*leave)(void);
11226 -};
11227 +} __no_const;
11228
11229 struct pv_time_ops {
11230 unsigned long long (*sched_clock)(void);
11231 unsigned long long (*steal_clock)(int cpu);
11232 unsigned long (*get_tsc_khz)(void);
11233 -};
11234 +} __no_const;
11235
11236 struct pv_cpu_ops {
11237 /* hooks for various privileged instructions */
11238 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11239
11240 void (*start_context_switch)(struct task_struct *prev);
11241 void (*end_context_switch)(struct task_struct *next);
11242 -};
11243 +} __no_const;
11244
11245 struct pv_irq_ops {
11246 /*
11247 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11248 unsigned long start_eip,
11249 unsigned long start_esp);
11250 #endif
11251 -};
11252 +} __no_const;
11253
11254 struct pv_mmu_ops {
11255 unsigned long (*read_cr2)(void);
11256 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11257 struct paravirt_callee_save make_pud;
11258
11259 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11260 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11261 #endif /* PAGETABLE_LEVELS == 4 */
11262 #endif /* PAGETABLE_LEVELS >= 3 */
11263
11264 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11265 an mfn. We can tell which is which from the index. */
11266 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11267 phys_addr_t phys, pgprot_t flags);
11268 +
11269 +#ifdef CONFIG_PAX_KERNEXEC
11270 + unsigned long (*pax_open_kernel)(void);
11271 + unsigned long (*pax_close_kernel)(void);
11272 +#endif
11273 +
11274 };
11275
11276 struct arch_spinlock;
11277 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11278 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11279 int (*spin_trylock)(struct arch_spinlock *lock);
11280 void (*spin_unlock)(struct arch_spinlock *lock);
11281 -};
11282 +} __no_const;
11283
11284 /* This contains all the paravirt structures: we get a convenient
11285 * number for each function using the offset which we use to indicate
11286 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11287 index b4389a4..7024269 100644
11288 --- a/arch/x86/include/asm/pgalloc.h
11289 +++ b/arch/x86/include/asm/pgalloc.h
11290 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11291 pmd_t *pmd, pte_t *pte)
11292 {
11293 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11294 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11295 +}
11296 +
11297 +static inline void pmd_populate_user(struct mm_struct *mm,
11298 + pmd_t *pmd, pte_t *pte)
11299 +{
11300 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11301 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11302 }
11303
11304 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11305
11306 #ifdef CONFIG_X86_PAE
11307 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11308 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11309 +{
11310 + pud_populate(mm, pudp, pmd);
11311 +}
11312 #else /* !CONFIG_X86_PAE */
11313 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11314 {
11315 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11316 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11317 }
11318 +
11319 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11320 +{
11321 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11322 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11323 +}
11324 #endif /* CONFIG_X86_PAE */
11325
11326 #if PAGETABLE_LEVELS > 3
11327 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11328 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11329 }
11330
11331 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11332 +{
11333 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11334 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11335 +}
11336 +
11337 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11338 {
11339 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11340 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11341 index f2b489c..4f7e2e5 100644
11342 --- a/arch/x86/include/asm/pgtable-2level.h
11343 +++ b/arch/x86/include/asm/pgtable-2level.h
11344 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11345
11346 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11347 {
11348 + pax_open_kernel();
11349 *pmdp = pmd;
11350 + pax_close_kernel();
11351 }
11352
11353 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11354 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11355 index 4cc9f2b..5fd9226 100644
11356 --- a/arch/x86/include/asm/pgtable-3level.h
11357 +++ b/arch/x86/include/asm/pgtable-3level.h
11358 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11359
11360 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11361 {
11362 + pax_open_kernel();
11363 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11364 + pax_close_kernel();
11365 }
11366
11367 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11368 {
11369 + pax_open_kernel();
11370 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11371 + pax_close_kernel();
11372 }
11373
11374 /*
11375 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11376 index c3520d7..cf742ef 100644
11377 --- a/arch/x86/include/asm/pgtable.h
11378 +++ b/arch/x86/include/asm/pgtable.h
11379 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11380
11381 #ifndef __PAGETABLE_PUD_FOLDED
11382 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11383 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11384 #define pgd_clear(pgd) native_pgd_clear(pgd)
11385 #endif
11386
11387 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11388
11389 #define arch_end_context_switch(prev) do {} while(0)
11390
11391 +#define pax_open_kernel() native_pax_open_kernel()
11392 +#define pax_close_kernel() native_pax_close_kernel()
11393 #endif /* CONFIG_PARAVIRT */
11394
11395 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11396 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11397 +
11398 +#ifdef CONFIG_PAX_KERNEXEC
11399 +static inline unsigned long native_pax_open_kernel(void)
11400 +{
11401 + unsigned long cr0;
11402 +
11403 + preempt_disable();
11404 + barrier();
11405 + cr0 = read_cr0() ^ X86_CR0_WP;
11406 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11407 + write_cr0(cr0);
11408 + return cr0 ^ X86_CR0_WP;
11409 +}
11410 +
11411 +static inline unsigned long native_pax_close_kernel(void)
11412 +{
11413 + unsigned long cr0;
11414 +
11415 + cr0 = read_cr0() ^ X86_CR0_WP;
11416 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11417 + write_cr0(cr0);
11418 + barrier();
11419 + preempt_enable_no_resched();
11420 + return cr0 ^ X86_CR0_WP;
11421 +}
11422 +#else
11423 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11424 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11425 +#endif
11426 +
11427 /*
11428 * The following only work if pte_present() is true.
11429 * Undefined behaviour if not..
11430 */
11431 +static inline int pte_user(pte_t pte)
11432 +{
11433 + return pte_val(pte) & _PAGE_USER;
11434 +}
11435 +
11436 static inline int pte_dirty(pte_t pte)
11437 {
11438 return pte_flags(pte) & _PAGE_DIRTY;
11439 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11440 return pte_clear_flags(pte, _PAGE_RW);
11441 }
11442
11443 +static inline pte_t pte_mkread(pte_t pte)
11444 +{
11445 + return __pte(pte_val(pte) | _PAGE_USER);
11446 +}
11447 +
11448 static inline pte_t pte_mkexec(pte_t pte)
11449 {
11450 - return pte_clear_flags(pte, _PAGE_NX);
11451 +#ifdef CONFIG_X86_PAE
11452 + if (__supported_pte_mask & _PAGE_NX)
11453 + return pte_clear_flags(pte, _PAGE_NX);
11454 + else
11455 +#endif
11456 + return pte_set_flags(pte, _PAGE_USER);
11457 +}
11458 +
11459 +static inline pte_t pte_exprotect(pte_t pte)
11460 +{
11461 +#ifdef CONFIG_X86_PAE
11462 + if (__supported_pte_mask & _PAGE_NX)
11463 + return pte_set_flags(pte, _PAGE_NX);
11464 + else
11465 +#endif
11466 + return pte_clear_flags(pte, _PAGE_USER);
11467 }
11468
11469 static inline pte_t pte_mkdirty(pte_t pte)
11470 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11471 #endif
11472
11473 #ifndef __ASSEMBLY__
11474 +
11475 +#ifdef CONFIG_PAX_PER_CPU_PGD
11476 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11477 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11478 +{
11479 + return cpu_pgd[cpu];
11480 +}
11481 +#endif
11482 +
11483 #include <linux/mm_types.h>
11484
11485 static inline int pte_none(pte_t pte)
11486 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11487
11488 static inline int pgd_bad(pgd_t pgd)
11489 {
11490 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11491 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11492 }
11493
11494 static inline int pgd_none(pgd_t pgd)
11495 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11496 * pgd_offset() returns a (pgd_t *)
11497 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11498 */
11499 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11500 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11501 +
11502 +#ifdef CONFIG_PAX_PER_CPU_PGD
11503 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11504 +#endif
11505 +
11506 /*
11507 * a shortcut which implies the use of the kernel's pgd, instead
11508 * of a process's
11509 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11510 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11511 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11512
11513 +#ifdef CONFIG_X86_32
11514 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11515 +#else
11516 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11517 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11518 +
11519 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11520 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11521 +#else
11522 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11523 +#endif
11524 +
11525 +#endif
11526 +
11527 #ifndef __ASSEMBLY__
11528
11529 extern int direct_gbpages;
11530 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11531 * dst and src can be on the same page, but the range must not overlap,
11532 * and must not cross a page boundary.
11533 */
11534 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11535 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11536 {
11537 - memcpy(dst, src, count * sizeof(pgd_t));
11538 + pax_open_kernel();
11539 + while (count--)
11540 + *dst++ = *src++;
11541 + pax_close_kernel();
11542 }
11543
11544 +#ifdef CONFIG_PAX_PER_CPU_PGD
11545 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11546 +#endif
11547 +
11548 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11549 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11550 +#else
11551 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11552 +#endif
11553
11554 #include <asm-generic/pgtable.h>
11555 #endif /* __ASSEMBLY__ */
11556 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11557 index 0c92113..34a77c6 100644
11558 --- a/arch/x86/include/asm/pgtable_32.h
11559 +++ b/arch/x86/include/asm/pgtable_32.h
11560 @@ -25,9 +25,6 @@
11561 struct mm_struct;
11562 struct vm_area_struct;
11563
11564 -extern pgd_t swapper_pg_dir[1024];
11565 -extern pgd_t initial_page_table[1024];
11566 -
11567 static inline void pgtable_cache_init(void) { }
11568 static inline void check_pgt_cache(void) { }
11569 void paging_init(void);
11570 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11571 # include <asm/pgtable-2level.h>
11572 #endif
11573
11574 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11575 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11576 +#ifdef CONFIG_X86_PAE
11577 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11578 +#endif
11579 +
11580 #if defined(CONFIG_HIGHPTE)
11581 #define pte_offset_map(dir, address) \
11582 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11583 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11584 /* Clear a kernel PTE and flush it from the TLB */
11585 #define kpte_clear_flush(ptep, vaddr) \
11586 do { \
11587 + pax_open_kernel(); \
11588 pte_clear(&init_mm, (vaddr), (ptep)); \
11589 + pax_close_kernel(); \
11590 __flush_tlb_one((vaddr)); \
11591 } while (0)
11592
11593 @@ -74,6 +79,9 @@ do { \
11594
11595 #endif /* !__ASSEMBLY__ */
11596
11597 +#define HAVE_ARCH_UNMAPPED_AREA
11598 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11599 +
11600 /*
11601 * kern_addr_valid() is (1) for FLATMEM and (0) for
11602 * SPARSEMEM and DISCONTIGMEM
11603 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11604 index ed5903b..c7fe163 100644
11605 --- a/arch/x86/include/asm/pgtable_32_types.h
11606 +++ b/arch/x86/include/asm/pgtable_32_types.h
11607 @@ -8,7 +8,7 @@
11608 */
11609 #ifdef CONFIG_X86_PAE
11610 # include <asm/pgtable-3level_types.h>
11611 -# define PMD_SIZE (1UL << PMD_SHIFT)
11612 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11613 # define PMD_MASK (~(PMD_SIZE - 1))
11614 #else
11615 # include <asm/pgtable-2level_types.h>
11616 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11617 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11618 #endif
11619
11620 +#ifdef CONFIG_PAX_KERNEXEC
11621 +#ifndef __ASSEMBLY__
11622 +extern unsigned char MODULES_EXEC_VADDR[];
11623 +extern unsigned char MODULES_EXEC_END[];
11624 +#endif
11625 +#include <asm/boot.h>
11626 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11627 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11628 +#else
11629 +#define ktla_ktva(addr) (addr)
11630 +#define ktva_ktla(addr) (addr)
11631 +#endif
11632 +
11633 #define MODULES_VADDR VMALLOC_START
11634 #define MODULES_END VMALLOC_END
11635 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11636 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11637 index 8251be0..4ea8b46 100644
11638 --- a/arch/x86/include/asm/pgtable_64.h
11639 +++ b/arch/x86/include/asm/pgtable_64.h
11640 @@ -16,10 +16,14 @@
11641
11642 extern pud_t level3_kernel_pgt[512];
11643 extern pud_t level3_ident_pgt[512];
11644 +extern pud_t level3_vmalloc_start_pgt[512];
11645 +extern pud_t level3_vmalloc_end_pgt[512];
11646 +extern pud_t level3_vmemmap_pgt[512];
11647 +extern pud_t level2_vmemmap_pgt[512];
11648 extern pmd_t level2_kernel_pgt[512];
11649 extern pmd_t level2_fixmap_pgt[512];
11650 -extern pmd_t level2_ident_pgt[512];
11651 -extern pgd_t init_level4_pgt[];
11652 +extern pmd_t level2_ident_pgt[512*2];
11653 +extern pgd_t init_level4_pgt[512];
11654
11655 #define swapper_pg_dir init_level4_pgt
11656
11657 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11658
11659 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11660 {
11661 + pax_open_kernel();
11662 *pmdp = pmd;
11663 + pax_close_kernel();
11664 }
11665
11666 static inline void native_pmd_clear(pmd_t *pmd)
11667 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11668
11669 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11670 {
11671 + pax_open_kernel();
11672 *pudp = pud;
11673 + pax_close_kernel();
11674 }
11675
11676 static inline void native_pud_clear(pud_t *pud)
11677 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11678
11679 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11680 {
11681 + pax_open_kernel();
11682 + *pgdp = pgd;
11683 + pax_close_kernel();
11684 +}
11685 +
11686 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11687 +{
11688 *pgdp = pgd;
11689 }
11690
11691 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11692 index 766ea16..5b96cb3 100644
11693 --- a/arch/x86/include/asm/pgtable_64_types.h
11694 +++ b/arch/x86/include/asm/pgtable_64_types.h
11695 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11696 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11697 #define MODULES_END _AC(0xffffffffff000000, UL)
11698 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11699 +#define MODULES_EXEC_VADDR MODULES_VADDR
11700 +#define MODULES_EXEC_END MODULES_END
11701 +
11702 +#define ktla_ktva(addr) (addr)
11703 +#define ktva_ktla(addr) (addr)
11704
11705 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11706 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11707 index 013286a..8b42f4f 100644
11708 --- a/arch/x86/include/asm/pgtable_types.h
11709 +++ b/arch/x86/include/asm/pgtable_types.h
11710 @@ -16,13 +16,12 @@
11711 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11712 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11713 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11714 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11715 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11716 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11717 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11718 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11719 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11720 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11721 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11722 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11723 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11724 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11725
11726 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11727 @@ -40,7 +39,6 @@
11728 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11729 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11730 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11731 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11732 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11733 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11734 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11735 @@ -57,8 +55,10 @@
11736
11737 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11738 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11739 -#else
11740 +#elif defined(CONFIG_KMEMCHECK)
11741 #define _PAGE_NX (_AT(pteval_t, 0))
11742 +#else
11743 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11744 #endif
11745
11746 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11747 @@ -96,6 +96,9 @@
11748 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11749 _PAGE_ACCESSED)
11750
11751 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11752 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11753 +
11754 #define __PAGE_KERNEL_EXEC \
11755 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11756 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11757 @@ -106,7 +109,7 @@
11758 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11759 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11760 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11761 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11762 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11763 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11764 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11765 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11766 @@ -168,8 +171,8 @@
11767 * bits are combined, this will alow user to access the high address mapped
11768 * VDSO in the presence of CONFIG_COMPAT_VDSO
11769 */
11770 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11771 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11772 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11773 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11774 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11775 #endif
11776
11777 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11778 {
11779 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11780 }
11781 +#endif
11782
11783 +#if PAGETABLE_LEVELS == 3
11784 +#include <asm-generic/pgtable-nopud.h>
11785 +#endif
11786 +
11787 +#if PAGETABLE_LEVELS == 2
11788 +#include <asm-generic/pgtable-nopmd.h>
11789 +#endif
11790 +
11791 +#ifndef __ASSEMBLY__
11792 #if PAGETABLE_LEVELS > 3
11793 typedef struct { pudval_t pud; } pud_t;
11794
11795 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11796 return pud.pud;
11797 }
11798 #else
11799 -#include <asm-generic/pgtable-nopud.h>
11800 -
11801 static inline pudval_t native_pud_val(pud_t pud)
11802 {
11803 return native_pgd_val(pud.pgd);
11804 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11805 return pmd.pmd;
11806 }
11807 #else
11808 -#include <asm-generic/pgtable-nopmd.h>
11809 -
11810 static inline pmdval_t native_pmd_val(pmd_t pmd)
11811 {
11812 return native_pgd_val(pmd.pud.pgd);
11813 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11814
11815 extern pteval_t __supported_pte_mask;
11816 extern void set_nx(void);
11817 -extern int nx_enabled;
11818
11819 #define pgprot_writecombine pgprot_writecombine
11820 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11821 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11822 index aea1d1d..680cf09 100644
11823 --- a/arch/x86/include/asm/processor-flags.h
11824 +++ b/arch/x86/include/asm/processor-flags.h
11825 @@ -65,6 +65,7 @@
11826 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11827 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11828 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11829 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11830
11831 /*
11832 * x86-64 Task Priority Register, CR8
11833 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11834 index d048cad..45e350f 100644
11835 --- a/arch/x86/include/asm/processor.h
11836 +++ b/arch/x86/include/asm/processor.h
11837 @@ -289,7 +289,7 @@ struct tss_struct {
11838
11839 } ____cacheline_aligned;
11840
11841 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11842 +extern struct tss_struct init_tss[NR_CPUS];
11843
11844 /*
11845 * Save the original ist values for checking stack pointers during debugging
11846 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11847 */
11848 #define TASK_SIZE PAGE_OFFSET
11849 #define TASK_SIZE_MAX TASK_SIZE
11850 +
11851 +#ifdef CONFIG_PAX_SEGMEXEC
11852 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11853 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11854 +#else
11855 #define STACK_TOP TASK_SIZE
11856 -#define STACK_TOP_MAX STACK_TOP
11857 +#endif
11858 +
11859 +#define STACK_TOP_MAX TASK_SIZE
11860
11861 #define INIT_THREAD { \
11862 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11863 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11864 .vm86_info = NULL, \
11865 .sysenter_cs = __KERNEL_CS, \
11866 .io_bitmap_ptr = NULL, \
11867 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11868 */
11869 #define INIT_TSS { \
11870 .x86_tss = { \
11871 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11872 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11873 .ss0 = __KERNEL_DS, \
11874 .ss1 = __KERNEL_CS, \
11875 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11876 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11877 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11878
11879 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11880 -#define KSTK_TOP(info) \
11881 -({ \
11882 - unsigned long *__ptr = (unsigned long *)(info); \
11883 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11884 -})
11885 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11886
11887 /*
11888 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11889 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11890 #define task_pt_regs(task) \
11891 ({ \
11892 struct pt_regs *__regs__; \
11893 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11894 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11895 __regs__ - 1; \
11896 })
11897
11898 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11899 /*
11900 * User space process size. 47bits minus one guard page.
11901 */
11902 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11903 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11904
11905 /* This decides where the kernel will search for a free chunk of vm
11906 * space during mmap's.
11907 */
11908 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11909 - 0xc0000000 : 0xFFFFe000)
11910 + 0xc0000000 : 0xFFFFf000)
11911
11912 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11913 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11914 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11915 #define STACK_TOP_MAX TASK_SIZE_MAX
11916
11917 #define INIT_THREAD { \
11918 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11919 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11920 }
11921
11922 #define INIT_TSS { \
11923 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11924 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11925 }
11926
11927 /*
11928 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11929 */
11930 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11931
11932 +#ifdef CONFIG_PAX_SEGMEXEC
11933 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11934 +#endif
11935 +
11936 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11937
11938 /* Get/set a process' ability to use the timestamp counter instruction */
11939 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11940 #define cpu_has_amd_erratum(x) (false)
11941 #endif /* CONFIG_CPU_SUP_AMD */
11942
11943 -extern unsigned long arch_align_stack(unsigned long sp);
11944 +#define arch_align_stack(x) ((x) & ~0xfUL)
11945 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11946
11947 void default_idle(void);
11948 bool set_pm_idle_to_default(void);
11949
11950 -void stop_this_cpu(void *dummy);
11951 +void stop_this_cpu(void *dummy) __noreturn;
11952
11953 #endif /* _ASM_X86_PROCESSOR_H */
11954 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11955 index dcfde52..dbfea06 100644
11956 --- a/arch/x86/include/asm/ptrace.h
11957 +++ b/arch/x86/include/asm/ptrace.h
11958 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11959 }
11960
11961 /*
11962 - * user_mode_vm(regs) determines whether a register set came from user mode.
11963 + * user_mode(regs) determines whether a register set came from user mode.
11964 * This is true if V8086 mode was enabled OR if the register set was from
11965 * protected mode with RPL-3 CS value. This tricky test checks that with
11966 * one comparison. Many places in the kernel can bypass this full check
11967 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11968 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11969 + * be used.
11970 */
11971 -static inline int user_mode(struct pt_regs *regs)
11972 +static inline int user_mode_novm(struct pt_regs *regs)
11973 {
11974 #ifdef CONFIG_X86_32
11975 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11976 #else
11977 - return !!(regs->cs & 3);
11978 + return !!(regs->cs & SEGMENT_RPL_MASK);
11979 #endif
11980 }
11981
11982 -static inline int user_mode_vm(struct pt_regs *regs)
11983 +static inline int user_mode(struct pt_regs *regs)
11984 {
11985 #ifdef CONFIG_X86_32
11986 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11987 USER_RPL;
11988 #else
11989 - return user_mode(regs);
11990 + return user_mode_novm(regs);
11991 #endif
11992 }
11993
11994 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11995 #ifdef CONFIG_X86_64
11996 static inline bool user_64bit_mode(struct pt_regs *regs)
11997 {
11998 + unsigned long cs = regs->cs & 0xffff;
11999 #ifndef CONFIG_PARAVIRT
12000 /*
12001 * On non-paravirt systems, this is the only long mode CPL 3
12002 * selector. We do not allow long mode selectors in the LDT.
12003 */
12004 - return regs->cs == __USER_CS;
12005 + return cs == __USER_CS;
12006 #else
12007 /* Headers are too twisted for this to go in paravirt.h. */
12008 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12009 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12010 #endif
12011 }
12012 #endif
12013 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12014 index fe1ec5b..dc5c3fe 100644
12015 --- a/arch/x86/include/asm/realmode.h
12016 +++ b/arch/x86/include/asm/realmode.h
12017 @@ -22,16 +22,14 @@ struct real_mode_header {
12018 #endif
12019 /* APM/BIOS reboot */
12020 u32 machine_real_restart_asm;
12021 -#ifdef CONFIG_X86_64
12022 u32 machine_real_restart_seg;
12023 -#endif
12024 };
12025
12026 /* This must match data at trampoline_32/64.S */
12027 struct trampoline_header {
12028 #ifdef CONFIG_X86_32
12029 u32 start;
12030 - u16 gdt_pad;
12031 + u16 boot_cs;
12032 u16 gdt_limit;
12033 u32 gdt_base;
12034 #else
12035 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12036 index a82c4f1..ac45053 100644
12037 --- a/arch/x86/include/asm/reboot.h
12038 +++ b/arch/x86/include/asm/reboot.h
12039 @@ -6,13 +6,13 @@
12040 struct pt_regs;
12041
12042 struct machine_ops {
12043 - void (*restart)(char *cmd);
12044 - void (*halt)(void);
12045 - void (*power_off)(void);
12046 + void (* __noreturn restart)(char *cmd);
12047 + void (* __noreturn halt)(void);
12048 + void (* __noreturn power_off)(void);
12049 void (*shutdown)(void);
12050 void (*crash_shutdown)(struct pt_regs *);
12051 - void (*emergency_restart)(void);
12052 -};
12053 + void (* __noreturn emergency_restart)(void);
12054 +} __no_const;
12055
12056 extern struct machine_ops machine_ops;
12057
12058 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12059 index 2dbe4a7..ce1db00 100644
12060 --- a/arch/x86/include/asm/rwsem.h
12061 +++ b/arch/x86/include/asm/rwsem.h
12062 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12063 {
12064 asm volatile("# beginning down_read\n\t"
12065 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12066 +
12067 +#ifdef CONFIG_PAX_REFCOUNT
12068 + "jno 0f\n"
12069 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12070 + "int $4\n0:\n"
12071 + _ASM_EXTABLE(0b, 0b)
12072 +#endif
12073 +
12074 /* adds 0x00000001 */
12075 " jns 1f\n"
12076 " call call_rwsem_down_read_failed\n"
12077 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12078 "1:\n\t"
12079 " mov %1,%2\n\t"
12080 " add %3,%2\n\t"
12081 +
12082 +#ifdef CONFIG_PAX_REFCOUNT
12083 + "jno 0f\n"
12084 + "sub %3,%2\n"
12085 + "int $4\n0:\n"
12086 + _ASM_EXTABLE(0b, 0b)
12087 +#endif
12088 +
12089 " jle 2f\n\t"
12090 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12091 " jnz 1b\n\t"
12092 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12093 long tmp;
12094 asm volatile("# beginning down_write\n\t"
12095 LOCK_PREFIX " xadd %1,(%2)\n\t"
12096 +
12097 +#ifdef CONFIG_PAX_REFCOUNT
12098 + "jno 0f\n"
12099 + "mov %1,(%2)\n"
12100 + "int $4\n0:\n"
12101 + _ASM_EXTABLE(0b, 0b)
12102 +#endif
12103 +
12104 /* adds 0xffff0001, returns the old value */
12105 " test %1,%1\n\t"
12106 /* was the count 0 before? */
12107 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12108 long tmp;
12109 asm volatile("# beginning __up_read\n\t"
12110 LOCK_PREFIX " xadd %1,(%2)\n\t"
12111 +
12112 +#ifdef CONFIG_PAX_REFCOUNT
12113 + "jno 0f\n"
12114 + "mov %1,(%2)\n"
12115 + "int $4\n0:\n"
12116 + _ASM_EXTABLE(0b, 0b)
12117 +#endif
12118 +
12119 /* subtracts 1, returns the old value */
12120 " jns 1f\n\t"
12121 " call call_rwsem_wake\n" /* expects old value in %edx */
12122 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12123 long tmp;
12124 asm volatile("# beginning __up_write\n\t"
12125 LOCK_PREFIX " xadd %1,(%2)\n\t"
12126 +
12127 +#ifdef CONFIG_PAX_REFCOUNT
12128 + "jno 0f\n"
12129 + "mov %1,(%2)\n"
12130 + "int $4\n0:\n"
12131 + _ASM_EXTABLE(0b, 0b)
12132 +#endif
12133 +
12134 /* subtracts 0xffff0001, returns the old value */
12135 " jns 1f\n\t"
12136 " call call_rwsem_wake\n" /* expects old value in %edx */
12137 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12138 {
12139 asm volatile("# beginning __downgrade_write\n\t"
12140 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12141 +
12142 +#ifdef CONFIG_PAX_REFCOUNT
12143 + "jno 0f\n"
12144 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12145 + "int $4\n0:\n"
12146 + _ASM_EXTABLE(0b, 0b)
12147 +#endif
12148 +
12149 /*
12150 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12151 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12152 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12153 */
12154 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12155 {
12156 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12157 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12158 +
12159 +#ifdef CONFIG_PAX_REFCOUNT
12160 + "jno 0f\n"
12161 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12162 + "int $4\n0:\n"
12163 + _ASM_EXTABLE(0b, 0b)
12164 +#endif
12165 +
12166 : "+m" (sem->count)
12167 : "er" (delta));
12168 }
12169 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12170 */
12171 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12172 {
12173 - return delta + xadd(&sem->count, delta);
12174 + return delta + xadd_check_overflow(&sem->count, delta);
12175 }
12176
12177 #endif /* __KERNEL__ */
12178 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12179 index c48a950..c6d7468 100644
12180 --- a/arch/x86/include/asm/segment.h
12181 +++ b/arch/x86/include/asm/segment.h
12182 @@ -64,10 +64,15 @@
12183 * 26 - ESPFIX small SS
12184 * 27 - per-cpu [ offset to per-cpu data area ]
12185 * 28 - stack_canary-20 [ for stack protector ]
12186 - * 29 - unused
12187 - * 30 - unused
12188 + * 29 - PCI BIOS CS
12189 + * 30 - PCI BIOS DS
12190 * 31 - TSS for double fault handler
12191 */
12192 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12193 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12194 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12195 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12196 +
12197 #define GDT_ENTRY_TLS_MIN 6
12198 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12199
12200 @@ -79,6 +84,8 @@
12201
12202 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12203
12204 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12205 +
12206 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12207
12208 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12209 @@ -104,6 +111,12 @@
12210 #define __KERNEL_STACK_CANARY 0
12211 #endif
12212
12213 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12214 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12215 +
12216 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12217 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12218 +
12219 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12220
12221 /*
12222 @@ -141,7 +154,7 @@
12223 */
12224
12225 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12226 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12227 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12228
12229
12230 #else
12231 @@ -165,6 +178,8 @@
12232 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12233 #define __USER32_DS __USER_DS
12234
12235 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12236 +
12237 #define GDT_ENTRY_TSS 8 /* needs two entries */
12238 #define GDT_ENTRY_LDT 10 /* needs two entries */
12239 #define GDT_ENTRY_TLS_MIN 12
12240 @@ -185,6 +200,7 @@
12241 #endif
12242
12243 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12244 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12245 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12246 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12247 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12248 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12249 {
12250 unsigned long __limit;
12251 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12252 - return __limit + 1;
12253 + return __limit;
12254 }
12255
12256 #endif /* !__ASSEMBLY__ */
12257 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12258 index 4f19a15..9e14f27 100644
12259 --- a/arch/x86/include/asm/smp.h
12260 +++ b/arch/x86/include/asm/smp.h
12261 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12262 /* cpus sharing the last level cache: */
12263 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12264 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12265 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12266 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12267
12268 static inline struct cpumask *cpu_sibling_mask(int cpu)
12269 {
12270 @@ -79,7 +79,7 @@ struct smp_ops {
12271
12272 void (*send_call_func_ipi)(const struct cpumask *mask);
12273 void (*send_call_func_single_ipi)(int cpu);
12274 -};
12275 +} __no_const;
12276
12277 /* Globals due to paravirt */
12278 extern void set_cpu_sibling_map(int cpu);
12279 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12280 extern int safe_smp_processor_id(void);
12281
12282 #elif defined(CONFIG_X86_64_SMP)
12283 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12284 -
12285 -#define stack_smp_processor_id() \
12286 -({ \
12287 - struct thread_info *ti; \
12288 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12289 - ti->cpu; \
12290 -})
12291 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12292 +#define stack_smp_processor_id() raw_smp_processor_id()
12293 #define safe_smp_processor_id() smp_processor_id()
12294
12295 #endif
12296 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12297 index 33692ea..350a534 100644
12298 --- a/arch/x86/include/asm/spinlock.h
12299 +++ b/arch/x86/include/asm/spinlock.h
12300 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12301 static inline void arch_read_lock(arch_rwlock_t *rw)
12302 {
12303 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12304 +
12305 +#ifdef CONFIG_PAX_REFCOUNT
12306 + "jno 0f\n"
12307 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12308 + "int $4\n0:\n"
12309 + _ASM_EXTABLE(0b, 0b)
12310 +#endif
12311 +
12312 "jns 1f\n"
12313 "call __read_lock_failed\n\t"
12314 "1:\n"
12315 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12316 static inline void arch_write_lock(arch_rwlock_t *rw)
12317 {
12318 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12319 +
12320 +#ifdef CONFIG_PAX_REFCOUNT
12321 + "jno 0f\n"
12322 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12323 + "int $4\n0:\n"
12324 + _ASM_EXTABLE(0b, 0b)
12325 +#endif
12326 +
12327 "jz 1f\n"
12328 "call __write_lock_failed\n\t"
12329 "1:\n"
12330 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12331
12332 static inline void arch_read_unlock(arch_rwlock_t *rw)
12333 {
12334 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12335 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12336 +
12337 +#ifdef CONFIG_PAX_REFCOUNT
12338 + "jno 0f\n"
12339 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12340 + "int $4\n0:\n"
12341 + _ASM_EXTABLE(0b, 0b)
12342 +#endif
12343 +
12344 :"+m" (rw->lock) : : "memory");
12345 }
12346
12347 static inline void arch_write_unlock(arch_rwlock_t *rw)
12348 {
12349 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12350 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12351 +
12352 +#ifdef CONFIG_PAX_REFCOUNT
12353 + "jno 0f\n"
12354 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12355 + "int $4\n0:\n"
12356 + _ASM_EXTABLE(0b, 0b)
12357 +#endif
12358 +
12359 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12360 }
12361
12362 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12363 index 6a99859..03cb807 100644
12364 --- a/arch/x86/include/asm/stackprotector.h
12365 +++ b/arch/x86/include/asm/stackprotector.h
12366 @@ -47,7 +47,7 @@
12367 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12368 */
12369 #define GDT_STACK_CANARY_INIT \
12370 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12371 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12372
12373 /*
12374 * Initialize the stackprotector canary value.
12375 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12376
12377 static inline void load_stack_canary_segment(void)
12378 {
12379 -#ifdef CONFIG_X86_32
12380 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12381 asm volatile ("mov %0, %%gs" : : "r" (0));
12382 #endif
12383 }
12384 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12385 index 70bbe39..4ae2bd4 100644
12386 --- a/arch/x86/include/asm/stacktrace.h
12387 +++ b/arch/x86/include/asm/stacktrace.h
12388 @@ -11,28 +11,20 @@
12389
12390 extern int kstack_depth_to_print;
12391
12392 -struct thread_info;
12393 +struct task_struct;
12394 struct stacktrace_ops;
12395
12396 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12397 - unsigned long *stack,
12398 - unsigned long bp,
12399 - const struct stacktrace_ops *ops,
12400 - void *data,
12401 - unsigned long *end,
12402 - int *graph);
12403 +typedef unsigned long walk_stack_t(struct task_struct *task,
12404 + void *stack_start,
12405 + unsigned long *stack,
12406 + unsigned long bp,
12407 + const struct stacktrace_ops *ops,
12408 + void *data,
12409 + unsigned long *end,
12410 + int *graph);
12411
12412 -extern unsigned long
12413 -print_context_stack(struct thread_info *tinfo,
12414 - unsigned long *stack, unsigned long bp,
12415 - const struct stacktrace_ops *ops, void *data,
12416 - unsigned long *end, int *graph);
12417 -
12418 -extern unsigned long
12419 -print_context_stack_bp(struct thread_info *tinfo,
12420 - unsigned long *stack, unsigned long bp,
12421 - const struct stacktrace_ops *ops, void *data,
12422 - unsigned long *end, int *graph);
12423 +extern walk_stack_t print_context_stack;
12424 +extern walk_stack_t print_context_stack_bp;
12425
12426 /* Generic stack tracer with callbacks */
12427
12428 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12429 void (*address)(void *data, unsigned long address, int reliable);
12430 /* On negative return stop dumping */
12431 int (*stack)(void *data, char *name);
12432 - walk_stack_t walk_stack;
12433 + walk_stack_t *walk_stack;
12434 };
12435
12436 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12437 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12438 index 4ec45b3..a4f0a8a 100644
12439 --- a/arch/x86/include/asm/switch_to.h
12440 +++ b/arch/x86/include/asm/switch_to.h
12441 @@ -108,7 +108,7 @@ do { \
12442 "call __switch_to\n\t" \
12443 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12444 __switch_canary \
12445 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12446 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12447 "movq %%rax,%%rdi\n\t" \
12448 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12449 "jnz ret_from_fork\n\t" \
12450 @@ -119,7 +119,7 @@ do { \
12451 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12452 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12453 [_tif_fork] "i" (_TIF_FORK), \
12454 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12455 + [thread_info] "m" (current_tinfo), \
12456 [current_task] "m" (current_task) \
12457 __switch_canary_iparam \
12458 : "memory", "cc" __EXTRA_CLOBBER)
12459 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12460 index 3fda9db4..4ca1c61 100644
12461 --- a/arch/x86/include/asm/sys_ia32.h
12462 +++ b/arch/x86/include/asm/sys_ia32.h
12463 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12464 struct old_sigaction32 __user *);
12465 asmlinkage long sys32_alarm(unsigned int);
12466
12467 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12468 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12469 asmlinkage long sys32_sysfs(int, u32, u32);
12470
12471 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12472 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12473 index 89f794f..1422765 100644
12474 --- a/arch/x86/include/asm/thread_info.h
12475 +++ b/arch/x86/include/asm/thread_info.h
12476 @@ -10,6 +10,7 @@
12477 #include <linux/compiler.h>
12478 #include <asm/page.h>
12479 #include <asm/types.h>
12480 +#include <asm/percpu.h>
12481
12482 /*
12483 * low level task data that entry.S needs immediate access to
12484 @@ -24,7 +25,6 @@ struct exec_domain;
12485 #include <linux/atomic.h>
12486
12487 struct thread_info {
12488 - struct task_struct *task; /* main task structure */
12489 struct exec_domain *exec_domain; /* execution domain */
12490 __u32 flags; /* low level flags */
12491 __u32 status; /* thread synchronous flags */
12492 @@ -34,19 +34,13 @@ struct thread_info {
12493 mm_segment_t addr_limit;
12494 struct restart_block restart_block;
12495 void __user *sysenter_return;
12496 -#ifdef CONFIG_X86_32
12497 - unsigned long previous_esp; /* ESP of the previous stack in
12498 - case of nested (IRQ) stacks
12499 - */
12500 - __u8 supervisor_stack[0];
12501 -#endif
12502 + unsigned long lowest_stack;
12503 unsigned int sig_on_uaccess_error:1;
12504 unsigned int uaccess_err:1; /* uaccess failed */
12505 };
12506
12507 -#define INIT_THREAD_INFO(tsk) \
12508 +#define INIT_THREAD_INFO \
12509 { \
12510 - .task = &tsk, \
12511 .exec_domain = &default_exec_domain, \
12512 .flags = 0, \
12513 .cpu = 0, \
12514 @@ -57,7 +51,7 @@ struct thread_info {
12515 }, \
12516 }
12517
12518 -#define init_thread_info (init_thread_union.thread_info)
12519 +#define init_thread_info (init_thread_union.stack)
12520 #define init_stack (init_thread_union.stack)
12521
12522 #else /* !__ASSEMBLY__ */
12523 @@ -98,6 +92,7 @@ struct thread_info {
12524 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12525 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12526 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12527 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12528
12529 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12530 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12531 @@ -122,16 +117,18 @@ struct thread_info {
12532 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12533 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12534 #define _TIF_X32 (1 << TIF_X32)
12535 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12536
12537 /* work to do in syscall_trace_enter() */
12538 #define _TIF_WORK_SYSCALL_ENTRY \
12539 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12540 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12541 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12542 + _TIF_GRSEC_SETXID)
12543
12544 /* work to do in syscall_trace_leave() */
12545 #define _TIF_WORK_SYSCALL_EXIT \
12546 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12547 - _TIF_SYSCALL_TRACEPOINT)
12548 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12549
12550 /* work to do on interrupt/exception return */
12551 #define _TIF_WORK_MASK \
12552 @@ -141,7 +138,8 @@ struct thread_info {
12553
12554 /* work to do on any return to user space */
12555 #define _TIF_ALLWORK_MASK \
12556 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12557 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12558 + _TIF_GRSEC_SETXID)
12559
12560 /* Only used for 64 bit */
12561 #define _TIF_DO_NOTIFY_MASK \
12562 @@ -157,45 +155,40 @@ struct thread_info {
12563
12564 #define PREEMPT_ACTIVE 0x10000000
12565
12566 -#ifdef CONFIG_X86_32
12567 -
12568 -#define STACK_WARN (THREAD_SIZE/8)
12569 -/*
12570 - * macros/functions for gaining access to the thread information structure
12571 - *
12572 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12573 - */
12574 -#ifndef __ASSEMBLY__
12575 -
12576 -
12577 -/* how to get the current stack pointer from C */
12578 -register unsigned long current_stack_pointer asm("esp") __used;
12579 -
12580 -/* how to get the thread information struct from C */
12581 -static inline struct thread_info *current_thread_info(void)
12582 -{
12583 - return (struct thread_info *)
12584 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12585 -}
12586 -
12587 -#else /* !__ASSEMBLY__ */
12588 -
12589 +#ifdef __ASSEMBLY__
12590 /* how to get the thread information struct from ASM */
12591 #define GET_THREAD_INFO(reg) \
12592 - movl $-THREAD_SIZE, reg; \
12593 - andl %esp, reg
12594 + mov PER_CPU_VAR(current_tinfo), reg
12595
12596 /* use this one if reg already contains %esp */
12597 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12598 - andl $-THREAD_SIZE, reg
12599 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12600 +#else
12601 +/* how to get the thread information struct from C */
12602 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12603 +
12604 +static __always_inline struct thread_info *current_thread_info(void)
12605 +{
12606 + return this_cpu_read_stable(current_tinfo);
12607 +}
12608 +#endif
12609 +
12610 +#ifdef CONFIG_X86_32
12611 +
12612 +#define STACK_WARN (THREAD_SIZE/8)
12613 +/*
12614 + * macros/functions for gaining access to the thread information structure
12615 + *
12616 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12617 + */
12618 +#ifndef __ASSEMBLY__
12619 +
12620 +/* how to get the current stack pointer from C */
12621 +register unsigned long current_stack_pointer asm("esp") __used;
12622
12623 #endif
12624
12625 #else /* X86_32 */
12626
12627 -#include <asm/percpu.h>
12628 -#define KERNEL_STACK_OFFSET (5*8)
12629 -
12630 /*
12631 * macros/functions for gaining access to the thread information structure
12632 * preempt_count needs to be 1 initially, until the scheduler is functional.
12633 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12634 #ifndef __ASSEMBLY__
12635 DECLARE_PER_CPU(unsigned long, kernel_stack);
12636
12637 -static inline struct thread_info *current_thread_info(void)
12638 -{
12639 - struct thread_info *ti;
12640 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12641 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12642 - return ti;
12643 -}
12644 -
12645 -#else /* !__ASSEMBLY__ */
12646 -
12647 -/* how to get the thread information struct from ASM */
12648 -#define GET_THREAD_INFO(reg) \
12649 - movq PER_CPU_VAR(kernel_stack),reg ; \
12650 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12651 -
12652 -/*
12653 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12654 - * a certain register (to be used in assembler memory operands).
12655 - */
12656 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12657 -
12658 +/* how to get the current stack pointer from C */
12659 +register unsigned long current_stack_pointer asm("rsp") __used;
12660 #endif
12661
12662 #endif /* !X86_32 */
12663 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12664 extern void arch_task_cache_init(void);
12665 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12666 extern void arch_release_task_struct(struct task_struct *tsk);
12667 +
12668 +#define __HAVE_THREAD_FUNCTIONS
12669 +#define task_thread_info(task) (&(task)->tinfo)
12670 +#define task_stack_page(task) ((task)->stack)
12671 +#define setup_thread_stack(p, org) do {} while (0)
12672 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12673 +
12674 #endif
12675 #endif /* _ASM_X86_THREAD_INFO_H */
12676 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12677 index e1f3a17..1ab364d 100644
12678 --- a/arch/x86/include/asm/uaccess.h
12679 +++ b/arch/x86/include/asm/uaccess.h
12680 @@ -7,12 +7,15 @@
12681 #include <linux/compiler.h>
12682 #include <linux/thread_info.h>
12683 #include <linux/string.h>
12684 +#include <linux/sched.h>
12685 #include <asm/asm.h>
12686 #include <asm/page.h>
12687
12688 #define VERIFY_READ 0
12689 #define VERIFY_WRITE 1
12690
12691 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12692 +
12693 /*
12694 * The fs value determines whether argument validity checking should be
12695 * performed or not. If get_fs() == USER_DS, checking is performed, with
12696 @@ -28,7 +31,12 @@
12697
12698 #define get_ds() (KERNEL_DS)
12699 #define get_fs() (current_thread_info()->addr_limit)
12700 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12701 +void __set_fs(mm_segment_t x);
12702 +void set_fs(mm_segment_t x);
12703 +#else
12704 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12705 +#endif
12706
12707 #define segment_eq(a, b) ((a).seg == (b).seg)
12708
12709 @@ -76,8 +84,33 @@
12710 * checks that the pointer is in the user space range - after calling
12711 * this function, memory access functions may still return -EFAULT.
12712 */
12713 -#define access_ok(type, addr, size) \
12714 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12715 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12716 +#define access_ok(type, addr, size) \
12717 +({ \
12718 + long __size = size; \
12719 + unsigned long __addr = (unsigned long)addr; \
12720 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12721 + unsigned long __end_ao = __addr + __size - 1; \
12722 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12723 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12724 + while(__addr_ao <= __end_ao) { \
12725 + char __c_ao; \
12726 + __addr_ao += PAGE_SIZE; \
12727 + if (__size > PAGE_SIZE) \
12728 + cond_resched(); \
12729 + if (__get_user(__c_ao, (char __user *)__addr)) \
12730 + break; \
12731 + if (type != VERIFY_WRITE) { \
12732 + __addr = __addr_ao; \
12733 + continue; \
12734 + } \
12735 + if (__put_user(__c_ao, (char __user *)__addr)) \
12736 + break; \
12737 + __addr = __addr_ao; \
12738 + } \
12739 + } \
12740 + __ret_ao; \
12741 +})
12742
12743 /*
12744 * The exception table consists of pairs of addresses relative to the
12745 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12746 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12747 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12748
12749 -
12750 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12751 +#define __copyuser_seg "gs;"
12752 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12753 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12754 +#else
12755 +#define __copyuser_seg
12756 +#define __COPYUSER_SET_ES
12757 +#define __COPYUSER_RESTORE_ES
12758 +#endif
12759
12760 #ifdef CONFIG_X86_32
12761 #define __put_user_asm_u64(x, addr, err, errret) \
12762 - asm volatile("1: movl %%eax,0(%2)\n" \
12763 - "2: movl %%edx,4(%2)\n" \
12764 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12765 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12766 "3:\n" \
12767 ".section .fixup,\"ax\"\n" \
12768 "4: movl %3,%0\n" \
12769 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12770 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12771
12772 #define __put_user_asm_ex_u64(x, addr) \
12773 - asm volatile("1: movl %%eax,0(%1)\n" \
12774 - "2: movl %%edx,4(%1)\n" \
12775 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12776 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12777 "3:\n" \
12778 _ASM_EXTABLE_EX(1b, 2b) \
12779 _ASM_EXTABLE_EX(2b, 3b) \
12780 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12781 __typeof__(*(ptr)) __pu_val; \
12782 __chk_user_ptr(ptr); \
12783 might_fault(); \
12784 - __pu_val = x; \
12785 + __pu_val = (x); \
12786 switch (sizeof(*(ptr))) { \
12787 case 1: \
12788 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12789 @@ -379,7 +420,7 @@ do { \
12790 } while (0)
12791
12792 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12793 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12794 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12795 "2:\n" \
12796 ".section .fixup,\"ax\"\n" \
12797 "3: mov %3,%0\n" \
12798 @@ -387,7 +428,7 @@ do { \
12799 " jmp 2b\n" \
12800 ".previous\n" \
12801 _ASM_EXTABLE(1b, 3b) \
12802 - : "=r" (err), ltype(x) \
12803 + : "=r" (err), ltype (x) \
12804 : "m" (__m(addr)), "i" (errret), "0" (err))
12805
12806 #define __get_user_size_ex(x, ptr, size) \
12807 @@ -412,7 +453,7 @@ do { \
12808 } while (0)
12809
12810 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12811 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12812 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12813 "2:\n" \
12814 _ASM_EXTABLE_EX(1b, 2b) \
12815 : ltype(x) : "m" (__m(addr)))
12816 @@ -429,13 +470,24 @@ do { \
12817 int __gu_err; \
12818 unsigned long __gu_val; \
12819 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12820 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12821 + (x) = (__typeof__(*(ptr)))__gu_val; \
12822 __gu_err; \
12823 })
12824
12825 /* FIXME: this hack is definitely wrong -AK */
12826 struct __large_struct { unsigned long buf[100]; };
12827 -#define __m(x) (*(struct __large_struct __user *)(x))
12828 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12829 +#define ____m(x) \
12830 +({ \
12831 + unsigned long ____x = (unsigned long)(x); \
12832 + if (____x < PAX_USER_SHADOW_BASE) \
12833 + ____x += PAX_USER_SHADOW_BASE; \
12834 + (void __user *)____x; \
12835 +})
12836 +#else
12837 +#define ____m(x) (x)
12838 +#endif
12839 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12840
12841 /*
12842 * Tell gcc we read from memory instead of writing: this is because
12843 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12844 * aliasing issues.
12845 */
12846 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12847 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12848 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12849 "2:\n" \
12850 ".section .fixup,\"ax\"\n" \
12851 "3: mov %3,%0\n" \
12852 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12853 ".previous\n" \
12854 _ASM_EXTABLE(1b, 3b) \
12855 : "=r"(err) \
12856 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12857 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12858
12859 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12860 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12861 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12862 "2:\n" \
12863 _ASM_EXTABLE_EX(1b, 2b) \
12864 : : ltype(x), "m" (__m(addr)))
12865 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12866 * On error, the variable @x is set to zero.
12867 */
12868
12869 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12870 +#define __get_user(x, ptr) get_user((x), (ptr))
12871 +#else
12872 #define __get_user(x, ptr) \
12873 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12874 +#endif
12875
12876 /**
12877 * __put_user: - Write a simple value into user space, with less checking.
12878 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12879 * Returns zero on success, or -EFAULT on error.
12880 */
12881
12882 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12883 +#define __put_user(x, ptr) put_user((x), (ptr))
12884 +#else
12885 #define __put_user(x, ptr) \
12886 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12887 +#endif
12888
12889 #define __get_user_unaligned __get_user
12890 #define __put_user_unaligned __put_user
12891 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12892 #define get_user_ex(x, ptr) do { \
12893 unsigned long __gue_val; \
12894 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12895 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12896 + (x) = (__typeof__(*(ptr)))__gue_val; \
12897 } while (0)
12898
12899 #ifdef CONFIG_X86_WP_WORKS_OK
12900 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12901 index 576e39b..ccd0a39 100644
12902 --- a/arch/x86/include/asm/uaccess_32.h
12903 +++ b/arch/x86/include/asm/uaccess_32.h
12904 @@ -11,15 +11,15 @@
12905 #include <asm/page.h>
12906
12907 unsigned long __must_check __copy_to_user_ll
12908 - (void __user *to, const void *from, unsigned long n);
12909 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12910 unsigned long __must_check __copy_from_user_ll
12911 - (void *to, const void __user *from, unsigned long n);
12912 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12913 unsigned long __must_check __copy_from_user_ll_nozero
12914 - (void *to, const void __user *from, unsigned long n);
12915 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12916 unsigned long __must_check __copy_from_user_ll_nocache
12917 - (void *to, const void __user *from, unsigned long n);
12918 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12919 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12920 - (void *to, const void __user *from, unsigned long n);
12921 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12922
12923 /**
12924 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12925 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12926 static __always_inline unsigned long __must_check
12927 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12928 {
12929 + if ((long)n < 0)
12930 + return n;
12931 +
12932 if (__builtin_constant_p(n)) {
12933 unsigned long ret;
12934
12935 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12936 return ret;
12937 }
12938 }
12939 + if (!__builtin_constant_p(n))
12940 + check_object_size(from, n, true);
12941 return __copy_to_user_ll(to, from, n);
12942 }
12943
12944 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12945 __copy_to_user(void __user *to, const void *from, unsigned long n)
12946 {
12947 might_fault();
12948 +
12949 return __copy_to_user_inatomic(to, from, n);
12950 }
12951
12952 static __always_inline unsigned long
12953 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12954 {
12955 + if ((long)n < 0)
12956 + return n;
12957 +
12958 /* Avoid zeroing the tail if the copy fails..
12959 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12960 * but as the zeroing behaviour is only significant when n is not
12961 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12962 __copy_from_user(void *to, const void __user *from, unsigned long n)
12963 {
12964 might_fault();
12965 +
12966 + if ((long)n < 0)
12967 + return n;
12968 +
12969 if (__builtin_constant_p(n)) {
12970 unsigned long ret;
12971
12972 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12973 return ret;
12974 }
12975 }
12976 + if (!__builtin_constant_p(n))
12977 + check_object_size(to, n, false);
12978 return __copy_from_user_ll(to, from, n);
12979 }
12980
12981 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12982 const void __user *from, unsigned long n)
12983 {
12984 might_fault();
12985 +
12986 + if ((long)n < 0)
12987 + return n;
12988 +
12989 if (__builtin_constant_p(n)) {
12990 unsigned long ret;
12991
12992 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12993 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12994 unsigned long n)
12995 {
12996 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12997 + if ((long)n < 0)
12998 + return n;
12999 +
13000 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13001 }
13002
13003 -unsigned long __must_check copy_to_user(void __user *to,
13004 - const void *from, unsigned long n);
13005 -unsigned long __must_check _copy_from_user(void *to,
13006 - const void __user *from,
13007 - unsigned long n);
13008 -
13009 +extern void copy_to_user_overflow(void)
13010 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13011 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13012 +#else
13013 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13014 +#endif
13015 +;
13016
13017 extern void copy_from_user_overflow(void)
13018 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13019 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13020 #endif
13021 ;
13022
13023 -static inline unsigned long __must_check copy_from_user(void *to,
13024 - const void __user *from,
13025 - unsigned long n)
13026 +/**
13027 + * copy_to_user: - Copy a block of data into user space.
13028 + * @to: Destination address, in user space.
13029 + * @from: Source address, in kernel space.
13030 + * @n: Number of bytes to copy.
13031 + *
13032 + * Context: User context only. This function may sleep.
13033 + *
13034 + * Copy data from kernel space to user space.
13035 + *
13036 + * Returns number of bytes that could not be copied.
13037 + * On success, this will be zero.
13038 + */
13039 +static inline unsigned long __must_check
13040 +copy_to_user(void __user *to, const void *from, unsigned long n)
13041 {
13042 - int sz = __compiletime_object_size(to);
13043 + size_t sz = __compiletime_object_size(from);
13044
13045 - if (likely(sz == -1 || sz >= n))
13046 - n = _copy_from_user(to, from, n);
13047 - else
13048 + if (unlikely(sz != (size_t)-1 && sz < n))
13049 + copy_to_user_overflow();
13050 + else if (access_ok(VERIFY_WRITE, to, n))
13051 + n = __copy_to_user(to, from, n);
13052 + return n;
13053 +}
13054 +
13055 +/**
13056 + * copy_from_user: - Copy a block of data from user space.
13057 + * @to: Destination address, in kernel space.
13058 + * @from: Source address, in user space.
13059 + * @n: Number of bytes to copy.
13060 + *
13061 + * Context: User context only. This function may sleep.
13062 + *
13063 + * Copy data from user space to kernel space.
13064 + *
13065 + * Returns number of bytes that could not be copied.
13066 + * On success, this will be zero.
13067 + *
13068 + * If some data could not be copied, this function will pad the copied
13069 + * data to the requested size using zero bytes.
13070 + */
13071 +static inline unsigned long __must_check
13072 +copy_from_user(void *to, const void __user *from, unsigned long n)
13073 +{
13074 + size_t sz = __compiletime_object_size(to);
13075 +
13076 + if (unlikely(sz != (size_t)-1 && sz < n))
13077 copy_from_user_overflow();
13078 -
13079 + else if (access_ok(VERIFY_READ, from, n))
13080 + n = __copy_from_user(to, from, n);
13081 + else if ((long)n > 0) {
13082 + if (!__builtin_constant_p(n))
13083 + check_object_size(to, n, false);
13084 + memset(to, 0, n);
13085 + }
13086 return n;
13087 }
13088
13089 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13090 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13091 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13092 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13093
13094 #endif /* _ASM_X86_UACCESS_32_H */
13095 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13096 index d8def8b..ac7fc15 100644
13097 --- a/arch/x86/include/asm/uaccess_64.h
13098 +++ b/arch/x86/include/asm/uaccess_64.h
13099 @@ -10,6 +10,9 @@
13100 #include <asm/alternative.h>
13101 #include <asm/cpufeature.h>
13102 #include <asm/page.h>
13103 +#include <asm/pgtable.h>
13104 +
13105 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13106
13107 /*
13108 * Copy To/From Userspace
13109 @@ -17,13 +20,13 @@
13110
13111 /* Handles exceptions in both to and from, but doesn't do access_ok */
13112 __must_check unsigned long
13113 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13114 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13115 __must_check unsigned long
13116 -copy_user_generic_string(void *to, const void *from, unsigned len);
13117 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13118 __must_check unsigned long
13119 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13120 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13121
13122 -static __always_inline __must_check unsigned long
13123 +static __always_inline __must_check __size_overflow(3) unsigned long
13124 copy_user_generic(void *to, const void *from, unsigned len)
13125 {
13126 unsigned ret;
13127 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13128 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13129 "=d" (len)),
13130 "1" (to), "2" (from), "3" (len)
13131 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13132 + : "memory", "rcx", "r8", "r9", "r11");
13133 return ret;
13134 }
13135
13136 +static __always_inline __must_check unsigned long
13137 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13138 +static __always_inline __must_check unsigned long
13139 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13140 __must_check unsigned long
13141 -_copy_to_user(void __user *to, const void *from, unsigned len);
13142 -__must_check unsigned long
13143 -_copy_from_user(void *to, const void __user *from, unsigned len);
13144 -__must_check unsigned long
13145 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13146 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13147 +
13148 +extern void copy_to_user_overflow(void)
13149 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13150 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13151 +#else
13152 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13153 +#endif
13154 +;
13155 +
13156 +extern void copy_from_user_overflow(void)
13157 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13158 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13159 +#else
13160 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13161 +#endif
13162 +;
13163
13164 static inline unsigned long __must_check copy_from_user(void *to,
13165 const void __user *from,
13166 unsigned long n)
13167 {
13168 - int sz = __compiletime_object_size(to);
13169 -
13170 might_fault();
13171 - if (likely(sz == -1 || sz >= n))
13172 - n = _copy_from_user(to, from, n);
13173 -#ifdef CONFIG_DEBUG_VM
13174 - else
13175 - WARN(1, "Buffer overflow detected!\n");
13176 -#endif
13177 +
13178 + if (access_ok(VERIFY_READ, from, n))
13179 + n = __copy_from_user(to, from, n);
13180 + else if (n < INT_MAX) {
13181 + if (!__builtin_constant_p(n))
13182 + check_object_size(to, n, false);
13183 + memset(to, 0, n);
13184 + }
13185 return n;
13186 }
13187
13188 static __always_inline __must_check
13189 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13190 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13191 {
13192 might_fault();
13193
13194 - return _copy_to_user(dst, src, size);
13195 + if (access_ok(VERIFY_WRITE, dst, size))
13196 + size = __copy_to_user(dst, src, size);
13197 + return size;
13198 }
13199
13200 static __always_inline __must_check
13201 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13202 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13203 {
13204 - int ret = 0;
13205 + size_t sz = __compiletime_object_size(dst);
13206 + unsigned ret = 0;
13207
13208 might_fault();
13209 - if (!__builtin_constant_p(size))
13210 - return copy_user_generic(dst, (__force void *)src, size);
13211 +
13212 + if (size > INT_MAX)
13213 + return size;
13214 +
13215 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13216 + if (!__access_ok(VERIFY_READ, src, size))
13217 + return size;
13218 +#endif
13219 +
13220 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13221 + copy_from_user_overflow();
13222 + return size;
13223 + }
13224 +
13225 + if (!__builtin_constant_p(size)) {
13226 + check_object_size(dst, size, false);
13227 +
13228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13229 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13230 + src += PAX_USER_SHADOW_BASE;
13231 +#endif
13232 +
13233 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13234 + }
13235 switch (size) {
13236 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13237 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13238 ret, "b", "b", "=q", 1);
13239 return ret;
13240 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13241 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13242 ret, "w", "w", "=r", 2);
13243 return ret;
13244 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13245 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13246 ret, "l", "k", "=r", 4);
13247 return ret;
13248 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13249 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13250 ret, "q", "", "=r", 8);
13251 return ret;
13252 case 10:
13253 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13254 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13255 ret, "q", "", "=r", 10);
13256 if (unlikely(ret))
13257 return ret;
13258 __get_user_asm(*(u16 *)(8 + (char *)dst),
13259 - (u16 __user *)(8 + (char __user *)src),
13260 + (const u16 __user *)(8 + (const char __user *)src),
13261 ret, "w", "w", "=r", 2);
13262 return ret;
13263 case 16:
13264 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13265 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13266 ret, "q", "", "=r", 16);
13267 if (unlikely(ret))
13268 return ret;
13269 __get_user_asm(*(u64 *)(8 + (char *)dst),
13270 - (u64 __user *)(8 + (char __user *)src),
13271 + (const u64 __user *)(8 + (const char __user *)src),
13272 ret, "q", "", "=r", 8);
13273 return ret;
13274 default:
13275 - return copy_user_generic(dst, (__force void *)src, size);
13276 +
13277 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13278 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13279 + src += PAX_USER_SHADOW_BASE;
13280 +#endif
13281 +
13282 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13283 }
13284 }
13285
13286 static __always_inline __must_check
13287 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13288 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13289 {
13290 - int ret = 0;
13291 + size_t sz = __compiletime_object_size(src);
13292 + unsigned ret = 0;
13293
13294 might_fault();
13295 - if (!__builtin_constant_p(size))
13296 - return copy_user_generic((__force void *)dst, src, size);
13297 +
13298 + if (size > INT_MAX)
13299 + return size;
13300 +
13301 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13302 + if (!__access_ok(VERIFY_WRITE, dst, size))
13303 + return size;
13304 +#endif
13305 +
13306 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13307 + copy_to_user_overflow();
13308 + return size;
13309 + }
13310 +
13311 + if (!__builtin_constant_p(size)) {
13312 + check_object_size(src, size, true);
13313 +
13314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13315 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13316 + dst += PAX_USER_SHADOW_BASE;
13317 +#endif
13318 +
13319 + return copy_user_generic((__force_kernel void *)dst, src, size);
13320 + }
13321 switch (size) {
13322 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13323 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13324 ret, "b", "b", "iq", 1);
13325 return ret;
13326 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13327 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13328 ret, "w", "w", "ir", 2);
13329 return ret;
13330 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13331 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13332 ret, "l", "k", "ir", 4);
13333 return ret;
13334 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13335 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13336 ret, "q", "", "er", 8);
13337 return ret;
13338 case 10:
13339 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13340 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13341 ret, "q", "", "er", 10);
13342 if (unlikely(ret))
13343 return ret;
13344 asm("":::"memory");
13345 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13346 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13347 ret, "w", "w", "ir", 2);
13348 return ret;
13349 case 16:
13350 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13351 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13352 ret, "q", "", "er", 16);
13353 if (unlikely(ret))
13354 return ret;
13355 asm("":::"memory");
13356 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13357 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13358 ret, "q", "", "er", 8);
13359 return ret;
13360 default:
13361 - return copy_user_generic((__force void *)dst, src, size);
13362 +
13363 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13364 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13365 + dst += PAX_USER_SHADOW_BASE;
13366 +#endif
13367 +
13368 + return copy_user_generic((__force_kernel void *)dst, src, size);
13369 }
13370 }
13371
13372 static __always_inline __must_check
13373 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13374 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13375 {
13376 - int ret = 0;
13377 + unsigned ret = 0;
13378
13379 might_fault();
13380 - if (!__builtin_constant_p(size))
13381 - return copy_user_generic((__force void *)dst,
13382 - (__force void *)src, size);
13383 +
13384 + if (size > INT_MAX)
13385 + return size;
13386 +
13387 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13388 + if (!__access_ok(VERIFY_READ, src, size))
13389 + return size;
13390 + if (!__access_ok(VERIFY_WRITE, dst, size))
13391 + return size;
13392 +#endif
13393 +
13394 + if (!__builtin_constant_p(size)) {
13395 +
13396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13397 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13398 + src += PAX_USER_SHADOW_BASE;
13399 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13400 + dst += PAX_USER_SHADOW_BASE;
13401 +#endif
13402 +
13403 + return copy_user_generic((__force_kernel void *)dst,
13404 + (__force_kernel const void *)src, size);
13405 + }
13406 switch (size) {
13407 case 1: {
13408 u8 tmp;
13409 - __get_user_asm(tmp, (u8 __user *)src,
13410 + __get_user_asm(tmp, (const u8 __user *)src,
13411 ret, "b", "b", "=q", 1);
13412 if (likely(!ret))
13413 __put_user_asm(tmp, (u8 __user *)dst,
13414 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13415 }
13416 case 2: {
13417 u16 tmp;
13418 - __get_user_asm(tmp, (u16 __user *)src,
13419 + __get_user_asm(tmp, (const u16 __user *)src,
13420 ret, "w", "w", "=r", 2);
13421 if (likely(!ret))
13422 __put_user_asm(tmp, (u16 __user *)dst,
13423 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13424
13425 case 4: {
13426 u32 tmp;
13427 - __get_user_asm(tmp, (u32 __user *)src,
13428 + __get_user_asm(tmp, (const u32 __user *)src,
13429 ret, "l", "k", "=r", 4);
13430 if (likely(!ret))
13431 __put_user_asm(tmp, (u32 __user *)dst,
13432 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13433 }
13434 case 8: {
13435 u64 tmp;
13436 - __get_user_asm(tmp, (u64 __user *)src,
13437 + __get_user_asm(tmp, (const u64 __user *)src,
13438 ret, "q", "", "=r", 8);
13439 if (likely(!ret))
13440 __put_user_asm(tmp, (u64 __user *)dst,
13441 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13442 return ret;
13443 }
13444 default:
13445 - return copy_user_generic((__force void *)dst,
13446 - (__force void *)src, size);
13447 +
13448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13449 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13450 + src += PAX_USER_SHADOW_BASE;
13451 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13452 + dst += PAX_USER_SHADOW_BASE;
13453 +#endif
13454 +
13455 + return copy_user_generic((__force_kernel void *)dst,
13456 + (__force_kernel const void *)src, size);
13457 }
13458 }
13459
13460 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13461 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13462 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13463 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13464
13465 static __must_check __always_inline int
13466 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13467 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13468 {
13469 - return copy_user_generic(dst, (__force const void *)src, size);
13470 + if (size > INT_MAX)
13471 + return size;
13472 +
13473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13474 + if (!__access_ok(VERIFY_READ, src, size))
13475 + return size;
13476 +
13477 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13478 + src += PAX_USER_SHADOW_BASE;
13479 +#endif
13480 +
13481 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13482 }
13483
13484 -static __must_check __always_inline int
13485 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13486 +static __must_check __always_inline unsigned long
13487 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13488 {
13489 - return copy_user_generic((__force void *)dst, src, size);
13490 + if (size > INT_MAX)
13491 + return size;
13492 +
13493 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13494 + if (!__access_ok(VERIFY_WRITE, dst, size))
13495 + return size;
13496 +
13497 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13498 + dst += PAX_USER_SHADOW_BASE;
13499 +#endif
13500 +
13501 + return copy_user_generic((__force_kernel void *)dst, src, size);
13502 }
13503
13504 -extern long __copy_user_nocache(void *dst, const void __user *src,
13505 - unsigned size, int zerorest);
13506 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13507 + unsigned long size, int zerorest) __size_overflow(3);
13508
13509 -static inline int
13510 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13511 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13512 {
13513 might_sleep();
13514 +
13515 + if (size > INT_MAX)
13516 + return size;
13517 +
13518 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13519 + if (!__access_ok(VERIFY_READ, src, size))
13520 + return size;
13521 +#endif
13522 +
13523 return __copy_user_nocache(dst, src, size, 1);
13524 }
13525
13526 -static inline int
13527 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13528 - unsigned size)
13529 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13530 + unsigned long size)
13531 {
13532 + if (size > INT_MAX)
13533 + return size;
13534 +
13535 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13536 + if (!__access_ok(VERIFY_READ, src, size))
13537 + return size;
13538 +#endif
13539 +
13540 return __copy_user_nocache(dst, src, size, 0);
13541 }
13542
13543 -unsigned long
13544 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13545 +extern unsigned long
13546 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13547
13548 #endif /* _ASM_X86_UACCESS_64_H */
13549 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13550 index bb05228..d763d5b 100644
13551 --- a/arch/x86/include/asm/vdso.h
13552 +++ b/arch/x86/include/asm/vdso.h
13553 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13554 #define VDSO32_SYMBOL(base, name) \
13555 ({ \
13556 extern const char VDSO32_##name[]; \
13557 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13558 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13559 })
13560 #endif
13561
13562 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13563 index 5b238981..77fdd78 100644
13564 --- a/arch/x86/include/asm/word-at-a-time.h
13565 +++ b/arch/x86/include/asm/word-at-a-time.h
13566 @@ -11,7 +11,7 @@
13567 * and shift, for example.
13568 */
13569 struct word_at_a_time {
13570 - const unsigned long one_bits, high_bits;
13571 + unsigned long one_bits, high_bits;
13572 };
13573
13574 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13575 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13576 index 38155f6..e4184ba 100644
13577 --- a/arch/x86/include/asm/x86_init.h
13578 +++ b/arch/x86/include/asm/x86_init.h
13579 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13580 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13581 void (*find_smp_config)(void);
13582 void (*get_smp_config)(unsigned int early);
13583 -};
13584 +} __no_const;
13585
13586 /**
13587 * struct x86_init_resources - platform specific resource related ops
13588 @@ -43,7 +43,7 @@ struct x86_init_resources {
13589 void (*probe_roms)(void);
13590 void (*reserve_resources)(void);
13591 char *(*memory_setup)(void);
13592 -};
13593 +} __no_const;
13594
13595 /**
13596 * struct x86_init_irqs - platform specific interrupt setup
13597 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13598 void (*pre_vector_init)(void);
13599 void (*intr_init)(void);
13600 void (*trap_init)(void);
13601 -};
13602 +} __no_const;
13603
13604 /**
13605 * struct x86_init_oem - oem platform specific customizing functions
13606 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13607 struct x86_init_oem {
13608 void (*arch_setup)(void);
13609 void (*banner)(void);
13610 -};
13611 +} __no_const;
13612
13613 /**
13614 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13615 @@ -77,7 +77,7 @@ struct x86_init_oem {
13616 */
13617 struct x86_init_mapping {
13618 void (*pagetable_reserve)(u64 start, u64 end);
13619 -};
13620 +} __no_const;
13621
13622 /**
13623 * struct x86_init_paging - platform specific paging functions
13624 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13625 struct x86_init_paging {
13626 void (*pagetable_setup_start)(pgd_t *base);
13627 void (*pagetable_setup_done)(pgd_t *base);
13628 -};
13629 +} __no_const;
13630
13631 /**
13632 * struct x86_init_timers - platform specific timer setup
13633 @@ -102,7 +102,7 @@ struct x86_init_timers {
13634 void (*tsc_pre_init)(void);
13635 void (*timer_init)(void);
13636 void (*wallclock_init)(void);
13637 -};
13638 +} __no_const;
13639
13640 /**
13641 * struct x86_init_iommu - platform specific iommu setup
13642 @@ -110,7 +110,7 @@ struct x86_init_timers {
13643 */
13644 struct x86_init_iommu {
13645 int (*iommu_init)(void);
13646 -};
13647 +} __no_const;
13648
13649 /**
13650 * struct x86_init_pci - platform specific pci init functions
13651 @@ -124,7 +124,7 @@ struct x86_init_pci {
13652 int (*init)(void);
13653 void (*init_irq)(void);
13654 void (*fixup_irqs)(void);
13655 -};
13656 +} __no_const;
13657
13658 /**
13659 * struct x86_init_ops - functions for platform specific setup
13660 @@ -140,7 +140,7 @@ struct x86_init_ops {
13661 struct x86_init_timers timers;
13662 struct x86_init_iommu iommu;
13663 struct x86_init_pci pci;
13664 -};
13665 +} __no_const;
13666
13667 /**
13668 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13669 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13670 void (*setup_percpu_clockev)(void);
13671 void (*early_percpu_clock_init)(void);
13672 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13673 -};
13674 +} __no_const;
13675
13676 /**
13677 * struct x86_platform_ops - platform specific runtime functions
13678 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13679 void (*save_sched_clock_state)(void);
13680 void (*restore_sched_clock_state)(void);
13681 void (*apic_post_init)(void);
13682 -};
13683 +} __no_const;
13684
13685 struct pci_dev;
13686
13687 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13688 void (*teardown_msi_irq)(unsigned int irq);
13689 void (*teardown_msi_irqs)(struct pci_dev *dev);
13690 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13691 -};
13692 +} __no_const;
13693
13694 struct x86_io_apic_ops {
13695 void (*init) (void);
13696 unsigned int (*read) (unsigned int apic, unsigned int reg);
13697 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13698 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13699 -};
13700 +} __no_const;
13701
13702 extern struct x86_init_ops x86_init;
13703 extern struct x86_cpuinit_ops x86_cpuinit;
13704 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13705 index 8a1b6f9..a29c4e4 100644
13706 --- a/arch/x86/include/asm/xsave.h
13707 +++ b/arch/x86/include/asm/xsave.h
13708 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13709 {
13710 int err;
13711
13712 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13713 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13714 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13715 +#endif
13716 +
13717 /*
13718 * Clear the xsave header first, so that reserved fields are
13719 * initialized to zero.
13720 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13721 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13722 {
13723 int err;
13724 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13725 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13726 u32 lmask = mask;
13727 u32 hmask = mask >> 32;
13728
13729 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13730 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13731 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13732 +#endif
13733 +
13734 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13735 "2:\n"
13736 ".section .fixup,\"ax\"\n"
13737 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13738 index 1b8e5a0..354fd59 100644
13739 --- a/arch/x86/kernel/acpi/sleep.c
13740 +++ b/arch/x86/kernel/acpi/sleep.c
13741 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13742 #else /* CONFIG_64BIT */
13743 #ifdef CONFIG_SMP
13744 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13745 +
13746 + pax_open_kernel();
13747 early_gdt_descr.address =
13748 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13749 + pax_close_kernel();
13750 +
13751 initial_gs = per_cpu_offset(smp_processor_id());
13752 #endif
13753 initial_code = (unsigned long)wakeup_long64;
13754 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13755 index 13ab720..95d5442 100644
13756 --- a/arch/x86/kernel/acpi/wakeup_32.S
13757 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13758 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13759 # and restore the stack ... but you need gdt for this to work
13760 movl saved_context_esp, %esp
13761
13762 - movl %cs:saved_magic, %eax
13763 - cmpl $0x12345678, %eax
13764 + cmpl $0x12345678, saved_magic
13765 jne bogus_magic
13766
13767 # jump to place where we left off
13768 - movl saved_eip, %eax
13769 - jmp *%eax
13770 + jmp *(saved_eip)
13771
13772 bogus_magic:
13773 jmp bogus_magic
13774 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13775 index ced4534..3e75d69 100644
13776 --- a/arch/x86/kernel/alternative.c
13777 +++ b/arch/x86/kernel/alternative.c
13778 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13779 */
13780 for (a = start; a < end; a++) {
13781 instr = (u8 *)&a->instr_offset + a->instr_offset;
13782 +
13783 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13784 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13785 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13786 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13787 +#endif
13788 +
13789 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13790 BUG_ON(a->replacementlen > a->instrlen);
13791 BUG_ON(a->instrlen > sizeof(insnbuf));
13792 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13793 for (poff = start; poff < end; poff++) {
13794 u8 *ptr = (u8 *)poff + *poff;
13795
13796 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13797 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13798 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13799 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13800 +#endif
13801 +
13802 if (!*poff || ptr < text || ptr >= text_end)
13803 continue;
13804 /* turn DS segment override prefix into lock prefix */
13805 - if (*ptr == 0x3e)
13806 + if (*ktla_ktva(ptr) == 0x3e)
13807 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13808 };
13809 mutex_unlock(&text_mutex);
13810 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13811 for (poff = start; poff < end; poff++) {
13812 u8 *ptr = (u8 *)poff + *poff;
13813
13814 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13815 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13816 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13817 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13818 +#endif
13819 +
13820 if (!*poff || ptr < text || ptr >= text_end)
13821 continue;
13822 /* turn lock prefix into DS segment override prefix */
13823 - if (*ptr == 0xf0)
13824 + if (*ktla_ktva(ptr) == 0xf0)
13825 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13826 };
13827 mutex_unlock(&text_mutex);
13828 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13829
13830 BUG_ON(p->len > MAX_PATCH_LEN);
13831 /* prep the buffer with the original instructions */
13832 - memcpy(insnbuf, p->instr, p->len);
13833 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13834 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13835 (unsigned long)p->instr, p->len);
13836
13837 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13838 if (smp_alt_once)
13839 free_init_pages("SMP alternatives",
13840 (unsigned long)__smp_locks,
13841 - (unsigned long)__smp_locks_end);
13842 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13843
13844 restart_nmi();
13845 }
13846 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13847 * instructions. And on the local CPU you need to be protected again NMI or MCE
13848 * handlers seeing an inconsistent instruction while you patch.
13849 */
13850 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13851 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13852 size_t len)
13853 {
13854 unsigned long flags;
13855 local_irq_save(flags);
13856 - memcpy(addr, opcode, len);
13857 +
13858 + pax_open_kernel();
13859 + memcpy(ktla_ktva(addr), opcode, len);
13860 sync_core();
13861 + pax_close_kernel();
13862 +
13863 local_irq_restore(flags);
13864 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13865 that causes hangs on some VIA CPUs. */
13866 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13867 */
13868 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13869 {
13870 - unsigned long flags;
13871 - char *vaddr;
13872 + unsigned char *vaddr = ktla_ktva(addr);
13873 struct page *pages[2];
13874 - int i;
13875 + size_t i;
13876
13877 if (!core_kernel_text((unsigned long)addr)) {
13878 - pages[0] = vmalloc_to_page(addr);
13879 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13880 + pages[0] = vmalloc_to_page(vaddr);
13881 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13882 } else {
13883 - pages[0] = virt_to_page(addr);
13884 + pages[0] = virt_to_page(vaddr);
13885 WARN_ON(!PageReserved(pages[0]));
13886 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13887 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13888 }
13889 BUG_ON(!pages[0]);
13890 - local_irq_save(flags);
13891 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13892 - if (pages[1])
13893 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13894 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13895 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13896 - clear_fixmap(FIX_TEXT_POKE0);
13897 - if (pages[1])
13898 - clear_fixmap(FIX_TEXT_POKE1);
13899 - local_flush_tlb();
13900 - sync_core();
13901 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13902 - that causes hangs on some VIA CPUs. */
13903 + text_poke_early(addr, opcode, len);
13904 for (i = 0; i < len; i++)
13905 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13906 - local_irq_restore(flags);
13907 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13908 return addr;
13909 }
13910
13911 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13912 index 24deb30..94a3426 100644
13913 --- a/arch/x86/kernel/apic/apic.c
13914 +++ b/arch/x86/kernel/apic/apic.c
13915 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13916 /*
13917 * Debug level, exported for io_apic.c
13918 */
13919 -unsigned int apic_verbosity;
13920 +int apic_verbosity;
13921
13922 int pic_mode;
13923
13924 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13925 apic_write(APIC_ESR, 0);
13926 v1 = apic_read(APIC_ESR);
13927 ack_APIC_irq();
13928 - atomic_inc(&irq_err_count);
13929 + atomic_inc_unchecked(&irq_err_count);
13930
13931 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13932 smp_processor_id(), v0 , v1);
13933 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13934 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13935 /* Should happen once for each apic */
13936 WARN_ON((*drv)->eoi_write == eoi_write);
13937 - (*drv)->eoi_write = eoi_write;
13938 + pax_open_kernel();
13939 + *(void **)&(*drv)->eoi_write = eoi_write;
13940 + pax_close_kernel();
13941 }
13942 }
13943
13944 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13945 index c265593..137c4ac 100644
13946 --- a/arch/x86/kernel/apic/io_apic.c
13947 +++ b/arch/x86/kernel/apic/io_apic.c
13948 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13949 }
13950 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13951
13952 -void lock_vector_lock(void)
13953 +void lock_vector_lock(void) __acquires(vector_lock)
13954 {
13955 /* Used to the online set of cpus does not change
13956 * during assign_irq_vector.
13957 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13958 raw_spin_lock(&vector_lock);
13959 }
13960
13961 -void unlock_vector_lock(void)
13962 +void unlock_vector_lock(void) __releases(vector_lock)
13963 {
13964 raw_spin_unlock(&vector_lock);
13965 }
13966 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13967 ack_APIC_irq();
13968 }
13969
13970 -atomic_t irq_mis_count;
13971 +atomic_unchecked_t irq_mis_count;
13972
13973 #ifdef CONFIG_GENERIC_PENDING_IRQ
13974 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13975 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13976 * at the cpu.
13977 */
13978 if (!(v & (1 << (i & 0x1f)))) {
13979 - atomic_inc(&irq_mis_count);
13980 + atomic_inc_unchecked(&irq_mis_count);
13981
13982 eoi_ioapic_irq(irq, cfg);
13983 }
13984 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13985 index d65464e..1035d31 100644
13986 --- a/arch/x86/kernel/apm_32.c
13987 +++ b/arch/x86/kernel/apm_32.c
13988 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
13989 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13990 * even though they are called in protected mode.
13991 */
13992 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13993 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13994 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13995
13996 static const char driver_version[] = "1.16ac"; /* no spaces */
13997 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
13998 BUG_ON(cpu != 0);
13999 gdt = get_cpu_gdt_table(cpu);
14000 save_desc_40 = gdt[0x40 / 8];
14001 +
14002 + pax_open_kernel();
14003 gdt[0x40 / 8] = bad_bios_desc;
14004 + pax_close_kernel();
14005
14006 apm_irq_save(flags);
14007 APM_DO_SAVE_SEGS;
14008 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14009 &call->esi);
14010 APM_DO_RESTORE_SEGS;
14011 apm_irq_restore(flags);
14012 +
14013 + pax_open_kernel();
14014 gdt[0x40 / 8] = save_desc_40;
14015 + pax_close_kernel();
14016 +
14017 put_cpu();
14018
14019 return call->eax & 0xff;
14020 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14021 BUG_ON(cpu != 0);
14022 gdt = get_cpu_gdt_table(cpu);
14023 save_desc_40 = gdt[0x40 / 8];
14024 +
14025 + pax_open_kernel();
14026 gdt[0x40 / 8] = bad_bios_desc;
14027 + pax_close_kernel();
14028
14029 apm_irq_save(flags);
14030 APM_DO_SAVE_SEGS;
14031 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14032 &call->eax);
14033 APM_DO_RESTORE_SEGS;
14034 apm_irq_restore(flags);
14035 +
14036 + pax_open_kernel();
14037 gdt[0x40 / 8] = save_desc_40;
14038 + pax_close_kernel();
14039 +
14040 put_cpu();
14041 return error;
14042 }
14043 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14044 * code to that CPU.
14045 */
14046 gdt = get_cpu_gdt_table(0);
14047 +
14048 + pax_open_kernel();
14049 set_desc_base(&gdt[APM_CS >> 3],
14050 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14051 set_desc_base(&gdt[APM_CS_16 >> 3],
14052 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14053 set_desc_base(&gdt[APM_DS >> 3],
14054 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14055 + pax_close_kernel();
14056
14057 proc_create("apm", 0, NULL, &apm_file_ops);
14058
14059 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14060 index 68de2dc..1f3c720 100644
14061 --- a/arch/x86/kernel/asm-offsets.c
14062 +++ b/arch/x86/kernel/asm-offsets.c
14063 @@ -33,6 +33,8 @@ void common(void) {
14064 OFFSET(TI_status, thread_info, status);
14065 OFFSET(TI_addr_limit, thread_info, addr_limit);
14066 OFFSET(TI_preempt_count, thread_info, preempt_count);
14067 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14068 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14069
14070 BLANK();
14071 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14072 @@ -53,8 +55,26 @@ void common(void) {
14073 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14074 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14075 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14076 +
14077 +#ifdef CONFIG_PAX_KERNEXEC
14078 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14079 #endif
14080
14081 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14082 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14083 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14084 +#ifdef CONFIG_X86_64
14085 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14086 +#endif
14087 +#endif
14088 +
14089 +#endif
14090 +
14091 + BLANK();
14092 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14093 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14094 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14095 +
14096 #ifdef CONFIG_XEN
14097 BLANK();
14098 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14099 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14100 index 1b4754f..fbb4227 100644
14101 --- a/arch/x86/kernel/asm-offsets_64.c
14102 +++ b/arch/x86/kernel/asm-offsets_64.c
14103 @@ -76,6 +76,7 @@ int main(void)
14104 BLANK();
14105 #undef ENTRY
14106
14107 + DEFINE(TSS_size, sizeof(struct tss_struct));
14108 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14109 BLANK();
14110
14111 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14112 index d30a6a9..79becab 100644
14113 --- a/arch/x86/kernel/cpu/Makefile
14114 +++ b/arch/x86/kernel/cpu/Makefile
14115 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14116 CFLAGS_REMOVE_perf_event.o = -pg
14117 endif
14118
14119 -# Make sure load_percpu_segment has no stackprotector
14120 -nostackp := $(call cc-option, -fno-stack-protector)
14121 -CFLAGS_common.o := $(nostackp)
14122 -
14123 obj-y := intel_cacheinfo.o scattered.o topology.o
14124 obj-y += proc.o capflags.o powerflags.o common.o
14125 obj-y += vmware.o hypervisor.o mshyperv.o
14126 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14127 index 9d92e19..49d7d79 100644
14128 --- a/arch/x86/kernel/cpu/amd.c
14129 +++ b/arch/x86/kernel/cpu/amd.c
14130 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14131 unsigned int size)
14132 {
14133 /* AMD errata T13 (order #21922) */
14134 - if ((c->x86 == 6)) {
14135 + if (c->x86 == 6) {
14136 /* Duron Rev A0 */
14137 if (c->x86_model == 3 && c->x86_mask == 0)
14138 size = 64;
14139 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14140 index a5fbc3c..2254849 100644
14141 --- a/arch/x86/kernel/cpu/common.c
14142 +++ b/arch/x86/kernel/cpu/common.c
14143 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14144
14145 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14146
14147 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14148 -#ifdef CONFIG_X86_64
14149 - /*
14150 - * We need valid kernel segments for data and code in long mode too
14151 - * IRET will check the segment types kkeil 2000/10/28
14152 - * Also sysret mandates a special GDT layout
14153 - *
14154 - * TLS descriptors are currently at a different place compared to i386.
14155 - * Hopefully nobody expects them at a fixed place (Wine?)
14156 - */
14157 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14158 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14159 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14160 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14161 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14162 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14163 -#else
14164 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14165 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14166 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14167 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14168 - /*
14169 - * Segments used for calling PnP BIOS have byte granularity.
14170 - * They code segments and data segments have fixed 64k limits,
14171 - * the transfer segment sizes are set at run time.
14172 - */
14173 - /* 32-bit code */
14174 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14175 - /* 16-bit code */
14176 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14177 - /* 16-bit data */
14178 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14179 - /* 16-bit data */
14180 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14181 - /* 16-bit data */
14182 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14183 - /*
14184 - * The APM segments have byte granularity and their bases
14185 - * are set at run time. All have 64k limits.
14186 - */
14187 - /* 32-bit code */
14188 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14189 - /* 16-bit code */
14190 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14191 - /* data */
14192 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14193 -
14194 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14195 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14196 - GDT_STACK_CANARY_INIT
14197 -#endif
14198 -} };
14199 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14200 -
14201 static int __init x86_xsave_setup(char *s)
14202 {
14203 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14204 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14205 {
14206 struct desc_ptr gdt_descr;
14207
14208 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14209 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14210 gdt_descr.size = GDT_SIZE - 1;
14211 load_gdt(&gdt_descr);
14212 /* Reload the per-cpu base */
14213 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14214 /* Filter out anything that depends on CPUID levels we don't have */
14215 filter_cpuid_features(c, true);
14216
14217 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14218 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14219 +#endif
14220 +
14221 /* If the model name is still unset, do table lookup. */
14222 if (!c->x86_model_id[0]) {
14223 const char *p;
14224 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14225 }
14226 __setup("clearcpuid=", setup_disablecpuid);
14227
14228 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14229 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14230 +
14231 #ifdef CONFIG_X86_64
14232 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14233 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14234 - (unsigned long) nmi_idt_table };
14235 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14236
14237 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14238 irq_stack_union) __aligned(PAGE_SIZE);
14239 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14240 EXPORT_PER_CPU_SYMBOL(current_task);
14241
14242 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14243 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14244 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14245 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14246
14247 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14248 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14249 {
14250 memset(regs, 0, sizeof(struct pt_regs));
14251 regs->fs = __KERNEL_PERCPU;
14252 - regs->gs = __KERNEL_STACK_CANARY;
14253 + savesegment(gs, regs->gs);
14254
14255 return regs;
14256 }
14257 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14258 int i;
14259
14260 cpu = stack_smp_processor_id();
14261 - t = &per_cpu(init_tss, cpu);
14262 + t = init_tss + cpu;
14263 oist = &per_cpu(orig_ist, cpu);
14264
14265 #ifdef CONFIG_NUMA
14266 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14267 switch_to_new_gdt(cpu);
14268 loadsegment(fs, 0);
14269
14270 - load_idt((const struct desc_ptr *)&idt_descr);
14271 + load_idt(&idt_descr);
14272
14273 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14274 syscall_init();
14275 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14276 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14277 barrier();
14278
14279 - x86_configure_nx();
14280 if (cpu != 0)
14281 enable_x2apic();
14282
14283 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14284 {
14285 int cpu = smp_processor_id();
14286 struct task_struct *curr = current;
14287 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14288 + struct tss_struct *t = init_tss + cpu;
14289 struct thread_struct *thread = &curr->thread;
14290
14291 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14292 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14293 index 0a4ce29..f211176 100644
14294 --- a/arch/x86/kernel/cpu/intel.c
14295 +++ b/arch/x86/kernel/cpu/intel.c
14296 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14297 * Update the IDT descriptor and reload the IDT so that
14298 * it uses the read-only mapped virtual address.
14299 */
14300 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14301 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14302 load_idt(&idt_descr);
14303 }
14304 #endif
14305 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14306 index 292d025..b520c94 100644
14307 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14308 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14309 @@ -45,6 +45,7 @@
14310 #include <asm/processor.h>
14311 #include <asm/mce.h>
14312 #include <asm/msr.h>
14313 +#include <asm/local.h>
14314
14315 #include "mce-internal.h"
14316
14317 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14318 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14319 m->cs, m->ip);
14320
14321 - if (m->cs == __KERNEL_CS)
14322 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14323 print_symbol("{%s}", m->ip);
14324 pr_cont("\n");
14325 }
14326 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14327
14328 #define PANIC_TIMEOUT 5 /* 5 seconds */
14329
14330 -static atomic_t mce_paniced;
14331 +static atomic_unchecked_t mce_paniced;
14332
14333 static int fake_panic;
14334 -static atomic_t mce_fake_paniced;
14335 +static atomic_unchecked_t mce_fake_paniced;
14336
14337 /* Panic in progress. Enable interrupts and wait for final IPI */
14338 static void wait_for_panic(void)
14339 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14340 /*
14341 * Make sure only one CPU runs in machine check panic
14342 */
14343 - if (atomic_inc_return(&mce_paniced) > 1)
14344 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14345 wait_for_panic();
14346 barrier();
14347
14348 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14349 console_verbose();
14350 } else {
14351 /* Don't log too much for fake panic */
14352 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14353 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14354 return;
14355 }
14356 /* First print corrected ones that are still unlogged */
14357 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14358 * might have been modified by someone else.
14359 */
14360 rmb();
14361 - if (atomic_read(&mce_paniced))
14362 + if (atomic_read_unchecked(&mce_paniced))
14363 wait_for_panic();
14364 if (!monarch_timeout)
14365 goto out;
14366 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14367 }
14368
14369 /* Call the installed machine check handler for this CPU setup. */
14370 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14371 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14372 unexpected_machine_check;
14373
14374 /*
14375 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14376 return;
14377 }
14378
14379 + pax_open_kernel();
14380 machine_check_vector = do_machine_check;
14381 + pax_close_kernel();
14382
14383 __mcheck_cpu_init_generic();
14384 __mcheck_cpu_init_vendor(c);
14385 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14386 */
14387
14388 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14389 -static int mce_chrdev_open_count; /* #times opened */
14390 +static local_t mce_chrdev_open_count; /* #times opened */
14391 static int mce_chrdev_open_exclu; /* already open exclusive? */
14392
14393 static int mce_chrdev_open(struct inode *inode, struct file *file)
14394 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14395 spin_lock(&mce_chrdev_state_lock);
14396
14397 if (mce_chrdev_open_exclu ||
14398 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14399 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14400 spin_unlock(&mce_chrdev_state_lock);
14401
14402 return -EBUSY;
14403 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14404
14405 if (file->f_flags & O_EXCL)
14406 mce_chrdev_open_exclu = 1;
14407 - mce_chrdev_open_count++;
14408 + local_inc(&mce_chrdev_open_count);
14409
14410 spin_unlock(&mce_chrdev_state_lock);
14411
14412 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14413 {
14414 spin_lock(&mce_chrdev_state_lock);
14415
14416 - mce_chrdev_open_count--;
14417 + local_dec(&mce_chrdev_open_count);
14418 mce_chrdev_open_exclu = 0;
14419
14420 spin_unlock(&mce_chrdev_state_lock);
14421 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14422 static void mce_reset(void)
14423 {
14424 cpu_missing = 0;
14425 - atomic_set(&mce_fake_paniced, 0);
14426 + atomic_set_unchecked(&mce_fake_paniced, 0);
14427 atomic_set(&mce_executing, 0);
14428 atomic_set(&mce_callin, 0);
14429 atomic_set(&global_nwo, 0);
14430 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14431 index 2d5454c..51987eb 100644
14432 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14433 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14434 @@ -11,6 +11,7 @@
14435 #include <asm/processor.h>
14436 #include <asm/mce.h>
14437 #include <asm/msr.h>
14438 +#include <asm/pgtable.h>
14439
14440 /* By default disabled */
14441 int mce_p5_enabled __read_mostly;
14442 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14443 if (!cpu_has(c, X86_FEATURE_MCE))
14444 return;
14445
14446 + pax_open_kernel();
14447 machine_check_vector = pentium_machine_check;
14448 + pax_close_kernel();
14449 /* Make sure the vector pointer is visible before we enable MCEs: */
14450 wmb();
14451
14452 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14453 index 2d7998f..17c9de1 100644
14454 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14455 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14456 @@ -10,6 +10,7 @@
14457 #include <asm/processor.h>
14458 #include <asm/mce.h>
14459 #include <asm/msr.h>
14460 +#include <asm/pgtable.h>
14461
14462 /* Machine check handler for WinChip C6: */
14463 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14464 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14465 {
14466 u32 lo, hi;
14467
14468 + pax_open_kernel();
14469 machine_check_vector = winchip_machine_check;
14470 + pax_close_kernel();
14471 /* Make sure the vector pointer is visible before we enable MCEs: */
14472 wmb();
14473
14474 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14475 index 6b96110..0da73eb 100644
14476 --- a/arch/x86/kernel/cpu/mtrr/main.c
14477 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14478 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14479 u64 size_or_mask, size_and_mask;
14480 static bool mtrr_aps_delayed_init;
14481
14482 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14483 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14484
14485 const struct mtrr_ops *mtrr_if;
14486
14487 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14488 index df5e41f..816c719 100644
14489 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14490 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14491 @@ -25,7 +25,7 @@ struct mtrr_ops {
14492 int (*validate_add_page)(unsigned long base, unsigned long size,
14493 unsigned int type);
14494 int (*have_wrcomb)(void);
14495 -};
14496 +} __do_const;
14497
14498 extern int generic_get_free_region(unsigned long base, unsigned long size,
14499 int replace_reg);
14500 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14501 index 915b876..171f845 100644
14502 --- a/arch/x86/kernel/cpu/perf_event.c
14503 +++ b/arch/x86/kernel/cpu/perf_event.c
14504 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14505 if (idx > GDT_ENTRIES)
14506 return 0;
14507
14508 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14509 + desc = get_cpu_gdt_table(smp_processor_id());
14510 }
14511
14512 return get_desc_base(desc + idx);
14513 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14514 break;
14515
14516 perf_callchain_store(entry, frame.return_address);
14517 - fp = frame.next_frame;
14518 + fp = (const void __force_user *)frame.next_frame;
14519 }
14520 }
14521
14522 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14523 index 6bca492..36e4496 100644
14524 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14525 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14526 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14527 * v2 and above have a perf capabilities MSR
14528 */
14529 if (version > 1) {
14530 - u64 capabilities;
14531 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14532
14533 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14534 - x86_pmu.intel_cap.capabilities = capabilities;
14535 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14536 + x86_pmu.intel_cap.capabilities = capabilities;
14537 }
14538
14539 intel_ds_init();
14540 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14541 index 13ad899..f642b9a 100644
14542 --- a/arch/x86/kernel/crash.c
14543 +++ b/arch/x86/kernel/crash.c
14544 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14545 {
14546 #ifdef CONFIG_X86_32
14547 struct pt_regs fixed_regs;
14548 -#endif
14549
14550 -#ifdef CONFIG_X86_32
14551 - if (!user_mode_vm(regs)) {
14552 + if (!user_mode(regs)) {
14553 crash_fixup_ss_esp(&fixed_regs, regs);
14554 regs = &fixed_regs;
14555 }
14556 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14557 index 37250fe..bf2ec74 100644
14558 --- a/arch/x86/kernel/doublefault_32.c
14559 +++ b/arch/x86/kernel/doublefault_32.c
14560 @@ -11,7 +11,7 @@
14561
14562 #define DOUBLEFAULT_STACKSIZE (1024)
14563 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14564 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14565 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14566
14567 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14568
14569 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14570 unsigned long gdt, tss;
14571
14572 store_gdt(&gdt_desc);
14573 - gdt = gdt_desc.address;
14574 + gdt = (unsigned long)gdt_desc.address;
14575
14576 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14577
14578 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14579 /* 0x2 bit is always set */
14580 .flags = X86_EFLAGS_SF | 0x2,
14581 .sp = STACK_START,
14582 - .es = __USER_DS,
14583 + .es = __KERNEL_DS,
14584 .cs = __KERNEL_CS,
14585 .ss = __KERNEL_DS,
14586 - .ds = __USER_DS,
14587 + .ds = __KERNEL_DS,
14588 .fs = __KERNEL_PERCPU,
14589
14590 .__cr3 = __pa_nodebug(swapper_pg_dir),
14591 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14592 index ae42418b..787c16b 100644
14593 --- a/arch/x86/kernel/dumpstack.c
14594 +++ b/arch/x86/kernel/dumpstack.c
14595 @@ -2,6 +2,9 @@
14596 * Copyright (C) 1991, 1992 Linus Torvalds
14597 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14598 */
14599 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14600 +#define __INCLUDED_BY_HIDESYM 1
14601 +#endif
14602 #include <linux/kallsyms.h>
14603 #include <linux/kprobes.h>
14604 #include <linux/uaccess.h>
14605 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14606 static void
14607 print_ftrace_graph_addr(unsigned long addr, void *data,
14608 const struct stacktrace_ops *ops,
14609 - struct thread_info *tinfo, int *graph)
14610 + struct task_struct *task, int *graph)
14611 {
14612 - struct task_struct *task;
14613 unsigned long ret_addr;
14614 int index;
14615
14616 if (addr != (unsigned long)return_to_handler)
14617 return;
14618
14619 - task = tinfo->task;
14620 index = task->curr_ret_stack;
14621
14622 if (!task->ret_stack || index < *graph)
14623 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14624 static inline void
14625 print_ftrace_graph_addr(unsigned long addr, void *data,
14626 const struct stacktrace_ops *ops,
14627 - struct thread_info *tinfo, int *graph)
14628 + struct task_struct *task, int *graph)
14629 { }
14630 #endif
14631
14632 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14634 */
14635
14636 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14637 - void *p, unsigned int size, void *end)
14638 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14639 {
14640 - void *t = tinfo;
14641 if (end) {
14642 if (p < end && p >= (end-THREAD_SIZE))
14643 return 1;
14644 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14645 }
14646
14647 unsigned long
14648 -print_context_stack(struct thread_info *tinfo,
14649 +print_context_stack(struct task_struct *task, void *stack_start,
14650 unsigned long *stack, unsigned long bp,
14651 const struct stacktrace_ops *ops, void *data,
14652 unsigned long *end, int *graph)
14653 {
14654 struct stack_frame *frame = (struct stack_frame *)bp;
14655
14656 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14657 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14658 unsigned long addr;
14659
14660 addr = *stack;
14661 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14662 } else {
14663 ops->address(data, addr, 0);
14664 }
14665 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14666 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14667 }
14668 stack++;
14669 }
14670 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14671 EXPORT_SYMBOL_GPL(print_context_stack);
14672
14673 unsigned long
14674 -print_context_stack_bp(struct thread_info *tinfo,
14675 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14676 unsigned long *stack, unsigned long bp,
14677 const struct stacktrace_ops *ops, void *data,
14678 unsigned long *end, int *graph)
14679 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14680 struct stack_frame *frame = (struct stack_frame *)bp;
14681 unsigned long *ret_addr = &frame->return_address;
14682
14683 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14684 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14685 unsigned long addr = *ret_addr;
14686
14687 if (!__kernel_text_address(addr))
14688 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 ops->address(data, addr, 1);
14690 frame = frame->next_frame;
14691 ret_addr = &frame->return_address;
14692 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14693 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14694 }
14695
14696 return (unsigned long)frame;
14697 @@ -189,7 +188,7 @@ void dump_stack(void)
14698
14699 bp = stack_frame(current, NULL);
14700 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14701 - current->pid, current->comm, print_tainted(),
14702 + task_pid_nr(current), current->comm, print_tainted(),
14703 init_utsname()->release,
14704 (int)strcspn(init_utsname()->version, " "),
14705 init_utsname()->version);
14706 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14707 }
14708 EXPORT_SYMBOL_GPL(oops_begin);
14709
14710 +extern void gr_handle_kernel_exploit(void);
14711 +
14712 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14713 {
14714 if (regs && kexec_should_crash(current))
14715 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14716 panic("Fatal exception in interrupt");
14717 if (panic_on_oops)
14718 panic("Fatal exception");
14719 - do_exit(signr);
14720 +
14721 + gr_handle_kernel_exploit();
14722 +
14723 + do_group_exit(signr);
14724 }
14725
14726 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14727 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14728 print_modules();
14729 show_regs(regs);
14730 #ifdef CONFIG_X86_32
14731 - if (user_mode_vm(regs)) {
14732 + if (user_mode(regs)) {
14733 sp = regs->sp;
14734 ss = regs->ss & 0xffff;
14735 } else {
14736 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14737 unsigned long flags = oops_begin();
14738 int sig = SIGSEGV;
14739
14740 - if (!user_mode_vm(regs))
14741 + if (!user_mode(regs))
14742 report_bug(regs->ip, regs);
14743
14744 if (__die(str, regs, err))
14745 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14746 index 1038a41..ac7e5f6 100644
14747 --- a/arch/x86/kernel/dumpstack_32.c
14748 +++ b/arch/x86/kernel/dumpstack_32.c
14749 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14750 bp = stack_frame(task, regs);
14751
14752 for (;;) {
14753 - struct thread_info *context;
14754 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14755
14756 - context = (struct thread_info *)
14757 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14758 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14759 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14760
14761 - stack = (unsigned long *)context->previous_esp;
14762 - if (!stack)
14763 + if (stack_start == task_stack_page(task))
14764 break;
14765 + stack = *(unsigned long **)stack_start;
14766 if (ops->stack(data, "IRQ") < 0)
14767 break;
14768 touch_nmi_watchdog();
14769 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14770 {
14771 int i;
14772
14773 - __show_regs(regs, !user_mode_vm(regs));
14774 + __show_regs(regs, !user_mode(regs));
14775
14776 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14777 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14778 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14779 * When in-kernel, we also print out the stack and code at the
14780 * time of the fault..
14781 */
14782 - if (!user_mode_vm(regs)) {
14783 + if (!user_mode(regs)) {
14784 unsigned int code_prologue = code_bytes * 43 / 64;
14785 unsigned int code_len = code_bytes;
14786 unsigned char c;
14787 u8 *ip;
14788 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14789
14790 pr_emerg("Stack:\n");
14791 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14792
14793 pr_emerg("Code:");
14794
14795 - ip = (u8 *)regs->ip - code_prologue;
14796 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14797 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14798 /* try starting at IP */
14799 - ip = (u8 *)regs->ip;
14800 + ip = (u8 *)regs->ip + cs_base;
14801 code_len = code_len - code_prologue + 1;
14802 }
14803 for (i = 0; i < code_len; i++, ip++) {
14804 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14805 pr_cont(" Bad EIP value.");
14806 break;
14807 }
14808 - if (ip == (u8 *)regs->ip)
14809 + if (ip == (u8 *)regs->ip + cs_base)
14810 pr_cont(" <%02x>", c);
14811 else
14812 pr_cont(" %02x", c);
14813 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14814 {
14815 unsigned short ud2;
14816
14817 + ip = ktla_ktva(ip);
14818 if (ip < PAGE_OFFSET)
14819 return 0;
14820 if (probe_kernel_address((unsigned short *)ip, ud2))
14821 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14822
14823 return ud2 == 0x0b0f;
14824 }
14825 +
14826 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14827 +void pax_check_alloca(unsigned long size)
14828 +{
14829 + unsigned long sp = (unsigned long)&sp, stack_left;
14830 +
14831 + /* all kernel stacks are of the same size */
14832 + stack_left = sp & (THREAD_SIZE - 1);
14833 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14834 +}
14835 +EXPORT_SYMBOL(pax_check_alloca);
14836 +#endif
14837 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14838 index b653675..33190c0 100644
14839 --- a/arch/x86/kernel/dumpstack_64.c
14840 +++ b/arch/x86/kernel/dumpstack_64.c
14841 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14842 unsigned long *irq_stack_end =
14843 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14844 unsigned used = 0;
14845 - struct thread_info *tinfo;
14846 int graph = 0;
14847 unsigned long dummy;
14848 + void *stack_start;
14849
14850 if (!task)
14851 task = current;
14852 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14853 * current stack address. If the stacks consist of nested
14854 * exceptions
14855 */
14856 - tinfo = task_thread_info(task);
14857 for (;;) {
14858 char *id;
14859 unsigned long *estack_end;
14860 +
14861 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14862 &used, &id);
14863
14864 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14865 if (ops->stack(data, id) < 0)
14866 break;
14867
14868 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14869 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14870 data, estack_end, &graph);
14871 ops->stack(data, "<EOE>");
14872 /*
14873 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 * second-to-last pointer (index -2 to end) in the
14875 * exception stack:
14876 */
14877 + if ((u16)estack_end[-1] != __KERNEL_DS)
14878 + goto out;
14879 stack = (unsigned long *) estack_end[-2];
14880 continue;
14881 }
14882 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14884 if (ops->stack(data, "IRQ") < 0)
14885 break;
14886 - bp = ops->walk_stack(tinfo, stack, bp,
14887 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14888 ops, data, irq_stack_end, &graph);
14889 /*
14890 * We link to the next stack (which would be
14891 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 /*
14893 * This handles the process stack:
14894 */
14895 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14896 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14897 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14898 +out:
14899 put_cpu();
14900 }
14901 EXPORT_SYMBOL(dump_trace);
14902 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14903
14904 return ud2 == 0x0b0f;
14905 }
14906 +
14907 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14908 +void pax_check_alloca(unsigned long size)
14909 +{
14910 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14911 + unsigned cpu, used;
14912 + char *id;
14913 +
14914 + /* check the process stack first */
14915 + stack_start = (unsigned long)task_stack_page(current);
14916 + stack_end = stack_start + THREAD_SIZE;
14917 + if (likely(stack_start <= sp && sp < stack_end)) {
14918 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14919 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14920 + return;
14921 + }
14922 +
14923 + cpu = get_cpu();
14924 +
14925 + /* check the irq stacks */
14926 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14927 + stack_start = stack_end - IRQ_STACK_SIZE;
14928 + if (stack_start <= sp && sp < stack_end) {
14929 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14930 + put_cpu();
14931 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14932 + return;
14933 + }
14934 +
14935 + /* check the exception stacks */
14936 + used = 0;
14937 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14938 + stack_start = stack_end - EXCEPTION_STKSZ;
14939 + if (stack_end && stack_start <= sp && sp < stack_end) {
14940 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14941 + put_cpu();
14942 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14943 + return;
14944 + }
14945 +
14946 + put_cpu();
14947 +
14948 + /* unknown stack */
14949 + BUG();
14950 +}
14951 +EXPORT_SYMBOL(pax_check_alloca);
14952 +#endif
14953 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14954 index 9b9f18b..9fcaa04 100644
14955 --- a/arch/x86/kernel/early_printk.c
14956 +++ b/arch/x86/kernel/early_printk.c
14957 @@ -7,6 +7,7 @@
14958 #include <linux/pci_regs.h>
14959 #include <linux/pci_ids.h>
14960 #include <linux/errno.h>
14961 +#include <linux/sched.h>
14962 #include <asm/io.h>
14963 #include <asm/processor.h>
14964 #include <asm/fcntl.h>
14965 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14966 index 8f8e8ee..3617d6e 100644
14967 --- a/arch/x86/kernel/entry_32.S
14968 +++ b/arch/x86/kernel/entry_32.S
14969 @@ -176,13 +176,153 @@
14970 /*CFI_REL_OFFSET gs, PT_GS*/
14971 .endm
14972 .macro SET_KERNEL_GS reg
14973 +
14974 +#ifdef CONFIG_CC_STACKPROTECTOR
14975 movl $(__KERNEL_STACK_CANARY), \reg
14976 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14977 + movl $(__USER_DS), \reg
14978 +#else
14979 + xorl \reg, \reg
14980 +#endif
14981 +
14982 movl \reg, %gs
14983 .endm
14984
14985 #endif /* CONFIG_X86_32_LAZY_GS */
14986
14987 -.macro SAVE_ALL
14988 +.macro pax_enter_kernel
14989 +#ifdef CONFIG_PAX_KERNEXEC
14990 + call pax_enter_kernel
14991 +#endif
14992 +.endm
14993 +
14994 +.macro pax_exit_kernel
14995 +#ifdef CONFIG_PAX_KERNEXEC
14996 + call pax_exit_kernel
14997 +#endif
14998 +.endm
14999 +
15000 +#ifdef CONFIG_PAX_KERNEXEC
15001 +ENTRY(pax_enter_kernel)
15002 +#ifdef CONFIG_PARAVIRT
15003 + pushl %eax
15004 + pushl %ecx
15005 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15006 + mov %eax, %esi
15007 +#else
15008 + mov %cr0, %esi
15009 +#endif
15010 + bts $16, %esi
15011 + jnc 1f
15012 + mov %cs, %esi
15013 + cmp $__KERNEL_CS, %esi
15014 + jz 3f
15015 + ljmp $__KERNEL_CS, $3f
15016 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15017 +2:
15018 +#ifdef CONFIG_PARAVIRT
15019 + mov %esi, %eax
15020 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15021 +#else
15022 + mov %esi, %cr0
15023 +#endif
15024 +3:
15025 +#ifdef CONFIG_PARAVIRT
15026 + popl %ecx
15027 + popl %eax
15028 +#endif
15029 + ret
15030 +ENDPROC(pax_enter_kernel)
15031 +
15032 +ENTRY(pax_exit_kernel)
15033 +#ifdef CONFIG_PARAVIRT
15034 + pushl %eax
15035 + pushl %ecx
15036 +#endif
15037 + mov %cs, %esi
15038 + cmp $__KERNEXEC_KERNEL_CS, %esi
15039 + jnz 2f
15040 +#ifdef CONFIG_PARAVIRT
15041 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15042 + mov %eax, %esi
15043 +#else
15044 + mov %cr0, %esi
15045 +#endif
15046 + btr $16, %esi
15047 + ljmp $__KERNEL_CS, $1f
15048 +1:
15049 +#ifdef CONFIG_PARAVIRT
15050 + mov %esi, %eax
15051 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15052 +#else
15053 + mov %esi, %cr0
15054 +#endif
15055 +2:
15056 +#ifdef CONFIG_PARAVIRT
15057 + popl %ecx
15058 + popl %eax
15059 +#endif
15060 + ret
15061 +ENDPROC(pax_exit_kernel)
15062 +#endif
15063 +
15064 +.macro pax_erase_kstack
15065 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15066 + call pax_erase_kstack
15067 +#endif
15068 +.endm
15069 +
15070 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15071 +/*
15072 + * ebp: thread_info
15073 + */
15074 +ENTRY(pax_erase_kstack)
15075 + pushl %edi
15076 + pushl %ecx
15077 + pushl %eax
15078 +
15079 + mov TI_lowest_stack(%ebp), %edi
15080 + mov $-0xBEEF, %eax
15081 + std
15082 +
15083 +1: mov %edi, %ecx
15084 + and $THREAD_SIZE_asm - 1, %ecx
15085 + shr $2, %ecx
15086 + repne scasl
15087 + jecxz 2f
15088 +
15089 + cmp $2*16, %ecx
15090 + jc 2f
15091 +
15092 + mov $2*16, %ecx
15093 + repe scasl
15094 + jecxz 2f
15095 + jne 1b
15096 +
15097 +2: cld
15098 + mov %esp, %ecx
15099 + sub %edi, %ecx
15100 +
15101 + cmp $THREAD_SIZE_asm, %ecx
15102 + jb 3f
15103 + ud2
15104 +3:
15105 +
15106 + shr $2, %ecx
15107 + rep stosl
15108 +
15109 + mov TI_task_thread_sp0(%ebp), %edi
15110 + sub $128, %edi
15111 + mov %edi, TI_lowest_stack(%ebp)
15112 +
15113 + popl %eax
15114 + popl %ecx
15115 + popl %edi
15116 + ret
15117 +ENDPROC(pax_erase_kstack)
15118 +#endif
15119 +
15120 +.macro __SAVE_ALL _DS
15121 cld
15122 PUSH_GS
15123 pushl_cfi %fs
15124 @@ -205,7 +345,7 @@
15125 CFI_REL_OFFSET ecx, 0
15126 pushl_cfi %ebx
15127 CFI_REL_OFFSET ebx, 0
15128 - movl $(__USER_DS), %edx
15129 + movl $\_DS, %edx
15130 movl %edx, %ds
15131 movl %edx, %es
15132 movl $(__KERNEL_PERCPU), %edx
15133 @@ -213,6 +353,15 @@
15134 SET_KERNEL_GS %edx
15135 .endm
15136
15137 +.macro SAVE_ALL
15138 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15139 + __SAVE_ALL __KERNEL_DS
15140 + pax_enter_kernel
15141 +#else
15142 + __SAVE_ALL __USER_DS
15143 +#endif
15144 +.endm
15145 +
15146 .macro RESTORE_INT_REGS
15147 popl_cfi %ebx
15148 CFI_RESTORE ebx
15149 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15150 popfl_cfi
15151 jmp syscall_exit
15152 CFI_ENDPROC
15153 -END(ret_from_fork)
15154 +ENDPROC(ret_from_fork)
15155
15156 /*
15157 * Interrupt exit functions should be protected against kprobes
15158 @@ -329,7 +478,15 @@ ret_from_intr:
15159 andl $SEGMENT_RPL_MASK, %eax
15160 #endif
15161 cmpl $USER_RPL, %eax
15162 +
15163 +#ifdef CONFIG_PAX_KERNEXEC
15164 + jae resume_userspace
15165 +
15166 + pax_exit_kernel
15167 + jmp resume_kernel
15168 +#else
15169 jb resume_kernel # not returning to v8086 or userspace
15170 +#endif
15171
15172 ENTRY(resume_userspace)
15173 LOCKDEP_SYS_EXIT
15174 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15175 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15176 # int/exception return?
15177 jne work_pending
15178 - jmp restore_all
15179 -END(ret_from_exception)
15180 + jmp restore_all_pax
15181 +ENDPROC(ret_from_exception)
15182
15183 #ifdef CONFIG_PREEMPT
15184 ENTRY(resume_kernel)
15185 @@ -357,7 +514,7 @@ need_resched:
15186 jz restore_all
15187 call preempt_schedule_irq
15188 jmp need_resched
15189 -END(resume_kernel)
15190 +ENDPROC(resume_kernel)
15191 #endif
15192 CFI_ENDPROC
15193 /*
15194 @@ -391,28 +548,43 @@ sysenter_past_esp:
15195 /*CFI_REL_OFFSET cs, 0*/
15196 /*
15197 * Push current_thread_info()->sysenter_return to the stack.
15198 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15199 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15200 */
15201 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15202 + pushl_cfi $0
15203 CFI_REL_OFFSET eip, 0
15204
15205 pushl_cfi %eax
15206 SAVE_ALL
15207 + GET_THREAD_INFO(%ebp)
15208 + movl TI_sysenter_return(%ebp),%ebp
15209 + movl %ebp,PT_EIP(%esp)
15210 ENABLE_INTERRUPTS(CLBR_NONE)
15211
15212 /*
15213 * Load the potential sixth argument from user stack.
15214 * Careful about security.
15215 */
15216 + movl PT_OLDESP(%esp),%ebp
15217 +
15218 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15219 + mov PT_OLDSS(%esp),%ds
15220 +1: movl %ds:(%ebp),%ebp
15221 + push %ss
15222 + pop %ds
15223 +#else
15224 cmpl $__PAGE_OFFSET-3,%ebp
15225 jae syscall_fault
15226 1: movl (%ebp),%ebp
15227 +#endif
15228 +
15229 movl %ebp,PT_EBP(%esp)
15230 _ASM_EXTABLE(1b,syscall_fault)
15231
15232 GET_THREAD_INFO(%ebp)
15233
15234 +#ifdef CONFIG_PAX_RANDKSTACK
15235 + pax_erase_kstack
15236 +#endif
15237 +
15238 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15239 jnz sysenter_audit
15240 sysenter_do_call:
15241 @@ -427,12 +599,24 @@ sysenter_do_call:
15242 testl $_TIF_ALLWORK_MASK, %ecx
15243 jne sysexit_audit
15244 sysenter_exit:
15245 +
15246 +#ifdef CONFIG_PAX_RANDKSTACK
15247 + pushl_cfi %eax
15248 + movl %esp, %eax
15249 + call pax_randomize_kstack
15250 + popl_cfi %eax
15251 +#endif
15252 +
15253 + pax_erase_kstack
15254 +
15255 /* if something modifies registers it must also disable sysexit */
15256 movl PT_EIP(%esp), %edx
15257 movl PT_OLDESP(%esp), %ecx
15258 xorl %ebp,%ebp
15259 TRACE_IRQS_ON
15260 1: mov PT_FS(%esp), %fs
15261 +2: mov PT_DS(%esp), %ds
15262 +3: mov PT_ES(%esp), %es
15263 PTGS_TO_GS
15264 ENABLE_INTERRUPTS_SYSEXIT
15265
15266 @@ -449,6 +633,9 @@ sysenter_audit:
15267 movl %eax,%edx /* 2nd arg: syscall number */
15268 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15269 call __audit_syscall_entry
15270 +
15271 + pax_erase_kstack
15272 +
15273 pushl_cfi %ebx
15274 movl PT_EAX(%esp),%eax /* reload syscall number */
15275 jmp sysenter_do_call
15276 @@ -474,10 +661,16 @@ sysexit_audit:
15277
15278 CFI_ENDPROC
15279 .pushsection .fixup,"ax"
15280 -2: movl $0,PT_FS(%esp)
15281 +4: movl $0,PT_FS(%esp)
15282 + jmp 1b
15283 +5: movl $0,PT_DS(%esp)
15284 + jmp 1b
15285 +6: movl $0,PT_ES(%esp)
15286 jmp 1b
15287 .popsection
15288 - _ASM_EXTABLE(1b,2b)
15289 + _ASM_EXTABLE(1b,4b)
15290 + _ASM_EXTABLE(2b,5b)
15291 + _ASM_EXTABLE(3b,6b)
15292 PTGS_TO_GS_EX
15293 ENDPROC(ia32_sysenter_target)
15294
15295 @@ -491,6 +684,11 @@ ENTRY(system_call)
15296 pushl_cfi %eax # save orig_eax
15297 SAVE_ALL
15298 GET_THREAD_INFO(%ebp)
15299 +
15300 +#ifdef CONFIG_PAX_RANDKSTACK
15301 + pax_erase_kstack
15302 +#endif
15303 +
15304 # system call tracing in operation / emulation
15305 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15306 jnz syscall_trace_entry
15307 @@ -509,6 +707,15 @@ syscall_exit:
15308 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15309 jne syscall_exit_work
15310
15311 +restore_all_pax:
15312 +
15313 +#ifdef CONFIG_PAX_RANDKSTACK
15314 + movl %esp, %eax
15315 + call pax_randomize_kstack
15316 +#endif
15317 +
15318 + pax_erase_kstack
15319 +
15320 restore_all:
15321 TRACE_IRQS_IRET
15322 restore_all_notrace:
15323 @@ -565,14 +772,34 @@ ldt_ss:
15324 * compensating for the offset by changing to the ESPFIX segment with
15325 * a base address that matches for the difference.
15326 */
15327 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15328 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15329 mov %esp, %edx /* load kernel esp */
15330 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15331 mov %dx, %ax /* eax: new kernel esp */
15332 sub %eax, %edx /* offset (low word is 0) */
15333 +#ifdef CONFIG_SMP
15334 + movl PER_CPU_VAR(cpu_number), %ebx
15335 + shll $PAGE_SHIFT_asm, %ebx
15336 + addl $cpu_gdt_table, %ebx
15337 +#else
15338 + movl $cpu_gdt_table, %ebx
15339 +#endif
15340 shr $16, %edx
15341 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15342 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15343 +
15344 +#ifdef CONFIG_PAX_KERNEXEC
15345 + mov %cr0, %esi
15346 + btr $16, %esi
15347 + mov %esi, %cr0
15348 +#endif
15349 +
15350 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15351 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15352 +
15353 +#ifdef CONFIG_PAX_KERNEXEC
15354 + bts $16, %esi
15355 + mov %esi, %cr0
15356 +#endif
15357 +
15358 pushl_cfi $__ESPFIX_SS
15359 pushl_cfi %eax /* new kernel esp */
15360 /* Disable interrupts, but do not irqtrace this section: we
15361 @@ -601,35 +828,23 @@ work_resched:
15362 movl TI_flags(%ebp), %ecx
15363 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15364 # than syscall tracing?
15365 - jz restore_all
15366 + jz restore_all_pax
15367 testb $_TIF_NEED_RESCHED, %cl
15368 jnz work_resched
15369
15370 work_notifysig: # deal with pending signals and
15371 # notify-resume requests
15372 + movl %esp, %eax
15373 #ifdef CONFIG_VM86
15374 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15375 - movl %esp, %eax
15376 - jne work_notifysig_v86 # returning to kernel-space or
15377 + jz 1f # returning to kernel-space or
15378 # vm86-space
15379 - TRACE_IRQS_ON
15380 - ENABLE_INTERRUPTS(CLBR_NONE)
15381 - movb PT_CS(%esp), %bl
15382 - andb $SEGMENT_RPL_MASK, %bl
15383 - cmpb $USER_RPL, %bl
15384 - jb resume_kernel
15385 - xorl %edx, %edx
15386 - call do_notify_resume
15387 - jmp resume_userspace
15388
15389 - ALIGN
15390 -work_notifysig_v86:
15391 pushl_cfi %ecx # save ti_flags for do_notify_resume
15392 call save_v86_state # %eax contains pt_regs pointer
15393 popl_cfi %ecx
15394 movl %eax, %esp
15395 -#else
15396 - movl %esp, %eax
15397 +1:
15398 #endif
15399 TRACE_IRQS_ON
15400 ENABLE_INTERRUPTS(CLBR_NONE)
15401 @@ -640,7 +855,7 @@ work_notifysig_v86:
15402 xorl %edx, %edx
15403 call do_notify_resume
15404 jmp resume_userspace
15405 -END(work_pending)
15406 +ENDPROC(work_pending)
15407
15408 # perform syscall exit tracing
15409 ALIGN
15410 @@ -648,11 +863,14 @@ syscall_trace_entry:
15411 movl $-ENOSYS,PT_EAX(%esp)
15412 movl %esp, %eax
15413 call syscall_trace_enter
15414 +
15415 + pax_erase_kstack
15416 +
15417 /* What it returned is what we'll actually use. */
15418 cmpl $(NR_syscalls), %eax
15419 jnae syscall_call
15420 jmp syscall_exit
15421 -END(syscall_trace_entry)
15422 +ENDPROC(syscall_trace_entry)
15423
15424 # perform syscall exit tracing
15425 ALIGN
15426 @@ -665,20 +883,24 @@ syscall_exit_work:
15427 movl %esp, %eax
15428 call syscall_trace_leave
15429 jmp resume_userspace
15430 -END(syscall_exit_work)
15431 +ENDPROC(syscall_exit_work)
15432 CFI_ENDPROC
15433
15434 RING0_INT_FRAME # can't unwind into user space anyway
15435 syscall_fault:
15436 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15437 + push %ss
15438 + pop %ds
15439 +#endif
15440 GET_THREAD_INFO(%ebp)
15441 movl $-EFAULT,PT_EAX(%esp)
15442 jmp resume_userspace
15443 -END(syscall_fault)
15444 +ENDPROC(syscall_fault)
15445
15446 syscall_badsys:
15447 movl $-ENOSYS,PT_EAX(%esp)
15448 jmp resume_userspace
15449 -END(syscall_badsys)
15450 +ENDPROC(syscall_badsys)
15451 CFI_ENDPROC
15452 /*
15453 * End of kprobes section
15454 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15455 CFI_ENDPROC
15456 ENDPROC(ptregs_clone)
15457
15458 + ALIGN;
15459 +ENTRY(kernel_execve)
15460 + CFI_STARTPROC
15461 + pushl_cfi %ebp
15462 + sub $PT_OLDSS+4,%esp
15463 + pushl_cfi %edi
15464 + pushl_cfi %ecx
15465 + pushl_cfi %eax
15466 + lea 3*4(%esp),%edi
15467 + mov $PT_OLDSS/4+1,%ecx
15468 + xorl %eax,%eax
15469 + rep stosl
15470 + popl_cfi %eax
15471 + popl_cfi %ecx
15472 + popl_cfi %edi
15473 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15474 + pushl_cfi %esp
15475 + call sys_execve
15476 + add $4,%esp
15477 + CFI_ADJUST_CFA_OFFSET -4
15478 + GET_THREAD_INFO(%ebp)
15479 + test %eax,%eax
15480 + jz syscall_exit
15481 + add $PT_OLDSS+4,%esp
15482 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15483 + popl_cfi %ebp
15484 + ret
15485 + CFI_ENDPROC
15486 +ENDPROC(kernel_execve)
15487 +
15488 .macro FIXUP_ESPFIX_STACK
15489 /*
15490 * Switch back for ESPFIX stack to the normal zerobased stack
15491 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15492 * normal stack and adjusts ESP with the matching offset.
15493 */
15494 /* fixup the stack */
15495 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15496 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15497 +#ifdef CONFIG_SMP
15498 + movl PER_CPU_VAR(cpu_number), %ebx
15499 + shll $PAGE_SHIFT_asm, %ebx
15500 + addl $cpu_gdt_table, %ebx
15501 +#else
15502 + movl $cpu_gdt_table, %ebx
15503 +#endif
15504 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15505 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15506 shl $16, %eax
15507 addl %esp, %eax /* the adjusted stack pointer */
15508 pushl_cfi $__KERNEL_DS
15509 @@ -813,7 +1072,7 @@ vector=vector+1
15510 .endr
15511 2: jmp common_interrupt
15512 .endr
15513 -END(irq_entries_start)
15514 +ENDPROC(irq_entries_start)
15515
15516 .previous
15517 END(interrupt)
15518 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15519 pushl_cfi $do_coprocessor_error
15520 jmp error_code
15521 CFI_ENDPROC
15522 -END(coprocessor_error)
15523 +ENDPROC(coprocessor_error)
15524
15525 ENTRY(simd_coprocessor_error)
15526 RING0_INT_FRAME
15527 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15528 #endif
15529 jmp error_code
15530 CFI_ENDPROC
15531 -END(simd_coprocessor_error)
15532 +ENDPROC(simd_coprocessor_error)
15533
15534 ENTRY(device_not_available)
15535 RING0_INT_FRAME
15536 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15537 pushl_cfi $do_device_not_available
15538 jmp error_code
15539 CFI_ENDPROC
15540 -END(device_not_available)
15541 +ENDPROC(device_not_available)
15542
15543 #ifdef CONFIG_PARAVIRT
15544 ENTRY(native_iret)
15545 iret
15546 _ASM_EXTABLE(native_iret, iret_exc)
15547 -END(native_iret)
15548 +ENDPROC(native_iret)
15549
15550 ENTRY(native_irq_enable_sysexit)
15551 sti
15552 sysexit
15553 -END(native_irq_enable_sysexit)
15554 +ENDPROC(native_irq_enable_sysexit)
15555 #endif
15556
15557 ENTRY(overflow)
15558 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15559 pushl_cfi $do_overflow
15560 jmp error_code
15561 CFI_ENDPROC
15562 -END(overflow)
15563 +ENDPROC(overflow)
15564
15565 ENTRY(bounds)
15566 RING0_INT_FRAME
15567 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15568 pushl_cfi $do_bounds
15569 jmp error_code
15570 CFI_ENDPROC
15571 -END(bounds)
15572 +ENDPROC(bounds)
15573
15574 ENTRY(invalid_op)
15575 RING0_INT_FRAME
15576 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15577 pushl_cfi $do_invalid_op
15578 jmp error_code
15579 CFI_ENDPROC
15580 -END(invalid_op)
15581 +ENDPROC(invalid_op)
15582
15583 ENTRY(coprocessor_segment_overrun)
15584 RING0_INT_FRAME
15585 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15586 pushl_cfi $do_coprocessor_segment_overrun
15587 jmp error_code
15588 CFI_ENDPROC
15589 -END(coprocessor_segment_overrun)
15590 +ENDPROC(coprocessor_segment_overrun)
15591
15592 ENTRY(invalid_TSS)
15593 RING0_EC_FRAME
15594 pushl_cfi $do_invalid_TSS
15595 jmp error_code
15596 CFI_ENDPROC
15597 -END(invalid_TSS)
15598 +ENDPROC(invalid_TSS)
15599
15600 ENTRY(segment_not_present)
15601 RING0_EC_FRAME
15602 pushl_cfi $do_segment_not_present
15603 jmp error_code
15604 CFI_ENDPROC
15605 -END(segment_not_present)
15606 +ENDPROC(segment_not_present)
15607
15608 ENTRY(stack_segment)
15609 RING0_EC_FRAME
15610 pushl_cfi $do_stack_segment
15611 jmp error_code
15612 CFI_ENDPROC
15613 -END(stack_segment)
15614 +ENDPROC(stack_segment)
15615
15616 ENTRY(alignment_check)
15617 RING0_EC_FRAME
15618 pushl_cfi $do_alignment_check
15619 jmp error_code
15620 CFI_ENDPROC
15621 -END(alignment_check)
15622 +ENDPROC(alignment_check)
15623
15624 ENTRY(divide_error)
15625 RING0_INT_FRAME
15626 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15627 pushl_cfi $do_divide_error
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(divide_error)
15631 +ENDPROC(divide_error)
15632
15633 #ifdef CONFIG_X86_MCE
15634 ENTRY(machine_check)
15635 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15636 pushl_cfi machine_check_vector
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(machine_check)
15640 +ENDPROC(machine_check)
15641 #endif
15642
15643 ENTRY(spurious_interrupt_bug)
15644 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15645 pushl_cfi $do_spurious_interrupt_bug
15646 jmp error_code
15647 CFI_ENDPROC
15648 -END(spurious_interrupt_bug)
15649 +ENDPROC(spurious_interrupt_bug)
15650 /*
15651 * End of kprobes section
15652 */
15653 @@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15654
15655 ENTRY(mcount)
15656 ret
15657 -END(mcount)
15658 +ENDPROC(mcount)
15659
15660 ENTRY(ftrace_caller)
15661 cmpl $0, function_trace_stop
15662 @@ -1131,7 +1390,7 @@ ftrace_graph_call:
15663 .globl ftrace_stub
15664 ftrace_stub:
15665 ret
15666 -END(ftrace_caller)
15667 +ENDPROC(ftrace_caller)
15668
15669 #else /* ! CONFIG_DYNAMIC_FTRACE */
15670
15671 @@ -1167,7 +1426,7 @@ trace:
15672 popl %ecx
15673 popl %eax
15674 jmp ftrace_stub
15675 -END(mcount)
15676 +ENDPROC(mcount)
15677 #endif /* CONFIG_DYNAMIC_FTRACE */
15678 #endif /* CONFIG_FUNCTION_TRACER */
15679
15680 @@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15681 popl %ecx
15682 popl %eax
15683 ret
15684 -END(ftrace_graph_caller)
15685 +ENDPROC(ftrace_graph_caller)
15686
15687 .globl return_to_handler
15688 return_to_handler:
15689 @@ -1243,15 +1502,18 @@ error_code:
15690 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15691 REG_TO_PTGS %ecx
15692 SET_KERNEL_GS %ecx
15693 - movl $(__USER_DS), %ecx
15694 + movl $(__KERNEL_DS), %ecx
15695 movl %ecx, %ds
15696 movl %ecx, %es
15697 +
15698 + pax_enter_kernel
15699 +
15700 TRACE_IRQS_OFF
15701 movl %esp,%eax # pt_regs pointer
15702 call *%edi
15703 jmp ret_from_exception
15704 CFI_ENDPROC
15705 -END(page_fault)
15706 +ENDPROC(page_fault)
15707
15708 /*
15709 * Debug traps and NMI can happen at the one SYSENTER instruction
15710 @@ -1293,7 +1555,7 @@ debug_stack_correct:
15711 call do_debug
15712 jmp ret_from_exception
15713 CFI_ENDPROC
15714 -END(debug)
15715 +ENDPROC(debug)
15716
15717 /*
15718 * NMI is doubly nasty. It can happen _while_ we're handling
15719 @@ -1330,6 +1592,9 @@ nmi_stack_correct:
15720 xorl %edx,%edx # zero error code
15721 movl %esp,%eax # pt_regs pointer
15722 call do_nmi
15723 +
15724 + pax_exit_kernel
15725 +
15726 jmp restore_all_notrace
15727 CFI_ENDPROC
15728
15729 @@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15730 FIXUP_ESPFIX_STACK # %eax == %esp
15731 xorl %edx,%edx # zero error code
15732 call do_nmi
15733 +
15734 + pax_exit_kernel
15735 +
15736 RESTORE_REGS
15737 lss 12+4(%esp), %esp # back to espfix stack
15738 CFI_ADJUST_CFA_OFFSET -24
15739 jmp irq_return
15740 CFI_ENDPROC
15741 -END(nmi)
15742 +ENDPROC(nmi)
15743
15744 ENTRY(int3)
15745 RING0_INT_FRAME
15746 @@ -1383,14 +1651,14 @@ ENTRY(int3)
15747 call do_int3
15748 jmp ret_from_exception
15749 CFI_ENDPROC
15750 -END(int3)
15751 +ENDPROC(int3)
15752
15753 ENTRY(general_protection)
15754 RING0_EC_FRAME
15755 pushl_cfi $do_general_protection
15756 jmp error_code
15757 CFI_ENDPROC
15758 -END(general_protection)
15759 +ENDPROC(general_protection)
15760
15761 #ifdef CONFIG_KVM_GUEST
15762 ENTRY(async_page_fault)
15763 @@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15764 pushl_cfi $do_async_page_fault
15765 jmp error_code
15766 CFI_ENDPROC
15767 -END(async_page_fault)
15768 +ENDPROC(async_page_fault)
15769 #endif
15770
15771 /*
15772 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15773 index dcdd0ea..de0bb2d 100644
15774 --- a/arch/x86/kernel/entry_64.S
15775 +++ b/arch/x86/kernel/entry_64.S
15776 @@ -57,6 +57,8 @@
15777 #include <asm/percpu.h>
15778 #include <asm/asm.h>
15779 #include <linux/err.h>
15780 +#include <asm/pgtable.h>
15781 +#include <asm/alternative-asm.h>
15782
15783 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15784 #include <linux/elf-em.h>
15785 @@ -70,8 +72,9 @@
15786 #ifdef CONFIG_FUNCTION_TRACER
15787 #ifdef CONFIG_DYNAMIC_FTRACE
15788 ENTRY(mcount)
15789 + pax_force_retaddr
15790 retq
15791 -END(mcount)
15792 +ENDPROC(mcount)
15793
15794 ENTRY(ftrace_caller)
15795 cmpl $0, function_trace_stop
15796 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15797 #endif
15798
15799 GLOBAL(ftrace_stub)
15800 + pax_force_retaddr
15801 retq
15802 -END(ftrace_caller)
15803 +ENDPROC(ftrace_caller)
15804
15805 #else /* ! CONFIG_DYNAMIC_FTRACE */
15806 ENTRY(mcount)
15807 @@ -114,6 +118,7 @@ ENTRY(mcount)
15808 #endif
15809
15810 GLOBAL(ftrace_stub)
15811 + pax_force_retaddr
15812 retq
15813
15814 trace:
15815 @@ -123,12 +128,13 @@ trace:
15816 movq 8(%rbp), %rsi
15817 subq $MCOUNT_INSN_SIZE, %rdi
15818
15819 + pax_force_fptr ftrace_trace_function
15820 call *ftrace_trace_function
15821
15822 MCOUNT_RESTORE_FRAME
15823
15824 jmp ftrace_stub
15825 -END(mcount)
15826 +ENDPROC(mcount)
15827 #endif /* CONFIG_DYNAMIC_FTRACE */
15828 #endif /* CONFIG_FUNCTION_TRACER */
15829
15830 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15831
15832 MCOUNT_RESTORE_FRAME
15833
15834 + pax_force_retaddr
15835 retq
15836 -END(ftrace_graph_caller)
15837 +ENDPROC(ftrace_graph_caller)
15838
15839 GLOBAL(return_to_handler)
15840 subq $24, %rsp
15841 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15842 movq 8(%rsp), %rdx
15843 movq (%rsp), %rax
15844 addq $24, %rsp
15845 + pax_force_fptr %rdi
15846 jmp *%rdi
15847 #endif
15848
15849 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15850 ENDPROC(native_usergs_sysret64)
15851 #endif /* CONFIG_PARAVIRT */
15852
15853 + .macro ljmpq sel, off
15854 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15855 + .byte 0x48; ljmp *1234f(%rip)
15856 + .pushsection .rodata
15857 + .align 16
15858 + 1234: .quad \off; .word \sel
15859 + .popsection
15860 +#else
15861 + pushq $\sel
15862 + pushq $\off
15863 + lretq
15864 +#endif
15865 + .endm
15866 +
15867 + .macro pax_enter_kernel
15868 + pax_set_fptr_mask
15869 +#ifdef CONFIG_PAX_KERNEXEC
15870 + call pax_enter_kernel
15871 +#endif
15872 + .endm
15873 +
15874 + .macro pax_exit_kernel
15875 +#ifdef CONFIG_PAX_KERNEXEC
15876 + call pax_exit_kernel
15877 +#endif
15878 + .endm
15879 +
15880 +#ifdef CONFIG_PAX_KERNEXEC
15881 +ENTRY(pax_enter_kernel)
15882 + pushq %rdi
15883 +
15884 +#ifdef CONFIG_PARAVIRT
15885 + PV_SAVE_REGS(CLBR_RDI)
15886 +#endif
15887 +
15888 + GET_CR0_INTO_RDI
15889 + bts $16,%rdi
15890 + jnc 3f
15891 + mov %cs,%edi
15892 + cmp $__KERNEL_CS,%edi
15893 + jnz 2f
15894 +1:
15895 +
15896 +#ifdef CONFIG_PARAVIRT
15897 + PV_RESTORE_REGS(CLBR_RDI)
15898 +#endif
15899 +
15900 + popq %rdi
15901 + pax_force_retaddr
15902 + retq
15903 +
15904 +2: ljmpq __KERNEL_CS,1f
15905 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15906 +4: SET_RDI_INTO_CR0
15907 + jmp 1b
15908 +ENDPROC(pax_enter_kernel)
15909 +
15910 +ENTRY(pax_exit_kernel)
15911 + pushq %rdi
15912 +
15913 +#ifdef CONFIG_PARAVIRT
15914 + PV_SAVE_REGS(CLBR_RDI)
15915 +#endif
15916 +
15917 + mov %cs,%rdi
15918 + cmp $__KERNEXEC_KERNEL_CS,%edi
15919 + jz 2f
15920 +1:
15921 +
15922 +#ifdef CONFIG_PARAVIRT
15923 + PV_RESTORE_REGS(CLBR_RDI);
15924 +#endif
15925 +
15926 + popq %rdi
15927 + pax_force_retaddr
15928 + retq
15929 +
15930 +2: GET_CR0_INTO_RDI
15931 + btr $16,%rdi
15932 + ljmpq __KERNEL_CS,3f
15933 +3: SET_RDI_INTO_CR0
15934 + jmp 1b
15935 +#ifdef CONFIG_PARAVIRT
15936 + PV_RESTORE_REGS(CLBR_RDI);
15937 +#endif
15938 +
15939 + popq %rdi
15940 + pax_force_retaddr
15941 + retq
15942 +ENDPROC(pax_exit_kernel)
15943 +#endif
15944 +
15945 + .macro pax_enter_kernel_user
15946 + pax_set_fptr_mask
15947 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15948 + call pax_enter_kernel_user
15949 +#endif
15950 + .endm
15951 +
15952 + .macro pax_exit_kernel_user
15953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15954 + call pax_exit_kernel_user
15955 +#endif
15956 +#ifdef CONFIG_PAX_RANDKSTACK
15957 + pushq %rax
15958 + call pax_randomize_kstack
15959 + popq %rax
15960 +#endif
15961 + .endm
15962 +
15963 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15964 +ENTRY(pax_enter_kernel_user)
15965 + pushq %rdi
15966 + pushq %rbx
15967 +
15968 +#ifdef CONFIG_PARAVIRT
15969 + PV_SAVE_REGS(CLBR_RDI)
15970 +#endif
15971 +
15972 + GET_CR3_INTO_RDI
15973 + mov %rdi,%rbx
15974 + add $__START_KERNEL_map,%rbx
15975 + sub phys_base(%rip),%rbx
15976 +
15977 +#ifdef CONFIG_PARAVIRT
15978 + pushq %rdi
15979 + cmpl $0, pv_info+PARAVIRT_enabled
15980 + jz 1f
15981 + i = 0
15982 + .rept USER_PGD_PTRS
15983 + mov i*8(%rbx),%rsi
15984 + mov $0,%sil
15985 + lea i*8(%rbx),%rdi
15986 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15987 + i = i + 1
15988 + .endr
15989 + jmp 2f
15990 +1:
15991 +#endif
15992 +
15993 + i = 0
15994 + .rept USER_PGD_PTRS
15995 + movb $0,i*8(%rbx)
15996 + i = i + 1
15997 + .endr
15998 +
15999 +#ifdef CONFIG_PARAVIRT
16000 +2: popq %rdi
16001 +#endif
16002 + SET_RDI_INTO_CR3
16003 +
16004 +#ifdef CONFIG_PAX_KERNEXEC
16005 + GET_CR0_INTO_RDI
16006 + bts $16,%rdi
16007 + SET_RDI_INTO_CR0
16008 +#endif
16009 +
16010 +#ifdef CONFIG_PARAVIRT
16011 + PV_RESTORE_REGS(CLBR_RDI)
16012 +#endif
16013 +
16014 + popq %rbx
16015 + popq %rdi
16016 + pax_force_retaddr
16017 + retq
16018 +ENDPROC(pax_enter_kernel_user)
16019 +
16020 +ENTRY(pax_exit_kernel_user)
16021 + push %rdi
16022 +
16023 +#ifdef CONFIG_PARAVIRT
16024 + pushq %rbx
16025 + PV_SAVE_REGS(CLBR_RDI)
16026 +#endif
16027 +
16028 +#ifdef CONFIG_PAX_KERNEXEC
16029 + GET_CR0_INTO_RDI
16030 + btr $16,%rdi
16031 + SET_RDI_INTO_CR0
16032 +#endif
16033 +
16034 + GET_CR3_INTO_RDI
16035 + add $__START_KERNEL_map,%rdi
16036 + sub phys_base(%rip),%rdi
16037 +
16038 +#ifdef CONFIG_PARAVIRT
16039 + cmpl $0, pv_info+PARAVIRT_enabled
16040 + jz 1f
16041 + mov %rdi,%rbx
16042 + i = 0
16043 + .rept USER_PGD_PTRS
16044 + mov i*8(%rbx),%rsi
16045 + mov $0x67,%sil
16046 + lea i*8(%rbx),%rdi
16047 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16048 + i = i + 1
16049 + .endr
16050 + jmp 2f
16051 +1:
16052 +#endif
16053 +
16054 + i = 0
16055 + .rept USER_PGD_PTRS
16056 + movb $0x67,i*8(%rdi)
16057 + i = i + 1
16058 + .endr
16059 +
16060 +#ifdef CONFIG_PARAVIRT
16061 +2: PV_RESTORE_REGS(CLBR_RDI)
16062 + popq %rbx
16063 +#endif
16064 +
16065 + popq %rdi
16066 + pax_force_retaddr
16067 + retq
16068 +ENDPROC(pax_exit_kernel_user)
16069 +#endif
16070 +
16071 +.macro pax_erase_kstack
16072 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16073 + call pax_erase_kstack
16074 +#endif
16075 +.endm
16076 +
16077 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16078 +ENTRY(pax_erase_kstack)
16079 + pushq %rdi
16080 + pushq %rcx
16081 + pushq %rax
16082 + pushq %r11
16083 +
16084 + GET_THREAD_INFO(%r11)
16085 + mov TI_lowest_stack(%r11), %rdi
16086 + mov $-0xBEEF, %rax
16087 + std
16088 +
16089 +1: mov %edi, %ecx
16090 + and $THREAD_SIZE_asm - 1, %ecx
16091 + shr $3, %ecx
16092 + repne scasq
16093 + jecxz 2f
16094 +
16095 + cmp $2*8, %ecx
16096 + jc 2f
16097 +
16098 + mov $2*8, %ecx
16099 + repe scasq
16100 + jecxz 2f
16101 + jne 1b
16102 +
16103 +2: cld
16104 + mov %esp, %ecx
16105 + sub %edi, %ecx
16106 +
16107 + cmp $THREAD_SIZE_asm, %rcx
16108 + jb 3f
16109 + ud2
16110 +3:
16111 +
16112 + shr $3, %ecx
16113 + rep stosq
16114 +
16115 + mov TI_task_thread_sp0(%r11), %rdi
16116 + sub $256, %rdi
16117 + mov %rdi, TI_lowest_stack(%r11)
16118 +
16119 + popq %r11
16120 + popq %rax
16121 + popq %rcx
16122 + popq %rdi
16123 + pax_force_retaddr
16124 + ret
16125 +ENDPROC(pax_erase_kstack)
16126 +#endif
16127
16128 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16129 #ifdef CONFIG_TRACE_IRQFLAGS
16130 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16131 .endm
16132
16133 .macro UNFAKE_STACK_FRAME
16134 - addq $8*6, %rsp
16135 - CFI_ADJUST_CFA_OFFSET -(6*8)
16136 + addq $8*6 + ARG_SKIP, %rsp
16137 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16138 .endm
16139
16140 /*
16141 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16142 movq %rsp, %rsi
16143
16144 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16145 - testl $3, CS-RBP(%rsi)
16146 + testb $3, CS-RBP(%rsi)
16147 je 1f
16148 SWAPGS
16149 /*
16150 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16151 movq_cfi r15, R15+16
16152 movq %r11, 8(%rsp) /* return address */
16153 FIXUP_TOP_OF_STACK %r11, 16
16154 + pax_force_retaddr
16155 ret
16156 CFI_ENDPROC
16157 -END(save_rest)
16158 +ENDPROC(save_rest)
16159
16160 /* save complete stack frame */
16161 .pushsection .kprobes.text, "ax"
16162 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16163 js 1f /* negative -> in kernel */
16164 SWAPGS
16165 xorl %ebx,%ebx
16166 -1: ret
16167 +1: pax_force_retaddr_bts
16168 + ret
16169 CFI_ENDPROC
16170 -END(save_paranoid)
16171 +ENDPROC(save_paranoid)
16172 .popsection
16173
16174 /*
16175 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16176
16177 RESTORE_REST
16178
16179 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16180 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16181 jz retint_restore_args
16182
16183 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16184 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16185 jmp ret_from_sys_call # go to the SYSRET fastpath
16186
16187 CFI_ENDPROC
16188 -END(ret_from_fork)
16189 +ENDPROC(ret_from_fork)
16190
16191 /*
16192 * System call entry. Up to 6 arguments in registers are supported.
16193 @@ -495,7 +779,7 @@ END(ret_from_fork)
16194 ENTRY(system_call)
16195 CFI_STARTPROC simple
16196 CFI_SIGNAL_FRAME
16197 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16198 + CFI_DEF_CFA rsp,0
16199 CFI_REGISTER rip,rcx
16200 /*CFI_REGISTER rflags,r11*/
16201 SWAPGS_UNSAFE_STACK
16202 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16203
16204 movq %rsp,PER_CPU_VAR(old_rsp)
16205 movq PER_CPU_VAR(kernel_stack),%rsp
16206 + SAVE_ARGS 8*6,0
16207 + pax_enter_kernel_user
16208 +
16209 +#ifdef CONFIG_PAX_RANDKSTACK
16210 + pax_erase_kstack
16211 +#endif
16212 +
16213 /*
16214 * No need to follow this irqs off/on section - it's straight
16215 * and short:
16216 */
16217 ENABLE_INTERRUPTS(CLBR_NONE)
16218 - SAVE_ARGS 8,0
16219 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16220 movq %rcx,RIP-ARGOFFSET(%rsp)
16221 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16222 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16223 + GET_THREAD_INFO(%rcx)
16224 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16225 jnz tracesys
16226 system_call_fastpath:
16227 #if __SYSCALL_MASK == ~0
16228 @@ -527,7 +818,7 @@ system_call_fastpath:
16229 cmpl $__NR_syscall_max,%eax
16230 #endif
16231 ja badsys
16232 - movq %r10,%rcx
16233 + movq R10-ARGOFFSET(%rsp),%rcx
16234 call *sys_call_table(,%rax,8) # XXX: rip relative
16235 movq %rax,RAX-ARGOFFSET(%rsp)
16236 /*
16237 @@ -541,10 +832,13 @@ sysret_check:
16238 LOCKDEP_SYS_EXIT
16239 DISABLE_INTERRUPTS(CLBR_NONE)
16240 TRACE_IRQS_OFF
16241 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16242 + GET_THREAD_INFO(%rcx)
16243 + movl TI_flags(%rcx),%edx
16244 andl %edi,%edx
16245 jnz sysret_careful
16246 CFI_REMEMBER_STATE
16247 + pax_exit_kernel_user
16248 + pax_erase_kstack
16249 /*
16250 * sysretq will re-enable interrupts:
16251 */
16252 @@ -596,14 +890,18 @@ badsys:
16253 * jump back to the normal fast path.
16254 */
16255 auditsys:
16256 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16257 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16258 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16259 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16260 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16261 movq %rax,%rsi /* 2nd arg: syscall number */
16262 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16263 call __audit_syscall_entry
16264 +
16265 + pax_erase_kstack
16266 +
16267 LOAD_ARGS 0 /* reload call-clobbered registers */
16268 + pax_set_fptr_mask
16269 jmp system_call_fastpath
16270
16271 /*
16272 @@ -624,7 +922,7 @@ sysret_audit:
16273 /* Do syscall tracing */
16274 tracesys:
16275 #ifdef CONFIG_AUDITSYSCALL
16276 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16277 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16278 jz auditsys
16279 #endif
16280 SAVE_REST
16281 @@ -632,12 +930,16 @@ tracesys:
16282 FIXUP_TOP_OF_STACK %rdi
16283 movq %rsp,%rdi
16284 call syscall_trace_enter
16285 +
16286 + pax_erase_kstack
16287 +
16288 /*
16289 * Reload arg registers from stack in case ptrace changed them.
16290 * We don't reload %rax because syscall_trace_enter() returned
16291 * the value it wants us to use in the table lookup.
16292 */
16293 LOAD_ARGS ARGOFFSET, 1
16294 + pax_set_fptr_mask
16295 RESTORE_REST
16296 #if __SYSCALL_MASK == ~0
16297 cmpq $__NR_syscall_max,%rax
16298 @@ -646,7 +948,7 @@ tracesys:
16299 cmpl $__NR_syscall_max,%eax
16300 #endif
16301 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16302 - movq %r10,%rcx /* fixup for C */
16303 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16304 call *sys_call_table(,%rax,8)
16305 movq %rax,RAX-ARGOFFSET(%rsp)
16306 /* Use IRET because user could have changed frame */
16307 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16308 andl %edi,%edx
16309 jnz int_careful
16310 andl $~TS_COMPAT,TI_status(%rcx)
16311 - jmp retint_swapgs
16312 + pax_exit_kernel_user
16313 + pax_erase_kstack
16314 + jmp retint_swapgs_pax
16315
16316 /* Either reschedule or signal or syscall exit tracking needed. */
16317 /* First do a reschedule test. */
16318 @@ -713,7 +1017,7 @@ int_restore_rest:
16319 TRACE_IRQS_OFF
16320 jmp int_with_check
16321 CFI_ENDPROC
16322 -END(system_call)
16323 +ENDPROC(system_call)
16324
16325 /*
16326 * Certain special system calls that need to save a complete full stack frame.
16327 @@ -729,7 +1033,7 @@ ENTRY(\label)
16328 call \func
16329 jmp ptregscall_common
16330 CFI_ENDPROC
16331 -END(\label)
16332 +ENDPROC(\label)
16333 .endm
16334
16335 PTREGSCALL stub_clone, sys_clone, %r8
16336 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16337 movq_cfi_restore R12+8, r12
16338 movq_cfi_restore RBP+8, rbp
16339 movq_cfi_restore RBX+8, rbx
16340 + pax_force_retaddr
16341 ret $REST_SKIP /* pop extended registers */
16342 CFI_ENDPROC
16343 -END(ptregscall_common)
16344 +ENDPROC(ptregscall_common)
16345
16346 ENTRY(stub_execve)
16347 CFI_STARTPROC
16348 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16349 RESTORE_REST
16350 jmp int_ret_from_sys_call
16351 CFI_ENDPROC
16352 -END(stub_execve)
16353 +ENDPROC(stub_execve)
16354
16355 /*
16356 * sigreturn is special because it needs to restore all registers on return.
16357 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16358 RESTORE_REST
16359 jmp int_ret_from_sys_call
16360 CFI_ENDPROC
16361 -END(stub_rt_sigreturn)
16362 +ENDPROC(stub_rt_sigreturn)
16363
16364 #ifdef CONFIG_X86_X32_ABI
16365 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16366 @@ -851,7 +1156,7 @@ vector=vector+1
16367 2: jmp common_interrupt
16368 .endr
16369 CFI_ENDPROC
16370 -END(irq_entries_start)
16371 +ENDPROC(irq_entries_start)
16372
16373 .previous
16374 END(interrupt)
16375 @@ -871,6 +1176,16 @@ END(interrupt)
16376 subq $ORIG_RAX-RBP, %rsp
16377 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16378 SAVE_ARGS_IRQ
16379 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16380 + testb $3, CS(%rdi)
16381 + jnz 1f
16382 + pax_enter_kernel
16383 + jmp 2f
16384 +1: pax_enter_kernel_user
16385 +2:
16386 +#else
16387 + pax_enter_kernel
16388 +#endif
16389 call \func
16390 .endm
16391
16392 @@ -902,7 +1217,7 @@ ret_from_intr:
16393
16394 exit_intr:
16395 GET_THREAD_INFO(%rcx)
16396 - testl $3,CS-ARGOFFSET(%rsp)
16397 + testb $3,CS-ARGOFFSET(%rsp)
16398 je retint_kernel
16399
16400 /* Interrupt came from user space */
16401 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16402 * The iretq could re-enable interrupts:
16403 */
16404 DISABLE_INTERRUPTS(CLBR_ANY)
16405 + pax_exit_kernel_user
16406 +retint_swapgs_pax:
16407 TRACE_IRQS_IRETQ
16408 SWAPGS
16409 jmp restore_args
16410
16411 retint_restore_args: /* return to kernel space */
16412 DISABLE_INTERRUPTS(CLBR_ANY)
16413 + pax_exit_kernel
16414 + pax_force_retaddr RIP-ARGOFFSET
16415 /*
16416 * The iretq could re-enable interrupts:
16417 */
16418 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16419 #endif
16420
16421 CFI_ENDPROC
16422 -END(common_interrupt)
16423 +ENDPROC(common_interrupt)
16424 /*
16425 * End of kprobes section
16426 */
16427 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16428 interrupt \do_sym
16429 jmp ret_from_intr
16430 CFI_ENDPROC
16431 -END(\sym)
16432 +ENDPROC(\sym)
16433 .endm
16434
16435 #ifdef CONFIG_SMP
16436 @@ -1084,12 +1403,22 @@ ENTRY(\sym)
16437 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16438 call error_entry
16439 DEFAULT_FRAME 0
16440 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16441 + testb $3, CS(%rsp)
16442 + jnz 1f
16443 + pax_enter_kernel
16444 + jmp 2f
16445 +1: pax_enter_kernel_user
16446 +2:
16447 +#else
16448 + pax_enter_kernel
16449 +#endif
16450 movq %rsp,%rdi /* pt_regs pointer */
16451 xorl %esi,%esi /* no error code */
16452 call \do_sym
16453 jmp error_exit /* %ebx: no swapgs flag */
16454 CFI_ENDPROC
16455 -END(\sym)
16456 +ENDPROC(\sym)
16457 .endm
16458
16459 .macro paranoidzeroentry sym do_sym
16460 @@ -1101,15 +1430,25 @@ ENTRY(\sym)
16461 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16462 call save_paranoid
16463 TRACE_IRQS_OFF
16464 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16465 + testb $3, CS(%rsp)
16466 + jnz 1f
16467 + pax_enter_kernel
16468 + jmp 2f
16469 +1: pax_enter_kernel_user
16470 +2:
16471 +#else
16472 + pax_enter_kernel
16473 +#endif
16474 movq %rsp,%rdi /* pt_regs pointer */
16475 xorl %esi,%esi /* no error code */
16476 call \do_sym
16477 jmp paranoid_exit /* %ebx: no swapgs flag */
16478 CFI_ENDPROC
16479 -END(\sym)
16480 +ENDPROC(\sym)
16481 .endm
16482
16483 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16484 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16485 .macro paranoidzeroentry_ist sym do_sym ist
16486 ENTRY(\sym)
16487 INTR_FRAME
16488 @@ -1119,14 +1458,30 @@ ENTRY(\sym)
16489 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16490 call save_paranoid
16491 TRACE_IRQS_OFF_DEBUG
16492 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16493 + testb $3, CS(%rsp)
16494 + jnz 1f
16495 + pax_enter_kernel
16496 + jmp 2f
16497 +1: pax_enter_kernel_user
16498 +2:
16499 +#else
16500 + pax_enter_kernel
16501 +#endif
16502 movq %rsp,%rdi /* pt_regs pointer */
16503 xorl %esi,%esi /* no error code */
16504 +#ifdef CONFIG_SMP
16505 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16506 + lea init_tss(%r12), %r12
16507 +#else
16508 + lea init_tss(%rip), %r12
16509 +#endif
16510 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16511 call \do_sym
16512 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16513 jmp paranoid_exit /* %ebx: no swapgs flag */
16514 CFI_ENDPROC
16515 -END(\sym)
16516 +ENDPROC(\sym)
16517 .endm
16518
16519 .macro errorentry sym do_sym
16520 @@ -1137,13 +1492,23 @@ ENTRY(\sym)
16521 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16522 call error_entry
16523 DEFAULT_FRAME 0
16524 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16525 + testb $3, CS(%rsp)
16526 + jnz 1f
16527 + pax_enter_kernel
16528 + jmp 2f
16529 +1: pax_enter_kernel_user
16530 +2:
16531 +#else
16532 + pax_enter_kernel
16533 +#endif
16534 movq %rsp,%rdi /* pt_regs pointer */
16535 movq ORIG_RAX(%rsp),%rsi /* get error code */
16536 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16537 call \do_sym
16538 jmp error_exit /* %ebx: no swapgs flag */
16539 CFI_ENDPROC
16540 -END(\sym)
16541 +ENDPROC(\sym)
16542 .endm
16543
16544 /* error code is on the stack already */
16545 @@ -1156,13 +1521,23 @@ ENTRY(\sym)
16546 call save_paranoid
16547 DEFAULT_FRAME 0
16548 TRACE_IRQS_OFF
16549 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16550 + testb $3, CS(%rsp)
16551 + jnz 1f
16552 + pax_enter_kernel
16553 + jmp 2f
16554 +1: pax_enter_kernel_user
16555 +2:
16556 +#else
16557 + pax_enter_kernel
16558 +#endif
16559 movq %rsp,%rdi /* pt_regs pointer */
16560 movq ORIG_RAX(%rsp),%rsi /* get error code */
16561 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16562 call \do_sym
16563 jmp paranoid_exit /* %ebx: no swapgs flag */
16564 CFI_ENDPROC
16565 -END(\sym)
16566 +ENDPROC(\sym)
16567 .endm
16568
16569 zeroentry divide_error do_divide_error
16570 @@ -1192,9 +1567,10 @@ gs_change:
16571 2: mfence /* workaround */
16572 SWAPGS
16573 popfq_cfi
16574 + pax_force_retaddr
16575 ret
16576 CFI_ENDPROC
16577 -END(native_load_gs_index)
16578 +ENDPROC(native_load_gs_index)
16579
16580 _ASM_EXTABLE(gs_change,bad_gs)
16581 .section .fixup,"ax"
16582 @@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16583 * Here we are in the child and the registers are set as they were
16584 * at kernel_thread() invocation in the parent.
16585 */
16586 + pax_force_fptr %rsi
16587 call *%rsi
16588 # exit
16589 mov %eax, %edi
16590 call do_exit
16591 ud2 # padding for call trace
16592 CFI_ENDPROC
16593 -END(kernel_thread_helper)
16594 +ENDPROC(kernel_thread_helper)
16595
16596 /*
16597 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16598 @@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16599 RESTORE_REST
16600 testq %rax,%rax
16601 je int_ret_from_sys_call
16602 - RESTORE_ARGS
16603 UNFAKE_STACK_FRAME
16604 + pax_force_retaddr
16605 ret
16606 CFI_ENDPROC
16607 -END(kernel_execve)
16608 +ENDPROC(kernel_execve)
16609
16610 /* Call softirq on interrupt stack. Interrupts are off. */
16611 ENTRY(call_softirq)
16612 @@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16613 CFI_DEF_CFA_REGISTER rsp
16614 CFI_ADJUST_CFA_OFFSET -8
16615 decl PER_CPU_VAR(irq_count)
16616 + pax_force_retaddr
16617 ret
16618 CFI_ENDPROC
16619 -END(call_softirq)
16620 +ENDPROC(call_softirq)
16621
16622 #ifdef CONFIG_XEN
16623 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16624 @@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16625 decl PER_CPU_VAR(irq_count)
16626 jmp error_exit
16627 CFI_ENDPROC
16628 -END(xen_do_hypervisor_callback)
16629 +ENDPROC(xen_do_hypervisor_callback)
16630
16631 /*
16632 * Hypervisor uses this for application faults while it executes.
16633 @@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16634 SAVE_ALL
16635 jmp error_exit
16636 CFI_ENDPROC
16637 -END(xen_failsafe_callback)
16638 +ENDPROC(xen_failsafe_callback)
16639
16640 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16641 xen_hvm_callback_vector xen_evtchn_do_upcall
16642 @@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16643 TRACE_IRQS_OFF_DEBUG
16644 testl %ebx,%ebx /* swapgs needed? */
16645 jnz paranoid_restore
16646 - testl $3,CS(%rsp)
16647 + testb $3,CS(%rsp)
16648 jnz paranoid_userspace
16649 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16650 + pax_exit_kernel
16651 + TRACE_IRQS_IRETQ 0
16652 + SWAPGS_UNSAFE_STACK
16653 + RESTORE_ALL 8
16654 + pax_force_retaddr_bts
16655 + jmp irq_return
16656 +#endif
16657 paranoid_swapgs:
16658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16659 + pax_exit_kernel_user
16660 +#else
16661 + pax_exit_kernel
16662 +#endif
16663 TRACE_IRQS_IRETQ 0
16664 SWAPGS_UNSAFE_STACK
16665 RESTORE_ALL 8
16666 jmp irq_return
16667 paranoid_restore:
16668 + pax_exit_kernel
16669 TRACE_IRQS_IRETQ_DEBUG 0
16670 RESTORE_ALL 8
16671 + pax_force_retaddr_bts
16672 jmp irq_return
16673 paranoid_userspace:
16674 GET_THREAD_INFO(%rcx)
16675 @@ -1454,7 +1847,7 @@ paranoid_schedule:
16676 TRACE_IRQS_OFF
16677 jmp paranoid_userspace
16678 CFI_ENDPROC
16679 -END(paranoid_exit)
16680 +ENDPROC(paranoid_exit)
16681
16682 /*
16683 * Exception entry point. This expects an error code/orig_rax on the stack.
16684 @@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16685 movq_cfi r14, R14+8
16686 movq_cfi r15, R15+8
16687 xorl %ebx,%ebx
16688 - testl $3,CS+8(%rsp)
16689 + testb $3,CS+8(%rsp)
16690 je error_kernelspace
16691 error_swapgs:
16692 SWAPGS
16693 error_sti:
16694 TRACE_IRQS_OFF
16695 + pax_force_retaddr_bts
16696 ret
16697
16698 /*
16699 @@ -1513,7 +1907,7 @@ bstep_iret:
16700 movq %rcx,RIP+8(%rsp)
16701 jmp error_swapgs
16702 CFI_ENDPROC
16703 -END(error_entry)
16704 +ENDPROC(error_entry)
16705
16706
16707 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16708 @@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16709 jnz retint_careful
16710 jmp retint_swapgs
16711 CFI_ENDPROC
16712 -END(error_exit)
16713 +ENDPROC(error_exit)
16714
16715 /*
16716 * Test if a given stack is an NMI stack or not.
16717 @@ -1591,9 +1985,11 @@ ENTRY(nmi)
16718 * If %cs was not the kernel segment, then the NMI triggered in user
16719 * space, which means it is definitely not nested.
16720 */
16721 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16722 + je 1f
16723 cmpl $__KERNEL_CS, 16(%rsp)
16724 jne first_nmi
16725 -
16726 +1:
16727 /*
16728 * Check the special variable on the stack to see if NMIs are
16729 * executing.
16730 @@ -1752,6 +2148,17 @@ end_repeat_nmi:
16731 */
16732 movq %cr2, %r12
16733
16734 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16735 + testb $3, CS(%rsp)
16736 + jnz 1f
16737 + pax_enter_kernel
16738 + jmp 2f
16739 +1: pax_enter_kernel_user
16740 +2:
16741 +#else
16742 + pax_enter_kernel
16743 +#endif
16744 +
16745 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16746 movq %rsp,%rdi
16747 movq $-1,%rsi
16748 @@ -1767,21 +2174,32 @@ end_repeat_nmi:
16749 testl %ebx,%ebx /* swapgs needed? */
16750 jnz nmi_restore
16751 nmi_swapgs:
16752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16753 + pax_exit_kernel_user
16754 +#else
16755 + pax_exit_kernel
16756 +#endif
16757 SWAPGS_UNSAFE_STACK
16758 + RESTORE_ALL 8
16759 + /* Clear the NMI executing stack variable */
16760 + movq $0, 10*8(%rsp)
16761 + jmp irq_return
16762 nmi_restore:
16763 + pax_exit_kernel
16764 RESTORE_ALL 8
16765 + pax_force_retaddr_bts
16766 /* Clear the NMI executing stack variable */
16767 movq $0, 10*8(%rsp)
16768 jmp irq_return
16769 CFI_ENDPROC
16770 -END(nmi)
16771 +ENDPROC(nmi)
16772
16773 ENTRY(ignore_sysret)
16774 CFI_STARTPROC
16775 mov $-ENOSYS,%eax
16776 sysret
16777 CFI_ENDPROC
16778 -END(ignore_sysret)
16779 +ENDPROC(ignore_sysret)
16780
16781 /*
16782 * End of kprobes section
16783 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16784 index c3a7cb4..3ad00dc 100644
16785 --- a/arch/x86/kernel/ftrace.c
16786 +++ b/arch/x86/kernel/ftrace.c
16787 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16788 {
16789 unsigned char replaced[MCOUNT_INSN_SIZE];
16790
16791 + ip = ktla_ktva(ip);
16792 +
16793 /*
16794 * Note: Due to modules and __init, code can
16795 * disappear and change, we need to protect against faulting
16796 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16797 unsigned char old[MCOUNT_INSN_SIZE], *new;
16798 int ret;
16799
16800 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16801 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16802 new = ftrace_call_replace(ip, (unsigned long)func);
16803
16804 /* See comment above by declaration of modifying_ftrace_code */
16805 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16806 {
16807 unsigned char code[MCOUNT_INSN_SIZE];
16808
16809 + ip = ktla_ktva(ip);
16810 +
16811 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16812 return -EFAULT;
16813
16814 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16815 index c18f59d..9c0c9f6 100644
16816 --- a/arch/x86/kernel/head32.c
16817 +++ b/arch/x86/kernel/head32.c
16818 @@ -18,6 +18,7 @@
16819 #include <asm/io_apic.h>
16820 #include <asm/bios_ebda.h>
16821 #include <asm/tlbflush.h>
16822 +#include <asm/boot.h>
16823
16824 static void __init i386_default_early_setup(void)
16825 {
16826 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16827
16828 void __init i386_start_kernel(void)
16829 {
16830 - memblock_reserve(__pa_symbol(&_text),
16831 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16832 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16833
16834 #ifdef CONFIG_BLK_DEV_INITRD
16835 /* Reserve INITRD */
16836 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16837 index d42ab17..87b9555 100644
16838 --- a/arch/x86/kernel/head_32.S
16839 +++ b/arch/x86/kernel/head_32.S
16840 @@ -26,6 +26,12 @@
16841 /* Physical address */
16842 #define pa(X) ((X) - __PAGE_OFFSET)
16843
16844 +#ifdef CONFIG_PAX_KERNEXEC
16845 +#define ta(X) (X)
16846 +#else
16847 +#define ta(X) ((X) - __PAGE_OFFSET)
16848 +#endif
16849 +
16850 /*
16851 * References to members of the new_cpu_data structure.
16852 */
16853 @@ -55,11 +61,7 @@
16854 * and small than max_low_pfn, otherwise will waste some page table entries
16855 */
16856
16857 -#if PTRS_PER_PMD > 1
16858 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16859 -#else
16860 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16861 -#endif
16862 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16863
16864 /* Number of possible pages in the lowmem region */
16865 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16866 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16867 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16868
16869 /*
16870 + * Real beginning of normal "text" segment
16871 + */
16872 +ENTRY(stext)
16873 +ENTRY(_stext)
16874 +
16875 +/*
16876 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16877 * %esi points to the real-mode code as a 32-bit pointer.
16878 * CS and DS must be 4 GB flat segments, but we don't depend on
16879 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16880 * can.
16881 */
16882 __HEAD
16883 +
16884 +#ifdef CONFIG_PAX_KERNEXEC
16885 + jmp startup_32
16886 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16887 +.fill PAGE_SIZE-5,1,0xcc
16888 +#endif
16889 +
16890 ENTRY(startup_32)
16891 movl pa(stack_start),%ecx
16892
16893 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16894 2:
16895 leal -__PAGE_OFFSET(%ecx),%esp
16896
16897 +#ifdef CONFIG_SMP
16898 + movl $pa(cpu_gdt_table),%edi
16899 + movl $__per_cpu_load,%eax
16900 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16901 + rorl $16,%eax
16902 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16903 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16904 + movl $__per_cpu_end - 1,%eax
16905 + subl $__per_cpu_start,%eax
16906 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16907 +#endif
16908 +
16909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16910 + movl $NR_CPUS,%ecx
16911 + movl $pa(cpu_gdt_table),%edi
16912 +1:
16913 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16914 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16915 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16916 + addl $PAGE_SIZE_asm,%edi
16917 + loop 1b
16918 +#endif
16919 +
16920 +#ifdef CONFIG_PAX_KERNEXEC
16921 + movl $pa(boot_gdt),%edi
16922 + movl $__LOAD_PHYSICAL_ADDR,%eax
16923 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16924 + rorl $16,%eax
16925 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16926 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16927 + rorl $16,%eax
16928 +
16929 + ljmp $(__BOOT_CS),$1f
16930 +1:
16931 +
16932 + movl $NR_CPUS,%ecx
16933 + movl $pa(cpu_gdt_table),%edi
16934 + addl $__PAGE_OFFSET,%eax
16935 +1:
16936 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16937 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16938 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16939 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16940 + rorl $16,%eax
16941 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16942 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16943 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16944 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16945 + rorl $16,%eax
16946 + addl $PAGE_SIZE_asm,%edi
16947 + loop 1b
16948 +#endif
16949 +
16950 /*
16951 * Clear BSS first so that there are no surprises...
16952 */
16953 @@ -196,8 +264,11 @@ ENTRY(startup_32)
16954 movl %eax, pa(max_pfn_mapped)
16955
16956 /* Do early initialization of the fixmap area */
16957 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16958 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16959 +#ifdef CONFIG_COMPAT_VDSO
16960 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16961 +#else
16962 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16963 +#endif
16964 #else /* Not PAE */
16965
16966 page_pde_offset = (__PAGE_OFFSET >> 20);
16967 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16968 movl %eax, pa(max_pfn_mapped)
16969
16970 /* Do early initialization of the fixmap area */
16971 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16972 - movl %eax,pa(initial_page_table+0xffc)
16973 +#ifdef CONFIG_COMPAT_VDSO
16974 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16975 +#else
16976 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16977 +#endif
16978 #endif
16979
16980 #ifdef CONFIG_PARAVIRT
16981 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16982 cmpl $num_subarch_entries, %eax
16983 jae bad_subarch
16984
16985 - movl pa(subarch_entries)(,%eax,4), %eax
16986 - subl $__PAGE_OFFSET, %eax
16987 - jmp *%eax
16988 + jmp *pa(subarch_entries)(,%eax,4)
16989
16990 bad_subarch:
16991 WEAK(lguest_entry)
16992 @@ -256,10 +328,10 @@ WEAK(xen_entry)
16993 __INITDATA
16994
16995 subarch_entries:
16996 - .long default_entry /* normal x86/PC */
16997 - .long lguest_entry /* lguest hypervisor */
16998 - .long xen_entry /* Xen hypervisor */
16999 - .long default_entry /* Moorestown MID */
17000 + .long ta(default_entry) /* normal x86/PC */
17001 + .long ta(lguest_entry) /* lguest hypervisor */
17002 + .long ta(xen_entry) /* Xen hypervisor */
17003 + .long ta(default_entry) /* Moorestown MID */
17004 num_subarch_entries = (. - subarch_entries) / 4
17005 .previous
17006 #else
17007 @@ -310,6 +382,7 @@ default_entry:
17008 orl %edx,%eax
17009 movl %eax,%cr4
17010
17011 +#ifdef CONFIG_X86_PAE
17012 testb $X86_CR4_PAE, %al # check if PAE is enabled
17013 jz 6f
17014
17015 @@ -338,6 +411,9 @@ default_entry:
17016 /* Make changes effective */
17017 wrmsr
17018
17019 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17020 +#endif
17021 +
17022 6:
17023
17024 /*
17025 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17026 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17027 movl %eax,%ss # after changing gdt.
17028
17029 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17030 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17031 movl %eax,%ds
17032 movl %eax,%es
17033
17034 movl $(__KERNEL_PERCPU), %eax
17035 movl %eax,%fs # set this cpu's percpu
17036
17037 +#ifdef CONFIG_CC_STACKPROTECTOR
17038 movl $(__KERNEL_STACK_CANARY),%eax
17039 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17040 + movl $(__USER_DS),%eax
17041 +#else
17042 + xorl %eax,%eax
17043 +#endif
17044 movl %eax,%gs
17045
17046 xorl %eax,%eax # Clear LDT
17047 @@ -520,8 +602,11 @@ setup_once:
17048 * relocation. Manually set base address in stack canary
17049 * segment descriptor.
17050 */
17051 - movl $gdt_page,%eax
17052 + movl $cpu_gdt_table,%eax
17053 movl $stack_canary,%ecx
17054 +#ifdef CONFIG_SMP
17055 + addl $__per_cpu_load,%ecx
17056 +#endif
17057 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17058 shrl $16, %ecx
17059 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17060 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17061 /* This is global to keep gas from relaxing the jumps */
17062 ENTRY(early_idt_handler)
17063 cld
17064 - cmpl $2,%ss:early_recursion_flag
17065 + cmpl $1,%ss:early_recursion_flag
17066 je hlt_loop
17067 incl %ss:early_recursion_flag
17068
17069 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17070 pushl (20+6*4)(%esp) /* trapno */
17071 pushl $fault_msg
17072 call printk
17073 -#endif
17074 call dump_stack
17075 +#endif
17076 hlt_loop:
17077 hlt
17078 jmp hlt_loop
17079 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17080 /* This is the default interrupt "handler" :-) */
17081 ALIGN
17082 ignore_int:
17083 - cld
17084 #ifdef CONFIG_PRINTK
17085 + cmpl $2,%ss:early_recursion_flag
17086 + je hlt_loop
17087 + incl %ss:early_recursion_flag
17088 + cld
17089 pushl %eax
17090 pushl %ecx
17091 pushl %edx
17092 @@ -620,9 +708,6 @@ ignore_int:
17093 movl $(__KERNEL_DS),%eax
17094 movl %eax,%ds
17095 movl %eax,%es
17096 - cmpl $2,early_recursion_flag
17097 - je hlt_loop
17098 - incl early_recursion_flag
17099 pushl 16(%esp)
17100 pushl 24(%esp)
17101 pushl 32(%esp)
17102 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17103 /*
17104 * BSS section
17105 */
17106 -__PAGE_ALIGNED_BSS
17107 - .align PAGE_SIZE
17108 #ifdef CONFIG_X86_PAE
17109 +.section .initial_pg_pmd,"a",@progbits
17110 initial_pg_pmd:
17111 .fill 1024*KPMDS,4,0
17112 #else
17113 +.section .initial_page_table,"a",@progbits
17114 ENTRY(initial_page_table)
17115 .fill 1024,4,0
17116 #endif
17117 +.section .initial_pg_fixmap,"a",@progbits
17118 initial_pg_fixmap:
17119 .fill 1024,4,0
17120 +.section .empty_zero_page,"a",@progbits
17121 ENTRY(empty_zero_page)
17122 .fill 4096,1,0
17123 +.section .swapper_pg_dir,"a",@progbits
17124 ENTRY(swapper_pg_dir)
17125 +#ifdef CONFIG_X86_PAE
17126 + .fill 4,8,0
17127 +#else
17128 .fill 1024,4,0
17129 +#endif
17130 +
17131 +/*
17132 + * The IDT has to be page-aligned to simplify the Pentium
17133 + * F0 0F bug workaround.. We have a special link segment
17134 + * for this.
17135 + */
17136 +.section .idt,"a",@progbits
17137 +ENTRY(idt_table)
17138 + .fill 256,8,0
17139
17140 /*
17141 * This starts the data section.
17142 */
17143 #ifdef CONFIG_X86_PAE
17144 -__PAGE_ALIGNED_DATA
17145 - /* Page-aligned for the benefit of paravirt? */
17146 - .align PAGE_SIZE
17147 +.section .initial_page_table,"a",@progbits
17148 ENTRY(initial_page_table)
17149 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17150 # if KPMDS == 3
17151 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17152 # error "Kernel PMDs should be 1, 2 or 3"
17153 # endif
17154 .align PAGE_SIZE /* needs to be page-sized too */
17155 +
17156 +#ifdef CONFIG_PAX_PER_CPU_PGD
17157 +ENTRY(cpu_pgd)
17158 + .rept NR_CPUS
17159 + .fill 4,8,0
17160 + .endr
17161 +#endif
17162 +
17163 #endif
17164
17165 .data
17166 .balign 4
17167 ENTRY(stack_start)
17168 - .long init_thread_union+THREAD_SIZE
17169 + .long init_thread_union+THREAD_SIZE-8
17170
17171 __INITRODATA
17172 int_msg:
17173 @@ -730,7 +837,7 @@ fault_msg:
17174 * segment size, and 32-bit linear address value:
17175 */
17176
17177 - .data
17178 +.section .rodata,"a",@progbits
17179 .globl boot_gdt_descr
17180 .globl idt_descr
17181
17182 @@ -739,7 +846,7 @@ fault_msg:
17183 .word 0 # 32 bit align gdt_desc.address
17184 boot_gdt_descr:
17185 .word __BOOT_DS+7
17186 - .long boot_gdt - __PAGE_OFFSET
17187 + .long pa(boot_gdt)
17188
17189 .word 0 # 32-bit align idt_desc.address
17190 idt_descr:
17191 @@ -750,7 +857,7 @@ idt_descr:
17192 .word 0 # 32 bit align gdt_desc.address
17193 ENTRY(early_gdt_descr)
17194 .word GDT_ENTRIES*8-1
17195 - .long gdt_page /* Overwritten for secondary CPUs */
17196 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17197
17198 /*
17199 * The boot_gdt must mirror the equivalent in setup.S and is
17200 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17201 .align L1_CACHE_BYTES
17202 ENTRY(boot_gdt)
17203 .fill GDT_ENTRY_BOOT_CS,8,0
17204 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17205 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17206 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17207 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17208 +
17209 + .align PAGE_SIZE_asm
17210 +ENTRY(cpu_gdt_table)
17211 + .rept NR_CPUS
17212 + .quad 0x0000000000000000 /* NULL descriptor */
17213 + .quad 0x0000000000000000 /* 0x0b reserved */
17214 + .quad 0x0000000000000000 /* 0x13 reserved */
17215 + .quad 0x0000000000000000 /* 0x1b reserved */
17216 +
17217 +#ifdef CONFIG_PAX_KERNEXEC
17218 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17219 +#else
17220 + .quad 0x0000000000000000 /* 0x20 unused */
17221 +#endif
17222 +
17223 + .quad 0x0000000000000000 /* 0x28 unused */
17224 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17225 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17226 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17227 + .quad 0x0000000000000000 /* 0x4b reserved */
17228 + .quad 0x0000000000000000 /* 0x53 reserved */
17229 + .quad 0x0000000000000000 /* 0x5b reserved */
17230 +
17231 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17232 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17233 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17234 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17235 +
17236 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17237 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17238 +
17239 + /*
17240 + * Segments used for calling PnP BIOS have byte granularity.
17241 + * The code segments and data segments have fixed 64k limits,
17242 + * the transfer segment sizes are set at run time.
17243 + */
17244 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17245 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17246 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17247 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17248 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17249 +
17250 + /*
17251 + * The APM segments have byte granularity and their bases
17252 + * are set at run time. All have 64k limits.
17253 + */
17254 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17255 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17256 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17257 +
17258 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17259 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17260 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17261 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17262 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17263 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17264 +
17265 + /* Be sure this is zeroed to avoid false validations in Xen */
17266 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17267 + .endr
17268 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17269 index 94bf9cc..400455a 100644
17270 --- a/arch/x86/kernel/head_64.S
17271 +++ b/arch/x86/kernel/head_64.S
17272 @@ -20,6 +20,8 @@
17273 #include <asm/processor-flags.h>
17274 #include <asm/percpu.h>
17275 #include <asm/nops.h>
17276 +#include <asm/cpufeature.h>
17277 +#include <asm/alternative-asm.h>
17278
17279 #ifdef CONFIG_PARAVIRT
17280 #include <asm/asm-offsets.h>
17281 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17282 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17283 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17284 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17285 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17286 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17287 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17288 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17289 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17290 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17291
17292 .text
17293 __HEAD
17294 @@ -88,35 +96,23 @@ startup_64:
17295 */
17296 addq %rbp, init_level4_pgt + 0(%rip)
17297 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17298 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17299 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17300 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17301 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17302
17303 addq %rbp, level3_ident_pgt + 0(%rip)
17304 +#ifndef CONFIG_XEN
17305 + addq %rbp, level3_ident_pgt + 8(%rip)
17306 +#endif
17307
17308 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17309 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17310 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17311 +
17312 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17313 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17314
17315 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17316 -
17317 - /* Add an Identity mapping if I am above 1G */
17318 - leaq _text(%rip), %rdi
17319 - andq $PMD_PAGE_MASK, %rdi
17320 -
17321 - movq %rdi, %rax
17322 - shrq $PUD_SHIFT, %rax
17323 - andq $(PTRS_PER_PUD - 1), %rax
17324 - jz ident_complete
17325 -
17326 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17327 - leaq level3_ident_pgt(%rip), %rbx
17328 - movq %rdx, 0(%rbx, %rax, 8)
17329 -
17330 - movq %rdi, %rax
17331 - shrq $PMD_SHIFT, %rax
17332 - andq $(PTRS_PER_PMD - 1), %rax
17333 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17334 - leaq level2_spare_pgt(%rip), %rbx
17335 - movq %rdx, 0(%rbx, %rax, 8)
17336 -ident_complete:
17337 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17338
17339 /*
17340 * Fixup the kernel text+data virtual addresses. Note that
17341 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17342 * after the boot processor executes this code.
17343 */
17344
17345 - /* Enable PAE mode and PGE */
17346 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17347 + /* Enable PAE mode and PSE/PGE */
17348 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17349 movq %rax, %cr4
17350
17351 /* Setup early boot stage 4 level pagetables. */
17352 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17353 movl $MSR_EFER, %ecx
17354 rdmsr
17355 btsl $_EFER_SCE, %eax /* Enable System Call */
17356 - btl $20,%edi /* No Execute supported? */
17357 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17358 jnc 1f
17359 btsl $_EFER_NX, %eax
17360 + leaq init_level4_pgt(%rip), %rdi
17361 +#ifndef CONFIG_EFI
17362 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17363 +#endif
17364 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17365 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17366 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17367 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17368 1: wrmsr /* Make changes effective */
17369
17370 /* Setup cr0 */
17371 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17372 * jump. In addition we need to ensure %cs is set so we make this
17373 * a far return.
17374 */
17375 + pax_set_fptr_mask
17376 movq initial_code(%rip),%rax
17377 pushq $0 # fake return address to stop unwinder
17378 pushq $__KERNEL_CS # set correct cs
17379 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17380 bad_address:
17381 jmp bad_address
17382
17383 - .section ".init.text","ax"
17384 + __INIT
17385 .globl early_idt_handlers
17386 early_idt_handlers:
17387 # 104(%rsp) %rflags
17388 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17389 addq $16,%rsp # drop vector number and error code
17390 decl early_recursion_flag(%rip)
17391 INTERRUPT_RETURN
17392 + .previous
17393
17394 + __INITDATA
17395 .balign 4
17396 early_recursion_flag:
17397 .long 0
17398 + .previous
17399
17400 + .section .rodata,"a",@progbits
17401 #ifdef CONFIG_EARLY_PRINTK
17402 early_idt_msg:
17403 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17404 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17405 #endif /* CONFIG_EARLY_PRINTK */
17406 .previous
17407
17408 + .section .rodata,"a",@progbits
17409 #define NEXT_PAGE(name) \
17410 .balign PAGE_SIZE; \
17411 ENTRY(name)
17412 @@ -372,7 +382,6 @@ ENTRY(name)
17413 i = i + 1 ; \
17414 .endr
17415
17416 - .data
17417 /*
17418 * This default setting generates an ident mapping at address 0x100000
17419 * and a mapping for the kernel that precisely maps virtual address
17420 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17421 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17422 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17423 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17424 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17425 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17426 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17427 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17428 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17429 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17430 .org init_level4_pgt + L4_START_KERNEL*8, 0
17431 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17432 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17433
17434 +#ifdef CONFIG_PAX_PER_CPU_PGD
17435 +NEXT_PAGE(cpu_pgd)
17436 + .rept NR_CPUS
17437 + .fill 512,8,0
17438 + .endr
17439 +#endif
17440 +
17441 NEXT_PAGE(level3_ident_pgt)
17442 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17443 +#ifdef CONFIG_XEN
17444 .fill 511,8,0
17445 +#else
17446 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17447 + .fill 510,8,0
17448 +#endif
17449 +
17450 +NEXT_PAGE(level3_vmalloc_start_pgt)
17451 + .fill 512,8,0
17452 +
17453 +NEXT_PAGE(level3_vmalloc_end_pgt)
17454 + .fill 512,8,0
17455 +
17456 +NEXT_PAGE(level3_vmemmap_pgt)
17457 + .fill L3_VMEMMAP_START,8,0
17458 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17459
17460 NEXT_PAGE(level3_kernel_pgt)
17461 .fill L3_START_KERNEL,8,0
17462 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17463 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17464 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17465
17466 +NEXT_PAGE(level2_vmemmap_pgt)
17467 + .fill 512,8,0
17468 +
17469 NEXT_PAGE(level2_fixmap_pgt)
17470 - .fill 506,8,0
17471 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17472 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17473 - .fill 5,8,0
17474 + .fill 507,8,0
17475 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17476 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17477 + .fill 4,8,0
17478
17479 -NEXT_PAGE(level1_fixmap_pgt)
17480 +NEXT_PAGE(level1_vsyscall_pgt)
17481 .fill 512,8,0
17482
17483 -NEXT_PAGE(level2_ident_pgt)
17484 - /* Since I easily can, map the first 1G.
17485 + /* Since I easily can, map the first 2G.
17486 * Don't set NX because code runs from these pages.
17487 */
17488 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17489 +NEXT_PAGE(level2_ident_pgt)
17490 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17491
17492 NEXT_PAGE(level2_kernel_pgt)
17493 /*
17494 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17495 * If you want to increase this then increase MODULES_VADDR
17496 * too.)
17497 */
17498 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17499 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17500 -
17501 -NEXT_PAGE(level2_spare_pgt)
17502 - .fill 512, 8, 0
17503 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17504
17505 #undef PMDS
17506 #undef NEXT_PAGE
17507
17508 - .data
17509 + .align PAGE_SIZE
17510 +ENTRY(cpu_gdt_table)
17511 + .rept NR_CPUS
17512 + .quad 0x0000000000000000 /* NULL descriptor */
17513 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17514 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17515 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17516 + .quad 0x00cffb000000ffff /* __USER32_CS */
17517 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17518 + .quad 0x00affb000000ffff /* __USER_CS */
17519 +
17520 +#ifdef CONFIG_PAX_KERNEXEC
17521 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17522 +#else
17523 + .quad 0x0 /* unused */
17524 +#endif
17525 +
17526 + .quad 0,0 /* TSS */
17527 + .quad 0,0 /* LDT */
17528 + .quad 0,0,0 /* three TLS descriptors */
17529 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17530 + /* asm/segment.h:GDT_ENTRIES must match this */
17531 +
17532 + /* zero the remaining page */
17533 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17534 + .endr
17535 +
17536 .align 16
17537 .globl early_gdt_descr
17538 early_gdt_descr:
17539 .word GDT_ENTRIES*8-1
17540 early_gdt_descr_base:
17541 - .quad INIT_PER_CPU_VAR(gdt_page)
17542 + .quad cpu_gdt_table
17543
17544 ENTRY(phys_base)
17545 /* This must match the first entry in level2_kernel_pgt */
17546 .quad 0x0000000000000000
17547
17548 #include "../../x86/xen/xen-head.S"
17549 -
17550 - .section .bss, "aw", @nobits
17551 +
17552 + .section .rodata,"a",@progbits
17553 .align L1_CACHE_BYTES
17554 ENTRY(idt_table)
17555 - .skip IDT_ENTRIES * 16
17556 + .fill 512,8,0
17557
17558 .align L1_CACHE_BYTES
17559 ENTRY(nmi_idt_table)
17560 - .skip IDT_ENTRIES * 16
17561 + .fill 512,8,0
17562
17563 __PAGE_ALIGNED_BSS
17564 .align PAGE_SIZE
17565 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17566 index 9c3bd4a..e1d9b35 100644
17567 --- a/arch/x86/kernel/i386_ksyms_32.c
17568 +++ b/arch/x86/kernel/i386_ksyms_32.c
17569 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17570 EXPORT_SYMBOL(cmpxchg8b_emu);
17571 #endif
17572
17573 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17574 +
17575 /* Networking helper routines. */
17576 EXPORT_SYMBOL(csum_partial_copy_generic);
17577 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17578 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17579
17580 EXPORT_SYMBOL(__get_user_1);
17581 EXPORT_SYMBOL(__get_user_2);
17582 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17583
17584 EXPORT_SYMBOL(csum_partial);
17585 EXPORT_SYMBOL(empty_zero_page);
17586 +
17587 +#ifdef CONFIG_PAX_KERNEXEC
17588 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17589 +#endif
17590 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17591 index f250431..54097e7 100644
17592 --- a/arch/x86/kernel/i387.c
17593 +++ b/arch/x86/kernel/i387.c
17594 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17595 static inline bool interrupted_user_mode(void)
17596 {
17597 struct pt_regs *regs = get_irq_regs();
17598 - return regs && user_mode_vm(regs);
17599 + return regs && user_mode(regs);
17600 }
17601
17602 /*
17603 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17604 index 36d1853..bf25736 100644
17605 --- a/arch/x86/kernel/i8259.c
17606 +++ b/arch/x86/kernel/i8259.c
17607 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17608 "spurious 8259A interrupt: IRQ%d.\n", irq);
17609 spurious_irq_mask |= irqmask;
17610 }
17611 - atomic_inc(&irq_err_count);
17612 + atomic_inc_unchecked(&irq_err_count);
17613 /*
17614 * Theoretically we do not have to handle this IRQ,
17615 * but in Linux this does not cause problems and is
17616 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17617 index 8c96897..be66bfa 100644
17618 --- a/arch/x86/kernel/ioport.c
17619 +++ b/arch/x86/kernel/ioport.c
17620 @@ -6,6 +6,7 @@
17621 #include <linux/sched.h>
17622 #include <linux/kernel.h>
17623 #include <linux/capability.h>
17624 +#include <linux/security.h>
17625 #include <linux/errno.h>
17626 #include <linux/types.h>
17627 #include <linux/ioport.h>
17628 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17629
17630 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17631 return -EINVAL;
17632 +#ifdef CONFIG_GRKERNSEC_IO
17633 + if (turn_on && grsec_disable_privio) {
17634 + gr_handle_ioperm();
17635 + return -EPERM;
17636 + }
17637 +#endif
17638 if (turn_on && !capable(CAP_SYS_RAWIO))
17639 return -EPERM;
17640
17641 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17642 * because the ->io_bitmap_max value must match the bitmap
17643 * contents:
17644 */
17645 - tss = &per_cpu(init_tss, get_cpu());
17646 + tss = init_tss + get_cpu();
17647
17648 if (turn_on)
17649 bitmap_clear(t->io_bitmap_ptr, from, num);
17650 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17651 return -EINVAL;
17652 /* Trying to gain more privileges? */
17653 if (level > old) {
17654 +#ifdef CONFIG_GRKERNSEC_IO
17655 + if (grsec_disable_privio) {
17656 + gr_handle_iopl();
17657 + return -EPERM;
17658 + }
17659 +#endif
17660 if (!capable(CAP_SYS_RAWIO))
17661 return -EPERM;
17662 }
17663 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17664 index d44f782..31ab01e 100644
17665 --- a/arch/x86/kernel/irq.c
17666 +++ b/arch/x86/kernel/irq.c
17667 @@ -18,7 +18,7 @@
17668 #include <asm/mce.h>
17669 #include <asm/hw_irq.h>
17670
17671 -atomic_t irq_err_count;
17672 +atomic_unchecked_t irq_err_count;
17673
17674 /* Function pointer for generic interrupt vector handling */
17675 void (*x86_platform_ipi_callback)(void) = NULL;
17676 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17677 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17678 seq_printf(p, " Machine check polls\n");
17679 #endif
17680 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17681 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17682 #if defined(CONFIG_X86_IO_APIC)
17683 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17684 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17685 #endif
17686 return 0;
17687 }
17688 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17689
17690 u64 arch_irq_stat(void)
17691 {
17692 - u64 sum = atomic_read(&irq_err_count);
17693 + u64 sum = atomic_read_unchecked(&irq_err_count);
17694
17695 #ifdef CONFIG_X86_IO_APIC
17696 - sum += atomic_read(&irq_mis_count);
17697 + sum += atomic_read_unchecked(&irq_mis_count);
17698 #endif
17699 return sum;
17700 }
17701 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17702 index 344faf8..355f60d 100644
17703 --- a/arch/x86/kernel/irq_32.c
17704 +++ b/arch/x86/kernel/irq_32.c
17705 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17706 __asm__ __volatile__("andl %%esp,%0" :
17707 "=r" (sp) : "0" (THREAD_SIZE - 1));
17708
17709 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17710 + return sp < STACK_WARN;
17711 }
17712
17713 static void print_stack_overflow(void)
17714 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17715 * per-CPU IRQ handling contexts (thread information and stack)
17716 */
17717 union irq_ctx {
17718 - struct thread_info tinfo;
17719 - u32 stack[THREAD_SIZE/sizeof(u32)];
17720 + unsigned long previous_esp;
17721 + u32 stack[THREAD_SIZE/sizeof(u32)];
17722 } __attribute__((aligned(THREAD_SIZE)));
17723
17724 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17725 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17726 static inline int
17727 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17728 {
17729 - union irq_ctx *curctx, *irqctx;
17730 + union irq_ctx *irqctx;
17731 u32 *isp, arg1, arg2;
17732
17733 - curctx = (union irq_ctx *) current_thread_info();
17734 irqctx = __this_cpu_read(hardirq_ctx);
17735
17736 /*
17737 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17738 * handler) we can't do that and just have to keep using the
17739 * current stack (which is the irq stack already after all)
17740 */
17741 - if (unlikely(curctx == irqctx))
17742 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17743 return 0;
17744
17745 /* build the stack frame on the IRQ stack */
17746 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17747 - irqctx->tinfo.task = curctx->tinfo.task;
17748 - irqctx->tinfo.previous_esp = current_stack_pointer;
17749 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17750 + irqctx->previous_esp = current_stack_pointer;
17751
17752 - /* Copy the preempt_count so that the [soft]irq checks work. */
17753 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17754 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17755 + __set_fs(MAKE_MM_SEG(0));
17756 +#endif
17757
17758 if (unlikely(overflow))
17759 call_on_stack(print_stack_overflow, isp);
17760 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17761 : "0" (irq), "1" (desc), "2" (isp),
17762 "D" (desc->handle_irq)
17763 : "memory", "cc", "ecx");
17764 +
17765 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17766 + __set_fs(current_thread_info()->addr_limit);
17767 +#endif
17768 +
17769 return 1;
17770 }
17771
17772 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17773 */
17774 void __cpuinit irq_ctx_init(int cpu)
17775 {
17776 - union irq_ctx *irqctx;
17777 -
17778 if (per_cpu(hardirq_ctx, cpu))
17779 return;
17780
17781 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17782 - THREADINFO_GFP,
17783 - THREAD_SIZE_ORDER));
17784 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17785 - irqctx->tinfo.cpu = cpu;
17786 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17787 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17788 -
17789 - per_cpu(hardirq_ctx, cpu) = irqctx;
17790 -
17791 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17792 - THREADINFO_GFP,
17793 - THREAD_SIZE_ORDER));
17794 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17795 - irqctx->tinfo.cpu = cpu;
17796 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17797 -
17798 - per_cpu(softirq_ctx, cpu) = irqctx;
17799 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17800 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17801 +
17802 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17803 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17804
17805 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17806 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17807 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17808 asmlinkage void do_softirq(void)
17809 {
17810 unsigned long flags;
17811 - struct thread_info *curctx;
17812 union irq_ctx *irqctx;
17813 u32 *isp;
17814
17815 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17816 local_irq_save(flags);
17817
17818 if (local_softirq_pending()) {
17819 - curctx = current_thread_info();
17820 irqctx = __this_cpu_read(softirq_ctx);
17821 - irqctx->tinfo.task = curctx->task;
17822 - irqctx->tinfo.previous_esp = current_stack_pointer;
17823 + irqctx->previous_esp = current_stack_pointer;
17824
17825 /* build the stack frame on the softirq stack */
17826 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17827 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17828 +
17829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17830 + __set_fs(MAKE_MM_SEG(0));
17831 +#endif
17832
17833 call_on_stack(__do_softirq, isp);
17834 +
17835 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17836 + __set_fs(current_thread_info()->addr_limit);
17837 +#endif
17838 +
17839 /*
17840 * Shouldn't happen, we returned above if in_interrupt():
17841 */
17842 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17843 if (unlikely(!desc))
17844 return false;
17845
17846 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17847 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17848 if (unlikely(overflow))
17849 print_stack_overflow();
17850 desc->handle_irq(irq, desc);
17851 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17852 index d04d3ec..ea4b374 100644
17853 --- a/arch/x86/kernel/irq_64.c
17854 +++ b/arch/x86/kernel/irq_64.c
17855 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17856 u64 estack_top, estack_bottom;
17857 u64 curbase = (u64)task_stack_page(current);
17858
17859 - if (user_mode_vm(regs))
17860 + if (user_mode(regs))
17861 return;
17862
17863 if (regs->sp >= curbase + sizeof(struct thread_info) +
17864 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17865 index dc1404b..bbc43e7 100644
17866 --- a/arch/x86/kernel/kdebugfs.c
17867 +++ b/arch/x86/kernel/kdebugfs.c
17868 @@ -27,7 +27,7 @@ struct setup_data_node {
17869 u32 len;
17870 };
17871
17872 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17873 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17874 size_t count, loff_t *ppos)
17875 {
17876 struct setup_data_node *node = file->private_data;
17877 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17878 index 3f61904..873cea9 100644
17879 --- a/arch/x86/kernel/kgdb.c
17880 +++ b/arch/x86/kernel/kgdb.c
17881 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17882 #ifdef CONFIG_X86_32
17883 switch (regno) {
17884 case GDB_SS:
17885 - if (!user_mode_vm(regs))
17886 + if (!user_mode(regs))
17887 *(unsigned long *)mem = __KERNEL_DS;
17888 break;
17889 case GDB_SP:
17890 - if (!user_mode_vm(regs))
17891 + if (!user_mode(regs))
17892 *(unsigned long *)mem = kernel_stack_pointer(regs);
17893 break;
17894 case GDB_GS:
17895 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17896 case 'k':
17897 /* clear the trace bit */
17898 linux_regs->flags &= ~X86_EFLAGS_TF;
17899 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17900 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17901
17902 /* set the trace bit if we're stepping */
17903 if (remcomInBuffer[0] == 's') {
17904 linux_regs->flags |= X86_EFLAGS_TF;
17905 - atomic_set(&kgdb_cpu_doing_single_step,
17906 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17907 raw_smp_processor_id());
17908 }
17909
17910 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17911
17912 switch (cmd) {
17913 case DIE_DEBUG:
17914 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17915 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17916 if (user_mode(regs))
17917 return single_step_cont(regs, args);
17918 break;
17919 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17920 index c5e410e..da6aaf9 100644
17921 --- a/arch/x86/kernel/kprobes-opt.c
17922 +++ b/arch/x86/kernel/kprobes-opt.c
17923 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17924 * Verify if the address gap is in 2GB range, because this uses
17925 * a relative jump.
17926 */
17927 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17928 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17929 if (abs(rel) > 0x7fffffff)
17930 return -ERANGE;
17931
17932 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17933 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17934
17935 /* Set probe function call */
17936 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17937 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17938
17939 /* Set returning jmp instruction at the tail of out-of-line buffer */
17940 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17941 - (u8 *)op->kp.addr + op->optinsn.size);
17942 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17943
17944 flush_icache_range((unsigned long) buf,
17945 (unsigned long) buf + TMPL_END_IDX +
17946 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17947 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17948
17949 /* Backup instructions which will be replaced by jump address */
17950 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17951 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17952 RELATIVE_ADDR_SIZE);
17953
17954 insn_buf[0] = RELATIVEJUMP_OPCODE;
17955 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17956 index e2f751e..dffa2a0 100644
17957 --- a/arch/x86/kernel/kprobes.c
17958 +++ b/arch/x86/kernel/kprobes.c
17959 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17960 } __attribute__((packed)) *insn;
17961
17962 insn = (struct __arch_relative_insn *)from;
17963 +
17964 + pax_open_kernel();
17965 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17966 insn->op = op;
17967 + pax_close_kernel();
17968 }
17969
17970 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17971 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17972 kprobe_opcode_t opcode;
17973 kprobe_opcode_t *orig_opcodes = opcodes;
17974
17975 - if (search_exception_tables((unsigned long)opcodes))
17976 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17977 return 0; /* Page fault may occur on this address. */
17978
17979 retry:
17980 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17981 /* Another subsystem puts a breakpoint, failed to recover */
17982 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17983 return 0;
17984 + pax_open_kernel();
17985 memcpy(dest, insn.kaddr, insn.length);
17986 + pax_close_kernel();
17987
17988 #ifdef CONFIG_X86_64
17989 if (insn_rip_relative(&insn)) {
17990 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17991 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17992 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17993 disp = (u8 *) dest + insn_offset_displacement(&insn);
17994 + pax_open_kernel();
17995 *(s32 *) disp = (s32) newdisp;
17996 + pax_close_kernel();
17997 }
17998 #endif
17999 return insn.length;
18000 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18001 * nor set current_kprobe, because it doesn't use single
18002 * stepping.
18003 */
18004 - regs->ip = (unsigned long)p->ainsn.insn;
18005 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18006 preempt_enable_no_resched();
18007 return;
18008 }
18009 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18010 if (p->opcode == BREAKPOINT_INSTRUCTION)
18011 regs->ip = (unsigned long)p->addr;
18012 else
18013 - regs->ip = (unsigned long)p->ainsn.insn;
18014 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18015 }
18016
18017 /*
18018 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18019 setup_singlestep(p, regs, kcb, 0);
18020 return 1;
18021 }
18022 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18023 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18024 /*
18025 * The breakpoint instruction was removed right
18026 * after we hit it. Another cpu has removed
18027 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18028 " movq %rax, 152(%rsp)\n"
18029 RESTORE_REGS_STRING
18030 " popfq\n"
18031 +#ifdef KERNEXEC_PLUGIN
18032 + " btsq $63,(%rsp)\n"
18033 +#endif
18034 #else
18035 " pushf\n"
18036 SAVE_REGS_STRING
18037 @@ -765,7 +775,7 @@ static void __kprobes
18038 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18039 {
18040 unsigned long *tos = stack_addr(regs);
18041 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18042 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18043 unsigned long orig_ip = (unsigned long)p->addr;
18044 kprobe_opcode_t *insn = p->ainsn.insn;
18045
18046 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18047 struct die_args *args = data;
18048 int ret = NOTIFY_DONE;
18049
18050 - if (args->regs && user_mode_vm(args->regs))
18051 + if (args->regs && user_mode(args->regs))
18052 return ret;
18053
18054 switch (val) {
18055 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18056 index ebc9873..1b9724b 100644
18057 --- a/arch/x86/kernel/ldt.c
18058 +++ b/arch/x86/kernel/ldt.c
18059 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18060 if (reload) {
18061 #ifdef CONFIG_SMP
18062 preempt_disable();
18063 - load_LDT(pc);
18064 + load_LDT_nolock(pc);
18065 if (!cpumask_equal(mm_cpumask(current->mm),
18066 cpumask_of(smp_processor_id())))
18067 smp_call_function(flush_ldt, current->mm, 1);
18068 preempt_enable();
18069 #else
18070 - load_LDT(pc);
18071 + load_LDT_nolock(pc);
18072 #endif
18073 }
18074 if (oldsize) {
18075 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18076 return err;
18077
18078 for (i = 0; i < old->size; i++)
18079 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18080 + write_ldt_entry(new->ldt, i, old->ldt + i);
18081 return 0;
18082 }
18083
18084 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18085 retval = copy_ldt(&mm->context, &old_mm->context);
18086 mutex_unlock(&old_mm->context.lock);
18087 }
18088 +
18089 + if (tsk == current) {
18090 + mm->context.vdso = 0;
18091 +
18092 +#ifdef CONFIG_X86_32
18093 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18094 + mm->context.user_cs_base = 0UL;
18095 + mm->context.user_cs_limit = ~0UL;
18096 +
18097 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18098 + cpus_clear(mm->context.cpu_user_cs_mask);
18099 +#endif
18100 +
18101 +#endif
18102 +#endif
18103 +
18104 + }
18105 +
18106 return retval;
18107 }
18108
18109 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18110 }
18111 }
18112
18113 +#ifdef CONFIG_PAX_SEGMEXEC
18114 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18115 + error = -EINVAL;
18116 + goto out_unlock;
18117 + }
18118 +#endif
18119 +
18120 fill_ldt(&ldt, &ldt_info);
18121 if (oldmode)
18122 ldt.avl = 0;
18123 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18124 index 5b19e4d..6476a76 100644
18125 --- a/arch/x86/kernel/machine_kexec_32.c
18126 +++ b/arch/x86/kernel/machine_kexec_32.c
18127 @@ -26,7 +26,7 @@
18128 #include <asm/cacheflush.h>
18129 #include <asm/debugreg.h>
18130
18131 -static void set_idt(void *newidt, __u16 limit)
18132 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18133 {
18134 struct desc_ptr curidt;
18135
18136 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18137 }
18138
18139
18140 -static void set_gdt(void *newgdt, __u16 limit)
18141 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18142 {
18143 struct desc_ptr curgdt;
18144
18145 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18146 }
18147
18148 control_page = page_address(image->control_code_page);
18149 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18150 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18151
18152 relocate_kernel_ptr = control_page;
18153 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18154 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18155 index 0327e2b..e43737b 100644
18156 --- a/arch/x86/kernel/microcode_intel.c
18157 +++ b/arch/x86/kernel/microcode_intel.c
18158 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18159
18160 static int get_ucode_user(void *to, const void *from, size_t n)
18161 {
18162 - return copy_from_user(to, from, n);
18163 + return copy_from_user(to, (const void __force_user *)from, n);
18164 }
18165
18166 static enum ucode_state
18167 request_microcode_user(int cpu, const void __user *buf, size_t size)
18168 {
18169 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18170 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18171 }
18172
18173 static void microcode_fini_cpu(int cpu)
18174 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18175 index 216a4d7..b328f09 100644
18176 --- a/arch/x86/kernel/module.c
18177 +++ b/arch/x86/kernel/module.c
18178 @@ -43,15 +43,60 @@ do { \
18179 } while (0)
18180 #endif
18181
18182 -void *module_alloc(unsigned long size)
18183 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18184 {
18185 - if (PAGE_ALIGN(size) > MODULES_LEN)
18186 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18187 return NULL;
18188 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18189 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18190 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18191 -1, __builtin_return_address(0));
18192 }
18193
18194 +void *module_alloc(unsigned long size)
18195 +{
18196 +
18197 +#ifdef CONFIG_PAX_KERNEXEC
18198 + return __module_alloc(size, PAGE_KERNEL);
18199 +#else
18200 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18201 +#endif
18202 +
18203 +}
18204 +
18205 +#ifdef CONFIG_PAX_KERNEXEC
18206 +#ifdef CONFIG_X86_32
18207 +void *module_alloc_exec(unsigned long size)
18208 +{
18209 + struct vm_struct *area;
18210 +
18211 + if (size == 0)
18212 + return NULL;
18213 +
18214 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18215 + return area ? area->addr : NULL;
18216 +}
18217 +EXPORT_SYMBOL(module_alloc_exec);
18218 +
18219 +void module_free_exec(struct module *mod, void *module_region)
18220 +{
18221 + vunmap(module_region);
18222 +}
18223 +EXPORT_SYMBOL(module_free_exec);
18224 +#else
18225 +void module_free_exec(struct module *mod, void *module_region)
18226 +{
18227 + module_free(mod, module_region);
18228 +}
18229 +EXPORT_SYMBOL(module_free_exec);
18230 +
18231 +void *module_alloc_exec(unsigned long size)
18232 +{
18233 + return __module_alloc(size, PAGE_KERNEL_RX);
18234 +}
18235 +EXPORT_SYMBOL(module_alloc_exec);
18236 +#endif
18237 +#endif
18238 +
18239 #ifdef CONFIG_X86_32
18240 int apply_relocate(Elf32_Shdr *sechdrs,
18241 const char *strtab,
18242 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18243 unsigned int i;
18244 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18245 Elf32_Sym *sym;
18246 - uint32_t *location;
18247 + uint32_t *plocation, location;
18248
18249 DEBUGP("Applying relocate section %u to %u\n",
18250 relsec, sechdrs[relsec].sh_info);
18251 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18252 /* This is where to make the change */
18253 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18254 - + rel[i].r_offset;
18255 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18256 + location = (uint32_t)plocation;
18257 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18258 + plocation = ktla_ktva((void *)plocation);
18259 /* This is the symbol it is referring to. Note that all
18260 undefined symbols have been resolved. */
18261 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18262 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18263 switch (ELF32_R_TYPE(rel[i].r_info)) {
18264 case R_386_32:
18265 /* We add the value into the location given */
18266 - *location += sym->st_value;
18267 + pax_open_kernel();
18268 + *plocation += sym->st_value;
18269 + pax_close_kernel();
18270 break;
18271 case R_386_PC32:
18272 /* Add the value, subtract its position */
18273 - *location += sym->st_value - (uint32_t)location;
18274 + pax_open_kernel();
18275 + *plocation += sym->st_value - location;
18276 + pax_close_kernel();
18277 break;
18278 default:
18279 pr_err("%s: Unknown relocation: %u\n",
18280 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18281 case R_X86_64_NONE:
18282 break;
18283 case R_X86_64_64:
18284 + pax_open_kernel();
18285 *(u64 *)loc = val;
18286 + pax_close_kernel();
18287 break;
18288 case R_X86_64_32:
18289 + pax_open_kernel();
18290 *(u32 *)loc = val;
18291 + pax_close_kernel();
18292 if (val != *(u32 *)loc)
18293 goto overflow;
18294 break;
18295 case R_X86_64_32S:
18296 + pax_open_kernel();
18297 *(s32 *)loc = val;
18298 + pax_close_kernel();
18299 if ((s64)val != *(s32 *)loc)
18300 goto overflow;
18301 break;
18302 case R_X86_64_PC32:
18303 val -= (u64)loc;
18304 + pax_open_kernel();
18305 *(u32 *)loc = val;
18306 + pax_close_kernel();
18307 +
18308 #if 0
18309 if ((s64)val != *(s32 *)loc)
18310 goto overflow;
18311 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18312 index f84f5c5..e27e54b 100644
18313 --- a/arch/x86/kernel/nmi.c
18314 +++ b/arch/x86/kernel/nmi.c
18315 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18316 dotraplinkage notrace __kprobes void
18317 do_nmi(struct pt_regs *regs, long error_code)
18318 {
18319 +
18320 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18321 + if (!user_mode(regs)) {
18322 + unsigned long cs = regs->cs & 0xFFFF;
18323 + unsigned long ip = ktva_ktla(regs->ip);
18324 +
18325 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18326 + regs->ip = ip;
18327 + }
18328 +#endif
18329 +
18330 nmi_nesting_preprocess(regs);
18331
18332 nmi_enter();
18333 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18334 index 676b8c7..870ba04 100644
18335 --- a/arch/x86/kernel/paravirt-spinlocks.c
18336 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18337 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18338 arch_spin_lock(lock);
18339 }
18340
18341 -struct pv_lock_ops pv_lock_ops = {
18342 +struct pv_lock_ops pv_lock_ops __read_only = {
18343 #ifdef CONFIG_SMP
18344 .spin_is_locked = __ticket_spin_is_locked,
18345 .spin_is_contended = __ticket_spin_is_contended,
18346 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18347 index 17fff18..7bb2088 100644
18348 --- a/arch/x86/kernel/paravirt.c
18349 +++ b/arch/x86/kernel/paravirt.c
18350 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18351 {
18352 return x;
18353 }
18354 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18355 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18356 +#endif
18357
18358 void __init default_banner(void)
18359 {
18360 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18361 if (opfunc == NULL)
18362 /* If there's no function, patch it with a ud2a (BUG) */
18363 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18364 - else if (opfunc == _paravirt_nop)
18365 + else if (opfunc == (void *)_paravirt_nop)
18366 /* If the operation is a nop, then nop the callsite */
18367 ret = paravirt_patch_nop();
18368
18369 /* identity functions just return their single argument */
18370 - else if (opfunc == _paravirt_ident_32)
18371 + else if (opfunc == (void *)_paravirt_ident_32)
18372 ret = paravirt_patch_ident_32(insnbuf, len);
18373 - else if (opfunc == _paravirt_ident_64)
18374 + else if (opfunc == (void *)_paravirt_ident_64)
18375 ret = paravirt_patch_ident_64(insnbuf, len);
18376 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18377 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18378 + ret = paravirt_patch_ident_64(insnbuf, len);
18379 +#endif
18380
18381 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18382 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18383 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18384 if (insn_len > len || start == NULL)
18385 insn_len = len;
18386 else
18387 - memcpy(insnbuf, start, insn_len);
18388 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18389
18390 return insn_len;
18391 }
18392 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18393 preempt_enable();
18394 }
18395
18396 -struct pv_info pv_info = {
18397 +struct pv_info pv_info __read_only = {
18398 .name = "bare hardware",
18399 .paravirt_enabled = 0,
18400 .kernel_rpl = 0,
18401 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18402 #endif
18403 };
18404
18405 -struct pv_init_ops pv_init_ops = {
18406 +struct pv_init_ops pv_init_ops __read_only = {
18407 .patch = native_patch,
18408 };
18409
18410 -struct pv_time_ops pv_time_ops = {
18411 +struct pv_time_ops pv_time_ops __read_only = {
18412 .sched_clock = native_sched_clock,
18413 .steal_clock = native_steal_clock,
18414 };
18415
18416 -struct pv_irq_ops pv_irq_ops = {
18417 +struct pv_irq_ops pv_irq_ops __read_only = {
18418 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18419 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18420 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18421 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18422 #endif
18423 };
18424
18425 -struct pv_cpu_ops pv_cpu_ops = {
18426 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18427 .cpuid = native_cpuid,
18428 .get_debugreg = native_get_debugreg,
18429 .set_debugreg = native_set_debugreg,
18430 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18431 .end_context_switch = paravirt_nop,
18432 };
18433
18434 -struct pv_apic_ops pv_apic_ops = {
18435 +struct pv_apic_ops pv_apic_ops __read_only = {
18436 #ifdef CONFIG_X86_LOCAL_APIC
18437 .startup_ipi_hook = paravirt_nop,
18438 #endif
18439 };
18440
18441 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18442 +#ifdef CONFIG_X86_32
18443 +#ifdef CONFIG_X86_PAE
18444 +/* 64-bit pagetable entries */
18445 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18446 +#else
18447 /* 32-bit pagetable entries */
18448 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18449 +#endif
18450 #else
18451 /* 64-bit pagetable entries */
18452 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18453 #endif
18454
18455 -struct pv_mmu_ops pv_mmu_ops = {
18456 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18457
18458 .read_cr2 = native_read_cr2,
18459 .write_cr2 = native_write_cr2,
18460 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18461 .make_pud = PTE_IDENT,
18462
18463 .set_pgd = native_set_pgd,
18464 + .set_pgd_batched = native_set_pgd_batched,
18465 #endif
18466 #endif /* PAGETABLE_LEVELS >= 3 */
18467
18468 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18469 },
18470
18471 .set_fixmap = native_set_fixmap,
18472 +
18473 +#ifdef CONFIG_PAX_KERNEXEC
18474 + .pax_open_kernel = native_pax_open_kernel,
18475 + .pax_close_kernel = native_pax_close_kernel,
18476 +#endif
18477 +
18478 };
18479
18480 EXPORT_SYMBOL_GPL(pv_time_ops);
18481 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18482 index 35ccf75..7a15747 100644
18483 --- a/arch/x86/kernel/pci-iommu_table.c
18484 +++ b/arch/x86/kernel/pci-iommu_table.c
18485 @@ -2,7 +2,7 @@
18486 #include <asm/iommu_table.h>
18487 #include <linux/string.h>
18488 #include <linux/kallsyms.h>
18489 -
18490 +#include <linux/sched.h>
18491
18492 #define DEBUG 1
18493
18494 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18495 index ef6a845..8028ed3 100644
18496 --- a/arch/x86/kernel/process.c
18497 +++ b/arch/x86/kernel/process.c
18498 @@ -36,7 +36,8 @@
18499 * section. Since TSS's are completely CPU-local, we want them
18500 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18501 */
18502 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18503 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18504 +EXPORT_SYMBOL(init_tss);
18505
18506 #ifdef CONFIG_X86_64
18507 static DEFINE_PER_CPU(unsigned char, is_idle);
18508 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18509 task_xstate_cachep =
18510 kmem_cache_create("task_xstate", xstate_size,
18511 __alignof__(union thread_xstate),
18512 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18513 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18514 }
18515
18516 static inline void drop_fpu(struct task_struct *tsk)
18517 @@ -117,7 +118,7 @@ void exit_thread(void)
18518 unsigned long *bp = t->io_bitmap_ptr;
18519
18520 if (bp) {
18521 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18522 + struct tss_struct *tss = init_tss + get_cpu();
18523
18524 t->io_bitmap_ptr = NULL;
18525 clear_thread_flag(TIF_IO_BITMAP);
18526 @@ -148,7 +149,7 @@ void show_regs_common(void)
18527 board = dmi_get_system_info(DMI_BOARD_NAME);
18528
18529 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18530 - current->pid, current->comm, print_tainted(),
18531 + task_pid_nr(current), current->comm, print_tainted(),
18532 init_utsname()->release,
18533 (int)strcspn(init_utsname()->version, " "),
18534 init_utsname()->version,
18535 @@ -161,6 +162,9 @@ void flush_thread(void)
18536 {
18537 struct task_struct *tsk = current;
18538
18539 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18540 + loadsegment(gs, 0);
18541 +#endif
18542 flush_ptrace_hw_breakpoint(tsk);
18543 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18544 drop_fpu(tsk);
18545 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18546 regs.di = (unsigned long) arg;
18547
18548 #ifdef CONFIG_X86_32
18549 - regs.ds = __USER_DS;
18550 - regs.es = __USER_DS;
18551 + regs.ds = __KERNEL_DS;
18552 + regs.es = __KERNEL_DS;
18553 regs.fs = __KERNEL_PERCPU;
18554 - regs.gs = __KERNEL_STACK_CANARY;
18555 + savesegment(gs, regs.gs);
18556 #else
18557 regs.ss = __KERNEL_DS;
18558 #endif
18559 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18560 void exit_idle(void)
18561 {
18562 /* idle loop has pid 0 */
18563 - if (current->pid)
18564 + if (task_pid_nr(current))
18565 return;
18566 __exit_idle();
18567 }
18568 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18569
18570 return ret;
18571 }
18572 -void stop_this_cpu(void *dummy)
18573 +__noreturn void stop_this_cpu(void *dummy)
18574 {
18575 local_irq_disable();
18576 /*
18577 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18578 }
18579 early_param("idle", idle_setup);
18580
18581 -unsigned long arch_align_stack(unsigned long sp)
18582 +#ifdef CONFIG_PAX_RANDKSTACK
18583 +void pax_randomize_kstack(struct pt_regs *regs)
18584 {
18585 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18586 - sp -= get_random_int() % 8192;
18587 - return sp & ~0xf;
18588 -}
18589 + struct thread_struct *thread = &current->thread;
18590 + unsigned long time;
18591
18592 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18593 -{
18594 - unsigned long range_end = mm->brk + 0x02000000;
18595 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18596 -}
18597 + if (!randomize_va_space)
18598 + return;
18599 +
18600 + if (v8086_mode(regs))
18601 + return;
18602
18603 + rdtscl(time);
18604 +
18605 + /* P4 seems to return a 0 LSB, ignore it */
18606 +#ifdef CONFIG_MPENTIUM4
18607 + time &= 0x3EUL;
18608 + time <<= 2;
18609 +#elif defined(CONFIG_X86_64)
18610 + time &= 0xFUL;
18611 + time <<= 4;
18612 +#else
18613 + time &= 0x1FUL;
18614 + time <<= 3;
18615 +#endif
18616 +
18617 + thread->sp0 ^= time;
18618 + load_sp0(init_tss + smp_processor_id(), thread);
18619 +
18620 +#ifdef CONFIG_X86_64
18621 + this_cpu_write(kernel_stack, thread->sp0);
18622 +#endif
18623 +}
18624 +#endif
18625 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18626 index 516fa18..80bd9e6 100644
18627 --- a/arch/x86/kernel/process_32.c
18628 +++ b/arch/x86/kernel/process_32.c
18629 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18630 unsigned long thread_saved_pc(struct task_struct *tsk)
18631 {
18632 return ((unsigned long *)tsk->thread.sp)[3];
18633 +//XXX return tsk->thread.eip;
18634 }
18635
18636 void __show_regs(struct pt_regs *regs, int all)
18637 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18638 unsigned long sp;
18639 unsigned short ss, gs;
18640
18641 - if (user_mode_vm(regs)) {
18642 + if (user_mode(regs)) {
18643 sp = regs->sp;
18644 ss = regs->ss & 0xffff;
18645 - gs = get_user_gs(regs);
18646 } else {
18647 sp = kernel_stack_pointer(regs);
18648 savesegment(ss, ss);
18649 - savesegment(gs, gs);
18650 }
18651 + gs = get_user_gs(regs);
18652
18653 show_regs_common();
18654
18655 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18656 struct task_struct *tsk;
18657 int err;
18658
18659 - childregs = task_pt_regs(p);
18660 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18661 *childregs = *regs;
18662 childregs->ax = 0;
18663 childregs->sp = sp;
18664
18665 p->thread.sp = (unsigned long) childregs;
18666 p->thread.sp0 = (unsigned long) (childregs+1);
18667 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18668
18669 p->thread.ip = (unsigned long) ret_from_fork;
18670
18671 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18672 struct thread_struct *prev = &prev_p->thread,
18673 *next = &next_p->thread;
18674 int cpu = smp_processor_id();
18675 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18676 + struct tss_struct *tss = init_tss + cpu;
18677 fpu_switch_t fpu;
18678
18679 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18680 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18681 */
18682 lazy_save_gs(prev->gs);
18683
18684 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18685 + __set_fs(task_thread_info(next_p)->addr_limit);
18686 +#endif
18687 +
18688 /*
18689 * Load the per-thread Thread-Local Storage descriptor.
18690 */
18691 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18692 */
18693 arch_end_context_switch(next_p);
18694
18695 + this_cpu_write(current_task, next_p);
18696 + this_cpu_write(current_tinfo, &next_p->tinfo);
18697 +
18698 /*
18699 * Restore %gs if needed (which is common)
18700 */
18701 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18702
18703 switch_fpu_finish(next_p, fpu);
18704
18705 - this_cpu_write(current_task, next_p);
18706 -
18707 return prev_p;
18708 }
18709
18710 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18711 } while (count++ < 16);
18712 return 0;
18713 }
18714 -
18715 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18716 index 0a980c9..1d0e689 100644
18717 --- a/arch/x86/kernel/process_64.c
18718 +++ b/arch/x86/kernel/process_64.c
18719 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18720 struct pt_regs *childregs;
18721 struct task_struct *me = current;
18722
18723 - childregs = ((struct pt_regs *)
18724 - (THREAD_SIZE + task_stack_page(p))) - 1;
18725 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18726 *childregs = *regs;
18727
18728 childregs->ax = 0;
18729 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18730 p->thread.sp = (unsigned long) childregs;
18731 p->thread.sp0 = (unsigned long) (childregs+1);
18732 p->thread.usersp = me->thread.usersp;
18733 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18734
18735 set_tsk_thread_flag(p, TIF_FORK);
18736
18737 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18738 struct thread_struct *prev = &prev_p->thread;
18739 struct thread_struct *next = &next_p->thread;
18740 int cpu = smp_processor_id();
18741 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18742 + struct tss_struct *tss = init_tss + cpu;
18743 unsigned fsindex, gsindex;
18744 fpu_switch_t fpu;
18745
18746 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18747 prev->usersp = this_cpu_read(old_rsp);
18748 this_cpu_write(old_rsp, next->usersp);
18749 this_cpu_write(current_task, next_p);
18750 + this_cpu_write(current_tinfo, &next_p->tinfo);
18751
18752 - this_cpu_write(kernel_stack,
18753 - (unsigned long)task_stack_page(next_p) +
18754 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18755 + this_cpu_write(kernel_stack, next->sp0);
18756
18757 /*
18758 * Now maybe reload the debug registers and handle I/O bitmaps
18759 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18760 if (!p || p == current || p->state == TASK_RUNNING)
18761 return 0;
18762 stack = (unsigned long)task_stack_page(p);
18763 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18764 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18765 return 0;
18766 fp = *(u64 *)(p->thread.sp);
18767 do {
18768 - if (fp < (unsigned long)stack ||
18769 - fp >= (unsigned long)stack+THREAD_SIZE)
18770 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18771 return 0;
18772 ip = *(u64 *)(fp+8);
18773 if (!in_sched_functions(ip))
18774 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18775 index c4c6a5c..905f440 100644
18776 --- a/arch/x86/kernel/ptrace.c
18777 +++ b/arch/x86/kernel/ptrace.c
18778 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18779 unsigned long addr, unsigned long data)
18780 {
18781 int ret;
18782 - unsigned long __user *datap = (unsigned long __user *)data;
18783 + unsigned long __user *datap = (__force unsigned long __user *)data;
18784
18785 switch (request) {
18786 /* read the word at location addr in the USER area. */
18787 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18788 if ((int) addr < 0)
18789 return -EIO;
18790 ret = do_get_thread_area(child, addr,
18791 - (struct user_desc __user *)data);
18792 + (__force struct user_desc __user *) data);
18793 break;
18794
18795 case PTRACE_SET_THREAD_AREA:
18796 if ((int) addr < 0)
18797 return -EIO;
18798 ret = do_set_thread_area(child, addr,
18799 - (struct user_desc __user *)data, 0);
18800 + (__force struct user_desc __user *) data, 0);
18801 break;
18802 #endif
18803
18804 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18805 memset(info, 0, sizeof(*info));
18806 info->si_signo = SIGTRAP;
18807 info->si_code = si_code;
18808 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18809 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18810 }
18811
18812 void user_single_step_siginfo(struct task_struct *tsk,
18813 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18814 # define IS_IA32 0
18815 #endif
18816
18817 +#ifdef CONFIG_GRKERNSEC_SETXID
18818 +extern void gr_delayed_cred_worker(void);
18819 +#endif
18820 +
18821 /*
18822 * We must return the syscall number to actually look up in the table.
18823 * This can be -1L to skip running any syscall at all.
18824 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18825 {
18826 long ret = 0;
18827
18828 +#ifdef CONFIG_GRKERNSEC_SETXID
18829 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18830 + gr_delayed_cred_worker();
18831 +#endif
18832 +
18833 /*
18834 * If we stepped into a sysenter/syscall insn, it trapped in
18835 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18836 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18837 {
18838 bool step;
18839
18840 +#ifdef CONFIG_GRKERNSEC_SETXID
18841 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18842 + gr_delayed_cred_worker();
18843 +#endif
18844 +
18845 audit_syscall_exit(regs);
18846
18847 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18848 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18849 index 42eb330..139955c 100644
18850 --- a/arch/x86/kernel/pvclock.c
18851 +++ b/arch/x86/kernel/pvclock.c
18852 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18853 return pv_tsc_khz;
18854 }
18855
18856 -static atomic64_t last_value = ATOMIC64_INIT(0);
18857 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18858
18859 void pvclock_resume(void)
18860 {
18861 - atomic64_set(&last_value, 0);
18862 + atomic64_set_unchecked(&last_value, 0);
18863 }
18864
18865 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18866 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18867 * updating at the same time, and one of them could be slightly behind,
18868 * making the assumption that last_value always go forward fail to hold.
18869 */
18870 - last = atomic64_read(&last_value);
18871 + last = atomic64_read_unchecked(&last_value);
18872 do {
18873 if (ret < last)
18874 return last;
18875 - last = atomic64_cmpxchg(&last_value, last, ret);
18876 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18877 } while (unlikely(last != ret));
18878
18879 return ret;
18880 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18881 index 52190a9..8074389 100644
18882 --- a/arch/x86/kernel/reboot.c
18883 +++ b/arch/x86/kernel/reboot.c
18884 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18885 EXPORT_SYMBOL(pm_power_off);
18886
18887 static const struct desc_ptr no_idt = {};
18888 -static int reboot_mode;
18889 +static unsigned short reboot_mode;
18890 enum reboot_type reboot_type = BOOT_ACPI;
18891 int reboot_force;
18892
18893 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18894
18895 void __noreturn machine_real_restart(unsigned int type)
18896 {
18897 +
18898 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18899 + struct desc_struct *gdt;
18900 +#endif
18901 +
18902 local_irq_disable();
18903
18904 /*
18905 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18906
18907 /* Jump to the identity-mapped low memory code */
18908 #ifdef CONFIG_X86_32
18909 - asm volatile("jmpl *%0" : :
18910 +
18911 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18912 + gdt = get_cpu_gdt_table(smp_processor_id());
18913 + pax_open_kernel();
18914 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18915 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18916 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18917 + loadsegment(ds, __KERNEL_DS);
18918 + loadsegment(es, __KERNEL_DS);
18919 + loadsegment(ss, __KERNEL_DS);
18920 +#endif
18921 +#ifdef CONFIG_PAX_KERNEXEC
18922 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18923 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18924 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18925 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18926 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18927 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18928 +#endif
18929 + pax_close_kernel();
18930 +#endif
18931 +
18932 + asm volatile("ljmpl *%0" : :
18933 "rm" (real_mode_header->machine_real_restart_asm),
18934 "a" (type));
18935 #else
18936 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18937 * try to force a triple fault and then cycle between hitting the keyboard
18938 * controller and doing that
18939 */
18940 -static void native_machine_emergency_restart(void)
18941 +static void __noreturn native_machine_emergency_restart(void)
18942 {
18943 int i;
18944 int attempt = 0;
18945 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18946 #endif
18947 }
18948
18949 -static void __machine_emergency_restart(int emergency)
18950 +static void __noreturn __machine_emergency_restart(int emergency)
18951 {
18952 reboot_emergency = emergency;
18953 machine_ops.emergency_restart();
18954 }
18955
18956 -static void native_machine_restart(char *__unused)
18957 +static void __noreturn native_machine_restart(char *__unused)
18958 {
18959 pr_notice("machine restart\n");
18960
18961 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18962 __machine_emergency_restart(0);
18963 }
18964
18965 -static void native_machine_halt(void)
18966 +static void __noreturn native_machine_halt(void)
18967 {
18968 /* Stop other cpus and apics */
18969 machine_shutdown();
18970 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
18971 stop_this_cpu(NULL);
18972 }
18973
18974 -static void native_machine_power_off(void)
18975 +static void __noreturn native_machine_power_off(void)
18976 {
18977 if (pm_power_off) {
18978 if (!reboot_force)
18979 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18980 }
18981 /* A fallback in case there is no PM info available */
18982 tboot_shutdown(TB_SHUTDOWN_HALT);
18983 + unreachable();
18984 }
18985
18986 struct machine_ops machine_ops = {
18987 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18988 index 7a6f3b3..bed145d7 100644
18989 --- a/arch/x86/kernel/relocate_kernel_64.S
18990 +++ b/arch/x86/kernel/relocate_kernel_64.S
18991 @@ -11,6 +11,7 @@
18992 #include <asm/kexec.h>
18993 #include <asm/processor-flags.h>
18994 #include <asm/pgtable_types.h>
18995 +#include <asm/alternative-asm.h>
18996
18997 /*
18998 * Must be relocatable PIC code callable as a C function
18999 @@ -160,13 +161,14 @@ identity_mapped:
19000 xorq %rbp, %rbp
19001 xorq %r8, %r8
19002 xorq %r9, %r9
19003 - xorq %r10, %r9
19004 + xorq %r10, %r10
19005 xorq %r11, %r11
19006 xorq %r12, %r12
19007 xorq %r13, %r13
19008 xorq %r14, %r14
19009 xorq %r15, %r15
19010
19011 + pax_force_retaddr 0, 1
19012 ret
19013
19014 1:
19015 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19016 index 198e774..e880f29 100644
19017 --- a/arch/x86/kernel/setup.c
19018 +++ b/arch/x86/kernel/setup.c
19019 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19020
19021 switch (data->type) {
19022 case SETUP_E820_EXT:
19023 - parse_e820_ext(data);
19024 + parse_e820_ext((struct setup_data __force_kernel *)data);
19025 break;
19026 case SETUP_DTB:
19027 add_dtb(pa_data);
19028 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19029 * area (640->1Mb) as ram even though it is not.
19030 * take them out.
19031 */
19032 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19033 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19034 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19035 }
19036
19037 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19038
19039 if (!boot_params.hdr.root_flags)
19040 root_mountflags &= ~MS_RDONLY;
19041 - init_mm.start_code = (unsigned long) _text;
19042 - init_mm.end_code = (unsigned long) _etext;
19043 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19044 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19045 init_mm.end_data = (unsigned long) _edata;
19046 init_mm.brk = _brk_end;
19047
19048 - code_resource.start = virt_to_phys(_text);
19049 - code_resource.end = virt_to_phys(_etext)-1;
19050 - data_resource.start = virt_to_phys(_etext);
19051 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19052 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19053 + data_resource.start = virt_to_phys(_sdata);
19054 data_resource.end = virt_to_phys(_edata)-1;
19055 bss_resource.start = virt_to_phys(&__bss_start);
19056 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19057 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19058 index 5cdff03..5810740 100644
19059 --- a/arch/x86/kernel/setup_percpu.c
19060 +++ b/arch/x86/kernel/setup_percpu.c
19061 @@ -21,19 +21,17 @@
19062 #include <asm/cpu.h>
19063 #include <asm/stackprotector.h>
19064
19065 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19066 +#ifdef CONFIG_SMP
19067 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19068 EXPORT_PER_CPU_SYMBOL(cpu_number);
19069 +#endif
19070
19071 -#ifdef CONFIG_X86_64
19072 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19073 -#else
19074 -#define BOOT_PERCPU_OFFSET 0
19075 -#endif
19076
19077 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19078 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19079
19080 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19081 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19082 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19083 };
19084 EXPORT_SYMBOL(__per_cpu_offset);
19085 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19086 {
19087 #ifdef CONFIG_X86_32
19088 struct desc_struct gdt;
19089 + unsigned long base = per_cpu_offset(cpu);
19090
19091 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19092 - 0x2 | DESCTYPE_S, 0x8);
19093 - gdt.s = 1;
19094 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19095 + 0x83 | DESCTYPE_S, 0xC);
19096 write_gdt_entry(get_cpu_gdt_table(cpu),
19097 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19098 #endif
19099 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19100 /* alrighty, percpu areas up and running */
19101 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19102 for_each_possible_cpu(cpu) {
19103 +#ifdef CONFIG_CC_STACKPROTECTOR
19104 +#ifdef CONFIG_X86_32
19105 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19106 +#endif
19107 +#endif
19108 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19109 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19110 per_cpu(cpu_number, cpu) = cpu;
19111 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19112 */
19113 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19114 #endif
19115 +#ifdef CONFIG_CC_STACKPROTECTOR
19116 +#ifdef CONFIG_X86_32
19117 + if (!cpu)
19118 + per_cpu(stack_canary.canary, cpu) = canary;
19119 +#endif
19120 +#endif
19121 /*
19122 * Up to this point, the boot CPU has been using .init.data
19123 * area. Reload any changed state for the boot CPU.
19124 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19125 index b280908..6de349e 100644
19126 --- a/arch/x86/kernel/signal.c
19127 +++ b/arch/x86/kernel/signal.c
19128 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19129 * Align the stack pointer according to the i386 ABI,
19130 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19131 */
19132 - sp = ((sp + 4) & -16ul) - 4;
19133 + sp = ((sp - 12) & -16ul) - 4;
19134 #else /* !CONFIG_X86_32 */
19135 sp = round_down(sp, 16) - 8;
19136 #endif
19137 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19138 * Return an always-bogus address instead so we will die with SIGSEGV.
19139 */
19140 if (onsigstack && !likely(on_sig_stack(sp)))
19141 - return (void __user *)-1L;
19142 + return (__force void __user *)-1L;
19143
19144 /* save i387 state */
19145 if (used_math() && save_i387_xstate(*fpstate) < 0)
19146 - return (void __user *)-1L;
19147 + return (__force void __user *)-1L;
19148
19149 return (void __user *)sp;
19150 }
19151 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19152 }
19153
19154 if (current->mm->context.vdso)
19155 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19156 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19157 else
19158 - restorer = &frame->retcode;
19159 + restorer = (void __user *)&frame->retcode;
19160 if (ka->sa.sa_flags & SA_RESTORER)
19161 restorer = ka->sa.sa_restorer;
19162
19163 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19164 * reasons and because gdb uses it as a signature to notice
19165 * signal handler stack frames.
19166 */
19167 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19168 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19169
19170 if (err)
19171 return -EFAULT;
19172 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19173 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19174
19175 /* Set up to return from userspace. */
19176 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19177 + if (current->mm->context.vdso)
19178 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19179 + else
19180 + restorer = (void __user *)&frame->retcode;
19181 if (ka->sa.sa_flags & SA_RESTORER)
19182 restorer = ka->sa.sa_restorer;
19183 put_user_ex(restorer, &frame->pretcode);
19184 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19185 * reasons and because gdb uses it as a signature to notice
19186 * signal handler stack frames.
19187 */
19188 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19189 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19190 } put_user_catch(err);
19191
19192 if (err)
19193 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19194 index 7c5a8c3..88d422f 100644
19195 --- a/arch/x86/kernel/smpboot.c
19196 +++ b/arch/x86/kernel/smpboot.c
19197 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19198 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19199 (THREAD_SIZE + task_stack_page(idle))) - 1);
19200 per_cpu(current_task, cpu) = idle;
19201 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19202
19203 #ifdef CONFIG_X86_32
19204 /* Stack for startup_32 can be just as for start_secondary onwards */
19205 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19206 #else
19207 clear_tsk_thread_flag(idle, TIF_FORK);
19208 initial_gs = per_cpu_offset(cpu);
19209 - per_cpu(kernel_stack, cpu) =
19210 - (unsigned long)task_stack_page(idle) -
19211 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19212 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19213 #endif
19214 +
19215 + pax_open_kernel();
19216 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19217 + pax_close_kernel();
19218 +
19219 initial_code = (unsigned long)start_secondary;
19220 stack_start = idle->thread.sp;
19221
19222 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19223
19224 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19225
19226 +#ifdef CONFIG_PAX_PER_CPU_PGD
19227 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19228 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19229 + KERNEL_PGD_PTRS);
19230 +#endif
19231 +
19232 err = do_boot_cpu(apicid, cpu, tidle);
19233 if (err) {
19234 pr_debug("do_boot_cpu failed %d\n", err);
19235 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19236 index c346d11..d43b163 100644
19237 --- a/arch/x86/kernel/step.c
19238 +++ b/arch/x86/kernel/step.c
19239 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19240 struct desc_struct *desc;
19241 unsigned long base;
19242
19243 - seg &= ~7UL;
19244 + seg >>= 3;
19245
19246 mutex_lock(&child->mm->context.lock);
19247 - if (unlikely((seg >> 3) >= child->mm->context.size))
19248 + if (unlikely(seg >= child->mm->context.size))
19249 addr = -1L; /* bogus selector, access would fault */
19250 else {
19251 desc = child->mm->context.ldt + seg;
19252 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19253 addr += base;
19254 }
19255 mutex_unlock(&child->mm->context.lock);
19256 - }
19257 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19258 + addr = ktla_ktva(addr);
19259
19260 return addr;
19261 }
19262 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19263 unsigned char opcode[15];
19264 unsigned long addr = convert_ip_to_linear(child, regs);
19265
19266 + if (addr == -EINVAL)
19267 + return 0;
19268 +
19269 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19270 for (i = 0; i < copied; i++) {
19271 switch (opcode[i]) {
19272 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19273 index 0b0cb5f..db6b9ed 100644
19274 --- a/arch/x86/kernel/sys_i386_32.c
19275 +++ b/arch/x86/kernel/sys_i386_32.c
19276 @@ -24,17 +24,224 @@
19277
19278 #include <asm/syscalls.h>
19279
19280 -/*
19281 - * Do a system call from kernel instead of calling sys_execve so we
19282 - * end up with proper pt_regs.
19283 - */
19284 -int kernel_execve(const char *filename,
19285 - const char *const argv[],
19286 - const char *const envp[])
19287 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19288 {
19289 - long __res;
19290 - asm volatile ("int $0x80"
19291 - : "=a" (__res)
19292 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19293 - return __res;
19294 + unsigned long pax_task_size = TASK_SIZE;
19295 +
19296 +#ifdef CONFIG_PAX_SEGMEXEC
19297 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19298 + pax_task_size = SEGMEXEC_TASK_SIZE;
19299 +#endif
19300 +
19301 + if (len > pax_task_size || addr > pax_task_size - len)
19302 + return -EINVAL;
19303 +
19304 + return 0;
19305 +}
19306 +
19307 +unsigned long
19308 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19309 + unsigned long len, unsigned long pgoff, unsigned long flags)
19310 +{
19311 + struct mm_struct *mm = current->mm;
19312 + struct vm_area_struct *vma;
19313 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19314 +
19315 +#ifdef CONFIG_PAX_SEGMEXEC
19316 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19317 + pax_task_size = SEGMEXEC_TASK_SIZE;
19318 +#endif
19319 +
19320 + pax_task_size -= PAGE_SIZE;
19321 +
19322 + if (len > pax_task_size)
19323 + return -ENOMEM;
19324 +
19325 + if (flags & MAP_FIXED)
19326 + return addr;
19327 +
19328 +#ifdef CONFIG_PAX_RANDMMAP
19329 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19330 +#endif
19331 +
19332 + if (addr) {
19333 + addr = PAGE_ALIGN(addr);
19334 + if (pax_task_size - len >= addr) {
19335 + vma = find_vma(mm, addr);
19336 + if (check_heap_stack_gap(vma, addr, len))
19337 + return addr;
19338 + }
19339 + }
19340 + if (len > mm->cached_hole_size) {
19341 + start_addr = addr = mm->free_area_cache;
19342 + } else {
19343 + start_addr = addr = mm->mmap_base;
19344 + mm->cached_hole_size = 0;
19345 + }
19346 +
19347 +#ifdef CONFIG_PAX_PAGEEXEC
19348 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19349 + start_addr = 0x00110000UL;
19350 +
19351 +#ifdef CONFIG_PAX_RANDMMAP
19352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19353 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19354 +#endif
19355 +
19356 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19357 + start_addr = addr = mm->mmap_base;
19358 + else
19359 + addr = start_addr;
19360 + }
19361 +#endif
19362 +
19363 +full_search:
19364 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19365 + /* At this point: (!vma || addr < vma->vm_end). */
19366 + if (pax_task_size - len < addr) {
19367 + /*
19368 + * Start a new search - just in case we missed
19369 + * some holes.
19370 + */
19371 + if (start_addr != mm->mmap_base) {
19372 + start_addr = addr = mm->mmap_base;
19373 + mm->cached_hole_size = 0;
19374 + goto full_search;
19375 + }
19376 + return -ENOMEM;
19377 + }
19378 + if (check_heap_stack_gap(vma, addr, len))
19379 + break;
19380 + if (addr + mm->cached_hole_size < vma->vm_start)
19381 + mm->cached_hole_size = vma->vm_start - addr;
19382 + addr = vma->vm_end;
19383 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19384 + start_addr = addr = mm->mmap_base;
19385 + mm->cached_hole_size = 0;
19386 + goto full_search;
19387 + }
19388 + }
19389 +
19390 + /*
19391 + * Remember the place where we stopped the search:
19392 + */
19393 + mm->free_area_cache = addr + len;
19394 + return addr;
19395 +}
19396 +
19397 +unsigned long
19398 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19399 + const unsigned long len, const unsigned long pgoff,
19400 + const unsigned long flags)
19401 +{
19402 + struct vm_area_struct *vma;
19403 + struct mm_struct *mm = current->mm;
19404 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19405 +
19406 +#ifdef CONFIG_PAX_SEGMEXEC
19407 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19408 + pax_task_size = SEGMEXEC_TASK_SIZE;
19409 +#endif
19410 +
19411 + pax_task_size -= PAGE_SIZE;
19412 +
19413 + /* requested length too big for entire address space */
19414 + if (len > pax_task_size)
19415 + return -ENOMEM;
19416 +
19417 + if (flags & MAP_FIXED)
19418 + return addr;
19419 +
19420 +#ifdef CONFIG_PAX_PAGEEXEC
19421 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19422 + goto bottomup;
19423 +#endif
19424 +
19425 +#ifdef CONFIG_PAX_RANDMMAP
19426 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19427 +#endif
19428 +
19429 + /* requesting a specific address */
19430 + if (addr) {
19431 + addr = PAGE_ALIGN(addr);
19432 + if (pax_task_size - len >= addr) {
19433 + vma = find_vma(mm, addr);
19434 + if (check_heap_stack_gap(vma, addr, len))
19435 + return addr;
19436 + }
19437 + }
19438 +
19439 + /* check if free_area_cache is useful for us */
19440 + if (len <= mm->cached_hole_size) {
19441 + mm->cached_hole_size = 0;
19442 + mm->free_area_cache = mm->mmap_base;
19443 + }
19444 +
19445 + /* either no address requested or can't fit in requested address hole */
19446 + addr = mm->free_area_cache;
19447 +
19448 + /* make sure it can fit in the remaining address space */
19449 + if (addr > len) {
19450 + vma = find_vma(mm, addr-len);
19451 + if (check_heap_stack_gap(vma, addr - len, len))
19452 + /* remember the address as a hint for next time */
19453 + return (mm->free_area_cache = addr-len);
19454 + }
19455 +
19456 + if (mm->mmap_base < len)
19457 + goto bottomup;
19458 +
19459 + addr = mm->mmap_base-len;
19460 +
19461 + do {
19462 + /*
19463 + * Lookup failure means no vma is above this address,
19464 + * else if new region fits below vma->vm_start,
19465 + * return with success:
19466 + */
19467 + vma = find_vma(mm, addr);
19468 + if (check_heap_stack_gap(vma, addr, len))
19469 + /* remember the address as a hint for next time */
19470 + return (mm->free_area_cache = addr);
19471 +
19472 + /* remember the largest hole we saw so far */
19473 + if (addr + mm->cached_hole_size < vma->vm_start)
19474 + mm->cached_hole_size = vma->vm_start - addr;
19475 +
19476 + /* try just below the current vma->vm_start */
19477 + addr = skip_heap_stack_gap(vma, len);
19478 + } while (!IS_ERR_VALUE(addr));
19479 +
19480 +bottomup:
19481 + /*
19482 + * A failed mmap() very likely causes application failure,
19483 + * so fall back to the bottom-up function here. This scenario
19484 + * can happen with large stack limits and large mmap()
19485 + * allocations.
19486 + */
19487 +
19488 +#ifdef CONFIG_PAX_SEGMEXEC
19489 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19490 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19491 + else
19492 +#endif
19493 +
19494 + mm->mmap_base = TASK_UNMAPPED_BASE;
19495 +
19496 +#ifdef CONFIG_PAX_RANDMMAP
19497 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19498 + mm->mmap_base += mm->delta_mmap;
19499 +#endif
19500 +
19501 + mm->free_area_cache = mm->mmap_base;
19502 + mm->cached_hole_size = ~0UL;
19503 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19504 + /*
19505 + * Restore the topdown base:
19506 + */
19507 + mm->mmap_base = base;
19508 + mm->free_area_cache = base;
19509 + mm->cached_hole_size = ~0UL;
19510 +
19511 + return addr;
19512 }
19513 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19514 index b4d3c39..82bb73b 100644
19515 --- a/arch/x86/kernel/sys_x86_64.c
19516 +++ b/arch/x86/kernel/sys_x86_64.c
19517 @@ -95,8 +95,8 @@ out:
19518 return error;
19519 }
19520
19521 -static void find_start_end(unsigned long flags, unsigned long *begin,
19522 - unsigned long *end)
19523 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19524 + unsigned long *begin, unsigned long *end)
19525 {
19526 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19527 unsigned long new_begin;
19528 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19529 *begin = new_begin;
19530 }
19531 } else {
19532 - *begin = TASK_UNMAPPED_BASE;
19533 + *begin = mm->mmap_base;
19534 *end = TASK_SIZE;
19535 }
19536 }
19537 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19538 if (flags & MAP_FIXED)
19539 return addr;
19540
19541 - find_start_end(flags, &begin, &end);
19542 + find_start_end(mm, flags, &begin, &end);
19543
19544 if (len > end)
19545 return -ENOMEM;
19546
19547 +#ifdef CONFIG_PAX_RANDMMAP
19548 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19549 +#endif
19550 +
19551 if (addr) {
19552 addr = PAGE_ALIGN(addr);
19553 vma = find_vma(mm, addr);
19554 - if (end - len >= addr &&
19555 - (!vma || addr + len <= vma->vm_start))
19556 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19557 return addr;
19558 }
19559 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19560 @@ -172,7 +175,7 @@ full_search:
19561 }
19562 return -ENOMEM;
19563 }
19564 - if (!vma || addr + len <= vma->vm_start) {
19565 + if (check_heap_stack_gap(vma, addr, len)) {
19566 /*
19567 * Remember the place where we stopped the search:
19568 */
19569 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19570 {
19571 struct vm_area_struct *vma;
19572 struct mm_struct *mm = current->mm;
19573 - unsigned long addr = addr0, start_addr;
19574 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19575
19576 /* requested length too big for entire address space */
19577 if (len > TASK_SIZE)
19578 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19579 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19580 goto bottomup;
19581
19582 +#ifdef CONFIG_PAX_RANDMMAP
19583 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19584 +#endif
19585 +
19586 /* requesting a specific address */
19587 if (addr) {
19588 addr = PAGE_ALIGN(addr);
19589 - vma = find_vma(mm, addr);
19590 - if (TASK_SIZE - len >= addr &&
19591 - (!vma || addr + len <= vma->vm_start))
19592 - return addr;
19593 + if (TASK_SIZE - len >= addr) {
19594 + vma = find_vma(mm, addr);
19595 + if (check_heap_stack_gap(vma, addr, len))
19596 + return addr;
19597 + }
19598 }
19599
19600 /* check if free_area_cache is useful for us */
19601 @@ -240,7 +248,7 @@ try_again:
19602 * return with success:
19603 */
19604 vma = find_vma(mm, addr);
19605 - if (!vma || addr+len <= vma->vm_start)
19606 + if (check_heap_stack_gap(vma, addr, len))
19607 /* remember the address as a hint for next time */
19608 return mm->free_area_cache = addr;
19609
19610 @@ -249,8 +257,8 @@ try_again:
19611 mm->cached_hole_size = vma->vm_start - addr;
19612
19613 /* try just below the current vma->vm_start */
19614 - addr = vma->vm_start-len;
19615 - } while (len < vma->vm_start);
19616 + addr = skip_heap_stack_gap(vma, len);
19617 + } while (!IS_ERR_VALUE(addr));
19618
19619 fail:
19620 /*
19621 @@ -270,13 +278,21 @@ bottomup:
19622 * can happen with large stack limits and large mmap()
19623 * allocations.
19624 */
19625 + mm->mmap_base = TASK_UNMAPPED_BASE;
19626 +
19627 +#ifdef CONFIG_PAX_RANDMMAP
19628 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19629 + mm->mmap_base += mm->delta_mmap;
19630 +#endif
19631 +
19632 + mm->free_area_cache = mm->mmap_base;
19633 mm->cached_hole_size = ~0UL;
19634 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19635 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19636 /*
19637 * Restore the topdown base:
19638 */
19639 - mm->free_area_cache = mm->mmap_base;
19640 + mm->mmap_base = base;
19641 + mm->free_area_cache = base;
19642 mm->cached_hole_size = ~0UL;
19643
19644 return addr;
19645 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19646 index f84fe00..93fe08f 100644
19647 --- a/arch/x86/kernel/tboot.c
19648 +++ b/arch/x86/kernel/tboot.c
19649 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19650
19651 void tboot_shutdown(u32 shutdown_type)
19652 {
19653 - void (*shutdown)(void);
19654 + void (* __noreturn shutdown)(void);
19655
19656 if (!tboot_enabled())
19657 return;
19658 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19659
19660 switch_to_tboot_pt();
19661
19662 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19663 + shutdown = (void *)tboot->shutdown_entry;
19664 shutdown();
19665
19666 /* should not reach here */
19667 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19668 return 0;
19669 }
19670
19671 -static atomic_t ap_wfs_count;
19672 +static atomic_unchecked_t ap_wfs_count;
19673
19674 static int tboot_wait_for_aps(int num_aps)
19675 {
19676 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19677 {
19678 switch (action) {
19679 case CPU_DYING:
19680 - atomic_inc(&ap_wfs_count);
19681 + atomic_inc_unchecked(&ap_wfs_count);
19682 if (num_online_cpus() == 1)
19683 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19684 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19685 return NOTIFY_BAD;
19686 break;
19687 }
19688 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19689
19690 tboot_create_trampoline();
19691
19692 - atomic_set(&ap_wfs_count, 0);
19693 + atomic_set_unchecked(&ap_wfs_count, 0);
19694 register_hotcpu_notifier(&tboot_cpu_notifier);
19695
19696 acpi_os_set_prepare_sleep(&tboot_sleep);
19697 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19698 index 24d3c91..d06b473 100644
19699 --- a/arch/x86/kernel/time.c
19700 +++ b/arch/x86/kernel/time.c
19701 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19702 {
19703 unsigned long pc = instruction_pointer(regs);
19704
19705 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19706 + if (!user_mode(regs) && in_lock_functions(pc)) {
19707 #ifdef CONFIG_FRAME_POINTER
19708 - return *(unsigned long *)(regs->bp + sizeof(long));
19709 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19710 #else
19711 unsigned long *sp =
19712 (unsigned long *)kernel_stack_pointer(regs);
19713 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19714 * or above a saved flags. Eflags has bits 22-31 zero,
19715 * kernel addresses don't.
19716 */
19717 +
19718 +#ifdef CONFIG_PAX_KERNEXEC
19719 + return ktla_ktva(sp[0]);
19720 +#else
19721 if (sp[0] >> 22)
19722 return sp[0];
19723 if (sp[1] >> 22)
19724 return sp[1];
19725 #endif
19726 +
19727 +#endif
19728 }
19729 return pc;
19730 }
19731 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19732 index 9d9d2f9..cad418a 100644
19733 --- a/arch/x86/kernel/tls.c
19734 +++ b/arch/x86/kernel/tls.c
19735 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19736 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19737 return -EINVAL;
19738
19739 +#ifdef CONFIG_PAX_SEGMEXEC
19740 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19741 + return -EINVAL;
19742 +#endif
19743 +
19744 set_tls_desc(p, idx, &info, 1);
19745
19746 return 0;
19747 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19748
19749 if (kbuf)
19750 info = kbuf;
19751 - else if (__copy_from_user(infobuf, ubuf, count))
19752 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19753 return -EFAULT;
19754 else
19755 info = infobuf;
19756 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19757 index b481341..5918bbe 100644
19758 --- a/arch/x86/kernel/traps.c
19759 +++ b/arch/x86/kernel/traps.c
19760 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19761
19762 /* Do we ignore FPU interrupts ? */
19763 char ignore_fpu_irq;
19764 -
19765 -/*
19766 - * The IDT has to be page-aligned to simplify the Pentium
19767 - * F0 0F bug workaround.
19768 - */
19769 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19770 #endif
19771
19772 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19773 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19774 }
19775
19776 static void __kprobes
19777 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19778 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19779 long error_code, siginfo_t *info)
19780 {
19781 struct task_struct *tsk = current;
19782
19783 #ifdef CONFIG_X86_32
19784 - if (regs->flags & X86_VM_MASK) {
19785 + if (v8086_mode(regs)) {
19786 /*
19787 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19788 * On nmi (interrupt 2), do_trap should not be called.
19789 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19790 }
19791 #endif
19792
19793 - if (!user_mode(regs))
19794 + if (!user_mode_novm(regs))
19795 goto kernel_trap;
19796
19797 #ifdef CONFIG_X86_32
19798 @@ -147,7 +141,7 @@ trap_signal:
19799 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19800 printk_ratelimit()) {
19801 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19802 - tsk->comm, tsk->pid, str,
19803 + tsk->comm, task_pid_nr(tsk), str,
19804 regs->ip, regs->sp, error_code);
19805 print_vma_addr(" in ", regs->ip);
19806 pr_cont("\n");
19807 @@ -164,8 +158,20 @@ kernel_trap:
19808 if (!fixup_exception(regs)) {
19809 tsk->thread.error_code = error_code;
19810 tsk->thread.trap_nr = trapnr;
19811 +
19812 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19813 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19814 + str = "PAX: suspicious stack segment fault";
19815 +#endif
19816 +
19817 die(str, regs, error_code);
19818 }
19819 +
19820 +#ifdef CONFIG_PAX_REFCOUNT
19821 + if (trapnr == 4)
19822 + pax_report_refcount_overflow(regs);
19823 +#endif
19824 +
19825 return;
19826
19827 #ifdef CONFIG_X86_32
19828 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19829 conditional_sti(regs);
19830
19831 #ifdef CONFIG_X86_32
19832 - if (regs->flags & X86_VM_MASK)
19833 + if (v8086_mode(regs))
19834 goto gp_in_vm86;
19835 #endif
19836
19837 tsk = current;
19838 - if (!user_mode(regs))
19839 + if (!user_mode_novm(regs))
19840 goto gp_in_kernel;
19841
19842 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19843 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19844 + struct mm_struct *mm = tsk->mm;
19845 + unsigned long limit;
19846 +
19847 + down_write(&mm->mmap_sem);
19848 + limit = mm->context.user_cs_limit;
19849 + if (limit < TASK_SIZE) {
19850 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19851 + up_write(&mm->mmap_sem);
19852 + return;
19853 + }
19854 + up_write(&mm->mmap_sem);
19855 + }
19856 +#endif
19857 +
19858 tsk->thread.error_code = error_code;
19859 tsk->thread.trap_nr = X86_TRAP_GP;
19860
19861 @@ -297,6 +319,13 @@ gp_in_kernel:
19862 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19863 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19864 return;
19865 +
19866 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19867 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19868 + die("PAX: suspicious general protection fault", regs, error_code);
19869 + else
19870 +#endif
19871 +
19872 die("general protection fault", regs, error_code);
19873 }
19874
19875 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19876 /* It's safe to allow irq's after DR6 has been saved */
19877 preempt_conditional_sti(regs);
19878
19879 - if (regs->flags & X86_VM_MASK) {
19880 + if (v8086_mode(regs)) {
19881 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19882 X86_TRAP_DB);
19883 preempt_conditional_cli(regs);
19884 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19885 * We already checked v86 mode above, so we can check for kernel mode
19886 * by just checking the CPL of CS.
19887 */
19888 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19889 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19890 tsk->thread.debugreg6 &= ~DR_STEP;
19891 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19892 regs->flags &= ~X86_EFLAGS_TF;
19893 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19894 return;
19895 conditional_sti(regs);
19896
19897 - if (!user_mode_vm(regs))
19898 + if (!user_mode(regs))
19899 {
19900 if (!fixup_exception(regs)) {
19901 task->thread.error_code = error_code;
19902 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19903 index 36fd420..7e5892d 100644
19904 --- a/arch/x86/kernel/uprobes.c
19905 +++ b/arch/x86/kernel/uprobes.c
19906 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19907 int ret = NOTIFY_DONE;
19908
19909 /* We are only interested in userspace traps */
19910 - if (regs && !user_mode_vm(regs))
19911 + if (regs && !user_mode(regs))
19912 return NOTIFY_DONE;
19913
19914 switch (val) {
19915 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19916 index b9242ba..50c5edd 100644
19917 --- a/arch/x86/kernel/verify_cpu.S
19918 +++ b/arch/x86/kernel/verify_cpu.S
19919 @@ -20,6 +20,7 @@
19920 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19921 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19922 * arch/x86/kernel/head_32.S: processor startup
19923 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19924 *
19925 * verify_cpu, returns the status of longmode and SSE in register %eax.
19926 * 0: Success 1: Failure
19927 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19928 index 54abcc0..eb6c848 100644
19929 --- a/arch/x86/kernel/vm86_32.c
19930 +++ b/arch/x86/kernel/vm86_32.c
19931 @@ -43,6 +43,7 @@
19932 #include <linux/ptrace.h>
19933 #include <linux/audit.h>
19934 #include <linux/stddef.h>
19935 +#include <linux/grsecurity.h>
19936
19937 #include <asm/uaccess.h>
19938 #include <asm/io.h>
19939 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19940 do_exit(SIGSEGV);
19941 }
19942
19943 - tss = &per_cpu(init_tss, get_cpu());
19944 + tss = init_tss + get_cpu();
19945 current->thread.sp0 = current->thread.saved_sp0;
19946 current->thread.sysenter_cs = __KERNEL_CS;
19947 load_sp0(tss, &current->thread);
19948 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19949 struct task_struct *tsk;
19950 int tmp, ret = -EPERM;
19951
19952 +#ifdef CONFIG_GRKERNSEC_VM86
19953 + if (!capable(CAP_SYS_RAWIO)) {
19954 + gr_handle_vm86();
19955 + goto out;
19956 + }
19957 +#endif
19958 +
19959 tsk = current;
19960 if (tsk->thread.saved_sp0)
19961 goto out;
19962 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19963 int tmp, ret;
19964 struct vm86plus_struct __user *v86;
19965
19966 +#ifdef CONFIG_GRKERNSEC_VM86
19967 + if (!capable(CAP_SYS_RAWIO)) {
19968 + gr_handle_vm86();
19969 + ret = -EPERM;
19970 + goto out;
19971 + }
19972 +#endif
19973 +
19974 tsk = current;
19975 switch (cmd) {
19976 case VM86_REQUEST_IRQ:
19977 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19978 tsk->thread.saved_fs = info->regs32->fs;
19979 tsk->thread.saved_gs = get_user_gs(info->regs32);
19980
19981 - tss = &per_cpu(init_tss, get_cpu());
19982 + tss = init_tss + get_cpu();
19983 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19984 if (cpu_has_sep)
19985 tsk->thread.sysenter_cs = 0;
19986 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19987 goto cannot_handle;
19988 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19989 goto cannot_handle;
19990 - intr_ptr = (unsigned long __user *) (i << 2);
19991 + intr_ptr = (__force unsigned long __user *) (i << 2);
19992 if (get_user(segoffs, intr_ptr))
19993 goto cannot_handle;
19994 if ((segoffs >> 16) == BIOSSEG)
19995 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19996 index 22a1530..8fbaaad 100644
19997 --- a/arch/x86/kernel/vmlinux.lds.S
19998 +++ b/arch/x86/kernel/vmlinux.lds.S
19999 @@ -26,6 +26,13 @@
20000 #include <asm/page_types.h>
20001 #include <asm/cache.h>
20002 #include <asm/boot.h>
20003 +#include <asm/segment.h>
20004 +
20005 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20006 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20007 +#else
20008 +#define __KERNEL_TEXT_OFFSET 0
20009 +#endif
20010
20011 #undef i386 /* in case the preprocessor is a 32bit one */
20012
20013 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20014
20015 PHDRS {
20016 text PT_LOAD FLAGS(5); /* R_E */
20017 +#ifdef CONFIG_X86_32
20018 + module PT_LOAD FLAGS(5); /* R_E */
20019 +#endif
20020 +#ifdef CONFIG_XEN
20021 + rodata PT_LOAD FLAGS(5); /* R_E */
20022 +#else
20023 + rodata PT_LOAD FLAGS(4); /* R__ */
20024 +#endif
20025 data PT_LOAD FLAGS(6); /* RW_ */
20026 -#ifdef CONFIG_X86_64
20027 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20028 #ifdef CONFIG_SMP
20029 percpu PT_LOAD FLAGS(6); /* RW_ */
20030 #endif
20031 + text.init PT_LOAD FLAGS(5); /* R_E */
20032 + text.exit PT_LOAD FLAGS(5); /* R_E */
20033 init PT_LOAD FLAGS(7); /* RWE */
20034 -#endif
20035 note PT_NOTE FLAGS(0); /* ___ */
20036 }
20037
20038 SECTIONS
20039 {
20040 #ifdef CONFIG_X86_32
20041 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20042 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20043 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20044 #else
20045 - . = __START_KERNEL;
20046 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20047 + . = __START_KERNEL;
20048 #endif
20049
20050 /* Text and read-only data */
20051 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20052 - _text = .;
20053 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20054 /* bootstrapping code */
20055 +#ifdef CONFIG_X86_32
20056 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20057 +#else
20058 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20059 +#endif
20060 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20061 + _text = .;
20062 HEAD_TEXT
20063 #ifdef CONFIG_X86_32
20064 . = ALIGN(PAGE_SIZE);
20065 @@ -108,13 +128,48 @@ SECTIONS
20066 IRQENTRY_TEXT
20067 *(.fixup)
20068 *(.gnu.warning)
20069 - /* End of text section */
20070 - _etext = .;
20071 } :text = 0x9090
20072
20073 - NOTES :text :note
20074 + . += __KERNEL_TEXT_OFFSET;
20075
20076 - EXCEPTION_TABLE(16) :text = 0x9090
20077 +#ifdef CONFIG_X86_32
20078 + . = ALIGN(PAGE_SIZE);
20079 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20080 +
20081 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20082 + MODULES_EXEC_VADDR = .;
20083 + BYTE(0)
20084 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20085 + . = ALIGN(HPAGE_SIZE) - 1;
20086 + MODULES_EXEC_END = .;
20087 +#endif
20088 +
20089 + } :module
20090 +#endif
20091 +
20092 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20093 + /* End of text section */
20094 + BYTE(0)
20095 + _etext = . - __KERNEL_TEXT_OFFSET;
20096 + }
20097 +
20098 +#ifdef CONFIG_X86_32
20099 + . = ALIGN(PAGE_SIZE);
20100 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20101 + *(.idt)
20102 + . = ALIGN(PAGE_SIZE);
20103 + *(.empty_zero_page)
20104 + *(.initial_pg_fixmap)
20105 + *(.initial_pg_pmd)
20106 + *(.initial_page_table)
20107 + *(.swapper_pg_dir)
20108 + } :rodata
20109 +#endif
20110 +
20111 + . = ALIGN(PAGE_SIZE);
20112 + NOTES :rodata :note
20113 +
20114 + EXCEPTION_TABLE(16) :rodata
20115
20116 #if defined(CONFIG_DEBUG_RODATA)
20117 /* .text should occupy whole number of pages */
20118 @@ -126,16 +181,20 @@ SECTIONS
20119
20120 /* Data */
20121 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20122 +
20123 +#ifdef CONFIG_PAX_KERNEXEC
20124 + . = ALIGN(HPAGE_SIZE);
20125 +#else
20126 + . = ALIGN(PAGE_SIZE);
20127 +#endif
20128 +
20129 /* Start of data section */
20130 _sdata = .;
20131
20132 /* init_task */
20133 INIT_TASK_DATA(THREAD_SIZE)
20134
20135 -#ifdef CONFIG_X86_32
20136 - /* 32 bit has nosave before _edata */
20137 NOSAVE_DATA
20138 -#endif
20139
20140 PAGE_ALIGNED_DATA(PAGE_SIZE)
20141
20142 @@ -176,12 +235,19 @@ SECTIONS
20143 #endif /* CONFIG_X86_64 */
20144
20145 /* Init code and data - will be freed after init */
20146 - . = ALIGN(PAGE_SIZE);
20147 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20148 + BYTE(0)
20149 +
20150 +#ifdef CONFIG_PAX_KERNEXEC
20151 + . = ALIGN(HPAGE_SIZE);
20152 +#else
20153 + . = ALIGN(PAGE_SIZE);
20154 +#endif
20155 +
20156 __init_begin = .; /* paired with __init_end */
20157 - }
20158 + } :init.begin
20159
20160 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20161 +#ifdef CONFIG_SMP
20162 /*
20163 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20164 * output PHDR, so the next output section - .init.text - should
20165 @@ -190,12 +256,27 @@ SECTIONS
20166 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20167 #endif
20168
20169 - INIT_TEXT_SECTION(PAGE_SIZE)
20170 -#ifdef CONFIG_X86_64
20171 - :init
20172 -#endif
20173 + . = ALIGN(PAGE_SIZE);
20174 + init_begin = .;
20175 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20176 + VMLINUX_SYMBOL(_sinittext) = .;
20177 + INIT_TEXT
20178 + VMLINUX_SYMBOL(_einittext) = .;
20179 + . = ALIGN(PAGE_SIZE);
20180 + } :text.init
20181
20182 - INIT_DATA_SECTION(16)
20183 + /*
20184 + * .exit.text is discard at runtime, not link time, to deal with
20185 + * references from .altinstructions and .eh_frame
20186 + */
20187 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20188 + EXIT_TEXT
20189 + . = ALIGN(16);
20190 + } :text.exit
20191 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20192 +
20193 + . = ALIGN(PAGE_SIZE);
20194 + INIT_DATA_SECTION(16) :init
20195
20196 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20197 __x86_cpu_dev_start = .;
20198 @@ -257,19 +338,12 @@ SECTIONS
20199 }
20200
20201 . = ALIGN(8);
20202 - /*
20203 - * .exit.text is discard at runtime, not link time, to deal with
20204 - * references from .altinstructions and .eh_frame
20205 - */
20206 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20207 - EXIT_TEXT
20208 - }
20209
20210 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20211 EXIT_DATA
20212 }
20213
20214 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20215 +#ifndef CONFIG_SMP
20216 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20217 #endif
20218
20219 @@ -288,16 +362,10 @@ SECTIONS
20220 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20221 __smp_locks = .;
20222 *(.smp_locks)
20223 - . = ALIGN(PAGE_SIZE);
20224 __smp_locks_end = .;
20225 + . = ALIGN(PAGE_SIZE);
20226 }
20227
20228 -#ifdef CONFIG_X86_64
20229 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20230 - NOSAVE_DATA
20231 - }
20232 -#endif
20233 -
20234 /* BSS */
20235 . = ALIGN(PAGE_SIZE);
20236 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20237 @@ -313,6 +381,7 @@ SECTIONS
20238 __brk_base = .;
20239 . += 64 * 1024; /* 64k alignment slop space */
20240 *(.brk_reservation) /* areas brk users have reserved */
20241 + . = ALIGN(HPAGE_SIZE);
20242 __brk_limit = .;
20243 }
20244
20245 @@ -339,13 +408,12 @@ SECTIONS
20246 * for the boot processor.
20247 */
20248 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20249 -INIT_PER_CPU(gdt_page);
20250 INIT_PER_CPU(irq_stack_union);
20251
20252 /*
20253 * Build-time check on the image size:
20254 */
20255 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20256 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20257 "kernel image bigger than KERNEL_IMAGE_SIZE");
20258
20259 #ifdef CONFIG_SMP
20260 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20261 index 992f890..fc38904 100644
20262 --- a/arch/x86/kernel/vsmp_64.c
20263 +++ b/arch/x86/kernel/vsmp_64.c
20264 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20265 static void vsmp_apic_post_init(void)
20266 {
20267 /* need to update phys_pkg_id */
20268 - apic->phys_pkg_id = apicid_phys_pkg_id;
20269 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20270 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20271 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20272 }
20273
20274 void __init vsmp_init(void)
20275 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20276 index 8d141b3..40a0fe4 100644
20277 --- a/arch/x86/kernel/vsyscall_64.c
20278 +++ b/arch/x86/kernel/vsyscall_64.c
20279 @@ -56,15 +56,13 @@
20280 DEFINE_VVAR(int, vgetcpu_mode);
20281 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20282
20283 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20284 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20285
20286 static int __init vsyscall_setup(char *str)
20287 {
20288 if (str) {
20289 if (!strcmp("emulate", str))
20290 vsyscall_mode = EMULATE;
20291 - else if (!strcmp("native", str))
20292 - vsyscall_mode = NATIVE;
20293 else if (!strcmp("none", str))
20294 vsyscall_mode = NONE;
20295 else
20296 @@ -306,8 +304,7 @@ done:
20297 return true;
20298
20299 sigsegv:
20300 - force_sig(SIGSEGV, current);
20301 - return true;
20302 + do_group_exit(SIGKILL);
20303 }
20304
20305 /*
20306 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20307 extern char __vvar_page;
20308 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20309
20310 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20311 - vsyscall_mode == NATIVE
20312 - ? PAGE_KERNEL_VSYSCALL
20313 - : PAGE_KERNEL_VVAR);
20314 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20315 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20316 (unsigned long)VSYSCALL_START);
20317
20318 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20319 index 6020f6f..bedd6e3 100644
20320 --- a/arch/x86/kernel/x8664_ksyms_64.c
20321 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20322 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20323 EXPORT_SYMBOL(copy_user_generic_unrolled);
20324 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20325 EXPORT_SYMBOL(__copy_user_nocache);
20326 -EXPORT_SYMBOL(_copy_from_user);
20327 -EXPORT_SYMBOL(_copy_to_user);
20328
20329 EXPORT_SYMBOL(copy_page);
20330 EXPORT_SYMBOL(clear_page);
20331 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20332 index 3d3e207..1a73ab2 100644
20333 --- a/arch/x86/kernel/xsave.c
20334 +++ b/arch/x86/kernel/xsave.c
20335 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20336 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20337 return -EINVAL;
20338
20339 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20340 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20341 fx_sw_user->extended_size -
20342 FP_XSTATE_MAGIC2_SIZE));
20343 if (err)
20344 @@ -268,7 +268,7 @@ fx_only:
20345 * the other extended state.
20346 */
20347 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20348 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20349 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20350 }
20351
20352 /*
20353 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20354 if (use_xsave())
20355 err = restore_user_xstate(buf);
20356 else
20357 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20358 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20359 buf);
20360 if (unlikely(err)) {
20361 /*
20362 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20363 index 0595f13..b544fa3 100644
20364 --- a/arch/x86/kvm/cpuid.c
20365 +++ b/arch/x86/kvm/cpuid.c
20366 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20367 struct kvm_cpuid2 *cpuid,
20368 struct kvm_cpuid_entry2 __user *entries)
20369 {
20370 - int r;
20371 + int r, i;
20372
20373 r = -E2BIG;
20374 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20375 goto out;
20376 r = -EFAULT;
20377 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20378 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20379 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20380 goto out;
20381 + for (i = 0; i < cpuid->nent; ++i) {
20382 + struct kvm_cpuid_entry2 cpuid_entry;
20383 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20384 + goto out;
20385 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20386 + }
20387 vcpu->arch.cpuid_nent = cpuid->nent;
20388 kvm_apic_set_version(vcpu);
20389 kvm_x86_ops->cpuid_update(vcpu);
20390 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20391 struct kvm_cpuid2 *cpuid,
20392 struct kvm_cpuid_entry2 __user *entries)
20393 {
20394 - int r;
20395 + int r, i;
20396
20397 r = -E2BIG;
20398 if (cpuid->nent < vcpu->arch.cpuid_nent)
20399 goto out;
20400 r = -EFAULT;
20401 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20402 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20403 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20404 goto out;
20405 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20406 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20407 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20408 + goto out;
20409 + }
20410 return 0;
20411
20412 out:
20413 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20414 index a3b57a2..ebbe732 100644
20415 --- a/arch/x86/kvm/emulate.c
20416 +++ b/arch/x86/kvm/emulate.c
20417 @@ -256,6 +256,7 @@ struct gprefix {
20418
20419 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20420 do { \
20421 + unsigned long _tmp; \
20422 __asm__ __volatile__ ( \
20423 _PRE_EFLAGS("0", "4", "2") \
20424 _op _suffix " %"_x"3,%1; " \
20425 @@ -270,8 +271,6 @@ struct gprefix {
20426 /* Raw emulation: instruction has two explicit operands. */
20427 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20428 do { \
20429 - unsigned long _tmp; \
20430 - \
20431 switch ((ctxt)->dst.bytes) { \
20432 case 2: \
20433 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20434 @@ -287,7 +286,6 @@ struct gprefix {
20435
20436 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20437 do { \
20438 - unsigned long _tmp; \
20439 switch ((ctxt)->dst.bytes) { \
20440 case 1: \
20441 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20442 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20443 index ce87878..ab48aa3 100644
20444 --- a/arch/x86/kvm/lapic.c
20445 +++ b/arch/x86/kvm/lapic.c
20446 @@ -54,7 +54,7 @@
20447 #define APIC_BUS_CYCLE_NS 1
20448
20449 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20450 -#define apic_debug(fmt, arg...)
20451 +#define apic_debug(fmt, arg...) do {} while (0)
20452
20453 #define APIC_LVT_NUM 6
20454 /* 14 is the version for Xeon and Pentium 8.4.8*/
20455 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20456 index bb7cf01..0348a05 100644
20457 --- a/arch/x86/kvm/paging_tmpl.h
20458 +++ b/arch/x86/kvm/paging_tmpl.h
20459 @@ -196,7 +196,7 @@ retry_walk:
20460 if (unlikely(kvm_is_error_hva(host_addr)))
20461 goto error;
20462
20463 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20464 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20465 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20466 goto error;
20467
20468 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20469 index baead95..90feeb4 100644
20470 --- a/arch/x86/kvm/svm.c
20471 +++ b/arch/x86/kvm/svm.c
20472 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20473 int cpu = raw_smp_processor_id();
20474
20475 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20476 +
20477 + pax_open_kernel();
20478 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20479 + pax_close_kernel();
20480 +
20481 load_TR_desc();
20482 }
20483
20484 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20485 #endif
20486 #endif
20487
20488 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20489 + __set_fs(current_thread_info()->addr_limit);
20490 +#endif
20491 +
20492 reload_tss(vcpu);
20493
20494 local_irq_disable();
20495 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20496 index b1eb202..254e292 100644
20497 --- a/arch/x86/kvm/vmx.c
20498 +++ b/arch/x86/kvm/vmx.c
20499 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20500 struct desc_struct *descs;
20501
20502 descs = (void *)gdt->address;
20503 +
20504 + pax_open_kernel();
20505 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20506 + pax_close_kernel();
20507 +
20508 load_TR_desc();
20509 }
20510
20511 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20512 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20513 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20514
20515 +#ifdef CONFIG_PAX_PER_CPU_PGD
20516 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20517 +#endif
20518 +
20519 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20520 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20521 vmx->loaded_vmcs->cpu = cpu;
20522 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20523 if (!cpu_has_vmx_flexpriority())
20524 flexpriority_enabled = 0;
20525
20526 - if (!cpu_has_vmx_tpr_shadow())
20527 - kvm_x86_ops->update_cr8_intercept = NULL;
20528 + if (!cpu_has_vmx_tpr_shadow()) {
20529 + pax_open_kernel();
20530 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20531 + pax_close_kernel();
20532 + }
20533
20534 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20535 kvm_disable_largepages();
20536 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20537
20538 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20539 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20540 +
20541 +#ifndef CONFIG_PAX_PER_CPU_PGD
20542 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20543 +#endif
20544
20545 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20546 #ifdef CONFIG_X86_64
20547 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20548 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20549
20550 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20551 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20552 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20553
20554 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20555 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20556 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20557 "jmp .Lkvm_vmx_return \n\t"
20558 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20559 ".Lkvm_vmx_return: "
20560 +
20561 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20562 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20563 + ".Lkvm_vmx_return2: "
20564 +#endif
20565 +
20566 /* Save guest registers, load host registers, keep flags */
20567 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20568 "pop %0 \n\t"
20569 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20570 #endif
20571 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20572 [wordsize]"i"(sizeof(ulong))
20573 +
20574 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20575 + ,[cs]"i"(__KERNEL_CS)
20576 +#endif
20577 +
20578 : "cc", "memory"
20579 , R"ax", R"bx", R"di", R"si"
20580 #ifdef CONFIG_X86_64
20581 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20582 #endif
20583 );
20584
20585 -#ifndef CONFIG_X86_64
20586 +#ifdef CONFIG_X86_32
20587 /*
20588 * The sysexit path does not restore ds/es, so we must set them to
20589 * a reasonable value ourselves.
20590 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20591 * may be executed in interrupt context, which saves and restore segments
20592 * around it, nullifying its effect.
20593 */
20594 - loadsegment(ds, __USER_DS);
20595 - loadsegment(es, __USER_DS);
20596 + loadsegment(ds, __KERNEL_DS);
20597 + loadsegment(es, __KERNEL_DS);
20598 + loadsegment(ss, __KERNEL_DS);
20599 +
20600 +#ifdef CONFIG_PAX_KERNEXEC
20601 + loadsegment(fs, __KERNEL_PERCPU);
20602 +#endif
20603 +
20604 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20605 + __set_fs(current_thread_info()->addr_limit);
20606 +#endif
20607 +
20608 #endif
20609
20610 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20611 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20612 index 2966c84..207d0cb 100644
20613 --- a/arch/x86/kvm/x86.c
20614 +++ b/arch/x86/kvm/x86.c
20615 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20616 {
20617 struct kvm *kvm = vcpu->kvm;
20618 int lm = is_long_mode(vcpu);
20619 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20620 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20621 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20622 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20623 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20624 : kvm->arch.xen_hvm_config.blob_size_32;
20625 u32 page_num = data & ~PAGE_MASK;
20626 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20627 if (n < msr_list.nmsrs)
20628 goto out;
20629 r = -EFAULT;
20630 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20631 + goto out;
20632 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20633 num_msrs_to_save * sizeof(u32)))
20634 goto out;
20635 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20636 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20637 struct kvm_interrupt *irq)
20638 {
20639 - if (irq->irq < 0 || irq->irq >= 256)
20640 + if (irq->irq >= 256)
20641 return -EINVAL;
20642 if (irqchip_in_kernel(vcpu->kvm))
20643 return -ENXIO;
20644 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20645 kvm_mmu_set_mmio_spte_mask(mask);
20646 }
20647
20648 -int kvm_arch_init(void *opaque)
20649 +int kvm_arch_init(const void *opaque)
20650 {
20651 int r;
20652 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20653 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20654 index 642d880..cc9ebac 100644
20655 --- a/arch/x86/lguest/boot.c
20656 +++ b/arch/x86/lguest/boot.c
20657 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20658
20659 static void set_lguest_basic_apic_ops(void)
20660 {
20661 - apic->read = lguest_apic_read;
20662 - apic->write = lguest_apic_write;
20663 - apic->icr_read = lguest_apic_icr_read;
20664 - apic->icr_write = lguest_apic_icr_write;
20665 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20666 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20667 + *(void **)&apic->read = lguest_apic_read;
20668 + *(void **)&apic->write = lguest_apic_write;
20669 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20670 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20671 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20672 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20673 };
20674 #endif
20675
20676 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20677 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20678 * Launcher to reboot us.
20679 */
20680 -static void lguest_restart(char *reason)
20681 +static __noreturn void lguest_restart(char *reason)
20682 {
20683 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20684 + BUG();
20685 }
20686
20687 /*G:050
20688 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20689 index 00933d5..3a64af9 100644
20690 --- a/arch/x86/lib/atomic64_386_32.S
20691 +++ b/arch/x86/lib/atomic64_386_32.S
20692 @@ -48,6 +48,10 @@ BEGIN(read)
20693 movl (v), %eax
20694 movl 4(v), %edx
20695 RET_ENDP
20696 +BEGIN(read_unchecked)
20697 + movl (v), %eax
20698 + movl 4(v), %edx
20699 +RET_ENDP
20700 #undef v
20701
20702 #define v %esi
20703 @@ -55,6 +59,10 @@ BEGIN(set)
20704 movl %ebx, (v)
20705 movl %ecx, 4(v)
20706 RET_ENDP
20707 +BEGIN(set_unchecked)
20708 + movl %ebx, (v)
20709 + movl %ecx, 4(v)
20710 +RET_ENDP
20711 #undef v
20712
20713 #define v %esi
20714 @@ -70,6 +78,20 @@ RET_ENDP
20715 BEGIN(add)
20716 addl %eax, (v)
20717 adcl %edx, 4(v)
20718 +
20719 +#ifdef CONFIG_PAX_REFCOUNT
20720 + jno 0f
20721 + subl %eax, (v)
20722 + sbbl %edx, 4(v)
20723 + int $4
20724 +0:
20725 + _ASM_EXTABLE(0b, 0b)
20726 +#endif
20727 +
20728 +RET_ENDP
20729 +BEGIN(add_unchecked)
20730 + addl %eax, (v)
20731 + adcl %edx, 4(v)
20732 RET_ENDP
20733 #undef v
20734
20735 @@ -77,6 +99,24 @@ RET_ENDP
20736 BEGIN(add_return)
20737 addl (v), %eax
20738 adcl 4(v), %edx
20739 +
20740 +#ifdef CONFIG_PAX_REFCOUNT
20741 + into
20742 +1234:
20743 + _ASM_EXTABLE(1234b, 2f)
20744 +#endif
20745 +
20746 + movl %eax, (v)
20747 + movl %edx, 4(v)
20748 +
20749 +#ifdef CONFIG_PAX_REFCOUNT
20750 +2:
20751 +#endif
20752 +
20753 +RET_ENDP
20754 +BEGIN(add_return_unchecked)
20755 + addl (v), %eax
20756 + adcl 4(v), %edx
20757 movl %eax, (v)
20758 movl %edx, 4(v)
20759 RET_ENDP
20760 @@ -86,6 +126,20 @@ RET_ENDP
20761 BEGIN(sub)
20762 subl %eax, (v)
20763 sbbl %edx, 4(v)
20764 +
20765 +#ifdef CONFIG_PAX_REFCOUNT
20766 + jno 0f
20767 + addl %eax, (v)
20768 + adcl %edx, 4(v)
20769 + int $4
20770 +0:
20771 + _ASM_EXTABLE(0b, 0b)
20772 +#endif
20773 +
20774 +RET_ENDP
20775 +BEGIN(sub_unchecked)
20776 + subl %eax, (v)
20777 + sbbl %edx, 4(v)
20778 RET_ENDP
20779 #undef v
20780
20781 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20782 sbbl $0, %edx
20783 addl (v), %eax
20784 adcl 4(v), %edx
20785 +
20786 +#ifdef CONFIG_PAX_REFCOUNT
20787 + into
20788 +1234:
20789 + _ASM_EXTABLE(1234b, 2f)
20790 +#endif
20791 +
20792 + movl %eax, (v)
20793 + movl %edx, 4(v)
20794 +
20795 +#ifdef CONFIG_PAX_REFCOUNT
20796 +2:
20797 +#endif
20798 +
20799 +RET_ENDP
20800 +BEGIN(sub_return_unchecked)
20801 + negl %edx
20802 + negl %eax
20803 + sbbl $0, %edx
20804 + addl (v), %eax
20805 + adcl 4(v), %edx
20806 movl %eax, (v)
20807 movl %edx, 4(v)
20808 RET_ENDP
20809 @@ -105,6 +180,20 @@ RET_ENDP
20810 BEGIN(inc)
20811 addl $1, (v)
20812 adcl $0, 4(v)
20813 +
20814 +#ifdef CONFIG_PAX_REFCOUNT
20815 + jno 0f
20816 + subl $1, (v)
20817 + sbbl $0, 4(v)
20818 + int $4
20819 +0:
20820 + _ASM_EXTABLE(0b, 0b)
20821 +#endif
20822 +
20823 +RET_ENDP
20824 +BEGIN(inc_unchecked)
20825 + addl $1, (v)
20826 + adcl $0, 4(v)
20827 RET_ENDP
20828 #undef v
20829
20830 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20831 movl 4(v), %edx
20832 addl $1, %eax
20833 adcl $0, %edx
20834 +
20835 +#ifdef CONFIG_PAX_REFCOUNT
20836 + into
20837 +1234:
20838 + _ASM_EXTABLE(1234b, 2f)
20839 +#endif
20840 +
20841 + movl %eax, (v)
20842 + movl %edx, 4(v)
20843 +
20844 +#ifdef CONFIG_PAX_REFCOUNT
20845 +2:
20846 +#endif
20847 +
20848 +RET_ENDP
20849 +BEGIN(inc_return_unchecked)
20850 + movl (v), %eax
20851 + movl 4(v), %edx
20852 + addl $1, %eax
20853 + adcl $0, %edx
20854 movl %eax, (v)
20855 movl %edx, 4(v)
20856 RET_ENDP
20857 @@ -123,6 +232,20 @@ RET_ENDP
20858 BEGIN(dec)
20859 subl $1, (v)
20860 sbbl $0, 4(v)
20861 +
20862 +#ifdef CONFIG_PAX_REFCOUNT
20863 + jno 0f
20864 + addl $1, (v)
20865 + adcl $0, 4(v)
20866 + int $4
20867 +0:
20868 + _ASM_EXTABLE(0b, 0b)
20869 +#endif
20870 +
20871 +RET_ENDP
20872 +BEGIN(dec_unchecked)
20873 + subl $1, (v)
20874 + sbbl $0, 4(v)
20875 RET_ENDP
20876 #undef v
20877
20878 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20879 movl 4(v), %edx
20880 subl $1, %eax
20881 sbbl $0, %edx
20882 +
20883 +#ifdef CONFIG_PAX_REFCOUNT
20884 + into
20885 +1234:
20886 + _ASM_EXTABLE(1234b, 2f)
20887 +#endif
20888 +
20889 + movl %eax, (v)
20890 + movl %edx, 4(v)
20891 +
20892 +#ifdef CONFIG_PAX_REFCOUNT
20893 +2:
20894 +#endif
20895 +
20896 +RET_ENDP
20897 +BEGIN(dec_return_unchecked)
20898 + movl (v), %eax
20899 + movl 4(v), %edx
20900 + subl $1, %eax
20901 + sbbl $0, %edx
20902 movl %eax, (v)
20903 movl %edx, 4(v)
20904 RET_ENDP
20905 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20906 adcl %edx, %edi
20907 addl (v), %eax
20908 adcl 4(v), %edx
20909 +
20910 +#ifdef CONFIG_PAX_REFCOUNT
20911 + into
20912 +1234:
20913 + _ASM_EXTABLE(1234b, 2f)
20914 +#endif
20915 +
20916 cmpl %eax, %ecx
20917 je 3f
20918 1:
20919 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20920 1:
20921 addl $1, %eax
20922 adcl $0, %edx
20923 +
20924 +#ifdef CONFIG_PAX_REFCOUNT
20925 + into
20926 +1234:
20927 + _ASM_EXTABLE(1234b, 2f)
20928 +#endif
20929 +
20930 movl %eax, (v)
20931 movl %edx, 4(v)
20932 movl $1, %eax
20933 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20934 movl 4(v), %edx
20935 subl $1, %eax
20936 sbbl $0, %edx
20937 +
20938 +#ifdef CONFIG_PAX_REFCOUNT
20939 + into
20940 +1234:
20941 + _ASM_EXTABLE(1234b, 1f)
20942 +#endif
20943 +
20944 js 1f
20945 movl %eax, (v)
20946 movl %edx, 4(v)
20947 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20948 index f5cc9eb..51fa319 100644
20949 --- a/arch/x86/lib/atomic64_cx8_32.S
20950 +++ b/arch/x86/lib/atomic64_cx8_32.S
20951 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20952 CFI_STARTPROC
20953
20954 read64 %ecx
20955 + pax_force_retaddr
20956 ret
20957 CFI_ENDPROC
20958 ENDPROC(atomic64_read_cx8)
20959
20960 +ENTRY(atomic64_read_unchecked_cx8)
20961 + CFI_STARTPROC
20962 +
20963 + read64 %ecx
20964 + pax_force_retaddr
20965 + ret
20966 + CFI_ENDPROC
20967 +ENDPROC(atomic64_read_unchecked_cx8)
20968 +
20969 ENTRY(atomic64_set_cx8)
20970 CFI_STARTPROC
20971
20972 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20973 cmpxchg8b (%esi)
20974 jne 1b
20975
20976 + pax_force_retaddr
20977 ret
20978 CFI_ENDPROC
20979 ENDPROC(atomic64_set_cx8)
20980
20981 +ENTRY(atomic64_set_unchecked_cx8)
20982 + CFI_STARTPROC
20983 +
20984 +1:
20985 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20986 + * are atomic on 586 and newer */
20987 + cmpxchg8b (%esi)
20988 + jne 1b
20989 +
20990 + pax_force_retaddr
20991 + ret
20992 + CFI_ENDPROC
20993 +ENDPROC(atomic64_set_unchecked_cx8)
20994 +
20995 ENTRY(atomic64_xchg_cx8)
20996 CFI_STARTPROC
20997
20998 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20999 cmpxchg8b (%esi)
21000 jne 1b
21001
21002 + pax_force_retaddr
21003 ret
21004 CFI_ENDPROC
21005 ENDPROC(atomic64_xchg_cx8)
21006
21007 -.macro addsub_return func ins insc
21008 -ENTRY(atomic64_\func\()_return_cx8)
21009 +.macro addsub_return func ins insc unchecked=""
21010 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21011 CFI_STARTPROC
21012 SAVE ebp
21013 SAVE ebx
21014 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21015 movl %edx, %ecx
21016 \ins\()l %esi, %ebx
21017 \insc\()l %edi, %ecx
21018 +
21019 +.ifb \unchecked
21020 +#ifdef CONFIG_PAX_REFCOUNT
21021 + into
21022 +2:
21023 + _ASM_EXTABLE(2b, 3f)
21024 +#endif
21025 +.endif
21026 +
21027 LOCK_PREFIX
21028 cmpxchg8b (%ebp)
21029 jne 1b
21030 -
21031 -10:
21032 movl %ebx, %eax
21033 movl %ecx, %edx
21034 +
21035 +.ifb \unchecked
21036 +#ifdef CONFIG_PAX_REFCOUNT
21037 +3:
21038 +#endif
21039 +.endif
21040 +
21041 RESTORE edi
21042 RESTORE esi
21043 RESTORE ebx
21044 RESTORE ebp
21045 + pax_force_retaddr
21046 ret
21047 CFI_ENDPROC
21048 -ENDPROC(atomic64_\func\()_return_cx8)
21049 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21050 .endm
21051
21052 addsub_return add add adc
21053 addsub_return sub sub sbb
21054 +addsub_return add add adc _unchecked
21055 +addsub_return sub sub sbb _unchecked
21056
21057 -.macro incdec_return func ins insc
21058 -ENTRY(atomic64_\func\()_return_cx8)
21059 +.macro incdec_return func ins insc unchecked=""
21060 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21061 CFI_STARTPROC
21062 SAVE ebx
21063
21064 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21065 movl %edx, %ecx
21066 \ins\()l $1, %ebx
21067 \insc\()l $0, %ecx
21068 +
21069 +.ifb \unchecked
21070 +#ifdef CONFIG_PAX_REFCOUNT
21071 + into
21072 +2:
21073 + _ASM_EXTABLE(2b, 3f)
21074 +#endif
21075 +.endif
21076 +
21077 LOCK_PREFIX
21078 cmpxchg8b (%esi)
21079 jne 1b
21080
21081 -10:
21082 movl %ebx, %eax
21083 movl %ecx, %edx
21084 +
21085 +.ifb \unchecked
21086 +#ifdef CONFIG_PAX_REFCOUNT
21087 +3:
21088 +#endif
21089 +.endif
21090 +
21091 RESTORE ebx
21092 + pax_force_retaddr
21093 ret
21094 CFI_ENDPROC
21095 -ENDPROC(atomic64_\func\()_return_cx8)
21096 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21097 .endm
21098
21099 incdec_return inc add adc
21100 incdec_return dec sub sbb
21101 +incdec_return inc add adc _unchecked
21102 +incdec_return dec sub sbb _unchecked
21103
21104 ENTRY(atomic64_dec_if_positive_cx8)
21105 CFI_STARTPROC
21106 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21107 movl %edx, %ecx
21108 subl $1, %ebx
21109 sbb $0, %ecx
21110 +
21111 +#ifdef CONFIG_PAX_REFCOUNT
21112 + into
21113 +1234:
21114 + _ASM_EXTABLE(1234b, 2f)
21115 +#endif
21116 +
21117 js 2f
21118 LOCK_PREFIX
21119 cmpxchg8b (%esi)
21120 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21121 movl %ebx, %eax
21122 movl %ecx, %edx
21123 RESTORE ebx
21124 + pax_force_retaddr
21125 ret
21126 CFI_ENDPROC
21127 ENDPROC(atomic64_dec_if_positive_cx8)
21128 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21129 movl %edx, %ecx
21130 addl %ebp, %ebx
21131 adcl %edi, %ecx
21132 +
21133 +#ifdef CONFIG_PAX_REFCOUNT
21134 + into
21135 +1234:
21136 + _ASM_EXTABLE(1234b, 3f)
21137 +#endif
21138 +
21139 LOCK_PREFIX
21140 cmpxchg8b (%esi)
21141 jne 1b
21142 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21143 CFI_ADJUST_CFA_OFFSET -8
21144 RESTORE ebx
21145 RESTORE ebp
21146 + pax_force_retaddr
21147 ret
21148 4:
21149 cmpl %edx, 4(%esp)
21150 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21151 xorl %ecx, %ecx
21152 addl $1, %ebx
21153 adcl %edx, %ecx
21154 +
21155 +#ifdef CONFIG_PAX_REFCOUNT
21156 + into
21157 +1234:
21158 + _ASM_EXTABLE(1234b, 3f)
21159 +#endif
21160 +
21161 LOCK_PREFIX
21162 cmpxchg8b (%esi)
21163 jne 1b
21164 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21165 movl $1, %eax
21166 3:
21167 RESTORE ebx
21168 + pax_force_retaddr
21169 ret
21170 CFI_ENDPROC
21171 ENDPROC(atomic64_inc_not_zero_cx8)
21172 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21173 index 2af5df3..62b1a5a 100644
21174 --- a/arch/x86/lib/checksum_32.S
21175 +++ b/arch/x86/lib/checksum_32.S
21176 @@ -29,7 +29,8 @@
21177 #include <asm/dwarf2.h>
21178 #include <asm/errno.h>
21179 #include <asm/asm.h>
21180 -
21181 +#include <asm/segment.h>
21182 +
21183 /*
21184 * computes a partial checksum, e.g. for TCP/UDP fragments
21185 */
21186 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21187
21188 #define ARGBASE 16
21189 #define FP 12
21190 -
21191 -ENTRY(csum_partial_copy_generic)
21192 +
21193 +ENTRY(csum_partial_copy_generic_to_user)
21194 CFI_STARTPROC
21195 +
21196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21197 + pushl_cfi %gs
21198 + popl_cfi %es
21199 + jmp csum_partial_copy_generic
21200 +#endif
21201 +
21202 +ENTRY(csum_partial_copy_generic_from_user)
21203 +
21204 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21205 + pushl_cfi %gs
21206 + popl_cfi %ds
21207 +#endif
21208 +
21209 +ENTRY(csum_partial_copy_generic)
21210 subl $4,%esp
21211 CFI_ADJUST_CFA_OFFSET 4
21212 pushl_cfi %edi
21213 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21214 jmp 4f
21215 SRC(1: movw (%esi), %bx )
21216 addl $2, %esi
21217 -DST( movw %bx, (%edi) )
21218 +DST( movw %bx, %es:(%edi) )
21219 addl $2, %edi
21220 addw %bx, %ax
21221 adcl $0, %eax
21222 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21223 SRC(1: movl (%esi), %ebx )
21224 SRC( movl 4(%esi), %edx )
21225 adcl %ebx, %eax
21226 -DST( movl %ebx, (%edi) )
21227 +DST( movl %ebx, %es:(%edi) )
21228 adcl %edx, %eax
21229 -DST( movl %edx, 4(%edi) )
21230 +DST( movl %edx, %es:4(%edi) )
21231
21232 SRC( movl 8(%esi), %ebx )
21233 SRC( movl 12(%esi), %edx )
21234 adcl %ebx, %eax
21235 -DST( movl %ebx, 8(%edi) )
21236 +DST( movl %ebx, %es:8(%edi) )
21237 adcl %edx, %eax
21238 -DST( movl %edx, 12(%edi) )
21239 +DST( movl %edx, %es:12(%edi) )
21240
21241 SRC( movl 16(%esi), %ebx )
21242 SRC( movl 20(%esi), %edx )
21243 adcl %ebx, %eax
21244 -DST( movl %ebx, 16(%edi) )
21245 +DST( movl %ebx, %es:16(%edi) )
21246 adcl %edx, %eax
21247 -DST( movl %edx, 20(%edi) )
21248 +DST( movl %edx, %es:20(%edi) )
21249
21250 SRC( movl 24(%esi), %ebx )
21251 SRC( movl 28(%esi), %edx )
21252 adcl %ebx, %eax
21253 -DST( movl %ebx, 24(%edi) )
21254 +DST( movl %ebx, %es:24(%edi) )
21255 adcl %edx, %eax
21256 -DST( movl %edx, 28(%edi) )
21257 +DST( movl %edx, %es:28(%edi) )
21258
21259 lea 32(%esi), %esi
21260 lea 32(%edi), %edi
21261 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21262 shrl $2, %edx # This clears CF
21263 SRC(3: movl (%esi), %ebx )
21264 adcl %ebx, %eax
21265 -DST( movl %ebx, (%edi) )
21266 +DST( movl %ebx, %es:(%edi) )
21267 lea 4(%esi), %esi
21268 lea 4(%edi), %edi
21269 dec %edx
21270 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21271 jb 5f
21272 SRC( movw (%esi), %cx )
21273 leal 2(%esi), %esi
21274 -DST( movw %cx, (%edi) )
21275 +DST( movw %cx, %es:(%edi) )
21276 leal 2(%edi), %edi
21277 je 6f
21278 shll $16,%ecx
21279 SRC(5: movb (%esi), %cl )
21280 -DST( movb %cl, (%edi) )
21281 +DST( movb %cl, %es:(%edi) )
21282 6: addl %ecx, %eax
21283 adcl $0, %eax
21284 7:
21285 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21286
21287 6001:
21288 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21289 - movl $-EFAULT, (%ebx)
21290 + movl $-EFAULT, %ss:(%ebx)
21291
21292 # zero the complete destination - computing the rest
21293 # is too much work
21294 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21295
21296 6002:
21297 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21298 - movl $-EFAULT,(%ebx)
21299 + movl $-EFAULT,%ss:(%ebx)
21300 jmp 5000b
21301
21302 .previous
21303
21304 + pushl_cfi %ss
21305 + popl_cfi %ds
21306 + pushl_cfi %ss
21307 + popl_cfi %es
21308 popl_cfi %ebx
21309 CFI_RESTORE ebx
21310 popl_cfi %esi
21311 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21312 popl_cfi %ecx # equivalent to addl $4,%esp
21313 ret
21314 CFI_ENDPROC
21315 -ENDPROC(csum_partial_copy_generic)
21316 +ENDPROC(csum_partial_copy_generic_to_user)
21317
21318 #else
21319
21320 /* Version for PentiumII/PPro */
21321
21322 #define ROUND1(x) \
21323 + nop; nop; nop; \
21324 SRC(movl x(%esi), %ebx ) ; \
21325 addl %ebx, %eax ; \
21326 - DST(movl %ebx, x(%edi) ) ;
21327 + DST(movl %ebx, %es:x(%edi)) ;
21328
21329 #define ROUND(x) \
21330 + nop; nop; nop; \
21331 SRC(movl x(%esi), %ebx ) ; \
21332 adcl %ebx, %eax ; \
21333 - DST(movl %ebx, x(%edi) ) ;
21334 + DST(movl %ebx, %es:x(%edi)) ;
21335
21336 #define ARGBASE 12
21337 -
21338 -ENTRY(csum_partial_copy_generic)
21339 +
21340 +ENTRY(csum_partial_copy_generic_to_user)
21341 CFI_STARTPROC
21342 +
21343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21344 + pushl_cfi %gs
21345 + popl_cfi %es
21346 + jmp csum_partial_copy_generic
21347 +#endif
21348 +
21349 +ENTRY(csum_partial_copy_generic_from_user)
21350 +
21351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21352 + pushl_cfi %gs
21353 + popl_cfi %ds
21354 +#endif
21355 +
21356 +ENTRY(csum_partial_copy_generic)
21357 pushl_cfi %ebx
21358 CFI_REL_OFFSET ebx, 0
21359 pushl_cfi %edi
21360 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21361 subl %ebx, %edi
21362 lea -1(%esi),%edx
21363 andl $-32,%edx
21364 - lea 3f(%ebx,%ebx), %ebx
21365 + lea 3f(%ebx,%ebx,2), %ebx
21366 testl %esi, %esi
21367 jmp *%ebx
21368 1: addl $64,%esi
21369 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21370 jb 5f
21371 SRC( movw (%esi), %dx )
21372 leal 2(%esi), %esi
21373 -DST( movw %dx, (%edi) )
21374 +DST( movw %dx, %es:(%edi) )
21375 leal 2(%edi), %edi
21376 je 6f
21377 shll $16,%edx
21378 5:
21379 SRC( movb (%esi), %dl )
21380 -DST( movb %dl, (%edi) )
21381 +DST( movb %dl, %es:(%edi) )
21382 6: addl %edx, %eax
21383 adcl $0, %eax
21384 7:
21385 .section .fixup, "ax"
21386 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21387 - movl $-EFAULT, (%ebx)
21388 + movl $-EFAULT, %ss:(%ebx)
21389 # zero the complete destination (computing the rest is too much work)
21390 movl ARGBASE+8(%esp),%edi # dst
21391 movl ARGBASE+12(%esp),%ecx # len
21392 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21393 rep; stosb
21394 jmp 7b
21395 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21396 - movl $-EFAULT, (%ebx)
21397 + movl $-EFAULT, %ss:(%ebx)
21398 jmp 7b
21399 .previous
21400
21401 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21402 + pushl_cfi %ss
21403 + popl_cfi %ds
21404 + pushl_cfi %ss
21405 + popl_cfi %es
21406 +#endif
21407 +
21408 popl_cfi %esi
21409 CFI_RESTORE esi
21410 popl_cfi %edi
21411 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21412 CFI_RESTORE ebx
21413 ret
21414 CFI_ENDPROC
21415 -ENDPROC(csum_partial_copy_generic)
21416 +ENDPROC(csum_partial_copy_generic_to_user)
21417
21418 #undef ROUND
21419 #undef ROUND1
21420 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21421 index f2145cf..cea889d 100644
21422 --- a/arch/x86/lib/clear_page_64.S
21423 +++ b/arch/x86/lib/clear_page_64.S
21424 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21425 movl $4096/8,%ecx
21426 xorl %eax,%eax
21427 rep stosq
21428 + pax_force_retaddr
21429 ret
21430 CFI_ENDPROC
21431 ENDPROC(clear_page_c)
21432 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21433 movl $4096,%ecx
21434 xorl %eax,%eax
21435 rep stosb
21436 + pax_force_retaddr
21437 ret
21438 CFI_ENDPROC
21439 ENDPROC(clear_page_c_e)
21440 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21441 leaq 64(%rdi),%rdi
21442 jnz .Lloop
21443 nop
21444 + pax_force_retaddr
21445 ret
21446 CFI_ENDPROC
21447 .Lclear_page_end:
21448 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21449
21450 #include <asm/cpufeature.h>
21451
21452 - .section .altinstr_replacement,"ax"
21453 + .section .altinstr_replacement,"a"
21454 1: .byte 0xeb /* jmp <disp8> */
21455 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21456 2: .byte 0xeb /* jmp <disp8> */
21457 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21458 index 1e572c5..2a162cd 100644
21459 --- a/arch/x86/lib/cmpxchg16b_emu.S
21460 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21461 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21462
21463 popf
21464 mov $1, %al
21465 + pax_force_retaddr
21466 ret
21467
21468 not_same:
21469 popf
21470 xor %al,%al
21471 + pax_force_retaddr
21472 ret
21473
21474 CFI_ENDPROC
21475 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21476 index 6b34d04..dccb07f 100644
21477 --- a/arch/x86/lib/copy_page_64.S
21478 +++ b/arch/x86/lib/copy_page_64.S
21479 @@ -9,6 +9,7 @@ copy_page_c:
21480 CFI_STARTPROC
21481 movl $4096/8,%ecx
21482 rep movsq
21483 + pax_force_retaddr
21484 ret
21485 CFI_ENDPROC
21486 ENDPROC(copy_page_c)
21487 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21488
21489 ENTRY(copy_page)
21490 CFI_STARTPROC
21491 - subq $2*8,%rsp
21492 - CFI_ADJUST_CFA_OFFSET 2*8
21493 + subq $3*8,%rsp
21494 + CFI_ADJUST_CFA_OFFSET 3*8
21495 movq %rbx,(%rsp)
21496 CFI_REL_OFFSET rbx, 0
21497 movq %r12,1*8(%rsp)
21498 CFI_REL_OFFSET r12, 1*8
21499 + movq %r13,2*8(%rsp)
21500 + CFI_REL_OFFSET r13, 2*8
21501
21502 movl $(4096/64)-5,%ecx
21503 .p2align 4
21504 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21505 movq 16 (%rsi), %rdx
21506 movq 24 (%rsi), %r8
21507 movq 32 (%rsi), %r9
21508 - movq 40 (%rsi), %r10
21509 + movq 40 (%rsi), %r13
21510 movq 48 (%rsi), %r11
21511 movq 56 (%rsi), %r12
21512
21513 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21514 movq %rdx, 16 (%rdi)
21515 movq %r8, 24 (%rdi)
21516 movq %r9, 32 (%rdi)
21517 - movq %r10, 40 (%rdi)
21518 + movq %r13, 40 (%rdi)
21519 movq %r11, 48 (%rdi)
21520 movq %r12, 56 (%rdi)
21521
21522 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21523 movq 16 (%rsi), %rdx
21524 movq 24 (%rsi), %r8
21525 movq 32 (%rsi), %r9
21526 - movq 40 (%rsi), %r10
21527 + movq 40 (%rsi), %r13
21528 movq 48 (%rsi), %r11
21529 movq 56 (%rsi), %r12
21530
21531 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21532 movq %rdx, 16 (%rdi)
21533 movq %r8, 24 (%rdi)
21534 movq %r9, 32 (%rdi)
21535 - movq %r10, 40 (%rdi)
21536 + movq %r13, 40 (%rdi)
21537 movq %r11, 48 (%rdi)
21538 movq %r12, 56 (%rdi)
21539
21540 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21541 CFI_RESTORE rbx
21542 movq 1*8(%rsp),%r12
21543 CFI_RESTORE r12
21544 - addq $2*8,%rsp
21545 - CFI_ADJUST_CFA_OFFSET -2*8
21546 + movq 2*8(%rsp),%r13
21547 + CFI_RESTORE r13
21548 + addq $3*8,%rsp
21549 + CFI_ADJUST_CFA_OFFSET -3*8
21550 + pax_force_retaddr
21551 ret
21552 .Lcopy_page_end:
21553 CFI_ENDPROC
21554 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21555
21556 #include <asm/cpufeature.h>
21557
21558 - .section .altinstr_replacement,"ax"
21559 + .section .altinstr_replacement,"a"
21560 1: .byte 0xeb /* jmp <disp8> */
21561 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21562 2:
21563 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21564 index 5b2995f..78e7644 100644
21565 --- a/arch/x86/lib/copy_user_64.S
21566 +++ b/arch/x86/lib/copy_user_64.S
21567 @@ -17,6 +17,7 @@
21568 #include <asm/cpufeature.h>
21569 #include <asm/alternative-asm.h>
21570 #include <asm/asm.h>
21571 +#include <asm/pgtable.h>
21572
21573 /*
21574 * By placing feature2 after feature1 in altinstructions section, we logically
21575 @@ -30,7 +31,7 @@
21576 .byte 0xe9 /* 32bit jump */
21577 .long \orig-1f /* by default jump to orig */
21578 1:
21579 - .section .altinstr_replacement,"ax"
21580 + .section .altinstr_replacement,"a"
21581 2: .byte 0xe9 /* near jump with 32bit immediate */
21582 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21583 3: .byte 0xe9 /* near jump with 32bit immediate */
21584 @@ -69,47 +70,20 @@
21585 #endif
21586 .endm
21587
21588 -/* Standard copy_to_user with segment limit checking */
21589 -ENTRY(_copy_to_user)
21590 - CFI_STARTPROC
21591 - GET_THREAD_INFO(%rax)
21592 - movq %rdi,%rcx
21593 - addq %rdx,%rcx
21594 - jc bad_to_user
21595 - cmpq TI_addr_limit(%rax),%rcx
21596 - ja bad_to_user
21597 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21598 - copy_user_generic_unrolled,copy_user_generic_string, \
21599 - copy_user_enhanced_fast_string
21600 - CFI_ENDPROC
21601 -ENDPROC(_copy_to_user)
21602 -
21603 -/* Standard copy_from_user with segment limit checking */
21604 -ENTRY(_copy_from_user)
21605 - CFI_STARTPROC
21606 - GET_THREAD_INFO(%rax)
21607 - movq %rsi,%rcx
21608 - addq %rdx,%rcx
21609 - jc bad_from_user
21610 - cmpq TI_addr_limit(%rax),%rcx
21611 - ja bad_from_user
21612 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21613 - copy_user_generic_unrolled,copy_user_generic_string, \
21614 - copy_user_enhanced_fast_string
21615 - CFI_ENDPROC
21616 -ENDPROC(_copy_from_user)
21617 -
21618 .section .fixup,"ax"
21619 /* must zero dest */
21620 ENTRY(bad_from_user)
21621 bad_from_user:
21622 CFI_STARTPROC
21623 + testl %edx,%edx
21624 + js bad_to_user
21625 movl %edx,%ecx
21626 xorl %eax,%eax
21627 rep
21628 stosb
21629 bad_to_user:
21630 movl %edx,%eax
21631 + pax_force_retaddr
21632 ret
21633 CFI_ENDPROC
21634 ENDPROC(bad_from_user)
21635 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21636 jz 17f
21637 1: movq (%rsi),%r8
21638 2: movq 1*8(%rsi),%r9
21639 -3: movq 2*8(%rsi),%r10
21640 +3: movq 2*8(%rsi),%rax
21641 4: movq 3*8(%rsi),%r11
21642 5: movq %r8,(%rdi)
21643 6: movq %r9,1*8(%rdi)
21644 -7: movq %r10,2*8(%rdi)
21645 +7: movq %rax,2*8(%rdi)
21646 8: movq %r11,3*8(%rdi)
21647 9: movq 4*8(%rsi),%r8
21648 10: movq 5*8(%rsi),%r9
21649 -11: movq 6*8(%rsi),%r10
21650 +11: movq 6*8(%rsi),%rax
21651 12: movq 7*8(%rsi),%r11
21652 13: movq %r8,4*8(%rdi)
21653 14: movq %r9,5*8(%rdi)
21654 -15: movq %r10,6*8(%rdi)
21655 +15: movq %rax,6*8(%rdi)
21656 16: movq %r11,7*8(%rdi)
21657 leaq 64(%rsi),%rsi
21658 leaq 64(%rdi),%rdi
21659 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21660 decl %ecx
21661 jnz 21b
21662 23: xor %eax,%eax
21663 + pax_force_retaddr
21664 ret
21665
21666 .section .fixup,"ax"
21667 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21668 3: rep
21669 movsb
21670 4: xorl %eax,%eax
21671 + pax_force_retaddr
21672 ret
21673
21674 .section .fixup,"ax"
21675 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21676 1: rep
21677 movsb
21678 2: xorl %eax,%eax
21679 + pax_force_retaddr
21680 ret
21681
21682 .section .fixup,"ax"
21683 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21684 index cacddc7..09d49e4 100644
21685 --- a/arch/x86/lib/copy_user_nocache_64.S
21686 +++ b/arch/x86/lib/copy_user_nocache_64.S
21687 @@ -8,6 +8,7 @@
21688
21689 #include <linux/linkage.h>
21690 #include <asm/dwarf2.h>
21691 +#include <asm/alternative-asm.h>
21692
21693 #define FIX_ALIGNMENT 1
21694
21695 @@ -15,6 +16,7 @@
21696 #include <asm/asm-offsets.h>
21697 #include <asm/thread_info.h>
21698 #include <asm/asm.h>
21699 +#include <asm/pgtable.h>
21700
21701 .macro ALIGN_DESTINATION
21702 #ifdef FIX_ALIGNMENT
21703 @@ -48,6 +50,15 @@
21704 */
21705 ENTRY(__copy_user_nocache)
21706 CFI_STARTPROC
21707 +
21708 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21709 + mov $PAX_USER_SHADOW_BASE,%rcx
21710 + cmp %rcx,%rsi
21711 + jae 1f
21712 + add %rcx,%rsi
21713 +1:
21714 +#endif
21715 +
21716 cmpl $8,%edx
21717 jb 20f /* less then 8 bytes, go to byte copy loop */
21718 ALIGN_DESTINATION
21719 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21720 jz 17f
21721 1: movq (%rsi),%r8
21722 2: movq 1*8(%rsi),%r9
21723 -3: movq 2*8(%rsi),%r10
21724 +3: movq 2*8(%rsi),%rax
21725 4: movq 3*8(%rsi),%r11
21726 5: movnti %r8,(%rdi)
21727 6: movnti %r9,1*8(%rdi)
21728 -7: movnti %r10,2*8(%rdi)
21729 +7: movnti %rax,2*8(%rdi)
21730 8: movnti %r11,3*8(%rdi)
21731 9: movq 4*8(%rsi),%r8
21732 10: movq 5*8(%rsi),%r9
21733 -11: movq 6*8(%rsi),%r10
21734 +11: movq 6*8(%rsi),%rax
21735 12: movq 7*8(%rsi),%r11
21736 13: movnti %r8,4*8(%rdi)
21737 14: movnti %r9,5*8(%rdi)
21738 -15: movnti %r10,6*8(%rdi)
21739 +15: movnti %rax,6*8(%rdi)
21740 16: movnti %r11,7*8(%rdi)
21741 leaq 64(%rsi),%rsi
21742 leaq 64(%rdi),%rdi
21743 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21744 jnz 21b
21745 23: xorl %eax,%eax
21746 sfence
21747 + pax_force_retaddr
21748 ret
21749
21750 .section .fixup,"ax"
21751 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21752 index 2419d5f..953ee51 100644
21753 --- a/arch/x86/lib/csum-copy_64.S
21754 +++ b/arch/x86/lib/csum-copy_64.S
21755 @@ -9,6 +9,7 @@
21756 #include <asm/dwarf2.h>
21757 #include <asm/errno.h>
21758 #include <asm/asm.h>
21759 +#include <asm/alternative-asm.h>
21760
21761 /*
21762 * Checksum copy with exception handling.
21763 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21764 CFI_RESTORE rbp
21765 addq $7*8, %rsp
21766 CFI_ADJUST_CFA_OFFSET -7*8
21767 + pax_force_retaddr 0, 1
21768 ret
21769 CFI_RESTORE_STATE
21770
21771 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21772 index 25b7ae8..3b52ccd 100644
21773 --- a/arch/x86/lib/csum-wrappers_64.c
21774 +++ b/arch/x86/lib/csum-wrappers_64.c
21775 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21776 len -= 2;
21777 }
21778 }
21779 - isum = csum_partial_copy_generic((__force const void *)src,
21780 +
21781 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21782 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21783 + src += PAX_USER_SHADOW_BASE;
21784 +#endif
21785 +
21786 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21787 dst, len, isum, errp, NULL);
21788 if (unlikely(*errp))
21789 goto out_err;
21790 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21791 }
21792
21793 *errp = 0;
21794 - return csum_partial_copy_generic(src, (void __force *)dst,
21795 +
21796 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21797 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21798 + dst += PAX_USER_SHADOW_BASE;
21799 +#endif
21800 +
21801 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21802 len, isum, NULL, errp);
21803 }
21804 EXPORT_SYMBOL(csum_partial_copy_to_user);
21805 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21806 index b33b1fb..219f389 100644
21807 --- a/arch/x86/lib/getuser.S
21808 +++ b/arch/x86/lib/getuser.S
21809 @@ -33,15 +33,38 @@
21810 #include <asm/asm-offsets.h>
21811 #include <asm/thread_info.h>
21812 #include <asm/asm.h>
21813 +#include <asm/segment.h>
21814 +#include <asm/pgtable.h>
21815 +#include <asm/alternative-asm.h>
21816 +
21817 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21818 +#define __copyuser_seg gs;
21819 +#else
21820 +#define __copyuser_seg
21821 +#endif
21822
21823 .text
21824 ENTRY(__get_user_1)
21825 CFI_STARTPROC
21826 +
21827 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21828 GET_THREAD_INFO(%_ASM_DX)
21829 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21830 jae bad_get_user
21831 -1: movzb (%_ASM_AX),%edx
21832 +
21833 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21834 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21835 + cmp %_ASM_DX,%_ASM_AX
21836 + jae 1234f
21837 + add %_ASM_DX,%_ASM_AX
21838 +1234:
21839 +#endif
21840 +
21841 +#endif
21842 +
21843 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21844 xor %eax,%eax
21845 + pax_force_retaddr
21846 ret
21847 CFI_ENDPROC
21848 ENDPROC(__get_user_1)
21849 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21850 ENTRY(__get_user_2)
21851 CFI_STARTPROC
21852 add $1,%_ASM_AX
21853 +
21854 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21855 jc bad_get_user
21856 GET_THREAD_INFO(%_ASM_DX)
21857 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21858 jae bad_get_user
21859 -2: movzwl -1(%_ASM_AX),%edx
21860 +
21861 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21862 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21863 + cmp %_ASM_DX,%_ASM_AX
21864 + jae 1234f
21865 + add %_ASM_DX,%_ASM_AX
21866 +1234:
21867 +#endif
21868 +
21869 +#endif
21870 +
21871 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21872 xor %eax,%eax
21873 + pax_force_retaddr
21874 ret
21875 CFI_ENDPROC
21876 ENDPROC(__get_user_2)
21877 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21878 ENTRY(__get_user_4)
21879 CFI_STARTPROC
21880 add $3,%_ASM_AX
21881 +
21882 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21883 jc bad_get_user
21884 GET_THREAD_INFO(%_ASM_DX)
21885 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21886 jae bad_get_user
21887 -3: mov -3(%_ASM_AX),%edx
21888 +
21889 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21890 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21891 + cmp %_ASM_DX,%_ASM_AX
21892 + jae 1234f
21893 + add %_ASM_DX,%_ASM_AX
21894 +1234:
21895 +#endif
21896 +
21897 +#endif
21898 +
21899 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21900 xor %eax,%eax
21901 + pax_force_retaddr
21902 ret
21903 CFI_ENDPROC
21904 ENDPROC(__get_user_4)
21905 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21906 GET_THREAD_INFO(%_ASM_DX)
21907 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21908 jae bad_get_user
21909 +
21910 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21911 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21912 + cmp %_ASM_DX,%_ASM_AX
21913 + jae 1234f
21914 + add %_ASM_DX,%_ASM_AX
21915 +1234:
21916 +#endif
21917 +
21918 4: movq -7(%_ASM_AX),%_ASM_DX
21919 xor %eax,%eax
21920 + pax_force_retaddr
21921 ret
21922 CFI_ENDPROC
21923 ENDPROC(__get_user_8)
21924 @@ -91,6 +152,7 @@ bad_get_user:
21925 CFI_STARTPROC
21926 xor %edx,%edx
21927 mov $(-EFAULT),%_ASM_AX
21928 + pax_force_retaddr
21929 ret
21930 CFI_ENDPROC
21931 END(bad_get_user)
21932 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21933 index b1e6c4b..21ae8fc 100644
21934 --- a/arch/x86/lib/insn.c
21935 +++ b/arch/x86/lib/insn.c
21936 @@ -21,6 +21,11 @@
21937 #include <linux/string.h>
21938 #include <asm/inat.h>
21939 #include <asm/insn.h>
21940 +#ifdef __KERNEL__
21941 +#include <asm/pgtable_types.h>
21942 +#else
21943 +#define ktla_ktva(addr) addr
21944 +#endif
21945
21946 /* Verify next sizeof(t) bytes can be on the same instruction */
21947 #define validate_next(t, insn, n) \
21948 @@ -49,8 +54,8 @@
21949 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21950 {
21951 memset(insn, 0, sizeof(*insn));
21952 - insn->kaddr = kaddr;
21953 - insn->next_byte = kaddr;
21954 + insn->kaddr = ktla_ktva(kaddr);
21955 + insn->next_byte = ktla_ktva(kaddr);
21956 insn->x86_64 = x86_64 ? 1 : 0;
21957 insn->opnd_bytes = 4;
21958 if (x86_64)
21959 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21960 index 05a95e7..326f2fa 100644
21961 --- a/arch/x86/lib/iomap_copy_64.S
21962 +++ b/arch/x86/lib/iomap_copy_64.S
21963 @@ -17,6 +17,7 @@
21964
21965 #include <linux/linkage.h>
21966 #include <asm/dwarf2.h>
21967 +#include <asm/alternative-asm.h>
21968
21969 /*
21970 * override generic version in lib/iomap_copy.c
21971 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21972 CFI_STARTPROC
21973 movl %edx,%ecx
21974 rep movsd
21975 + pax_force_retaddr
21976 ret
21977 CFI_ENDPROC
21978 ENDPROC(__iowrite32_copy)
21979 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21980 index 1c273be..da9cc0e 100644
21981 --- a/arch/x86/lib/memcpy_64.S
21982 +++ b/arch/x86/lib/memcpy_64.S
21983 @@ -33,6 +33,7 @@
21984 rep movsq
21985 movl %edx, %ecx
21986 rep movsb
21987 + pax_force_retaddr
21988 ret
21989 .Lmemcpy_e:
21990 .previous
21991 @@ -49,6 +50,7 @@
21992 movq %rdi, %rax
21993 movq %rdx, %rcx
21994 rep movsb
21995 + pax_force_retaddr
21996 ret
21997 .Lmemcpy_e_e:
21998 .previous
21999 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22000 */
22001 movq 0*8(%rsi), %r8
22002 movq 1*8(%rsi), %r9
22003 - movq 2*8(%rsi), %r10
22004 + movq 2*8(%rsi), %rcx
22005 movq 3*8(%rsi), %r11
22006 leaq 4*8(%rsi), %rsi
22007
22008 movq %r8, 0*8(%rdi)
22009 movq %r9, 1*8(%rdi)
22010 - movq %r10, 2*8(%rdi)
22011 + movq %rcx, 2*8(%rdi)
22012 movq %r11, 3*8(%rdi)
22013 leaq 4*8(%rdi), %rdi
22014 jae .Lcopy_forward_loop
22015 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22016 subq $0x20, %rdx
22017 movq -1*8(%rsi), %r8
22018 movq -2*8(%rsi), %r9
22019 - movq -3*8(%rsi), %r10
22020 + movq -3*8(%rsi), %rcx
22021 movq -4*8(%rsi), %r11
22022 leaq -4*8(%rsi), %rsi
22023 movq %r8, -1*8(%rdi)
22024 movq %r9, -2*8(%rdi)
22025 - movq %r10, -3*8(%rdi)
22026 + movq %rcx, -3*8(%rdi)
22027 movq %r11, -4*8(%rdi)
22028 leaq -4*8(%rdi), %rdi
22029 jae .Lcopy_backward_loop
22030 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22031 */
22032 movq 0*8(%rsi), %r8
22033 movq 1*8(%rsi), %r9
22034 - movq -2*8(%rsi, %rdx), %r10
22035 + movq -2*8(%rsi, %rdx), %rcx
22036 movq -1*8(%rsi, %rdx), %r11
22037 movq %r8, 0*8(%rdi)
22038 movq %r9, 1*8(%rdi)
22039 - movq %r10, -2*8(%rdi, %rdx)
22040 + movq %rcx, -2*8(%rdi, %rdx)
22041 movq %r11, -1*8(%rdi, %rdx)
22042 + pax_force_retaddr
22043 retq
22044 .p2align 4
22045 .Lless_16bytes:
22046 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22047 movq -1*8(%rsi, %rdx), %r9
22048 movq %r8, 0*8(%rdi)
22049 movq %r9, -1*8(%rdi, %rdx)
22050 + pax_force_retaddr
22051 retq
22052 .p2align 4
22053 .Lless_8bytes:
22054 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22055 movl -4(%rsi, %rdx), %r8d
22056 movl %ecx, (%rdi)
22057 movl %r8d, -4(%rdi, %rdx)
22058 + pax_force_retaddr
22059 retq
22060 .p2align 4
22061 .Lless_3bytes:
22062 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22063 movb %cl, (%rdi)
22064
22065 .Lend:
22066 + pax_force_retaddr
22067 retq
22068 CFI_ENDPROC
22069 ENDPROC(memcpy)
22070 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22071 index ee16461..c39c199 100644
22072 --- a/arch/x86/lib/memmove_64.S
22073 +++ b/arch/x86/lib/memmove_64.S
22074 @@ -61,13 +61,13 @@ ENTRY(memmove)
22075 5:
22076 sub $0x20, %rdx
22077 movq 0*8(%rsi), %r11
22078 - movq 1*8(%rsi), %r10
22079 + movq 1*8(%rsi), %rcx
22080 movq 2*8(%rsi), %r9
22081 movq 3*8(%rsi), %r8
22082 leaq 4*8(%rsi), %rsi
22083
22084 movq %r11, 0*8(%rdi)
22085 - movq %r10, 1*8(%rdi)
22086 + movq %rcx, 1*8(%rdi)
22087 movq %r9, 2*8(%rdi)
22088 movq %r8, 3*8(%rdi)
22089 leaq 4*8(%rdi), %rdi
22090 @@ -81,10 +81,10 @@ ENTRY(memmove)
22091 4:
22092 movq %rdx, %rcx
22093 movq -8(%rsi, %rdx), %r11
22094 - lea -8(%rdi, %rdx), %r10
22095 + lea -8(%rdi, %rdx), %r9
22096 shrq $3, %rcx
22097 rep movsq
22098 - movq %r11, (%r10)
22099 + movq %r11, (%r9)
22100 jmp 13f
22101 .Lmemmove_end_forward:
22102
22103 @@ -95,14 +95,14 @@ ENTRY(memmove)
22104 7:
22105 movq %rdx, %rcx
22106 movq (%rsi), %r11
22107 - movq %rdi, %r10
22108 + movq %rdi, %r9
22109 leaq -8(%rsi, %rdx), %rsi
22110 leaq -8(%rdi, %rdx), %rdi
22111 shrq $3, %rcx
22112 std
22113 rep movsq
22114 cld
22115 - movq %r11, (%r10)
22116 + movq %r11, (%r9)
22117 jmp 13f
22118
22119 /*
22120 @@ -127,13 +127,13 @@ ENTRY(memmove)
22121 8:
22122 subq $0x20, %rdx
22123 movq -1*8(%rsi), %r11
22124 - movq -2*8(%rsi), %r10
22125 + movq -2*8(%rsi), %rcx
22126 movq -3*8(%rsi), %r9
22127 movq -4*8(%rsi), %r8
22128 leaq -4*8(%rsi), %rsi
22129
22130 movq %r11, -1*8(%rdi)
22131 - movq %r10, -2*8(%rdi)
22132 + movq %rcx, -2*8(%rdi)
22133 movq %r9, -3*8(%rdi)
22134 movq %r8, -4*8(%rdi)
22135 leaq -4*8(%rdi), %rdi
22136 @@ -151,11 +151,11 @@ ENTRY(memmove)
22137 * Move data from 16 bytes to 31 bytes.
22138 */
22139 movq 0*8(%rsi), %r11
22140 - movq 1*8(%rsi), %r10
22141 + movq 1*8(%rsi), %rcx
22142 movq -2*8(%rsi, %rdx), %r9
22143 movq -1*8(%rsi, %rdx), %r8
22144 movq %r11, 0*8(%rdi)
22145 - movq %r10, 1*8(%rdi)
22146 + movq %rcx, 1*8(%rdi)
22147 movq %r9, -2*8(%rdi, %rdx)
22148 movq %r8, -1*8(%rdi, %rdx)
22149 jmp 13f
22150 @@ -167,9 +167,9 @@ ENTRY(memmove)
22151 * Move data from 8 bytes to 15 bytes.
22152 */
22153 movq 0*8(%rsi), %r11
22154 - movq -1*8(%rsi, %rdx), %r10
22155 + movq -1*8(%rsi, %rdx), %r9
22156 movq %r11, 0*8(%rdi)
22157 - movq %r10, -1*8(%rdi, %rdx)
22158 + movq %r9, -1*8(%rdi, %rdx)
22159 jmp 13f
22160 10:
22161 cmpq $4, %rdx
22162 @@ -178,9 +178,9 @@ ENTRY(memmove)
22163 * Move data from 4 bytes to 7 bytes.
22164 */
22165 movl (%rsi), %r11d
22166 - movl -4(%rsi, %rdx), %r10d
22167 + movl -4(%rsi, %rdx), %r9d
22168 movl %r11d, (%rdi)
22169 - movl %r10d, -4(%rdi, %rdx)
22170 + movl %r9d, -4(%rdi, %rdx)
22171 jmp 13f
22172 11:
22173 cmp $2, %rdx
22174 @@ -189,9 +189,9 @@ ENTRY(memmove)
22175 * Move data from 2 bytes to 3 bytes.
22176 */
22177 movw (%rsi), %r11w
22178 - movw -2(%rsi, %rdx), %r10w
22179 + movw -2(%rsi, %rdx), %r9w
22180 movw %r11w, (%rdi)
22181 - movw %r10w, -2(%rdi, %rdx)
22182 + movw %r9w, -2(%rdi, %rdx)
22183 jmp 13f
22184 12:
22185 cmp $1, %rdx
22186 @@ -202,6 +202,7 @@ ENTRY(memmove)
22187 movb (%rsi), %r11b
22188 movb %r11b, (%rdi)
22189 13:
22190 + pax_force_retaddr
22191 retq
22192 CFI_ENDPROC
22193
22194 @@ -210,6 +211,7 @@ ENTRY(memmove)
22195 /* Forward moving data. */
22196 movq %rdx, %rcx
22197 rep movsb
22198 + pax_force_retaddr
22199 retq
22200 .Lmemmove_end_forward_efs:
22201 .previous
22202 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22203 index 2dcb380..963660a 100644
22204 --- a/arch/x86/lib/memset_64.S
22205 +++ b/arch/x86/lib/memset_64.S
22206 @@ -30,6 +30,7 @@
22207 movl %edx,%ecx
22208 rep stosb
22209 movq %r9,%rax
22210 + pax_force_retaddr
22211 ret
22212 .Lmemset_e:
22213 .previous
22214 @@ -52,6 +53,7 @@
22215 movq %rdx,%rcx
22216 rep stosb
22217 movq %r9,%rax
22218 + pax_force_retaddr
22219 ret
22220 .Lmemset_e_e:
22221 .previous
22222 @@ -59,7 +61,7 @@
22223 ENTRY(memset)
22224 ENTRY(__memset)
22225 CFI_STARTPROC
22226 - movq %rdi,%r10
22227 + movq %rdi,%r11
22228
22229 /* expand byte value */
22230 movzbl %sil,%ecx
22231 @@ -117,7 +119,8 @@ ENTRY(__memset)
22232 jnz .Lloop_1
22233
22234 .Lende:
22235 - movq %r10,%rax
22236 + movq %r11,%rax
22237 + pax_force_retaddr
22238 ret
22239
22240 CFI_RESTORE_STATE
22241 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22242 index c9f2d9b..e7fd2c0 100644
22243 --- a/arch/x86/lib/mmx_32.c
22244 +++ b/arch/x86/lib/mmx_32.c
22245 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22246 {
22247 void *p;
22248 int i;
22249 + unsigned long cr0;
22250
22251 if (unlikely(in_interrupt()))
22252 return __memcpy(to, from, len);
22253 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22254 kernel_fpu_begin();
22255
22256 __asm__ __volatile__ (
22257 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22258 - " prefetch 64(%0)\n"
22259 - " prefetch 128(%0)\n"
22260 - " prefetch 192(%0)\n"
22261 - " prefetch 256(%0)\n"
22262 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22263 + " prefetch 64(%1)\n"
22264 + " prefetch 128(%1)\n"
22265 + " prefetch 192(%1)\n"
22266 + " prefetch 256(%1)\n"
22267 "2: \n"
22268 ".section .fixup, \"ax\"\n"
22269 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22270 + "3: \n"
22271 +
22272 +#ifdef CONFIG_PAX_KERNEXEC
22273 + " movl %%cr0, %0\n"
22274 + " movl %0, %%eax\n"
22275 + " andl $0xFFFEFFFF, %%eax\n"
22276 + " movl %%eax, %%cr0\n"
22277 +#endif
22278 +
22279 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22280 +
22281 +#ifdef CONFIG_PAX_KERNEXEC
22282 + " movl %0, %%cr0\n"
22283 +#endif
22284 +
22285 " jmp 2b\n"
22286 ".previous\n"
22287 _ASM_EXTABLE(1b, 3b)
22288 - : : "r" (from));
22289 + : "=&r" (cr0) : "r" (from) : "ax");
22290
22291 for ( ; i > 5; i--) {
22292 __asm__ __volatile__ (
22293 - "1: prefetch 320(%0)\n"
22294 - "2: movq (%0), %%mm0\n"
22295 - " movq 8(%0), %%mm1\n"
22296 - " movq 16(%0), %%mm2\n"
22297 - " movq 24(%0), %%mm3\n"
22298 - " movq %%mm0, (%1)\n"
22299 - " movq %%mm1, 8(%1)\n"
22300 - " movq %%mm2, 16(%1)\n"
22301 - " movq %%mm3, 24(%1)\n"
22302 - " movq 32(%0), %%mm0\n"
22303 - " movq 40(%0), %%mm1\n"
22304 - " movq 48(%0), %%mm2\n"
22305 - " movq 56(%0), %%mm3\n"
22306 - " movq %%mm0, 32(%1)\n"
22307 - " movq %%mm1, 40(%1)\n"
22308 - " movq %%mm2, 48(%1)\n"
22309 - " movq %%mm3, 56(%1)\n"
22310 + "1: prefetch 320(%1)\n"
22311 + "2: movq (%1), %%mm0\n"
22312 + " movq 8(%1), %%mm1\n"
22313 + " movq 16(%1), %%mm2\n"
22314 + " movq 24(%1), %%mm3\n"
22315 + " movq %%mm0, (%2)\n"
22316 + " movq %%mm1, 8(%2)\n"
22317 + " movq %%mm2, 16(%2)\n"
22318 + " movq %%mm3, 24(%2)\n"
22319 + " movq 32(%1), %%mm0\n"
22320 + " movq 40(%1), %%mm1\n"
22321 + " movq 48(%1), %%mm2\n"
22322 + " movq 56(%1), %%mm3\n"
22323 + " movq %%mm0, 32(%2)\n"
22324 + " movq %%mm1, 40(%2)\n"
22325 + " movq %%mm2, 48(%2)\n"
22326 + " movq %%mm3, 56(%2)\n"
22327 ".section .fixup, \"ax\"\n"
22328 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22329 + "3:\n"
22330 +
22331 +#ifdef CONFIG_PAX_KERNEXEC
22332 + " movl %%cr0, %0\n"
22333 + " movl %0, %%eax\n"
22334 + " andl $0xFFFEFFFF, %%eax\n"
22335 + " movl %%eax, %%cr0\n"
22336 +#endif
22337 +
22338 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22339 +
22340 +#ifdef CONFIG_PAX_KERNEXEC
22341 + " movl %0, %%cr0\n"
22342 +#endif
22343 +
22344 " jmp 2b\n"
22345 ".previous\n"
22346 _ASM_EXTABLE(1b, 3b)
22347 - : : "r" (from), "r" (to) : "memory");
22348 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22349
22350 from += 64;
22351 to += 64;
22352 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22353 static void fast_copy_page(void *to, void *from)
22354 {
22355 int i;
22356 + unsigned long cr0;
22357
22358 kernel_fpu_begin();
22359
22360 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22361 * but that is for later. -AV
22362 */
22363 __asm__ __volatile__(
22364 - "1: prefetch (%0)\n"
22365 - " prefetch 64(%0)\n"
22366 - " prefetch 128(%0)\n"
22367 - " prefetch 192(%0)\n"
22368 - " prefetch 256(%0)\n"
22369 + "1: prefetch (%1)\n"
22370 + " prefetch 64(%1)\n"
22371 + " prefetch 128(%1)\n"
22372 + " prefetch 192(%1)\n"
22373 + " prefetch 256(%1)\n"
22374 "2: \n"
22375 ".section .fixup, \"ax\"\n"
22376 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22377 + "3: \n"
22378 +
22379 +#ifdef CONFIG_PAX_KERNEXEC
22380 + " movl %%cr0, %0\n"
22381 + " movl %0, %%eax\n"
22382 + " andl $0xFFFEFFFF, %%eax\n"
22383 + " movl %%eax, %%cr0\n"
22384 +#endif
22385 +
22386 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22387 +
22388 +#ifdef CONFIG_PAX_KERNEXEC
22389 + " movl %0, %%cr0\n"
22390 +#endif
22391 +
22392 " jmp 2b\n"
22393 ".previous\n"
22394 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22395 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22396
22397 for (i = 0; i < (4096-320)/64; i++) {
22398 __asm__ __volatile__ (
22399 - "1: prefetch 320(%0)\n"
22400 - "2: movq (%0), %%mm0\n"
22401 - " movntq %%mm0, (%1)\n"
22402 - " movq 8(%0), %%mm1\n"
22403 - " movntq %%mm1, 8(%1)\n"
22404 - " movq 16(%0), %%mm2\n"
22405 - " movntq %%mm2, 16(%1)\n"
22406 - " movq 24(%0), %%mm3\n"
22407 - " movntq %%mm3, 24(%1)\n"
22408 - " movq 32(%0), %%mm4\n"
22409 - " movntq %%mm4, 32(%1)\n"
22410 - " movq 40(%0), %%mm5\n"
22411 - " movntq %%mm5, 40(%1)\n"
22412 - " movq 48(%0), %%mm6\n"
22413 - " movntq %%mm6, 48(%1)\n"
22414 - " movq 56(%0), %%mm7\n"
22415 - " movntq %%mm7, 56(%1)\n"
22416 + "1: prefetch 320(%1)\n"
22417 + "2: movq (%1), %%mm0\n"
22418 + " movntq %%mm0, (%2)\n"
22419 + " movq 8(%1), %%mm1\n"
22420 + " movntq %%mm1, 8(%2)\n"
22421 + " movq 16(%1), %%mm2\n"
22422 + " movntq %%mm2, 16(%2)\n"
22423 + " movq 24(%1), %%mm3\n"
22424 + " movntq %%mm3, 24(%2)\n"
22425 + " movq 32(%1), %%mm4\n"
22426 + " movntq %%mm4, 32(%2)\n"
22427 + " movq 40(%1), %%mm5\n"
22428 + " movntq %%mm5, 40(%2)\n"
22429 + " movq 48(%1), %%mm6\n"
22430 + " movntq %%mm6, 48(%2)\n"
22431 + " movq 56(%1), %%mm7\n"
22432 + " movntq %%mm7, 56(%2)\n"
22433 ".section .fixup, \"ax\"\n"
22434 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22435 + "3:\n"
22436 +
22437 +#ifdef CONFIG_PAX_KERNEXEC
22438 + " movl %%cr0, %0\n"
22439 + " movl %0, %%eax\n"
22440 + " andl $0xFFFEFFFF, %%eax\n"
22441 + " movl %%eax, %%cr0\n"
22442 +#endif
22443 +
22444 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22445 +
22446 +#ifdef CONFIG_PAX_KERNEXEC
22447 + " movl %0, %%cr0\n"
22448 +#endif
22449 +
22450 " jmp 2b\n"
22451 ".previous\n"
22452 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22453 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22454
22455 from += 64;
22456 to += 64;
22457 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22458 static void fast_copy_page(void *to, void *from)
22459 {
22460 int i;
22461 + unsigned long cr0;
22462
22463 kernel_fpu_begin();
22464
22465 __asm__ __volatile__ (
22466 - "1: prefetch (%0)\n"
22467 - " prefetch 64(%0)\n"
22468 - " prefetch 128(%0)\n"
22469 - " prefetch 192(%0)\n"
22470 - " prefetch 256(%0)\n"
22471 + "1: prefetch (%1)\n"
22472 + " prefetch 64(%1)\n"
22473 + " prefetch 128(%1)\n"
22474 + " prefetch 192(%1)\n"
22475 + " prefetch 256(%1)\n"
22476 "2: \n"
22477 ".section .fixup, \"ax\"\n"
22478 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22479 + "3: \n"
22480 +
22481 +#ifdef CONFIG_PAX_KERNEXEC
22482 + " movl %%cr0, %0\n"
22483 + " movl %0, %%eax\n"
22484 + " andl $0xFFFEFFFF, %%eax\n"
22485 + " movl %%eax, %%cr0\n"
22486 +#endif
22487 +
22488 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22489 +
22490 +#ifdef CONFIG_PAX_KERNEXEC
22491 + " movl %0, %%cr0\n"
22492 +#endif
22493 +
22494 " jmp 2b\n"
22495 ".previous\n"
22496 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22497 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22498
22499 for (i = 0; i < 4096/64; i++) {
22500 __asm__ __volatile__ (
22501 - "1: prefetch 320(%0)\n"
22502 - "2: movq (%0), %%mm0\n"
22503 - " movq 8(%0), %%mm1\n"
22504 - " movq 16(%0), %%mm2\n"
22505 - " movq 24(%0), %%mm3\n"
22506 - " movq %%mm0, (%1)\n"
22507 - " movq %%mm1, 8(%1)\n"
22508 - " movq %%mm2, 16(%1)\n"
22509 - " movq %%mm3, 24(%1)\n"
22510 - " movq 32(%0), %%mm0\n"
22511 - " movq 40(%0), %%mm1\n"
22512 - " movq 48(%0), %%mm2\n"
22513 - " movq 56(%0), %%mm3\n"
22514 - " movq %%mm0, 32(%1)\n"
22515 - " movq %%mm1, 40(%1)\n"
22516 - " movq %%mm2, 48(%1)\n"
22517 - " movq %%mm3, 56(%1)\n"
22518 + "1: prefetch 320(%1)\n"
22519 + "2: movq (%1), %%mm0\n"
22520 + " movq 8(%1), %%mm1\n"
22521 + " movq 16(%1), %%mm2\n"
22522 + " movq 24(%1), %%mm3\n"
22523 + " movq %%mm0, (%2)\n"
22524 + " movq %%mm1, 8(%2)\n"
22525 + " movq %%mm2, 16(%2)\n"
22526 + " movq %%mm3, 24(%2)\n"
22527 + " movq 32(%1), %%mm0\n"
22528 + " movq 40(%1), %%mm1\n"
22529 + " movq 48(%1), %%mm2\n"
22530 + " movq 56(%1), %%mm3\n"
22531 + " movq %%mm0, 32(%2)\n"
22532 + " movq %%mm1, 40(%2)\n"
22533 + " movq %%mm2, 48(%2)\n"
22534 + " movq %%mm3, 56(%2)\n"
22535 ".section .fixup, \"ax\"\n"
22536 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22537 + "3:\n"
22538 +
22539 +#ifdef CONFIG_PAX_KERNEXEC
22540 + " movl %%cr0, %0\n"
22541 + " movl %0, %%eax\n"
22542 + " andl $0xFFFEFFFF, %%eax\n"
22543 + " movl %%eax, %%cr0\n"
22544 +#endif
22545 +
22546 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22547 +
22548 +#ifdef CONFIG_PAX_KERNEXEC
22549 + " movl %0, %%cr0\n"
22550 +#endif
22551 +
22552 " jmp 2b\n"
22553 ".previous\n"
22554 _ASM_EXTABLE(1b, 3b)
22555 - : : "r" (from), "r" (to) : "memory");
22556 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22557
22558 from += 64;
22559 to += 64;
22560 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22561 index f6d13ee..aca5f0b 100644
22562 --- a/arch/x86/lib/msr-reg.S
22563 +++ b/arch/x86/lib/msr-reg.S
22564 @@ -3,6 +3,7 @@
22565 #include <asm/dwarf2.h>
22566 #include <asm/asm.h>
22567 #include <asm/msr.h>
22568 +#include <asm/alternative-asm.h>
22569
22570 #ifdef CONFIG_X86_64
22571 /*
22572 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22573 CFI_STARTPROC
22574 pushq_cfi %rbx
22575 pushq_cfi %rbp
22576 - movq %rdi, %r10 /* Save pointer */
22577 + movq %rdi, %r9 /* Save pointer */
22578 xorl %r11d, %r11d /* Return value */
22579 movl (%rdi), %eax
22580 movl 4(%rdi), %ecx
22581 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22582 movl 28(%rdi), %edi
22583 CFI_REMEMBER_STATE
22584 1: \op
22585 -2: movl %eax, (%r10)
22586 +2: movl %eax, (%r9)
22587 movl %r11d, %eax /* Return value */
22588 - movl %ecx, 4(%r10)
22589 - movl %edx, 8(%r10)
22590 - movl %ebx, 12(%r10)
22591 - movl %ebp, 20(%r10)
22592 - movl %esi, 24(%r10)
22593 - movl %edi, 28(%r10)
22594 + movl %ecx, 4(%r9)
22595 + movl %edx, 8(%r9)
22596 + movl %ebx, 12(%r9)
22597 + movl %ebp, 20(%r9)
22598 + movl %esi, 24(%r9)
22599 + movl %edi, 28(%r9)
22600 popq_cfi %rbp
22601 popq_cfi %rbx
22602 + pax_force_retaddr
22603 ret
22604 3:
22605 CFI_RESTORE_STATE
22606 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22607 index 7f951c8..ebd573a 100644
22608 --- a/arch/x86/lib/putuser.S
22609 +++ b/arch/x86/lib/putuser.S
22610 @@ -15,7 +15,9 @@
22611 #include <asm/thread_info.h>
22612 #include <asm/errno.h>
22613 #include <asm/asm.h>
22614 -
22615 +#include <asm/segment.h>
22616 +#include <asm/pgtable.h>
22617 +#include <asm/alternative-asm.h>
22618
22619 /*
22620 * __put_user_X
22621 @@ -29,52 +31,119 @@
22622 * as they get called from within inline assembly.
22623 */
22624
22625 -#define ENTER CFI_STARTPROC ; \
22626 - GET_THREAD_INFO(%_ASM_BX)
22627 -#define EXIT ret ; \
22628 +#define ENTER CFI_STARTPROC
22629 +#define EXIT pax_force_retaddr; ret ; \
22630 CFI_ENDPROC
22631
22632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22633 +#define _DEST %_ASM_CX,%_ASM_BX
22634 +#else
22635 +#define _DEST %_ASM_CX
22636 +#endif
22637 +
22638 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22639 +#define __copyuser_seg gs;
22640 +#else
22641 +#define __copyuser_seg
22642 +#endif
22643 +
22644 .text
22645 ENTRY(__put_user_1)
22646 ENTER
22647 +
22648 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22649 + GET_THREAD_INFO(%_ASM_BX)
22650 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22651 jae bad_put_user
22652 -1: movb %al,(%_ASM_CX)
22653 +
22654 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22655 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22656 + cmp %_ASM_BX,%_ASM_CX
22657 + jb 1234f
22658 + xor %ebx,%ebx
22659 +1234:
22660 +#endif
22661 +
22662 +#endif
22663 +
22664 +1: __copyuser_seg movb %al,(_DEST)
22665 xor %eax,%eax
22666 EXIT
22667 ENDPROC(__put_user_1)
22668
22669 ENTRY(__put_user_2)
22670 ENTER
22671 +
22672 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22673 + GET_THREAD_INFO(%_ASM_BX)
22674 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22675 sub $1,%_ASM_BX
22676 cmp %_ASM_BX,%_ASM_CX
22677 jae bad_put_user
22678 -2: movw %ax,(%_ASM_CX)
22679 +
22680 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22681 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22682 + cmp %_ASM_BX,%_ASM_CX
22683 + jb 1234f
22684 + xor %ebx,%ebx
22685 +1234:
22686 +#endif
22687 +
22688 +#endif
22689 +
22690 +2: __copyuser_seg movw %ax,(_DEST)
22691 xor %eax,%eax
22692 EXIT
22693 ENDPROC(__put_user_2)
22694
22695 ENTRY(__put_user_4)
22696 ENTER
22697 +
22698 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22699 + GET_THREAD_INFO(%_ASM_BX)
22700 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22701 sub $3,%_ASM_BX
22702 cmp %_ASM_BX,%_ASM_CX
22703 jae bad_put_user
22704 -3: movl %eax,(%_ASM_CX)
22705 +
22706 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22707 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22708 + cmp %_ASM_BX,%_ASM_CX
22709 + jb 1234f
22710 + xor %ebx,%ebx
22711 +1234:
22712 +#endif
22713 +
22714 +#endif
22715 +
22716 +3: __copyuser_seg movl %eax,(_DEST)
22717 xor %eax,%eax
22718 EXIT
22719 ENDPROC(__put_user_4)
22720
22721 ENTRY(__put_user_8)
22722 ENTER
22723 +
22724 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22725 + GET_THREAD_INFO(%_ASM_BX)
22726 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22727 sub $7,%_ASM_BX
22728 cmp %_ASM_BX,%_ASM_CX
22729 jae bad_put_user
22730 -4: mov %_ASM_AX,(%_ASM_CX)
22731 +
22732 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22733 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22734 + cmp %_ASM_BX,%_ASM_CX
22735 + jb 1234f
22736 + xor %ebx,%ebx
22737 +1234:
22738 +#endif
22739 +
22740 +#endif
22741 +
22742 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22743 #ifdef CONFIG_X86_32
22744 -5: movl %edx,4(%_ASM_CX)
22745 +5: __copyuser_seg movl %edx,4(_DEST)
22746 #endif
22747 xor %eax,%eax
22748 EXIT
22749 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22750 index 1cad221..de671ee 100644
22751 --- a/arch/x86/lib/rwlock.S
22752 +++ b/arch/x86/lib/rwlock.S
22753 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22754 FRAME
22755 0: LOCK_PREFIX
22756 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22757 +
22758 +#ifdef CONFIG_PAX_REFCOUNT
22759 + jno 1234f
22760 + LOCK_PREFIX
22761 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22762 + int $4
22763 +1234:
22764 + _ASM_EXTABLE(1234b, 1234b)
22765 +#endif
22766 +
22767 1: rep; nop
22768 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22769 jne 1b
22770 LOCK_PREFIX
22771 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22772 +
22773 +#ifdef CONFIG_PAX_REFCOUNT
22774 + jno 1234f
22775 + LOCK_PREFIX
22776 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22777 + int $4
22778 +1234:
22779 + _ASM_EXTABLE(1234b, 1234b)
22780 +#endif
22781 +
22782 jnz 0b
22783 ENDFRAME
22784 + pax_force_retaddr
22785 ret
22786 CFI_ENDPROC
22787 END(__write_lock_failed)
22788 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22789 FRAME
22790 0: LOCK_PREFIX
22791 READ_LOCK_SIZE(inc) (%__lock_ptr)
22792 +
22793 +#ifdef CONFIG_PAX_REFCOUNT
22794 + jno 1234f
22795 + LOCK_PREFIX
22796 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22797 + int $4
22798 +1234:
22799 + _ASM_EXTABLE(1234b, 1234b)
22800 +#endif
22801 +
22802 1: rep; nop
22803 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22804 js 1b
22805 LOCK_PREFIX
22806 READ_LOCK_SIZE(dec) (%__lock_ptr)
22807 +
22808 +#ifdef CONFIG_PAX_REFCOUNT
22809 + jno 1234f
22810 + LOCK_PREFIX
22811 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22812 + int $4
22813 +1234:
22814 + _ASM_EXTABLE(1234b, 1234b)
22815 +#endif
22816 +
22817 js 0b
22818 ENDFRAME
22819 + pax_force_retaddr
22820 ret
22821 CFI_ENDPROC
22822 END(__read_lock_failed)
22823 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22824 index 5dff5f0..cadebf4 100644
22825 --- a/arch/x86/lib/rwsem.S
22826 +++ b/arch/x86/lib/rwsem.S
22827 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22828 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22829 CFI_RESTORE __ASM_REG(dx)
22830 restore_common_regs
22831 + pax_force_retaddr
22832 ret
22833 CFI_ENDPROC
22834 ENDPROC(call_rwsem_down_read_failed)
22835 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22836 movq %rax,%rdi
22837 call rwsem_down_write_failed
22838 restore_common_regs
22839 + pax_force_retaddr
22840 ret
22841 CFI_ENDPROC
22842 ENDPROC(call_rwsem_down_write_failed)
22843 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22844 movq %rax,%rdi
22845 call rwsem_wake
22846 restore_common_regs
22847 -1: ret
22848 +1: pax_force_retaddr
22849 + ret
22850 CFI_ENDPROC
22851 ENDPROC(call_rwsem_wake)
22852
22853 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22854 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22855 CFI_RESTORE __ASM_REG(dx)
22856 restore_common_regs
22857 + pax_force_retaddr
22858 ret
22859 CFI_ENDPROC
22860 ENDPROC(call_rwsem_downgrade_wake)
22861 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22862 index a63efd6..ccecad8 100644
22863 --- a/arch/x86/lib/thunk_64.S
22864 +++ b/arch/x86/lib/thunk_64.S
22865 @@ -8,6 +8,7 @@
22866 #include <linux/linkage.h>
22867 #include <asm/dwarf2.h>
22868 #include <asm/calling.h>
22869 +#include <asm/alternative-asm.h>
22870
22871 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22872 .macro THUNK name, func, put_ret_addr_in_rdi=0
22873 @@ -41,5 +42,6 @@
22874 SAVE_ARGS
22875 restore:
22876 RESTORE_ARGS
22877 + pax_force_retaddr
22878 ret
22879 CFI_ENDPROC
22880 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22881 index 1781b2f..90368dd 100644
22882 --- a/arch/x86/lib/usercopy_32.c
22883 +++ b/arch/x86/lib/usercopy_32.c
22884 @@ -42,10 +42,12 @@ do { \
22885 int __d0; \
22886 might_fault(); \
22887 __asm__ __volatile__( \
22888 + __COPYUSER_SET_ES \
22889 "0: rep; stosl\n" \
22890 " movl %2,%0\n" \
22891 "1: rep; stosb\n" \
22892 "2:\n" \
22893 + __COPYUSER_RESTORE_ES \
22894 ".section .fixup,\"ax\"\n" \
22895 "3: lea 0(%2,%0,4),%0\n" \
22896 " jmp 2b\n" \
22897 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22898
22899 #ifdef CONFIG_X86_INTEL_USERCOPY
22900 static unsigned long
22901 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22902 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22903 {
22904 int d0, d1;
22905 __asm__ __volatile__(
22906 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22907 " .align 2,0x90\n"
22908 "3: movl 0(%4), %%eax\n"
22909 "4: movl 4(%4), %%edx\n"
22910 - "5: movl %%eax, 0(%3)\n"
22911 - "6: movl %%edx, 4(%3)\n"
22912 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22913 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22914 "7: movl 8(%4), %%eax\n"
22915 "8: movl 12(%4),%%edx\n"
22916 - "9: movl %%eax, 8(%3)\n"
22917 - "10: movl %%edx, 12(%3)\n"
22918 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22919 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22920 "11: movl 16(%4), %%eax\n"
22921 "12: movl 20(%4), %%edx\n"
22922 - "13: movl %%eax, 16(%3)\n"
22923 - "14: movl %%edx, 20(%3)\n"
22924 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22925 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22926 "15: movl 24(%4), %%eax\n"
22927 "16: movl 28(%4), %%edx\n"
22928 - "17: movl %%eax, 24(%3)\n"
22929 - "18: movl %%edx, 28(%3)\n"
22930 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22931 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22932 "19: movl 32(%4), %%eax\n"
22933 "20: movl 36(%4), %%edx\n"
22934 - "21: movl %%eax, 32(%3)\n"
22935 - "22: movl %%edx, 36(%3)\n"
22936 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22937 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22938 "23: movl 40(%4), %%eax\n"
22939 "24: movl 44(%4), %%edx\n"
22940 - "25: movl %%eax, 40(%3)\n"
22941 - "26: movl %%edx, 44(%3)\n"
22942 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22943 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22944 "27: movl 48(%4), %%eax\n"
22945 "28: movl 52(%4), %%edx\n"
22946 - "29: movl %%eax, 48(%3)\n"
22947 - "30: movl %%edx, 52(%3)\n"
22948 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22949 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22950 "31: movl 56(%4), %%eax\n"
22951 "32: movl 60(%4), %%edx\n"
22952 - "33: movl %%eax, 56(%3)\n"
22953 - "34: movl %%edx, 60(%3)\n"
22954 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22955 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22956 " addl $-64, %0\n"
22957 " addl $64, %4\n"
22958 " addl $64, %3\n"
22959 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22960 " shrl $2, %0\n"
22961 " andl $3, %%eax\n"
22962 " cld\n"
22963 + __COPYUSER_SET_ES
22964 "99: rep; movsl\n"
22965 "36: movl %%eax, %0\n"
22966 "37: rep; movsb\n"
22967 "100:\n"
22968 + __COPYUSER_RESTORE_ES
22969 ".section .fixup,\"ax\"\n"
22970 "101: lea 0(%%eax,%0,4),%0\n"
22971 " jmp 100b\n"
22972 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22973 }
22974
22975 static unsigned long
22976 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22977 +{
22978 + int d0, d1;
22979 + __asm__ __volatile__(
22980 + " .align 2,0x90\n"
22981 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22982 + " cmpl $67, %0\n"
22983 + " jbe 3f\n"
22984 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22985 + " .align 2,0x90\n"
22986 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22987 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22988 + "5: movl %%eax, 0(%3)\n"
22989 + "6: movl %%edx, 4(%3)\n"
22990 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22991 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22992 + "9: movl %%eax, 8(%3)\n"
22993 + "10: movl %%edx, 12(%3)\n"
22994 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22995 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22996 + "13: movl %%eax, 16(%3)\n"
22997 + "14: movl %%edx, 20(%3)\n"
22998 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22999 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23000 + "17: movl %%eax, 24(%3)\n"
23001 + "18: movl %%edx, 28(%3)\n"
23002 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23003 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23004 + "21: movl %%eax, 32(%3)\n"
23005 + "22: movl %%edx, 36(%3)\n"
23006 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23007 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23008 + "25: movl %%eax, 40(%3)\n"
23009 + "26: movl %%edx, 44(%3)\n"
23010 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23011 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23012 + "29: movl %%eax, 48(%3)\n"
23013 + "30: movl %%edx, 52(%3)\n"
23014 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23015 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23016 + "33: movl %%eax, 56(%3)\n"
23017 + "34: movl %%edx, 60(%3)\n"
23018 + " addl $-64, %0\n"
23019 + " addl $64, %4\n"
23020 + " addl $64, %3\n"
23021 + " cmpl $63, %0\n"
23022 + " ja 1b\n"
23023 + "35: movl %0, %%eax\n"
23024 + " shrl $2, %0\n"
23025 + " andl $3, %%eax\n"
23026 + " cld\n"
23027 + "99: rep; "__copyuser_seg" movsl\n"
23028 + "36: movl %%eax, %0\n"
23029 + "37: rep; "__copyuser_seg" movsb\n"
23030 + "100:\n"
23031 + ".section .fixup,\"ax\"\n"
23032 + "101: lea 0(%%eax,%0,4),%0\n"
23033 + " jmp 100b\n"
23034 + ".previous\n"
23035 + _ASM_EXTABLE(1b,100b)
23036 + _ASM_EXTABLE(2b,100b)
23037 + _ASM_EXTABLE(3b,100b)
23038 + _ASM_EXTABLE(4b,100b)
23039 + _ASM_EXTABLE(5b,100b)
23040 + _ASM_EXTABLE(6b,100b)
23041 + _ASM_EXTABLE(7b,100b)
23042 + _ASM_EXTABLE(8b,100b)
23043 + _ASM_EXTABLE(9b,100b)
23044 + _ASM_EXTABLE(10b,100b)
23045 + _ASM_EXTABLE(11b,100b)
23046 + _ASM_EXTABLE(12b,100b)
23047 + _ASM_EXTABLE(13b,100b)
23048 + _ASM_EXTABLE(14b,100b)
23049 + _ASM_EXTABLE(15b,100b)
23050 + _ASM_EXTABLE(16b,100b)
23051 + _ASM_EXTABLE(17b,100b)
23052 + _ASM_EXTABLE(18b,100b)
23053 + _ASM_EXTABLE(19b,100b)
23054 + _ASM_EXTABLE(20b,100b)
23055 + _ASM_EXTABLE(21b,100b)
23056 + _ASM_EXTABLE(22b,100b)
23057 + _ASM_EXTABLE(23b,100b)
23058 + _ASM_EXTABLE(24b,100b)
23059 + _ASM_EXTABLE(25b,100b)
23060 + _ASM_EXTABLE(26b,100b)
23061 + _ASM_EXTABLE(27b,100b)
23062 + _ASM_EXTABLE(28b,100b)
23063 + _ASM_EXTABLE(29b,100b)
23064 + _ASM_EXTABLE(30b,100b)
23065 + _ASM_EXTABLE(31b,100b)
23066 + _ASM_EXTABLE(32b,100b)
23067 + _ASM_EXTABLE(33b,100b)
23068 + _ASM_EXTABLE(34b,100b)
23069 + _ASM_EXTABLE(35b,100b)
23070 + _ASM_EXTABLE(36b,100b)
23071 + _ASM_EXTABLE(37b,100b)
23072 + _ASM_EXTABLE(99b,101b)
23073 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23074 + : "1"(to), "2"(from), "0"(size)
23075 + : "eax", "edx", "memory");
23076 + return size;
23077 +}
23078 +
23079 +static unsigned long __size_overflow(3)
23080 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23081 {
23082 int d0, d1;
23083 __asm__ __volatile__(
23084 " .align 2,0x90\n"
23085 - "0: movl 32(%4), %%eax\n"
23086 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23087 " cmpl $67, %0\n"
23088 " jbe 2f\n"
23089 - "1: movl 64(%4), %%eax\n"
23090 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23091 " .align 2,0x90\n"
23092 - "2: movl 0(%4), %%eax\n"
23093 - "21: movl 4(%4), %%edx\n"
23094 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23095 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23096 " movl %%eax, 0(%3)\n"
23097 " movl %%edx, 4(%3)\n"
23098 - "3: movl 8(%4), %%eax\n"
23099 - "31: movl 12(%4),%%edx\n"
23100 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23101 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23102 " movl %%eax, 8(%3)\n"
23103 " movl %%edx, 12(%3)\n"
23104 - "4: movl 16(%4), %%eax\n"
23105 - "41: movl 20(%4), %%edx\n"
23106 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23107 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23108 " movl %%eax, 16(%3)\n"
23109 " movl %%edx, 20(%3)\n"
23110 - "10: movl 24(%4), %%eax\n"
23111 - "51: movl 28(%4), %%edx\n"
23112 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23113 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23114 " movl %%eax, 24(%3)\n"
23115 " movl %%edx, 28(%3)\n"
23116 - "11: movl 32(%4), %%eax\n"
23117 - "61: movl 36(%4), %%edx\n"
23118 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23119 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23120 " movl %%eax, 32(%3)\n"
23121 " movl %%edx, 36(%3)\n"
23122 - "12: movl 40(%4), %%eax\n"
23123 - "71: movl 44(%4), %%edx\n"
23124 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23125 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23126 " movl %%eax, 40(%3)\n"
23127 " movl %%edx, 44(%3)\n"
23128 - "13: movl 48(%4), %%eax\n"
23129 - "81: movl 52(%4), %%edx\n"
23130 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23131 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23132 " movl %%eax, 48(%3)\n"
23133 " movl %%edx, 52(%3)\n"
23134 - "14: movl 56(%4), %%eax\n"
23135 - "91: movl 60(%4), %%edx\n"
23136 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23137 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23138 " movl %%eax, 56(%3)\n"
23139 " movl %%edx, 60(%3)\n"
23140 " addl $-64, %0\n"
23141 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23142 " shrl $2, %0\n"
23143 " andl $3, %%eax\n"
23144 " cld\n"
23145 - "6: rep; movsl\n"
23146 + "6: rep; "__copyuser_seg" movsl\n"
23147 " movl %%eax,%0\n"
23148 - "7: rep; movsb\n"
23149 + "7: rep; "__copyuser_seg" movsb\n"
23150 "8:\n"
23151 ".section .fixup,\"ax\"\n"
23152 "9: lea 0(%%eax,%0,4),%0\n"
23153 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23154 * hyoshiok@miraclelinux.com
23155 */
23156
23157 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23158 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23159 const void __user *from, unsigned long size)
23160 {
23161 int d0, d1;
23162
23163 __asm__ __volatile__(
23164 " .align 2,0x90\n"
23165 - "0: movl 32(%4), %%eax\n"
23166 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23167 " cmpl $67, %0\n"
23168 " jbe 2f\n"
23169 - "1: movl 64(%4), %%eax\n"
23170 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23171 " .align 2,0x90\n"
23172 - "2: movl 0(%4), %%eax\n"
23173 - "21: movl 4(%4), %%edx\n"
23174 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23175 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23176 " movnti %%eax, 0(%3)\n"
23177 " movnti %%edx, 4(%3)\n"
23178 - "3: movl 8(%4), %%eax\n"
23179 - "31: movl 12(%4),%%edx\n"
23180 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23181 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23182 " movnti %%eax, 8(%3)\n"
23183 " movnti %%edx, 12(%3)\n"
23184 - "4: movl 16(%4), %%eax\n"
23185 - "41: movl 20(%4), %%edx\n"
23186 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23187 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23188 " movnti %%eax, 16(%3)\n"
23189 " movnti %%edx, 20(%3)\n"
23190 - "10: movl 24(%4), %%eax\n"
23191 - "51: movl 28(%4), %%edx\n"
23192 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23193 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23194 " movnti %%eax, 24(%3)\n"
23195 " movnti %%edx, 28(%3)\n"
23196 - "11: movl 32(%4), %%eax\n"
23197 - "61: movl 36(%4), %%edx\n"
23198 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23199 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23200 " movnti %%eax, 32(%3)\n"
23201 " movnti %%edx, 36(%3)\n"
23202 - "12: movl 40(%4), %%eax\n"
23203 - "71: movl 44(%4), %%edx\n"
23204 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23205 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23206 " movnti %%eax, 40(%3)\n"
23207 " movnti %%edx, 44(%3)\n"
23208 - "13: movl 48(%4), %%eax\n"
23209 - "81: movl 52(%4), %%edx\n"
23210 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23211 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23212 " movnti %%eax, 48(%3)\n"
23213 " movnti %%edx, 52(%3)\n"
23214 - "14: movl 56(%4), %%eax\n"
23215 - "91: movl 60(%4), %%edx\n"
23216 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23217 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23218 " movnti %%eax, 56(%3)\n"
23219 " movnti %%edx, 60(%3)\n"
23220 " addl $-64, %0\n"
23221 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23222 " shrl $2, %0\n"
23223 " andl $3, %%eax\n"
23224 " cld\n"
23225 - "6: rep; movsl\n"
23226 + "6: rep; "__copyuser_seg" movsl\n"
23227 " movl %%eax,%0\n"
23228 - "7: rep; movsb\n"
23229 + "7: rep; "__copyuser_seg" movsb\n"
23230 "8:\n"
23231 ".section .fixup,\"ax\"\n"
23232 "9: lea 0(%%eax,%0,4),%0\n"
23233 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23234 return size;
23235 }
23236
23237 -static unsigned long __copy_user_intel_nocache(void *to,
23238 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23239 const void __user *from, unsigned long size)
23240 {
23241 int d0, d1;
23242
23243 __asm__ __volatile__(
23244 " .align 2,0x90\n"
23245 - "0: movl 32(%4), %%eax\n"
23246 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23247 " cmpl $67, %0\n"
23248 " jbe 2f\n"
23249 - "1: movl 64(%4), %%eax\n"
23250 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23251 " .align 2,0x90\n"
23252 - "2: movl 0(%4), %%eax\n"
23253 - "21: movl 4(%4), %%edx\n"
23254 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23255 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23256 " movnti %%eax, 0(%3)\n"
23257 " movnti %%edx, 4(%3)\n"
23258 - "3: movl 8(%4), %%eax\n"
23259 - "31: movl 12(%4),%%edx\n"
23260 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23261 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23262 " movnti %%eax, 8(%3)\n"
23263 " movnti %%edx, 12(%3)\n"
23264 - "4: movl 16(%4), %%eax\n"
23265 - "41: movl 20(%4), %%edx\n"
23266 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23267 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23268 " movnti %%eax, 16(%3)\n"
23269 " movnti %%edx, 20(%3)\n"
23270 - "10: movl 24(%4), %%eax\n"
23271 - "51: movl 28(%4), %%edx\n"
23272 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23273 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23274 " movnti %%eax, 24(%3)\n"
23275 " movnti %%edx, 28(%3)\n"
23276 - "11: movl 32(%4), %%eax\n"
23277 - "61: movl 36(%4), %%edx\n"
23278 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23279 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23280 " movnti %%eax, 32(%3)\n"
23281 " movnti %%edx, 36(%3)\n"
23282 - "12: movl 40(%4), %%eax\n"
23283 - "71: movl 44(%4), %%edx\n"
23284 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23285 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23286 " movnti %%eax, 40(%3)\n"
23287 " movnti %%edx, 44(%3)\n"
23288 - "13: movl 48(%4), %%eax\n"
23289 - "81: movl 52(%4), %%edx\n"
23290 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23291 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23292 " movnti %%eax, 48(%3)\n"
23293 " movnti %%edx, 52(%3)\n"
23294 - "14: movl 56(%4), %%eax\n"
23295 - "91: movl 60(%4), %%edx\n"
23296 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23297 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23298 " movnti %%eax, 56(%3)\n"
23299 " movnti %%edx, 60(%3)\n"
23300 " addl $-64, %0\n"
23301 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23302 " shrl $2, %0\n"
23303 " andl $3, %%eax\n"
23304 " cld\n"
23305 - "6: rep; movsl\n"
23306 + "6: rep; "__copyuser_seg" movsl\n"
23307 " movl %%eax,%0\n"
23308 - "7: rep; movsb\n"
23309 + "7: rep; "__copyuser_seg" movsb\n"
23310 "8:\n"
23311 ".section .fixup,\"ax\"\n"
23312 "9: lea 0(%%eax,%0,4),%0\n"
23313 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23314 */
23315 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23316 unsigned long size);
23317 -unsigned long __copy_user_intel(void __user *to, const void *from,
23318 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23319 + unsigned long size);
23320 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23321 unsigned long size);
23322 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23323 const void __user *from, unsigned long size);
23324 #endif /* CONFIG_X86_INTEL_USERCOPY */
23325
23326 /* Generic arbitrary sized copy. */
23327 -#define __copy_user(to, from, size) \
23328 +#define __copy_user(to, from, size, prefix, set, restore) \
23329 do { \
23330 int __d0, __d1, __d2; \
23331 __asm__ __volatile__( \
23332 + set \
23333 " cmp $7,%0\n" \
23334 " jbe 1f\n" \
23335 " movl %1,%0\n" \
23336 " negl %0\n" \
23337 " andl $7,%0\n" \
23338 " subl %0,%3\n" \
23339 - "4: rep; movsb\n" \
23340 + "4: rep; "prefix"movsb\n" \
23341 " movl %3,%0\n" \
23342 " shrl $2,%0\n" \
23343 " andl $3,%3\n" \
23344 " .align 2,0x90\n" \
23345 - "0: rep; movsl\n" \
23346 + "0: rep; "prefix"movsl\n" \
23347 " movl %3,%0\n" \
23348 - "1: rep; movsb\n" \
23349 + "1: rep; "prefix"movsb\n" \
23350 "2:\n" \
23351 + restore \
23352 ".section .fixup,\"ax\"\n" \
23353 "5: addl %3,%0\n" \
23354 " jmp 2b\n" \
23355 @@ -537,14 +649,14 @@ do { \
23356 " negl %0\n" \
23357 " andl $7,%0\n" \
23358 " subl %0,%3\n" \
23359 - "4: rep; movsb\n" \
23360 + "4: rep; "__copyuser_seg"movsb\n" \
23361 " movl %3,%0\n" \
23362 " shrl $2,%0\n" \
23363 " andl $3,%3\n" \
23364 " .align 2,0x90\n" \
23365 - "0: rep; movsl\n" \
23366 + "0: rep; "__copyuser_seg"movsl\n" \
23367 " movl %3,%0\n" \
23368 - "1: rep; movsb\n" \
23369 + "1: rep; "__copyuser_seg"movsb\n" \
23370 "2:\n" \
23371 ".section .fixup,\"ax\"\n" \
23372 "5: addl %3,%0\n" \
23373 @@ -627,9 +739,9 @@ survive:
23374 }
23375 #endif
23376 if (movsl_is_ok(to, from, n))
23377 - __copy_user(to, from, n);
23378 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23379 else
23380 - n = __copy_user_intel(to, from, n);
23381 + n = __generic_copy_to_user_intel(to, from, n);
23382 return n;
23383 }
23384 EXPORT_SYMBOL(__copy_to_user_ll);
23385 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23386 unsigned long n)
23387 {
23388 if (movsl_is_ok(to, from, n))
23389 - __copy_user(to, from, n);
23390 + __copy_user(to, from, n, __copyuser_seg, "", "");
23391 else
23392 - n = __copy_user_intel((void __user *)to,
23393 - (const void *)from, n);
23394 + n = __generic_copy_from_user_intel(to, from, n);
23395 return n;
23396 }
23397 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23398 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23399 if (n > 64 && cpu_has_xmm2)
23400 n = __copy_user_intel_nocache(to, from, n);
23401 else
23402 - __copy_user(to, from, n);
23403 + __copy_user(to, from, n, __copyuser_seg, "", "");
23404 #else
23405 - __copy_user(to, from, n);
23406 + __copy_user(to, from, n, __copyuser_seg, "", "");
23407 #endif
23408 return n;
23409 }
23410 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23411
23412 -/**
23413 - * copy_to_user: - Copy a block of data into user space.
23414 - * @to: Destination address, in user space.
23415 - * @from: Source address, in kernel space.
23416 - * @n: Number of bytes to copy.
23417 - *
23418 - * Context: User context only. This function may sleep.
23419 - *
23420 - * Copy data from kernel space to user space.
23421 - *
23422 - * Returns number of bytes that could not be copied.
23423 - * On success, this will be zero.
23424 - */
23425 -unsigned long
23426 -copy_to_user(void __user *to, const void *from, unsigned long n)
23427 -{
23428 - if (access_ok(VERIFY_WRITE, to, n))
23429 - n = __copy_to_user(to, from, n);
23430 - return n;
23431 -}
23432 -EXPORT_SYMBOL(copy_to_user);
23433 -
23434 -/**
23435 - * copy_from_user: - Copy a block of data from user space.
23436 - * @to: Destination address, in kernel space.
23437 - * @from: Source address, in user space.
23438 - * @n: Number of bytes to copy.
23439 - *
23440 - * Context: User context only. This function may sleep.
23441 - *
23442 - * Copy data from user space to kernel space.
23443 - *
23444 - * Returns number of bytes that could not be copied.
23445 - * On success, this will be zero.
23446 - *
23447 - * If some data could not be copied, this function will pad the copied
23448 - * data to the requested size using zero bytes.
23449 - */
23450 -unsigned long
23451 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23452 -{
23453 - if (access_ok(VERIFY_READ, from, n))
23454 - n = __copy_from_user(to, from, n);
23455 - else
23456 - memset(to, 0, n);
23457 - return n;
23458 -}
23459 -EXPORT_SYMBOL(_copy_from_user);
23460 -
23461 void copy_from_user_overflow(void)
23462 {
23463 WARN(1, "Buffer overflow detected!\n");
23464 }
23465 EXPORT_SYMBOL(copy_from_user_overflow);
23466 +
23467 +void copy_to_user_overflow(void)
23468 +{
23469 + WARN(1, "Buffer overflow detected!\n");
23470 +}
23471 +EXPORT_SYMBOL(copy_to_user_overflow);
23472 +
23473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23474 +void __set_fs(mm_segment_t x)
23475 +{
23476 + switch (x.seg) {
23477 + case 0:
23478 + loadsegment(gs, 0);
23479 + break;
23480 + case TASK_SIZE_MAX:
23481 + loadsegment(gs, __USER_DS);
23482 + break;
23483 + case -1UL:
23484 + loadsegment(gs, __KERNEL_DS);
23485 + break;
23486 + default:
23487 + BUG();
23488 + }
23489 + return;
23490 +}
23491 +EXPORT_SYMBOL(__set_fs);
23492 +
23493 +void set_fs(mm_segment_t x)
23494 +{
23495 + current_thread_info()->addr_limit = x;
23496 + __set_fs(x);
23497 +}
23498 +EXPORT_SYMBOL(set_fs);
23499 +#endif
23500 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23501 index e5b130b..6690d31 100644
23502 --- a/arch/x86/lib/usercopy_64.c
23503 +++ b/arch/x86/lib/usercopy_64.c
23504 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23505 {
23506 long __d0;
23507 might_fault();
23508 +
23509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23510 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23511 + addr += PAX_USER_SHADOW_BASE;
23512 +#endif
23513 +
23514 /* no memory constraint because it doesn't change any memory gcc knows
23515 about */
23516 asm volatile(
23517 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23518 }
23519 EXPORT_SYMBOL(clear_user);
23520
23521 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23522 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23523 {
23524 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23525 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23526 - }
23527 - return len;
23528 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23529 +
23530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23531 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23532 + to += PAX_USER_SHADOW_BASE;
23533 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23534 + from += PAX_USER_SHADOW_BASE;
23535 +#endif
23536 +
23537 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23538 + }
23539 + return len;
23540 }
23541 EXPORT_SYMBOL(copy_in_user);
23542
23543 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23544 * it is not necessary to optimize tail handling.
23545 */
23546 unsigned long
23547 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23548 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23549 {
23550 char c;
23551 unsigned zero_len;
23552 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23553 break;
23554 return len;
23555 }
23556 +
23557 +void copy_from_user_overflow(void)
23558 +{
23559 + WARN(1, "Buffer overflow detected!\n");
23560 +}
23561 +EXPORT_SYMBOL(copy_from_user_overflow);
23562 +
23563 +void copy_to_user_overflow(void)
23564 +{
23565 + WARN(1, "Buffer overflow detected!\n");
23566 +}
23567 +EXPORT_SYMBOL(copy_to_user_overflow);
23568 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23569 index 903ec1e..c4166b2 100644
23570 --- a/arch/x86/mm/extable.c
23571 +++ b/arch/x86/mm/extable.c
23572 @@ -6,12 +6,24 @@
23573 static inline unsigned long
23574 ex_insn_addr(const struct exception_table_entry *x)
23575 {
23576 - return (unsigned long)&x->insn + x->insn;
23577 + unsigned long reloc = 0;
23578 +
23579 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23580 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23581 +#endif
23582 +
23583 + return (unsigned long)&x->insn + x->insn + reloc;
23584 }
23585 static inline unsigned long
23586 ex_fixup_addr(const struct exception_table_entry *x)
23587 {
23588 - return (unsigned long)&x->fixup + x->fixup;
23589 + unsigned long reloc = 0;
23590 +
23591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23592 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23593 +#endif
23594 +
23595 + return (unsigned long)&x->fixup + x->fixup + reloc;
23596 }
23597
23598 int fixup_exception(struct pt_regs *regs)
23599 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23600 unsigned long new_ip;
23601
23602 #ifdef CONFIG_PNPBIOS
23603 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23604 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23605 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23606 extern u32 pnp_bios_is_utter_crap;
23607 pnp_bios_is_utter_crap = 1;
23608 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23609 i += 4;
23610 p->fixup -= i;
23611 i += 4;
23612 +
23613 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23614 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23615 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23616 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23617 +#endif
23618 +
23619 }
23620 }
23621
23622 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23623 index 76dcd9d..e9dffde 100644
23624 --- a/arch/x86/mm/fault.c
23625 +++ b/arch/x86/mm/fault.c
23626 @@ -13,11 +13,18 @@
23627 #include <linux/perf_event.h> /* perf_sw_event */
23628 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23629 #include <linux/prefetch.h> /* prefetchw */
23630 +#include <linux/unistd.h>
23631 +#include <linux/compiler.h>
23632
23633 #include <asm/traps.h> /* dotraplinkage, ... */
23634 #include <asm/pgalloc.h> /* pgd_*(), ... */
23635 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23636 #include <asm/fixmap.h> /* VSYSCALL_START */
23637 +#include <asm/tlbflush.h>
23638 +
23639 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23640 +#include <asm/stacktrace.h>
23641 +#endif
23642
23643 /*
23644 * Page fault error code bits:
23645 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23646 int ret = 0;
23647
23648 /* kprobe_running() needs smp_processor_id() */
23649 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23650 + if (kprobes_built_in() && !user_mode(regs)) {
23651 preempt_disable();
23652 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23653 ret = 1;
23654 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23655 return !instr_lo || (instr_lo>>1) == 1;
23656 case 0x00:
23657 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23658 - if (probe_kernel_address(instr, opcode))
23659 + if (user_mode(regs)) {
23660 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23661 + return 0;
23662 + } else if (probe_kernel_address(instr, opcode))
23663 return 0;
23664
23665 *prefetch = (instr_lo == 0xF) &&
23666 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23667 while (instr < max_instr) {
23668 unsigned char opcode;
23669
23670 - if (probe_kernel_address(instr, opcode))
23671 + if (user_mode(regs)) {
23672 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23673 + break;
23674 + } else if (probe_kernel_address(instr, opcode))
23675 break;
23676
23677 instr++;
23678 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23679 force_sig_info(si_signo, &info, tsk);
23680 }
23681
23682 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23683 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23684 +#endif
23685 +
23686 +#ifdef CONFIG_PAX_EMUTRAMP
23687 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23688 +#endif
23689 +
23690 +#ifdef CONFIG_PAX_PAGEEXEC
23691 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23692 +{
23693 + pgd_t *pgd;
23694 + pud_t *pud;
23695 + pmd_t *pmd;
23696 +
23697 + pgd = pgd_offset(mm, address);
23698 + if (!pgd_present(*pgd))
23699 + return NULL;
23700 + pud = pud_offset(pgd, address);
23701 + if (!pud_present(*pud))
23702 + return NULL;
23703 + pmd = pmd_offset(pud, address);
23704 + if (!pmd_present(*pmd))
23705 + return NULL;
23706 + return pmd;
23707 +}
23708 +#endif
23709 +
23710 DEFINE_SPINLOCK(pgd_lock);
23711 LIST_HEAD(pgd_list);
23712
23713 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23714 for (address = VMALLOC_START & PMD_MASK;
23715 address >= TASK_SIZE && address < FIXADDR_TOP;
23716 address += PMD_SIZE) {
23717 +
23718 +#ifdef CONFIG_PAX_PER_CPU_PGD
23719 + unsigned long cpu;
23720 +#else
23721 struct page *page;
23722 +#endif
23723
23724 spin_lock(&pgd_lock);
23725 +
23726 +#ifdef CONFIG_PAX_PER_CPU_PGD
23727 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23728 + pgd_t *pgd = get_cpu_pgd(cpu);
23729 + pmd_t *ret;
23730 +#else
23731 list_for_each_entry(page, &pgd_list, lru) {
23732 + pgd_t *pgd = page_address(page);
23733 spinlock_t *pgt_lock;
23734 pmd_t *ret;
23735
23736 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23737 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23738
23739 spin_lock(pgt_lock);
23740 - ret = vmalloc_sync_one(page_address(page), address);
23741 +#endif
23742 +
23743 + ret = vmalloc_sync_one(pgd, address);
23744 +
23745 +#ifndef CONFIG_PAX_PER_CPU_PGD
23746 spin_unlock(pgt_lock);
23747 +#endif
23748
23749 if (!ret)
23750 break;
23751 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23752 * an interrupt in the middle of a task switch..
23753 */
23754 pgd_paddr = read_cr3();
23755 +
23756 +#ifdef CONFIG_PAX_PER_CPU_PGD
23757 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23758 +#endif
23759 +
23760 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23761 if (!pmd_k)
23762 return -1;
23763 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23764 * happen within a race in page table update. In the later
23765 * case just flush:
23766 */
23767 +
23768 +#ifdef CONFIG_PAX_PER_CPU_PGD
23769 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23770 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23771 +#else
23772 pgd = pgd_offset(current->active_mm, address);
23773 +#endif
23774 +
23775 pgd_ref = pgd_offset_k(address);
23776 if (pgd_none(*pgd_ref))
23777 return -1;
23778 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23779 static int is_errata100(struct pt_regs *regs, unsigned long address)
23780 {
23781 #ifdef CONFIG_X86_64
23782 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23783 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23784 return 1;
23785 #endif
23786 return 0;
23787 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23788 }
23789
23790 static const char nx_warning[] = KERN_CRIT
23791 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23792 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23793
23794 static void
23795 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23796 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23797 if (!oops_may_print())
23798 return;
23799
23800 - if (error_code & PF_INSTR) {
23801 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23802 unsigned int level;
23803
23804 pte_t *pte = lookup_address(address, &level);
23805
23806 if (pte && pte_present(*pte) && !pte_exec(*pte))
23807 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23808 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23809 }
23810
23811 +#ifdef CONFIG_PAX_KERNEXEC
23812 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23813 + if (current->signal->curr_ip)
23814 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23815 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23816 + else
23817 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23818 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23819 + }
23820 +#endif
23821 +
23822 printk(KERN_ALERT "BUG: unable to handle kernel ");
23823 if (address < PAGE_SIZE)
23824 printk(KERN_CONT "NULL pointer dereference");
23825 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23826 }
23827 #endif
23828
23829 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23830 + if (pax_is_fetch_fault(regs, error_code, address)) {
23831 +
23832 +#ifdef CONFIG_PAX_EMUTRAMP
23833 + switch (pax_handle_fetch_fault(regs)) {
23834 + case 2:
23835 + return;
23836 + }
23837 +#endif
23838 +
23839 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23840 + do_group_exit(SIGKILL);
23841 + }
23842 +#endif
23843 +
23844 if (unlikely(show_unhandled_signals))
23845 show_signal_msg(regs, error_code, address, tsk);
23846
23847 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23848 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23849 printk(KERN_ERR
23850 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23851 - tsk->comm, tsk->pid, address);
23852 + tsk->comm, task_pid_nr(tsk), address);
23853 code = BUS_MCEERR_AR;
23854 }
23855 #endif
23856 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23857 return 1;
23858 }
23859
23860 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23861 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23862 +{
23863 + pte_t *pte;
23864 + pmd_t *pmd;
23865 + spinlock_t *ptl;
23866 + unsigned char pte_mask;
23867 +
23868 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23869 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23870 + return 0;
23871 +
23872 + /* PaX: it's our fault, let's handle it if we can */
23873 +
23874 + /* PaX: take a look at read faults before acquiring any locks */
23875 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23876 + /* instruction fetch attempt from a protected page in user mode */
23877 + up_read(&mm->mmap_sem);
23878 +
23879 +#ifdef CONFIG_PAX_EMUTRAMP
23880 + switch (pax_handle_fetch_fault(regs)) {
23881 + case 2:
23882 + return 1;
23883 + }
23884 +#endif
23885 +
23886 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23887 + do_group_exit(SIGKILL);
23888 + }
23889 +
23890 + pmd = pax_get_pmd(mm, address);
23891 + if (unlikely(!pmd))
23892 + return 0;
23893 +
23894 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23895 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23896 + pte_unmap_unlock(pte, ptl);
23897 + return 0;
23898 + }
23899 +
23900 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23901 + /* write attempt to a protected page in user mode */
23902 + pte_unmap_unlock(pte, ptl);
23903 + return 0;
23904 + }
23905 +
23906 +#ifdef CONFIG_SMP
23907 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23908 +#else
23909 + if (likely(address > get_limit(regs->cs)))
23910 +#endif
23911 + {
23912 + set_pte(pte, pte_mkread(*pte));
23913 + __flush_tlb_one(address);
23914 + pte_unmap_unlock(pte, ptl);
23915 + up_read(&mm->mmap_sem);
23916 + return 1;
23917 + }
23918 +
23919 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23920 +
23921 + /*
23922 + * PaX: fill DTLB with user rights and retry
23923 + */
23924 + __asm__ __volatile__ (
23925 + "orb %2,(%1)\n"
23926 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23927 +/*
23928 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23929 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23930 + * page fault when examined during a TLB load attempt. this is true not only
23931 + * for PTEs holding a non-present entry but also present entries that will
23932 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23933 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23934 + * for our target pages since their PTEs are simply not in the TLBs at all.
23935 +
23936 + * the best thing in omitting it is that we gain around 15-20% speed in the
23937 + * fast path of the page fault handler and can get rid of tracing since we
23938 + * can no longer flush unintended entries.
23939 + */
23940 + "invlpg (%0)\n"
23941 +#endif
23942 + __copyuser_seg"testb $0,(%0)\n"
23943 + "xorb %3,(%1)\n"
23944 + :
23945 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23946 + : "memory", "cc");
23947 + pte_unmap_unlock(pte, ptl);
23948 + up_read(&mm->mmap_sem);
23949 + return 1;
23950 +}
23951 +#endif
23952 +
23953 /*
23954 * Handle a spurious fault caused by a stale TLB entry.
23955 *
23956 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23957 static inline int
23958 access_error(unsigned long error_code, struct vm_area_struct *vma)
23959 {
23960 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23961 + return 1;
23962 +
23963 if (error_code & PF_WRITE) {
23964 /* write, present and write, not present: */
23965 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23966 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23967 {
23968 struct vm_area_struct *vma;
23969 struct task_struct *tsk;
23970 - unsigned long address;
23971 struct mm_struct *mm;
23972 int fault;
23973 int write = error_code & PF_WRITE;
23974 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23975 (write ? FAULT_FLAG_WRITE : 0);
23976
23977 - tsk = current;
23978 - mm = tsk->mm;
23979 -
23980 /* Get the faulting address: */
23981 - address = read_cr2();
23982 + unsigned long address = read_cr2();
23983 +
23984 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23985 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23986 + if (!search_exception_tables(regs->ip)) {
23987 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23988 + bad_area_nosemaphore(regs, error_code, address);
23989 + return;
23990 + }
23991 + if (address < PAX_USER_SHADOW_BASE) {
23992 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23993 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23994 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23995 + } else
23996 + address -= PAX_USER_SHADOW_BASE;
23997 + }
23998 +#endif
23999 +
24000 + tsk = current;
24001 + mm = tsk->mm;
24002
24003 /*
24004 * Detect and handle instructions that would cause a page fault for
24005 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24006 * User-mode registers count as a user access even for any
24007 * potential system fault or CPU buglet:
24008 */
24009 - if (user_mode_vm(regs)) {
24010 + if (user_mode(regs)) {
24011 local_irq_enable();
24012 error_code |= PF_USER;
24013 } else {
24014 @@ -1132,6 +1339,11 @@ retry:
24015 might_sleep();
24016 }
24017
24018 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24019 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24020 + return;
24021 +#endif
24022 +
24023 vma = find_vma(mm, address);
24024 if (unlikely(!vma)) {
24025 bad_area(regs, error_code, address);
24026 @@ -1143,18 +1355,24 @@ retry:
24027 bad_area(regs, error_code, address);
24028 return;
24029 }
24030 - if (error_code & PF_USER) {
24031 - /*
24032 - * Accessing the stack below %sp is always a bug.
24033 - * The large cushion allows instructions like enter
24034 - * and pusha to work. ("enter $65535, $31" pushes
24035 - * 32 pointers and then decrements %sp by 65535.)
24036 - */
24037 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24038 - bad_area(regs, error_code, address);
24039 - return;
24040 - }
24041 + /*
24042 + * Accessing the stack below %sp is always a bug.
24043 + * The large cushion allows instructions like enter
24044 + * and pusha to work. ("enter $65535, $31" pushes
24045 + * 32 pointers and then decrements %sp by 65535.)
24046 + */
24047 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24048 + bad_area(regs, error_code, address);
24049 + return;
24050 }
24051 +
24052 +#ifdef CONFIG_PAX_SEGMEXEC
24053 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24054 + bad_area(regs, error_code, address);
24055 + return;
24056 + }
24057 +#endif
24058 +
24059 if (unlikely(expand_stack(vma, address))) {
24060 bad_area(regs, error_code, address);
24061 return;
24062 @@ -1209,3 +1427,292 @@ good_area:
24063
24064 up_read(&mm->mmap_sem);
24065 }
24066 +
24067 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24068 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24069 +{
24070 + struct mm_struct *mm = current->mm;
24071 + unsigned long ip = regs->ip;
24072 +
24073 + if (v8086_mode(regs))
24074 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24075 +
24076 +#ifdef CONFIG_PAX_PAGEEXEC
24077 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24078 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24079 + return true;
24080 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24081 + return true;
24082 + return false;
24083 + }
24084 +#endif
24085 +
24086 +#ifdef CONFIG_PAX_SEGMEXEC
24087 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24088 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24089 + return true;
24090 + return false;
24091 + }
24092 +#endif
24093 +
24094 + return false;
24095 +}
24096 +#endif
24097 +
24098 +#ifdef CONFIG_PAX_EMUTRAMP
24099 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24100 +{
24101 + int err;
24102 +
24103 + do { /* PaX: libffi trampoline emulation */
24104 + unsigned char mov, jmp;
24105 + unsigned int addr1, addr2;
24106 +
24107 +#ifdef CONFIG_X86_64
24108 + if ((regs->ip + 9) >> 32)
24109 + break;
24110 +#endif
24111 +
24112 + err = get_user(mov, (unsigned char __user *)regs->ip);
24113 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24114 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24115 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24116 +
24117 + if (err)
24118 + break;
24119 +
24120 + if (mov == 0xB8 && jmp == 0xE9) {
24121 + regs->ax = addr1;
24122 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24123 + return 2;
24124 + }
24125 + } while (0);
24126 +
24127 + do { /* PaX: gcc trampoline emulation #1 */
24128 + unsigned char mov1, mov2;
24129 + unsigned short jmp;
24130 + unsigned int addr1, addr2;
24131 +
24132 +#ifdef CONFIG_X86_64
24133 + if ((regs->ip + 11) >> 32)
24134 + break;
24135 +#endif
24136 +
24137 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24138 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24139 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24140 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24141 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24142 +
24143 + if (err)
24144 + break;
24145 +
24146 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24147 + regs->cx = addr1;
24148 + regs->ax = addr2;
24149 + regs->ip = addr2;
24150 + return 2;
24151 + }
24152 + } while (0);
24153 +
24154 + do { /* PaX: gcc trampoline emulation #2 */
24155 + unsigned char mov, jmp;
24156 + unsigned int addr1, addr2;
24157 +
24158 +#ifdef CONFIG_X86_64
24159 + if ((regs->ip + 9) >> 32)
24160 + break;
24161 +#endif
24162 +
24163 + err = get_user(mov, (unsigned char __user *)regs->ip);
24164 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24165 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24166 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24167 +
24168 + if (err)
24169 + break;
24170 +
24171 + if (mov == 0xB9 && jmp == 0xE9) {
24172 + regs->cx = addr1;
24173 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24174 + return 2;
24175 + }
24176 + } while (0);
24177 +
24178 + return 1; /* PaX in action */
24179 +}
24180 +
24181 +#ifdef CONFIG_X86_64
24182 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24183 +{
24184 + int err;
24185 +
24186 + do { /* PaX: libffi trampoline emulation */
24187 + unsigned short mov1, mov2, jmp1;
24188 + unsigned char stcclc, jmp2;
24189 + unsigned long addr1, addr2;
24190 +
24191 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24192 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24193 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24194 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24195 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24196 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24197 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24198 +
24199 + if (err)
24200 + break;
24201 +
24202 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24203 + regs->r11 = addr1;
24204 + regs->r10 = addr2;
24205 + if (stcclc == 0xF8)
24206 + regs->flags &= ~X86_EFLAGS_CF;
24207 + else
24208 + regs->flags |= X86_EFLAGS_CF;
24209 + regs->ip = addr1;
24210 + return 2;
24211 + }
24212 + } while (0);
24213 +
24214 + do { /* PaX: gcc trampoline emulation #1 */
24215 + unsigned short mov1, mov2, jmp1;
24216 + unsigned char jmp2;
24217 + unsigned int addr1;
24218 + unsigned long addr2;
24219 +
24220 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24221 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24222 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24223 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24224 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24225 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24226 +
24227 + if (err)
24228 + break;
24229 +
24230 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24231 + regs->r11 = addr1;
24232 + regs->r10 = addr2;
24233 + regs->ip = addr1;
24234 + return 2;
24235 + }
24236 + } while (0);
24237 +
24238 + do { /* PaX: gcc trampoline emulation #2 */
24239 + unsigned short mov1, mov2, jmp1;
24240 + unsigned char jmp2;
24241 + unsigned long addr1, addr2;
24242 +
24243 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24244 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24245 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24246 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24247 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24248 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24249 +
24250 + if (err)
24251 + break;
24252 +
24253 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24254 + regs->r11 = addr1;
24255 + regs->r10 = addr2;
24256 + regs->ip = addr1;
24257 + return 2;
24258 + }
24259 + } while (0);
24260 +
24261 + return 1; /* PaX in action */
24262 +}
24263 +#endif
24264 +
24265 +/*
24266 + * PaX: decide what to do with offenders (regs->ip = fault address)
24267 + *
24268 + * returns 1 when task should be killed
24269 + * 2 when gcc trampoline was detected
24270 + */
24271 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24272 +{
24273 + if (v8086_mode(regs))
24274 + return 1;
24275 +
24276 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24277 + return 1;
24278 +
24279 +#ifdef CONFIG_X86_32
24280 + return pax_handle_fetch_fault_32(regs);
24281 +#else
24282 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24283 + return pax_handle_fetch_fault_32(regs);
24284 + else
24285 + return pax_handle_fetch_fault_64(regs);
24286 +#endif
24287 +}
24288 +#endif
24289 +
24290 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24291 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24292 +{
24293 + long i;
24294 +
24295 + printk(KERN_ERR "PAX: bytes at PC: ");
24296 + for (i = 0; i < 20; i++) {
24297 + unsigned char c;
24298 + if (get_user(c, (unsigned char __force_user *)pc+i))
24299 + printk(KERN_CONT "?? ");
24300 + else
24301 + printk(KERN_CONT "%02x ", c);
24302 + }
24303 + printk("\n");
24304 +
24305 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24306 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24307 + unsigned long c;
24308 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24309 +#ifdef CONFIG_X86_32
24310 + printk(KERN_CONT "???????? ");
24311 +#else
24312 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24313 + printk(KERN_CONT "???????? ???????? ");
24314 + else
24315 + printk(KERN_CONT "???????????????? ");
24316 +#endif
24317 + } else {
24318 +#ifdef CONFIG_X86_64
24319 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24320 + printk(KERN_CONT "%08x ", (unsigned int)c);
24321 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24322 + } else
24323 +#endif
24324 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24325 + }
24326 + }
24327 + printk("\n");
24328 +}
24329 +#endif
24330 +
24331 +/**
24332 + * probe_kernel_write(): safely attempt to write to a location
24333 + * @dst: address to write to
24334 + * @src: pointer to the data that shall be written
24335 + * @size: size of the data chunk
24336 + *
24337 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24338 + * happens, handle that and return -EFAULT.
24339 + */
24340 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24341 +{
24342 + long ret;
24343 + mm_segment_t old_fs = get_fs();
24344 +
24345 + set_fs(KERNEL_DS);
24346 + pagefault_disable();
24347 + pax_open_kernel();
24348 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24349 + pax_close_kernel();
24350 + pagefault_enable();
24351 + set_fs(old_fs);
24352 +
24353 + return ret ? -EFAULT : 0;
24354 +}
24355 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24356 index dd74e46..7d26398 100644
24357 --- a/arch/x86/mm/gup.c
24358 +++ b/arch/x86/mm/gup.c
24359 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24360 addr = start;
24361 len = (unsigned long) nr_pages << PAGE_SHIFT;
24362 end = start + len;
24363 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24364 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24365 (void __user *)start, len)))
24366 return 0;
24367
24368 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24369 index 6f31ee5..8ee4164 100644
24370 --- a/arch/x86/mm/highmem_32.c
24371 +++ b/arch/x86/mm/highmem_32.c
24372 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24373 idx = type + KM_TYPE_NR*smp_processor_id();
24374 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24375 BUG_ON(!pte_none(*(kmap_pte-idx)));
24376 +
24377 + pax_open_kernel();
24378 set_pte(kmap_pte-idx, mk_pte(page, prot));
24379 + pax_close_kernel();
24380 +
24381 arch_flush_lazy_mmu_mode();
24382
24383 return (void *)vaddr;
24384 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24385 index b91e485..d00e7c9 100644
24386 --- a/arch/x86/mm/hugetlbpage.c
24387 +++ b/arch/x86/mm/hugetlbpage.c
24388 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24389 struct hstate *h = hstate_file(file);
24390 struct mm_struct *mm = current->mm;
24391 struct vm_area_struct *vma;
24392 - unsigned long start_addr;
24393 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24394 +
24395 +#ifdef CONFIG_PAX_SEGMEXEC
24396 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24397 + pax_task_size = SEGMEXEC_TASK_SIZE;
24398 +#endif
24399 +
24400 + pax_task_size -= PAGE_SIZE;
24401
24402 if (len > mm->cached_hole_size) {
24403 - start_addr = mm->free_area_cache;
24404 + start_addr = mm->free_area_cache;
24405 } else {
24406 - start_addr = TASK_UNMAPPED_BASE;
24407 - mm->cached_hole_size = 0;
24408 + start_addr = mm->mmap_base;
24409 + mm->cached_hole_size = 0;
24410 }
24411
24412 full_search:
24413 @@ -291,26 +298,27 @@ full_search:
24414
24415 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24416 /* At this point: (!vma || addr < vma->vm_end). */
24417 - if (TASK_SIZE - len < addr) {
24418 + if (pax_task_size - len < addr) {
24419 /*
24420 * Start a new search - just in case we missed
24421 * some holes.
24422 */
24423 - if (start_addr != TASK_UNMAPPED_BASE) {
24424 - start_addr = TASK_UNMAPPED_BASE;
24425 + if (start_addr != mm->mmap_base) {
24426 + start_addr = mm->mmap_base;
24427 mm->cached_hole_size = 0;
24428 goto full_search;
24429 }
24430 return -ENOMEM;
24431 }
24432 - if (!vma || addr + len <= vma->vm_start) {
24433 - mm->free_area_cache = addr + len;
24434 - return addr;
24435 - }
24436 + if (check_heap_stack_gap(vma, addr, len))
24437 + break;
24438 if (addr + mm->cached_hole_size < vma->vm_start)
24439 mm->cached_hole_size = vma->vm_start - addr;
24440 addr = ALIGN(vma->vm_end, huge_page_size(h));
24441 }
24442 +
24443 + mm->free_area_cache = addr + len;
24444 + return addr;
24445 }
24446
24447 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24448 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24449 struct mm_struct *mm = current->mm;
24450 struct vm_area_struct *vma;
24451 unsigned long base = mm->mmap_base;
24452 - unsigned long addr = addr0;
24453 + unsigned long addr;
24454 unsigned long largest_hole = mm->cached_hole_size;
24455 - unsigned long start_addr;
24456
24457 /* don't allow allocations above current base */
24458 if (mm->free_area_cache > base)
24459 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24460 largest_hole = 0;
24461 mm->free_area_cache = base;
24462 }
24463 -try_again:
24464 - start_addr = mm->free_area_cache;
24465
24466 /* make sure it can fit in the remaining address space */
24467 if (mm->free_area_cache < len)
24468 goto fail;
24469
24470 /* either no address requested or can't fit in requested address hole */
24471 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24472 + addr = mm->free_area_cache - len;
24473 do {
24474 + addr &= huge_page_mask(h);
24475 /*
24476 * Lookup failure means no vma is above this address,
24477 * i.e. return with success:
24478 @@ -351,10 +357,10 @@ try_again:
24479 if (!vma)
24480 return addr;
24481
24482 - if (addr + len <= vma->vm_start) {
24483 + if (check_heap_stack_gap(vma, addr, len)) {
24484 /* remember the address as a hint for next time */
24485 - mm->cached_hole_size = largest_hole;
24486 - return (mm->free_area_cache = addr);
24487 + mm->cached_hole_size = largest_hole;
24488 + return (mm->free_area_cache = addr);
24489 } else if (mm->free_area_cache == vma->vm_end) {
24490 /* pull free_area_cache down to the first hole */
24491 mm->free_area_cache = vma->vm_start;
24492 @@ -363,29 +369,34 @@ try_again:
24493
24494 /* remember the largest hole we saw so far */
24495 if (addr + largest_hole < vma->vm_start)
24496 - largest_hole = vma->vm_start - addr;
24497 + largest_hole = vma->vm_start - addr;
24498
24499 /* try just below the current vma->vm_start */
24500 - addr = (vma->vm_start - len) & huge_page_mask(h);
24501 - } while (len <= vma->vm_start);
24502 + addr = skip_heap_stack_gap(vma, len);
24503 + } while (!IS_ERR_VALUE(addr));
24504
24505 fail:
24506 /*
24507 - * if hint left us with no space for the requested
24508 - * mapping then try again:
24509 - */
24510 - if (start_addr != base) {
24511 - mm->free_area_cache = base;
24512 - largest_hole = 0;
24513 - goto try_again;
24514 - }
24515 - /*
24516 * A failed mmap() very likely causes application failure,
24517 * so fall back to the bottom-up function here. This scenario
24518 * can happen with large stack limits and large mmap()
24519 * allocations.
24520 */
24521 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24522 +
24523 +#ifdef CONFIG_PAX_SEGMEXEC
24524 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24525 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24526 + else
24527 +#endif
24528 +
24529 + mm->mmap_base = TASK_UNMAPPED_BASE;
24530 +
24531 +#ifdef CONFIG_PAX_RANDMMAP
24532 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24533 + mm->mmap_base += mm->delta_mmap;
24534 +#endif
24535 +
24536 + mm->free_area_cache = mm->mmap_base;
24537 mm->cached_hole_size = ~0UL;
24538 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24539 len, pgoff, flags);
24540 @@ -393,6 +404,7 @@ fail:
24541 /*
24542 * Restore the topdown base:
24543 */
24544 + mm->mmap_base = base;
24545 mm->free_area_cache = base;
24546 mm->cached_hole_size = ~0UL;
24547
24548 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24549 struct hstate *h = hstate_file(file);
24550 struct mm_struct *mm = current->mm;
24551 struct vm_area_struct *vma;
24552 + unsigned long pax_task_size = TASK_SIZE;
24553
24554 if (len & ~huge_page_mask(h))
24555 return -EINVAL;
24556 - if (len > TASK_SIZE)
24557 +
24558 +#ifdef CONFIG_PAX_SEGMEXEC
24559 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24560 + pax_task_size = SEGMEXEC_TASK_SIZE;
24561 +#endif
24562 +
24563 + pax_task_size -= PAGE_SIZE;
24564 +
24565 + if (len > pax_task_size)
24566 return -ENOMEM;
24567
24568 if (flags & MAP_FIXED) {
24569 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24570 if (addr) {
24571 addr = ALIGN(addr, huge_page_size(h));
24572 vma = find_vma(mm, addr);
24573 - if (TASK_SIZE - len >= addr &&
24574 - (!vma || addr + len <= vma->vm_start))
24575 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24576 return addr;
24577 }
24578 if (mm->get_unmapped_area == arch_get_unmapped_area)
24579 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24580 index ab1f6a9..23030ba 100644
24581 --- a/arch/x86/mm/init.c
24582 +++ b/arch/x86/mm/init.c
24583 @@ -16,6 +16,8 @@
24584 #include <asm/tlb.h>
24585 #include <asm/proto.h>
24586 #include <asm/dma.h> /* for MAX_DMA_PFN */
24587 +#include <asm/desc.h>
24588 +#include <asm/bios_ebda.h>
24589
24590 unsigned long __initdata pgt_buf_start;
24591 unsigned long __meminitdata pgt_buf_end;
24592 @@ -38,7 +40,7 @@ struct map_range {
24593 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24594 int use_pse, int use_gbpages)
24595 {
24596 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24597 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24598 phys_addr_t base;
24599
24600 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24601 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24602 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24603 * mmio resources as well as potential bios/acpi data regions.
24604 */
24605 +
24606 +#ifdef CONFIG_GRKERNSEC_KMEM
24607 +static unsigned int ebda_start __read_only;
24608 +static unsigned int ebda_end __read_only;
24609 +#endif
24610 +
24611 int devmem_is_allowed(unsigned long pagenr)
24612 {
24613 - if (pagenr < 256)
24614 +#ifdef CONFIG_GRKERNSEC_KMEM
24615 + /* allow BDA */
24616 + if (!pagenr)
24617 return 1;
24618 + /* allow EBDA */
24619 + if (pagenr >= ebda_start && pagenr < ebda_end)
24620 + return 1;
24621 +#else
24622 + if (!pagenr)
24623 + return 1;
24624 +#ifdef CONFIG_VM86
24625 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24626 + return 1;
24627 +#endif
24628 +#endif
24629 +
24630 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24631 + return 1;
24632 +#ifdef CONFIG_GRKERNSEC_KMEM
24633 + /* throw out everything else below 1MB */
24634 + if (pagenr <= 256)
24635 + return 0;
24636 +#endif
24637 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24638 return 0;
24639 if (!page_is_ram(pagenr))
24640 @@ -377,8 +406,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24641 #endif
24642 }
24643
24644 +#ifdef CONFIG_GRKERNSEC_KMEM
24645 +static inline void gr_init_ebda(void)
24646 +{
24647 + unsigned int ebda_addr;
24648 + unsigned int ebda_size = 0;
24649 +
24650 + ebda_addr = get_bios_ebda();
24651 + if (ebda_addr) {
24652 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24653 + ebda_size <<= 10;
24654 + }
24655 + if (ebda_addr && ebda_size) {
24656 + ebda_start = ebda_addr >> PAGE_SHIFT;
24657 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24658 + } else {
24659 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24660 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24661 + }
24662 +}
24663 +#else
24664 +static inline void gr_init_ebda(void) { }
24665 +#endif
24666 +
24667 void free_initmem(void)
24668 {
24669 +#ifdef CONFIG_PAX_KERNEXEC
24670 +#ifdef CONFIG_X86_32
24671 + /* PaX: limit KERNEL_CS to actual size */
24672 + unsigned long addr, limit;
24673 + struct desc_struct d;
24674 + int cpu;
24675 +#else
24676 + pgd_t *pgd;
24677 + pud_t *pud;
24678 + pmd_t *pmd;
24679 + unsigned long addr, end;
24680 +#endif
24681 +#endif
24682 +
24683 + gr_init_ebda();
24684 +
24685 +#ifdef CONFIG_PAX_KERNEXEC
24686 +#ifdef CONFIG_X86_32
24687 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24688 + limit = (limit - 1UL) >> PAGE_SHIFT;
24689 +
24690 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24691 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24692 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24693 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24694 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24695 + }
24696 +
24697 + /* PaX: make KERNEL_CS read-only */
24698 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24699 + if (!paravirt_enabled())
24700 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24701 +/*
24702 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24703 + pgd = pgd_offset_k(addr);
24704 + pud = pud_offset(pgd, addr);
24705 + pmd = pmd_offset(pud, addr);
24706 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24707 + }
24708 +*/
24709 +#ifdef CONFIG_X86_PAE
24710 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24711 +/*
24712 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24713 + pgd = pgd_offset_k(addr);
24714 + pud = pud_offset(pgd, addr);
24715 + pmd = pmd_offset(pud, addr);
24716 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24717 + }
24718 +*/
24719 +#endif
24720 +
24721 +#ifdef CONFIG_MODULES
24722 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24723 +#endif
24724 +
24725 +#else
24726 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24727 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24728 + pgd = pgd_offset_k(addr);
24729 + pud = pud_offset(pgd, addr);
24730 + pmd = pmd_offset(pud, addr);
24731 + if (!pmd_present(*pmd))
24732 + continue;
24733 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24734 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24735 + else
24736 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24737 + }
24738 +
24739 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24740 + end = addr + KERNEL_IMAGE_SIZE;
24741 + for (; addr < end; addr += PMD_SIZE) {
24742 + pgd = pgd_offset_k(addr);
24743 + pud = pud_offset(pgd, addr);
24744 + pmd = pmd_offset(pud, addr);
24745 + if (!pmd_present(*pmd))
24746 + continue;
24747 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24748 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24749 + }
24750 +#endif
24751 +
24752 + flush_tlb_all();
24753 +#endif
24754 +
24755 free_init_pages("unused kernel memory",
24756 (unsigned long)(&__init_begin),
24757 (unsigned long)(&__init_end));
24758 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24759 index 575d86f..4987469 100644
24760 --- a/arch/x86/mm/init_32.c
24761 +++ b/arch/x86/mm/init_32.c
24762 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24763 }
24764
24765 /*
24766 - * Creates a middle page table and puts a pointer to it in the
24767 - * given global directory entry. This only returns the gd entry
24768 - * in non-PAE compilation mode, since the middle layer is folded.
24769 - */
24770 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24771 -{
24772 - pud_t *pud;
24773 - pmd_t *pmd_table;
24774 -
24775 -#ifdef CONFIG_X86_PAE
24776 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24777 - if (after_bootmem)
24778 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24779 - else
24780 - pmd_table = (pmd_t *)alloc_low_page();
24781 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24782 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24783 - pud = pud_offset(pgd, 0);
24784 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24785 -
24786 - return pmd_table;
24787 - }
24788 -#endif
24789 - pud = pud_offset(pgd, 0);
24790 - pmd_table = pmd_offset(pud, 0);
24791 -
24792 - return pmd_table;
24793 -}
24794 -
24795 -/*
24796 * Create a page table and place a pointer to it in a middle page
24797 * directory entry:
24798 */
24799 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24800 page_table = (pte_t *)alloc_low_page();
24801
24802 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24803 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24804 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24805 +#else
24806 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24807 +#endif
24808 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24809 }
24810
24811 return pte_offset_kernel(pmd, 0);
24812 }
24813
24814 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24815 +{
24816 + pud_t *pud;
24817 + pmd_t *pmd_table;
24818 +
24819 + pud = pud_offset(pgd, 0);
24820 + pmd_table = pmd_offset(pud, 0);
24821 +
24822 + return pmd_table;
24823 +}
24824 +
24825 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24826 {
24827 int pgd_idx = pgd_index(vaddr);
24828 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24829 int pgd_idx, pmd_idx;
24830 unsigned long vaddr;
24831 pgd_t *pgd;
24832 + pud_t *pud;
24833 pmd_t *pmd;
24834 pte_t *pte = NULL;
24835
24836 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24837 pgd = pgd_base + pgd_idx;
24838
24839 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24840 - pmd = one_md_table_init(pgd);
24841 - pmd = pmd + pmd_index(vaddr);
24842 + pud = pud_offset(pgd, vaddr);
24843 + pmd = pmd_offset(pud, vaddr);
24844 +
24845 +#ifdef CONFIG_X86_PAE
24846 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24847 +#endif
24848 +
24849 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24850 pmd++, pmd_idx++) {
24851 pte = page_table_kmap_check(one_page_table_init(pmd),
24852 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24853 }
24854 }
24855
24856 -static inline int is_kernel_text(unsigned long addr)
24857 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24858 {
24859 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24860 - return 1;
24861 - return 0;
24862 + if ((start > ktla_ktva((unsigned long)_etext) ||
24863 + end <= ktla_ktva((unsigned long)_stext)) &&
24864 + (start > ktla_ktva((unsigned long)_einittext) ||
24865 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24866 +
24867 +#ifdef CONFIG_ACPI_SLEEP
24868 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24869 +#endif
24870 +
24871 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24872 + return 0;
24873 + return 1;
24874 }
24875
24876 /*
24877 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24878 unsigned long last_map_addr = end;
24879 unsigned long start_pfn, end_pfn;
24880 pgd_t *pgd_base = swapper_pg_dir;
24881 - int pgd_idx, pmd_idx, pte_ofs;
24882 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24883 unsigned long pfn;
24884 pgd_t *pgd;
24885 + pud_t *pud;
24886 pmd_t *pmd;
24887 pte_t *pte;
24888 unsigned pages_2m, pages_4k;
24889 @@ -280,8 +281,13 @@ repeat:
24890 pfn = start_pfn;
24891 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24892 pgd = pgd_base + pgd_idx;
24893 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24894 - pmd = one_md_table_init(pgd);
24895 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24896 + pud = pud_offset(pgd, 0);
24897 + pmd = pmd_offset(pud, 0);
24898 +
24899 +#ifdef CONFIG_X86_PAE
24900 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24901 +#endif
24902
24903 if (pfn >= end_pfn)
24904 continue;
24905 @@ -293,14 +299,13 @@ repeat:
24906 #endif
24907 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24908 pmd++, pmd_idx++) {
24909 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24910 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24911
24912 /*
24913 * Map with big pages if possible, otherwise
24914 * create normal page tables:
24915 */
24916 if (use_pse) {
24917 - unsigned int addr2;
24918 pgprot_t prot = PAGE_KERNEL_LARGE;
24919 /*
24920 * first pass will use the same initial
24921 @@ -310,11 +315,7 @@ repeat:
24922 __pgprot(PTE_IDENT_ATTR |
24923 _PAGE_PSE);
24924
24925 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24926 - PAGE_OFFSET + PAGE_SIZE-1;
24927 -
24928 - if (is_kernel_text(addr) ||
24929 - is_kernel_text(addr2))
24930 + if (is_kernel_text(address, address + PMD_SIZE))
24931 prot = PAGE_KERNEL_LARGE_EXEC;
24932
24933 pages_2m++;
24934 @@ -331,7 +332,7 @@ repeat:
24935 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24936 pte += pte_ofs;
24937 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24938 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24939 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24940 pgprot_t prot = PAGE_KERNEL;
24941 /*
24942 * first pass will use the same initial
24943 @@ -339,7 +340,7 @@ repeat:
24944 */
24945 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24946
24947 - if (is_kernel_text(addr))
24948 + if (is_kernel_text(address, address + PAGE_SIZE))
24949 prot = PAGE_KERNEL_EXEC;
24950
24951 pages_4k++;
24952 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24953
24954 pud = pud_offset(pgd, va);
24955 pmd = pmd_offset(pud, va);
24956 - if (!pmd_present(*pmd))
24957 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24958 break;
24959
24960 pte = pte_offset_kernel(pmd, va);
24961 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24962
24963 static void __init pagetable_init(void)
24964 {
24965 - pgd_t *pgd_base = swapper_pg_dir;
24966 -
24967 - permanent_kmaps_init(pgd_base);
24968 + permanent_kmaps_init(swapper_pg_dir);
24969 }
24970
24971 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24972 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24973 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24974
24975 /* user-defined highmem size */
24976 @@ -734,6 +733,12 @@ void __init mem_init(void)
24977
24978 pci_iommu_alloc();
24979
24980 +#ifdef CONFIG_PAX_PER_CPU_PGD
24981 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24982 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24983 + KERNEL_PGD_PTRS);
24984 +#endif
24985 +
24986 #ifdef CONFIG_FLATMEM
24987 BUG_ON(!mem_map);
24988 #endif
24989 @@ -760,7 +765,7 @@ void __init mem_init(void)
24990 reservedpages++;
24991
24992 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24993 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24994 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24995 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24996
24997 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24998 @@ -801,10 +806,10 @@ void __init mem_init(void)
24999 ((unsigned long)&__init_end -
25000 (unsigned long)&__init_begin) >> 10,
25001
25002 - (unsigned long)&_etext, (unsigned long)&_edata,
25003 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25004 + (unsigned long)&_sdata, (unsigned long)&_edata,
25005 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25006
25007 - (unsigned long)&_text, (unsigned long)&_etext,
25008 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25009 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25010
25011 /*
25012 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25013 if (!kernel_set_to_readonly)
25014 return;
25015
25016 + start = ktla_ktva(start);
25017 pr_debug("Set kernel text: %lx - %lx for read write\n",
25018 start, start+size);
25019
25020 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25021 if (!kernel_set_to_readonly)
25022 return;
25023
25024 + start = ktla_ktva(start);
25025 pr_debug("Set kernel text: %lx - %lx for read only\n",
25026 start, start+size);
25027
25028 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25029 unsigned long start = PFN_ALIGN(_text);
25030 unsigned long size = PFN_ALIGN(_etext) - start;
25031
25032 + start = ktla_ktva(start);
25033 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25034 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25035 size >> 10);
25036 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25037 index 2b6b4a3..c17210d 100644
25038 --- a/arch/x86/mm/init_64.c
25039 +++ b/arch/x86/mm/init_64.c
25040 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25041 * around without checking the pgd every time.
25042 */
25043
25044 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25045 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25046 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25047
25048 int force_personality32;
25049 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25050
25051 for (address = start; address <= end; address += PGDIR_SIZE) {
25052 const pgd_t *pgd_ref = pgd_offset_k(address);
25053 +
25054 +#ifdef CONFIG_PAX_PER_CPU_PGD
25055 + unsigned long cpu;
25056 +#else
25057 struct page *page;
25058 +#endif
25059
25060 if (pgd_none(*pgd_ref))
25061 continue;
25062
25063 spin_lock(&pgd_lock);
25064 +
25065 +#ifdef CONFIG_PAX_PER_CPU_PGD
25066 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25067 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25068 +#else
25069 list_for_each_entry(page, &pgd_list, lru) {
25070 pgd_t *pgd;
25071 spinlock_t *pgt_lock;
25072 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25073 /* the pgt_lock only for Xen */
25074 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25075 spin_lock(pgt_lock);
25076 +#endif
25077
25078 if (pgd_none(*pgd))
25079 set_pgd(pgd, *pgd_ref);
25080 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25081 BUG_ON(pgd_page_vaddr(*pgd)
25082 != pgd_page_vaddr(*pgd_ref));
25083
25084 +#ifndef CONFIG_PAX_PER_CPU_PGD
25085 spin_unlock(pgt_lock);
25086 +#endif
25087 +
25088 }
25089 spin_unlock(&pgd_lock);
25090 }
25091 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25092 {
25093 if (pgd_none(*pgd)) {
25094 pud_t *pud = (pud_t *)spp_getpage();
25095 - pgd_populate(&init_mm, pgd, pud);
25096 + pgd_populate_kernel(&init_mm, pgd, pud);
25097 if (pud != pud_offset(pgd, 0))
25098 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25099 pud, pud_offset(pgd, 0));
25100 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25101 {
25102 if (pud_none(*pud)) {
25103 pmd_t *pmd = (pmd_t *) spp_getpage();
25104 - pud_populate(&init_mm, pud, pmd);
25105 + pud_populate_kernel(&init_mm, pud, pmd);
25106 if (pmd != pmd_offset(pud, 0))
25107 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25108 pmd, pmd_offset(pud, 0));
25109 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25110 pmd = fill_pmd(pud, vaddr);
25111 pte = fill_pte(pmd, vaddr);
25112
25113 + pax_open_kernel();
25114 set_pte(pte, new_pte);
25115 + pax_close_kernel();
25116
25117 /*
25118 * It's enough to flush this one mapping.
25119 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25120 pgd = pgd_offset_k((unsigned long)__va(phys));
25121 if (pgd_none(*pgd)) {
25122 pud = (pud_t *) spp_getpage();
25123 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25124 - _PAGE_USER));
25125 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25126 }
25127 pud = pud_offset(pgd, (unsigned long)__va(phys));
25128 if (pud_none(*pud)) {
25129 pmd = (pmd_t *) spp_getpage();
25130 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25131 - _PAGE_USER));
25132 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25133 }
25134 pmd = pmd_offset(pud, phys);
25135 BUG_ON(!pmd_none(*pmd));
25136 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25137 if (pfn >= pgt_buf_top)
25138 panic("alloc_low_page: ran out of memory");
25139
25140 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25141 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25142 clear_page(adr);
25143 *phys = pfn * PAGE_SIZE;
25144 return adr;
25145 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25146
25147 phys = __pa(virt);
25148 left = phys & (PAGE_SIZE - 1);
25149 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25150 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25151 adr = (void *)(((unsigned long)adr) | left);
25152
25153 return adr;
25154 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25155 unmap_low_page(pmd);
25156
25157 spin_lock(&init_mm.page_table_lock);
25158 - pud_populate(&init_mm, pud, __va(pmd_phys));
25159 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25160 spin_unlock(&init_mm.page_table_lock);
25161 }
25162 __flush_tlb_all();
25163 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25164 unmap_low_page(pud);
25165
25166 spin_lock(&init_mm.page_table_lock);
25167 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25168 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25169 spin_unlock(&init_mm.page_table_lock);
25170 pgd_changed = true;
25171 }
25172 @@ -686,6 +700,12 @@ void __init mem_init(void)
25173
25174 pci_iommu_alloc();
25175
25176 +#ifdef CONFIG_PAX_PER_CPU_PGD
25177 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25178 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25179 + KERNEL_PGD_PTRS);
25180 +#endif
25181 +
25182 /* clear_bss() already clear the empty_zero_page */
25183
25184 reservedpages = 0;
25185 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25186 static struct vm_area_struct gate_vma = {
25187 .vm_start = VSYSCALL_START,
25188 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25189 - .vm_page_prot = PAGE_READONLY_EXEC,
25190 - .vm_flags = VM_READ | VM_EXEC
25191 + .vm_page_prot = PAGE_READONLY,
25192 + .vm_flags = VM_READ
25193 };
25194
25195 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25196 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25197
25198 const char *arch_vma_name(struct vm_area_struct *vma)
25199 {
25200 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25201 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25202 return "[vdso]";
25203 if (vma == &gate_vma)
25204 return "[vsyscall]";
25205 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25206 index 7b179b4..6bd1777 100644
25207 --- a/arch/x86/mm/iomap_32.c
25208 +++ b/arch/x86/mm/iomap_32.c
25209 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25210 type = kmap_atomic_idx_push();
25211 idx = type + KM_TYPE_NR * smp_processor_id();
25212 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25213 +
25214 + pax_open_kernel();
25215 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25216 + pax_close_kernel();
25217 +
25218 arch_flush_lazy_mmu_mode();
25219
25220 return (void *)vaddr;
25221 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25222 index 78fe3f1..8293b6f 100644
25223 --- a/arch/x86/mm/ioremap.c
25224 +++ b/arch/x86/mm/ioremap.c
25225 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25226 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25227 int is_ram = page_is_ram(pfn);
25228
25229 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25230 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25231 return NULL;
25232 WARN_ON_ONCE(is_ram);
25233 }
25234 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25235
25236 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25237 if (page_is_ram(start >> PAGE_SHIFT))
25238 +#ifdef CONFIG_HIGHMEM
25239 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25240 +#endif
25241 return __va(phys);
25242
25243 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25244 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25245 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25246
25247 static __initdata int after_paging_init;
25248 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25249 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25250
25251 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25252 {
25253 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25254 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25255
25256 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25257 - memset(bm_pte, 0, sizeof(bm_pte));
25258 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25259 + pmd_populate_user(&init_mm, pmd, bm_pte);
25260
25261 /*
25262 * The boot-ioremap range spans multiple pmds, for which
25263 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25264 index d87dd6d..bf3fa66 100644
25265 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25266 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25267 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25268 * memory (e.g. tracked pages)? For now, we need this to avoid
25269 * invoking kmemcheck for PnP BIOS calls.
25270 */
25271 - if (regs->flags & X86_VM_MASK)
25272 + if (v8086_mode(regs))
25273 return false;
25274 - if (regs->cs != __KERNEL_CS)
25275 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25276 return false;
25277
25278 pte = kmemcheck_pte_lookup(address);
25279 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25280 index 845df68..1d8d29f 100644
25281 --- a/arch/x86/mm/mmap.c
25282 +++ b/arch/x86/mm/mmap.c
25283 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25284 * Leave an at least ~128 MB hole with possible stack randomization.
25285 */
25286 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25287 -#define MAX_GAP (TASK_SIZE/6*5)
25288 +#define MAX_GAP (pax_task_size/6*5)
25289
25290 static int mmap_is_legacy(void)
25291 {
25292 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25293 return rnd << PAGE_SHIFT;
25294 }
25295
25296 -static unsigned long mmap_base(void)
25297 +static unsigned long mmap_base(struct mm_struct *mm)
25298 {
25299 unsigned long gap = rlimit(RLIMIT_STACK);
25300 + unsigned long pax_task_size = TASK_SIZE;
25301 +
25302 +#ifdef CONFIG_PAX_SEGMEXEC
25303 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25304 + pax_task_size = SEGMEXEC_TASK_SIZE;
25305 +#endif
25306
25307 if (gap < MIN_GAP)
25308 gap = MIN_GAP;
25309 else if (gap > MAX_GAP)
25310 gap = MAX_GAP;
25311
25312 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25313 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25314 }
25315
25316 /*
25317 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25318 * does, but not when emulating X86_32
25319 */
25320 -static unsigned long mmap_legacy_base(void)
25321 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25322 {
25323 - if (mmap_is_ia32())
25324 + if (mmap_is_ia32()) {
25325 +
25326 +#ifdef CONFIG_PAX_SEGMEXEC
25327 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25328 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25329 + else
25330 +#endif
25331 +
25332 return TASK_UNMAPPED_BASE;
25333 - else
25334 + } else
25335 return TASK_UNMAPPED_BASE + mmap_rnd();
25336 }
25337
25338 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25339 void arch_pick_mmap_layout(struct mm_struct *mm)
25340 {
25341 if (mmap_is_legacy()) {
25342 - mm->mmap_base = mmap_legacy_base();
25343 + mm->mmap_base = mmap_legacy_base(mm);
25344 +
25345 +#ifdef CONFIG_PAX_RANDMMAP
25346 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25347 + mm->mmap_base += mm->delta_mmap;
25348 +#endif
25349 +
25350 mm->get_unmapped_area = arch_get_unmapped_area;
25351 mm->unmap_area = arch_unmap_area;
25352 } else {
25353 - mm->mmap_base = mmap_base();
25354 + mm->mmap_base = mmap_base(mm);
25355 +
25356 +#ifdef CONFIG_PAX_RANDMMAP
25357 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25358 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25359 +#endif
25360 +
25361 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25362 mm->unmap_area = arch_unmap_area_topdown;
25363 }
25364 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25365 index dc0b727..dc9d71a 100644
25366 --- a/arch/x86/mm/mmio-mod.c
25367 +++ b/arch/x86/mm/mmio-mod.c
25368 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25369 break;
25370 default:
25371 {
25372 - unsigned char *ip = (unsigned char *)instptr;
25373 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25374 my_trace->opcode = MMIO_UNKNOWN_OP;
25375 my_trace->width = 0;
25376 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25377 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25378 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25379 void __iomem *addr)
25380 {
25381 - static atomic_t next_id;
25382 + static atomic_unchecked_t next_id;
25383 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25384 /* These are page-unaligned. */
25385 struct mmiotrace_map map = {
25386 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25387 .private = trace
25388 },
25389 .phys = offset,
25390 - .id = atomic_inc_return(&next_id)
25391 + .id = atomic_inc_return_unchecked(&next_id)
25392 };
25393 map.map_id = trace->id;
25394
25395 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25396 index b008656..773eac2 100644
25397 --- a/arch/x86/mm/pageattr-test.c
25398 +++ b/arch/x86/mm/pageattr-test.c
25399 @@ -36,7 +36,7 @@ enum {
25400
25401 static int pte_testbit(pte_t pte)
25402 {
25403 - return pte_flags(pte) & _PAGE_UNUSED1;
25404 + return pte_flags(pte) & _PAGE_CPA_TEST;
25405 }
25406
25407 struct split_state {
25408 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25409 index a718e0d..45efc32 100644
25410 --- a/arch/x86/mm/pageattr.c
25411 +++ b/arch/x86/mm/pageattr.c
25412 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25413 */
25414 #ifdef CONFIG_PCI_BIOS
25415 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25416 - pgprot_val(forbidden) |= _PAGE_NX;
25417 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25418 #endif
25419
25420 /*
25421 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25422 * Does not cover __inittext since that is gone later on. On
25423 * 64bit we do not enforce !NX on the low mapping
25424 */
25425 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25426 - pgprot_val(forbidden) |= _PAGE_NX;
25427 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25428 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25429
25430 +#ifdef CONFIG_DEBUG_RODATA
25431 /*
25432 * The .rodata section needs to be read-only. Using the pfn
25433 * catches all aliases.
25434 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25435 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25436 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25437 pgprot_val(forbidden) |= _PAGE_RW;
25438 +#endif
25439
25440 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25441 /*
25442 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25443 }
25444 #endif
25445
25446 +#ifdef CONFIG_PAX_KERNEXEC
25447 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25448 + pgprot_val(forbidden) |= _PAGE_RW;
25449 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25450 + }
25451 +#endif
25452 +
25453 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25454
25455 return prot;
25456 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25457 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25458 {
25459 /* change init_mm */
25460 + pax_open_kernel();
25461 set_pte_atomic(kpte, pte);
25462 +
25463 #ifdef CONFIG_X86_32
25464 if (!SHARED_KERNEL_PMD) {
25465 +
25466 +#ifdef CONFIG_PAX_PER_CPU_PGD
25467 + unsigned long cpu;
25468 +#else
25469 struct page *page;
25470 +#endif
25471
25472 +#ifdef CONFIG_PAX_PER_CPU_PGD
25473 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25474 + pgd_t *pgd = get_cpu_pgd(cpu);
25475 +#else
25476 list_for_each_entry(page, &pgd_list, lru) {
25477 - pgd_t *pgd;
25478 + pgd_t *pgd = (pgd_t *)page_address(page);
25479 +#endif
25480 +
25481 pud_t *pud;
25482 pmd_t *pmd;
25483
25484 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25485 + pgd += pgd_index(address);
25486 pud = pud_offset(pgd, address);
25487 pmd = pmd_offset(pud, address);
25488 set_pte_atomic((pte_t *)pmd, pte);
25489 }
25490 }
25491 #endif
25492 + pax_close_kernel();
25493 }
25494
25495 static int
25496 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25497 index 3d68ef6..7f69136 100644
25498 --- a/arch/x86/mm/pat.c
25499 +++ b/arch/x86/mm/pat.c
25500 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25501
25502 if (!entry) {
25503 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25504 - current->comm, current->pid, start, end - 1);
25505 + current->comm, task_pid_nr(current), start, end - 1);
25506 return -EINVAL;
25507 }
25508
25509 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25510
25511 while (cursor < to) {
25512 if (!devmem_is_allowed(pfn)) {
25513 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25514 - current->comm, from, to - 1);
25515 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25516 + current->comm, from, to - 1, cursor);
25517 return 0;
25518 }
25519 cursor += PAGE_SIZE;
25520 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25521 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25522 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25523 "for [mem %#010Lx-%#010Lx]\n",
25524 - current->comm, current->pid,
25525 + current->comm, task_pid_nr(current),
25526 cattr_name(flags),
25527 base, (unsigned long long)(base + size-1));
25528 return -EINVAL;
25529 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25530 flags = lookup_memtype(paddr);
25531 if (want_flags != flags) {
25532 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25533 - current->comm, current->pid,
25534 + current->comm, task_pid_nr(current),
25535 cattr_name(want_flags),
25536 (unsigned long long)paddr,
25537 (unsigned long long)(paddr + size - 1),
25538 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25539 free_memtype(paddr, paddr + size);
25540 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25541 " for [mem %#010Lx-%#010Lx], got %s\n",
25542 - current->comm, current->pid,
25543 + current->comm, task_pid_nr(current),
25544 cattr_name(want_flags),
25545 (unsigned long long)paddr,
25546 (unsigned long long)(paddr + size - 1),
25547 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25548 index 9f0614d..92ae64a 100644
25549 --- a/arch/x86/mm/pf_in.c
25550 +++ b/arch/x86/mm/pf_in.c
25551 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25552 int i;
25553 enum reason_type rv = OTHERS;
25554
25555 - p = (unsigned char *)ins_addr;
25556 + p = (unsigned char *)ktla_ktva(ins_addr);
25557 p += skip_prefix(p, &prf);
25558 p += get_opcode(p, &opcode);
25559
25560 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25561 struct prefix_bits prf;
25562 int i;
25563
25564 - p = (unsigned char *)ins_addr;
25565 + p = (unsigned char *)ktla_ktva(ins_addr);
25566 p += skip_prefix(p, &prf);
25567 p += get_opcode(p, &opcode);
25568
25569 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25570 struct prefix_bits prf;
25571 int i;
25572
25573 - p = (unsigned char *)ins_addr;
25574 + p = (unsigned char *)ktla_ktva(ins_addr);
25575 p += skip_prefix(p, &prf);
25576 p += get_opcode(p, &opcode);
25577
25578 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25579 struct prefix_bits prf;
25580 int i;
25581
25582 - p = (unsigned char *)ins_addr;
25583 + p = (unsigned char *)ktla_ktva(ins_addr);
25584 p += skip_prefix(p, &prf);
25585 p += get_opcode(p, &opcode);
25586 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25587 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25588 struct prefix_bits prf;
25589 int i;
25590
25591 - p = (unsigned char *)ins_addr;
25592 + p = (unsigned char *)ktla_ktva(ins_addr);
25593 p += skip_prefix(p, &prf);
25594 p += get_opcode(p, &opcode);
25595 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25596 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25597 index 8573b83..4f3ed7e 100644
25598 --- a/arch/x86/mm/pgtable.c
25599 +++ b/arch/x86/mm/pgtable.c
25600 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25601 list_del(&page->lru);
25602 }
25603
25604 -#define UNSHARED_PTRS_PER_PGD \
25605 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25606 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25607 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25608
25609 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25610 +{
25611 + unsigned int count = USER_PGD_PTRS;
25612
25613 + while (count--)
25614 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25615 +}
25616 +#endif
25617 +
25618 +#ifdef CONFIG_PAX_PER_CPU_PGD
25619 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25620 +{
25621 + unsigned int count = USER_PGD_PTRS;
25622 +
25623 + while (count--) {
25624 + pgd_t pgd;
25625 +
25626 +#ifdef CONFIG_X86_64
25627 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25628 +#else
25629 + pgd = *src++;
25630 +#endif
25631 +
25632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25633 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25634 +#endif
25635 +
25636 + *dst++ = pgd;
25637 + }
25638 +
25639 +}
25640 +#endif
25641 +
25642 +#ifdef CONFIG_X86_64
25643 +#define pxd_t pud_t
25644 +#define pyd_t pgd_t
25645 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25646 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25647 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25648 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25649 +#define PYD_SIZE PGDIR_SIZE
25650 +#else
25651 +#define pxd_t pmd_t
25652 +#define pyd_t pud_t
25653 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25654 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25655 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25656 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25657 +#define PYD_SIZE PUD_SIZE
25658 +#endif
25659 +
25660 +#ifdef CONFIG_PAX_PER_CPU_PGD
25661 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25662 +static inline void pgd_dtor(pgd_t *pgd) {}
25663 +#else
25664 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25665 {
25666 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25667 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25668 pgd_list_del(pgd);
25669 spin_unlock(&pgd_lock);
25670 }
25671 +#endif
25672
25673 /*
25674 * List of all pgd's needed for non-PAE so it can invalidate entries
25675 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25676 * -- wli
25677 */
25678
25679 -#ifdef CONFIG_X86_PAE
25680 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25681 /*
25682 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25683 * updating the top-level pagetable entries to guarantee the
25684 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25685 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25686 * and initialize the kernel pmds here.
25687 */
25688 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25689 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25690
25691 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25692 {
25693 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25694 */
25695 flush_tlb_mm(mm);
25696 }
25697 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25698 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25699 #else /* !CONFIG_X86_PAE */
25700
25701 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25702 -#define PREALLOCATED_PMDS 0
25703 +#define PREALLOCATED_PXDS 0
25704
25705 #endif /* CONFIG_X86_PAE */
25706
25707 -static void free_pmds(pmd_t *pmds[])
25708 +static void free_pxds(pxd_t *pxds[])
25709 {
25710 int i;
25711
25712 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25713 - if (pmds[i])
25714 - free_page((unsigned long)pmds[i]);
25715 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25716 + if (pxds[i])
25717 + free_page((unsigned long)pxds[i]);
25718 }
25719
25720 -static int preallocate_pmds(pmd_t *pmds[])
25721 +static int preallocate_pxds(pxd_t *pxds[])
25722 {
25723 int i;
25724 bool failed = false;
25725
25726 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25727 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25728 - if (pmd == NULL)
25729 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25730 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25731 + if (pxd == NULL)
25732 failed = true;
25733 - pmds[i] = pmd;
25734 + pxds[i] = pxd;
25735 }
25736
25737 if (failed) {
25738 - free_pmds(pmds);
25739 + free_pxds(pxds);
25740 return -ENOMEM;
25741 }
25742
25743 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25744 * preallocate which never got a corresponding vma will need to be
25745 * freed manually.
25746 */
25747 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25748 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25749 {
25750 int i;
25751
25752 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25753 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25754 pgd_t pgd = pgdp[i];
25755
25756 if (pgd_val(pgd) != 0) {
25757 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25758 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25759
25760 - pgdp[i] = native_make_pgd(0);
25761 + set_pgd(pgdp + i, native_make_pgd(0));
25762
25763 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25764 - pmd_free(mm, pmd);
25765 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25766 + pxd_free(mm, pxd);
25767 }
25768 }
25769 }
25770
25771 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25772 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25773 {
25774 - pud_t *pud;
25775 + pyd_t *pyd;
25776 unsigned long addr;
25777 int i;
25778
25779 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25780 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25781 return;
25782
25783 - pud = pud_offset(pgd, 0);
25784 +#ifdef CONFIG_X86_64
25785 + pyd = pyd_offset(mm, 0L);
25786 +#else
25787 + pyd = pyd_offset(pgd, 0L);
25788 +#endif
25789
25790 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25791 - i++, pud++, addr += PUD_SIZE) {
25792 - pmd_t *pmd = pmds[i];
25793 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25794 + i++, pyd++, addr += PYD_SIZE) {
25795 + pxd_t *pxd = pxds[i];
25796
25797 if (i >= KERNEL_PGD_BOUNDARY)
25798 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25799 - sizeof(pmd_t) * PTRS_PER_PMD);
25800 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25801 + sizeof(pxd_t) * PTRS_PER_PMD);
25802
25803 - pud_populate(mm, pud, pmd);
25804 + pyd_populate(mm, pyd, pxd);
25805 }
25806 }
25807
25808 pgd_t *pgd_alloc(struct mm_struct *mm)
25809 {
25810 pgd_t *pgd;
25811 - pmd_t *pmds[PREALLOCATED_PMDS];
25812 + pxd_t *pxds[PREALLOCATED_PXDS];
25813
25814 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25815
25816 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25817
25818 mm->pgd = pgd;
25819
25820 - if (preallocate_pmds(pmds) != 0)
25821 + if (preallocate_pxds(pxds) != 0)
25822 goto out_free_pgd;
25823
25824 if (paravirt_pgd_alloc(mm) != 0)
25825 - goto out_free_pmds;
25826 + goto out_free_pxds;
25827
25828 /*
25829 * Make sure that pre-populating the pmds is atomic with
25830 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25831 spin_lock(&pgd_lock);
25832
25833 pgd_ctor(mm, pgd);
25834 - pgd_prepopulate_pmd(mm, pgd, pmds);
25835 + pgd_prepopulate_pxd(mm, pgd, pxds);
25836
25837 spin_unlock(&pgd_lock);
25838
25839 return pgd;
25840
25841 -out_free_pmds:
25842 - free_pmds(pmds);
25843 +out_free_pxds:
25844 + free_pxds(pxds);
25845 out_free_pgd:
25846 free_page((unsigned long)pgd);
25847 out:
25848 @@ -295,7 +356,7 @@ out:
25849
25850 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25851 {
25852 - pgd_mop_up_pmds(mm, pgd);
25853 + pgd_mop_up_pxds(mm, pgd);
25854 pgd_dtor(pgd);
25855 paravirt_pgd_free(mm, pgd);
25856 free_page((unsigned long)pgd);
25857 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25858 index a69bcb8..19068ab 100644
25859 --- a/arch/x86/mm/pgtable_32.c
25860 +++ b/arch/x86/mm/pgtable_32.c
25861 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25862 return;
25863 }
25864 pte = pte_offset_kernel(pmd, vaddr);
25865 +
25866 + pax_open_kernel();
25867 if (pte_val(pteval))
25868 set_pte_at(&init_mm, vaddr, pte, pteval);
25869 else
25870 pte_clear(&init_mm, vaddr, pte);
25871 + pax_close_kernel();
25872
25873 /*
25874 * It's enough to flush this one mapping.
25875 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25876 index 410531d..0f16030 100644
25877 --- a/arch/x86/mm/setup_nx.c
25878 +++ b/arch/x86/mm/setup_nx.c
25879 @@ -5,8 +5,10 @@
25880 #include <asm/pgtable.h>
25881 #include <asm/proto.h>
25882
25883 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25884 static int disable_nx __cpuinitdata;
25885
25886 +#ifndef CONFIG_PAX_PAGEEXEC
25887 /*
25888 * noexec = on|off
25889 *
25890 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25891 return 0;
25892 }
25893 early_param("noexec", noexec_setup);
25894 +#endif
25895 +
25896 +#endif
25897
25898 void __cpuinit x86_configure_nx(void)
25899 {
25900 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25901 if (cpu_has_nx && !disable_nx)
25902 __supported_pte_mask |= _PAGE_NX;
25903 else
25904 +#endif
25905 __supported_pte_mask &= ~_PAGE_NX;
25906 }
25907
25908 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25909 index 613cd83..3a21f1c 100644
25910 --- a/arch/x86/mm/tlb.c
25911 +++ b/arch/x86/mm/tlb.c
25912 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25913 BUG();
25914 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25915 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25916 +
25917 +#ifndef CONFIG_PAX_PER_CPU_PGD
25918 load_cr3(swapper_pg_dir);
25919 +#endif
25920 +
25921 }
25922 }
25923 EXPORT_SYMBOL_GPL(leave_mm);
25924 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25925 index 877b9a1..a8ecf42 100644
25926 --- a/arch/x86/net/bpf_jit.S
25927 +++ b/arch/x86/net/bpf_jit.S
25928 @@ -9,6 +9,7 @@
25929 */
25930 #include <linux/linkage.h>
25931 #include <asm/dwarf2.h>
25932 +#include <asm/alternative-asm.h>
25933
25934 /*
25935 * Calling convention :
25936 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25937 jle bpf_slow_path_word
25938 mov (SKBDATA,%rsi),%eax
25939 bswap %eax /* ntohl() */
25940 + pax_force_retaddr
25941 ret
25942
25943 sk_load_half:
25944 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25945 jle bpf_slow_path_half
25946 movzwl (SKBDATA,%rsi),%eax
25947 rol $8,%ax # ntohs()
25948 + pax_force_retaddr
25949 ret
25950
25951 sk_load_byte:
25952 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25953 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25954 jle bpf_slow_path_byte
25955 movzbl (SKBDATA,%rsi),%eax
25956 + pax_force_retaddr
25957 ret
25958
25959 /**
25960 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25961 movzbl (SKBDATA,%rsi),%ebx
25962 and $15,%bl
25963 shl $2,%bl
25964 + pax_force_retaddr
25965 ret
25966
25967 /* rsi contains offset and can be scratched */
25968 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25969 js bpf_error
25970 mov -12(%rbp),%eax
25971 bswap %eax
25972 + pax_force_retaddr
25973 ret
25974
25975 bpf_slow_path_half:
25976 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25977 mov -12(%rbp),%ax
25978 rol $8,%ax
25979 movzwl %ax,%eax
25980 + pax_force_retaddr
25981 ret
25982
25983 bpf_slow_path_byte:
25984 bpf_slow_path_common(1)
25985 js bpf_error
25986 movzbl -12(%rbp),%eax
25987 + pax_force_retaddr
25988 ret
25989
25990 bpf_slow_path_byte_msh:
25991 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25992 and $15,%al
25993 shl $2,%al
25994 xchg %eax,%ebx
25995 + pax_force_retaddr
25996 ret
25997
25998 #define sk_negative_common(SIZE) \
25999 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26000 sk_negative_common(4)
26001 mov (%rax), %eax
26002 bswap %eax
26003 + pax_force_retaddr
26004 ret
26005
26006 bpf_slow_path_half_neg:
26007 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26008 mov (%rax),%ax
26009 rol $8,%ax
26010 movzwl %ax,%eax
26011 + pax_force_retaddr
26012 ret
26013
26014 bpf_slow_path_byte_neg:
26015 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26016 .globl sk_load_byte_negative_offset
26017 sk_negative_common(1)
26018 movzbl (%rax), %eax
26019 + pax_force_retaddr
26020 ret
26021
26022 bpf_slow_path_byte_msh_neg:
26023 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26024 and $15,%al
26025 shl $2,%al
26026 xchg %eax,%ebx
26027 + pax_force_retaddr
26028 ret
26029
26030 bpf_error:
26031 @@ -197,4 +210,5 @@ bpf_error:
26032 xor %eax,%eax
26033 mov -8(%rbp),%rbx
26034 leaveq
26035 + pax_force_retaddr
26036 ret
26037 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26038 index 33643a8..8e44870 100644
26039 --- a/arch/x86/net/bpf_jit_comp.c
26040 +++ b/arch/x86/net/bpf_jit_comp.c
26041 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26042 set_fs(old_fs);
26043 }
26044
26045 +struct bpf_jit_work {
26046 + struct work_struct work;
26047 + void *image;
26048 +};
26049 +
26050 #define CHOOSE_LOAD_FUNC(K, func) \
26051 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26052
26053 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26054 if (addrs == NULL)
26055 return;
26056
26057 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26058 + if (!fp->work)
26059 + goto out;
26060 +
26061 /* Before first pass, make a rough estimation of addrs[]
26062 * each bpf instruction is translated to less than 64 bytes
26063 */
26064 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26065 break;
26066 default:
26067 /* hmm, too complex filter, give up with jit compiler */
26068 - goto out;
26069 + goto error;
26070 }
26071 ilen = prog - temp;
26072 if (image) {
26073 if (unlikely(proglen + ilen > oldproglen)) {
26074 pr_err("bpb_jit_compile fatal error\n");
26075 - kfree(addrs);
26076 - module_free(NULL, image);
26077 - return;
26078 + module_free_exec(NULL, image);
26079 + goto error;
26080 }
26081 + pax_open_kernel();
26082 memcpy(image + proglen, temp, ilen);
26083 + pax_close_kernel();
26084 }
26085 proglen += ilen;
26086 addrs[i] = proglen;
26087 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26088 break;
26089 }
26090 if (proglen == oldproglen) {
26091 - image = module_alloc(max_t(unsigned int,
26092 - proglen,
26093 - sizeof(struct work_struct)));
26094 + image = module_alloc_exec(proglen);
26095 if (!image)
26096 - goto out;
26097 + goto error;
26098 }
26099 oldproglen = proglen;
26100 }
26101 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26102 bpf_flush_icache(image, image + proglen);
26103
26104 fp->bpf_func = (void *)image;
26105 - }
26106 + } else
26107 +error:
26108 + kfree(fp->work);
26109 +
26110 out:
26111 kfree(addrs);
26112 return;
26113 @@ -652,18 +663,20 @@ out:
26114
26115 static void jit_free_defer(struct work_struct *arg)
26116 {
26117 - module_free(NULL, arg);
26118 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26119 + kfree(arg);
26120 }
26121
26122 /* run from softirq, we must use a work_struct to call
26123 - * module_free() from process context
26124 + * module_free_exec() from process context
26125 */
26126 void bpf_jit_free(struct sk_filter *fp)
26127 {
26128 if (fp->bpf_func != sk_run_filter) {
26129 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26130 + struct work_struct *work = &fp->work->work;
26131
26132 INIT_WORK(work, jit_free_defer);
26133 + fp->work->image = fp->bpf_func;
26134 schedule_work(work);
26135 }
26136 }
26137 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26138 index d6aa6e8..266395a 100644
26139 --- a/arch/x86/oprofile/backtrace.c
26140 +++ b/arch/x86/oprofile/backtrace.c
26141 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26142 struct stack_frame_ia32 *fp;
26143 unsigned long bytes;
26144
26145 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26146 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26147 if (bytes != sizeof(bufhead))
26148 return NULL;
26149
26150 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26151 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26152
26153 oprofile_add_trace(bufhead[0].return_address);
26154
26155 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26156 struct stack_frame bufhead[2];
26157 unsigned long bytes;
26158
26159 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26160 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26161 if (bytes != sizeof(bufhead))
26162 return NULL;
26163
26164 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26165 {
26166 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26167
26168 - if (!user_mode_vm(regs)) {
26169 + if (!user_mode(regs)) {
26170 unsigned long stack = kernel_stack_pointer(regs);
26171 if (depth)
26172 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26173 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26174 index e14a2ff..3fd6b58 100644
26175 --- a/arch/x86/pci/mrst.c
26176 +++ b/arch/x86/pci/mrst.c
26177 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26178 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26179 pci_mmcfg_late_init();
26180 pcibios_enable_irq = mrst_pci_irq_enable;
26181 - pci_root_ops = pci_mrst_ops;
26182 + pax_open_kernel();
26183 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26184 + pax_close_kernel();
26185 pci_soc_mode = 1;
26186 /* Continue with standard init */
26187 return 1;
26188 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26189 index da8fe05..7ee6704 100644
26190 --- a/arch/x86/pci/pcbios.c
26191 +++ b/arch/x86/pci/pcbios.c
26192 @@ -79,50 +79,93 @@ union bios32 {
26193 static struct {
26194 unsigned long address;
26195 unsigned short segment;
26196 -} bios32_indirect = { 0, __KERNEL_CS };
26197 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26198
26199 /*
26200 * Returns the entry point for the given service, NULL on error
26201 */
26202
26203 -static unsigned long bios32_service(unsigned long service)
26204 +static unsigned long __devinit bios32_service(unsigned long service)
26205 {
26206 unsigned char return_code; /* %al */
26207 unsigned long address; /* %ebx */
26208 unsigned long length; /* %ecx */
26209 unsigned long entry; /* %edx */
26210 unsigned long flags;
26211 + struct desc_struct d, *gdt;
26212
26213 local_irq_save(flags);
26214 - __asm__("lcall *(%%edi); cld"
26215 +
26216 + gdt = get_cpu_gdt_table(smp_processor_id());
26217 +
26218 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26219 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26220 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26221 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26222 +
26223 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26224 : "=a" (return_code),
26225 "=b" (address),
26226 "=c" (length),
26227 "=d" (entry)
26228 : "0" (service),
26229 "1" (0),
26230 - "D" (&bios32_indirect));
26231 + "D" (&bios32_indirect),
26232 + "r"(__PCIBIOS_DS)
26233 + : "memory");
26234 +
26235 + pax_open_kernel();
26236 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26237 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26238 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26239 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26240 + pax_close_kernel();
26241 +
26242 local_irq_restore(flags);
26243
26244 switch (return_code) {
26245 - case 0:
26246 - return address + entry;
26247 - case 0x80: /* Not present */
26248 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26249 - return 0;
26250 - default: /* Shouldn't happen */
26251 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26252 - service, return_code);
26253 + case 0: {
26254 + int cpu;
26255 + unsigned char flags;
26256 +
26257 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26258 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26259 + printk(KERN_WARNING "bios32_service: not valid\n");
26260 return 0;
26261 + }
26262 + address = address + PAGE_OFFSET;
26263 + length += 16UL; /* some BIOSs underreport this... */
26264 + flags = 4;
26265 + if (length >= 64*1024*1024) {
26266 + length >>= PAGE_SHIFT;
26267 + flags |= 8;
26268 + }
26269 +
26270 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26271 + gdt = get_cpu_gdt_table(cpu);
26272 + pack_descriptor(&d, address, length, 0x9b, flags);
26273 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26274 + pack_descriptor(&d, address, length, 0x93, flags);
26275 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26276 + }
26277 + return entry;
26278 + }
26279 + case 0x80: /* Not present */
26280 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26281 + return 0;
26282 + default: /* Shouldn't happen */
26283 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26284 + service, return_code);
26285 + return 0;
26286 }
26287 }
26288
26289 static struct {
26290 unsigned long address;
26291 unsigned short segment;
26292 -} pci_indirect = { 0, __KERNEL_CS };
26293 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26294
26295 -static int pci_bios_present;
26296 +static int pci_bios_present __read_only;
26297
26298 static int __devinit check_pcibios(void)
26299 {
26300 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26301 unsigned long flags, pcibios_entry;
26302
26303 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26304 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26305 + pci_indirect.address = pcibios_entry;
26306
26307 local_irq_save(flags);
26308 - __asm__(
26309 - "lcall *(%%edi); cld\n\t"
26310 + __asm__("movw %w6, %%ds\n\t"
26311 + "lcall *%%ss:(%%edi); cld\n\t"
26312 + "push %%ss\n\t"
26313 + "pop %%ds\n\t"
26314 "jc 1f\n\t"
26315 "xor %%ah, %%ah\n"
26316 "1:"
26317 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26318 "=b" (ebx),
26319 "=c" (ecx)
26320 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26321 - "D" (&pci_indirect)
26322 + "D" (&pci_indirect),
26323 + "r" (__PCIBIOS_DS)
26324 : "memory");
26325 local_irq_restore(flags);
26326
26327 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26328
26329 switch (len) {
26330 case 1:
26331 - __asm__("lcall *(%%esi); cld\n\t"
26332 + __asm__("movw %w6, %%ds\n\t"
26333 + "lcall *%%ss:(%%esi); cld\n\t"
26334 + "push %%ss\n\t"
26335 + "pop %%ds\n\t"
26336 "jc 1f\n\t"
26337 "xor %%ah, %%ah\n"
26338 "1:"
26339 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26340 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26341 "b" (bx),
26342 "D" ((long)reg),
26343 - "S" (&pci_indirect));
26344 + "S" (&pci_indirect),
26345 + "r" (__PCIBIOS_DS));
26346 /*
26347 * Zero-extend the result beyond 8 bits, do not trust the
26348 * BIOS having done it:
26349 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26350 *value &= 0xff;
26351 break;
26352 case 2:
26353 - __asm__("lcall *(%%esi); cld\n\t"
26354 + __asm__("movw %w6, %%ds\n\t"
26355 + "lcall *%%ss:(%%esi); cld\n\t"
26356 + "push %%ss\n\t"
26357 + "pop %%ds\n\t"
26358 "jc 1f\n\t"
26359 "xor %%ah, %%ah\n"
26360 "1:"
26361 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26362 : "1" (PCIBIOS_READ_CONFIG_WORD),
26363 "b" (bx),
26364 "D" ((long)reg),
26365 - "S" (&pci_indirect));
26366 + "S" (&pci_indirect),
26367 + "r" (__PCIBIOS_DS));
26368 /*
26369 * Zero-extend the result beyond 16 bits, do not trust the
26370 * BIOS having done it:
26371 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26372 *value &= 0xffff;
26373 break;
26374 case 4:
26375 - __asm__("lcall *(%%esi); cld\n\t"
26376 + __asm__("movw %w6, %%ds\n\t"
26377 + "lcall *%%ss:(%%esi); cld\n\t"
26378 + "push %%ss\n\t"
26379 + "pop %%ds\n\t"
26380 "jc 1f\n\t"
26381 "xor %%ah, %%ah\n"
26382 "1:"
26383 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26384 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26385 "b" (bx),
26386 "D" ((long)reg),
26387 - "S" (&pci_indirect));
26388 + "S" (&pci_indirect),
26389 + "r" (__PCIBIOS_DS));
26390 break;
26391 }
26392
26393 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26394
26395 switch (len) {
26396 case 1:
26397 - __asm__("lcall *(%%esi); cld\n\t"
26398 + __asm__("movw %w6, %%ds\n\t"
26399 + "lcall *%%ss:(%%esi); cld\n\t"
26400 + "push %%ss\n\t"
26401 + "pop %%ds\n\t"
26402 "jc 1f\n\t"
26403 "xor %%ah, %%ah\n"
26404 "1:"
26405 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26406 "c" (value),
26407 "b" (bx),
26408 "D" ((long)reg),
26409 - "S" (&pci_indirect));
26410 + "S" (&pci_indirect),
26411 + "r" (__PCIBIOS_DS));
26412 break;
26413 case 2:
26414 - __asm__("lcall *(%%esi); cld\n\t"
26415 + __asm__("movw %w6, %%ds\n\t"
26416 + "lcall *%%ss:(%%esi); cld\n\t"
26417 + "push %%ss\n\t"
26418 + "pop %%ds\n\t"
26419 "jc 1f\n\t"
26420 "xor %%ah, %%ah\n"
26421 "1:"
26422 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26423 "c" (value),
26424 "b" (bx),
26425 "D" ((long)reg),
26426 - "S" (&pci_indirect));
26427 + "S" (&pci_indirect),
26428 + "r" (__PCIBIOS_DS));
26429 break;
26430 case 4:
26431 - __asm__("lcall *(%%esi); cld\n\t"
26432 + __asm__("movw %w6, %%ds\n\t"
26433 + "lcall *%%ss:(%%esi); cld\n\t"
26434 + "push %%ss\n\t"
26435 + "pop %%ds\n\t"
26436 "jc 1f\n\t"
26437 "xor %%ah, %%ah\n"
26438 "1:"
26439 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26440 "c" (value),
26441 "b" (bx),
26442 "D" ((long)reg),
26443 - "S" (&pci_indirect));
26444 + "S" (&pci_indirect),
26445 + "r" (__PCIBIOS_DS));
26446 break;
26447 }
26448
26449 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26450
26451 DBG("PCI: Fetching IRQ routing table... ");
26452 __asm__("push %%es\n\t"
26453 + "movw %w8, %%ds\n\t"
26454 "push %%ds\n\t"
26455 "pop %%es\n\t"
26456 - "lcall *(%%esi); cld\n\t"
26457 + "lcall *%%ss:(%%esi); cld\n\t"
26458 "pop %%es\n\t"
26459 + "push %%ss\n\t"
26460 + "pop %%ds\n"
26461 "jc 1f\n\t"
26462 "xor %%ah, %%ah\n"
26463 "1:"
26464 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26465 "1" (0),
26466 "D" ((long) &opt),
26467 "S" (&pci_indirect),
26468 - "m" (opt)
26469 + "m" (opt),
26470 + "r" (__PCIBIOS_DS)
26471 : "memory");
26472 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26473 if (ret & 0xff00)
26474 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26475 {
26476 int ret;
26477
26478 - __asm__("lcall *(%%esi); cld\n\t"
26479 + __asm__("movw %w5, %%ds\n\t"
26480 + "lcall *%%ss:(%%esi); cld\n\t"
26481 + "push %%ss\n\t"
26482 + "pop %%ds\n"
26483 "jc 1f\n\t"
26484 "xor %%ah, %%ah\n"
26485 "1:"
26486 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26487 : "0" (PCIBIOS_SET_PCI_HW_INT),
26488 "b" ((dev->bus->number << 8) | dev->devfn),
26489 "c" ((irq << 8) | (pin + 10)),
26490 - "S" (&pci_indirect));
26491 + "S" (&pci_indirect),
26492 + "r" (__PCIBIOS_DS));
26493 return !(ret & 0xff00);
26494 }
26495 EXPORT_SYMBOL(pcibios_set_irq_routing);
26496 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26497 index 40e4469..1ab536e 100644
26498 --- a/arch/x86/platform/efi/efi_32.c
26499 +++ b/arch/x86/platform/efi/efi_32.c
26500 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26501 {
26502 struct desc_ptr gdt_descr;
26503
26504 +#ifdef CONFIG_PAX_KERNEXEC
26505 + struct desc_struct d;
26506 +#endif
26507 +
26508 local_irq_save(efi_rt_eflags);
26509
26510 load_cr3(initial_page_table);
26511 __flush_tlb_all();
26512
26513 +#ifdef CONFIG_PAX_KERNEXEC
26514 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26515 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26516 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26517 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26518 +#endif
26519 +
26520 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26521 gdt_descr.size = GDT_SIZE - 1;
26522 load_gdt(&gdt_descr);
26523 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26524 {
26525 struct desc_ptr gdt_descr;
26526
26527 +#ifdef CONFIG_PAX_KERNEXEC
26528 + struct desc_struct d;
26529 +
26530 + memset(&d, 0, sizeof d);
26531 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26532 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26533 +#endif
26534 +
26535 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26536 gdt_descr.size = GDT_SIZE - 1;
26537 load_gdt(&gdt_descr);
26538 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26539 index fbe66e6..eae5e38 100644
26540 --- a/arch/x86/platform/efi/efi_stub_32.S
26541 +++ b/arch/x86/platform/efi/efi_stub_32.S
26542 @@ -6,7 +6,9 @@
26543 */
26544
26545 #include <linux/linkage.h>
26546 +#include <linux/init.h>
26547 #include <asm/page_types.h>
26548 +#include <asm/segment.h>
26549
26550 /*
26551 * efi_call_phys(void *, ...) is a function with variable parameters.
26552 @@ -20,7 +22,7 @@
26553 * service functions will comply with gcc calling convention, too.
26554 */
26555
26556 -.text
26557 +__INIT
26558 ENTRY(efi_call_phys)
26559 /*
26560 * 0. The function can only be called in Linux kernel. So CS has been
26561 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26562 * The mapping of lower virtual memory has been created in prelog and
26563 * epilog.
26564 */
26565 - movl $1f, %edx
26566 - subl $__PAGE_OFFSET, %edx
26567 - jmp *%edx
26568 +#ifdef CONFIG_PAX_KERNEXEC
26569 + movl $(__KERNEXEC_EFI_DS), %edx
26570 + mov %edx, %ds
26571 + mov %edx, %es
26572 + mov %edx, %ss
26573 + addl $2f,(1f)
26574 + ljmp *(1f)
26575 +
26576 +__INITDATA
26577 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26578 +.previous
26579 +
26580 +2:
26581 + subl $2b,(1b)
26582 +#else
26583 + jmp 1f-__PAGE_OFFSET
26584 1:
26585 +#endif
26586
26587 /*
26588 * 2. Now on the top of stack is the return
26589 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26590 * parameter 2, ..., param n. To make things easy, we save the return
26591 * address of efi_call_phys in a global variable.
26592 */
26593 - popl %edx
26594 - movl %edx, saved_return_addr
26595 - /* get the function pointer into ECX*/
26596 - popl %ecx
26597 - movl %ecx, efi_rt_function_ptr
26598 - movl $2f, %edx
26599 - subl $__PAGE_OFFSET, %edx
26600 - pushl %edx
26601 + popl (saved_return_addr)
26602 + popl (efi_rt_function_ptr)
26603
26604 /*
26605 * 3. Clear PG bit in %CR0.
26606 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26607 /*
26608 * 5. Call the physical function.
26609 */
26610 - jmp *%ecx
26611 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26612
26613 -2:
26614 /*
26615 * 6. After EFI runtime service returns, control will return to
26616 * following instruction. We'd better readjust stack pointer first.
26617 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26618 movl %cr0, %edx
26619 orl $0x80000000, %edx
26620 movl %edx, %cr0
26621 - jmp 1f
26622 -1:
26623 +
26624 /*
26625 * 8. Now restore the virtual mode from flat mode by
26626 * adding EIP with PAGE_OFFSET.
26627 */
26628 - movl $1f, %edx
26629 - jmp *%edx
26630 +#ifdef CONFIG_PAX_KERNEXEC
26631 + movl $(__KERNEL_DS), %edx
26632 + mov %edx, %ds
26633 + mov %edx, %es
26634 + mov %edx, %ss
26635 + ljmp $(__KERNEL_CS),$1f
26636 +#else
26637 + jmp 1f+__PAGE_OFFSET
26638 +#endif
26639 1:
26640
26641 /*
26642 * 9. Balance the stack. And because EAX contain the return value,
26643 * we'd better not clobber it.
26644 */
26645 - leal efi_rt_function_ptr, %edx
26646 - movl (%edx), %ecx
26647 - pushl %ecx
26648 + pushl (efi_rt_function_ptr)
26649
26650 /*
26651 - * 10. Push the saved return address onto the stack and return.
26652 + * 10. Return to the saved return address.
26653 */
26654 - leal saved_return_addr, %edx
26655 - movl (%edx), %ecx
26656 - pushl %ecx
26657 - ret
26658 + jmpl *(saved_return_addr)
26659 ENDPROC(efi_call_phys)
26660 .previous
26661
26662 -.data
26663 +__INITDATA
26664 saved_return_addr:
26665 .long 0
26666 efi_rt_function_ptr:
26667 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26668 index 4c07cca..2c8427d 100644
26669 --- a/arch/x86/platform/efi/efi_stub_64.S
26670 +++ b/arch/x86/platform/efi/efi_stub_64.S
26671 @@ -7,6 +7,7 @@
26672 */
26673
26674 #include <linux/linkage.h>
26675 +#include <asm/alternative-asm.h>
26676
26677 #define SAVE_XMM \
26678 mov %rsp, %rax; \
26679 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26680 call *%rdi
26681 addq $32, %rsp
26682 RESTORE_XMM
26683 + pax_force_retaddr 0, 1
26684 ret
26685 ENDPROC(efi_call0)
26686
26687 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26688 call *%rdi
26689 addq $32, %rsp
26690 RESTORE_XMM
26691 + pax_force_retaddr 0, 1
26692 ret
26693 ENDPROC(efi_call1)
26694
26695 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26696 call *%rdi
26697 addq $32, %rsp
26698 RESTORE_XMM
26699 + pax_force_retaddr 0, 1
26700 ret
26701 ENDPROC(efi_call2)
26702
26703 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26704 call *%rdi
26705 addq $32, %rsp
26706 RESTORE_XMM
26707 + pax_force_retaddr 0, 1
26708 ret
26709 ENDPROC(efi_call3)
26710
26711 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26712 call *%rdi
26713 addq $32, %rsp
26714 RESTORE_XMM
26715 + pax_force_retaddr 0, 1
26716 ret
26717 ENDPROC(efi_call4)
26718
26719 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26720 call *%rdi
26721 addq $48, %rsp
26722 RESTORE_XMM
26723 + pax_force_retaddr 0, 1
26724 ret
26725 ENDPROC(efi_call5)
26726
26727 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26728 call *%rdi
26729 addq $48, %rsp
26730 RESTORE_XMM
26731 + pax_force_retaddr 0, 1
26732 ret
26733 ENDPROC(efi_call6)
26734 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26735 index fd41a92..9c33628 100644
26736 --- a/arch/x86/platform/mrst/mrst.c
26737 +++ b/arch/x86/platform/mrst/mrst.c
26738 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26739 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26740 int sfi_mrtc_num;
26741
26742 -static void mrst_power_off(void)
26743 +static __noreturn void mrst_power_off(void)
26744 {
26745 + BUG();
26746 }
26747
26748 -static void mrst_reboot(void)
26749 +static __noreturn void mrst_reboot(void)
26750 {
26751 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26752 + BUG();
26753 }
26754
26755 /* parse all the mtimer info to a static mtimer array */
26756 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26757 index 218cdb1..fd55c08 100644
26758 --- a/arch/x86/power/cpu.c
26759 +++ b/arch/x86/power/cpu.c
26760 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26761 static void fix_processor_context(void)
26762 {
26763 int cpu = smp_processor_id();
26764 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26765 + struct tss_struct *t = init_tss + cpu;
26766
26767 set_tss_desc(cpu, t); /*
26768 * This just modifies memory; should not be
26769 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26770 */
26771
26772 #ifdef CONFIG_X86_64
26773 + pax_open_kernel();
26774 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26775 + pax_close_kernel();
26776
26777 syscall_init(); /* This sets MSR_*STAR and related */
26778 #endif
26779 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26780 index cbca565..bae7133 100644
26781 --- a/arch/x86/realmode/init.c
26782 +++ b/arch/x86/realmode/init.c
26783 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26784 __va(real_mode_header->trampoline_header);
26785
26786 #ifdef CONFIG_X86_32
26787 - trampoline_header->start = __pa(startup_32_smp);
26788 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26789 +
26790 +#ifdef CONFIG_PAX_KERNEXEC
26791 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26792 +#endif
26793 +
26794 + trampoline_header->boot_cs = __BOOT_CS;
26795 trampoline_header->gdt_limit = __BOOT_DS + 7;
26796 trampoline_header->gdt_base = __pa(boot_gdt);
26797 #else
26798 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26799 index 8869287..d577672 100644
26800 --- a/arch/x86/realmode/rm/Makefile
26801 +++ b/arch/x86/realmode/rm/Makefile
26802 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26803 $(call cc-option, -fno-unit-at-a-time)) \
26804 $(call cc-option, -fno-stack-protector) \
26805 $(call cc-option, -mpreferred-stack-boundary=2)
26806 +ifdef CONSTIFY_PLUGIN
26807 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26808 +endif
26809 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26810 GCOV_PROFILE := n
26811 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26812 index a28221d..93c40f1 100644
26813 --- a/arch/x86/realmode/rm/header.S
26814 +++ b/arch/x86/realmode/rm/header.S
26815 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26816 #endif
26817 /* APM/BIOS reboot */
26818 .long pa_machine_real_restart_asm
26819 -#ifdef CONFIG_X86_64
26820 +#ifdef CONFIG_X86_32
26821 + .long __KERNEL_CS
26822 +#else
26823 .long __KERNEL32_CS
26824 #endif
26825 END(real_mode_header)
26826 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26827 index c1b2791..f9e31c7 100644
26828 --- a/arch/x86/realmode/rm/trampoline_32.S
26829 +++ b/arch/x86/realmode/rm/trampoline_32.S
26830 @@ -25,6 +25,12 @@
26831 #include <asm/page_types.h>
26832 #include "realmode.h"
26833
26834 +#ifdef CONFIG_PAX_KERNEXEC
26835 +#define ta(X) (X)
26836 +#else
26837 +#define ta(X) (pa_ ## X)
26838 +#endif
26839 +
26840 .text
26841 .code16
26842
26843 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26844
26845 cli # We should be safe anyway
26846
26847 - movl tr_start, %eax # where we need to go
26848 -
26849 movl $0xA5A5A5A5, trampoline_status
26850 # write marker for master knows we're running
26851
26852 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26853 movw $1, %dx # protected mode (PE) bit
26854 lmsw %dx # into protected mode
26855
26856 - ljmpl $__BOOT_CS, $pa_startup_32
26857 + ljmpl *(trampoline_header)
26858
26859 .section ".text32","ax"
26860 .code32
26861 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26862 .balign 8
26863 GLOBAL(trampoline_header)
26864 tr_start: .space 4
26865 - tr_gdt_pad: .space 2
26866 + tr_boot_cs: .space 2
26867 tr_gdt: .space 6
26868 END(trampoline_header)
26869
26870 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26871 index bb360dc..3e5945f 100644
26872 --- a/arch/x86/realmode/rm/trampoline_64.S
26873 +++ b/arch/x86/realmode/rm/trampoline_64.S
26874 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26875 wrmsr
26876
26877 # Enable paging and in turn activate Long Mode
26878 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26879 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26880 movl %eax, %cr0
26881
26882 /*
26883 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26884 index 5a1847d..deccb30 100644
26885 --- a/arch/x86/tools/relocs.c
26886 +++ b/arch/x86/tools/relocs.c
26887 @@ -12,10 +12,13 @@
26888 #include <regex.h>
26889 #include <tools/le_byteshift.h>
26890
26891 +#include "../../../include/generated/autoconf.h"
26892 +
26893 static void die(char *fmt, ...);
26894
26895 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26896 static Elf32_Ehdr ehdr;
26897 +static Elf32_Phdr *phdr;
26898 static unsigned long reloc_count, reloc_idx;
26899 static unsigned long *relocs;
26900 static unsigned long reloc16_count, reloc16_idx;
26901 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26902 }
26903 }
26904
26905 +static void read_phdrs(FILE *fp)
26906 +{
26907 + unsigned int i;
26908 +
26909 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26910 + if (!phdr) {
26911 + die("Unable to allocate %d program headers\n",
26912 + ehdr.e_phnum);
26913 + }
26914 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26915 + die("Seek to %d failed: %s\n",
26916 + ehdr.e_phoff, strerror(errno));
26917 + }
26918 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26919 + die("Cannot read ELF program headers: %s\n",
26920 + strerror(errno));
26921 + }
26922 + for(i = 0; i < ehdr.e_phnum; i++) {
26923 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26924 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26925 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26926 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26927 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26928 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26929 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26930 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26931 + }
26932 +
26933 +}
26934 +
26935 static void read_shdrs(FILE *fp)
26936 {
26937 - int i;
26938 + unsigned int i;
26939 Elf32_Shdr shdr;
26940
26941 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26942 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26943
26944 static void read_strtabs(FILE *fp)
26945 {
26946 - int i;
26947 + unsigned int i;
26948 for (i = 0; i < ehdr.e_shnum; i++) {
26949 struct section *sec = &secs[i];
26950 if (sec->shdr.sh_type != SHT_STRTAB) {
26951 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26952
26953 static void read_symtabs(FILE *fp)
26954 {
26955 - int i,j;
26956 + unsigned int i,j;
26957 for (i = 0; i < ehdr.e_shnum; i++) {
26958 struct section *sec = &secs[i];
26959 if (sec->shdr.sh_type != SHT_SYMTAB) {
26960 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26961 }
26962
26963
26964 -static void read_relocs(FILE *fp)
26965 +static void read_relocs(FILE *fp, int use_real_mode)
26966 {
26967 - int i,j;
26968 + unsigned int i,j;
26969 + uint32_t base;
26970 +
26971 for (i = 0; i < ehdr.e_shnum; i++) {
26972 struct section *sec = &secs[i];
26973 if (sec->shdr.sh_type != SHT_REL) {
26974 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26975 die("Cannot read symbol table: %s\n",
26976 strerror(errno));
26977 }
26978 + base = 0;
26979 +
26980 +#ifdef CONFIG_X86_32
26981 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26982 + if (phdr[j].p_type != PT_LOAD )
26983 + continue;
26984 + 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)
26985 + continue;
26986 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26987 + break;
26988 + }
26989 +#endif
26990 +
26991 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26992 Elf32_Rel *rel = &sec->reltab[j];
26993 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26994 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26995 rel->r_info = elf32_to_cpu(rel->r_info);
26996 }
26997 }
26998 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26999
27000 static void print_absolute_symbols(void)
27001 {
27002 - int i;
27003 + unsigned int i;
27004 printf("Absolute symbols\n");
27005 printf(" Num: Value Size Type Bind Visibility Name\n");
27006 for (i = 0; i < ehdr.e_shnum; i++) {
27007 struct section *sec = &secs[i];
27008 char *sym_strtab;
27009 - int j;
27010 + unsigned int j;
27011
27012 if (sec->shdr.sh_type != SHT_SYMTAB) {
27013 continue;
27014 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27015
27016 static void print_absolute_relocs(void)
27017 {
27018 - int i, printed = 0;
27019 + unsigned int i, printed = 0;
27020
27021 for (i = 0; i < ehdr.e_shnum; i++) {
27022 struct section *sec = &secs[i];
27023 struct section *sec_applies, *sec_symtab;
27024 char *sym_strtab;
27025 Elf32_Sym *sh_symtab;
27026 - int j;
27027 + unsigned int j;
27028 if (sec->shdr.sh_type != SHT_REL) {
27029 continue;
27030 }
27031 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27032 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27033 int use_real_mode)
27034 {
27035 - int i;
27036 + unsigned int i;
27037 /* Walk through the relocations */
27038 for (i = 0; i < ehdr.e_shnum; i++) {
27039 char *sym_strtab;
27040 Elf32_Sym *sh_symtab;
27041 struct section *sec_applies, *sec_symtab;
27042 - int j;
27043 + unsigned int j;
27044 struct section *sec = &secs[i];
27045
27046 if (sec->shdr.sh_type != SHT_REL) {
27047 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27048 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27049 r_type = ELF32_R_TYPE(rel->r_info);
27050
27051 + if (!use_real_mode) {
27052 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27053 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27054 + continue;
27055 +
27056 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27057 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27058 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27059 + continue;
27060 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27061 + continue;
27062 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27063 + continue;
27064 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27065 + continue;
27066 +#endif
27067 + }
27068 +
27069 shn_abs = sym->st_shndx == SHN_ABS;
27070
27071 switch (r_type) {
27072 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27073
27074 static void emit_relocs(int as_text, int use_real_mode)
27075 {
27076 - int i;
27077 + unsigned int i;
27078 /* Count how many relocations I have and allocate space for them. */
27079 reloc_count = 0;
27080 walk_relocs(count_reloc, use_real_mode);
27081 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27082 fname, strerror(errno));
27083 }
27084 read_ehdr(fp);
27085 + read_phdrs(fp);
27086 read_shdrs(fp);
27087 read_strtabs(fp);
27088 read_symtabs(fp);
27089 - read_relocs(fp);
27090 + read_relocs(fp, use_real_mode);
27091 if (show_absolute_syms) {
27092 print_absolute_symbols();
27093 return 0;
27094 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27095 index fd14be1..e3c79c0 100644
27096 --- a/arch/x86/vdso/Makefile
27097 +++ b/arch/x86/vdso/Makefile
27098 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27099 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27100 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27101
27102 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27103 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27104 GCOV_PROFILE := n
27105
27106 #
27107 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27108 index 0faad64..39ef157 100644
27109 --- a/arch/x86/vdso/vdso32-setup.c
27110 +++ b/arch/x86/vdso/vdso32-setup.c
27111 @@ -25,6 +25,7 @@
27112 #include <asm/tlbflush.h>
27113 #include <asm/vdso.h>
27114 #include <asm/proto.h>
27115 +#include <asm/mman.h>
27116
27117 enum {
27118 VDSO_DISABLED = 0,
27119 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27120 void enable_sep_cpu(void)
27121 {
27122 int cpu = get_cpu();
27123 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27124 + struct tss_struct *tss = init_tss + cpu;
27125
27126 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27127 put_cpu();
27128 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27129 gate_vma.vm_start = FIXADDR_USER_START;
27130 gate_vma.vm_end = FIXADDR_USER_END;
27131 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27132 - gate_vma.vm_page_prot = __P101;
27133 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27134
27135 return 0;
27136 }
27137 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27138 if (compat)
27139 addr = VDSO_HIGH_BASE;
27140 else {
27141 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27142 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27143 if (IS_ERR_VALUE(addr)) {
27144 ret = addr;
27145 goto up_fail;
27146 }
27147 }
27148
27149 - current->mm->context.vdso = (void *)addr;
27150 + current->mm->context.vdso = addr;
27151
27152 if (compat_uses_vma || !compat) {
27153 /*
27154 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27155 }
27156
27157 current_thread_info()->sysenter_return =
27158 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27159 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27160
27161 up_fail:
27162 if (ret)
27163 - current->mm->context.vdso = NULL;
27164 + current->mm->context.vdso = 0;
27165
27166 up_write(&mm->mmap_sem);
27167
27168 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27169
27170 const char *arch_vma_name(struct vm_area_struct *vma)
27171 {
27172 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27173 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27174 return "[vdso]";
27175 +
27176 +#ifdef CONFIG_PAX_SEGMEXEC
27177 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27178 + return "[vdso]";
27179 +#endif
27180 +
27181 return NULL;
27182 }
27183
27184 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27185 * Check to see if the corresponding task was created in compat vdso
27186 * mode.
27187 */
27188 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27189 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27190 return &gate_vma;
27191 return NULL;
27192 }
27193 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27194 index 00aaf04..4a26505 100644
27195 --- a/arch/x86/vdso/vma.c
27196 +++ b/arch/x86/vdso/vma.c
27197 @@ -16,8 +16,6 @@
27198 #include <asm/vdso.h>
27199 #include <asm/page.h>
27200
27201 -unsigned int __read_mostly vdso_enabled = 1;
27202 -
27203 extern char vdso_start[], vdso_end[];
27204 extern unsigned short vdso_sync_cpuid;
27205
27206 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27207 * unaligned here as a result of stack start randomization.
27208 */
27209 addr = PAGE_ALIGN(addr);
27210 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27211
27212 return addr;
27213 }
27214 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27215 unsigned size)
27216 {
27217 struct mm_struct *mm = current->mm;
27218 - unsigned long addr;
27219 + unsigned long addr = 0;
27220 int ret;
27221
27222 - if (!vdso_enabled)
27223 - return 0;
27224 -
27225 down_write(&mm->mmap_sem);
27226 +
27227 +#ifdef CONFIG_PAX_RANDMMAP
27228 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27229 +#endif
27230 +
27231 addr = vdso_addr(mm->start_stack, size);
27232 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27233 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27234 if (IS_ERR_VALUE(addr)) {
27235 ret = addr;
27236 goto up_fail;
27237 }
27238
27239 - current->mm->context.vdso = (void *)addr;
27240 + mm->context.vdso = addr;
27241
27242 ret = install_special_mapping(mm, addr, size,
27243 VM_READ|VM_EXEC|
27244 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27245 pages);
27246 - if (ret) {
27247 - current->mm->context.vdso = NULL;
27248 - goto up_fail;
27249 - }
27250 + if (ret)
27251 + mm->context.vdso = 0;
27252
27253 up_fail:
27254 up_write(&mm->mmap_sem);
27255 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27256 vdsox32_size);
27257 }
27258 #endif
27259 -
27260 -static __init int vdso_setup(char *s)
27261 -{
27262 - vdso_enabled = simple_strtoul(s, NULL, 0);
27263 - return 0;
27264 -}
27265 -__setup("vdso=", vdso_setup);
27266 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27267 index c1461de..355f120 100644
27268 --- a/arch/x86/xen/enlighten.c
27269 +++ b/arch/x86/xen/enlighten.c
27270 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27271
27272 struct shared_info xen_dummy_shared_info;
27273
27274 -void *xen_initial_gdt;
27275 -
27276 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27277 __read_mostly int xen_have_vector_callback;
27278 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27279 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27280
27281 static void set_xen_basic_apic_ops(void)
27282 {
27283 - apic->read = xen_apic_read;
27284 - apic->write = xen_apic_write;
27285 - apic->icr_read = xen_apic_icr_read;
27286 - apic->icr_write = xen_apic_icr_write;
27287 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27288 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27289 - apic->set_apic_id = xen_set_apic_id;
27290 - apic->get_apic_id = xen_get_apic_id;
27291 + *(void **)&apic->read = xen_apic_read;
27292 + *(void **)&apic->write = xen_apic_write;
27293 + *(void **)&apic->icr_read = xen_apic_icr_read;
27294 + *(void **)&apic->icr_write = xen_apic_icr_write;
27295 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27296 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27297 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27298 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27299
27300 #ifdef CONFIG_SMP
27301 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27302 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27303 - apic->send_IPI_mask = xen_send_IPI_mask;
27304 - apic->send_IPI_all = xen_send_IPI_all;
27305 - apic->send_IPI_self = xen_send_IPI_self;
27306 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27307 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27308 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27309 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27310 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27311 #endif
27312 }
27313
27314 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27315 #endif
27316 };
27317
27318 -static void xen_reboot(int reason)
27319 +static __noreturn void xen_reboot(int reason)
27320 {
27321 struct sched_shutdown r = { .reason = reason };
27322
27323 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27324 - BUG();
27325 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27326 + BUG();
27327 }
27328
27329 -static void xen_restart(char *msg)
27330 +static __noreturn void xen_restart(char *msg)
27331 {
27332 xen_reboot(SHUTDOWN_reboot);
27333 }
27334
27335 -static void xen_emergency_restart(void)
27336 +static __noreturn void xen_emergency_restart(void)
27337 {
27338 xen_reboot(SHUTDOWN_reboot);
27339 }
27340
27341 -static void xen_machine_halt(void)
27342 +static __noreturn void xen_machine_halt(void)
27343 {
27344 xen_reboot(SHUTDOWN_poweroff);
27345 }
27346
27347 -static void xen_machine_power_off(void)
27348 +static __noreturn void xen_machine_power_off(void)
27349 {
27350 if (pm_power_off)
27351 pm_power_off();
27352 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27353 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27354
27355 /* Work out if we support NX */
27356 - x86_configure_nx();
27357 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27358 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27359 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27360 + unsigned l, h;
27361 +
27362 + __supported_pte_mask |= _PAGE_NX;
27363 + rdmsr(MSR_EFER, l, h);
27364 + l |= EFER_NX;
27365 + wrmsr(MSR_EFER, l, h);
27366 + }
27367 +#endif
27368
27369 xen_setup_features();
27370
27371 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27372
27373 machine_ops = xen_machine_ops;
27374
27375 - /*
27376 - * The only reliable way to retain the initial address of the
27377 - * percpu gdt_page is to remember it here, so we can go and
27378 - * mark it RW later, when the initial percpu area is freed.
27379 - */
27380 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27381 -
27382 xen_smp_init();
27383
27384 #ifdef CONFIG_ACPI_NUMA
27385 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27386 index 5141d80..6c9fb41 100644
27387 --- a/arch/x86/xen/mmu.c
27388 +++ b/arch/x86/xen/mmu.c
27389 @@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27390 convert_pfn_mfn(init_level4_pgt);
27391 convert_pfn_mfn(level3_ident_pgt);
27392 convert_pfn_mfn(level3_kernel_pgt);
27393 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27394 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27395 + convert_pfn_mfn(level3_vmemmap_pgt);
27396
27397 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27398 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27399 @@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27400 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27401 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27402 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27403 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27404 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27405 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27406 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27407 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27408 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27409 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27410
27411 @@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27412 pv_mmu_ops.set_pud = xen_set_pud;
27413 #if PAGETABLE_LEVELS == 4
27414 pv_mmu_ops.set_pgd = xen_set_pgd;
27415 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27416 #endif
27417
27418 /* This will work as long as patching hasn't happened yet
27419 @@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27420 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27421 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27422 .set_pgd = xen_set_pgd_hyper,
27423 + .set_pgd_batched = xen_set_pgd_hyper,
27424
27425 .alloc_pud = xen_alloc_pmd_init,
27426 .release_pud = xen_release_pmd_init,
27427 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27428 index f58dca7..ad21f52 100644
27429 --- a/arch/x86/xen/smp.c
27430 +++ b/arch/x86/xen/smp.c
27431 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27432 {
27433 BUG_ON(smp_processor_id() != 0);
27434 native_smp_prepare_boot_cpu();
27435 -
27436 - /* We've switched to the "real" per-cpu gdt, so make sure the
27437 - old memory can be recycled */
27438 - make_lowmem_page_readwrite(xen_initial_gdt);
27439 -
27440 xen_filter_cpu_maps();
27441 xen_setup_vcpu_info_placement();
27442 }
27443 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27444 gdt = get_cpu_gdt_table(cpu);
27445
27446 ctxt->flags = VGCF_IN_KERNEL;
27447 - ctxt->user_regs.ds = __USER_DS;
27448 - ctxt->user_regs.es = __USER_DS;
27449 + ctxt->user_regs.ds = __KERNEL_DS;
27450 + ctxt->user_regs.es = __KERNEL_DS;
27451 ctxt->user_regs.ss = __KERNEL_DS;
27452 #ifdef CONFIG_X86_32
27453 ctxt->user_regs.fs = __KERNEL_PERCPU;
27454 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27455 + savesegment(gs, ctxt->user_regs.gs);
27456 #else
27457 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27458 #endif
27459 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27460 int rc;
27461
27462 per_cpu(current_task, cpu) = idle;
27463 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27464 #ifdef CONFIG_X86_32
27465 irq_ctx_init(cpu);
27466 #else
27467 clear_tsk_thread_flag(idle, TIF_FORK);
27468 - per_cpu(kernel_stack, cpu) =
27469 - (unsigned long)task_stack_page(idle) -
27470 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27471 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27472 #endif
27473 xen_setup_runstate_info(cpu);
27474 xen_setup_timer(cpu);
27475 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27476 index f9643fc..602e8af 100644
27477 --- a/arch/x86/xen/xen-asm_32.S
27478 +++ b/arch/x86/xen/xen-asm_32.S
27479 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27480 ESP_OFFSET=4 # bytes pushed onto stack
27481
27482 /*
27483 - * Store vcpu_info pointer for easy access. Do it this way to
27484 - * avoid having to reload %fs
27485 + * Store vcpu_info pointer for easy access.
27486 */
27487 #ifdef CONFIG_SMP
27488 - GET_THREAD_INFO(%eax)
27489 - movl TI_cpu(%eax), %eax
27490 - movl __per_cpu_offset(,%eax,4), %eax
27491 - mov xen_vcpu(%eax), %eax
27492 + push %fs
27493 + mov $(__KERNEL_PERCPU), %eax
27494 + mov %eax, %fs
27495 + mov PER_CPU_VAR(xen_vcpu), %eax
27496 + pop %fs
27497 #else
27498 movl xen_vcpu, %eax
27499 #endif
27500 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27501 index aaa7291..3f77960 100644
27502 --- a/arch/x86/xen/xen-head.S
27503 +++ b/arch/x86/xen/xen-head.S
27504 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27505 #ifdef CONFIG_X86_32
27506 mov %esi,xen_start_info
27507 mov $init_thread_union+THREAD_SIZE,%esp
27508 +#ifdef CONFIG_SMP
27509 + movl $cpu_gdt_table,%edi
27510 + movl $__per_cpu_load,%eax
27511 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27512 + rorl $16,%eax
27513 + movb %al,__KERNEL_PERCPU + 4(%edi)
27514 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27515 + movl $__per_cpu_end - 1,%eax
27516 + subl $__per_cpu_start,%eax
27517 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27518 +#endif
27519 #else
27520 mov %rsi,xen_start_info
27521 mov $init_thread_union+THREAD_SIZE,%rsp
27522 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27523 index 202d4c1..99b072a 100644
27524 --- a/arch/x86/xen/xen-ops.h
27525 +++ b/arch/x86/xen/xen-ops.h
27526 @@ -10,8 +10,6 @@
27527 extern const char xen_hypervisor_callback[];
27528 extern const char xen_failsafe_callback[];
27529
27530 -extern void *xen_initial_gdt;
27531 -
27532 struct trap_info;
27533 void xen_copy_trap_info(struct trap_info *traps);
27534
27535 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27536 index 525bd3d..ef888b1 100644
27537 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27538 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27539 @@ -119,9 +119,9 @@
27540 ----------------------------------------------------------------------*/
27541
27542 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27543 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27544 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27545 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27546 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27547
27548 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27549 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27550 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27551 index 2f33760..835e50a 100644
27552 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27553 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27554 @@ -11,6 +11,7 @@
27555 #ifndef _XTENSA_CORE_H
27556 #define _XTENSA_CORE_H
27557
27558 +#include <linux/const.h>
27559
27560 /****************************************************************************
27561 Parameters Useful for Any Code, USER or PRIVILEGED
27562 @@ -112,9 +113,9 @@
27563 ----------------------------------------------------------------------*/
27564
27565 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27566 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27567 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27568 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27569 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27570
27571 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27572 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27573 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27574 index af00795..2bb8105 100644
27575 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27576 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27577 @@ -11,6 +11,7 @@
27578 #ifndef _XTENSA_CORE_CONFIGURATION_H
27579 #define _XTENSA_CORE_CONFIGURATION_H
27580
27581 +#include <linux/const.h>
27582
27583 /****************************************************************************
27584 Parameters Useful for Any Code, USER or PRIVILEGED
27585 @@ -118,9 +119,9 @@
27586 ----------------------------------------------------------------------*/
27587
27588 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27589 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27590 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27591 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27592 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27593
27594 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27595 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27596 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27597 index 58916af..9cb880b 100644
27598 --- a/block/blk-iopoll.c
27599 +++ b/block/blk-iopoll.c
27600 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27601 }
27602 EXPORT_SYMBOL(blk_iopoll_complete);
27603
27604 -static void blk_iopoll_softirq(struct softirq_action *h)
27605 +static void blk_iopoll_softirq(void)
27606 {
27607 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27608 int rearm = 0, budget = blk_iopoll_budget;
27609 diff --git a/block/blk-map.c b/block/blk-map.c
27610 index 623e1cd..ca1e109 100644
27611 --- a/block/blk-map.c
27612 +++ b/block/blk-map.c
27613 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27614 if (!len || !kbuf)
27615 return -EINVAL;
27616
27617 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27618 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27619 if (do_copy)
27620 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27621 else
27622 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27623 index 467c8de..4bddc6d 100644
27624 --- a/block/blk-softirq.c
27625 +++ b/block/blk-softirq.c
27626 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27627 * Softirq action handler - move entries to local list and loop over them
27628 * while passing them to the queue registered handler.
27629 */
27630 -static void blk_done_softirq(struct softirq_action *h)
27631 +static void blk_done_softirq(void)
27632 {
27633 struct list_head *cpu_list, local_list;
27634
27635 diff --git a/block/bsg.c b/block/bsg.c
27636 index ff64ae3..593560c 100644
27637 --- a/block/bsg.c
27638 +++ b/block/bsg.c
27639 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27640 struct sg_io_v4 *hdr, struct bsg_device *bd,
27641 fmode_t has_write_perm)
27642 {
27643 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27644 + unsigned char *cmdptr;
27645 +
27646 if (hdr->request_len > BLK_MAX_CDB) {
27647 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27648 if (!rq->cmd)
27649 return -ENOMEM;
27650 - }
27651 + cmdptr = rq->cmd;
27652 + } else
27653 + cmdptr = tmpcmd;
27654
27655 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27656 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27657 hdr->request_len))
27658 return -EFAULT;
27659
27660 + if (cmdptr != rq->cmd)
27661 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27662 +
27663 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27664 if (blk_verify_command(rq->cmd, has_write_perm))
27665 return -EPERM;
27666 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27667 index 7c668c8..db3521c 100644
27668 --- a/block/compat_ioctl.c
27669 +++ b/block/compat_ioctl.c
27670 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27671 err |= __get_user(f->spec1, &uf->spec1);
27672 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27673 err |= __get_user(name, &uf->name);
27674 - f->name = compat_ptr(name);
27675 + f->name = (void __force_kernel *)compat_ptr(name);
27676 if (err) {
27677 err = -EFAULT;
27678 goto out;
27679 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27680 index 6296b40..417c00f 100644
27681 --- a/block/partitions/efi.c
27682 +++ b/block/partitions/efi.c
27683 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27684 if (!gpt)
27685 return NULL;
27686
27687 + if (!le32_to_cpu(gpt->num_partition_entries))
27688 + return NULL;
27689 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27690 + if (!pte)
27691 + return NULL;
27692 +
27693 count = le32_to_cpu(gpt->num_partition_entries) *
27694 le32_to_cpu(gpt->sizeof_partition_entry);
27695 - if (!count)
27696 - return NULL;
27697 - pte = kzalloc(count, GFP_KERNEL);
27698 - if (!pte)
27699 - return NULL;
27700 -
27701 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27702 (u8 *) pte,
27703 count) < count) {
27704 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27705 index 9a87daa..fb17486 100644
27706 --- a/block/scsi_ioctl.c
27707 +++ b/block/scsi_ioctl.c
27708 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27709 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27710 struct sg_io_hdr *hdr, fmode_t mode)
27711 {
27712 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27713 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27714 + unsigned char *cmdptr;
27715 +
27716 + if (rq->cmd != rq->__cmd)
27717 + cmdptr = rq->cmd;
27718 + else
27719 + cmdptr = tmpcmd;
27720 +
27721 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27722 return -EFAULT;
27723 +
27724 + if (cmdptr != rq->cmd)
27725 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27726 +
27727 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27728 return -EPERM;
27729
27730 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27731 int err;
27732 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27733 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27734 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27735 + unsigned char *cmdptr;
27736
27737 if (!sic)
27738 return -EINVAL;
27739 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27740 */
27741 err = -EFAULT;
27742 rq->cmd_len = cmdlen;
27743 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27744 +
27745 + if (rq->cmd != rq->__cmd)
27746 + cmdptr = rq->cmd;
27747 + else
27748 + cmdptr = tmpcmd;
27749 +
27750 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27751 goto error;
27752
27753 + if (rq->cmd != cmdptr)
27754 + memcpy(rq->cmd, cmdptr, cmdlen);
27755 +
27756 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27757 goto error;
27758
27759 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27760 index 671d4d6..5f24030 100644
27761 --- a/crypto/cryptd.c
27762 +++ b/crypto/cryptd.c
27763 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27764
27765 struct cryptd_blkcipher_request_ctx {
27766 crypto_completion_t complete;
27767 -};
27768 +} __no_const;
27769
27770 struct cryptd_hash_ctx {
27771 struct crypto_shash *child;
27772 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27773
27774 struct cryptd_aead_request_ctx {
27775 crypto_completion_t complete;
27776 -};
27777 +} __no_const;
27778
27779 static void cryptd_queue_worker(struct work_struct *work);
27780
27781 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27782 index e6defd8..c26a225 100644
27783 --- a/drivers/acpi/apei/cper.c
27784 +++ b/drivers/acpi/apei/cper.c
27785 @@ -38,12 +38,12 @@
27786 */
27787 u64 cper_next_record_id(void)
27788 {
27789 - static atomic64_t seq;
27790 + static atomic64_unchecked_t seq;
27791
27792 - if (!atomic64_read(&seq))
27793 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27794 + if (!atomic64_read_unchecked(&seq))
27795 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27796
27797 - return atomic64_inc_return(&seq);
27798 + return atomic64_inc_return_unchecked(&seq);
27799 }
27800 EXPORT_SYMBOL_GPL(cper_next_record_id);
27801
27802 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27803 index 7586544..636a2f0 100644
27804 --- a/drivers/acpi/ec_sys.c
27805 +++ b/drivers/acpi/ec_sys.c
27806 @@ -12,6 +12,7 @@
27807 #include <linux/acpi.h>
27808 #include <linux/debugfs.h>
27809 #include <linux/module.h>
27810 +#include <linux/uaccess.h>
27811 #include "internal.h"
27812
27813 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27814 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27815 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27816 */
27817 unsigned int size = EC_SPACE_SIZE;
27818 - u8 *data = (u8 *) buf;
27819 + u8 data;
27820 loff_t init_off = *off;
27821 int err = 0;
27822
27823 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27824 size = count;
27825
27826 while (size) {
27827 - err = ec_read(*off, &data[*off - init_off]);
27828 + err = ec_read(*off, &data);
27829 if (err)
27830 return err;
27831 + if (put_user(data, &buf[*off - init_off]))
27832 + return -EFAULT;
27833 *off += 1;
27834 size--;
27835 }
27836 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27837
27838 unsigned int size = count;
27839 loff_t init_off = *off;
27840 - u8 *data = (u8 *) buf;
27841 int err = 0;
27842
27843 if (*off >= EC_SPACE_SIZE)
27844 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27845 }
27846
27847 while (size) {
27848 - u8 byte_write = data[*off - init_off];
27849 + u8 byte_write;
27850 + if (get_user(byte_write, &buf[*off - init_off]))
27851 + return -EFAULT;
27852 err = ec_write(*off, byte_write);
27853 if (err)
27854 return err;
27855 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27856 index 251c7b62..000462d 100644
27857 --- a/drivers/acpi/proc.c
27858 +++ b/drivers/acpi/proc.c
27859 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27860 size_t count, loff_t * ppos)
27861 {
27862 struct list_head *node, *next;
27863 - char strbuf[5];
27864 - char str[5] = "";
27865 - unsigned int len = count;
27866 + char strbuf[5] = {0};
27867
27868 - if (len > 4)
27869 - len = 4;
27870 - if (len < 0)
27871 + if (count > 4)
27872 + count = 4;
27873 + if (copy_from_user(strbuf, buffer, count))
27874 return -EFAULT;
27875 -
27876 - if (copy_from_user(strbuf, buffer, len))
27877 - return -EFAULT;
27878 - strbuf[len] = '\0';
27879 - sscanf(strbuf, "%s", str);
27880 + strbuf[count] = '\0';
27881
27882 mutex_lock(&acpi_device_lock);
27883 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27884 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27885 if (!dev->wakeup.flags.valid)
27886 continue;
27887
27888 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27889 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27890 if (device_can_wakeup(&dev->dev)) {
27891 bool enable = !device_may_wakeup(&dev->dev);
27892 device_set_wakeup_enable(&dev->dev, enable);
27893 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27894 index bfc31cb..8213ce1 100644
27895 --- a/drivers/acpi/processor_driver.c
27896 +++ b/drivers/acpi/processor_driver.c
27897 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27898 return 0;
27899 #endif
27900
27901 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27902 + BUG_ON(pr->id >= nr_cpu_ids);
27903
27904 /*
27905 * Buggy BIOS check
27906 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27907 index 8e1039c..ea9cbd4 100644
27908 --- a/drivers/ata/libata-core.c
27909 +++ b/drivers/ata/libata-core.c
27910 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27911 struct ata_port *ap;
27912 unsigned int tag;
27913
27914 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27915 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27916 ap = qc->ap;
27917
27918 qc->flags = 0;
27919 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27920 struct ata_port *ap;
27921 struct ata_link *link;
27922
27923 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27924 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27925 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27926 ap = qc->ap;
27927 link = qc->dev->link;
27928 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27929 return;
27930
27931 spin_lock(&lock);
27932 + pax_open_kernel();
27933
27934 for (cur = ops->inherits; cur; cur = cur->inherits) {
27935 void **inherit = (void **)cur;
27936 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27937 if (IS_ERR(*pp))
27938 *pp = NULL;
27939
27940 - ops->inherits = NULL;
27941 + *(struct ata_port_operations **)&ops->inherits = NULL;
27942
27943 + pax_close_kernel();
27944 spin_unlock(&lock);
27945 }
27946
27947 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27948 index bfaa5cb..3ba1cc3 100644
27949 --- a/drivers/ata/pata_arasan_cf.c
27950 +++ b/drivers/ata/pata_arasan_cf.c
27951 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27952 /* Handle platform specific quirks */
27953 if (pdata->quirk) {
27954 if (pdata->quirk & CF_BROKEN_PIO) {
27955 - ap->ops->set_piomode = NULL;
27956 + pax_open_kernel();
27957 + *(void **)&ap->ops->set_piomode = NULL;
27958 + pax_close_kernel();
27959 ap->pio_mask = 0;
27960 }
27961 if (pdata->quirk & CF_BROKEN_MWDMA)
27962 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27963 index f9b983a..887b9d8 100644
27964 --- a/drivers/atm/adummy.c
27965 +++ b/drivers/atm/adummy.c
27966 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27967 vcc->pop(vcc, skb);
27968 else
27969 dev_kfree_skb_any(skb);
27970 - atomic_inc(&vcc->stats->tx);
27971 + atomic_inc_unchecked(&vcc->stats->tx);
27972
27973 return 0;
27974 }
27975 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27976 index 89b30f3..7964211 100644
27977 --- a/drivers/atm/ambassador.c
27978 +++ b/drivers/atm/ambassador.c
27979 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27980 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27981
27982 // VC layer stats
27983 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27984 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27985
27986 // free the descriptor
27987 kfree (tx_descr);
27988 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27989 dump_skb ("<<<", vc, skb);
27990
27991 // VC layer stats
27992 - atomic_inc(&atm_vcc->stats->rx);
27993 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27994 __net_timestamp(skb);
27995 // end of our responsibility
27996 atm_vcc->push (atm_vcc, skb);
27997 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27998 } else {
27999 PRINTK (KERN_INFO, "dropped over-size frame");
28000 // should we count this?
28001 - atomic_inc(&atm_vcc->stats->rx_drop);
28002 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28003 }
28004
28005 } else {
28006 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28007 }
28008
28009 if (check_area (skb->data, skb->len)) {
28010 - atomic_inc(&atm_vcc->stats->tx_err);
28011 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28012 return -ENOMEM; // ?
28013 }
28014
28015 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28016 index b22d71c..d6e1049 100644
28017 --- a/drivers/atm/atmtcp.c
28018 +++ b/drivers/atm/atmtcp.c
28019 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28020 if (vcc->pop) vcc->pop(vcc,skb);
28021 else dev_kfree_skb(skb);
28022 if (dev_data) return 0;
28023 - atomic_inc(&vcc->stats->tx_err);
28024 + atomic_inc_unchecked(&vcc->stats->tx_err);
28025 return -ENOLINK;
28026 }
28027 size = skb->len+sizeof(struct atmtcp_hdr);
28028 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28029 if (!new_skb) {
28030 if (vcc->pop) vcc->pop(vcc,skb);
28031 else dev_kfree_skb(skb);
28032 - atomic_inc(&vcc->stats->tx_err);
28033 + atomic_inc_unchecked(&vcc->stats->tx_err);
28034 return -ENOBUFS;
28035 }
28036 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28037 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28038 if (vcc->pop) vcc->pop(vcc,skb);
28039 else dev_kfree_skb(skb);
28040 out_vcc->push(out_vcc,new_skb);
28041 - atomic_inc(&vcc->stats->tx);
28042 - atomic_inc(&out_vcc->stats->rx);
28043 + atomic_inc_unchecked(&vcc->stats->tx);
28044 + atomic_inc_unchecked(&out_vcc->stats->rx);
28045 return 0;
28046 }
28047
28048 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28049 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28050 read_unlock(&vcc_sklist_lock);
28051 if (!out_vcc) {
28052 - atomic_inc(&vcc->stats->tx_err);
28053 + atomic_inc_unchecked(&vcc->stats->tx_err);
28054 goto done;
28055 }
28056 skb_pull(skb,sizeof(struct atmtcp_hdr));
28057 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28058 __net_timestamp(new_skb);
28059 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28060 out_vcc->push(out_vcc,new_skb);
28061 - atomic_inc(&vcc->stats->tx);
28062 - atomic_inc(&out_vcc->stats->rx);
28063 + atomic_inc_unchecked(&vcc->stats->tx);
28064 + atomic_inc_unchecked(&out_vcc->stats->rx);
28065 done:
28066 if (vcc->pop) vcc->pop(vcc,skb);
28067 else dev_kfree_skb(skb);
28068 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28069 index 2059ee4..faf51c7 100644
28070 --- a/drivers/atm/eni.c
28071 +++ b/drivers/atm/eni.c
28072 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28073 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28074 vcc->dev->number);
28075 length = 0;
28076 - atomic_inc(&vcc->stats->rx_err);
28077 + atomic_inc_unchecked(&vcc->stats->rx_err);
28078 }
28079 else {
28080 length = ATM_CELL_SIZE-1; /* no HEC */
28081 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28082 size);
28083 }
28084 eff = length = 0;
28085 - atomic_inc(&vcc->stats->rx_err);
28086 + atomic_inc_unchecked(&vcc->stats->rx_err);
28087 }
28088 else {
28089 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28090 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28091 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28092 vcc->dev->number,vcc->vci,length,size << 2,descr);
28093 length = eff = 0;
28094 - atomic_inc(&vcc->stats->rx_err);
28095 + atomic_inc_unchecked(&vcc->stats->rx_err);
28096 }
28097 }
28098 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28099 @@ -767,7 +767,7 @@ rx_dequeued++;
28100 vcc->push(vcc,skb);
28101 pushed++;
28102 }
28103 - atomic_inc(&vcc->stats->rx);
28104 + atomic_inc_unchecked(&vcc->stats->rx);
28105 }
28106 wake_up(&eni_dev->rx_wait);
28107 }
28108 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28109 PCI_DMA_TODEVICE);
28110 if (vcc->pop) vcc->pop(vcc,skb);
28111 else dev_kfree_skb_irq(skb);
28112 - atomic_inc(&vcc->stats->tx);
28113 + atomic_inc_unchecked(&vcc->stats->tx);
28114 wake_up(&eni_dev->tx_wait);
28115 dma_complete++;
28116 }
28117 @@ -1567,7 +1567,7 @@ tx_complete++;
28118 /*--------------------------------- entries ---------------------------------*/
28119
28120
28121 -static const char *media_name[] __devinitdata = {
28122 +static const char *media_name[] __devinitconst = {
28123 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28124 "UTP", "05?", "06?", "07?", /* 4- 7 */
28125 "TAXI","09?", "10?", "11?", /* 8-11 */
28126 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28127 index 86fed1b..6dc4721 100644
28128 --- a/drivers/atm/firestream.c
28129 +++ b/drivers/atm/firestream.c
28130 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28131 }
28132 }
28133
28134 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28135 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28136
28137 fs_dprintk (FS_DEBUG_TXMEM, "i");
28138 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28139 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28140 #endif
28141 skb_put (skb, qe->p1 & 0xffff);
28142 ATM_SKB(skb)->vcc = atm_vcc;
28143 - atomic_inc(&atm_vcc->stats->rx);
28144 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28145 __net_timestamp(skb);
28146 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28147 atm_vcc->push (atm_vcc, skb);
28148 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28149 kfree (pe);
28150 }
28151 if (atm_vcc)
28152 - atomic_inc(&atm_vcc->stats->rx_drop);
28153 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28154 break;
28155 case 0x1f: /* Reassembly abort: no buffers. */
28156 /* Silently increment error counter. */
28157 if (atm_vcc)
28158 - atomic_inc(&atm_vcc->stats->rx_drop);
28159 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28160 break;
28161 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28162 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28163 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28164 index 361f5ae..7fc552d 100644
28165 --- a/drivers/atm/fore200e.c
28166 +++ b/drivers/atm/fore200e.c
28167 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28168 #endif
28169 /* check error condition */
28170 if (*entry->status & STATUS_ERROR)
28171 - atomic_inc(&vcc->stats->tx_err);
28172 + atomic_inc_unchecked(&vcc->stats->tx_err);
28173 else
28174 - atomic_inc(&vcc->stats->tx);
28175 + atomic_inc_unchecked(&vcc->stats->tx);
28176 }
28177 }
28178
28179 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28180 if (skb == NULL) {
28181 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28182
28183 - atomic_inc(&vcc->stats->rx_drop);
28184 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28185 return -ENOMEM;
28186 }
28187
28188 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28189
28190 dev_kfree_skb_any(skb);
28191
28192 - atomic_inc(&vcc->stats->rx_drop);
28193 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28194 return -ENOMEM;
28195 }
28196
28197 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28198
28199 vcc->push(vcc, skb);
28200 - atomic_inc(&vcc->stats->rx);
28201 + atomic_inc_unchecked(&vcc->stats->rx);
28202
28203 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28204
28205 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28206 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28207 fore200e->atm_dev->number,
28208 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28209 - atomic_inc(&vcc->stats->rx_err);
28210 + atomic_inc_unchecked(&vcc->stats->rx_err);
28211 }
28212 }
28213
28214 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28215 goto retry_here;
28216 }
28217
28218 - atomic_inc(&vcc->stats->tx_err);
28219 + atomic_inc_unchecked(&vcc->stats->tx_err);
28220
28221 fore200e->tx_sat++;
28222 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28223 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28224 index b182c2f..1c6fa8a 100644
28225 --- a/drivers/atm/he.c
28226 +++ b/drivers/atm/he.c
28227 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28228
28229 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28230 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28231 - atomic_inc(&vcc->stats->rx_drop);
28232 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28233 goto return_host_buffers;
28234 }
28235
28236 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28237 RBRQ_LEN_ERR(he_dev->rbrq_head)
28238 ? "LEN_ERR" : "",
28239 vcc->vpi, vcc->vci);
28240 - atomic_inc(&vcc->stats->rx_err);
28241 + atomic_inc_unchecked(&vcc->stats->rx_err);
28242 goto return_host_buffers;
28243 }
28244
28245 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28246 vcc->push(vcc, skb);
28247 spin_lock(&he_dev->global_lock);
28248
28249 - atomic_inc(&vcc->stats->rx);
28250 + atomic_inc_unchecked(&vcc->stats->rx);
28251
28252 return_host_buffers:
28253 ++pdus_assembled;
28254 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28255 tpd->vcc->pop(tpd->vcc, tpd->skb);
28256 else
28257 dev_kfree_skb_any(tpd->skb);
28258 - atomic_inc(&tpd->vcc->stats->tx_err);
28259 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28260 }
28261 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28262 return;
28263 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28264 vcc->pop(vcc, skb);
28265 else
28266 dev_kfree_skb_any(skb);
28267 - atomic_inc(&vcc->stats->tx_err);
28268 + atomic_inc_unchecked(&vcc->stats->tx_err);
28269 return -EINVAL;
28270 }
28271
28272 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28273 vcc->pop(vcc, skb);
28274 else
28275 dev_kfree_skb_any(skb);
28276 - atomic_inc(&vcc->stats->tx_err);
28277 + atomic_inc_unchecked(&vcc->stats->tx_err);
28278 return -EINVAL;
28279 }
28280 #endif
28281 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28282 vcc->pop(vcc, skb);
28283 else
28284 dev_kfree_skb_any(skb);
28285 - atomic_inc(&vcc->stats->tx_err);
28286 + atomic_inc_unchecked(&vcc->stats->tx_err);
28287 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28288 return -ENOMEM;
28289 }
28290 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28291 vcc->pop(vcc, skb);
28292 else
28293 dev_kfree_skb_any(skb);
28294 - atomic_inc(&vcc->stats->tx_err);
28295 + atomic_inc_unchecked(&vcc->stats->tx_err);
28296 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28297 return -ENOMEM;
28298 }
28299 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28300 __enqueue_tpd(he_dev, tpd, cid);
28301 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28302
28303 - atomic_inc(&vcc->stats->tx);
28304 + atomic_inc_unchecked(&vcc->stats->tx);
28305
28306 return 0;
28307 }
28308 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28309 index 7d01c2a..4e3ac01 100644
28310 --- a/drivers/atm/horizon.c
28311 +++ b/drivers/atm/horizon.c
28312 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28313 {
28314 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28315 // VC layer stats
28316 - atomic_inc(&vcc->stats->rx);
28317 + atomic_inc_unchecked(&vcc->stats->rx);
28318 __net_timestamp(skb);
28319 // end of our responsibility
28320 vcc->push (vcc, skb);
28321 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28322 dev->tx_iovec = NULL;
28323
28324 // VC layer stats
28325 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28326 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28327
28328 // free the skb
28329 hrz_kfree_skb (skb);
28330 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28331 index 8974bd2..b856f85 100644
28332 --- a/drivers/atm/idt77252.c
28333 +++ b/drivers/atm/idt77252.c
28334 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28335 else
28336 dev_kfree_skb(skb);
28337
28338 - atomic_inc(&vcc->stats->tx);
28339 + atomic_inc_unchecked(&vcc->stats->tx);
28340 }
28341
28342 atomic_dec(&scq->used);
28343 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28344 if ((sb = dev_alloc_skb(64)) == NULL) {
28345 printk("%s: Can't allocate buffers for aal0.\n",
28346 card->name);
28347 - atomic_add(i, &vcc->stats->rx_drop);
28348 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28349 break;
28350 }
28351 if (!atm_charge(vcc, sb->truesize)) {
28352 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28353 card->name);
28354 - atomic_add(i - 1, &vcc->stats->rx_drop);
28355 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28356 dev_kfree_skb(sb);
28357 break;
28358 }
28359 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28360 ATM_SKB(sb)->vcc = vcc;
28361 __net_timestamp(sb);
28362 vcc->push(vcc, sb);
28363 - atomic_inc(&vcc->stats->rx);
28364 + atomic_inc_unchecked(&vcc->stats->rx);
28365
28366 cell += ATM_CELL_PAYLOAD;
28367 }
28368 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28369 "(CDC: %08x)\n",
28370 card->name, len, rpp->len, readl(SAR_REG_CDC));
28371 recycle_rx_pool_skb(card, rpp);
28372 - atomic_inc(&vcc->stats->rx_err);
28373 + atomic_inc_unchecked(&vcc->stats->rx_err);
28374 return;
28375 }
28376 if (stat & SAR_RSQE_CRC) {
28377 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28378 recycle_rx_pool_skb(card, rpp);
28379 - atomic_inc(&vcc->stats->rx_err);
28380 + atomic_inc_unchecked(&vcc->stats->rx_err);
28381 return;
28382 }
28383 if (skb_queue_len(&rpp->queue) > 1) {
28384 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28385 RXPRINTK("%s: Can't alloc RX skb.\n",
28386 card->name);
28387 recycle_rx_pool_skb(card, rpp);
28388 - atomic_inc(&vcc->stats->rx_err);
28389 + atomic_inc_unchecked(&vcc->stats->rx_err);
28390 return;
28391 }
28392 if (!atm_charge(vcc, skb->truesize)) {
28393 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28394 __net_timestamp(skb);
28395
28396 vcc->push(vcc, skb);
28397 - atomic_inc(&vcc->stats->rx);
28398 + atomic_inc_unchecked(&vcc->stats->rx);
28399
28400 return;
28401 }
28402 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28403 __net_timestamp(skb);
28404
28405 vcc->push(vcc, skb);
28406 - atomic_inc(&vcc->stats->rx);
28407 + atomic_inc_unchecked(&vcc->stats->rx);
28408
28409 if (skb->truesize > SAR_FB_SIZE_3)
28410 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28411 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28412 if (vcc->qos.aal != ATM_AAL0) {
28413 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28414 card->name, vpi, vci);
28415 - atomic_inc(&vcc->stats->rx_drop);
28416 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28417 goto drop;
28418 }
28419
28420 if ((sb = dev_alloc_skb(64)) == NULL) {
28421 printk("%s: Can't allocate buffers for AAL0.\n",
28422 card->name);
28423 - atomic_inc(&vcc->stats->rx_err);
28424 + atomic_inc_unchecked(&vcc->stats->rx_err);
28425 goto drop;
28426 }
28427
28428 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28429 ATM_SKB(sb)->vcc = vcc;
28430 __net_timestamp(sb);
28431 vcc->push(vcc, sb);
28432 - atomic_inc(&vcc->stats->rx);
28433 + atomic_inc_unchecked(&vcc->stats->rx);
28434
28435 drop:
28436 skb_pull(queue, 64);
28437 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28438
28439 if (vc == NULL) {
28440 printk("%s: NULL connection in send().\n", card->name);
28441 - atomic_inc(&vcc->stats->tx_err);
28442 + atomic_inc_unchecked(&vcc->stats->tx_err);
28443 dev_kfree_skb(skb);
28444 return -EINVAL;
28445 }
28446 if (!test_bit(VCF_TX, &vc->flags)) {
28447 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28448 - atomic_inc(&vcc->stats->tx_err);
28449 + atomic_inc_unchecked(&vcc->stats->tx_err);
28450 dev_kfree_skb(skb);
28451 return -EINVAL;
28452 }
28453 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28454 break;
28455 default:
28456 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28457 - atomic_inc(&vcc->stats->tx_err);
28458 + atomic_inc_unchecked(&vcc->stats->tx_err);
28459 dev_kfree_skb(skb);
28460 return -EINVAL;
28461 }
28462
28463 if (skb_shinfo(skb)->nr_frags != 0) {
28464 printk("%s: No scatter-gather yet.\n", card->name);
28465 - atomic_inc(&vcc->stats->tx_err);
28466 + atomic_inc_unchecked(&vcc->stats->tx_err);
28467 dev_kfree_skb(skb);
28468 return -EINVAL;
28469 }
28470 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28471
28472 err = queue_skb(card, vc, skb, oam);
28473 if (err) {
28474 - atomic_inc(&vcc->stats->tx_err);
28475 + atomic_inc_unchecked(&vcc->stats->tx_err);
28476 dev_kfree_skb(skb);
28477 return err;
28478 }
28479 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28480 skb = dev_alloc_skb(64);
28481 if (!skb) {
28482 printk("%s: Out of memory in send_oam().\n", card->name);
28483 - atomic_inc(&vcc->stats->tx_err);
28484 + atomic_inc_unchecked(&vcc->stats->tx_err);
28485 return -ENOMEM;
28486 }
28487 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28488 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28489 index 96cce6d..62c3ec5 100644
28490 --- a/drivers/atm/iphase.c
28491 +++ b/drivers/atm/iphase.c
28492 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28493 status = (u_short) (buf_desc_ptr->desc_mode);
28494 if (status & (RX_CER | RX_PTE | RX_OFL))
28495 {
28496 - atomic_inc(&vcc->stats->rx_err);
28497 + atomic_inc_unchecked(&vcc->stats->rx_err);
28498 IF_ERR(printk("IA: bad packet, dropping it");)
28499 if (status & RX_CER) {
28500 IF_ERR(printk(" cause: packet CRC error\n");)
28501 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28502 len = dma_addr - buf_addr;
28503 if (len > iadev->rx_buf_sz) {
28504 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28505 - atomic_inc(&vcc->stats->rx_err);
28506 + atomic_inc_unchecked(&vcc->stats->rx_err);
28507 goto out_free_desc;
28508 }
28509
28510 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28511 ia_vcc = INPH_IA_VCC(vcc);
28512 if (ia_vcc == NULL)
28513 {
28514 - atomic_inc(&vcc->stats->rx_err);
28515 + atomic_inc_unchecked(&vcc->stats->rx_err);
28516 atm_return(vcc, skb->truesize);
28517 dev_kfree_skb_any(skb);
28518 goto INCR_DLE;
28519 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28520 if ((length > iadev->rx_buf_sz) || (length >
28521 (skb->len - sizeof(struct cpcs_trailer))))
28522 {
28523 - atomic_inc(&vcc->stats->rx_err);
28524 + atomic_inc_unchecked(&vcc->stats->rx_err);
28525 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28526 length, skb->len);)
28527 atm_return(vcc, skb->truesize);
28528 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28529
28530 IF_RX(printk("rx_dle_intr: skb push");)
28531 vcc->push(vcc,skb);
28532 - atomic_inc(&vcc->stats->rx);
28533 + atomic_inc_unchecked(&vcc->stats->rx);
28534 iadev->rx_pkt_cnt++;
28535 }
28536 INCR_DLE:
28537 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28538 {
28539 struct k_sonet_stats *stats;
28540 stats = &PRIV(_ia_dev[board])->sonet_stats;
28541 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28542 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28543 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28544 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28545 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28546 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28547 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28548 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28549 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28550 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28551 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28552 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28553 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28554 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28555 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28556 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28557 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28558 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28559 }
28560 ia_cmds.status = 0;
28561 break;
28562 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28563 if ((desc == 0) || (desc > iadev->num_tx_desc))
28564 {
28565 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28566 - atomic_inc(&vcc->stats->tx);
28567 + atomic_inc_unchecked(&vcc->stats->tx);
28568 if (vcc->pop)
28569 vcc->pop(vcc, skb);
28570 else
28571 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28572 ATM_DESC(skb) = vcc->vci;
28573 skb_queue_tail(&iadev->tx_dma_q, skb);
28574
28575 - atomic_inc(&vcc->stats->tx);
28576 + atomic_inc_unchecked(&vcc->stats->tx);
28577 iadev->tx_pkt_cnt++;
28578 /* Increment transaction counter */
28579 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28580
28581 #if 0
28582 /* add flow control logic */
28583 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28584 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28585 if (iavcc->vc_desc_cnt > 10) {
28586 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28587 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28588 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28589 index 68c7588..7036683 100644
28590 --- a/drivers/atm/lanai.c
28591 +++ b/drivers/atm/lanai.c
28592 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28593 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28594 lanai_endtx(lanai, lvcc);
28595 lanai_free_skb(lvcc->tx.atmvcc, skb);
28596 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28597 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28598 }
28599
28600 /* Try to fill the buffer - don't call unless there is backlog */
28601 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28602 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28603 __net_timestamp(skb);
28604 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28605 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28606 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28607 out:
28608 lvcc->rx.buf.ptr = end;
28609 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28610 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28611 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28612 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28613 lanai->stats.service_rxnotaal5++;
28614 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28615 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28616 return 0;
28617 }
28618 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28619 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28620 int bytes;
28621 read_unlock(&vcc_sklist_lock);
28622 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28623 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28624 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28625 lvcc->stats.x.aal5.service_trash++;
28626 bytes = (SERVICE_GET_END(s) * 16) -
28627 (((unsigned long) lvcc->rx.buf.ptr) -
28628 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28629 }
28630 if (s & SERVICE_STREAM) {
28631 read_unlock(&vcc_sklist_lock);
28632 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28633 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28634 lvcc->stats.x.aal5.service_stream++;
28635 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28636 "PDU on VCI %d!\n", lanai->number, vci);
28637 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28638 return 0;
28639 }
28640 DPRINTK("got rx crc error on vci %d\n", vci);
28641 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28642 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28643 lvcc->stats.x.aal5.service_rxcrc++;
28644 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28645 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28646 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28647 index 1c70c45..300718d 100644
28648 --- a/drivers/atm/nicstar.c
28649 +++ b/drivers/atm/nicstar.c
28650 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28651 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28652 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28653 card->index);
28654 - atomic_inc(&vcc->stats->tx_err);
28655 + atomic_inc_unchecked(&vcc->stats->tx_err);
28656 dev_kfree_skb_any(skb);
28657 return -EINVAL;
28658 }
28659 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28660 if (!vc->tx) {
28661 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28662 card->index);
28663 - atomic_inc(&vcc->stats->tx_err);
28664 + atomic_inc_unchecked(&vcc->stats->tx_err);
28665 dev_kfree_skb_any(skb);
28666 return -EINVAL;
28667 }
28668 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28669 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28670 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28671 card->index);
28672 - atomic_inc(&vcc->stats->tx_err);
28673 + atomic_inc_unchecked(&vcc->stats->tx_err);
28674 dev_kfree_skb_any(skb);
28675 return -EINVAL;
28676 }
28677
28678 if (skb_shinfo(skb)->nr_frags != 0) {
28679 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28680 - atomic_inc(&vcc->stats->tx_err);
28681 + atomic_inc_unchecked(&vcc->stats->tx_err);
28682 dev_kfree_skb_any(skb);
28683 return -EINVAL;
28684 }
28685 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28686 }
28687
28688 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28689 - atomic_inc(&vcc->stats->tx_err);
28690 + atomic_inc_unchecked(&vcc->stats->tx_err);
28691 dev_kfree_skb_any(skb);
28692 return -EIO;
28693 }
28694 - atomic_inc(&vcc->stats->tx);
28695 + atomic_inc_unchecked(&vcc->stats->tx);
28696
28697 return 0;
28698 }
28699 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28700 printk
28701 ("nicstar%d: Can't allocate buffers for aal0.\n",
28702 card->index);
28703 - atomic_add(i, &vcc->stats->rx_drop);
28704 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28705 break;
28706 }
28707 if (!atm_charge(vcc, sb->truesize)) {
28708 RXPRINTK
28709 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28710 card->index);
28711 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28712 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28713 dev_kfree_skb_any(sb);
28714 break;
28715 }
28716 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28717 ATM_SKB(sb)->vcc = vcc;
28718 __net_timestamp(sb);
28719 vcc->push(vcc, sb);
28720 - atomic_inc(&vcc->stats->rx);
28721 + atomic_inc_unchecked(&vcc->stats->rx);
28722 cell += ATM_CELL_PAYLOAD;
28723 }
28724
28725 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28726 if (iovb == NULL) {
28727 printk("nicstar%d: Out of iovec buffers.\n",
28728 card->index);
28729 - atomic_inc(&vcc->stats->rx_drop);
28730 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28731 recycle_rx_buf(card, skb);
28732 return;
28733 }
28734 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28735 small or large buffer itself. */
28736 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28737 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28738 - atomic_inc(&vcc->stats->rx_err);
28739 + atomic_inc_unchecked(&vcc->stats->rx_err);
28740 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28741 NS_MAX_IOVECS);
28742 NS_PRV_IOVCNT(iovb) = 0;
28743 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28744 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28745 card->index);
28746 which_list(card, skb);
28747 - atomic_inc(&vcc->stats->rx_err);
28748 + atomic_inc_unchecked(&vcc->stats->rx_err);
28749 recycle_rx_buf(card, skb);
28750 vc->rx_iov = NULL;
28751 recycle_iov_buf(card, iovb);
28752 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28753 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28754 card->index);
28755 which_list(card, skb);
28756 - atomic_inc(&vcc->stats->rx_err);
28757 + atomic_inc_unchecked(&vcc->stats->rx_err);
28758 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28759 NS_PRV_IOVCNT(iovb));
28760 vc->rx_iov = NULL;
28761 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28762 printk(" - PDU size mismatch.\n");
28763 else
28764 printk(".\n");
28765 - atomic_inc(&vcc->stats->rx_err);
28766 + atomic_inc_unchecked(&vcc->stats->rx_err);
28767 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28768 NS_PRV_IOVCNT(iovb));
28769 vc->rx_iov = NULL;
28770 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28771 /* skb points to a small buffer */
28772 if (!atm_charge(vcc, skb->truesize)) {
28773 push_rxbufs(card, skb);
28774 - atomic_inc(&vcc->stats->rx_drop);
28775 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28776 } else {
28777 skb_put(skb, len);
28778 dequeue_sm_buf(card, skb);
28779 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28780 ATM_SKB(skb)->vcc = vcc;
28781 __net_timestamp(skb);
28782 vcc->push(vcc, skb);
28783 - atomic_inc(&vcc->stats->rx);
28784 + atomic_inc_unchecked(&vcc->stats->rx);
28785 }
28786 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28787 struct sk_buff *sb;
28788 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28789 if (len <= NS_SMBUFSIZE) {
28790 if (!atm_charge(vcc, sb->truesize)) {
28791 push_rxbufs(card, sb);
28792 - atomic_inc(&vcc->stats->rx_drop);
28793 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28794 } else {
28795 skb_put(sb, len);
28796 dequeue_sm_buf(card, sb);
28797 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28798 ATM_SKB(sb)->vcc = vcc;
28799 __net_timestamp(sb);
28800 vcc->push(vcc, sb);
28801 - atomic_inc(&vcc->stats->rx);
28802 + atomic_inc_unchecked(&vcc->stats->rx);
28803 }
28804
28805 push_rxbufs(card, skb);
28806 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28807
28808 if (!atm_charge(vcc, skb->truesize)) {
28809 push_rxbufs(card, skb);
28810 - atomic_inc(&vcc->stats->rx_drop);
28811 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28812 } else {
28813 dequeue_lg_buf(card, skb);
28814 #ifdef NS_USE_DESTRUCTORS
28815 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28816 ATM_SKB(skb)->vcc = vcc;
28817 __net_timestamp(skb);
28818 vcc->push(vcc, skb);
28819 - atomic_inc(&vcc->stats->rx);
28820 + atomic_inc_unchecked(&vcc->stats->rx);
28821 }
28822
28823 push_rxbufs(card, sb);
28824 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28825 printk
28826 ("nicstar%d: Out of huge buffers.\n",
28827 card->index);
28828 - atomic_inc(&vcc->stats->rx_drop);
28829 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28830 recycle_iovec_rx_bufs(card,
28831 (struct iovec *)
28832 iovb->data,
28833 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28834 card->hbpool.count++;
28835 } else
28836 dev_kfree_skb_any(hb);
28837 - atomic_inc(&vcc->stats->rx_drop);
28838 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28839 } else {
28840 /* Copy the small buffer to the huge buffer */
28841 sb = (struct sk_buff *)iov->iov_base;
28842 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28843 #endif /* NS_USE_DESTRUCTORS */
28844 __net_timestamp(hb);
28845 vcc->push(vcc, hb);
28846 - atomic_inc(&vcc->stats->rx);
28847 + atomic_inc_unchecked(&vcc->stats->rx);
28848 }
28849 }
28850
28851 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28852 index 9851093..adb2b1e 100644
28853 --- a/drivers/atm/solos-pci.c
28854 +++ b/drivers/atm/solos-pci.c
28855 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28856 }
28857 atm_charge(vcc, skb->truesize);
28858 vcc->push(vcc, skb);
28859 - atomic_inc(&vcc->stats->rx);
28860 + atomic_inc_unchecked(&vcc->stats->rx);
28861 break;
28862
28863 case PKT_STATUS:
28864 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28865 vcc = SKB_CB(oldskb)->vcc;
28866
28867 if (vcc) {
28868 - atomic_inc(&vcc->stats->tx);
28869 + atomic_inc_unchecked(&vcc->stats->tx);
28870 solos_pop(vcc, oldskb);
28871 } else
28872 dev_kfree_skb_irq(oldskb);
28873 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28874 index 0215934..ce9f5b1 100644
28875 --- a/drivers/atm/suni.c
28876 +++ b/drivers/atm/suni.c
28877 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28878
28879
28880 #define ADD_LIMITED(s,v) \
28881 - atomic_add((v),&stats->s); \
28882 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28883 + atomic_add_unchecked((v),&stats->s); \
28884 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28885
28886
28887 static void suni_hz(unsigned long from_timer)
28888 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28889 index 5120a96..e2572bd 100644
28890 --- a/drivers/atm/uPD98402.c
28891 +++ b/drivers/atm/uPD98402.c
28892 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28893 struct sonet_stats tmp;
28894 int error = 0;
28895
28896 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28897 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28898 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28899 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28900 if (zero && !error) {
28901 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28902
28903
28904 #define ADD_LIMITED(s,v) \
28905 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28906 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28907 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28908 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28909 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28910 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28911
28912
28913 static void stat_event(struct atm_dev *dev)
28914 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28915 if (reason & uPD98402_INT_PFM) stat_event(dev);
28916 if (reason & uPD98402_INT_PCO) {
28917 (void) GET(PCOCR); /* clear interrupt cause */
28918 - atomic_add(GET(HECCT),
28919 + atomic_add_unchecked(GET(HECCT),
28920 &PRIV(dev)->sonet_stats.uncorr_hcs);
28921 }
28922 if ((reason & uPD98402_INT_RFO) &&
28923 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28924 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28925 uPD98402_INT_LOS),PIMR); /* enable them */
28926 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28927 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28928 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28929 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28930 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28931 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28932 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28933 return 0;
28934 }
28935
28936 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28937 index abe4e20..83c4727 100644
28938 --- a/drivers/atm/zatm.c
28939 +++ b/drivers/atm/zatm.c
28940 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28941 }
28942 if (!size) {
28943 dev_kfree_skb_irq(skb);
28944 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28945 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28946 continue;
28947 }
28948 if (!atm_charge(vcc,skb->truesize)) {
28949 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28950 skb->len = size;
28951 ATM_SKB(skb)->vcc = vcc;
28952 vcc->push(vcc,skb);
28953 - atomic_inc(&vcc->stats->rx);
28954 + atomic_inc_unchecked(&vcc->stats->rx);
28955 }
28956 zout(pos & 0xffff,MTA(mbx));
28957 #if 0 /* probably a stupid idea */
28958 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28959 skb_queue_head(&zatm_vcc->backlog,skb);
28960 break;
28961 }
28962 - atomic_inc(&vcc->stats->tx);
28963 + atomic_inc_unchecked(&vcc->stats->tx);
28964 wake_up(&zatm_vcc->tx_wait);
28965 }
28966
28967 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28968 index deb4a45..211eff2 100644
28969 --- a/drivers/base/devtmpfs.c
28970 +++ b/drivers/base/devtmpfs.c
28971 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28972 if (!thread)
28973 return 0;
28974
28975 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28976 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28977 if (err)
28978 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28979 else
28980 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28981 index cbb463b..babe2cf 100644
28982 --- a/drivers/base/power/wakeup.c
28983 +++ b/drivers/base/power/wakeup.c
28984 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28985 * They need to be modified together atomically, so it's better to use one
28986 * atomic variable to hold them both.
28987 */
28988 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28989 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28990
28991 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28992 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28993
28994 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28995 {
28996 - unsigned int comb = atomic_read(&combined_event_count);
28997 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28998
28999 *cnt = (comb >> IN_PROGRESS_BITS);
29000 *inpr = comb & MAX_IN_PROGRESS;
29001 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29002 ws->start_prevent_time = ws->last_time;
29003
29004 /* Increment the counter of events in progress. */
29005 - cec = atomic_inc_return(&combined_event_count);
29006 + cec = atomic_inc_return_unchecked(&combined_event_count);
29007
29008 trace_wakeup_source_activate(ws->name, cec);
29009 }
29010 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29011 * Increment the counter of registered wakeup events and decrement the
29012 * couter of wakeup events in progress simultaneously.
29013 */
29014 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29015 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29016 trace_wakeup_source_deactivate(ws->name, cec);
29017
29018 split_counters(&cnt, &inpr);
29019 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29020 index b0f553b..77b928b 100644
29021 --- a/drivers/block/cciss.c
29022 +++ b/drivers/block/cciss.c
29023 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29024 int err;
29025 u32 cp;
29026
29027 + memset(&arg64, 0, sizeof(arg64));
29028 +
29029 err = 0;
29030 err |=
29031 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29032 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29033 while (!list_empty(&h->reqQ)) {
29034 c = list_entry(h->reqQ.next, CommandList_struct, list);
29035 /* can't do anything if fifo is full */
29036 - if ((h->access.fifo_full(h))) {
29037 + if ((h->access->fifo_full(h))) {
29038 dev_warn(&h->pdev->dev, "fifo full\n");
29039 break;
29040 }
29041 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29042 h->Qdepth--;
29043
29044 /* Tell the controller execute command */
29045 - h->access.submit_command(h, c);
29046 + h->access->submit_command(h, c);
29047
29048 /* Put job onto the completed Q */
29049 addQ(&h->cmpQ, c);
29050 @@ -3443,17 +3445,17 @@ startio:
29051
29052 static inline unsigned long get_next_completion(ctlr_info_t *h)
29053 {
29054 - return h->access.command_completed(h);
29055 + return h->access->command_completed(h);
29056 }
29057
29058 static inline int interrupt_pending(ctlr_info_t *h)
29059 {
29060 - return h->access.intr_pending(h);
29061 + return h->access->intr_pending(h);
29062 }
29063
29064 static inline long interrupt_not_for_us(ctlr_info_t *h)
29065 {
29066 - return ((h->access.intr_pending(h) == 0) ||
29067 + return ((h->access->intr_pending(h) == 0) ||
29068 (h->interrupts_enabled == 0));
29069 }
29070
29071 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29072 u32 a;
29073
29074 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29075 - return h->access.command_completed(h);
29076 + return h->access->command_completed(h);
29077
29078 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29079 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29080 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29081 trans_support & CFGTBL_Trans_use_short_tags);
29082
29083 /* Change the access methods to the performant access methods */
29084 - h->access = SA5_performant_access;
29085 + h->access = &SA5_performant_access;
29086 h->transMethod = CFGTBL_Trans_Performant;
29087
29088 return;
29089 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29090 if (prod_index < 0)
29091 return -ENODEV;
29092 h->product_name = products[prod_index].product_name;
29093 - h->access = *(products[prod_index].access);
29094 + h->access = products[prod_index].access;
29095
29096 if (cciss_board_disabled(h)) {
29097 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29098 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29099 }
29100
29101 /* make sure the board interrupts are off */
29102 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29103 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29104 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29105 if (rc)
29106 goto clean2;
29107 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29108 * fake ones to scoop up any residual completions.
29109 */
29110 spin_lock_irqsave(&h->lock, flags);
29111 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29112 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29113 spin_unlock_irqrestore(&h->lock, flags);
29114 free_irq(h->intr[h->intr_mode], h);
29115 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29116 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29117 dev_info(&h->pdev->dev, "Board READY.\n");
29118 dev_info(&h->pdev->dev,
29119 "Waiting for stale completions to drain.\n");
29120 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29121 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29122 msleep(10000);
29123 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29124 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29125
29126 rc = controller_reset_failed(h->cfgtable);
29127 if (rc)
29128 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29129 cciss_scsi_setup(h);
29130
29131 /* Turn the interrupts on so we can service requests */
29132 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29133 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29134
29135 /* Get the firmware version */
29136 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29137 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29138 kfree(flush_buf);
29139 if (return_code != IO_OK)
29140 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29141 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29142 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29143 free_irq(h->intr[h->intr_mode], h);
29144 }
29145
29146 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29147 index 7fda30e..eb5dfe0 100644
29148 --- a/drivers/block/cciss.h
29149 +++ b/drivers/block/cciss.h
29150 @@ -101,7 +101,7 @@ struct ctlr_info
29151 /* information about each logical volume */
29152 drive_info_struct *drv[CISS_MAX_LUN];
29153
29154 - struct access_method access;
29155 + struct access_method *access;
29156
29157 /* queue and queue Info */
29158 struct list_head reqQ;
29159 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29160 index 9125bbe..eede5c8 100644
29161 --- a/drivers/block/cpqarray.c
29162 +++ b/drivers/block/cpqarray.c
29163 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29164 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29165 goto Enomem4;
29166 }
29167 - hba[i]->access.set_intr_mask(hba[i], 0);
29168 + hba[i]->access->set_intr_mask(hba[i], 0);
29169 if (request_irq(hba[i]->intr, do_ida_intr,
29170 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29171 {
29172 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29173 add_timer(&hba[i]->timer);
29174
29175 /* Enable IRQ now that spinlock and rate limit timer are set up */
29176 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29177 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29178
29179 for(j=0; j<NWD; j++) {
29180 struct gendisk *disk = ida_gendisk[i][j];
29181 @@ -694,7 +694,7 @@ DBGINFO(
29182 for(i=0; i<NR_PRODUCTS; i++) {
29183 if (board_id == products[i].board_id) {
29184 c->product_name = products[i].product_name;
29185 - c->access = *(products[i].access);
29186 + c->access = products[i].access;
29187 break;
29188 }
29189 }
29190 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29191 hba[ctlr]->intr = intr;
29192 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29193 hba[ctlr]->product_name = products[j].product_name;
29194 - hba[ctlr]->access = *(products[j].access);
29195 + hba[ctlr]->access = products[j].access;
29196 hba[ctlr]->ctlr = ctlr;
29197 hba[ctlr]->board_id = board_id;
29198 hba[ctlr]->pci_dev = NULL; /* not PCI */
29199 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29200
29201 while((c = h->reqQ) != NULL) {
29202 /* Can't do anything if we're busy */
29203 - if (h->access.fifo_full(h) == 0)
29204 + if (h->access->fifo_full(h) == 0)
29205 return;
29206
29207 /* Get the first entry from the request Q */
29208 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29209 h->Qdepth--;
29210
29211 /* Tell the controller to do our bidding */
29212 - h->access.submit_command(h, c);
29213 + h->access->submit_command(h, c);
29214
29215 /* Get onto the completion Q */
29216 addQ(&h->cmpQ, c);
29217 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29218 unsigned long flags;
29219 __u32 a,a1;
29220
29221 - istat = h->access.intr_pending(h);
29222 + istat = h->access->intr_pending(h);
29223 /* Is this interrupt for us? */
29224 if (istat == 0)
29225 return IRQ_NONE;
29226 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29227 */
29228 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29229 if (istat & FIFO_NOT_EMPTY) {
29230 - while((a = h->access.command_completed(h))) {
29231 + while((a = h->access->command_completed(h))) {
29232 a1 = a; a &= ~3;
29233 if ((c = h->cmpQ) == NULL)
29234 {
29235 @@ -1449,11 +1449,11 @@ static int sendcmd(
29236 /*
29237 * Disable interrupt
29238 */
29239 - info_p->access.set_intr_mask(info_p, 0);
29240 + info_p->access->set_intr_mask(info_p, 0);
29241 /* Make sure there is room in the command FIFO */
29242 /* Actually it should be completely empty at this time. */
29243 for (i = 200000; i > 0; i--) {
29244 - temp = info_p->access.fifo_full(info_p);
29245 + temp = info_p->access->fifo_full(info_p);
29246 if (temp != 0) {
29247 break;
29248 }
29249 @@ -1466,7 +1466,7 @@ DBG(
29250 /*
29251 * Send the cmd
29252 */
29253 - info_p->access.submit_command(info_p, c);
29254 + info_p->access->submit_command(info_p, c);
29255 complete = pollcomplete(ctlr);
29256
29257 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29258 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29259 * we check the new geometry. Then turn interrupts back on when
29260 * we're done.
29261 */
29262 - host->access.set_intr_mask(host, 0);
29263 + host->access->set_intr_mask(host, 0);
29264 getgeometry(ctlr);
29265 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29266 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29267
29268 for(i=0; i<NWD; i++) {
29269 struct gendisk *disk = ida_gendisk[ctlr][i];
29270 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29271 /* Wait (up to 2 seconds) for a command to complete */
29272
29273 for (i = 200000; i > 0; i--) {
29274 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29275 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29276 if (done == 0) {
29277 udelay(10); /* a short fixed delay */
29278 } else
29279 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29280 index be73e9d..7fbf140 100644
29281 --- a/drivers/block/cpqarray.h
29282 +++ b/drivers/block/cpqarray.h
29283 @@ -99,7 +99,7 @@ struct ctlr_info {
29284 drv_info_t drv[NWD];
29285 struct proc_dir_entry *proc;
29286
29287 - struct access_method access;
29288 + struct access_method *access;
29289
29290 cmdlist_t *reqQ;
29291 cmdlist_t *cmpQ;
29292 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29293 index b953cc7..e3dc580 100644
29294 --- a/drivers/block/drbd/drbd_int.h
29295 +++ b/drivers/block/drbd/drbd_int.h
29296 @@ -735,7 +735,7 @@ struct drbd_request;
29297 struct drbd_epoch {
29298 struct list_head list;
29299 unsigned int barrier_nr;
29300 - atomic_t epoch_size; /* increased on every request added. */
29301 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29302 atomic_t active; /* increased on every req. added, and dec on every finished. */
29303 unsigned long flags;
29304 };
29305 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29306 void *int_dig_in;
29307 void *int_dig_vv;
29308 wait_queue_head_t seq_wait;
29309 - atomic_t packet_seq;
29310 + atomic_unchecked_t packet_seq;
29311 unsigned int peer_seq;
29312 spinlock_t peer_seq_lock;
29313 unsigned int minor;
29314 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29315
29316 static inline void drbd_tcp_cork(struct socket *sock)
29317 {
29318 - int __user val = 1;
29319 + int val = 1;
29320 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29321 - (char __user *)&val, sizeof(val));
29322 + (char __force_user *)&val, sizeof(val));
29323 }
29324
29325 static inline void drbd_tcp_uncork(struct socket *sock)
29326 {
29327 - int __user val = 0;
29328 + int val = 0;
29329 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29330 - (char __user *)&val, sizeof(val));
29331 + (char __force_user *)&val, sizeof(val));
29332 }
29333
29334 static inline void drbd_tcp_nodelay(struct socket *sock)
29335 {
29336 - int __user val = 1;
29337 + int val = 1;
29338 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29339 - (char __user *)&val, sizeof(val));
29340 + (char __force_user *)&val, sizeof(val));
29341 }
29342
29343 static inline void drbd_tcp_quickack(struct socket *sock)
29344 {
29345 - int __user val = 2;
29346 + int val = 2;
29347 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29348 - (char __user *)&val, sizeof(val));
29349 + (char __force_user *)&val, sizeof(val));
29350 }
29351
29352 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29353 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29354 index f93a032..71c87bf 100644
29355 --- a/drivers/block/drbd/drbd_main.c
29356 +++ b/drivers/block/drbd/drbd_main.c
29357 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29358 p.sector = sector;
29359 p.block_id = block_id;
29360 p.blksize = blksize;
29361 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29362 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29363
29364 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29365 return false;
29366 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29367
29368 p.sector = cpu_to_be64(req->sector);
29369 p.block_id = (unsigned long)req;
29370 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29371 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29372
29373 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29374
29375 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29376 atomic_set(&mdev->unacked_cnt, 0);
29377 atomic_set(&mdev->local_cnt, 0);
29378 atomic_set(&mdev->net_cnt, 0);
29379 - atomic_set(&mdev->packet_seq, 0);
29380 + atomic_set_unchecked(&mdev->packet_seq, 0);
29381 atomic_set(&mdev->pp_in_use, 0);
29382 atomic_set(&mdev->pp_in_use_by_net, 0);
29383 atomic_set(&mdev->rs_sect_in, 0);
29384 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29385 mdev->receiver.t_state);
29386
29387 /* no need to lock it, I'm the only thread alive */
29388 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29389 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29390 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29391 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29392 mdev->al_writ_cnt =
29393 mdev->bm_writ_cnt =
29394 mdev->read_cnt =
29395 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29396 index edb490a..ecd69da 100644
29397 --- a/drivers/block/drbd/drbd_nl.c
29398 +++ b/drivers/block/drbd/drbd_nl.c
29399 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29400 module_put(THIS_MODULE);
29401 }
29402
29403 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29404 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29405
29406 static unsigned short *
29407 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29408 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29409 cn_reply->id.idx = CN_IDX_DRBD;
29410 cn_reply->id.val = CN_VAL_DRBD;
29411
29412 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29413 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29414 cn_reply->ack = 0; /* not used here. */
29415 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29416 (int)((char *)tl - (char *)reply->tag_list);
29417 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29418 cn_reply->id.idx = CN_IDX_DRBD;
29419 cn_reply->id.val = CN_VAL_DRBD;
29420
29421 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29422 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29423 cn_reply->ack = 0; /* not used here. */
29424 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29425 (int)((char *)tl - (char *)reply->tag_list);
29426 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29427 cn_reply->id.idx = CN_IDX_DRBD;
29428 cn_reply->id.val = CN_VAL_DRBD;
29429
29430 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29431 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29432 cn_reply->ack = 0; // not used here.
29433 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29434 (int)((char*)tl - (char*)reply->tag_list);
29435 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29436 cn_reply->id.idx = CN_IDX_DRBD;
29437 cn_reply->id.val = CN_VAL_DRBD;
29438
29439 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29440 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29441 cn_reply->ack = 0; /* not used here. */
29442 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29443 (int)((char *)tl - (char *)reply->tag_list);
29444 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29445 index c74ca2d..860c819 100644
29446 --- a/drivers/block/drbd/drbd_receiver.c
29447 +++ b/drivers/block/drbd/drbd_receiver.c
29448 @@ -898,7 +898,7 @@ retry:
29449 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29450 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29451
29452 - atomic_set(&mdev->packet_seq, 0);
29453 + atomic_set_unchecked(&mdev->packet_seq, 0);
29454 mdev->peer_seq = 0;
29455
29456 if (drbd_send_protocol(mdev) == -1)
29457 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29458 do {
29459 next_epoch = NULL;
29460
29461 - epoch_size = atomic_read(&epoch->epoch_size);
29462 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29463
29464 switch (ev & ~EV_CLEANUP) {
29465 case EV_PUT:
29466 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29467 rv = FE_DESTROYED;
29468 } else {
29469 epoch->flags = 0;
29470 - atomic_set(&epoch->epoch_size, 0);
29471 + atomic_set_unchecked(&epoch->epoch_size, 0);
29472 /* atomic_set(&epoch->active, 0); is already zero */
29473 if (rv == FE_STILL_LIVE)
29474 rv = FE_RECYCLED;
29475 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29476 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29477 drbd_flush(mdev);
29478
29479 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29480 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29481 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29482 if (epoch)
29483 break;
29484 }
29485
29486 epoch = mdev->current_epoch;
29487 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29488 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29489
29490 D_ASSERT(atomic_read(&epoch->active) == 0);
29491 D_ASSERT(epoch->flags == 0);
29492 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29493 }
29494
29495 epoch->flags = 0;
29496 - atomic_set(&epoch->epoch_size, 0);
29497 + atomic_set_unchecked(&epoch->epoch_size, 0);
29498 atomic_set(&epoch->active, 0);
29499
29500 spin_lock(&mdev->epoch_lock);
29501 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29502 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29503 list_add(&epoch->list, &mdev->current_epoch->list);
29504 mdev->current_epoch = epoch;
29505 mdev->epochs++;
29506 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29507 spin_unlock(&mdev->peer_seq_lock);
29508
29509 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29510 - atomic_inc(&mdev->current_epoch->epoch_size);
29511 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29512 return drbd_drain_block(mdev, data_size);
29513 }
29514
29515 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29516
29517 spin_lock(&mdev->epoch_lock);
29518 e->epoch = mdev->current_epoch;
29519 - atomic_inc(&e->epoch->epoch_size);
29520 + atomic_inc_unchecked(&e->epoch->epoch_size);
29521 atomic_inc(&e->epoch->active);
29522 spin_unlock(&mdev->epoch_lock);
29523
29524 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29525 D_ASSERT(list_empty(&mdev->done_ee));
29526
29527 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29528 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29529 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29530 D_ASSERT(list_empty(&mdev->current_epoch->list));
29531 }
29532
29533 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29534 index 3bba655..6151b66 100644
29535 --- a/drivers/block/loop.c
29536 +++ b/drivers/block/loop.c
29537 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29538 mm_segment_t old_fs = get_fs();
29539
29540 set_fs(get_ds());
29541 - bw = file->f_op->write(file, buf, len, &pos);
29542 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29543 set_fs(old_fs);
29544 if (likely(bw == len))
29545 return 0;
29546 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29547 index ea6f632..eafb192 100644
29548 --- a/drivers/char/Kconfig
29549 +++ b/drivers/char/Kconfig
29550 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29551
29552 config DEVKMEM
29553 bool "/dev/kmem virtual device support"
29554 - default y
29555 + default n
29556 + depends on !GRKERNSEC_KMEM
29557 help
29558 Say Y here if you want to support the /dev/kmem device. The
29559 /dev/kmem device is rarely used, but can be used for certain
29560 @@ -581,6 +582,7 @@ config DEVPORT
29561 bool
29562 depends on !M68K
29563 depends on ISA || PCI
29564 + depends on !GRKERNSEC_KMEM
29565 default y
29566
29567 source "drivers/s390/char/Kconfig"
29568 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29569 index 2e04433..22afc64 100644
29570 --- a/drivers/char/agp/frontend.c
29571 +++ b/drivers/char/agp/frontend.c
29572 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29573 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29574 return -EFAULT;
29575
29576 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29577 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29578 return -EFAULT;
29579
29580 client = agp_find_client_by_pid(reserve.pid);
29581 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29582 index 21cb980..f15107c 100644
29583 --- a/drivers/char/genrtc.c
29584 +++ b/drivers/char/genrtc.c
29585 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29586 switch (cmd) {
29587
29588 case RTC_PLL_GET:
29589 + memset(&pll, 0, sizeof(pll));
29590 if (get_rtc_pll(&pll))
29591 return -EINVAL;
29592 else
29593 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29594 index dfd7876..c0b0885 100644
29595 --- a/drivers/char/hpet.c
29596 +++ b/drivers/char/hpet.c
29597 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29598 }
29599
29600 static int
29601 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29602 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29603 struct hpet_info *info)
29604 {
29605 struct hpet_timer __iomem *timer;
29606 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29607 index 2c29942..604c5ba 100644
29608 --- a/drivers/char/ipmi/ipmi_msghandler.c
29609 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29610 @@ -420,7 +420,7 @@ struct ipmi_smi {
29611 struct proc_dir_entry *proc_dir;
29612 char proc_dir_name[10];
29613
29614 - atomic_t stats[IPMI_NUM_STATS];
29615 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29616
29617 /*
29618 * run_to_completion duplicate of smb_info, smi_info
29619 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29620
29621
29622 #define ipmi_inc_stat(intf, stat) \
29623 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29624 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29625 #define ipmi_get_stat(intf, stat) \
29626 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29627 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29628
29629 static int is_lan_addr(struct ipmi_addr *addr)
29630 {
29631 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29632 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29633 init_waitqueue_head(&intf->waitq);
29634 for (i = 0; i < IPMI_NUM_STATS; i++)
29635 - atomic_set(&intf->stats[i], 0);
29636 + atomic_set_unchecked(&intf->stats[i], 0);
29637
29638 intf->proc_dir = NULL;
29639
29640 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29641 index 83f85cf..279e63f 100644
29642 --- a/drivers/char/ipmi/ipmi_si_intf.c
29643 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29644 @@ -275,7 +275,7 @@ struct smi_info {
29645 unsigned char slave_addr;
29646
29647 /* Counters and things for the proc filesystem. */
29648 - atomic_t stats[SI_NUM_STATS];
29649 + atomic_unchecked_t stats[SI_NUM_STATS];
29650
29651 struct task_struct *thread;
29652
29653 @@ -284,9 +284,9 @@ struct smi_info {
29654 };
29655
29656 #define smi_inc_stat(smi, stat) \
29657 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29658 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29659 #define smi_get_stat(smi, stat) \
29660 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29661 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29662
29663 #define SI_MAX_PARMS 4
29664
29665 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29666 atomic_set(&new_smi->req_events, 0);
29667 new_smi->run_to_completion = 0;
29668 for (i = 0; i < SI_NUM_STATS; i++)
29669 - atomic_set(&new_smi->stats[i], 0);
29670 + atomic_set_unchecked(&new_smi->stats[i], 0);
29671
29672 new_smi->interrupt_disabled = 1;
29673 atomic_set(&new_smi->stop_operation, 0);
29674 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29675 index 47ff7e4..0c7d340 100644
29676 --- a/drivers/char/mbcs.c
29677 +++ b/drivers/char/mbcs.c
29678 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29679 return 0;
29680 }
29681
29682 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29683 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29684 {
29685 .part_num = MBCS_PART_NUM,
29686 .mfg_num = MBCS_MFG_NUM,
29687 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29688 index e5eedfa..fcab50ea 100644
29689 --- a/drivers/char/mem.c
29690 +++ b/drivers/char/mem.c
29691 @@ -18,6 +18,7 @@
29692 #include <linux/raw.h>
29693 #include <linux/tty.h>
29694 #include <linux/capability.h>
29695 +#include <linux/security.h>
29696 #include <linux/ptrace.h>
29697 #include <linux/device.h>
29698 #include <linux/highmem.h>
29699 @@ -37,6 +38,10 @@
29700
29701 #define DEVPORT_MINOR 4
29702
29703 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29704 +extern const struct file_operations grsec_fops;
29705 +#endif
29706 +
29707 static inline unsigned long size_inside_page(unsigned long start,
29708 unsigned long size)
29709 {
29710 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29711
29712 while (cursor < to) {
29713 if (!devmem_is_allowed(pfn)) {
29714 +#ifdef CONFIG_GRKERNSEC_KMEM
29715 + gr_handle_mem_readwrite(from, to);
29716 +#else
29717 printk(KERN_INFO
29718 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29719 current->comm, from, to);
29720 +#endif
29721 return 0;
29722 }
29723 cursor += PAGE_SIZE;
29724 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29725 }
29726 return 1;
29727 }
29728 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29729 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29730 +{
29731 + return 0;
29732 +}
29733 #else
29734 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29735 {
29736 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29737
29738 while (count > 0) {
29739 unsigned long remaining;
29740 + char *temp;
29741
29742 sz = size_inside_page(p, count);
29743
29744 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29745 if (!ptr)
29746 return -EFAULT;
29747
29748 - remaining = copy_to_user(buf, ptr, sz);
29749 +#ifdef CONFIG_PAX_USERCOPY
29750 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29751 + if (!temp) {
29752 + unxlate_dev_mem_ptr(p, ptr);
29753 + return -ENOMEM;
29754 + }
29755 + memcpy(temp, ptr, sz);
29756 +#else
29757 + temp = ptr;
29758 +#endif
29759 +
29760 + remaining = copy_to_user(buf, temp, sz);
29761 +
29762 +#ifdef CONFIG_PAX_USERCOPY
29763 + kfree(temp);
29764 +#endif
29765 +
29766 unxlate_dev_mem_ptr(p, ptr);
29767 if (remaining)
29768 return -EFAULT;
29769 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29770 size_t count, loff_t *ppos)
29771 {
29772 unsigned long p = *ppos;
29773 - ssize_t low_count, read, sz;
29774 + ssize_t low_count, read, sz, err = 0;
29775 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29776 - int err = 0;
29777
29778 read = 0;
29779 if (p < (unsigned long) high_memory) {
29780 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29781 }
29782 #endif
29783 while (low_count > 0) {
29784 + char *temp;
29785 +
29786 sz = size_inside_page(p, low_count);
29787
29788 /*
29789 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29790 */
29791 kbuf = xlate_dev_kmem_ptr((char *)p);
29792
29793 - if (copy_to_user(buf, kbuf, sz))
29794 +#ifdef CONFIG_PAX_USERCOPY
29795 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29796 + if (!temp)
29797 + return -ENOMEM;
29798 + memcpy(temp, kbuf, sz);
29799 +#else
29800 + temp = kbuf;
29801 +#endif
29802 +
29803 + err = copy_to_user(buf, temp, sz);
29804 +
29805 +#ifdef CONFIG_PAX_USERCOPY
29806 + kfree(temp);
29807 +#endif
29808 +
29809 + if (err)
29810 return -EFAULT;
29811 buf += sz;
29812 p += sz;
29813 @@ -833,6 +880,9 @@ static const struct memdev {
29814 #ifdef CONFIG_CRASH_DUMP
29815 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29816 #endif
29817 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29818 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29819 +#endif
29820 };
29821
29822 static int memory_open(struct inode *inode, struct file *filp)
29823 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29824 index 9df78e2..01ba9ae 100644
29825 --- a/drivers/char/nvram.c
29826 +++ b/drivers/char/nvram.c
29827 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29828
29829 spin_unlock_irq(&rtc_lock);
29830
29831 - if (copy_to_user(buf, contents, tmp - contents))
29832 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29833 return -EFAULT;
29834
29835 *ppos = i;
29836 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29837 index 0a484b4..f48ccd1 100644
29838 --- a/drivers/char/pcmcia/synclink_cs.c
29839 +++ b/drivers/char/pcmcia/synclink_cs.c
29840 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29841
29842 if (debug_level >= DEBUG_LEVEL_INFO)
29843 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29844 - __FILE__,__LINE__, info->device_name, port->count);
29845 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29846
29847 - WARN_ON(!port->count);
29848 + WARN_ON(!atomic_read(&port->count));
29849
29850 if (tty_port_close_start(port, tty, filp) == 0)
29851 goto cleanup;
29852 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29853 cleanup:
29854 if (debug_level >= DEBUG_LEVEL_INFO)
29855 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29856 - tty->driver->name, port->count);
29857 + tty->driver->name, atomic_read(&port->count));
29858 }
29859
29860 /* Wait until the transmitter is empty.
29861 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29862
29863 if (debug_level >= DEBUG_LEVEL_INFO)
29864 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29865 - __FILE__,__LINE__,tty->driver->name, port->count);
29866 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29867
29868 /* If port is closing, signal caller to try again */
29869 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29870 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29871 goto cleanup;
29872 }
29873 spin_lock(&port->lock);
29874 - port->count++;
29875 + atomic_inc(&port->count);
29876 spin_unlock(&port->lock);
29877 spin_unlock_irqrestore(&info->netlock, flags);
29878
29879 - if (port->count == 1) {
29880 + if (atomic_read(&port->count) == 1) {
29881 /* 1st open on this device, init hardware */
29882 retval = startup(info, tty);
29883 if (retval < 0)
29884 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29885 unsigned short new_crctype;
29886
29887 /* return error if TTY interface open */
29888 - if (info->port.count)
29889 + if (atomic_read(&info->port.count))
29890 return -EBUSY;
29891
29892 switch (encoding)
29893 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29894
29895 /* arbitrate between network and tty opens */
29896 spin_lock_irqsave(&info->netlock, flags);
29897 - if (info->port.count != 0 || info->netcount != 0) {
29898 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29899 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29900 spin_unlock_irqrestore(&info->netlock, flags);
29901 return -EBUSY;
29902 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29903 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29904
29905 /* return error if TTY interface open */
29906 - if (info->port.count)
29907 + if (atomic_read(&info->port.count))
29908 return -EBUSY;
29909
29910 if (cmd != SIOCWANDEV)
29911 diff --git a/drivers/char/random.c b/drivers/char/random.c
29912 index b86eae9..4192a7a 100644
29913 --- a/drivers/char/random.c
29914 +++ b/drivers/char/random.c
29915 @@ -272,8 +272,13 @@
29916 /*
29917 * Configuration information
29918 */
29919 +#ifdef CONFIG_GRKERNSEC_RANDNET
29920 +#define INPUT_POOL_WORDS 512
29921 +#define OUTPUT_POOL_WORDS 128
29922 +#else
29923 #define INPUT_POOL_WORDS 128
29924 #define OUTPUT_POOL_WORDS 32
29925 +#endif
29926 #define SEC_XFER_SIZE 512
29927 #define EXTRACT_SIZE 10
29928
29929 @@ -313,10 +318,17 @@ static struct poolinfo {
29930 int poolwords;
29931 int tap1, tap2, tap3, tap4, tap5;
29932 } poolinfo_table[] = {
29933 +#ifdef CONFIG_GRKERNSEC_RANDNET
29934 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29935 + { 512, 411, 308, 208, 104, 1 },
29936 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29937 + { 128, 103, 76, 51, 25, 1 },
29938 +#else
29939 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29940 { 128, 103, 76, 51, 25, 1 },
29941 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29942 { 32, 26, 20, 14, 7, 1 },
29943 +#endif
29944 #if 0
29945 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29946 { 2048, 1638, 1231, 819, 411, 1 },
29947 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29948 input_rotate += i ? 7 : 14;
29949 }
29950
29951 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29952 - ACCESS_ONCE(r->add_ptr) = i;
29953 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29954 + ACCESS_ONCE_RW(r->add_ptr) = i;
29955 smp_wmb();
29956
29957 if (out)
29958 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29959 }
29960 #endif
29961
29962 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29963 +u64 latent_entropy;
29964 +
29965 +__init void transfer_latent_entropy(void)
29966 +{
29967 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29968 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29969 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29970 +}
29971 +#endif
29972 +
29973 /*********************************************************************
29974 *
29975 * Entropy extraction routines
29976 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29977
29978 extract_buf(r, tmp);
29979 i = min_t(int, nbytes, EXTRACT_SIZE);
29980 - if (copy_to_user(buf, tmp, i)) {
29981 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29982 ret = -EFAULT;
29983 break;
29984 }
29985 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29986 #include <linux/sysctl.h>
29987
29988 static int min_read_thresh = 8, min_write_thresh;
29989 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29990 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29991 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29992 static char sysctl_bootid[16];
29993
29994 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29995 index f877805..403375a 100644
29996 --- a/drivers/char/sonypi.c
29997 +++ b/drivers/char/sonypi.c
29998 @@ -54,6 +54,7 @@
29999
30000 #include <asm/uaccess.h>
30001 #include <asm/io.h>
30002 +#include <asm/local.h>
30003
30004 #include <linux/sonypi.h>
30005
30006 @@ -490,7 +491,7 @@ static struct sonypi_device {
30007 spinlock_t fifo_lock;
30008 wait_queue_head_t fifo_proc_list;
30009 struct fasync_struct *fifo_async;
30010 - int open_count;
30011 + local_t open_count;
30012 int model;
30013 struct input_dev *input_jog_dev;
30014 struct input_dev *input_key_dev;
30015 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30016 static int sonypi_misc_release(struct inode *inode, struct file *file)
30017 {
30018 mutex_lock(&sonypi_device.lock);
30019 - sonypi_device.open_count--;
30020 + local_dec(&sonypi_device.open_count);
30021 mutex_unlock(&sonypi_device.lock);
30022 return 0;
30023 }
30024 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30025 {
30026 mutex_lock(&sonypi_device.lock);
30027 /* Flush input queue on first open */
30028 - if (!sonypi_device.open_count)
30029 + if (!local_read(&sonypi_device.open_count))
30030 kfifo_reset(&sonypi_device.fifo);
30031 - sonypi_device.open_count++;
30032 + local_inc(&sonypi_device.open_count);
30033 mutex_unlock(&sonypi_device.lock);
30034
30035 return 0;
30036 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30037 index 4dc8024..90108d1 100644
30038 --- a/drivers/char/tpm/tpm.c
30039 +++ b/drivers/char/tpm/tpm.c
30040 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30041 chip->vendor.req_complete_val)
30042 goto out_recv;
30043
30044 - if ((status == chip->vendor.req_canceled)) {
30045 + if (status == chip->vendor.req_canceled) {
30046 dev_err(chip->dev, "Operation Canceled\n");
30047 rc = -ECANCELED;
30048 goto out;
30049 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30050 index 0636520..169c1d0 100644
30051 --- a/drivers/char/tpm/tpm_bios.c
30052 +++ b/drivers/char/tpm/tpm_bios.c
30053 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30054 event = addr;
30055
30056 if ((event->event_type == 0 && event->event_size == 0) ||
30057 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30058 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30059 return NULL;
30060
30061 return addr;
30062 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30063 return NULL;
30064
30065 if ((event->event_type == 0 && event->event_size == 0) ||
30066 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30067 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30068 return NULL;
30069
30070 (*pos)++;
30071 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30072 int i;
30073
30074 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30075 - seq_putc(m, data[i]);
30076 + if (!seq_putc(m, data[i]))
30077 + return -EFAULT;
30078
30079 return 0;
30080 }
30081 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30082 log->bios_event_log_end = log->bios_event_log + len;
30083
30084 virt = acpi_os_map_memory(start, len);
30085 + if (!virt) {
30086 + kfree(log->bios_event_log);
30087 + log->bios_event_log = NULL;
30088 + return -EFAULT;
30089 + }
30090
30091 - memcpy(log->bios_event_log, virt, len);
30092 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30093
30094 acpi_os_unmap_memory(virt, len);
30095 return 0;
30096 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30097 index cdf2f54..e55c197 100644
30098 --- a/drivers/char/virtio_console.c
30099 +++ b/drivers/char/virtio_console.c
30100 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30101 if (to_user) {
30102 ssize_t ret;
30103
30104 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30105 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30106 if (ret)
30107 return -EFAULT;
30108 } else {
30109 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30110 if (!port_has_data(port) && !port->host_connected)
30111 return 0;
30112
30113 - return fill_readbuf(port, ubuf, count, true);
30114 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30115 }
30116
30117 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30118 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30119 index e164c55..3aabb50 100644
30120 --- a/drivers/edac/edac_pci_sysfs.c
30121 +++ b/drivers/edac/edac_pci_sysfs.c
30122 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30123 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30124 static int edac_pci_poll_msec = 1000; /* one second workq period */
30125
30126 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30127 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30128 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30129 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30130
30131 static struct kobject *edac_pci_top_main_kobj;
30132 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30133 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30134 edac_printk(KERN_CRIT, EDAC_PCI,
30135 "Signaled System Error on %s\n",
30136 pci_name(dev));
30137 - atomic_inc(&pci_nonparity_count);
30138 + atomic_inc_unchecked(&pci_nonparity_count);
30139 }
30140
30141 if (status & (PCI_STATUS_PARITY)) {
30142 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30143 "Master Data Parity Error on %s\n",
30144 pci_name(dev));
30145
30146 - atomic_inc(&pci_parity_count);
30147 + atomic_inc_unchecked(&pci_parity_count);
30148 }
30149
30150 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30151 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30152 "Detected Parity Error on %s\n",
30153 pci_name(dev));
30154
30155 - atomic_inc(&pci_parity_count);
30156 + atomic_inc_unchecked(&pci_parity_count);
30157 }
30158 }
30159
30160 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30161 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30162 "Signaled System Error on %s\n",
30163 pci_name(dev));
30164 - atomic_inc(&pci_nonparity_count);
30165 + atomic_inc_unchecked(&pci_nonparity_count);
30166 }
30167
30168 if (status & (PCI_STATUS_PARITY)) {
30169 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30170 "Master Data Parity Error on "
30171 "%s\n", pci_name(dev));
30172
30173 - atomic_inc(&pci_parity_count);
30174 + atomic_inc_unchecked(&pci_parity_count);
30175 }
30176
30177 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30178 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30179 "Detected Parity Error on %s\n",
30180 pci_name(dev));
30181
30182 - atomic_inc(&pci_parity_count);
30183 + atomic_inc_unchecked(&pci_parity_count);
30184 }
30185 }
30186 }
30187 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30188 if (!check_pci_errors)
30189 return;
30190
30191 - before_count = atomic_read(&pci_parity_count);
30192 + before_count = atomic_read_unchecked(&pci_parity_count);
30193
30194 /* scan all PCI devices looking for a Parity Error on devices and
30195 * bridges.
30196 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30197 /* Only if operator has selected panic on PCI Error */
30198 if (edac_pci_get_panic_on_pe()) {
30199 /* If the count is different 'after' from 'before' */
30200 - if (before_count != atomic_read(&pci_parity_count))
30201 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30202 panic("EDAC: PCI Parity Error");
30203 }
30204 }
30205 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30206 index 8c87a5e..a19cbd7 100644
30207 --- a/drivers/edac/mce_amd.h
30208 +++ b/drivers/edac/mce_amd.h
30209 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30210 struct amd_decoder_ops {
30211 bool (*dc_mce)(u16, u8);
30212 bool (*ic_mce)(u16, u8);
30213 -};
30214 +} __no_const;
30215
30216 void amd_report_gart_errors(bool);
30217 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30218 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30219 index 57ea7f4..789e3c3 100644
30220 --- a/drivers/firewire/core-card.c
30221 +++ b/drivers/firewire/core-card.c
30222 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30223
30224 void fw_core_remove_card(struct fw_card *card)
30225 {
30226 - struct fw_card_driver dummy_driver = dummy_driver_template;
30227 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30228
30229 card->driver->update_phy_reg(card, 4,
30230 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30231 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30232 index f8d2287..5aaf4db 100644
30233 --- a/drivers/firewire/core-cdev.c
30234 +++ b/drivers/firewire/core-cdev.c
30235 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30236 int ret;
30237
30238 if ((request->channels == 0 && request->bandwidth == 0) ||
30239 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30240 - request->bandwidth < 0)
30241 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30242 return -EINVAL;
30243
30244 r = kmalloc(sizeof(*r), GFP_KERNEL);
30245 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30246 index 87d6f2d..5bf9d90 100644
30247 --- a/drivers/firewire/core-transaction.c
30248 +++ b/drivers/firewire/core-transaction.c
30249 @@ -37,6 +37,7 @@
30250 #include <linux/timer.h>
30251 #include <linux/types.h>
30252 #include <linux/workqueue.h>
30253 +#include <linux/sched.h>
30254
30255 #include <asm/byteorder.h>
30256
30257 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30258 index 515a42c..5ecf3ba 100644
30259 --- a/drivers/firewire/core.h
30260 +++ b/drivers/firewire/core.h
30261 @@ -111,6 +111,7 @@ struct fw_card_driver {
30262
30263 int (*stop_iso)(struct fw_iso_context *ctx);
30264 };
30265 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30266
30267 void fw_card_initialize(struct fw_card *card,
30268 const struct fw_card_driver *driver, struct device *device);
30269 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30270 index b298158..7ed8432 100644
30271 --- a/drivers/firmware/dmi_scan.c
30272 +++ b/drivers/firmware/dmi_scan.c
30273 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30274 }
30275 }
30276 else {
30277 - /*
30278 - * no iounmap() for that ioremap(); it would be a no-op, but
30279 - * it's so early in setup that sucker gets confused into doing
30280 - * what it shouldn't if we actually call it.
30281 - */
30282 p = dmi_ioremap(0xF0000, 0x10000);
30283 if (p == NULL)
30284 goto error;
30285 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30286 if (buf == NULL)
30287 return -1;
30288
30289 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30290 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30291
30292 iounmap(buf);
30293 return 0;
30294 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30295 index 82d5c20..44a7177 100644
30296 --- a/drivers/gpio/gpio-vr41xx.c
30297 +++ b/drivers/gpio/gpio-vr41xx.c
30298 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30299 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30300 maskl, pendl, maskh, pendh);
30301
30302 - atomic_inc(&irq_err_count);
30303 + atomic_inc_unchecked(&irq_err_count);
30304
30305 return -EINVAL;
30306 }
30307 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30308 index 3252e70..b5314ace 100644
30309 --- a/drivers/gpu/drm/drm_crtc_helper.c
30310 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30311 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30312 struct drm_crtc *tmp;
30313 int crtc_mask = 1;
30314
30315 - WARN(!crtc, "checking null crtc?\n");
30316 + BUG_ON(!crtc);
30317
30318 dev = crtc->dev;
30319
30320 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30321 index 9238de4..a27c72a 100644
30322 --- a/drivers/gpu/drm/drm_drv.c
30323 +++ b/drivers/gpu/drm/drm_drv.c
30324 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30325 /**
30326 * Copy and IOCTL return string to user space
30327 */
30328 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30329 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30330 {
30331 int len;
30332
30333 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30334 return -ENODEV;
30335
30336 atomic_inc(&dev->ioctl_count);
30337 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30338 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30339 ++file_priv->ioctl_count;
30340
30341 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30342 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30343 index 5062eec..4e3e51f 100644
30344 --- a/drivers/gpu/drm/drm_fops.c
30345 +++ b/drivers/gpu/drm/drm_fops.c
30346 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30347 }
30348
30349 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30350 - atomic_set(&dev->counts[i], 0);
30351 + atomic_set_unchecked(&dev->counts[i], 0);
30352
30353 dev->sigdata.lock = NULL;
30354
30355 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30356
30357 retcode = drm_open_helper(inode, filp, dev);
30358 if (!retcode) {
30359 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30360 - if (!dev->open_count++)
30361 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30362 + if (local_inc_return(&dev->open_count) == 1)
30363 retcode = drm_setup(dev);
30364 }
30365 if (!retcode) {
30366 @@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30367
30368 mutex_lock(&drm_global_mutex);
30369
30370 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30371 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30372
30373 if (dev->driver->preclose)
30374 dev->driver->preclose(dev, file_priv);
30375 @@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30376 * Begin inline drm_release
30377 */
30378
30379 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30380 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30381 task_pid_nr(current),
30382 (long)old_encode_dev(file_priv->minor->device),
30383 - dev->open_count);
30384 + local_read(&dev->open_count));
30385
30386 /* Release any auth tokens that might point to this file_priv,
30387 (do that under the drm_global_mutex) */
30388 @@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30389 * End inline drm_release
30390 */
30391
30392 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30393 - if (!--dev->open_count) {
30394 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30395 + if (local_dec_and_test(&dev->open_count)) {
30396 if (atomic_read(&dev->ioctl_count)) {
30397 DRM_ERROR("Device busy: %d\n",
30398 atomic_read(&dev->ioctl_count));
30399 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30400 index c87dc96..326055d 100644
30401 --- a/drivers/gpu/drm/drm_global.c
30402 +++ b/drivers/gpu/drm/drm_global.c
30403 @@ -36,7 +36,7 @@
30404 struct drm_global_item {
30405 struct mutex mutex;
30406 void *object;
30407 - int refcount;
30408 + atomic_t refcount;
30409 };
30410
30411 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30412 @@ -49,7 +49,7 @@ void drm_global_init(void)
30413 struct drm_global_item *item = &glob[i];
30414 mutex_init(&item->mutex);
30415 item->object = NULL;
30416 - item->refcount = 0;
30417 + atomic_set(&item->refcount, 0);
30418 }
30419 }
30420
30421 @@ -59,7 +59,7 @@ void drm_global_release(void)
30422 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30423 struct drm_global_item *item = &glob[i];
30424 BUG_ON(item->object != NULL);
30425 - BUG_ON(item->refcount != 0);
30426 + BUG_ON(atomic_read(&item->refcount) != 0);
30427 }
30428 }
30429
30430 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30431 void *object;
30432
30433 mutex_lock(&item->mutex);
30434 - if (item->refcount == 0) {
30435 + if (atomic_read(&item->refcount) == 0) {
30436 item->object = kzalloc(ref->size, GFP_KERNEL);
30437 if (unlikely(item->object == NULL)) {
30438 ret = -ENOMEM;
30439 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30440 goto out_err;
30441
30442 }
30443 - ++item->refcount;
30444 + atomic_inc(&item->refcount);
30445 ref->object = item->object;
30446 object = item->object;
30447 mutex_unlock(&item->mutex);
30448 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30449 struct drm_global_item *item = &glob[ref->global_type];
30450
30451 mutex_lock(&item->mutex);
30452 - BUG_ON(item->refcount == 0);
30453 + BUG_ON(atomic_read(&item->refcount) == 0);
30454 BUG_ON(ref->object != item->object);
30455 - if (--item->refcount == 0) {
30456 + if (atomic_dec_and_test(&item->refcount)) {
30457 ref->release(ref);
30458 item->object = NULL;
30459 }
30460 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30461 index 8928edb..0c79258 100644
30462 --- a/drivers/gpu/drm/drm_info.c
30463 +++ b/drivers/gpu/drm/drm_info.c
30464 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30465 struct drm_local_map *map;
30466 struct drm_map_list *r_list;
30467
30468 - /* Hardcoded from _DRM_FRAME_BUFFER,
30469 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30470 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30471 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30472 + static const char * const types[] = {
30473 + [_DRM_FRAME_BUFFER] = "FB",
30474 + [_DRM_REGISTERS] = "REG",
30475 + [_DRM_SHM] = "SHM",
30476 + [_DRM_AGP] = "AGP",
30477 + [_DRM_SCATTER_GATHER] = "SG",
30478 + [_DRM_CONSISTENT] = "PCI",
30479 + [_DRM_GEM] = "GEM" };
30480 const char *type;
30481 int i;
30482
30483 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30484 map = r_list->map;
30485 if (!map)
30486 continue;
30487 - if (map->type < 0 || map->type > 5)
30488 + if (map->type >= ARRAY_SIZE(types))
30489 type = "??";
30490 else
30491 type = types[map->type];
30492 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30493 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30494 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30495 vma->vm_flags & VM_IO ? 'i' : '-',
30496 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30497 + 0);
30498 +#else
30499 vma->vm_pgoff);
30500 +#endif
30501
30502 #if defined(__i386__)
30503 pgprot = pgprot_val(vma->vm_page_prot);
30504 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30505 index 637fcc3..e890b33 100644
30506 --- a/drivers/gpu/drm/drm_ioc32.c
30507 +++ b/drivers/gpu/drm/drm_ioc32.c
30508 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30509 request = compat_alloc_user_space(nbytes);
30510 if (!access_ok(VERIFY_WRITE, request, nbytes))
30511 return -EFAULT;
30512 - list = (struct drm_buf_desc *) (request + 1);
30513 + list = (struct drm_buf_desc __user *) (request + 1);
30514
30515 if (__put_user(count, &request->count)
30516 || __put_user(list, &request->list))
30517 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30518 request = compat_alloc_user_space(nbytes);
30519 if (!access_ok(VERIFY_WRITE, request, nbytes))
30520 return -EFAULT;
30521 - list = (struct drm_buf_pub *) (request + 1);
30522 + list = (struct drm_buf_pub __user *) (request + 1);
30523
30524 if (__put_user(count, &request->count)
30525 || __put_user(list, &request->list))
30526 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30527 index 64a62c6..ceab35e 100644
30528 --- a/drivers/gpu/drm/drm_ioctl.c
30529 +++ b/drivers/gpu/drm/drm_ioctl.c
30530 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30531 stats->data[i].value =
30532 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30533 else
30534 - stats->data[i].value = atomic_read(&dev->counts[i]);
30535 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30536 stats->data[i].type = dev->types[i];
30537 }
30538
30539 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30540 index 3203955..c8090af 100644
30541 --- a/drivers/gpu/drm/drm_lock.c
30542 +++ b/drivers/gpu/drm/drm_lock.c
30543 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30544 if (drm_lock_take(&master->lock, lock->context)) {
30545 master->lock.file_priv = file_priv;
30546 master->lock.lock_time = jiffies;
30547 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30548 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30549 break; /* Got lock */
30550 }
30551
30552 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30553 return -EINVAL;
30554 }
30555
30556 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30557 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30558
30559 if (drm_lock_free(&master->lock, lock->context)) {
30560 /* FIXME: Should really bail out here. */
30561 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30562 index 21bcd4a..8e074e0 100644
30563 --- a/drivers/gpu/drm/drm_stub.c
30564 +++ b/drivers/gpu/drm/drm_stub.c
30565 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30566
30567 drm_device_set_unplugged(dev);
30568
30569 - if (dev->open_count == 0) {
30570 + if (local_read(&dev->open_count) == 0) {
30571 drm_put_dev(dev);
30572 }
30573 mutex_unlock(&drm_global_mutex);
30574 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30575 index 463ec68..f5bd2b5 100644
30576 --- a/drivers/gpu/drm/i810/i810_dma.c
30577 +++ b/drivers/gpu/drm/i810/i810_dma.c
30578 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30579 dma->buflist[vertex->idx],
30580 vertex->discard, vertex->used);
30581
30582 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30583 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30584 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30585 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30586 sarea_priv->last_enqueue = dev_priv->counter - 1;
30587 sarea_priv->last_dispatch = (int)hw_status[5];
30588
30589 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30590 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30591 mc->last_render);
30592
30593 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30594 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30595 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30596 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30597 sarea_priv->last_enqueue = dev_priv->counter - 1;
30598 sarea_priv->last_dispatch = (int)hw_status[5];
30599
30600 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30601 index 6e0acad..93c8289 100644
30602 --- a/drivers/gpu/drm/i810/i810_drv.h
30603 +++ b/drivers/gpu/drm/i810/i810_drv.h
30604 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30605 int page_flipping;
30606
30607 wait_queue_head_t irq_queue;
30608 - atomic_t irq_received;
30609 - atomic_t irq_emitted;
30610 + atomic_unchecked_t irq_received;
30611 + atomic_unchecked_t irq_emitted;
30612
30613 int front_offset;
30614 } drm_i810_private_t;
30615 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30616 index 359f6e8..ada68fd 100644
30617 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30618 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30619 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30620 I915_READ(GTIMR));
30621 }
30622 seq_printf(m, "Interrupts received: %d\n",
30623 - atomic_read(&dev_priv->irq_received));
30624 + atomic_read_unchecked(&dev_priv->irq_received));
30625 for (i = 0; i < I915_NUM_RINGS; i++) {
30626 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30627 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30628 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30629 index 914c0df..d47d380 100644
30630 --- a/drivers/gpu/drm/i915/i915_dma.c
30631 +++ b/drivers/gpu/drm/i915/i915_dma.c
30632 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30633 bool can_switch;
30634
30635 spin_lock(&dev->count_lock);
30636 - can_switch = (dev->open_count == 0);
30637 + can_switch = (local_read(&dev->open_count) == 0);
30638 spin_unlock(&dev->count_lock);
30639 return can_switch;
30640 }
30641 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30642 index 627fe35..c9a7346 100644
30643 --- a/drivers/gpu/drm/i915/i915_drv.h
30644 +++ b/drivers/gpu/drm/i915/i915_drv.h
30645 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30646 /* render clock increase/decrease */
30647 /* display clock increase/decrease */
30648 /* pll clock increase/decrease */
30649 -};
30650 +} __no_const;
30651
30652 struct drm_i915_gt_funcs {
30653 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30654 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30655 -};
30656 +} __no_const;
30657
30658 struct intel_device_info {
30659 u8 gen;
30660 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30661 int current_page;
30662 int page_flipping;
30663
30664 - atomic_t irq_received;
30665 + atomic_unchecked_t irq_received;
30666
30667 /* protects the irq masks */
30668 spinlock_t irq_lock;
30669 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30670 * will be page flipped away on the next vblank. When it
30671 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30672 */
30673 - atomic_t pending_flip;
30674 + atomic_unchecked_t pending_flip;
30675 };
30676
30677 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30678 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30679 struct drm_i915_private *dev_priv, unsigned port);
30680 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30681 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30682 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30683 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30684 {
30685 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30686 }
30687 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30688 index cdf46b5..e785624 100644
30689 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30690 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30691 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30692 i915_gem_clflush_object(obj);
30693
30694 if (obj->base.pending_write_domain)
30695 - cd->flips |= atomic_read(&obj->pending_flip);
30696 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30697
30698 /* The actual obj->write_domain will be updated with
30699 * pending_write_domain after we emit the accumulated flush for all
30700 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30701
30702 static int
30703 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30704 - int count)
30705 + unsigned int count)
30706 {
30707 - int i;
30708 + unsigned int i;
30709
30710 for (i = 0; i < count; i++) {
30711 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30712 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30713 index 73fa3e1..ab2e9b9 100644
30714 --- a/drivers/gpu/drm/i915/i915_irq.c
30715 +++ b/drivers/gpu/drm/i915/i915_irq.c
30716 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30717 u32 pipe_stats[I915_MAX_PIPES];
30718 bool blc_event;
30719
30720 - atomic_inc(&dev_priv->irq_received);
30721 + atomic_inc_unchecked(&dev_priv->irq_received);
30722
30723 while (true) {
30724 iir = I915_READ(VLV_IIR);
30725 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30726 irqreturn_t ret = IRQ_NONE;
30727 int i;
30728
30729 - atomic_inc(&dev_priv->irq_received);
30730 + atomic_inc_unchecked(&dev_priv->irq_received);
30731
30732 /* disable master interrupt before clearing iir */
30733 de_ier = I915_READ(DEIER);
30734 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30735 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30736 u32 hotplug_mask;
30737
30738 - atomic_inc(&dev_priv->irq_received);
30739 + atomic_inc_unchecked(&dev_priv->irq_received);
30740
30741 /* disable master interrupt before clearing iir */
30742 de_ier = I915_READ(DEIER);
30743 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30744 {
30745 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30746
30747 - atomic_set(&dev_priv->irq_received, 0);
30748 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30749
30750 I915_WRITE(HWSTAM, 0xeffe);
30751
30752 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30753 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30754 int pipe;
30755
30756 - atomic_set(&dev_priv->irq_received, 0);
30757 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30758
30759 /* VLV magic */
30760 I915_WRITE(VLV_IMR, 0);
30761 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30762 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30763 int pipe;
30764
30765 - atomic_set(&dev_priv->irq_received, 0);
30766 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30767
30768 for_each_pipe(pipe)
30769 I915_WRITE(PIPESTAT(pipe), 0);
30770 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30771 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30772 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30773
30774 - atomic_inc(&dev_priv->irq_received);
30775 + atomic_inc_unchecked(&dev_priv->irq_received);
30776
30777 iir = I915_READ16(IIR);
30778 if (iir == 0)
30779 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30780 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30781 int pipe;
30782
30783 - atomic_set(&dev_priv->irq_received, 0);
30784 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30785
30786 if (I915_HAS_HOTPLUG(dev)) {
30787 I915_WRITE(PORT_HOTPLUG_EN, 0);
30788 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30789 };
30790 int pipe, ret = IRQ_NONE;
30791
30792 - atomic_inc(&dev_priv->irq_received);
30793 + atomic_inc_unchecked(&dev_priv->irq_received);
30794
30795 iir = I915_READ(IIR);
30796 do {
30797 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30798 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30799 int pipe;
30800
30801 - atomic_set(&dev_priv->irq_received, 0);
30802 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30803
30804 I915_WRITE(PORT_HOTPLUG_EN, 0);
30805 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30806 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30807 int irq_received;
30808 int ret = IRQ_NONE, pipe;
30809
30810 - atomic_inc(&dev_priv->irq_received);
30811 + atomic_inc_unchecked(&dev_priv->irq_received);
30812
30813 iir = I915_READ(IIR);
30814
30815 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30816 index b634f6f..84bb8ba 100644
30817 --- a/drivers/gpu/drm/i915/intel_display.c
30818 +++ b/drivers/gpu/drm/i915/intel_display.c
30819 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30820
30821 wait_event(dev_priv->pending_flip_queue,
30822 atomic_read(&dev_priv->mm.wedged) ||
30823 - atomic_read(&obj->pending_flip) == 0);
30824 + atomic_read_unchecked(&obj->pending_flip) == 0);
30825
30826 /* Big Hammer, we also need to ensure that any pending
30827 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30828 @@ -6168,7 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30829
30830 obj = work->old_fb_obj;
30831
30832 - atomic_clear_mask(1 << intel_crtc->plane,
30833 + atomic_clear_mask_unchecked(1 << intel_crtc->plane,
30834 &obj->pending_flip.counter);
30835
30836 wake_up(&dev_priv->pending_flip_queue);
30837 @@ -6515,7 +6515,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30838 /* Block clients from rendering to the new back buffer until
30839 * the flip occurs and the object is no longer visible.
30840 */
30841 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30842 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30843
30844 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30845 if (ret)
30846 @@ -6530,7 +6530,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30847 return 0;
30848
30849 cleanup_pending:
30850 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30851 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30852 drm_gem_object_unreference(&work->old_fb_obj->base);
30853 drm_gem_object_unreference(&obj->base);
30854 mutex_unlock(&dev->struct_mutex);
30855 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30856 index 54558a0..2d97005 100644
30857 --- a/drivers/gpu/drm/mga/mga_drv.h
30858 +++ b/drivers/gpu/drm/mga/mga_drv.h
30859 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30860 u32 clear_cmd;
30861 u32 maccess;
30862
30863 - atomic_t vbl_received; /**< Number of vblanks received. */
30864 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30865 wait_queue_head_t fence_queue;
30866 - atomic_t last_fence_retired;
30867 + atomic_unchecked_t last_fence_retired;
30868 u32 next_fence_to_post;
30869
30870 unsigned int fb_cpp;
30871 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30872 index 2581202..f230a8d9 100644
30873 --- a/drivers/gpu/drm/mga/mga_irq.c
30874 +++ b/drivers/gpu/drm/mga/mga_irq.c
30875 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30876 if (crtc != 0)
30877 return 0;
30878
30879 - return atomic_read(&dev_priv->vbl_received);
30880 + return atomic_read_unchecked(&dev_priv->vbl_received);
30881 }
30882
30883
30884 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30885 /* VBLANK interrupt */
30886 if (status & MGA_VLINEPEN) {
30887 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30888 - atomic_inc(&dev_priv->vbl_received);
30889 + atomic_inc_unchecked(&dev_priv->vbl_received);
30890 drm_handle_vblank(dev, 0);
30891 handled = 1;
30892 }
30893 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30894 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30895 MGA_WRITE(MGA_PRIMEND, prim_end);
30896
30897 - atomic_inc(&dev_priv->last_fence_retired);
30898 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30899 DRM_WAKEUP(&dev_priv->fence_queue);
30900 handled = 1;
30901 }
30902 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30903 * using fences.
30904 */
30905 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30906 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30907 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30908 - *sequence) <= (1 << 23)));
30909
30910 *sequence = cur_fence;
30911 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30912 index a0a3fe3..209bf10 100644
30913 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30914 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30915 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30916 struct bit_table {
30917 const char id;
30918 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30919 -};
30920 +} __no_const;
30921
30922 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30923
30924 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30925 index 4f2cc95..9c6c510 100644
30926 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30927 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30928 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30929 u32 handle, u16 class);
30930 void (*set_tile_region)(struct drm_device *dev, int i);
30931 void (*tlb_flush)(struct drm_device *, int engine);
30932 -};
30933 +} __no_const;
30934
30935 struct nouveau_instmem_engine {
30936 void *priv;
30937 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30938 struct nouveau_mc_engine {
30939 int (*init)(struct drm_device *dev);
30940 void (*takedown)(struct drm_device *dev);
30941 -};
30942 +} __no_const;
30943
30944 struct nouveau_timer_engine {
30945 int (*init)(struct drm_device *dev);
30946 void (*takedown)(struct drm_device *dev);
30947 uint64_t (*read)(struct drm_device *dev);
30948 -};
30949 +} __no_const;
30950
30951 struct nouveau_fb_engine {
30952 int num_tiles;
30953 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30954 void (*put)(struct drm_device *, struct nouveau_mem **);
30955
30956 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30957 -};
30958 +} __no_const;
30959
30960 struct nouveau_engine {
30961 struct nouveau_instmem_engine instmem;
30962 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30963 struct drm_global_reference mem_global_ref;
30964 struct ttm_bo_global_ref bo_global_ref;
30965 struct ttm_bo_device bdev;
30966 - atomic_t validate_sequence;
30967 + atomic_unchecked_t validate_sequence;
30968 int (*move)(struct nouveau_channel *,
30969 struct ttm_buffer_object *,
30970 struct ttm_mem_reg *, struct ttm_mem_reg *);
30971 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30972 index af7cfb8..aadc2a3 100644
30973 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30974 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30975 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30976 int trycnt = 0;
30977 int ret, i;
30978
30979 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30980 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30981 retry:
30982 if (++trycnt > 100000) {
30983 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30984 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30985 index c610144..97440e2 100644
30986 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30987 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30988 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30989 bool can_switch;
30990
30991 spin_lock(&dev->count_lock);
30992 - can_switch = (dev->open_count == 0);
30993 + can_switch = (local_read(&dev->open_count) == 0);
30994 spin_unlock(&dev->count_lock);
30995 return can_switch;
30996 }
30997 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30998 index 93240bd..c490f60 100644
30999 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31000 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31001 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31002 }
31003
31004 if (nv_encoder->dcb->type == OUTPUT_DP) {
31005 - struct dp_train_func func = {
31006 + static struct dp_train_func func = {
31007 .link_set = nv50_sor_dp_link_set,
31008 .train_set = nv50_sor_dp_train_set,
31009 .train_adj = nv50_sor_dp_train_adj
31010 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31011 index 8a2fc89..3a5cf40 100644
31012 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31013 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31014 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31015 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31016
31017 if (nv_encoder->dcb->type == OUTPUT_DP) {
31018 - struct dp_train_func func = {
31019 + static struct dp_train_func func = {
31020 .link_set = nvd0_sor_dp_link_set,
31021 .train_set = nvd0_sor_dp_train_set,
31022 .train_adj = nvd0_sor_dp_train_adj
31023 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31024 index bcac90b..53bfc76 100644
31025 --- a/drivers/gpu/drm/r128/r128_cce.c
31026 +++ b/drivers/gpu/drm/r128/r128_cce.c
31027 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31028
31029 /* GH: Simple idle check.
31030 */
31031 - atomic_set(&dev_priv->idle_count, 0);
31032 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31033
31034 /* We don't support anything other than bus-mastering ring mode,
31035 * but the ring can be in either AGP or PCI space for the ring
31036 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31037 index 930c71b..499aded 100644
31038 --- a/drivers/gpu/drm/r128/r128_drv.h
31039 +++ b/drivers/gpu/drm/r128/r128_drv.h
31040 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31041 int is_pci;
31042 unsigned long cce_buffers_offset;
31043
31044 - atomic_t idle_count;
31045 + atomic_unchecked_t idle_count;
31046
31047 int page_flipping;
31048 int current_page;
31049 u32 crtc_offset;
31050 u32 crtc_offset_cntl;
31051
31052 - atomic_t vbl_received;
31053 + atomic_unchecked_t vbl_received;
31054
31055 u32 color_fmt;
31056 unsigned int front_offset;
31057 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31058 index 429d5a0..7e899ed 100644
31059 --- a/drivers/gpu/drm/r128/r128_irq.c
31060 +++ b/drivers/gpu/drm/r128/r128_irq.c
31061 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31062 if (crtc != 0)
31063 return 0;
31064
31065 - return atomic_read(&dev_priv->vbl_received);
31066 + return atomic_read_unchecked(&dev_priv->vbl_received);
31067 }
31068
31069 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31070 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31071 /* VBLANK interrupt */
31072 if (status & R128_CRTC_VBLANK_INT) {
31073 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31074 - atomic_inc(&dev_priv->vbl_received);
31075 + atomic_inc_unchecked(&dev_priv->vbl_received);
31076 drm_handle_vblank(dev, 0);
31077 return IRQ_HANDLED;
31078 }
31079 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31080 index a9e33ce..09edd4b 100644
31081 --- a/drivers/gpu/drm/r128/r128_state.c
31082 +++ b/drivers/gpu/drm/r128/r128_state.c
31083 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31084
31085 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31086 {
31087 - if (atomic_read(&dev_priv->idle_count) == 0)
31088 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31089 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31090 else
31091 - atomic_set(&dev_priv->idle_count, 0);
31092 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31093 }
31094
31095 #endif
31096 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31097 index 5a82b6b..9e69c73 100644
31098 --- a/drivers/gpu/drm/radeon/mkregtable.c
31099 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31100 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31101 regex_t mask_rex;
31102 regmatch_t match[4];
31103 char buf[1024];
31104 - size_t end;
31105 + long end;
31106 int len;
31107 int done = 0;
31108 int r;
31109 unsigned o;
31110 struct offset *offset;
31111 char last_reg_s[10];
31112 - int last_reg;
31113 + unsigned long last_reg;
31114
31115 if (regcomp
31116 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31117 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31118 index 59a1531..3bab49b 100644
31119 --- a/drivers/gpu/drm/radeon/radeon.h
31120 +++ b/drivers/gpu/drm/radeon/radeon.h
31121 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31122 int x2, int y2);
31123 void (*draw_auto)(struct radeon_device *rdev);
31124 void (*set_default_state)(struct radeon_device *rdev);
31125 -};
31126 +} __no_const;
31127
31128 struct r600_blit {
31129 struct radeon_bo *shader_obj;
31130 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31131 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31132 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31133 } pflip;
31134 -};
31135 +} __no_const;
31136
31137 /*
31138 * Asic structures
31139 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31140 index 7a3daeb..5016171 100644
31141 --- a/drivers/gpu/drm/radeon/radeon_device.c
31142 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31143 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31144 bool can_switch;
31145
31146 spin_lock(&dev->count_lock);
31147 - can_switch = (dev->open_count == 0);
31148 + can_switch = (local_read(&dev->open_count) == 0);
31149 spin_unlock(&dev->count_lock);
31150 return can_switch;
31151 }
31152 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31153 index a1b59ca..86f2d44 100644
31154 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31155 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31156 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31157
31158 /* SW interrupt */
31159 wait_queue_head_t swi_queue;
31160 - atomic_t swi_emitted;
31161 + atomic_unchecked_t swi_emitted;
31162 int vblank_crtc;
31163 uint32_t irq_enable_reg;
31164 uint32_t r500_disp_irq_reg;
31165 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31166 index 48b7cea..342236f 100644
31167 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31168 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31169 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31170 request = compat_alloc_user_space(sizeof(*request));
31171 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31172 || __put_user(req32.param, &request->param)
31173 - || __put_user((void __user *)(unsigned long)req32.value,
31174 + || __put_user((unsigned long)req32.value,
31175 &request->value))
31176 return -EFAULT;
31177
31178 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31179 index 00da384..32f972d 100644
31180 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31181 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31182 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31183 unsigned int ret;
31184 RING_LOCALS;
31185
31186 - atomic_inc(&dev_priv->swi_emitted);
31187 - ret = atomic_read(&dev_priv->swi_emitted);
31188 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31189 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31190
31191 BEGIN_RING(4);
31192 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31193 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31194 drm_radeon_private_t *dev_priv =
31195 (drm_radeon_private_t *) dev->dev_private;
31196
31197 - atomic_set(&dev_priv->swi_emitted, 0);
31198 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31199 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31200
31201 dev->max_vblank_count = 0x001fffff;
31202 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31203 index e8422ae..d22d4a8 100644
31204 --- a/drivers/gpu/drm/radeon/radeon_state.c
31205 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31206 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31207 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31208 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31209
31210 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31211 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31212 sarea_priv->nbox * sizeof(depth_boxes[0])))
31213 return -EFAULT;
31214
31215 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31216 {
31217 drm_radeon_private_t *dev_priv = dev->dev_private;
31218 drm_radeon_getparam_t *param = data;
31219 - int value;
31220 + int value = 0;
31221
31222 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31223
31224 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31225 index 5b71c71..650f9e4 100644
31226 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31227 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31228 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31229 }
31230 if (unlikely(ttm_vm_ops == NULL)) {
31231 ttm_vm_ops = vma->vm_ops;
31232 - radeon_ttm_vm_ops = *ttm_vm_ops;
31233 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31234 + pax_open_kernel();
31235 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31236 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31237 + pax_close_kernel();
31238 }
31239 vma->vm_ops = &radeon_ttm_vm_ops;
31240 return 0;
31241 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31242 index 3b663fc..57850f4 100644
31243 --- a/drivers/gpu/drm/radeon/rs690.c
31244 +++ b/drivers/gpu/drm/radeon/rs690.c
31245 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31246 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31247 rdev->pm.sideport_bandwidth.full)
31248 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31249 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31250 + read_delay_latency.full = dfixed_const(800 * 1000);
31251 read_delay_latency.full = dfixed_div(read_delay_latency,
31252 rdev->pm.igp_sideport_mclk);
31253 + a.full = dfixed_const(370);
31254 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31255 } else {
31256 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31257 rdev->pm.k8_bandwidth.full)
31258 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31259 index ebc6fac..a8313ed 100644
31260 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31261 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31262 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31263 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31264 struct shrink_control *sc)
31265 {
31266 - static atomic_t start_pool = ATOMIC_INIT(0);
31267 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31268 unsigned i;
31269 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31270 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31271 struct ttm_page_pool *pool;
31272 int shrink_pages = sc->nr_to_scan;
31273
31274 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31275 index 88edacc..1e5412b 100644
31276 --- a/drivers/gpu/drm/via/via_drv.h
31277 +++ b/drivers/gpu/drm/via/via_drv.h
31278 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31279 typedef uint32_t maskarray_t[5];
31280
31281 typedef struct drm_via_irq {
31282 - atomic_t irq_received;
31283 + atomic_unchecked_t irq_received;
31284 uint32_t pending_mask;
31285 uint32_t enable_mask;
31286 wait_queue_head_t irq_queue;
31287 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31288 struct timeval last_vblank;
31289 int last_vblank_valid;
31290 unsigned usec_per_vblank;
31291 - atomic_t vbl_received;
31292 + atomic_unchecked_t vbl_received;
31293 drm_via_state_t hc_state;
31294 char pci_buf[VIA_PCI_BUF_SIZE];
31295 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31296 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31297 index d391f48..10c8ca3 100644
31298 --- a/drivers/gpu/drm/via/via_irq.c
31299 +++ b/drivers/gpu/drm/via/via_irq.c
31300 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31301 if (crtc != 0)
31302 return 0;
31303
31304 - return atomic_read(&dev_priv->vbl_received);
31305 + return atomic_read_unchecked(&dev_priv->vbl_received);
31306 }
31307
31308 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31309 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31310
31311 status = VIA_READ(VIA_REG_INTERRUPT);
31312 if (status & VIA_IRQ_VBLANK_PENDING) {
31313 - atomic_inc(&dev_priv->vbl_received);
31314 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31315 + atomic_inc_unchecked(&dev_priv->vbl_received);
31316 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31317 do_gettimeofday(&cur_vblank);
31318 if (dev_priv->last_vblank_valid) {
31319 dev_priv->usec_per_vblank =
31320 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31321 dev_priv->last_vblank = cur_vblank;
31322 dev_priv->last_vblank_valid = 1;
31323 }
31324 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31325 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31326 DRM_DEBUG("US per vblank is: %u\n",
31327 dev_priv->usec_per_vblank);
31328 }
31329 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31330
31331 for (i = 0; i < dev_priv->num_irqs; ++i) {
31332 if (status & cur_irq->pending_mask) {
31333 - atomic_inc(&cur_irq->irq_received);
31334 + atomic_inc_unchecked(&cur_irq->irq_received);
31335 DRM_WAKEUP(&cur_irq->irq_queue);
31336 handled = 1;
31337 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31338 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31339 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31340 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31341 masks[irq][4]));
31342 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31343 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31344 } else {
31345 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31346 (((cur_irq_sequence =
31347 - atomic_read(&cur_irq->irq_received)) -
31348 + atomic_read_unchecked(&cur_irq->irq_received)) -
31349 *sequence) <= (1 << 23)));
31350 }
31351 *sequence = cur_irq_sequence;
31352 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31353 }
31354
31355 for (i = 0; i < dev_priv->num_irqs; ++i) {
31356 - atomic_set(&cur_irq->irq_received, 0);
31357 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31358 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31359 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31360 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31361 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31362 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31363 case VIA_IRQ_RELATIVE:
31364 irqwait->request.sequence +=
31365 - atomic_read(&cur_irq->irq_received);
31366 + atomic_read_unchecked(&cur_irq->irq_received);
31367 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31368 case VIA_IRQ_ABSOLUTE:
31369 break;
31370 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31371 index 29c984f..4084f1a 100644
31372 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31373 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31374 @@ -263,7 +263,7 @@ struct vmw_private {
31375 * Fencing and IRQs.
31376 */
31377
31378 - atomic_t marker_seq;
31379 + atomic_unchecked_t marker_seq;
31380 wait_queue_head_t fence_queue;
31381 wait_queue_head_t fifo_queue;
31382 int fence_queue_waiters; /* Protected by hw_mutex */
31383 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31384 index a0c2f12..68ae6cb 100644
31385 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31386 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31387 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31388 (unsigned int) min,
31389 (unsigned int) fifo->capabilities);
31390
31391 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31392 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31393 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31394 vmw_marker_queue_init(&fifo->marker_queue);
31395 return vmw_fifo_send_fence(dev_priv, &dummy);
31396 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31397 if (reserveable)
31398 iowrite32(bytes, fifo_mem +
31399 SVGA_FIFO_RESERVED);
31400 - return fifo_mem + (next_cmd >> 2);
31401 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31402 } else {
31403 need_bounce = true;
31404 }
31405 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31406
31407 fm = vmw_fifo_reserve(dev_priv, bytes);
31408 if (unlikely(fm == NULL)) {
31409 - *seqno = atomic_read(&dev_priv->marker_seq);
31410 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31411 ret = -ENOMEM;
31412 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31413 false, 3*HZ);
31414 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31415 }
31416
31417 do {
31418 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31419 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31420 } while (*seqno == 0);
31421
31422 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31423 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31424 index cabc95f..14b3d77 100644
31425 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31426 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31427 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31428 * emitted. Then the fence is stale and signaled.
31429 */
31430
31431 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31432 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31433 > VMW_FENCE_WRAP);
31434
31435 return ret;
31436 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31437
31438 if (fifo_idle)
31439 down_read(&fifo_state->rwsem);
31440 - signal_seq = atomic_read(&dev_priv->marker_seq);
31441 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31442 ret = 0;
31443
31444 for (;;) {
31445 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31446 index 8a8725c..afed796 100644
31447 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31448 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31449 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31450 while (!vmw_lag_lt(queue, us)) {
31451 spin_lock(&queue->lock);
31452 if (list_empty(&queue->head))
31453 - seqno = atomic_read(&dev_priv->marker_seq);
31454 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31455 else {
31456 marker = list_first_entry(&queue->head,
31457 struct vmw_marker, head);
31458 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31459 index 5de3bb3..08e5063 100644
31460 --- a/drivers/hid/hid-core.c
31461 +++ b/drivers/hid/hid-core.c
31462 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31463
31464 int hid_add_device(struct hid_device *hdev)
31465 {
31466 - static atomic_t id = ATOMIC_INIT(0);
31467 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31468 int ret;
31469
31470 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31471 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31472 /* XXX hack, any other cleaner solution after the driver core
31473 * is converted to allow more than 20 bytes as the device name? */
31474 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31475 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31476 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31477
31478 hid_debug_register(hdev, dev_name(&hdev->dev));
31479 ret = device_add(&hdev->dev);
31480 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31481 index eec3291..8ed706b 100644
31482 --- a/drivers/hid/hid-wiimote-debug.c
31483 +++ b/drivers/hid/hid-wiimote-debug.c
31484 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31485 else if (size == 0)
31486 return -EIO;
31487
31488 - if (copy_to_user(u, buf, size))
31489 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31490 return -EFAULT;
31491
31492 *off += size;
31493 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31494 index 14599e2..711c965 100644
31495 --- a/drivers/hid/usbhid/hiddev.c
31496 +++ b/drivers/hid/usbhid/hiddev.c
31497 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31498 break;
31499
31500 case HIDIOCAPPLICATION:
31501 - if (arg < 0 || arg >= hid->maxapplication)
31502 + if (arg >= hid->maxapplication)
31503 break;
31504
31505 for (i = 0; i < hid->maxcollection; i++)
31506 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31507 index 4065374..10ed7dc 100644
31508 --- a/drivers/hv/channel.c
31509 +++ b/drivers/hv/channel.c
31510 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31511 int ret = 0;
31512 int t;
31513
31514 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31515 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31516 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31517 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31518
31519 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31520 if (ret)
31521 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31522 index 86f8885..ab9cb2b 100644
31523 --- a/drivers/hv/hv.c
31524 +++ b/drivers/hv/hv.c
31525 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31526 u64 output_address = (output) ? virt_to_phys(output) : 0;
31527 u32 output_address_hi = output_address >> 32;
31528 u32 output_address_lo = output_address & 0xFFFFFFFF;
31529 - void *hypercall_page = hv_context.hypercall_page;
31530 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31531
31532 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31533 "=a"(hv_status_lo) : "d" (control_hi),
31534 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31535 index 0614ff3..f0b2b5c 100644
31536 --- a/drivers/hv/hyperv_vmbus.h
31537 +++ b/drivers/hv/hyperv_vmbus.h
31538 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31539 struct vmbus_connection {
31540 enum vmbus_connect_state conn_state;
31541
31542 - atomic_t next_gpadl_handle;
31543 + atomic_unchecked_t next_gpadl_handle;
31544
31545 /*
31546 * Represents channel interrupts. Each bit position represents a
31547 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31548 index 4748086..3abf845 100644
31549 --- a/drivers/hv/vmbus_drv.c
31550 +++ b/drivers/hv/vmbus_drv.c
31551 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31552 {
31553 int ret = 0;
31554
31555 - static atomic_t device_num = ATOMIC_INIT(0);
31556 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31557
31558 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31559 - atomic_inc_return(&device_num));
31560 + atomic_inc_return_unchecked(&device_num));
31561
31562 child_device_obj->device.bus = &hv_bus;
31563 child_device_obj->device.parent = &hv_acpi_dev->dev;
31564 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31565 index 8b011d0..3de24a1 100644
31566 --- a/drivers/hwmon/sht15.c
31567 +++ b/drivers/hwmon/sht15.c
31568 @@ -166,7 +166,7 @@ struct sht15_data {
31569 int supply_uV;
31570 bool supply_uV_valid;
31571 struct work_struct update_supply_work;
31572 - atomic_t interrupt_handled;
31573 + atomic_unchecked_t interrupt_handled;
31574 };
31575
31576 /**
31577 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31578 return ret;
31579
31580 gpio_direction_input(data->pdata->gpio_data);
31581 - atomic_set(&data->interrupt_handled, 0);
31582 + atomic_set_unchecked(&data->interrupt_handled, 0);
31583
31584 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31585 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31586 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31587 /* Only relevant if the interrupt hasn't occurred. */
31588 - if (!atomic_read(&data->interrupt_handled))
31589 + if (!atomic_read_unchecked(&data->interrupt_handled))
31590 schedule_work(&data->read_work);
31591 }
31592 ret = wait_event_timeout(data->wait_queue,
31593 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31594
31595 /* First disable the interrupt */
31596 disable_irq_nosync(irq);
31597 - atomic_inc(&data->interrupt_handled);
31598 + atomic_inc_unchecked(&data->interrupt_handled);
31599 /* Then schedule a reading work struct */
31600 if (data->state != SHT15_READING_NOTHING)
31601 schedule_work(&data->read_work);
31602 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31603 * If not, then start the interrupt again - care here as could
31604 * have gone low in meantime so verify it hasn't!
31605 */
31606 - atomic_set(&data->interrupt_handled, 0);
31607 + atomic_set_unchecked(&data->interrupt_handled, 0);
31608 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31609 /* If still not occurred or another handler was scheduled */
31610 if (gpio_get_value(data->pdata->gpio_data)
31611 - || atomic_read(&data->interrupt_handled))
31612 + || atomic_read_unchecked(&data->interrupt_handled))
31613 return;
31614 }
31615
31616 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31617 index 378fcb5..5e91fa8 100644
31618 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31619 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31620 @@ -43,7 +43,7 @@
31621 extern struct i2c_adapter amd756_smbus;
31622
31623 static struct i2c_adapter *s4882_adapter;
31624 -static struct i2c_algorithm *s4882_algo;
31625 +static i2c_algorithm_no_const *s4882_algo;
31626
31627 /* Wrapper access functions for multiplexed SMBus */
31628 static DEFINE_MUTEX(amd756_lock);
31629 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31630 index 29015eb..af2d8e9 100644
31631 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31632 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31633 @@ -41,7 +41,7 @@
31634 extern struct i2c_adapter *nforce2_smbus;
31635
31636 static struct i2c_adapter *s4985_adapter;
31637 -static struct i2c_algorithm *s4985_algo;
31638 +static i2c_algorithm_no_const *s4985_algo;
31639
31640 /* Wrapper access functions for multiplexed SMBus */
31641 static DEFINE_MUTEX(nforce2_lock);
31642 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31643 index 1038c38..eb92f51 100644
31644 --- a/drivers/i2c/i2c-mux.c
31645 +++ b/drivers/i2c/i2c-mux.c
31646 @@ -30,7 +30,7 @@
31647 /* multiplexer per channel data */
31648 struct i2c_mux_priv {
31649 struct i2c_adapter adap;
31650 - struct i2c_algorithm algo;
31651 + i2c_algorithm_no_const algo;
31652
31653 struct i2c_adapter *parent;
31654 void *mux_priv; /* the mux chip/device */
31655 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31656 index 57d00ca..0145194 100644
31657 --- a/drivers/ide/aec62xx.c
31658 +++ b/drivers/ide/aec62xx.c
31659 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31660 .cable_detect = atp86x_cable_detect,
31661 };
31662
31663 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31664 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31665 { /* 0: AEC6210 */
31666 .name = DRV_NAME,
31667 .init_chipset = init_chipset_aec62xx,
31668 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31669 index 2c8016a..911a27c 100644
31670 --- a/drivers/ide/alim15x3.c
31671 +++ b/drivers/ide/alim15x3.c
31672 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31673 .dma_sff_read_status = ide_dma_sff_read_status,
31674 };
31675
31676 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31677 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31678 .name = DRV_NAME,
31679 .init_chipset = init_chipset_ali15x3,
31680 .init_hwif = init_hwif_ali15x3,
31681 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31682 index 3747b25..56fc995 100644
31683 --- a/drivers/ide/amd74xx.c
31684 +++ b/drivers/ide/amd74xx.c
31685 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31686 .udma_mask = udma, \
31687 }
31688
31689 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31690 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31691 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31692 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31693 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31694 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31695 index 15f0ead..cb43480 100644
31696 --- a/drivers/ide/atiixp.c
31697 +++ b/drivers/ide/atiixp.c
31698 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31699 .cable_detect = atiixp_cable_detect,
31700 };
31701
31702 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31703 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31704 { /* 0: IXP200/300/400/700 */
31705 .name = DRV_NAME,
31706 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31707 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31708 index 5f80312..d1fc438 100644
31709 --- a/drivers/ide/cmd64x.c
31710 +++ b/drivers/ide/cmd64x.c
31711 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31712 .dma_sff_read_status = ide_dma_sff_read_status,
31713 };
31714
31715 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31716 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31717 { /* 0: CMD643 */
31718 .name = DRV_NAME,
31719 .init_chipset = init_chipset_cmd64x,
31720 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31721 index 2c1e5f7..1444762 100644
31722 --- a/drivers/ide/cs5520.c
31723 +++ b/drivers/ide/cs5520.c
31724 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31725 .set_dma_mode = cs5520_set_dma_mode,
31726 };
31727
31728 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31729 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31730 .name = DRV_NAME,
31731 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31732 .port_ops = &cs5520_port_ops,
31733 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31734 index 4dc4eb9..49b40ad 100644
31735 --- a/drivers/ide/cs5530.c
31736 +++ b/drivers/ide/cs5530.c
31737 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31738 .udma_filter = cs5530_udma_filter,
31739 };
31740
31741 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31742 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31743 .name = DRV_NAME,
31744 .init_chipset = init_chipset_cs5530,
31745 .init_hwif = init_hwif_cs5530,
31746 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31747 index 5059faf..18d4c85 100644
31748 --- a/drivers/ide/cs5535.c
31749 +++ b/drivers/ide/cs5535.c
31750 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31751 .cable_detect = cs5535_cable_detect,
31752 };
31753
31754 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31755 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31756 .name = DRV_NAME,
31757 .port_ops = &cs5535_port_ops,
31758 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31759 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31760 index 847553f..3ffb49d 100644
31761 --- a/drivers/ide/cy82c693.c
31762 +++ b/drivers/ide/cy82c693.c
31763 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31764 .set_dma_mode = cy82c693_set_dma_mode,
31765 };
31766
31767 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31768 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31769 .name = DRV_NAME,
31770 .init_iops = init_iops_cy82c693,
31771 .port_ops = &cy82c693_port_ops,
31772 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31773 index 58c51cd..4aec3b8 100644
31774 --- a/drivers/ide/hpt366.c
31775 +++ b/drivers/ide/hpt366.c
31776 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31777 }
31778 };
31779
31780 -static const struct hpt_info hpt36x __devinitdata = {
31781 +static const struct hpt_info hpt36x __devinitconst = {
31782 .chip_name = "HPT36x",
31783 .chip_type = HPT36x,
31784 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31785 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31786 .timings = &hpt36x_timings
31787 };
31788
31789 -static const struct hpt_info hpt370 __devinitdata = {
31790 +static const struct hpt_info hpt370 __devinitconst = {
31791 .chip_name = "HPT370",
31792 .chip_type = HPT370,
31793 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31794 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31795 .timings = &hpt37x_timings
31796 };
31797
31798 -static const struct hpt_info hpt370a __devinitdata = {
31799 +static const struct hpt_info hpt370a __devinitconst = {
31800 .chip_name = "HPT370A",
31801 .chip_type = HPT370A,
31802 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31803 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31804 .timings = &hpt37x_timings
31805 };
31806
31807 -static const struct hpt_info hpt374 __devinitdata = {
31808 +static const struct hpt_info hpt374 __devinitconst = {
31809 .chip_name = "HPT374",
31810 .chip_type = HPT374,
31811 .udma_mask = ATA_UDMA5,
31812 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31813 .timings = &hpt37x_timings
31814 };
31815
31816 -static const struct hpt_info hpt372 __devinitdata = {
31817 +static const struct hpt_info hpt372 __devinitconst = {
31818 .chip_name = "HPT372",
31819 .chip_type = HPT372,
31820 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31821 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31822 .timings = &hpt37x_timings
31823 };
31824
31825 -static const struct hpt_info hpt372a __devinitdata = {
31826 +static const struct hpt_info hpt372a __devinitconst = {
31827 .chip_name = "HPT372A",
31828 .chip_type = HPT372A,
31829 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31830 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31831 .timings = &hpt37x_timings
31832 };
31833
31834 -static const struct hpt_info hpt302 __devinitdata = {
31835 +static const struct hpt_info hpt302 __devinitconst = {
31836 .chip_name = "HPT302",
31837 .chip_type = HPT302,
31838 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31839 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31840 .timings = &hpt37x_timings
31841 };
31842
31843 -static const struct hpt_info hpt371 __devinitdata = {
31844 +static const struct hpt_info hpt371 __devinitconst = {
31845 .chip_name = "HPT371",
31846 .chip_type = HPT371,
31847 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31848 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31849 .timings = &hpt37x_timings
31850 };
31851
31852 -static const struct hpt_info hpt372n __devinitdata = {
31853 +static const struct hpt_info hpt372n __devinitconst = {
31854 .chip_name = "HPT372N",
31855 .chip_type = HPT372N,
31856 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31857 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31858 .timings = &hpt37x_timings
31859 };
31860
31861 -static const struct hpt_info hpt302n __devinitdata = {
31862 +static const struct hpt_info hpt302n __devinitconst = {
31863 .chip_name = "HPT302N",
31864 .chip_type = HPT302N,
31865 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31866 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31867 .timings = &hpt37x_timings
31868 };
31869
31870 -static const struct hpt_info hpt371n __devinitdata = {
31871 +static const struct hpt_info hpt371n __devinitconst = {
31872 .chip_name = "HPT371N",
31873 .chip_type = HPT371N,
31874 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31875 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31876 .dma_sff_read_status = ide_dma_sff_read_status,
31877 };
31878
31879 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31880 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31881 { /* 0: HPT36x */
31882 .name = DRV_NAME,
31883 .init_chipset = init_chipset_hpt366,
31884 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31885 index 8126824..55a2798 100644
31886 --- a/drivers/ide/ide-cd.c
31887 +++ b/drivers/ide/ide-cd.c
31888 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31889 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31890 if ((unsigned long)buf & alignment
31891 || blk_rq_bytes(rq) & q->dma_pad_mask
31892 - || object_is_on_stack(buf))
31893 + || object_starts_on_stack(buf))
31894 drive->dma = 0;
31895 }
31896 }
31897 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31898 index 7f56b73..dab5b67 100644
31899 --- a/drivers/ide/ide-pci-generic.c
31900 +++ b/drivers/ide/ide-pci-generic.c
31901 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31902 .udma_mask = ATA_UDMA6, \
31903 }
31904
31905 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31906 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31907 /* 0: Unknown */
31908 DECLARE_GENERIC_PCI_DEV(0),
31909
31910 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31911 index 560e66d..d5dd180 100644
31912 --- a/drivers/ide/it8172.c
31913 +++ b/drivers/ide/it8172.c
31914 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31915 .set_dma_mode = it8172_set_dma_mode,
31916 };
31917
31918 -static const struct ide_port_info it8172_port_info __devinitdata = {
31919 +static const struct ide_port_info it8172_port_info __devinitconst = {
31920 .name = DRV_NAME,
31921 .port_ops = &it8172_port_ops,
31922 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31923 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31924 index 46816ba..1847aeb 100644
31925 --- a/drivers/ide/it8213.c
31926 +++ b/drivers/ide/it8213.c
31927 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31928 .cable_detect = it8213_cable_detect,
31929 };
31930
31931 -static const struct ide_port_info it8213_chipset __devinitdata = {
31932 +static const struct ide_port_info it8213_chipset __devinitconst = {
31933 .name = DRV_NAME,
31934 .enablebits = { {0x41, 0x80, 0x80} },
31935 .port_ops = &it8213_port_ops,
31936 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31937 index 2e3169f..c5611db 100644
31938 --- a/drivers/ide/it821x.c
31939 +++ b/drivers/ide/it821x.c
31940 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31941 .cable_detect = it821x_cable_detect,
31942 };
31943
31944 -static const struct ide_port_info it821x_chipset __devinitdata = {
31945 +static const struct ide_port_info it821x_chipset __devinitconst = {
31946 .name = DRV_NAME,
31947 .init_chipset = init_chipset_it821x,
31948 .init_hwif = init_hwif_it821x,
31949 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31950 index 74c2c4a..efddd7d 100644
31951 --- a/drivers/ide/jmicron.c
31952 +++ b/drivers/ide/jmicron.c
31953 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31954 .cable_detect = jmicron_cable_detect,
31955 };
31956
31957 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31958 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31959 .name = DRV_NAME,
31960 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31961 .port_ops = &jmicron_port_ops,
31962 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31963 index 95327a2..73f78d8 100644
31964 --- a/drivers/ide/ns87415.c
31965 +++ b/drivers/ide/ns87415.c
31966 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31967 .dma_sff_read_status = superio_dma_sff_read_status,
31968 };
31969
31970 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31971 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31972 .name = DRV_NAME,
31973 .init_hwif = init_hwif_ns87415,
31974 .tp_ops = &ns87415_tp_ops,
31975 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31976 index 1a53a4c..39edc66 100644
31977 --- a/drivers/ide/opti621.c
31978 +++ b/drivers/ide/opti621.c
31979 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31980 .set_pio_mode = opti621_set_pio_mode,
31981 };
31982
31983 -static const struct ide_port_info opti621_chipset __devinitdata = {
31984 +static const struct ide_port_info opti621_chipset __devinitconst = {
31985 .name = DRV_NAME,
31986 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31987 .port_ops = &opti621_port_ops,
31988 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31989 index 9546fe2..2e5ceb6 100644
31990 --- a/drivers/ide/pdc202xx_new.c
31991 +++ b/drivers/ide/pdc202xx_new.c
31992 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31993 .udma_mask = udma, \
31994 }
31995
31996 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31997 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31998 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31999 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32000 };
32001 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32002 index 3a35ec6..5634510 100644
32003 --- a/drivers/ide/pdc202xx_old.c
32004 +++ b/drivers/ide/pdc202xx_old.c
32005 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32006 .max_sectors = sectors, \
32007 }
32008
32009 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32010 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32011 { /* 0: PDC20246 */
32012 .name = DRV_NAME,
32013 .init_chipset = init_chipset_pdc202xx,
32014 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32015 index 1892e81..fe0fd60 100644
32016 --- a/drivers/ide/piix.c
32017 +++ b/drivers/ide/piix.c
32018 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32019 .udma_mask = udma, \
32020 }
32021
32022 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32023 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32024 /* 0: MPIIX */
32025 { /*
32026 * MPIIX actually has only a single IDE channel mapped to
32027 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32028 index a6414a8..c04173e 100644
32029 --- a/drivers/ide/rz1000.c
32030 +++ b/drivers/ide/rz1000.c
32031 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32032 }
32033 }
32034
32035 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32036 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32037 .name = DRV_NAME,
32038 .host_flags = IDE_HFLAG_NO_DMA,
32039 };
32040 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32041 index 356b9b5..d4758eb 100644
32042 --- a/drivers/ide/sc1200.c
32043 +++ b/drivers/ide/sc1200.c
32044 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32045 .dma_sff_read_status = ide_dma_sff_read_status,
32046 };
32047
32048 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32049 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32050 .name = DRV_NAME,
32051 .port_ops = &sc1200_port_ops,
32052 .dma_ops = &sc1200_dma_ops,
32053 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32054 index b7f5b0c..9701038 100644
32055 --- a/drivers/ide/scc_pata.c
32056 +++ b/drivers/ide/scc_pata.c
32057 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32058 .dma_sff_read_status = scc_dma_sff_read_status,
32059 };
32060
32061 -static const struct ide_port_info scc_chipset __devinitdata = {
32062 +static const struct ide_port_info scc_chipset __devinitconst = {
32063 .name = "sccIDE",
32064 .init_iops = init_iops_scc,
32065 .init_dma = scc_init_dma,
32066 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32067 index 35fb8da..24d72ef 100644
32068 --- a/drivers/ide/serverworks.c
32069 +++ b/drivers/ide/serverworks.c
32070 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32071 .cable_detect = svwks_cable_detect,
32072 };
32073
32074 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32075 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32076 { /* 0: OSB4 */
32077 .name = DRV_NAME,
32078 .init_chipset = init_chipset_svwks,
32079 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32080 index ddeda44..46f7e30 100644
32081 --- a/drivers/ide/siimage.c
32082 +++ b/drivers/ide/siimage.c
32083 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32084 .udma_mask = ATA_UDMA6, \
32085 }
32086
32087 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32088 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32089 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32090 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32091 };
32092 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32093 index 4a00225..09e61b4 100644
32094 --- a/drivers/ide/sis5513.c
32095 +++ b/drivers/ide/sis5513.c
32096 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32097 .cable_detect = sis_cable_detect,
32098 };
32099
32100 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32101 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32102 .name = DRV_NAME,
32103 .init_chipset = init_chipset_sis5513,
32104 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32105 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32106 index f21dc2a..d051cd2 100644
32107 --- a/drivers/ide/sl82c105.c
32108 +++ b/drivers/ide/sl82c105.c
32109 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32110 .dma_sff_read_status = ide_dma_sff_read_status,
32111 };
32112
32113 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32114 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32115 .name = DRV_NAME,
32116 .init_chipset = init_chipset_sl82c105,
32117 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32118 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32119 index 864ffe0..863a5e9 100644
32120 --- a/drivers/ide/slc90e66.c
32121 +++ b/drivers/ide/slc90e66.c
32122 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32123 .cable_detect = slc90e66_cable_detect,
32124 };
32125
32126 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32127 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32128 .name = DRV_NAME,
32129 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32130 .port_ops = &slc90e66_port_ops,
32131 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32132 index 4799d5c..1794678 100644
32133 --- a/drivers/ide/tc86c001.c
32134 +++ b/drivers/ide/tc86c001.c
32135 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32136 .dma_sff_read_status = ide_dma_sff_read_status,
32137 };
32138
32139 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32140 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32141 .name = DRV_NAME,
32142 .init_hwif = init_hwif_tc86c001,
32143 .port_ops = &tc86c001_port_ops,
32144 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32145 index 281c914..55ce1b8 100644
32146 --- a/drivers/ide/triflex.c
32147 +++ b/drivers/ide/triflex.c
32148 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32149 .set_dma_mode = triflex_set_mode,
32150 };
32151
32152 -static const struct ide_port_info triflex_device __devinitdata = {
32153 +static const struct ide_port_info triflex_device __devinitconst = {
32154 .name = DRV_NAME,
32155 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32156 .port_ops = &triflex_port_ops,
32157 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32158 index 4b42ca0..e494a98 100644
32159 --- a/drivers/ide/trm290.c
32160 +++ b/drivers/ide/trm290.c
32161 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32162 .dma_check = trm290_dma_check,
32163 };
32164
32165 -static const struct ide_port_info trm290_chipset __devinitdata = {
32166 +static const struct ide_port_info trm290_chipset __devinitconst = {
32167 .name = DRV_NAME,
32168 .init_hwif = init_hwif_trm290,
32169 .tp_ops = &trm290_tp_ops,
32170 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32171 index f46f49c..eb77678 100644
32172 --- a/drivers/ide/via82cxxx.c
32173 +++ b/drivers/ide/via82cxxx.c
32174 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32175 .cable_detect = via82cxxx_cable_detect,
32176 };
32177
32178 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32179 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32180 .name = DRV_NAME,
32181 .init_chipset = init_chipset_via82cxxx,
32182 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32183 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32184 index 73d4531..c90cd2d 100644
32185 --- a/drivers/ieee802154/fakehard.c
32186 +++ b/drivers/ieee802154/fakehard.c
32187 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32188 phy->transmit_power = 0xbf;
32189
32190 dev->netdev_ops = &fake_ops;
32191 - dev->ml_priv = &fake_mlme;
32192 + dev->ml_priv = (void *)&fake_mlme;
32193
32194 priv = netdev_priv(dev);
32195 priv->phy = phy;
32196 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32197 index d67999f..4c5d083 100644
32198 --- a/drivers/infiniband/core/cm.c
32199 +++ b/drivers/infiniband/core/cm.c
32200 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32201
32202 struct cm_counter_group {
32203 struct kobject obj;
32204 - atomic_long_t counter[CM_ATTR_COUNT];
32205 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32206 };
32207
32208 struct cm_counter_attribute {
32209 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32210 struct ib_mad_send_buf *msg = NULL;
32211 int ret;
32212
32213 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32214 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32215 counter[CM_REQ_COUNTER]);
32216
32217 /* Quick state check to discard duplicate REQs. */
32218 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32219 if (!cm_id_priv)
32220 return;
32221
32222 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32223 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32224 counter[CM_REP_COUNTER]);
32225 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32226 if (ret)
32227 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32228 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32229 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32230 spin_unlock_irq(&cm_id_priv->lock);
32231 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32232 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32233 counter[CM_RTU_COUNTER]);
32234 goto out;
32235 }
32236 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32237 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32238 dreq_msg->local_comm_id);
32239 if (!cm_id_priv) {
32240 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32241 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32242 counter[CM_DREQ_COUNTER]);
32243 cm_issue_drep(work->port, work->mad_recv_wc);
32244 return -EINVAL;
32245 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32246 case IB_CM_MRA_REP_RCVD:
32247 break;
32248 case IB_CM_TIMEWAIT:
32249 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32250 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32251 counter[CM_DREQ_COUNTER]);
32252 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32253 goto unlock;
32254 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32255 cm_free_msg(msg);
32256 goto deref;
32257 case IB_CM_DREQ_RCVD:
32258 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32259 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32260 counter[CM_DREQ_COUNTER]);
32261 goto unlock;
32262 default:
32263 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32264 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32265 cm_id_priv->msg, timeout)) {
32266 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32267 - atomic_long_inc(&work->port->
32268 + atomic_long_inc_unchecked(&work->port->
32269 counter_group[CM_RECV_DUPLICATES].
32270 counter[CM_MRA_COUNTER]);
32271 goto out;
32272 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32273 break;
32274 case IB_CM_MRA_REQ_RCVD:
32275 case IB_CM_MRA_REP_RCVD:
32276 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32277 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32278 counter[CM_MRA_COUNTER]);
32279 /* fall through */
32280 default:
32281 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32282 case IB_CM_LAP_IDLE:
32283 break;
32284 case IB_CM_MRA_LAP_SENT:
32285 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32286 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32287 counter[CM_LAP_COUNTER]);
32288 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32289 goto unlock;
32290 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32291 cm_free_msg(msg);
32292 goto deref;
32293 case IB_CM_LAP_RCVD:
32294 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32295 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32296 counter[CM_LAP_COUNTER]);
32297 goto unlock;
32298 default:
32299 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32300 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32301 if (cur_cm_id_priv) {
32302 spin_unlock_irq(&cm.lock);
32303 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32304 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32305 counter[CM_SIDR_REQ_COUNTER]);
32306 goto out; /* Duplicate message. */
32307 }
32308 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32309 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32310 msg->retries = 1;
32311
32312 - atomic_long_add(1 + msg->retries,
32313 + atomic_long_add_unchecked(1 + msg->retries,
32314 &port->counter_group[CM_XMIT].counter[attr_index]);
32315 if (msg->retries)
32316 - atomic_long_add(msg->retries,
32317 + atomic_long_add_unchecked(msg->retries,
32318 &port->counter_group[CM_XMIT_RETRIES].
32319 counter[attr_index]);
32320
32321 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32322 }
32323
32324 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32325 - atomic_long_inc(&port->counter_group[CM_RECV].
32326 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32327 counter[attr_id - CM_ATTR_ID_OFFSET]);
32328
32329 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32330 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32331 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32332
32333 return sprintf(buf, "%ld\n",
32334 - atomic_long_read(&group->counter[cm_attr->index]));
32335 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32336 }
32337
32338 static const struct sysfs_ops cm_counter_ops = {
32339 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32340 index 176c8f9..2627b62 100644
32341 --- a/drivers/infiniband/core/fmr_pool.c
32342 +++ b/drivers/infiniband/core/fmr_pool.c
32343 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32344
32345 struct task_struct *thread;
32346
32347 - atomic_t req_ser;
32348 - atomic_t flush_ser;
32349 + atomic_unchecked_t req_ser;
32350 + atomic_unchecked_t flush_ser;
32351
32352 wait_queue_head_t force_wait;
32353 };
32354 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32355 struct ib_fmr_pool *pool = pool_ptr;
32356
32357 do {
32358 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32359 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32360 ib_fmr_batch_release(pool);
32361
32362 - atomic_inc(&pool->flush_ser);
32363 + atomic_inc_unchecked(&pool->flush_ser);
32364 wake_up_interruptible(&pool->force_wait);
32365
32366 if (pool->flush_function)
32367 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32368 }
32369
32370 set_current_state(TASK_INTERRUPTIBLE);
32371 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32372 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32373 !kthread_should_stop())
32374 schedule();
32375 __set_current_state(TASK_RUNNING);
32376 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32377 pool->dirty_watermark = params->dirty_watermark;
32378 pool->dirty_len = 0;
32379 spin_lock_init(&pool->pool_lock);
32380 - atomic_set(&pool->req_ser, 0);
32381 - atomic_set(&pool->flush_ser, 0);
32382 + atomic_set_unchecked(&pool->req_ser, 0);
32383 + atomic_set_unchecked(&pool->flush_ser, 0);
32384 init_waitqueue_head(&pool->force_wait);
32385
32386 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32387 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32388 }
32389 spin_unlock_irq(&pool->pool_lock);
32390
32391 - serial = atomic_inc_return(&pool->req_ser);
32392 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32393 wake_up_process(pool->thread);
32394
32395 if (wait_event_interruptible(pool->force_wait,
32396 - atomic_read(&pool->flush_ser) - serial >= 0))
32397 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32398 return -EINTR;
32399
32400 return 0;
32401 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32402 } else {
32403 list_add_tail(&fmr->list, &pool->dirty_list);
32404 if (++pool->dirty_len >= pool->dirty_watermark) {
32405 - atomic_inc(&pool->req_ser);
32406 + atomic_inc_unchecked(&pool->req_ser);
32407 wake_up_process(pool->thread);
32408 }
32409 }
32410 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32411 index 57e07c6..56d09d4 100644
32412 --- a/drivers/infiniband/hw/cxgb4/mem.c
32413 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32414 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32415 int err;
32416 struct fw_ri_tpte tpt;
32417 u32 stag_idx;
32418 - static atomic_t key;
32419 + static atomic_unchecked_t key;
32420
32421 if (c4iw_fatal_error(rdev))
32422 return -EIO;
32423 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32424 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32425 rdev->stats.stag.max = rdev->stats.stag.cur;
32426 mutex_unlock(&rdev->stats.lock);
32427 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32428 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32429 }
32430 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32431 __func__, stag_state, type, pdid, stag_idx);
32432 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32433 index 79b3dbc..96e5fcc 100644
32434 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32435 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32436 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32437 struct ib_atomic_eth *ateth;
32438 struct ipath_ack_entry *e;
32439 u64 vaddr;
32440 - atomic64_t *maddr;
32441 + atomic64_unchecked_t *maddr;
32442 u64 sdata;
32443 u32 rkey;
32444 u8 next;
32445 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32446 IB_ACCESS_REMOTE_ATOMIC)))
32447 goto nack_acc_unlck;
32448 /* Perform atomic OP and save result. */
32449 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32450 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32451 sdata = be64_to_cpu(ateth->swap_data);
32452 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32453 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32454 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32455 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32456 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32457 be64_to_cpu(ateth->compare_data),
32458 sdata);
32459 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32460 index 1f95bba..9530f87 100644
32461 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32462 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32463 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32464 unsigned long flags;
32465 struct ib_wc wc;
32466 u64 sdata;
32467 - atomic64_t *maddr;
32468 + atomic64_unchecked_t *maddr;
32469 enum ib_wc_status send_status;
32470
32471 /*
32472 @@ -382,11 +382,11 @@ again:
32473 IB_ACCESS_REMOTE_ATOMIC)))
32474 goto acc_err;
32475 /* Perform atomic OP and save result. */
32476 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32477 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32478 sdata = wqe->wr.wr.atomic.compare_add;
32479 *(u64 *) sqp->s_sge.sge.vaddr =
32480 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32481 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32482 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32483 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32484 sdata, wqe->wr.wr.atomic.swap);
32485 goto send_comp;
32486 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32487 index 7140199..da60063 100644
32488 --- a/drivers/infiniband/hw/nes/nes.c
32489 +++ b/drivers/infiniband/hw/nes/nes.c
32490 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32491 LIST_HEAD(nes_adapter_list);
32492 static LIST_HEAD(nes_dev_list);
32493
32494 -atomic_t qps_destroyed;
32495 +atomic_unchecked_t qps_destroyed;
32496
32497 static unsigned int ee_flsh_adapter;
32498 static unsigned int sysfs_nonidx_addr;
32499 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32500 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32501 struct nes_adapter *nesadapter = nesdev->nesadapter;
32502
32503 - atomic_inc(&qps_destroyed);
32504 + atomic_inc_unchecked(&qps_destroyed);
32505
32506 /* Free the control structures */
32507
32508 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32509 index c438e46..ca30356 100644
32510 --- a/drivers/infiniband/hw/nes/nes.h
32511 +++ b/drivers/infiniband/hw/nes/nes.h
32512 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32513 extern unsigned int wqm_quanta;
32514 extern struct list_head nes_adapter_list;
32515
32516 -extern atomic_t cm_connects;
32517 -extern atomic_t cm_accepts;
32518 -extern atomic_t cm_disconnects;
32519 -extern atomic_t cm_closes;
32520 -extern atomic_t cm_connecteds;
32521 -extern atomic_t cm_connect_reqs;
32522 -extern atomic_t cm_rejects;
32523 -extern atomic_t mod_qp_timouts;
32524 -extern atomic_t qps_created;
32525 -extern atomic_t qps_destroyed;
32526 -extern atomic_t sw_qps_destroyed;
32527 +extern atomic_unchecked_t cm_connects;
32528 +extern atomic_unchecked_t cm_accepts;
32529 +extern atomic_unchecked_t cm_disconnects;
32530 +extern atomic_unchecked_t cm_closes;
32531 +extern atomic_unchecked_t cm_connecteds;
32532 +extern atomic_unchecked_t cm_connect_reqs;
32533 +extern atomic_unchecked_t cm_rejects;
32534 +extern atomic_unchecked_t mod_qp_timouts;
32535 +extern atomic_unchecked_t qps_created;
32536 +extern atomic_unchecked_t qps_destroyed;
32537 +extern atomic_unchecked_t sw_qps_destroyed;
32538 extern u32 mh_detected;
32539 extern u32 mh_pauses_sent;
32540 extern u32 cm_packets_sent;
32541 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32542 extern u32 cm_packets_received;
32543 extern u32 cm_packets_dropped;
32544 extern u32 cm_packets_retrans;
32545 -extern atomic_t cm_listens_created;
32546 -extern atomic_t cm_listens_destroyed;
32547 +extern atomic_unchecked_t cm_listens_created;
32548 +extern atomic_unchecked_t cm_listens_destroyed;
32549 extern u32 cm_backlog_drops;
32550 -extern atomic_t cm_loopbacks;
32551 -extern atomic_t cm_nodes_created;
32552 -extern atomic_t cm_nodes_destroyed;
32553 -extern atomic_t cm_accel_dropped_pkts;
32554 -extern atomic_t cm_resets_recvd;
32555 -extern atomic_t pau_qps_created;
32556 -extern atomic_t pau_qps_destroyed;
32557 +extern atomic_unchecked_t cm_loopbacks;
32558 +extern atomic_unchecked_t cm_nodes_created;
32559 +extern atomic_unchecked_t cm_nodes_destroyed;
32560 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32561 +extern atomic_unchecked_t cm_resets_recvd;
32562 +extern atomic_unchecked_t pau_qps_created;
32563 +extern atomic_unchecked_t pau_qps_destroyed;
32564
32565 extern u32 int_mod_timer_init;
32566 extern u32 int_mod_cq_depth_256;
32567 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32568 index 020e95c..fbb3450 100644
32569 --- a/drivers/infiniband/hw/nes/nes_cm.c
32570 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32571 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32572 u32 cm_packets_retrans;
32573 u32 cm_packets_created;
32574 u32 cm_packets_received;
32575 -atomic_t cm_listens_created;
32576 -atomic_t cm_listens_destroyed;
32577 +atomic_unchecked_t cm_listens_created;
32578 +atomic_unchecked_t cm_listens_destroyed;
32579 u32 cm_backlog_drops;
32580 -atomic_t cm_loopbacks;
32581 -atomic_t cm_nodes_created;
32582 -atomic_t cm_nodes_destroyed;
32583 -atomic_t cm_accel_dropped_pkts;
32584 -atomic_t cm_resets_recvd;
32585 +atomic_unchecked_t cm_loopbacks;
32586 +atomic_unchecked_t cm_nodes_created;
32587 +atomic_unchecked_t cm_nodes_destroyed;
32588 +atomic_unchecked_t cm_accel_dropped_pkts;
32589 +atomic_unchecked_t cm_resets_recvd;
32590
32591 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32592 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32593 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32594
32595 static struct nes_cm_core *g_cm_core;
32596
32597 -atomic_t cm_connects;
32598 -atomic_t cm_accepts;
32599 -atomic_t cm_disconnects;
32600 -atomic_t cm_closes;
32601 -atomic_t cm_connecteds;
32602 -atomic_t cm_connect_reqs;
32603 -atomic_t cm_rejects;
32604 +atomic_unchecked_t cm_connects;
32605 +atomic_unchecked_t cm_accepts;
32606 +atomic_unchecked_t cm_disconnects;
32607 +atomic_unchecked_t cm_closes;
32608 +atomic_unchecked_t cm_connecteds;
32609 +atomic_unchecked_t cm_connect_reqs;
32610 +atomic_unchecked_t cm_rejects;
32611
32612 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32613 {
32614 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32615 kfree(listener);
32616 listener = NULL;
32617 ret = 0;
32618 - atomic_inc(&cm_listens_destroyed);
32619 + atomic_inc_unchecked(&cm_listens_destroyed);
32620 } else {
32621 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32622 }
32623 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32624 cm_node->rem_mac);
32625
32626 add_hte_node(cm_core, cm_node);
32627 - atomic_inc(&cm_nodes_created);
32628 + atomic_inc_unchecked(&cm_nodes_created);
32629
32630 return cm_node;
32631 }
32632 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32633 }
32634
32635 atomic_dec(&cm_core->node_cnt);
32636 - atomic_inc(&cm_nodes_destroyed);
32637 + atomic_inc_unchecked(&cm_nodes_destroyed);
32638 nesqp = cm_node->nesqp;
32639 if (nesqp) {
32640 nesqp->cm_node = NULL;
32641 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32642
32643 static void drop_packet(struct sk_buff *skb)
32644 {
32645 - atomic_inc(&cm_accel_dropped_pkts);
32646 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32647 dev_kfree_skb_any(skb);
32648 }
32649
32650 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32651 {
32652
32653 int reset = 0; /* whether to send reset in case of err.. */
32654 - atomic_inc(&cm_resets_recvd);
32655 + atomic_inc_unchecked(&cm_resets_recvd);
32656 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32657 " refcnt=%d\n", cm_node, cm_node->state,
32658 atomic_read(&cm_node->ref_count));
32659 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32660 rem_ref_cm_node(cm_node->cm_core, cm_node);
32661 return NULL;
32662 }
32663 - atomic_inc(&cm_loopbacks);
32664 + atomic_inc_unchecked(&cm_loopbacks);
32665 loopbackremotenode->loopbackpartner = cm_node;
32666 loopbackremotenode->tcp_cntxt.rcv_wscale =
32667 NES_CM_DEFAULT_RCV_WND_SCALE;
32668 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32669 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32670 else {
32671 rem_ref_cm_node(cm_core, cm_node);
32672 - atomic_inc(&cm_accel_dropped_pkts);
32673 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32674 dev_kfree_skb_any(skb);
32675 }
32676 break;
32677 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32678
32679 if ((cm_id) && (cm_id->event_handler)) {
32680 if (issue_disconn) {
32681 - atomic_inc(&cm_disconnects);
32682 + atomic_inc_unchecked(&cm_disconnects);
32683 cm_event.event = IW_CM_EVENT_DISCONNECT;
32684 cm_event.status = disconn_status;
32685 cm_event.local_addr = cm_id->local_addr;
32686 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32687 }
32688
32689 if (issue_close) {
32690 - atomic_inc(&cm_closes);
32691 + atomic_inc_unchecked(&cm_closes);
32692 nes_disconnect(nesqp, 1);
32693
32694 cm_id->provider_data = nesqp;
32695 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32696
32697 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32698 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32699 - atomic_inc(&cm_accepts);
32700 + atomic_inc_unchecked(&cm_accepts);
32701
32702 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32703 netdev_refcnt_read(nesvnic->netdev));
32704 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32705 struct nes_cm_core *cm_core;
32706 u8 *start_buff;
32707
32708 - atomic_inc(&cm_rejects);
32709 + atomic_inc_unchecked(&cm_rejects);
32710 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32711 loopback = cm_node->loopbackpartner;
32712 cm_core = cm_node->cm_core;
32713 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32714 ntohl(cm_id->local_addr.sin_addr.s_addr),
32715 ntohs(cm_id->local_addr.sin_port));
32716
32717 - atomic_inc(&cm_connects);
32718 + atomic_inc_unchecked(&cm_connects);
32719 nesqp->active_conn = 1;
32720
32721 /* cache the cm_id in the qp */
32722 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32723 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32724 return err;
32725 }
32726 - atomic_inc(&cm_listens_created);
32727 + atomic_inc_unchecked(&cm_listens_created);
32728 }
32729
32730 cm_id->add_ref(cm_id);
32731 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32732
32733 if (nesqp->destroyed)
32734 return;
32735 - atomic_inc(&cm_connecteds);
32736 + atomic_inc_unchecked(&cm_connecteds);
32737 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32738 " local port 0x%04X. jiffies = %lu.\n",
32739 nesqp->hwqp.qp_id,
32740 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32741
32742 cm_id->add_ref(cm_id);
32743 ret = cm_id->event_handler(cm_id, &cm_event);
32744 - atomic_inc(&cm_closes);
32745 + atomic_inc_unchecked(&cm_closes);
32746 cm_event.event = IW_CM_EVENT_CLOSE;
32747 cm_event.status = 0;
32748 cm_event.provider_data = cm_id->provider_data;
32749 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32750 return;
32751 cm_id = cm_node->cm_id;
32752
32753 - atomic_inc(&cm_connect_reqs);
32754 + atomic_inc_unchecked(&cm_connect_reqs);
32755 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32756 cm_node, cm_id, jiffies);
32757
32758 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32759 return;
32760 cm_id = cm_node->cm_id;
32761
32762 - atomic_inc(&cm_connect_reqs);
32763 + atomic_inc_unchecked(&cm_connect_reqs);
32764 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32765 cm_node, cm_id, jiffies);
32766
32767 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32768 index 3ba7be3..c81f6ff 100644
32769 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32770 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32771 @@ -40,8 +40,8 @@
32772 #include "nes.h"
32773 #include "nes_mgt.h"
32774
32775 -atomic_t pau_qps_created;
32776 -atomic_t pau_qps_destroyed;
32777 +atomic_unchecked_t pau_qps_created;
32778 +atomic_unchecked_t pau_qps_destroyed;
32779
32780 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32781 {
32782 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32783 {
32784 struct sk_buff *skb;
32785 unsigned long flags;
32786 - atomic_inc(&pau_qps_destroyed);
32787 + atomic_inc_unchecked(&pau_qps_destroyed);
32788
32789 /* Free packets that have not yet been forwarded */
32790 /* Lock is acquired by skb_dequeue when removing the skb */
32791 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32792 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32793 skb_queue_head_init(&nesqp->pau_list);
32794 spin_lock_init(&nesqp->pau_lock);
32795 - atomic_inc(&pau_qps_created);
32796 + atomic_inc_unchecked(&pau_qps_created);
32797 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32798 }
32799
32800 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32801 index f3a3ecf..57d311d 100644
32802 --- a/drivers/infiniband/hw/nes/nes_nic.c
32803 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32804 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32805 target_stat_values[++index] = mh_detected;
32806 target_stat_values[++index] = mh_pauses_sent;
32807 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32808 - target_stat_values[++index] = atomic_read(&cm_connects);
32809 - target_stat_values[++index] = atomic_read(&cm_accepts);
32810 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32811 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32812 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32813 - target_stat_values[++index] = atomic_read(&cm_rejects);
32814 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32815 - target_stat_values[++index] = atomic_read(&qps_created);
32816 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32817 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32818 - target_stat_values[++index] = atomic_read(&cm_closes);
32819 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32820 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32821 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32822 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32823 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32824 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32825 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32826 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32827 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32828 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32829 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32830 target_stat_values[++index] = cm_packets_sent;
32831 target_stat_values[++index] = cm_packets_bounced;
32832 target_stat_values[++index] = cm_packets_created;
32833 target_stat_values[++index] = cm_packets_received;
32834 target_stat_values[++index] = cm_packets_dropped;
32835 target_stat_values[++index] = cm_packets_retrans;
32836 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32837 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32838 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32839 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32840 target_stat_values[++index] = cm_backlog_drops;
32841 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32842 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32843 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32844 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32845 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32846 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32847 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32848 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32849 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32850 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32851 target_stat_values[++index] = nesadapter->free_4kpbl;
32852 target_stat_values[++index] = nesadapter->free_256pbl;
32853 target_stat_values[++index] = int_mod_timer_init;
32854 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32855 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32856 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32857 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32858 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32859 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32860 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32861 }
32862
32863 /**
32864 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32865 index 8b8812d..a5e1133 100644
32866 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32867 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32868 @@ -46,9 +46,9 @@
32869
32870 #include <rdma/ib_umem.h>
32871
32872 -atomic_t mod_qp_timouts;
32873 -atomic_t qps_created;
32874 -atomic_t sw_qps_destroyed;
32875 +atomic_unchecked_t mod_qp_timouts;
32876 +atomic_unchecked_t qps_created;
32877 +atomic_unchecked_t sw_qps_destroyed;
32878
32879 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32880
32881 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32882 if (init_attr->create_flags)
32883 return ERR_PTR(-EINVAL);
32884
32885 - atomic_inc(&qps_created);
32886 + atomic_inc_unchecked(&qps_created);
32887 switch (init_attr->qp_type) {
32888 case IB_QPT_RC:
32889 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32890 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32891 struct iw_cm_event cm_event;
32892 int ret = 0;
32893
32894 - atomic_inc(&sw_qps_destroyed);
32895 + atomic_inc_unchecked(&sw_qps_destroyed);
32896 nesqp->destroyed = 1;
32897
32898 /* Blow away the connection if it exists. */
32899 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32900 index 7b1b8669..4b69f85 100644
32901 --- a/drivers/infiniband/hw/qib/qib.h
32902 +++ b/drivers/infiniband/hw/qib/qib.h
32903 @@ -51,6 +51,7 @@
32904 #include <linux/completion.h>
32905 #include <linux/kref.h>
32906 #include <linux/sched.h>
32907 +#include <linux/slab.h>
32908
32909 #include "qib_common.h"
32910 #include "qib_verbs.h"
32911 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32912 index da739d9..da1c7f4 100644
32913 --- a/drivers/input/gameport/gameport.c
32914 +++ b/drivers/input/gameport/gameport.c
32915 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32916 */
32917 static void gameport_init_port(struct gameport *gameport)
32918 {
32919 - static atomic_t gameport_no = ATOMIC_INIT(0);
32920 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32921
32922 __module_get(THIS_MODULE);
32923
32924 mutex_init(&gameport->drv_mutex);
32925 device_initialize(&gameport->dev);
32926 dev_set_name(&gameport->dev, "gameport%lu",
32927 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32928 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32929 gameport->dev.bus = &gameport_bus;
32930 gameport->dev.release = gameport_release_port;
32931 if (gameport->parent)
32932 diff --git a/drivers/input/input.c b/drivers/input/input.c
32933 index 8921c61..f5cd63d 100644
32934 --- a/drivers/input/input.c
32935 +++ b/drivers/input/input.c
32936 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32937 */
32938 int input_register_device(struct input_dev *dev)
32939 {
32940 - static atomic_t input_no = ATOMIC_INIT(0);
32941 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32942 struct input_handler *handler;
32943 const char *path;
32944 int error;
32945 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32946 dev->setkeycode = input_default_setkeycode;
32947
32948 dev_set_name(&dev->dev, "input%ld",
32949 - (unsigned long) atomic_inc_return(&input_no) - 1);
32950 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32951
32952 error = device_add(&dev->dev);
32953 if (error)
32954 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32955 index 04c69af..5f92d00 100644
32956 --- a/drivers/input/joystick/sidewinder.c
32957 +++ b/drivers/input/joystick/sidewinder.c
32958 @@ -30,6 +30,7 @@
32959 #include <linux/kernel.h>
32960 #include <linux/module.h>
32961 #include <linux/slab.h>
32962 +#include <linux/sched.h>
32963 #include <linux/init.h>
32964 #include <linux/input.h>
32965 #include <linux/gameport.h>
32966 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32967 index 83811e4..0822b90 100644
32968 --- a/drivers/input/joystick/xpad.c
32969 +++ b/drivers/input/joystick/xpad.c
32970 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32971
32972 static int xpad_led_probe(struct usb_xpad *xpad)
32973 {
32974 - static atomic_t led_seq = ATOMIC_INIT(0);
32975 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32976 long led_no;
32977 struct xpad_led *led;
32978 struct led_classdev *led_cdev;
32979 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32980 if (!led)
32981 return -ENOMEM;
32982
32983 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32984 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32985
32986 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32987 led->xpad = xpad;
32988 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32989 index 0110b5a..d3ad144 100644
32990 --- a/drivers/input/mousedev.c
32991 +++ b/drivers/input/mousedev.c
32992 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32993
32994 spin_unlock_irq(&client->packet_lock);
32995
32996 - if (copy_to_user(buffer, data, count))
32997 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32998 return -EFAULT;
32999
33000 return count;
33001 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33002 index d0f7533..fb8215b 100644
33003 --- a/drivers/input/serio/serio.c
33004 +++ b/drivers/input/serio/serio.c
33005 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33006 */
33007 static void serio_init_port(struct serio *serio)
33008 {
33009 - static atomic_t serio_no = ATOMIC_INIT(0);
33010 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33011
33012 __module_get(THIS_MODULE);
33013
33014 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33015 mutex_init(&serio->drv_mutex);
33016 device_initialize(&serio->dev);
33017 dev_set_name(&serio->dev, "serio%ld",
33018 - (long)atomic_inc_return(&serio_no) - 1);
33019 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33020 serio->dev.bus = &serio_bus;
33021 serio->dev.release = serio_release_port;
33022 serio->dev.groups = serio_device_attr_groups;
33023 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33024 index 38c4bd8..58965d9 100644
33025 --- a/drivers/isdn/capi/capi.c
33026 +++ b/drivers/isdn/capi/capi.c
33027 @@ -83,8 +83,8 @@ struct capiminor {
33028
33029 struct capi20_appl *ap;
33030 u32 ncci;
33031 - atomic_t datahandle;
33032 - atomic_t msgid;
33033 + atomic_unchecked_t datahandle;
33034 + atomic_unchecked_t msgid;
33035
33036 struct tty_port port;
33037 int ttyinstop;
33038 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33039 capimsg_setu16(s, 2, mp->ap->applid);
33040 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33041 capimsg_setu8 (s, 5, CAPI_RESP);
33042 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33043 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33044 capimsg_setu32(s, 8, mp->ncci);
33045 capimsg_setu16(s, 12, datahandle);
33046 }
33047 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33048 mp->outbytes -= len;
33049 spin_unlock_bh(&mp->outlock);
33050
33051 - datahandle = atomic_inc_return(&mp->datahandle);
33052 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33053 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33054 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33055 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33056 capimsg_setu16(skb->data, 2, mp->ap->applid);
33057 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33058 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33059 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33060 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33061 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33062 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33063 capimsg_setu16(skb->data, 16, len); /* Data length */
33064 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33065 index a6d9fd2..afdb8a3 100644
33066 --- a/drivers/isdn/gigaset/interface.c
33067 +++ b/drivers/isdn/gigaset/interface.c
33068 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33069 }
33070 tty->driver_data = cs;
33071
33072 - ++cs->port.count;
33073 + atomic_inc(&cs->port.count);
33074
33075 - if (cs->port.count == 1) {
33076 + if (atomic_read(&cs->port.count) == 1) {
33077 tty_port_tty_set(&cs->port, tty);
33078 tty->low_latency = 1;
33079 }
33080 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33081
33082 if (!cs->connected)
33083 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33084 - else if (!cs->port.count)
33085 + else if (!atomic_read(&cs->port.count))
33086 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33087 - else if (!--cs->port.count)
33088 + else if (!atomic_dec_return(&cs->port.count))
33089 tty_port_tty_set(&cs->port, NULL);
33090
33091 mutex_unlock(&cs->mutex);
33092 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33093 index 821f7ac..28d4030 100644
33094 --- a/drivers/isdn/hardware/avm/b1.c
33095 +++ b/drivers/isdn/hardware/avm/b1.c
33096 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33097 }
33098 if (left) {
33099 if (t4file->user) {
33100 - if (copy_from_user(buf, dp, left))
33101 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33102 return -EFAULT;
33103 } else {
33104 memcpy(buf, dp, left);
33105 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33106 }
33107 if (left) {
33108 if (config->user) {
33109 - if (copy_from_user(buf, dp, left))
33110 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33111 return -EFAULT;
33112 } else {
33113 memcpy(buf, dp, left);
33114 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33115 index dd6b53a..19d9ee6 100644
33116 --- a/drivers/isdn/hardware/eicon/divasync.h
33117 +++ b/drivers/isdn/hardware/eicon/divasync.h
33118 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33119 } diva_didd_add_adapter_t;
33120 typedef struct _diva_didd_remove_adapter {
33121 IDI_CALL p_request;
33122 -} diva_didd_remove_adapter_t;
33123 +} __no_const diva_didd_remove_adapter_t;
33124 typedef struct _diva_didd_read_adapter_array {
33125 void *buffer;
33126 dword length;
33127 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33128 index d303e65..28bcb7b 100644
33129 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33130 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33131 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33132 typedef struct _diva_os_idi_adapter_interface {
33133 diva_init_card_proc_t cleanup_adapter_proc;
33134 diva_cmd_card_proc_t cmd_proc;
33135 -} diva_os_idi_adapter_interface_t;
33136 +} __no_const diva_os_idi_adapter_interface_t;
33137
33138 typedef struct _diva_os_xdi_adapter {
33139 struct list_head link;
33140 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33141 index 7bc5067..fd36232 100644
33142 --- a/drivers/isdn/i4l/isdn_tty.c
33143 +++ b/drivers/isdn/i4l/isdn_tty.c
33144 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33145 port = &info->port;
33146 #ifdef ISDN_DEBUG_MODEM_OPEN
33147 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33148 - port->count);
33149 + atomic_read(&port->count))
33150 #endif
33151 - port->count++;
33152 + atomic_inc(&port->count);
33153 tty->driver_data = info;
33154 port->tty = tty;
33155 tty->port = port;
33156 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33157 #endif
33158 return;
33159 }
33160 - if ((tty->count == 1) && (port->count != 1)) {
33161 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33162 /*
33163 * Uh, oh. tty->count is 1, which means that the tty
33164 * structure will be freed. Info->count should always
33165 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33166 * serial port won't be shutdown.
33167 */
33168 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33169 - "info->count is %d\n", port->count);
33170 - port->count = 1;
33171 + "info->count is %d\n", atomic_read(&port->count));
33172 + atomic_set(&port->count, 1);
33173 }
33174 - if (--port->count < 0) {
33175 + if (atomic_dec_return(&port->count) < 0) {
33176 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33177 - info->line, port->count);
33178 - port->count = 0;
33179 + info->line, atomic_read(&port->count));
33180 + atomic_set(&port->count, 0);
33181 }
33182 - if (port->count) {
33183 + if (atomic_read(&port->count)) {
33184 #ifdef ISDN_DEBUG_MODEM_OPEN
33185 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33186 #endif
33187 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33188 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33189 return;
33190 isdn_tty_shutdown(info);
33191 - port->count = 0;
33192 + atomic_set(&port->count, 0);
33193 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33194 port->tty = NULL;
33195 wake_up_interruptible(&port->open_wait);
33196 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33197 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33198 modem_info *info = &dev->mdm.info[i];
33199
33200 - if (info->port.count == 0)
33201 + if (atomic_read(&info->port.count) == 0)
33202 continue;
33203 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33204 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33205 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33206 index e74df7c..03a03ba 100644
33207 --- a/drivers/isdn/icn/icn.c
33208 +++ b/drivers/isdn/icn/icn.c
33209 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33210 if (count > len)
33211 count = len;
33212 if (user) {
33213 - if (copy_from_user(msg, buf, count))
33214 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33215 return -EFAULT;
33216 } else
33217 memcpy(msg, buf, count);
33218 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33219 index b5fdcb7..5b6c59f 100644
33220 --- a/drivers/lguest/core.c
33221 +++ b/drivers/lguest/core.c
33222 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33223 * it's worked so far. The end address needs +1 because __get_vm_area
33224 * allocates an extra guard page, so we need space for that.
33225 */
33226 +
33227 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33228 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33229 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33230 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33231 +#else
33232 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33233 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33234 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33235 +#endif
33236 +
33237 if (!switcher_vma) {
33238 err = -ENOMEM;
33239 printk("lguest: could not map switcher pages high\n");
33240 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33241 * Now the Switcher is mapped at the right address, we can't fail!
33242 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33243 */
33244 - memcpy(switcher_vma->addr, start_switcher_text,
33245 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33246 end_switcher_text - start_switcher_text);
33247
33248 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33249 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33250 index 39809035..ce25c5e 100644
33251 --- a/drivers/lguest/x86/core.c
33252 +++ b/drivers/lguest/x86/core.c
33253 @@ -59,7 +59,7 @@ static struct {
33254 /* Offset from where switcher.S was compiled to where we've copied it */
33255 static unsigned long switcher_offset(void)
33256 {
33257 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33258 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33259 }
33260
33261 /* This cpu's struct lguest_pages. */
33262 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33263 * These copies are pretty cheap, so we do them unconditionally: */
33264 /* Save the current Host top-level page directory.
33265 */
33266 +
33267 +#ifdef CONFIG_PAX_PER_CPU_PGD
33268 + pages->state.host_cr3 = read_cr3();
33269 +#else
33270 pages->state.host_cr3 = __pa(current->mm->pgd);
33271 +#endif
33272 +
33273 /*
33274 * Set up the Guest's page tables to see this CPU's pages (and no
33275 * other CPU's pages).
33276 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33277 * compiled-in switcher code and the high-mapped copy we just made.
33278 */
33279 for (i = 0; i < IDT_ENTRIES; i++)
33280 - default_idt_entries[i] += switcher_offset();
33281 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33282
33283 /*
33284 * Set up the Switcher's per-cpu areas.
33285 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33286 * it will be undisturbed when we switch. To change %cs and jump we
33287 * need this structure to feed to Intel's "lcall" instruction.
33288 */
33289 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33290 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33291 lguest_entry.segment = LGUEST_CS;
33292
33293 /*
33294 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33295 index 40634b0..4f5855e 100644
33296 --- a/drivers/lguest/x86/switcher_32.S
33297 +++ b/drivers/lguest/x86/switcher_32.S
33298 @@ -87,6 +87,7 @@
33299 #include <asm/page.h>
33300 #include <asm/segment.h>
33301 #include <asm/lguest.h>
33302 +#include <asm/processor-flags.h>
33303
33304 // We mark the start of the code to copy
33305 // It's placed in .text tho it's never run here
33306 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33307 // Changes type when we load it: damn Intel!
33308 // For after we switch over our page tables
33309 // That entry will be read-only: we'd crash.
33310 +
33311 +#ifdef CONFIG_PAX_KERNEXEC
33312 + mov %cr0, %edx
33313 + xor $X86_CR0_WP, %edx
33314 + mov %edx, %cr0
33315 +#endif
33316 +
33317 movl $(GDT_ENTRY_TSS*8), %edx
33318 ltr %dx
33319
33320 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33321 // Let's clear it again for our return.
33322 // The GDT descriptor of the Host
33323 // Points to the table after two "size" bytes
33324 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33325 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33326 // Clear "used" from type field (byte 5, bit 2)
33327 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33328 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33329 +
33330 +#ifdef CONFIG_PAX_KERNEXEC
33331 + mov %cr0, %eax
33332 + xor $X86_CR0_WP, %eax
33333 + mov %eax, %cr0
33334 +#endif
33335
33336 // Once our page table's switched, the Guest is live!
33337 // The Host fades as we run this final step.
33338 @@ -295,13 +309,12 @@ deliver_to_host:
33339 // I consulted gcc, and it gave
33340 // These instructions, which I gladly credit:
33341 leal (%edx,%ebx,8), %eax
33342 - movzwl (%eax),%edx
33343 - movl 4(%eax), %eax
33344 - xorw %ax, %ax
33345 - orl %eax, %edx
33346 + movl 4(%eax), %edx
33347 + movw (%eax), %dx
33348 // Now the address of the handler's in %edx
33349 // We call it now: its "iret" drops us home.
33350 - jmp *%edx
33351 + ljmp $__KERNEL_CS, $1f
33352 +1: jmp *%edx
33353
33354 // Every interrupt can come to us here
33355 // But we must truly tell each apart.
33356 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33357 index 20e5c2c..9e849a9 100644
33358 --- a/drivers/macintosh/macio_asic.c
33359 +++ b/drivers/macintosh/macio_asic.c
33360 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33361 * MacIO is matched against any Apple ID, it's probe() function
33362 * will then decide wether it applies or not
33363 */
33364 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33365 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33366 .vendor = PCI_VENDOR_ID_APPLE,
33367 .device = PCI_ANY_ID,
33368 .subvendor = PCI_ANY_ID,
33369 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33370 index 94e7f6b..2f4a0d8 100644
33371 --- a/drivers/md/bitmap.c
33372 +++ b/drivers/md/bitmap.c
33373 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33374 chunk_kb ? "KB" : "B");
33375 if (bitmap->storage.file) {
33376 seq_printf(seq, ", file: ");
33377 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33378 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33379 }
33380
33381 seq_printf(seq, "\n");
33382 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33383 index afd9598..528d8f9 100644
33384 --- a/drivers/md/dm-ioctl.c
33385 +++ b/drivers/md/dm-ioctl.c
33386 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33387 cmd == DM_LIST_VERSIONS_CMD)
33388 return 0;
33389
33390 - if ((cmd == DM_DEV_CREATE_CMD)) {
33391 + if (cmd == DM_DEV_CREATE_CMD) {
33392 if (!*param->name) {
33393 DMWARN("name not supplied when creating device");
33394 return -EINVAL;
33395 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33396 index bc5ddba8..b961159 100644
33397 --- a/drivers/md/dm-raid1.c
33398 +++ b/drivers/md/dm-raid1.c
33399 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33400
33401 struct mirror {
33402 struct mirror_set *ms;
33403 - atomic_t error_count;
33404 + atomic_unchecked_t error_count;
33405 unsigned long error_type;
33406 struct dm_dev *dev;
33407 sector_t offset;
33408 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33409 struct mirror *m;
33410
33411 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33412 - if (!atomic_read(&m->error_count))
33413 + if (!atomic_read_unchecked(&m->error_count))
33414 return m;
33415
33416 return NULL;
33417 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33418 * simple way to tell if a device has encountered
33419 * errors.
33420 */
33421 - atomic_inc(&m->error_count);
33422 + atomic_inc_unchecked(&m->error_count);
33423
33424 if (test_and_set_bit(error_type, &m->error_type))
33425 return;
33426 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33427 struct mirror *m = get_default_mirror(ms);
33428
33429 do {
33430 - if (likely(!atomic_read(&m->error_count)))
33431 + if (likely(!atomic_read_unchecked(&m->error_count)))
33432 return m;
33433
33434 if (m-- == ms->mirror)
33435 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33436 {
33437 struct mirror *default_mirror = get_default_mirror(m->ms);
33438
33439 - return !atomic_read(&default_mirror->error_count);
33440 + return !atomic_read_unchecked(&default_mirror->error_count);
33441 }
33442
33443 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33444 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33445 */
33446 if (likely(region_in_sync(ms, region, 1)))
33447 m = choose_mirror(ms, bio->bi_sector);
33448 - else if (m && atomic_read(&m->error_count))
33449 + else if (m && atomic_read_unchecked(&m->error_count))
33450 m = NULL;
33451
33452 if (likely(m))
33453 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33454 }
33455
33456 ms->mirror[mirror].ms = ms;
33457 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33458 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33459 ms->mirror[mirror].error_type = 0;
33460 ms->mirror[mirror].offset = offset;
33461
33462 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33463 */
33464 static char device_status_char(struct mirror *m)
33465 {
33466 - if (!atomic_read(&(m->error_count)))
33467 + if (!atomic_read_unchecked(&(m->error_count)))
33468 return 'A';
33469
33470 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33471 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33472 index a087bf2..4c94786 100644
33473 --- a/drivers/md/dm-stripe.c
33474 +++ b/drivers/md/dm-stripe.c
33475 @@ -20,7 +20,7 @@ struct stripe {
33476 struct dm_dev *dev;
33477 sector_t physical_start;
33478
33479 - atomic_t error_count;
33480 + atomic_unchecked_t error_count;
33481 };
33482
33483 struct stripe_c {
33484 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33485 kfree(sc);
33486 return r;
33487 }
33488 - atomic_set(&(sc->stripe[i].error_count), 0);
33489 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33490 }
33491
33492 ti->private = sc;
33493 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33494 DMEMIT("%d ", sc->stripes);
33495 for (i = 0; i < sc->stripes; i++) {
33496 DMEMIT("%s ", sc->stripe[i].dev->name);
33497 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33498 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33499 'D' : 'A';
33500 }
33501 buffer[i] = '\0';
33502 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33503 */
33504 for (i = 0; i < sc->stripes; i++)
33505 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33506 - atomic_inc(&(sc->stripe[i].error_count));
33507 - if (atomic_read(&(sc->stripe[i].error_count)) <
33508 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33509 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33510 DM_IO_ERROR_THRESHOLD)
33511 schedule_work(&sc->trigger_event);
33512 }
33513 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33514 index 100368e..64262ce 100644
33515 --- a/drivers/md/dm-table.c
33516 +++ b/drivers/md/dm-table.c
33517 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33518 if (!dev_size)
33519 return 0;
33520
33521 - if ((start >= dev_size) || (start + len > dev_size)) {
33522 + if ((start >= dev_size) || (len > dev_size - start)) {
33523 DMWARN("%s: %s too small for target: "
33524 "start=%llu, len=%llu, dev_size=%llu",
33525 dm_device_name(ti->table->md), bdevname(bdev, b),
33526 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33527 index 693e149..b7e0fde 100644
33528 --- a/drivers/md/dm-thin-metadata.c
33529 +++ b/drivers/md/dm-thin-metadata.c
33530 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33531 {
33532 pmd->info.tm = pmd->tm;
33533 pmd->info.levels = 2;
33534 - pmd->info.value_type.context = pmd->data_sm;
33535 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33536 pmd->info.value_type.size = sizeof(__le64);
33537 pmd->info.value_type.inc = data_block_inc;
33538 pmd->info.value_type.dec = data_block_dec;
33539 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33540
33541 pmd->bl_info.tm = pmd->tm;
33542 pmd->bl_info.levels = 1;
33543 - pmd->bl_info.value_type.context = pmd->data_sm;
33544 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33545 pmd->bl_info.value_type.size = sizeof(__le64);
33546 pmd->bl_info.value_type.inc = data_block_inc;
33547 pmd->bl_info.value_type.dec = data_block_dec;
33548 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33549 index 67ffa39..cb3b1dd 100644
33550 --- a/drivers/md/dm.c
33551 +++ b/drivers/md/dm.c
33552 @@ -176,9 +176,9 @@ struct mapped_device {
33553 /*
33554 * Event handling.
33555 */
33556 - atomic_t event_nr;
33557 + atomic_unchecked_t event_nr;
33558 wait_queue_head_t eventq;
33559 - atomic_t uevent_seq;
33560 + atomic_unchecked_t uevent_seq;
33561 struct list_head uevent_list;
33562 spinlock_t uevent_lock; /* Protect access to uevent_list */
33563
33564 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33565 rwlock_init(&md->map_lock);
33566 atomic_set(&md->holders, 1);
33567 atomic_set(&md->open_count, 0);
33568 - atomic_set(&md->event_nr, 0);
33569 - atomic_set(&md->uevent_seq, 0);
33570 + atomic_set_unchecked(&md->event_nr, 0);
33571 + atomic_set_unchecked(&md->uevent_seq, 0);
33572 INIT_LIST_HEAD(&md->uevent_list);
33573 spin_lock_init(&md->uevent_lock);
33574
33575 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33576
33577 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33578
33579 - atomic_inc(&md->event_nr);
33580 + atomic_inc_unchecked(&md->event_nr);
33581 wake_up(&md->eventq);
33582 }
33583
33584 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33585
33586 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33587 {
33588 - return atomic_add_return(1, &md->uevent_seq);
33589 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33590 }
33591
33592 uint32_t dm_get_event_nr(struct mapped_device *md)
33593 {
33594 - return atomic_read(&md->event_nr);
33595 + return atomic_read_unchecked(&md->event_nr);
33596 }
33597
33598 int dm_wait_event(struct mapped_device *md, int event_nr)
33599 {
33600 return wait_event_interruptible(md->eventq,
33601 - (event_nr != atomic_read(&md->event_nr)));
33602 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33603 }
33604
33605 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33606 diff --git a/drivers/md/md.c b/drivers/md/md.c
33607 index 308e87b..7f365d6 100644
33608 --- a/drivers/md/md.c
33609 +++ b/drivers/md/md.c
33610 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33611 * start build, activate spare
33612 */
33613 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33614 -static atomic_t md_event_count;
33615 +static atomic_unchecked_t md_event_count;
33616 void md_new_event(struct mddev *mddev)
33617 {
33618 - atomic_inc(&md_event_count);
33619 + atomic_inc_unchecked(&md_event_count);
33620 wake_up(&md_event_waiters);
33621 }
33622 EXPORT_SYMBOL_GPL(md_new_event);
33623 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33624 */
33625 static void md_new_event_inintr(struct mddev *mddev)
33626 {
33627 - atomic_inc(&md_event_count);
33628 + atomic_inc_unchecked(&md_event_count);
33629 wake_up(&md_event_waiters);
33630 }
33631
33632 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33633 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33634 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33635 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33636 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33637 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33638
33639 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33640 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33641 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33642 else
33643 sb->resync_offset = cpu_to_le64(0);
33644
33645 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33646 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33647
33648 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33649 sb->size = cpu_to_le64(mddev->dev_sectors);
33650 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33651 static ssize_t
33652 errors_show(struct md_rdev *rdev, char *page)
33653 {
33654 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33655 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33656 }
33657
33658 static ssize_t
33659 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33660 char *e;
33661 unsigned long n = simple_strtoul(buf, &e, 10);
33662 if (*buf && (*e == 0 || *e == '\n')) {
33663 - atomic_set(&rdev->corrected_errors, n);
33664 + atomic_set_unchecked(&rdev->corrected_errors, n);
33665 return len;
33666 }
33667 return -EINVAL;
33668 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33669 rdev->sb_loaded = 0;
33670 rdev->bb_page = NULL;
33671 atomic_set(&rdev->nr_pending, 0);
33672 - atomic_set(&rdev->read_errors, 0);
33673 - atomic_set(&rdev->corrected_errors, 0);
33674 + atomic_set_unchecked(&rdev->read_errors, 0);
33675 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33676
33677 INIT_LIST_HEAD(&rdev->same_set);
33678 init_waitqueue_head(&rdev->blocked_wait);
33679 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33680
33681 spin_unlock(&pers_lock);
33682 seq_printf(seq, "\n");
33683 - seq->poll_event = atomic_read(&md_event_count);
33684 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33685 return 0;
33686 }
33687 if (v == (void*)2) {
33688 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33689 return error;
33690
33691 seq = file->private_data;
33692 - seq->poll_event = atomic_read(&md_event_count);
33693 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33694 return error;
33695 }
33696
33697 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33698 /* always allow read */
33699 mask = POLLIN | POLLRDNORM;
33700
33701 - if (seq->poll_event != atomic_read(&md_event_count))
33702 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33703 mask |= POLLERR | POLLPRI;
33704 return mask;
33705 }
33706 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33707 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33708 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33709 (int)part_stat_read(&disk->part0, sectors[1]) -
33710 - atomic_read(&disk->sync_io);
33711 + atomic_read_unchecked(&disk->sync_io);
33712 /* sync IO will cause sync_io to increase before the disk_stats
33713 * as sync_io is counted when a request starts, and
33714 * disk_stats is counted when it completes.
33715 diff --git a/drivers/md/md.h b/drivers/md/md.h
33716 index f385b03..b600be8 100644
33717 --- a/drivers/md/md.h
33718 +++ b/drivers/md/md.h
33719 @@ -94,13 +94,13 @@ struct md_rdev {
33720 * only maintained for arrays that
33721 * support hot removal
33722 */
33723 - atomic_t read_errors; /* number of consecutive read errors that
33724 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33725 * we have tried to ignore.
33726 */
33727 struct timespec last_read_error; /* monotonic time since our
33728 * last read error
33729 */
33730 - atomic_t corrected_errors; /* number of corrected read errors,
33731 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33732 * for reporting to userspace and storing
33733 * in superblock.
33734 */
33735 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33736
33737 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33738 {
33739 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33740 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33741 }
33742
33743 struct md_personality
33744 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33745 index f6d29e6..7917f5e 100644
33746 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33747 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33748 @@ -22,7 +22,7 @@
33749 * Space map interface.
33750 */
33751 struct sm_disk {
33752 - struct dm_space_map sm;
33753 + dm_space_map_no_const sm;
33754
33755 struct ll_disk ll;
33756 struct ll_disk old_ll;
33757 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33758 index e89ae5e..062e4c2 100644
33759 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33760 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33761 @@ -43,7 +43,7 @@ struct block_op {
33762 };
33763
33764 struct sm_metadata {
33765 - struct dm_space_map sm;
33766 + dm_space_map_no_const sm;
33767
33768 struct ll_disk ll;
33769 struct ll_disk old_ll;
33770 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33771 index 1cbfc6b..56e1dbb 100644
33772 --- a/drivers/md/persistent-data/dm-space-map.h
33773 +++ b/drivers/md/persistent-data/dm-space-map.h
33774 @@ -60,6 +60,7 @@ struct dm_space_map {
33775 int (*root_size)(struct dm_space_map *sm, size_t *result);
33776 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33777 };
33778 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33779
33780 /*----------------------------------------------------------------*/
33781
33782 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33783 index 611b5f7..cee0bfb 100644
33784 --- a/drivers/md/raid1.c
33785 +++ b/drivers/md/raid1.c
33786 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33787 if (r1_sync_page_io(rdev, sect, s,
33788 bio->bi_io_vec[idx].bv_page,
33789 READ) != 0)
33790 - atomic_add(s, &rdev->corrected_errors);
33791 + atomic_add_unchecked(s, &rdev->corrected_errors);
33792 }
33793 sectors -= s;
33794 sect += s;
33795 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33796 test_bit(In_sync, &rdev->flags)) {
33797 if (r1_sync_page_io(rdev, sect, s,
33798 conf->tmppage, READ)) {
33799 - atomic_add(s, &rdev->corrected_errors);
33800 + atomic_add_unchecked(s, &rdev->corrected_errors);
33801 printk(KERN_INFO
33802 "md/raid1:%s: read error corrected "
33803 "(%d sectors at %llu on %s)\n",
33804 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33805 index a48c215..6bda6f4 100644
33806 --- a/drivers/md/raid10.c
33807 +++ b/drivers/md/raid10.c
33808 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33809 /* The write handler will notice the lack of
33810 * R10BIO_Uptodate and record any errors etc
33811 */
33812 - atomic_add(r10_bio->sectors,
33813 + atomic_add_unchecked(r10_bio->sectors,
33814 &conf->mirrors[d].rdev->corrected_errors);
33815
33816 /* for reconstruct, we always reschedule after a read.
33817 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33818 {
33819 struct timespec cur_time_mon;
33820 unsigned long hours_since_last;
33821 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33822 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33823
33824 ktime_get_ts(&cur_time_mon);
33825
33826 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33827 * overflowing the shift of read_errors by hours_since_last.
33828 */
33829 if (hours_since_last >= 8 * sizeof(read_errors))
33830 - atomic_set(&rdev->read_errors, 0);
33831 + atomic_set_unchecked(&rdev->read_errors, 0);
33832 else
33833 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33834 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33835 }
33836
33837 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33838 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33839 return;
33840
33841 check_decay_read_errors(mddev, rdev);
33842 - atomic_inc(&rdev->read_errors);
33843 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33844 + atomic_inc_unchecked(&rdev->read_errors);
33845 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33846 char b[BDEVNAME_SIZE];
33847 bdevname(rdev->bdev, b);
33848
33849 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33850 "md/raid10:%s: %s: Raid device exceeded "
33851 "read_error threshold [cur %d:max %d]\n",
33852 mdname(mddev), b,
33853 - atomic_read(&rdev->read_errors), max_read_errors);
33854 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33855 printk(KERN_NOTICE
33856 "md/raid10:%s: %s: Failing raid device\n",
33857 mdname(mddev), b);
33858 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33859 sect +
33860 choose_data_offset(r10_bio, rdev)),
33861 bdevname(rdev->bdev, b));
33862 - atomic_add(s, &rdev->corrected_errors);
33863 + atomic_add_unchecked(s, &rdev->corrected_errors);
33864 }
33865
33866 rdev_dec_pending(rdev, mddev);
33867 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33868 index 0689173..35df76c 100644
33869 --- a/drivers/md/raid5.c
33870 +++ b/drivers/md/raid5.c
33871 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33872 mdname(conf->mddev), STRIPE_SECTORS,
33873 (unsigned long long)s,
33874 bdevname(rdev->bdev, b));
33875 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33876 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33877 clear_bit(R5_ReadError, &sh->dev[i].flags);
33878 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33879 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33880 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33881
33882 - if (atomic_read(&rdev->read_errors))
33883 - atomic_set(&rdev->read_errors, 0);
33884 + if (atomic_read_unchecked(&rdev->read_errors))
33885 + atomic_set_unchecked(&rdev->read_errors, 0);
33886 } else {
33887 const char *bdn = bdevname(rdev->bdev, b);
33888 int retry = 0;
33889 int set_bad = 0;
33890
33891 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33892 - atomic_inc(&rdev->read_errors);
33893 + atomic_inc_unchecked(&rdev->read_errors);
33894 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33895 printk_ratelimited(
33896 KERN_WARNING
33897 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33898 mdname(conf->mddev),
33899 (unsigned long long)s,
33900 bdn);
33901 - } else if (atomic_read(&rdev->read_errors)
33902 + } else if (atomic_read_unchecked(&rdev->read_errors)
33903 > conf->max_nr_stripes)
33904 printk(KERN_WARNING
33905 "md/raid:%s: Too many read errors, failing device %s.\n",
33906 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33907 index ebf3f05..b1f3e77 100644
33908 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33909 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33910 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33911 .subvendor = _subvend, .subdevice = _subdev, \
33912 .driver_data = (unsigned long)&_driverdata }
33913
33914 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33915 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33916 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33917 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33918 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33919 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33920 index fa7188a..04a045e 100644
33921 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33922 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33923 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33924 union {
33925 dmx_ts_cb ts;
33926 dmx_section_cb sec;
33927 - } cb;
33928 + } __no_const cb;
33929
33930 struct dvb_demux *demux;
33931 void *priv;
33932 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33933 index 39eab73..60033e7 100644
33934 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33935 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33936 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33937 const struct dvb_device *template, void *priv, int type)
33938 {
33939 struct dvb_device *dvbdev;
33940 - struct file_operations *dvbdevfops;
33941 + file_operations_no_const *dvbdevfops;
33942 struct device *clsdev;
33943 int minor;
33944 int id;
33945 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33946 index 3940bb0..fb3952a 100644
33947 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33948 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33949 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33950
33951 struct dib0700_adapter_state {
33952 int (*set_param_save) (struct dvb_frontend *);
33953 -};
33954 +} __no_const;
33955
33956 static int dib7070_set_param_override(struct dvb_frontend *fe)
33957 {
33958 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33959 index 9382895..ac8093c 100644
33960 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33961 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33962 @@ -95,7 +95,7 @@ struct su3000_state {
33963
33964 struct s6x0_state {
33965 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33966 -};
33967 +} __no_const;
33968
33969 /* debug */
33970 static int dvb_usb_dw2102_debug;
33971 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33972 index 404f63a..4796533 100644
33973 --- a/drivers/media/dvb/frontends/dib3000.h
33974 +++ b/drivers/media/dvb/frontends/dib3000.h
33975 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33976 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33977 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33978 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33979 -};
33980 +} __no_const;
33981
33982 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33983 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33984 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33985 index 72ee8de..eae0c80 100644
33986 --- a/drivers/media/dvb/ngene/ngene-cards.c
33987 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33988 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
33989
33990 /****************************************************************************/
33991
33992 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33993 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33994 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33995 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33996 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33997 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33998 index 697a421..16c5a5f 100644
33999 --- a/drivers/media/radio/radio-cadet.c
34000 +++ b/drivers/media/radio/radio-cadet.c
34001 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34002 unsigned char readbuf[RDS_BUFFER];
34003 int i = 0;
34004
34005 + if (count > RDS_BUFFER)
34006 + return -EFAULT;
34007 mutex_lock(&dev->lock);
34008 if (dev->rdsstat == 0)
34009 cadet_start_rds(dev);
34010 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34011 while (i < count && dev->rdsin != dev->rdsout)
34012 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34013
34014 - if (i && copy_to_user(data, readbuf, i))
34015 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34016 i = -EFAULT;
34017 unlock:
34018 mutex_unlock(&dev->lock);
34019 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34020 index 55cbd78..428b0da 100644
34021 --- a/drivers/media/radio/radio-tea5777.h
34022 +++ b/drivers/media/radio/radio-tea5777.h
34023 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34024
34025 struct radio_tea5777 {
34026 struct v4l2_device *v4l2_dev;
34027 - struct v4l2_file_operations fops;
34028 + v4l2_file_operations_no_const fops;
34029 struct video_device vd; /* video device */
34030 bool has_am; /* Device can tune to AM freqs */
34031 bool write_before_read; /* must write before read quirk */
34032 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34033 index 9cde353..8c6a1c3 100644
34034 --- a/drivers/media/video/au0828/au0828.h
34035 +++ b/drivers/media/video/au0828/au0828.h
34036 @@ -191,7 +191,7 @@ struct au0828_dev {
34037
34038 /* I2C */
34039 struct i2c_adapter i2c_adap;
34040 - struct i2c_algorithm i2c_algo;
34041 + i2c_algorithm_no_const i2c_algo;
34042 struct i2c_client i2c_client;
34043 u32 i2c_rc;
34044
34045 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34046 index dfac6e3..c26de31 100644
34047 --- a/drivers/media/video/cx88/cx88-alsa.c
34048 +++ b/drivers/media/video/cx88/cx88-alsa.c
34049 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34050 * Only boards with eeprom and byte 1 at eeprom=1 have it
34051 */
34052
34053 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34054 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34055 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34056 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34057 {0, }
34058 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34059 index 88cf9d9..bbc4b2c 100644
34060 --- a/drivers/media/video/omap/omap_vout.c
34061 +++ b/drivers/media/video/omap/omap_vout.c
34062 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34063 OMAP_VIDEO2,
34064 };
34065
34066 -static struct videobuf_queue_ops video_vbq_ops;
34067 /* Variables configurable through module params*/
34068 static u32 video1_numbuffers = 3;
34069 static u32 video2_numbuffers = 3;
34070 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34071 {
34072 struct videobuf_queue *q;
34073 struct omap_vout_device *vout = NULL;
34074 + static struct videobuf_queue_ops video_vbq_ops = {
34075 + .buf_setup = omap_vout_buffer_setup,
34076 + .buf_prepare = omap_vout_buffer_prepare,
34077 + .buf_release = omap_vout_buffer_release,
34078 + .buf_queue = omap_vout_buffer_queue,
34079 + };
34080
34081 vout = video_drvdata(file);
34082 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34083 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34084 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34085
34086 q = &vout->vbq;
34087 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34088 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34089 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34090 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34091 spin_lock_init(&vout->vbq_lock);
34092
34093 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34094 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34095 index 036952f..80d356d 100644
34096 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34097 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34098 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34099
34100 /* I2C stuff */
34101 struct i2c_adapter i2c_adap;
34102 - struct i2c_algorithm i2c_algo;
34103 + i2c_algorithm_no_const i2c_algo;
34104 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34105 int i2c_cx25840_hack_state;
34106 int i2c_linked;
34107 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34108 index 02194c0..091733b 100644
34109 --- a/drivers/media/video/timblogiw.c
34110 +++ b/drivers/media/video/timblogiw.c
34111 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34112
34113 /* Platform device functions */
34114
34115 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34116 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34117 .vidioc_querycap = timblogiw_querycap,
34118 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34119 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34120 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34121 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34122 };
34123
34124 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34125 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34126 .owner = THIS_MODULE,
34127 .open = timblogiw_open,
34128 .release = timblogiw_close,
34129 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34130 index d99db56..a16b959 100644
34131 --- a/drivers/message/fusion/mptbase.c
34132 +++ b/drivers/message/fusion/mptbase.c
34133 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34134 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34135 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34136
34137 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34138 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34139 +#else
34140 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34141 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34142 +#endif
34143 +
34144 /*
34145 * Rounding UP to nearest 4-kB boundary here...
34146 */
34147 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34148 index 551262e..7551198 100644
34149 --- a/drivers/message/fusion/mptsas.c
34150 +++ b/drivers/message/fusion/mptsas.c
34151 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34152 return 0;
34153 }
34154
34155 +static inline void
34156 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34157 +{
34158 + if (phy_info->port_details) {
34159 + phy_info->port_details->rphy = rphy;
34160 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34161 + ioc->name, rphy));
34162 + }
34163 +
34164 + if (rphy) {
34165 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34166 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34167 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34168 + ioc->name, rphy, rphy->dev.release));
34169 + }
34170 +}
34171 +
34172 /* no mutex */
34173 static void
34174 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34175 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34176 return NULL;
34177 }
34178
34179 -static inline void
34180 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34181 -{
34182 - if (phy_info->port_details) {
34183 - phy_info->port_details->rphy = rphy;
34184 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34185 - ioc->name, rphy));
34186 - }
34187 -
34188 - if (rphy) {
34189 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34190 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34191 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34192 - ioc->name, rphy, rphy->dev.release));
34193 - }
34194 -}
34195 -
34196 static inline struct sas_port *
34197 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34198 {
34199 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34200 index 0c3ced7..1fe34ec 100644
34201 --- a/drivers/message/fusion/mptscsih.c
34202 +++ b/drivers/message/fusion/mptscsih.c
34203 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34204
34205 h = shost_priv(SChost);
34206
34207 - if (h) {
34208 - if (h->info_kbuf == NULL)
34209 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34210 - return h->info_kbuf;
34211 - h->info_kbuf[0] = '\0';
34212 + if (!h)
34213 + return NULL;
34214
34215 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34216 - h->info_kbuf[size-1] = '\0';
34217 - }
34218 + if (h->info_kbuf == NULL)
34219 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34220 + return h->info_kbuf;
34221 + h->info_kbuf[0] = '\0';
34222 +
34223 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34224 + h->info_kbuf[size-1] = '\0';
34225
34226 return h->info_kbuf;
34227 }
34228 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34229 index 8001aa6..b137580 100644
34230 --- a/drivers/message/i2o/i2o_proc.c
34231 +++ b/drivers/message/i2o/i2o_proc.c
34232 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34233 "Array Controller Device"
34234 };
34235
34236 -static char *chtostr(char *tmp, u8 *chars, int n)
34237 -{
34238 - tmp[0] = 0;
34239 - return strncat(tmp, (char *)chars, n);
34240 -}
34241 -
34242 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34243 char *group)
34244 {
34245 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34246 } *result;
34247
34248 i2o_exec_execute_ddm_table ddm_table;
34249 - char tmp[28 + 1];
34250
34251 result = kmalloc(sizeof(*result), GFP_KERNEL);
34252 if (!result)
34253 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34254
34255 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34256 seq_printf(seq, "%-#8x", ddm_table.module_id);
34257 - seq_printf(seq, "%-29s",
34258 - chtostr(tmp, ddm_table.module_name_version, 28));
34259 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34260 seq_printf(seq, "%9d ", ddm_table.data_size);
34261 seq_printf(seq, "%8d", ddm_table.code_size);
34262
34263 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34264
34265 i2o_driver_result_table *result;
34266 i2o_driver_store_table *dst;
34267 - char tmp[28 + 1];
34268
34269 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34270 if (result == NULL)
34271 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34272
34273 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34274 seq_printf(seq, "%-#8x", dst->module_id);
34275 - seq_printf(seq, "%-29s",
34276 - chtostr(tmp, dst->module_name_version, 28));
34277 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34278 + seq_printf(seq, "%-.28s", dst->module_name_version);
34279 + seq_printf(seq, "%-.8s", dst->date);
34280 seq_printf(seq, "%8d ", dst->module_size);
34281 seq_printf(seq, "%8d ", dst->mpb_size);
34282 seq_printf(seq, "0x%04x", dst->module_flags);
34283 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34284 // == (allow) 512d bytes (max)
34285 static u16 *work16 = (u16 *) work32;
34286 int token;
34287 - char tmp[16 + 1];
34288
34289 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34290
34291 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34292 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34293 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34294 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34295 - seq_printf(seq, "Vendor info : %s\n",
34296 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34297 - seq_printf(seq, "Product info : %s\n",
34298 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34299 - seq_printf(seq, "Description : %s\n",
34300 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34301 - seq_printf(seq, "Product rev. : %s\n",
34302 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34303 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34304 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34305 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34306 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34307
34308 seq_printf(seq, "Serial number : ");
34309 print_serial_number(seq, (u8 *) (work32 + 16),
34310 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34311 u8 pad[256]; // allow up to 256 byte (max) serial number
34312 } result;
34313
34314 - char tmp[24 + 1];
34315 -
34316 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34317
34318 if (token < 0) {
34319 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34320 }
34321
34322 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34323 - seq_printf(seq, "Module name : %s\n",
34324 - chtostr(tmp, result.module_name, 24));
34325 - seq_printf(seq, "Module revision : %s\n",
34326 - chtostr(tmp, result.module_rev, 8));
34327 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34328 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34329
34330 seq_printf(seq, "Serial number : ");
34331 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34332 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34333 u8 instance_number[4];
34334 } result;
34335
34336 - char tmp[64 + 1];
34337 -
34338 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34339
34340 if (token < 0) {
34341 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34342 return 0;
34343 }
34344
34345 - seq_printf(seq, "Device name : %s\n",
34346 - chtostr(tmp, result.device_name, 64));
34347 - seq_printf(seq, "Service name : %s\n",
34348 - chtostr(tmp, result.service_name, 64));
34349 - seq_printf(seq, "Physical name : %s\n",
34350 - chtostr(tmp, result.physical_location, 64));
34351 - seq_printf(seq, "Instance number : %s\n",
34352 - chtostr(tmp, result.instance_number, 4));
34353 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34354 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34355 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34356 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34357
34358 return 0;
34359 }
34360 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34361 index a8c08f3..155fe3d 100644
34362 --- a/drivers/message/i2o/iop.c
34363 +++ b/drivers/message/i2o/iop.c
34364 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34365
34366 spin_lock_irqsave(&c->context_list_lock, flags);
34367
34368 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34369 - atomic_inc(&c->context_list_counter);
34370 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34371 + atomic_inc_unchecked(&c->context_list_counter);
34372
34373 - entry->context = atomic_read(&c->context_list_counter);
34374 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34375
34376 list_add(&entry->list, &c->context_list);
34377
34378 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34379
34380 #if BITS_PER_LONG == 64
34381 spin_lock_init(&c->context_list_lock);
34382 - atomic_set(&c->context_list_counter, 0);
34383 + atomic_set_unchecked(&c->context_list_counter, 0);
34384 INIT_LIST_HEAD(&c->context_list);
34385 #endif
34386
34387 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34388 index 7ce65f4..e66e9bc 100644
34389 --- a/drivers/mfd/abx500-core.c
34390 +++ b/drivers/mfd/abx500-core.c
34391 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34392
34393 struct abx500_device_entry {
34394 struct list_head list;
34395 - struct abx500_ops ops;
34396 + abx500_ops_no_const ops;
34397 struct device *dev;
34398 };
34399
34400 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34401 index 965c480..71f2db9 100644
34402 --- a/drivers/mfd/janz-cmodio.c
34403 +++ b/drivers/mfd/janz-cmodio.c
34404 @@ -13,6 +13,7 @@
34405
34406 #include <linux/kernel.h>
34407 #include <linux/module.h>
34408 +#include <linux/slab.h>
34409 #include <linux/init.h>
34410 #include <linux/pci.h>
34411 #include <linux/interrupt.h>
34412 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34413 index a981e2a..5ca0c8b 100644
34414 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34415 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34416 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34417 * the lid is closed. This leads to interrupts as soon as a little move
34418 * is done.
34419 */
34420 - atomic_inc(&lis3->count);
34421 + atomic_inc_unchecked(&lis3->count);
34422
34423 wake_up_interruptible(&lis3->misc_wait);
34424 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34425 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34426 if (lis3->pm_dev)
34427 pm_runtime_get_sync(lis3->pm_dev);
34428
34429 - atomic_set(&lis3->count, 0);
34430 + atomic_set_unchecked(&lis3->count, 0);
34431 return 0;
34432 }
34433
34434 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34435 add_wait_queue(&lis3->misc_wait, &wait);
34436 while (true) {
34437 set_current_state(TASK_INTERRUPTIBLE);
34438 - data = atomic_xchg(&lis3->count, 0);
34439 + data = atomic_xchg_unchecked(&lis3->count, 0);
34440 if (data)
34441 break;
34442
34443 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34444 struct lis3lv02d, miscdev);
34445
34446 poll_wait(file, &lis3->misc_wait, wait);
34447 - if (atomic_read(&lis3->count))
34448 + if (atomic_read_unchecked(&lis3->count))
34449 return POLLIN | POLLRDNORM;
34450 return 0;
34451 }
34452 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34453 index 2b1482a..5d33616 100644
34454 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34455 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34456 @@ -266,7 +266,7 @@ struct lis3lv02d {
34457 struct input_polled_dev *idev; /* input device */
34458 struct platform_device *pdev; /* platform device */
34459 struct regulator_bulk_data regulators[2];
34460 - atomic_t count; /* interrupt count after last read */
34461 + atomic_unchecked_t count; /* interrupt count after last read */
34462 union axis_conversion ac; /* hw -> logical axis */
34463 int mapped_btns[3];
34464
34465 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34466 index 2f30bad..c4c13d0 100644
34467 --- a/drivers/misc/sgi-gru/gruhandles.c
34468 +++ b/drivers/misc/sgi-gru/gruhandles.c
34469 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34470 unsigned long nsec;
34471
34472 nsec = CLKS2NSEC(clks);
34473 - atomic_long_inc(&mcs_op_statistics[op].count);
34474 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34475 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34476 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34477 if (mcs_op_statistics[op].max < nsec)
34478 mcs_op_statistics[op].max = nsec;
34479 }
34480 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34481 index 950dbe9..eeef0f8 100644
34482 --- a/drivers/misc/sgi-gru/gruprocfs.c
34483 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34484 @@ -32,9 +32,9 @@
34485
34486 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34487
34488 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34489 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34490 {
34491 - unsigned long val = atomic_long_read(v);
34492 + unsigned long val = atomic_long_read_unchecked(v);
34493
34494 seq_printf(s, "%16lu %s\n", val, id);
34495 }
34496 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34497
34498 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34499 for (op = 0; op < mcsop_last; op++) {
34500 - count = atomic_long_read(&mcs_op_statistics[op].count);
34501 - total = atomic_long_read(&mcs_op_statistics[op].total);
34502 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34503 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34504 max = mcs_op_statistics[op].max;
34505 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34506 count ? total / count : 0, max);
34507 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34508 index 5c3ce24..4915ccb 100644
34509 --- a/drivers/misc/sgi-gru/grutables.h
34510 +++ b/drivers/misc/sgi-gru/grutables.h
34511 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34512 * GRU statistics.
34513 */
34514 struct gru_stats_s {
34515 - atomic_long_t vdata_alloc;
34516 - atomic_long_t vdata_free;
34517 - atomic_long_t gts_alloc;
34518 - atomic_long_t gts_free;
34519 - atomic_long_t gms_alloc;
34520 - atomic_long_t gms_free;
34521 - atomic_long_t gts_double_allocate;
34522 - atomic_long_t assign_context;
34523 - atomic_long_t assign_context_failed;
34524 - atomic_long_t free_context;
34525 - atomic_long_t load_user_context;
34526 - atomic_long_t load_kernel_context;
34527 - atomic_long_t lock_kernel_context;
34528 - atomic_long_t unlock_kernel_context;
34529 - atomic_long_t steal_user_context;
34530 - atomic_long_t steal_kernel_context;
34531 - atomic_long_t steal_context_failed;
34532 - atomic_long_t nopfn;
34533 - atomic_long_t asid_new;
34534 - atomic_long_t asid_next;
34535 - atomic_long_t asid_wrap;
34536 - atomic_long_t asid_reuse;
34537 - atomic_long_t intr;
34538 - atomic_long_t intr_cbr;
34539 - atomic_long_t intr_tfh;
34540 - atomic_long_t intr_spurious;
34541 - atomic_long_t intr_mm_lock_failed;
34542 - atomic_long_t call_os;
34543 - atomic_long_t call_os_wait_queue;
34544 - atomic_long_t user_flush_tlb;
34545 - atomic_long_t user_unload_context;
34546 - atomic_long_t user_exception;
34547 - atomic_long_t set_context_option;
34548 - atomic_long_t check_context_retarget_intr;
34549 - atomic_long_t check_context_unload;
34550 - atomic_long_t tlb_dropin;
34551 - atomic_long_t tlb_preload_page;
34552 - atomic_long_t tlb_dropin_fail_no_asid;
34553 - atomic_long_t tlb_dropin_fail_upm;
34554 - atomic_long_t tlb_dropin_fail_invalid;
34555 - atomic_long_t tlb_dropin_fail_range_active;
34556 - atomic_long_t tlb_dropin_fail_idle;
34557 - atomic_long_t tlb_dropin_fail_fmm;
34558 - atomic_long_t tlb_dropin_fail_no_exception;
34559 - atomic_long_t tfh_stale_on_fault;
34560 - atomic_long_t mmu_invalidate_range;
34561 - atomic_long_t mmu_invalidate_page;
34562 - atomic_long_t flush_tlb;
34563 - atomic_long_t flush_tlb_gru;
34564 - atomic_long_t flush_tlb_gru_tgh;
34565 - atomic_long_t flush_tlb_gru_zero_asid;
34566 + atomic_long_unchecked_t vdata_alloc;
34567 + atomic_long_unchecked_t vdata_free;
34568 + atomic_long_unchecked_t gts_alloc;
34569 + atomic_long_unchecked_t gts_free;
34570 + atomic_long_unchecked_t gms_alloc;
34571 + atomic_long_unchecked_t gms_free;
34572 + atomic_long_unchecked_t gts_double_allocate;
34573 + atomic_long_unchecked_t assign_context;
34574 + atomic_long_unchecked_t assign_context_failed;
34575 + atomic_long_unchecked_t free_context;
34576 + atomic_long_unchecked_t load_user_context;
34577 + atomic_long_unchecked_t load_kernel_context;
34578 + atomic_long_unchecked_t lock_kernel_context;
34579 + atomic_long_unchecked_t unlock_kernel_context;
34580 + atomic_long_unchecked_t steal_user_context;
34581 + atomic_long_unchecked_t steal_kernel_context;
34582 + atomic_long_unchecked_t steal_context_failed;
34583 + atomic_long_unchecked_t nopfn;
34584 + atomic_long_unchecked_t asid_new;
34585 + atomic_long_unchecked_t asid_next;
34586 + atomic_long_unchecked_t asid_wrap;
34587 + atomic_long_unchecked_t asid_reuse;
34588 + atomic_long_unchecked_t intr;
34589 + atomic_long_unchecked_t intr_cbr;
34590 + atomic_long_unchecked_t intr_tfh;
34591 + atomic_long_unchecked_t intr_spurious;
34592 + atomic_long_unchecked_t intr_mm_lock_failed;
34593 + atomic_long_unchecked_t call_os;
34594 + atomic_long_unchecked_t call_os_wait_queue;
34595 + atomic_long_unchecked_t user_flush_tlb;
34596 + atomic_long_unchecked_t user_unload_context;
34597 + atomic_long_unchecked_t user_exception;
34598 + atomic_long_unchecked_t set_context_option;
34599 + atomic_long_unchecked_t check_context_retarget_intr;
34600 + atomic_long_unchecked_t check_context_unload;
34601 + atomic_long_unchecked_t tlb_dropin;
34602 + atomic_long_unchecked_t tlb_preload_page;
34603 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34604 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34605 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34606 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34607 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34608 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34609 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34610 + atomic_long_unchecked_t tfh_stale_on_fault;
34611 + atomic_long_unchecked_t mmu_invalidate_range;
34612 + atomic_long_unchecked_t mmu_invalidate_page;
34613 + atomic_long_unchecked_t flush_tlb;
34614 + atomic_long_unchecked_t flush_tlb_gru;
34615 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34616 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34617
34618 - atomic_long_t copy_gpa;
34619 - atomic_long_t read_gpa;
34620 + atomic_long_unchecked_t copy_gpa;
34621 + atomic_long_unchecked_t read_gpa;
34622
34623 - atomic_long_t mesq_receive;
34624 - atomic_long_t mesq_receive_none;
34625 - atomic_long_t mesq_send;
34626 - atomic_long_t mesq_send_failed;
34627 - atomic_long_t mesq_noop;
34628 - atomic_long_t mesq_send_unexpected_error;
34629 - atomic_long_t mesq_send_lb_overflow;
34630 - atomic_long_t mesq_send_qlimit_reached;
34631 - atomic_long_t mesq_send_amo_nacked;
34632 - atomic_long_t mesq_send_put_nacked;
34633 - atomic_long_t mesq_page_overflow;
34634 - atomic_long_t mesq_qf_locked;
34635 - atomic_long_t mesq_qf_noop_not_full;
34636 - atomic_long_t mesq_qf_switch_head_failed;
34637 - atomic_long_t mesq_qf_unexpected_error;
34638 - atomic_long_t mesq_noop_unexpected_error;
34639 - atomic_long_t mesq_noop_lb_overflow;
34640 - atomic_long_t mesq_noop_qlimit_reached;
34641 - atomic_long_t mesq_noop_amo_nacked;
34642 - atomic_long_t mesq_noop_put_nacked;
34643 - atomic_long_t mesq_noop_page_overflow;
34644 + atomic_long_unchecked_t mesq_receive;
34645 + atomic_long_unchecked_t mesq_receive_none;
34646 + atomic_long_unchecked_t mesq_send;
34647 + atomic_long_unchecked_t mesq_send_failed;
34648 + atomic_long_unchecked_t mesq_noop;
34649 + atomic_long_unchecked_t mesq_send_unexpected_error;
34650 + atomic_long_unchecked_t mesq_send_lb_overflow;
34651 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34652 + atomic_long_unchecked_t mesq_send_amo_nacked;
34653 + atomic_long_unchecked_t mesq_send_put_nacked;
34654 + atomic_long_unchecked_t mesq_page_overflow;
34655 + atomic_long_unchecked_t mesq_qf_locked;
34656 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34657 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34658 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34659 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34660 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34661 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34662 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34663 + atomic_long_unchecked_t mesq_noop_put_nacked;
34664 + atomic_long_unchecked_t mesq_noop_page_overflow;
34665
34666 };
34667
34668 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34669 tghop_invalidate, mcsop_last};
34670
34671 struct mcs_op_statistic {
34672 - atomic_long_t count;
34673 - atomic_long_t total;
34674 + atomic_long_unchecked_t count;
34675 + atomic_long_unchecked_t total;
34676 unsigned long max;
34677 };
34678
34679 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34680
34681 #define STAT(id) do { \
34682 if (gru_options & OPT_STATS) \
34683 - atomic_long_inc(&gru_stats.id); \
34684 + atomic_long_inc_unchecked(&gru_stats.id); \
34685 } while (0)
34686
34687 #ifdef CONFIG_SGI_GRU_DEBUG
34688 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34689 index c862cd4..0d176fe 100644
34690 --- a/drivers/misc/sgi-xp/xp.h
34691 +++ b/drivers/misc/sgi-xp/xp.h
34692 @@ -288,7 +288,7 @@ struct xpc_interface {
34693 xpc_notify_func, void *);
34694 void (*received) (short, int, void *);
34695 enum xp_retval (*partid_to_nasids) (short, void *);
34696 -};
34697 +} __no_const;
34698
34699 extern struct xpc_interface xpc_interface;
34700
34701 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34702 index b94d5f7..7f494c5 100644
34703 --- a/drivers/misc/sgi-xp/xpc.h
34704 +++ b/drivers/misc/sgi-xp/xpc.h
34705 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34706 void (*received_payload) (struct xpc_channel *, void *);
34707 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34708 };
34709 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34710
34711 /* struct xpc_partition act_state values (for XPC HB) */
34712
34713 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34714 /* found in xpc_main.c */
34715 extern struct device *xpc_part;
34716 extern struct device *xpc_chan;
34717 -extern struct xpc_arch_operations xpc_arch_ops;
34718 +extern xpc_arch_operations_no_const xpc_arch_ops;
34719 extern int xpc_disengage_timelimit;
34720 extern int xpc_disengage_timedout;
34721 extern int xpc_activate_IRQ_rcvd;
34722 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34723 index 8d082b4..aa749ae 100644
34724 --- a/drivers/misc/sgi-xp/xpc_main.c
34725 +++ b/drivers/misc/sgi-xp/xpc_main.c
34726 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34727 .notifier_call = xpc_system_die,
34728 };
34729
34730 -struct xpc_arch_operations xpc_arch_ops;
34731 +xpc_arch_operations_no_const xpc_arch_ops;
34732
34733 /*
34734 * Timer function to enforce the timelimit on the partition disengage.
34735 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34736 index 504da71..9722d43 100644
34737 --- a/drivers/mmc/host/sdhci-pci.c
34738 +++ b/drivers/mmc/host/sdhci-pci.c
34739 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34740 .probe = via_probe,
34741 };
34742
34743 -static const struct pci_device_id pci_ids[] __devinitdata = {
34744 +static const struct pci_device_id pci_ids[] __devinitconst = {
34745 {
34746 .vendor = PCI_VENDOR_ID_RICOH,
34747 .device = PCI_DEVICE_ID_RICOH_R5C822,
34748 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34749 index a4eb8b5..8c0628f 100644
34750 --- a/drivers/mtd/devices/doc2000.c
34751 +++ b/drivers/mtd/devices/doc2000.c
34752 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34753
34754 /* The ECC will not be calculated correctly if less than 512 is written */
34755 /* DBB-
34756 - if (len != 0x200 && eccbuf)
34757 + if (len != 0x200)
34758 printk(KERN_WARNING
34759 "ECC needs a full sector write (adr: %lx size %lx)\n",
34760 (long) to, (long) len);
34761 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34762 index 0650aaf..7718762 100644
34763 --- a/drivers/mtd/nand/denali.c
34764 +++ b/drivers/mtd/nand/denali.c
34765 @@ -26,6 +26,7 @@
34766 #include <linux/pci.h>
34767 #include <linux/mtd/mtd.h>
34768 #include <linux/module.h>
34769 +#include <linux/slab.h>
34770
34771 #include "denali.h"
34772
34773 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34774 index 51b9d6a..52af9a7 100644
34775 --- a/drivers/mtd/nftlmount.c
34776 +++ b/drivers/mtd/nftlmount.c
34777 @@ -24,6 +24,7 @@
34778 #include <asm/errno.h>
34779 #include <linux/delay.h>
34780 #include <linux/slab.h>
34781 +#include <linux/sched.h>
34782 #include <linux/mtd/mtd.h>
34783 #include <linux/mtd/nand.h>
34784 #include <linux/mtd/nftl.h>
34785 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34786 index 57d64b8..623dd86 100644
34787 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34788 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34789 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34790 */
34791
34792 #define ATL2_PARAM(X, desc) \
34793 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34794 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34795 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34796 MODULE_PARM_DESC(X, desc);
34797 #else
34798 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34799 index f83e033..8b4f43a 100644
34800 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34801 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34802 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34803
34804 int (*wait_comp)(struct bnx2x *bp,
34805 struct bnx2x_rx_mode_ramrod_params *p);
34806 -};
34807 +} __no_const;
34808
34809 /********************** Set multicast group ***********************************/
34810
34811 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34812 index 6d52cb2..bc95640 100644
34813 --- a/drivers/net/ethernet/broadcom/tg3.h
34814 +++ b/drivers/net/ethernet/broadcom/tg3.h
34815 @@ -140,6 +140,7 @@
34816 #define CHIPREV_ID_5750_A0 0x4000
34817 #define CHIPREV_ID_5750_A1 0x4001
34818 #define CHIPREV_ID_5750_A3 0x4003
34819 +#define CHIPREV_ID_5750_C1 0x4201
34820 #define CHIPREV_ID_5750_C2 0x4202
34821 #define CHIPREV_ID_5752_A0_HW 0x5000
34822 #define CHIPREV_ID_5752_A0 0x6000
34823 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34824 index 8cffcdf..aadf043 100644
34825 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34826 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34827 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34828 */
34829 struct l2t_skb_cb {
34830 arp_failure_handler_func arp_failure_handler;
34831 -};
34832 +} __no_const;
34833
34834 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34835
34836 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34837 index f879e92..726f20f 100644
34838 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34839 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34840 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34841 for (i=0; i<ETH_ALEN; i++) {
34842 tmp.addr[i] = dev->dev_addr[i];
34843 }
34844 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34845 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34846 break;
34847
34848 case DE4X5_SET_HWADDR: /* Set the hardware address */
34849 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34850 spin_lock_irqsave(&lp->lock, flags);
34851 memcpy(&statbuf, &lp->pktStats, ioc->len);
34852 spin_unlock_irqrestore(&lp->lock, flags);
34853 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34854 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34855 return -EFAULT;
34856 break;
34857 }
34858 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34859 index ed7d1dc..d426748 100644
34860 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34861 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34862 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34863 {NULL}};
34864
34865
34866 -static const char *block_name[] __devinitdata = {
34867 +static const char *block_name[] __devinitconst = {
34868 "21140 non-MII",
34869 "21140 MII PHY",
34870 "21142 Serial PHY",
34871 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34872 index 75d45f8..3d9c55b 100644
34873 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34874 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34875 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34876 struct uli_phy_ops {
34877 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34878 u16 (*read)(struct uli526x_board_info *, u8, u8);
34879 - } phy;
34880 + } __no_const phy;
34881 struct net_device *next_dev; /* next device */
34882 struct pci_dev *pdev; /* PCI device */
34883 spinlock_t lock;
34884 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34885 index 4d1ffca..7c1ec4d 100644
34886 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34887 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34888 @@ -236,7 +236,7 @@ struct pci_id_info {
34889 int drv_flags; /* Driver use, intended as capability flags. */
34890 };
34891
34892 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34893 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34894 { /* Sometime a Level-One switch card. */
34895 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34896 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34897 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34898 index d7bb52a..3b83588 100644
34899 --- a/drivers/net/ethernet/dlink/sundance.c
34900 +++ b/drivers/net/ethernet/dlink/sundance.c
34901 @@ -218,7 +218,7 @@ enum {
34902 struct pci_id_info {
34903 const char *name;
34904 };
34905 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34906 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34907 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34908 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34909 {"D-Link DFE-580TX 4 port Server Adapter"},
34910 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34911 index 78b8aa8..dd6323a 100644
34912 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34913 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34914 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34915
34916 if (wrapped)
34917 newacc += 65536;
34918 - ACCESS_ONCE(*acc) = newacc;
34919 + ACCESS_ONCE_RW(*acc) = newacc;
34920 }
34921
34922 void be_parse_stats(struct be_adapter *adapter)
34923 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34924 index 74d749e..eefb1bd 100644
34925 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34926 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34927 @@ -31,6 +31,8 @@
34928 #include <linux/netdevice.h>
34929 #include <linux/phy.h>
34930 #include <linux/platform_device.h>
34931 +#include <linux/interrupt.h>
34932 +#include <linux/irqreturn.h>
34933 #include <net/ip.h>
34934
34935 #include "ftgmac100.h"
34936 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34937 index b901a01..1ff32ee 100644
34938 --- a/drivers/net/ethernet/faraday/ftmac100.c
34939 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34940 @@ -31,6 +31,8 @@
34941 #include <linux/module.h>
34942 #include <linux/netdevice.h>
34943 #include <linux/platform_device.h>
34944 +#include <linux/interrupt.h>
34945 +#include <linux/irqreturn.h>
34946
34947 #include "ftmac100.h"
34948
34949 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34950 index 9d71c9c..0e4a0ac 100644
34951 --- a/drivers/net/ethernet/fealnx.c
34952 +++ b/drivers/net/ethernet/fealnx.c
34953 @@ -150,7 +150,7 @@ struct chip_info {
34954 int flags;
34955 };
34956
34957 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34958 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34959 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34960 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34961 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34962 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34963 index ed5b409..ec37828 100644
34964 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34965 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34966 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34967 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34968 s32 (*read_mac_addr)(struct e1000_hw *);
34969 };
34970 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34971
34972 /*
34973 * When to use various PHY register access functions:
34974 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34975 void (*power_up)(struct e1000_hw *);
34976 void (*power_down)(struct e1000_hw *);
34977 };
34978 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34979
34980 /* Function pointers for the NVM. */
34981 struct e1000_nvm_operations {
34982 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34983 s32 (*validate)(struct e1000_hw *);
34984 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34985 };
34986 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34987
34988 struct e1000_mac_info {
34989 - struct e1000_mac_operations ops;
34990 + e1000_mac_operations_no_const ops;
34991 u8 addr[ETH_ALEN];
34992 u8 perm_addr[ETH_ALEN];
34993
34994 @@ -892,7 +895,7 @@ struct e1000_mac_info {
34995 };
34996
34997 struct e1000_phy_info {
34998 - struct e1000_phy_operations ops;
34999 + e1000_phy_operations_no_const ops;
35000
35001 enum e1000_phy_type type;
35002
35003 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35004 };
35005
35006 struct e1000_nvm_info {
35007 - struct e1000_nvm_operations ops;
35008 + e1000_nvm_operations_no_const ops;
35009
35010 enum e1000_nvm_type type;
35011 enum e1000_nvm_override override;
35012 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35013 index c2a51dc..c2bd262 100644
35014 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35015 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35016 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35017 void (*release_swfw_sync)(struct e1000_hw *, u16);
35018
35019 };
35020 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35021
35022 struct e1000_phy_operations {
35023 s32 (*acquire)(struct e1000_hw *);
35024 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35025 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35026 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35027 };
35028 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35029
35030 struct e1000_nvm_operations {
35031 s32 (*acquire)(struct e1000_hw *);
35032 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35033 s32 (*validate)(struct e1000_hw *);
35034 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35035 };
35036 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35037
35038 struct e1000_info {
35039 s32 (*get_invariants)(struct e1000_hw *);
35040 @@ -364,7 +367,7 @@ struct e1000_info {
35041 extern const struct e1000_info e1000_82575_info;
35042
35043 struct e1000_mac_info {
35044 - struct e1000_mac_operations ops;
35045 + e1000_mac_operations_no_const ops;
35046
35047 u8 addr[6];
35048 u8 perm_addr[6];
35049 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35050 };
35051
35052 struct e1000_phy_info {
35053 - struct e1000_phy_operations ops;
35054 + e1000_phy_operations_no_const ops;
35055
35056 enum e1000_phy_type type;
35057
35058 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35059 };
35060
35061 struct e1000_nvm_info {
35062 - struct e1000_nvm_operations ops;
35063 + e1000_nvm_operations_no_const ops;
35064 enum e1000_nvm_type type;
35065 enum e1000_nvm_override override;
35066
35067 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35068 s32 (*check_for_ack)(struct e1000_hw *, u16);
35069 s32 (*check_for_rst)(struct e1000_hw *, u16);
35070 };
35071 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35072
35073 struct e1000_mbx_stats {
35074 u32 msgs_tx;
35075 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35076 };
35077
35078 struct e1000_mbx_info {
35079 - struct e1000_mbx_operations ops;
35080 + e1000_mbx_operations_no_const ops;
35081 struct e1000_mbx_stats stats;
35082 u32 timeout;
35083 u32 usec_delay;
35084 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35085 index 57db3c6..aa825fc 100644
35086 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35087 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35088 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35089 s32 (*read_mac_addr)(struct e1000_hw *);
35090 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35091 };
35092 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35093
35094 struct e1000_mac_info {
35095 - struct e1000_mac_operations ops;
35096 + e1000_mac_operations_no_const ops;
35097 u8 addr[6];
35098 u8 perm_addr[6];
35099
35100 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35101 s32 (*check_for_ack)(struct e1000_hw *);
35102 s32 (*check_for_rst)(struct e1000_hw *);
35103 };
35104 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35105
35106 struct e1000_mbx_stats {
35107 u32 msgs_tx;
35108 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35109 };
35110
35111 struct e1000_mbx_info {
35112 - struct e1000_mbx_operations ops;
35113 + e1000_mbx_operations_no_const ops;
35114 struct e1000_mbx_stats stats;
35115 u32 timeout;
35116 u32 usec_delay;
35117 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35118 index 3456d56..b688d81 100644
35119 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35120 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35121 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35122 /* store the new cycle speed */
35123 adapter->cycle_speed = cycle_speed;
35124
35125 - ACCESS_ONCE(adapter->base_incval) = incval;
35126 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35127 smp_mb();
35128
35129 /* grab the ptp lock */
35130 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35131 index 400f86a..7f2e062 100644
35132 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35133 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35134 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35135 s32 (*update_checksum)(struct ixgbe_hw *);
35136 u16 (*calc_checksum)(struct ixgbe_hw *);
35137 };
35138 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35139
35140 struct ixgbe_mac_operations {
35141 s32 (*init_hw)(struct ixgbe_hw *);
35142 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35143 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35144 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35145 };
35146 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35147
35148 struct ixgbe_phy_operations {
35149 s32 (*identify)(struct ixgbe_hw *);
35150 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35151 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35152 s32 (*check_overtemp)(struct ixgbe_hw *);
35153 };
35154 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35155
35156 struct ixgbe_eeprom_info {
35157 - struct ixgbe_eeprom_operations ops;
35158 + ixgbe_eeprom_operations_no_const ops;
35159 enum ixgbe_eeprom_type type;
35160 u32 semaphore_delay;
35161 u16 word_size;
35162 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35163
35164 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35165 struct ixgbe_mac_info {
35166 - struct ixgbe_mac_operations ops;
35167 + ixgbe_mac_operations_no_const ops;
35168 enum ixgbe_mac_type type;
35169 u8 addr[ETH_ALEN];
35170 u8 perm_addr[ETH_ALEN];
35171 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35172 };
35173
35174 struct ixgbe_phy_info {
35175 - struct ixgbe_phy_operations ops;
35176 + ixgbe_phy_operations_no_const ops;
35177 struct mdio_if_info mdio;
35178 enum ixgbe_phy_type type;
35179 u32 id;
35180 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35181 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35182 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35183 };
35184 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35185
35186 struct ixgbe_mbx_stats {
35187 u32 msgs_tx;
35188 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35189 };
35190
35191 struct ixgbe_mbx_info {
35192 - struct ixgbe_mbx_operations ops;
35193 + ixgbe_mbx_operations_no_const ops;
35194 struct ixgbe_mbx_stats stats;
35195 u32 timeout;
35196 u32 usec_delay;
35197 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35198 index 25c951d..cc7cf33 100644
35199 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35200 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35201 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35202 s32 (*clear_vfta)(struct ixgbe_hw *);
35203 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35204 };
35205 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35206
35207 enum ixgbe_mac_type {
35208 ixgbe_mac_unknown = 0,
35209 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35210 };
35211
35212 struct ixgbe_mac_info {
35213 - struct ixgbe_mac_operations ops;
35214 + ixgbe_mac_operations_no_const ops;
35215 u8 addr[6];
35216 u8 perm_addr[6];
35217
35218 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35219 s32 (*check_for_ack)(struct ixgbe_hw *);
35220 s32 (*check_for_rst)(struct ixgbe_hw *);
35221 };
35222 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35223
35224 struct ixgbe_mbx_stats {
35225 u32 msgs_tx;
35226 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35227 };
35228
35229 struct ixgbe_mbx_info {
35230 - struct ixgbe_mbx_operations ops;
35231 + ixgbe_mbx_operations_no_const ops;
35232 struct ixgbe_mbx_stats stats;
35233 u32 timeout;
35234 u32 udelay;
35235 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35236 index 9e0c1ee..8471f77 100644
35237 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35238 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35239 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35240 void (*link_down)(struct __vxge_hw_device *devh);
35241 void (*crit_err)(struct __vxge_hw_device *devh,
35242 enum vxge_hw_event type, u64 ext_data);
35243 -};
35244 +} __no_const;
35245
35246 /*
35247 * struct __vxge_hw_blockpool_entry - Block private data structure
35248 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35249 index 4a518a3..936b334 100644
35250 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35251 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35252 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35253 struct vxge_hw_mempool_dma *dma_object,
35254 u32 index,
35255 u32 is_last);
35256 -};
35257 +} __no_const;
35258
35259 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35260 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35261 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35262 index b47d5b3..273a516 100644
35263 --- a/drivers/net/ethernet/realtek/r8169.c
35264 +++ b/drivers/net/ethernet/realtek/r8169.c
35265 @@ -745,22 +745,22 @@ struct rtl8169_private {
35266 struct mdio_ops {
35267 void (*write)(struct rtl8169_private *, int, int);
35268 int (*read)(struct rtl8169_private *, int);
35269 - } mdio_ops;
35270 + } __no_const mdio_ops;
35271
35272 struct pll_power_ops {
35273 void (*down)(struct rtl8169_private *);
35274 void (*up)(struct rtl8169_private *);
35275 - } pll_power_ops;
35276 + } __no_const pll_power_ops;
35277
35278 struct jumbo_ops {
35279 void (*enable)(struct rtl8169_private *);
35280 void (*disable)(struct rtl8169_private *);
35281 - } jumbo_ops;
35282 + } __no_const jumbo_ops;
35283
35284 struct csi_ops {
35285 void (*write)(struct rtl8169_private *, int, int);
35286 u32 (*read)(struct rtl8169_private *, int);
35287 - } csi_ops;
35288 + } __no_const csi_ops;
35289
35290 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35291 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35292 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35293 index 4613591..d816601 100644
35294 --- a/drivers/net/ethernet/sis/sis190.c
35295 +++ b/drivers/net/ethernet/sis/sis190.c
35296 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35297 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35298 struct net_device *dev)
35299 {
35300 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35301 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35302 struct sis190_private *tp = netdev_priv(dev);
35303 struct pci_dev *isa_bridge;
35304 u8 reg, tmp8;
35305 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35306 index 0c74a70..3bc6f68 100644
35307 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35308 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35309 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35310
35311 writel(value, ioaddr + MMC_CNTRL);
35312
35313 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35314 - MMC_CNTRL, value);
35315 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35316 +// MMC_CNTRL, value);
35317 }
35318
35319 /* To mask all all interrupts.*/
35320 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35321 index 95ceb35..318fc12 100644
35322 --- a/drivers/net/hyperv/hyperv_net.h
35323 +++ b/drivers/net/hyperv/hyperv_net.h
35324 @@ -99,7 +99,7 @@ struct rndis_device {
35325
35326 enum rndis_device_state state;
35327 bool link_state;
35328 - atomic_t new_req_id;
35329 + atomic_unchecked_t new_req_id;
35330
35331 spinlock_t request_lock;
35332 struct list_head req_list;
35333 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35334 index 1e88a10..1b01736 100644
35335 --- a/drivers/net/hyperv/rndis_filter.c
35336 +++ b/drivers/net/hyperv/rndis_filter.c
35337 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35338 * template
35339 */
35340 set = &rndis_msg->msg.set_req;
35341 - set->req_id = atomic_inc_return(&dev->new_req_id);
35342 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35343
35344 /* Add to the request list */
35345 spin_lock_irqsave(&dev->request_lock, flags);
35346 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35347
35348 /* Setup the rndis set */
35349 halt = &request->request_msg.msg.halt_req;
35350 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35351 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35352
35353 /* Ignore return since this msg is optional. */
35354 rndis_filter_send_request(dev, request);
35355 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35356 index 5c05572..389610b 100644
35357 --- a/drivers/net/ppp/ppp_generic.c
35358 +++ b/drivers/net/ppp/ppp_generic.c
35359 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35360 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35361 struct ppp_stats stats;
35362 struct ppp_comp_stats cstats;
35363 - char *vers;
35364
35365 switch (cmd) {
35366 case SIOCGPPPSTATS:
35367 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35368 break;
35369
35370 case SIOCGPPPVER:
35371 - vers = PPP_VERSION;
35372 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35373 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35374 break;
35375 err = 0;
35376 break;
35377 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35378 index 3a16d4f..a311cec 100644
35379 --- a/drivers/net/tun.c
35380 +++ b/drivers/net/tun.c
35381 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35382 }
35383
35384 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35385 - unsigned long arg, int ifreq_len)
35386 + unsigned long arg, size_t ifreq_len)
35387 {
35388 struct tun_file *tfile = file->private_data;
35389 struct tun_struct *tun;
35390 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35391 int vnet_hdr_sz;
35392 int ret;
35393
35394 + if (ifreq_len > sizeof ifr)
35395 + return -EFAULT;
35396 +
35397 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35398 if (copy_from_user(&ifr, argp, ifreq_len))
35399 return -EFAULT;
35400 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35401 index 62f30b4..ff99dfd 100644
35402 --- a/drivers/net/usb/hso.c
35403 +++ b/drivers/net/usb/hso.c
35404 @@ -71,7 +71,7 @@
35405 #include <asm/byteorder.h>
35406 #include <linux/serial_core.h>
35407 #include <linux/serial.h>
35408 -
35409 +#include <asm/local.h>
35410
35411 #define MOD_AUTHOR "Option Wireless"
35412 #define MOD_DESCRIPTION "USB High Speed Option driver"
35413 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35414 struct urb *urb;
35415
35416 urb = serial->rx_urb[0];
35417 - if (serial->port.count > 0) {
35418 + if (atomic_read(&serial->port.count) > 0) {
35419 count = put_rxbuf_data(urb, serial);
35420 if (count == -1)
35421 return;
35422 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35423 DUMP1(urb->transfer_buffer, urb->actual_length);
35424
35425 /* Anyone listening? */
35426 - if (serial->port.count == 0)
35427 + if (atomic_read(&serial->port.count) == 0)
35428 return;
35429
35430 if (status == 0) {
35431 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35432 tty_port_tty_set(&serial->port, tty);
35433
35434 /* check for port already opened, if not set the termios */
35435 - serial->port.count++;
35436 - if (serial->port.count == 1) {
35437 + if (atomic_inc_return(&serial->port.count) == 1) {
35438 serial->rx_state = RX_IDLE;
35439 /* Force default termio settings */
35440 _hso_serial_set_termios(tty, NULL);
35441 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35442 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35443 if (result) {
35444 hso_stop_serial_device(serial->parent);
35445 - serial->port.count--;
35446 + atomic_dec(&serial->port.count);
35447 kref_put(&serial->parent->ref, hso_serial_ref_free);
35448 }
35449 } else {
35450 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35451
35452 /* reset the rts and dtr */
35453 /* do the actual close */
35454 - serial->port.count--;
35455 + atomic_dec(&serial->port.count);
35456
35457 - if (serial->port.count <= 0) {
35458 - serial->port.count = 0;
35459 + if (atomic_read(&serial->port.count) <= 0) {
35460 + atomic_set(&serial->port.count, 0);
35461 tty_port_tty_set(&serial->port, NULL);
35462 if (!usb_gone)
35463 hso_stop_serial_device(serial->parent);
35464 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35465
35466 /* the actual setup */
35467 spin_lock_irqsave(&serial->serial_lock, flags);
35468 - if (serial->port.count)
35469 + if (atomic_read(&serial->port.count))
35470 _hso_serial_set_termios(tty, old);
35471 else
35472 tty->termios = old;
35473 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35474 D1("Pending read interrupt on port %d\n", i);
35475 spin_lock(&serial->serial_lock);
35476 if (serial->rx_state == RX_IDLE &&
35477 - serial->port.count > 0) {
35478 + atomic_read(&serial->port.count) > 0) {
35479 /* Setup and send a ctrl req read on
35480 * port i */
35481 if (!serial->rx_urb_filled[0]) {
35482 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35483 /* Start all serial ports */
35484 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35485 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35486 - if (dev2ser(serial_table[i])->port.count) {
35487 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35488 result =
35489 hso_start_serial_device(serial_table[i], GFP_NOIO);
35490 hso_kick_transmit(dev2ser(serial_table[i]));
35491 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35492 index 6169fbd..40e8422 100644
35493 --- a/drivers/net/wireless/ath/ath.h
35494 +++ b/drivers/net/wireless/ath/ath.h
35495 @@ -119,6 +119,7 @@ struct ath_ops {
35496 void (*write_flush) (void *);
35497 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35498 };
35499 +typedef struct ath_ops __no_const ath_ops_no_const;
35500
35501 struct ath_common;
35502 struct ath_bus_ops;
35503 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35504 index 8d78253..bebbb68 100644
35505 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35506 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35507 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35508 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35509 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35510
35511 - ACCESS_ONCE(ads->ds_link) = i->link;
35512 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35513 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35514 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35515
35516 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35517 ctl6 = SM(i->keytype, AR_EncrType);
35518 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35519
35520 if ((i->is_first || i->is_last) &&
35521 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35522 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35523 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35524 | set11nTries(i->rates, 1)
35525 | set11nTries(i->rates, 2)
35526 | set11nTries(i->rates, 3)
35527 | (i->dur_update ? AR_DurUpdateEna : 0)
35528 | SM(0, AR_BurstDur);
35529
35530 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35531 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35532 | set11nRate(i->rates, 1)
35533 | set11nRate(i->rates, 2)
35534 | set11nRate(i->rates, 3);
35535 } else {
35536 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35537 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35538 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35539 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35540 }
35541
35542 if (!i->is_first) {
35543 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35544 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35545 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35546 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35547 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35548 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35549 return;
35550 }
35551
35552 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35553 break;
35554 }
35555
35556 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35557 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35558 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35559 | SM(i->txpower, AR_XmitPower)
35560 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35561 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35562 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35563 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35564
35565 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35566 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35567 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35568 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35569
35570 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35571 return;
35572
35573 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35574 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35575 | set11nPktDurRTSCTS(i->rates, 1);
35576
35577 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35578 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35579 | set11nPktDurRTSCTS(i->rates, 3);
35580
35581 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35582 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35583 | set11nRateFlags(i->rates, 1)
35584 | set11nRateFlags(i->rates, 2)
35585 | set11nRateFlags(i->rates, 3)
35586 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35587 index 78816b8..1fcdfae 100644
35588 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35589 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35590 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35591 (i->qcu << AR_TxQcuNum_S) | desc_len;
35592
35593 checksum += val;
35594 - ACCESS_ONCE(ads->info) = val;
35595 + ACCESS_ONCE_RW(ads->info) = val;
35596
35597 checksum += i->link;
35598 - ACCESS_ONCE(ads->link) = i->link;
35599 + ACCESS_ONCE_RW(ads->link) = i->link;
35600
35601 checksum += i->buf_addr[0];
35602 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35603 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35604 checksum += i->buf_addr[1];
35605 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35606 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35607 checksum += i->buf_addr[2];
35608 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35609 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35610 checksum += i->buf_addr[3];
35611 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35612 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35613
35614 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35615 - ACCESS_ONCE(ads->ctl3) = val;
35616 + ACCESS_ONCE_RW(ads->ctl3) = val;
35617 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35618 - ACCESS_ONCE(ads->ctl5) = val;
35619 + ACCESS_ONCE_RW(ads->ctl5) = val;
35620 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35621 - ACCESS_ONCE(ads->ctl7) = val;
35622 + ACCESS_ONCE_RW(ads->ctl7) = val;
35623 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35624 - ACCESS_ONCE(ads->ctl9) = val;
35625 + ACCESS_ONCE_RW(ads->ctl9) = val;
35626
35627 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35628 - ACCESS_ONCE(ads->ctl10) = checksum;
35629 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35630
35631 if (i->is_first || i->is_last) {
35632 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35633 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35634 | set11nTries(i->rates, 1)
35635 | set11nTries(i->rates, 2)
35636 | set11nTries(i->rates, 3)
35637 | (i->dur_update ? AR_DurUpdateEna : 0)
35638 | SM(0, AR_BurstDur);
35639
35640 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35641 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35642 | set11nRate(i->rates, 1)
35643 | set11nRate(i->rates, 2)
35644 | set11nRate(i->rates, 3);
35645 } else {
35646 - ACCESS_ONCE(ads->ctl13) = 0;
35647 - ACCESS_ONCE(ads->ctl14) = 0;
35648 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35649 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35650 }
35651
35652 ads->ctl20 = 0;
35653 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35654
35655 ctl17 = SM(i->keytype, AR_EncrType);
35656 if (!i->is_first) {
35657 - ACCESS_ONCE(ads->ctl11) = 0;
35658 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35659 - ACCESS_ONCE(ads->ctl15) = 0;
35660 - ACCESS_ONCE(ads->ctl16) = 0;
35661 - ACCESS_ONCE(ads->ctl17) = ctl17;
35662 - ACCESS_ONCE(ads->ctl18) = 0;
35663 - ACCESS_ONCE(ads->ctl19) = 0;
35664 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35665 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35666 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35667 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35668 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35669 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35670 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35671 return;
35672 }
35673
35674 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35675 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35676 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35677 | SM(i->txpower, AR_XmitPower)
35678 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35679 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35680 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35681 ctl12 |= SM(val, AR_PAPRDChainMask);
35682
35683 - ACCESS_ONCE(ads->ctl12) = ctl12;
35684 - ACCESS_ONCE(ads->ctl17) = ctl17;
35685 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35686 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35687
35688 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35689 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35690 | set11nPktDurRTSCTS(i->rates, 1);
35691
35692 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35693 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35694 | set11nPktDurRTSCTS(i->rates, 3);
35695
35696 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35697 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35698 | set11nRateFlags(i->rates, 1)
35699 | set11nRateFlags(i->rates, 2)
35700 | set11nRateFlags(i->rates, 3)
35701 | SM(i->rtscts_rate, AR_RTSCTSRate);
35702
35703 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35704 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35705 }
35706
35707 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35708 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35709 index de6968f..29ac4c1 100644
35710 --- a/drivers/net/wireless/ath/ath9k/hw.h
35711 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35712 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35713
35714 /* ANI */
35715 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35716 -};
35717 +} __no_const;
35718
35719 /**
35720 * struct ath_hw_ops - callbacks used by hardware code and driver code
35721 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35722 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35723 struct ath_hw_antcomb_conf *antconf);
35724
35725 -};
35726 +} __no_const;
35727
35728 struct ath_nf_limits {
35729 s16 max;
35730 @@ -706,7 +706,7 @@ enum ath_cal_list {
35731 #define AH_FASTCC 0x4
35732
35733 struct ath_hw {
35734 - struct ath_ops reg_ops;
35735 + ath_ops_no_const reg_ops;
35736
35737 struct ieee80211_hw *hw;
35738 struct ath_common common;
35739 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35740 index af00e2c..ab04d34 100644
35741 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35742 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35743 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35744 void (*carrsuppr)(struct brcms_phy *);
35745 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35746 void (*detach)(struct brcms_phy *);
35747 -};
35748 +} __no_const;
35749
35750 struct brcms_phy {
35751 struct brcms_phy_pub pubpi_ro;
35752 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35753 index faec404..a5277f1 100644
35754 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35755 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35756 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35757 */
35758 if (il3945_mod_params.disable_hw_scan) {
35759 D_INFO("Disabling hw_scan\n");
35760 - il3945_mac_ops.hw_scan = NULL;
35761 + pax_open_kernel();
35762 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35763 + pax_close_kernel();
35764 }
35765
35766 D_INFO("*** LOAD DRIVER ***\n");
35767 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35768 index a47b306..297daf2 100644
35769 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35770 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35771 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35772 {
35773 struct iwl_priv *priv = file->private_data;
35774 char buf[64];
35775 - int buf_size;
35776 + size_t buf_size;
35777 u32 offset, len;
35778
35779 memset(buf, 0, sizeof(buf));
35780 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35781 struct iwl_priv *priv = file->private_data;
35782
35783 char buf[8];
35784 - int buf_size;
35785 + size_t buf_size;
35786 u32 reset_flag;
35787
35788 memset(buf, 0, sizeof(buf));
35789 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35790 {
35791 struct iwl_priv *priv = file->private_data;
35792 char buf[8];
35793 - int buf_size;
35794 + size_t buf_size;
35795 int ht40;
35796
35797 memset(buf, 0, sizeof(buf));
35798 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35799 {
35800 struct iwl_priv *priv = file->private_data;
35801 char buf[8];
35802 - int buf_size;
35803 + size_t buf_size;
35804 int value;
35805
35806 memset(buf, 0, sizeof(buf));
35807 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35808 {
35809 struct iwl_priv *priv = file->private_data;
35810 char buf[8];
35811 - int buf_size;
35812 + size_t buf_size;
35813 int clear;
35814
35815 memset(buf, 0, sizeof(buf));
35816 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35817 {
35818 struct iwl_priv *priv = file->private_data;
35819 char buf[8];
35820 - int buf_size;
35821 + size_t buf_size;
35822 int trace;
35823
35824 memset(buf, 0, sizeof(buf));
35825 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35826 {
35827 struct iwl_priv *priv = file->private_data;
35828 char buf[8];
35829 - int buf_size;
35830 + size_t buf_size;
35831 int missed;
35832
35833 memset(buf, 0, sizeof(buf));
35834 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35835
35836 struct iwl_priv *priv = file->private_data;
35837 char buf[8];
35838 - int buf_size;
35839 + size_t buf_size;
35840 int plcp;
35841
35842 memset(buf, 0, sizeof(buf));
35843 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35844
35845 struct iwl_priv *priv = file->private_data;
35846 char buf[8];
35847 - int buf_size;
35848 + size_t buf_size;
35849 int flush;
35850
35851 memset(buf, 0, sizeof(buf));
35852 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35853
35854 struct iwl_priv *priv = file->private_data;
35855 char buf[8];
35856 - int buf_size;
35857 + size_t buf_size;
35858 int rts;
35859
35860 if (!priv->cfg->ht_params)
35861 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35862 {
35863 struct iwl_priv *priv = file->private_data;
35864 char buf[8];
35865 - int buf_size;
35866 + size_t buf_size;
35867
35868 memset(buf, 0, sizeof(buf));
35869 buf_size = min(count, sizeof(buf) - 1);
35870 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35871 struct iwl_priv *priv = file->private_data;
35872 u32 event_log_flag;
35873 char buf[8];
35874 - int buf_size;
35875 + size_t buf_size;
35876
35877 /* check that the interface is up */
35878 if (!iwl_is_ready(priv))
35879 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35880 struct iwl_priv *priv = file->private_data;
35881 char buf[8];
35882 u32 calib_disabled;
35883 - int buf_size;
35884 + size_t buf_size;
35885
35886 memset(buf, 0, sizeof(buf));
35887 buf_size = min(count, sizeof(buf) - 1);
35888 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35889 index dbeebef..b45a152 100644
35890 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35891 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35892 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35893 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35894
35895 char buf[8];
35896 - int buf_size;
35897 + size_t buf_size;
35898 u32 reset_flag;
35899
35900 memset(buf, 0, sizeof(buf));
35901 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35902 {
35903 struct iwl_trans *trans = file->private_data;
35904 char buf[8];
35905 - int buf_size;
35906 + size_t buf_size;
35907 int csr;
35908
35909 memset(buf, 0, sizeof(buf));
35910 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35911 index 0083839..fcb7225 100644
35912 --- a/drivers/net/wireless/mac80211_hwsim.c
35913 +++ b/drivers/net/wireless/mac80211_hwsim.c
35914 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35915 return -EINVAL;
35916
35917 if (fake_hw_scan) {
35918 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35919 - mac80211_hwsim_ops.sw_scan_start = NULL;
35920 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35921 + pax_open_kernel();
35922 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35923 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35924 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35925 + pax_close_kernel();
35926 }
35927
35928 spin_lock_init(&hwsim_radio_lock);
35929 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35930 index e7c2a82..582e228 100644
35931 --- a/drivers/net/wireless/mwifiex/main.h
35932 +++ b/drivers/net/wireless/mwifiex/main.h
35933 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
35934 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35935 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35936 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35937 -};
35938 +} __no_const;
35939
35940 struct mwifiex_adapter {
35941 u8 iface_type;
35942 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35943 index 7a4ae9e..56e00bd 100644
35944 --- a/drivers/net/wireless/rndis_wlan.c
35945 +++ b/drivers/net/wireless/rndis_wlan.c
35946 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35947
35948 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35949
35950 - if (rts_threshold < 0 || rts_threshold > 2347)
35951 + if (rts_threshold > 2347)
35952 rts_threshold = 2347;
35953
35954 tmp = cpu_to_le32(rts_threshold);
35955 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35956 index 8afb546..0c0dc5c 100644
35957 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35958 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35959 @@ -397,7 +397,7 @@ struct rt2x00_intf {
35960 * for hardware which doesn't support hardware
35961 * sequence counting.
35962 */
35963 - atomic_t seqno;
35964 + atomic_unchecked_t seqno;
35965 };
35966
35967 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35968 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35969 index f7e74a0..da71431 100644
35970 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35971 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35972 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35973 * sequence counter given by mac80211.
35974 */
35975 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35976 - seqno = atomic_add_return(0x10, &intf->seqno);
35977 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35978 else
35979 - seqno = atomic_read(&intf->seqno);
35980 + seqno = atomic_read_unchecked(&intf->seqno);
35981
35982 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35983 hdr->seq_ctrl |= cpu_to_le16(seqno);
35984 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35985 index fd02060..74ee481 100644
35986 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35987 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35988 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35989 void (*reset)(struct wl1251 *wl);
35990 void (*enable_irq)(struct wl1251 *wl);
35991 void (*disable_irq)(struct wl1251 *wl);
35992 -};
35993 +} __no_const;
35994
35995 struct wl1251 {
35996 struct ieee80211_hw *hw;
35997 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35998 index 0ce7a8e..56a0ccf 100644
35999 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36000 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36001 @@ -81,7 +81,7 @@ struct wlcore_ops {
36002 struct ieee80211_sta *sta,
36003 struct ieee80211_key_conf *key_conf);
36004 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36005 -};
36006 +} __no_const;
36007
36008 enum wlcore_partitions {
36009 PART_DOWN,
36010 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36011 index f34b5b2..b5abb9f 100644
36012 --- a/drivers/oprofile/buffer_sync.c
36013 +++ b/drivers/oprofile/buffer_sync.c
36014 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36015 if (cookie == NO_COOKIE)
36016 offset = pc;
36017 if (cookie == INVALID_COOKIE) {
36018 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36019 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36020 offset = pc;
36021 }
36022 if (cookie != last_cookie) {
36023 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36024 /* add userspace sample */
36025
36026 if (!mm) {
36027 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36028 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36029 return 0;
36030 }
36031
36032 cookie = lookup_dcookie(mm, s->eip, &offset);
36033
36034 if (cookie == INVALID_COOKIE) {
36035 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36036 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36037 return 0;
36038 }
36039
36040 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36041 /* ignore backtraces if failed to add a sample */
36042 if (state == sb_bt_start) {
36043 state = sb_bt_ignore;
36044 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36045 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36046 }
36047 }
36048 release_mm(mm);
36049 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36050 index c0cc4e7..44d4e54 100644
36051 --- a/drivers/oprofile/event_buffer.c
36052 +++ b/drivers/oprofile/event_buffer.c
36053 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36054 }
36055
36056 if (buffer_pos == buffer_size) {
36057 - atomic_inc(&oprofile_stats.event_lost_overflow);
36058 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36059 return;
36060 }
36061
36062 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36063 index ed2c3ec..deda85a 100644
36064 --- a/drivers/oprofile/oprof.c
36065 +++ b/drivers/oprofile/oprof.c
36066 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36067 if (oprofile_ops.switch_events())
36068 return;
36069
36070 - atomic_inc(&oprofile_stats.multiplex_counter);
36071 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36072 start_switch_worker();
36073 }
36074
36075 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36076 index 917d28e..d62d981 100644
36077 --- a/drivers/oprofile/oprofile_stats.c
36078 +++ b/drivers/oprofile/oprofile_stats.c
36079 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36080 cpu_buf->sample_invalid_eip = 0;
36081 }
36082
36083 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36084 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36085 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36086 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36087 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36088 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36089 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36090 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36091 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36092 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36093 }
36094
36095
36096 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36097 index 38b6fc0..b5cbfce 100644
36098 --- a/drivers/oprofile/oprofile_stats.h
36099 +++ b/drivers/oprofile/oprofile_stats.h
36100 @@ -13,11 +13,11 @@
36101 #include <linux/atomic.h>
36102
36103 struct oprofile_stat_struct {
36104 - atomic_t sample_lost_no_mm;
36105 - atomic_t sample_lost_no_mapping;
36106 - atomic_t bt_lost_no_mapping;
36107 - atomic_t event_lost_overflow;
36108 - atomic_t multiplex_counter;
36109 + atomic_unchecked_t sample_lost_no_mm;
36110 + atomic_unchecked_t sample_lost_no_mapping;
36111 + atomic_unchecked_t bt_lost_no_mapping;
36112 + atomic_unchecked_t event_lost_overflow;
36113 + atomic_unchecked_t multiplex_counter;
36114 };
36115
36116 extern struct oprofile_stat_struct oprofile_stats;
36117 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36118 index 849357c..b83c1e0 100644
36119 --- a/drivers/oprofile/oprofilefs.c
36120 +++ b/drivers/oprofile/oprofilefs.c
36121 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36122
36123
36124 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36125 - char const *name, atomic_t *val)
36126 + char const *name, atomic_unchecked_t *val)
36127 {
36128 return __oprofilefs_create_file(sb, root, name,
36129 &atomic_ro_fops, 0444, val);
36130 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36131 index 3f56bc0..707d642 100644
36132 --- a/drivers/parport/procfs.c
36133 +++ b/drivers/parport/procfs.c
36134 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36135
36136 *ppos += len;
36137
36138 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36139 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36140 }
36141
36142 #ifdef CONFIG_PARPORT_1284
36143 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36144
36145 *ppos += len;
36146
36147 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36148 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36149 }
36150 #endif /* IEEE1284.3 support. */
36151
36152 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36153 index 9fff878..ad0ad53 100644
36154 --- a/drivers/pci/hotplug/cpci_hotplug.h
36155 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36156 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36157 int (*hardware_test) (struct slot* slot, u32 value);
36158 u8 (*get_power) (struct slot* slot);
36159 int (*set_power) (struct slot* slot, int value);
36160 -};
36161 +} __no_const;
36162
36163 struct cpci_hp_controller {
36164 unsigned int irq;
36165 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36166 index 76ba8a1..20ca857 100644
36167 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36168 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36169 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36170
36171 void compaq_nvram_init (void __iomem *rom_start)
36172 {
36173 +
36174 +#ifndef CONFIG_PAX_KERNEXEC
36175 if (rom_start) {
36176 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36177 }
36178 +#endif
36179 +
36180 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36181
36182 /* initialize our int15 lock */
36183 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36184 index b500840..d7159d3 100644
36185 --- a/drivers/pci/pcie/aspm.c
36186 +++ b/drivers/pci/pcie/aspm.c
36187 @@ -27,9 +27,9 @@
36188 #define MODULE_PARAM_PREFIX "pcie_aspm."
36189
36190 /* Note: those are not register definitions */
36191 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36192 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36193 -#define ASPM_STATE_L1 (4) /* L1 state */
36194 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36195 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36196 +#define ASPM_STATE_L1 (4U) /* L1 state */
36197 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36198 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36199
36200 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36201 index 61859d0..124539e 100644
36202 --- a/drivers/pci/probe.c
36203 +++ b/drivers/pci/probe.c
36204 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36205 struct pci_bus_region region;
36206 bool bar_too_big = false, bar_disabled = false;
36207
36208 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36209 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36210
36211 /* No printks while decoding is disabled! */
36212 if (!dev->mmio_always_on) {
36213 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36214 index 27911b5..5b6db88 100644
36215 --- a/drivers/pci/proc.c
36216 +++ b/drivers/pci/proc.c
36217 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36218 static int __init pci_proc_init(void)
36219 {
36220 struct pci_dev *dev = NULL;
36221 +
36222 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36223 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36224 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36225 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36226 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36227 +#endif
36228 +#else
36229 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36230 +#endif
36231 proc_create("devices", 0, proc_bus_pci_dir,
36232 &proc_bus_pci_dev_operations);
36233 proc_initialized = 1;
36234 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36235 index 52daaa8..d6b81eb 100644
36236 --- a/drivers/platform/x86/thinkpad_acpi.c
36237 +++ b/drivers/platform/x86/thinkpad_acpi.c
36238 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36239 return 0;
36240 }
36241
36242 -void static hotkey_mask_warn_incomplete_mask(void)
36243 +static void hotkey_mask_warn_incomplete_mask(void)
36244 {
36245 /* log only what the user can fix... */
36246 const u32 wantedmask = hotkey_driver_mask &
36247 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36248 }
36249 }
36250
36251 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36252 - struct tp_nvram_state *newn,
36253 - const u32 event_mask)
36254 -{
36255 -
36256 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36257 do { \
36258 if ((event_mask & (1 << __scancode)) && \
36259 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36260 tpacpi_hotkey_send_key(__scancode); \
36261 } while (0)
36262
36263 - void issue_volchange(const unsigned int oldvol,
36264 - const unsigned int newvol)
36265 - {
36266 - unsigned int i = oldvol;
36267 +static void issue_volchange(const unsigned int oldvol,
36268 + const unsigned int newvol,
36269 + const u32 event_mask)
36270 +{
36271 + unsigned int i = oldvol;
36272
36273 - while (i > newvol) {
36274 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36275 - i--;
36276 - }
36277 - while (i < newvol) {
36278 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36279 - i++;
36280 - }
36281 + while (i > newvol) {
36282 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36283 + i--;
36284 }
36285 + while (i < newvol) {
36286 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36287 + i++;
36288 + }
36289 +}
36290
36291 - void issue_brightnesschange(const unsigned int oldbrt,
36292 - const unsigned int newbrt)
36293 - {
36294 - unsigned int i = oldbrt;
36295 +static void issue_brightnesschange(const unsigned int oldbrt,
36296 + const unsigned int newbrt,
36297 + const u32 event_mask)
36298 +{
36299 + unsigned int i = oldbrt;
36300
36301 - while (i > newbrt) {
36302 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36303 - i--;
36304 - }
36305 - while (i < newbrt) {
36306 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36307 - i++;
36308 - }
36309 + while (i > newbrt) {
36310 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36311 + i--;
36312 + }
36313 + while (i < newbrt) {
36314 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36315 + i++;
36316 }
36317 +}
36318
36319 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36320 + struct tp_nvram_state *newn,
36321 + const u32 event_mask)
36322 +{
36323 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36324 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36325 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36326 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36327 oldn->volume_level != newn->volume_level) {
36328 /* recently muted, or repeated mute keypress, or
36329 * multiple presses ending in mute */
36330 - issue_volchange(oldn->volume_level, newn->volume_level);
36331 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36332 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36333 }
36334 } else {
36335 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36336 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36337 }
36338 if (oldn->volume_level != newn->volume_level) {
36339 - issue_volchange(oldn->volume_level, newn->volume_level);
36340 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36341 } else if (oldn->volume_toggle != newn->volume_toggle) {
36342 /* repeated vol up/down keypress at end of scale ? */
36343 if (newn->volume_level == 0)
36344 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36345 /* handle brightness */
36346 if (oldn->brightness_level != newn->brightness_level) {
36347 issue_brightnesschange(oldn->brightness_level,
36348 - newn->brightness_level);
36349 + newn->brightness_level,
36350 + event_mask);
36351 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36352 /* repeated key presses that didn't change state */
36353 if (newn->brightness_level == 0)
36354 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36355 && !tp_features.bright_unkfw)
36356 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36357 }
36358 +}
36359
36360 #undef TPACPI_COMPARE_KEY
36361 #undef TPACPI_MAY_SEND_KEY
36362 -}
36363
36364 /*
36365 * Polling driver
36366 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36367 index 769d265..a3a05ca 100644
36368 --- a/drivers/pnp/pnpbios/bioscalls.c
36369 +++ b/drivers/pnp/pnpbios/bioscalls.c
36370 @@ -58,7 +58,7 @@ do { \
36371 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36372 } while(0)
36373
36374 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36375 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36376 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36377
36378 /*
36379 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36380
36381 cpu = get_cpu();
36382 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36383 +
36384 + pax_open_kernel();
36385 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36386 + pax_close_kernel();
36387
36388 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36389 spin_lock_irqsave(&pnp_bios_lock, flags);
36390 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36391 :"memory");
36392 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36393
36394 + pax_open_kernel();
36395 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36396 + pax_close_kernel();
36397 +
36398 put_cpu();
36399
36400 /* If we get here and this is set then the PnP BIOS faulted on us. */
36401 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36402 return status;
36403 }
36404
36405 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36406 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36407 {
36408 int i;
36409
36410 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36411 pnp_bios_callpoint.offset = header->fields.pm16offset;
36412 pnp_bios_callpoint.segment = PNP_CS16;
36413
36414 + pax_open_kernel();
36415 +
36416 for_each_possible_cpu(i) {
36417 struct desc_struct *gdt = get_cpu_gdt_table(i);
36418 if (!gdt)
36419 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36420 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36421 (unsigned long)__va(header->fields.pm16dseg));
36422 }
36423 +
36424 + pax_close_kernel();
36425 }
36426 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36427 index b0ecacb..7c9da2e 100644
36428 --- a/drivers/pnp/resource.c
36429 +++ b/drivers/pnp/resource.c
36430 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36431 return 1;
36432
36433 /* check if the resource is valid */
36434 - if (*irq < 0 || *irq > 15)
36435 + if (*irq > 15)
36436 return 0;
36437
36438 /* check if the resource is reserved */
36439 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36440 return 1;
36441
36442 /* check if the resource is valid */
36443 - if (*dma < 0 || *dma == 4 || *dma > 7)
36444 + if (*dma == 4 || *dma > 7)
36445 return 0;
36446
36447 /* check if the resource is reserved */
36448 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36449 index 181ddec..774b6da 100644
36450 --- a/drivers/power/bq27x00_battery.c
36451 +++ b/drivers/power/bq27x00_battery.c
36452 @@ -80,7 +80,7 @@
36453 struct bq27x00_device_info;
36454 struct bq27x00_access_methods {
36455 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36456 -};
36457 +} __no_const;
36458
36459 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36460
36461 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36462 index 8d53174..04c65de 100644
36463 --- a/drivers/regulator/max8660.c
36464 +++ b/drivers/regulator/max8660.c
36465 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36466 max8660->shadow_regs[MAX8660_OVER1] = 5;
36467 } else {
36468 /* Otherwise devices can be toggled via software */
36469 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36470 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36471 + pax_open_kernel();
36472 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36473 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36474 + pax_close_kernel();
36475 }
36476
36477 /*
36478 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36479 index b388b74..ed82573 100644
36480 --- a/drivers/regulator/mc13892-regulator.c
36481 +++ b/drivers/regulator/mc13892-regulator.c
36482 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36483 }
36484 mc13xxx_unlock(mc13892);
36485
36486 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36487 + pax_open_kernel();
36488 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36489 = mc13892_vcam_set_mode;
36490 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36491 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36492 = mc13892_vcam_get_mode;
36493 + pax_close_kernel();
36494
36495 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36496 ARRAY_SIZE(mc13892_regulators));
36497 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36498 index cace6d3..f623fda 100644
36499 --- a/drivers/rtc/rtc-dev.c
36500 +++ b/drivers/rtc/rtc-dev.c
36501 @@ -14,6 +14,7 @@
36502 #include <linux/module.h>
36503 #include <linux/rtc.h>
36504 #include <linux/sched.h>
36505 +#include <linux/grsecurity.h>
36506 #include "rtc-core.h"
36507
36508 static dev_t rtc_devt;
36509 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36510 if (copy_from_user(&tm, uarg, sizeof(tm)))
36511 return -EFAULT;
36512
36513 + gr_log_timechange();
36514 +
36515 return rtc_set_time(rtc, &tm);
36516
36517 case RTC_PIE_ON:
36518 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36519 index 9e933a8..4f969f7 100644
36520 --- a/drivers/scsi/aacraid/aacraid.h
36521 +++ b/drivers/scsi/aacraid/aacraid.h
36522 @@ -503,7 +503,7 @@ struct adapter_ops
36523 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36524 /* Administrative operations */
36525 int (*adapter_comm)(struct aac_dev * dev, int comm);
36526 -};
36527 +} __no_const;
36528
36529 /*
36530 * Define which interrupt handler needs to be installed
36531 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36532 index 7199534..cb7f158 100644
36533 --- a/drivers/scsi/aacraid/linit.c
36534 +++ b/drivers/scsi/aacraid/linit.c
36535 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36536 #elif defined(__devinitconst)
36537 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36538 #else
36539 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36540 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36541 #endif
36542 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36543 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36544 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36545 index ff80552..1c4120c 100644
36546 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36547 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36548 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36549 .lldd_ata_set_dmamode = asd_set_dmamode,
36550 };
36551
36552 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36553 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36554 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36555 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36556 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36557 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36558 index 4ad7e36..d004679 100644
36559 --- a/drivers/scsi/bfa/bfa.h
36560 +++ b/drivers/scsi/bfa/bfa.h
36561 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36562 u32 *end);
36563 int cpe_vec_q0;
36564 int rme_vec_q0;
36565 -};
36566 +} __no_const;
36567 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36568
36569 struct bfa_faa_cbfn_s {
36570 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36571 index f0f80e2..8ec946b 100644
36572 --- a/drivers/scsi/bfa/bfa_fcpim.c
36573 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36574 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36575
36576 bfa_iotag_attach(fcp);
36577
36578 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36579 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36580 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36581 (fcp->num_itns * sizeof(struct bfa_itn_s));
36582 memset(fcp->itn_arr, 0,
36583 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36584 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36585 {
36586 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36587 - struct bfa_itn_s *itn;
36588 + bfa_itn_s_no_const *itn;
36589
36590 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36591 itn->isr = isr;
36592 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36593 index 36f26da..38a34a8 100644
36594 --- a/drivers/scsi/bfa/bfa_fcpim.h
36595 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36596 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36597 struct bfa_itn_s {
36598 bfa_isr_func_t isr;
36599 };
36600 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36601
36602 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36603 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36604 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36605 struct list_head iotag_tio_free_q; /* free IO resources */
36606 struct list_head iotag_unused_q; /* unused IO resources*/
36607 struct bfa_iotag_s *iotag_arr;
36608 - struct bfa_itn_s *itn_arr;
36609 + bfa_itn_s_no_const *itn_arr;
36610 int num_ioim_reqs;
36611 int num_fwtio_reqs;
36612 int num_itns;
36613 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36614 index 1a99d4b..e85d64b 100644
36615 --- a/drivers/scsi/bfa/bfa_ioc.h
36616 +++ b/drivers/scsi/bfa/bfa_ioc.h
36617 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36618 bfa_ioc_disable_cbfn_t disable_cbfn;
36619 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36620 bfa_ioc_reset_cbfn_t reset_cbfn;
36621 -};
36622 +} __no_const;
36623
36624 /*
36625 * IOC event notification mechanism.
36626 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36627 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36628 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36629 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36630 -};
36631 +} __no_const;
36632
36633 /*
36634 * Queue element to wait for room in request queue. FIFO order is
36635 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36636 index 593085a..47aa999 100644
36637 --- a/drivers/scsi/hosts.c
36638 +++ b/drivers/scsi/hosts.c
36639 @@ -42,7 +42,7 @@
36640 #include "scsi_logging.h"
36641
36642
36643 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36644 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36645
36646
36647 static void scsi_host_cls_release(struct device *dev)
36648 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36649 * subtract one because we increment first then return, but we need to
36650 * know what the next host number was before increment
36651 */
36652 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36653 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36654 shost->dma_channel = 0xff;
36655
36656 /* These three are default values which can be overridden */
36657 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36658 index f9823f2..7bc3e81 100644
36659 --- a/drivers/scsi/hpsa.c
36660 +++ b/drivers/scsi/hpsa.c
36661 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36662 unsigned long flags;
36663
36664 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36665 - return h->access.command_completed(h, q);
36666 + return h->access->command_completed(h, q);
36667
36668 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36669 a = rq->head[rq->current_entry];
36670 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36671 while (!list_empty(&h->reqQ)) {
36672 c = list_entry(h->reqQ.next, struct CommandList, list);
36673 /* can't do anything if fifo is full */
36674 - if ((h->access.fifo_full(h))) {
36675 + if ((h->access->fifo_full(h))) {
36676 dev_warn(&h->pdev->dev, "fifo full\n");
36677 break;
36678 }
36679 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36680
36681 /* Tell the controller execute command */
36682 spin_unlock_irqrestore(&h->lock, flags);
36683 - h->access.submit_command(h, c);
36684 + h->access->submit_command(h, c);
36685 spin_lock_irqsave(&h->lock, flags);
36686 }
36687 spin_unlock_irqrestore(&h->lock, flags);
36688 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36689
36690 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36691 {
36692 - return h->access.command_completed(h, q);
36693 + return h->access->command_completed(h, q);
36694 }
36695
36696 static inline bool interrupt_pending(struct ctlr_info *h)
36697 {
36698 - return h->access.intr_pending(h);
36699 + return h->access->intr_pending(h);
36700 }
36701
36702 static inline long interrupt_not_for_us(struct ctlr_info *h)
36703 {
36704 - return (h->access.intr_pending(h) == 0) ||
36705 + return (h->access->intr_pending(h) == 0) ||
36706 (h->interrupts_enabled == 0);
36707 }
36708
36709 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36710 if (prod_index < 0)
36711 return -ENODEV;
36712 h->product_name = products[prod_index].product_name;
36713 - h->access = *(products[prod_index].access);
36714 + h->access = products[prod_index].access;
36715
36716 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36717 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36718 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36719
36720 assert_spin_locked(&lockup_detector_lock);
36721 remove_ctlr_from_lockup_detector_list(h);
36722 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36723 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36724 spin_lock_irqsave(&h->lock, flags);
36725 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36726 spin_unlock_irqrestore(&h->lock, flags);
36727 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36728 }
36729
36730 /* make sure the board interrupts are off */
36731 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36732 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36733
36734 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36735 goto clean2;
36736 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36737 * fake ones to scoop up any residual completions.
36738 */
36739 spin_lock_irqsave(&h->lock, flags);
36740 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36741 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36742 spin_unlock_irqrestore(&h->lock, flags);
36743 free_irqs(h);
36744 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36745 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36746 dev_info(&h->pdev->dev, "Board READY.\n");
36747 dev_info(&h->pdev->dev,
36748 "Waiting for stale completions to drain.\n");
36749 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36750 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36751 msleep(10000);
36752 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36753 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36754
36755 rc = controller_reset_failed(h->cfgtable);
36756 if (rc)
36757 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36758 }
36759
36760 /* Turn the interrupts on so we can service requests */
36761 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36762 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36763
36764 hpsa_hba_inquiry(h);
36765 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36766 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36767 * To write all data in the battery backed cache to disks
36768 */
36769 hpsa_flush_cache(h);
36770 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36771 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36772 hpsa_free_irqs_and_disable_msix(h);
36773 }
36774
36775 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36776 return;
36777 }
36778 /* Change the access methods to the performant access methods */
36779 - h->access = SA5_performant_access;
36780 + h->access = &SA5_performant_access;
36781 h->transMethod = CFGTBL_Trans_Performant;
36782 }
36783
36784 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36785 index 9816479..c5d4e97 100644
36786 --- a/drivers/scsi/hpsa.h
36787 +++ b/drivers/scsi/hpsa.h
36788 @@ -79,7 +79,7 @@ struct ctlr_info {
36789 unsigned int msix_vector;
36790 unsigned int msi_vector;
36791 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36792 - struct access_method access;
36793 + struct access_method *access;
36794
36795 /* queue and queue Info */
36796 struct list_head reqQ;
36797 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36798 index f2df059..a3a9930 100644
36799 --- a/drivers/scsi/ips.h
36800 +++ b/drivers/scsi/ips.h
36801 @@ -1027,7 +1027,7 @@ typedef struct {
36802 int (*intr)(struct ips_ha *);
36803 void (*enableint)(struct ips_ha *);
36804 uint32_t (*statupd)(struct ips_ha *);
36805 -} ips_hw_func_t;
36806 +} __no_const ips_hw_func_t;
36807
36808 typedef struct ips_ha {
36809 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36810 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36811 index c772d8d..35c362c 100644
36812 --- a/drivers/scsi/libfc/fc_exch.c
36813 +++ b/drivers/scsi/libfc/fc_exch.c
36814 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36815 u16 pool_max_index;
36816
36817 struct {
36818 - atomic_t no_free_exch;
36819 - atomic_t no_free_exch_xid;
36820 - atomic_t xid_not_found;
36821 - atomic_t xid_busy;
36822 - atomic_t seq_not_found;
36823 - atomic_t non_bls_resp;
36824 + atomic_unchecked_t no_free_exch;
36825 + atomic_unchecked_t no_free_exch_xid;
36826 + atomic_unchecked_t xid_not_found;
36827 + atomic_unchecked_t xid_busy;
36828 + atomic_unchecked_t seq_not_found;
36829 + atomic_unchecked_t non_bls_resp;
36830 } stats;
36831 };
36832
36833 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36834 /* allocate memory for exchange */
36835 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36836 if (!ep) {
36837 - atomic_inc(&mp->stats.no_free_exch);
36838 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36839 goto out;
36840 }
36841 memset(ep, 0, sizeof(*ep));
36842 @@ -786,7 +786,7 @@ out:
36843 return ep;
36844 err:
36845 spin_unlock_bh(&pool->lock);
36846 - atomic_inc(&mp->stats.no_free_exch_xid);
36847 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36848 mempool_free(ep, mp->ep_pool);
36849 return NULL;
36850 }
36851 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36852 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36853 ep = fc_exch_find(mp, xid);
36854 if (!ep) {
36855 - atomic_inc(&mp->stats.xid_not_found);
36856 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36857 reject = FC_RJT_OX_ID;
36858 goto out;
36859 }
36860 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36861 ep = fc_exch_find(mp, xid);
36862 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36863 if (ep) {
36864 - atomic_inc(&mp->stats.xid_busy);
36865 + atomic_inc_unchecked(&mp->stats.xid_busy);
36866 reject = FC_RJT_RX_ID;
36867 goto rel;
36868 }
36869 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36870 }
36871 xid = ep->xid; /* get our XID */
36872 } else if (!ep) {
36873 - atomic_inc(&mp->stats.xid_not_found);
36874 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36875 reject = FC_RJT_RX_ID; /* XID not found */
36876 goto out;
36877 }
36878 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36879 } else {
36880 sp = &ep->seq;
36881 if (sp->id != fh->fh_seq_id) {
36882 - atomic_inc(&mp->stats.seq_not_found);
36883 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36884 if (f_ctl & FC_FC_END_SEQ) {
36885 /*
36886 * Update sequence_id based on incoming last
36887 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36888
36889 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36890 if (!ep) {
36891 - atomic_inc(&mp->stats.xid_not_found);
36892 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36893 goto out;
36894 }
36895 if (ep->esb_stat & ESB_ST_COMPLETE) {
36896 - atomic_inc(&mp->stats.xid_not_found);
36897 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36898 goto rel;
36899 }
36900 if (ep->rxid == FC_XID_UNKNOWN)
36901 ep->rxid = ntohs(fh->fh_rx_id);
36902 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36903 - atomic_inc(&mp->stats.xid_not_found);
36904 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36905 goto rel;
36906 }
36907 if (ep->did != ntoh24(fh->fh_s_id) &&
36908 ep->did != FC_FID_FLOGI) {
36909 - atomic_inc(&mp->stats.xid_not_found);
36910 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36911 goto rel;
36912 }
36913 sof = fr_sof(fp);
36914 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36915 sp->ssb_stat |= SSB_ST_RESP;
36916 sp->id = fh->fh_seq_id;
36917 } else if (sp->id != fh->fh_seq_id) {
36918 - atomic_inc(&mp->stats.seq_not_found);
36919 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36920 goto rel;
36921 }
36922
36923 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36924 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36925
36926 if (!sp)
36927 - atomic_inc(&mp->stats.xid_not_found);
36928 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36929 else
36930 - atomic_inc(&mp->stats.non_bls_resp);
36931 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36932
36933 fc_frame_free(fp);
36934 }
36935 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36936
36937 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36938 mp = ema->mp;
36939 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36940 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36941 st->fc_no_free_exch_xid +=
36942 - atomic_read(&mp->stats.no_free_exch_xid);
36943 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36944 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36945 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36946 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36947 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36948 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36949 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36950 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36951 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36952 }
36953 }
36954 EXPORT_SYMBOL(fc_exch_update_stats);
36955 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36956 index a59fcdc..abe55f3 100644
36957 --- a/drivers/scsi/libsas/sas_ata.c
36958 +++ b/drivers/scsi/libsas/sas_ata.c
36959 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36960 .postreset = ata_std_postreset,
36961 .error_handler = ata_std_error_handler,
36962 .post_internal_cmd = sas_ata_post_internal,
36963 - .qc_defer = ata_std_qc_defer,
36964 + .qc_defer = ata_std_qc_defer,
36965 .qc_prep = ata_noop_qc_prep,
36966 .qc_issue = sas_ata_qc_issue,
36967 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36968 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36969 index a65c05a..a39e402 100644
36970 --- a/drivers/scsi/lpfc/lpfc.h
36971 +++ b/drivers/scsi/lpfc/lpfc.h
36972 @@ -420,7 +420,7 @@ struct lpfc_vport {
36973 struct dentry *debug_nodelist;
36974 struct dentry *vport_debugfs_root;
36975 struct lpfc_debugfs_trc *disc_trc;
36976 - atomic_t disc_trc_cnt;
36977 + atomic_unchecked_t disc_trc_cnt;
36978 #endif
36979 uint8_t stat_data_enabled;
36980 uint8_t stat_data_blocked;
36981 @@ -834,8 +834,8 @@ struct lpfc_hba {
36982 struct timer_list fabric_block_timer;
36983 unsigned long bit_flags;
36984 #define FABRIC_COMANDS_BLOCKED 0
36985 - atomic_t num_rsrc_err;
36986 - atomic_t num_cmd_success;
36987 + atomic_unchecked_t num_rsrc_err;
36988 + atomic_unchecked_t num_cmd_success;
36989 unsigned long last_rsrc_error_time;
36990 unsigned long last_ramp_down_time;
36991 unsigned long last_ramp_up_time;
36992 @@ -871,7 +871,7 @@ struct lpfc_hba {
36993
36994 struct dentry *debug_slow_ring_trc;
36995 struct lpfc_debugfs_trc *slow_ring_trc;
36996 - atomic_t slow_ring_trc_cnt;
36997 + atomic_unchecked_t slow_ring_trc_cnt;
36998 /* iDiag debugfs sub-directory */
36999 struct dentry *idiag_root;
37000 struct dentry *idiag_pci_cfg;
37001 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37002 index 3217d63..c417981 100644
37003 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37004 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37005 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37006
37007 #include <linux/debugfs.h>
37008
37009 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37010 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37011 static unsigned long lpfc_debugfs_start_time = 0L;
37012
37013 /* iDiag */
37014 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37015 lpfc_debugfs_enable = 0;
37016
37017 len = 0;
37018 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37019 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37020 (lpfc_debugfs_max_disc_trc - 1);
37021 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37022 dtp = vport->disc_trc + i;
37023 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37024 lpfc_debugfs_enable = 0;
37025
37026 len = 0;
37027 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37028 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37029 (lpfc_debugfs_max_slow_ring_trc - 1);
37030 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37031 dtp = phba->slow_ring_trc + i;
37032 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37033 !vport || !vport->disc_trc)
37034 return;
37035
37036 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37037 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37038 (lpfc_debugfs_max_disc_trc - 1);
37039 dtp = vport->disc_trc + index;
37040 dtp->fmt = fmt;
37041 dtp->data1 = data1;
37042 dtp->data2 = data2;
37043 dtp->data3 = data3;
37044 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37045 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37046 dtp->jif = jiffies;
37047 #endif
37048 return;
37049 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37050 !phba || !phba->slow_ring_trc)
37051 return;
37052
37053 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37054 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37055 (lpfc_debugfs_max_slow_ring_trc - 1);
37056 dtp = phba->slow_ring_trc + index;
37057 dtp->fmt = fmt;
37058 dtp->data1 = data1;
37059 dtp->data2 = data2;
37060 dtp->data3 = data3;
37061 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37062 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37063 dtp->jif = jiffies;
37064 #endif
37065 return;
37066 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37067 "slow_ring buffer\n");
37068 goto debug_failed;
37069 }
37070 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37071 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37072 memset(phba->slow_ring_trc, 0,
37073 (sizeof(struct lpfc_debugfs_trc) *
37074 lpfc_debugfs_max_slow_ring_trc));
37075 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37076 "buffer\n");
37077 goto debug_failed;
37078 }
37079 - atomic_set(&vport->disc_trc_cnt, 0);
37080 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37081
37082 snprintf(name, sizeof(name), "discovery_trace");
37083 vport->debug_disc_trc =
37084 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37085 index 45c1520..35ba744 100644
37086 --- a/drivers/scsi/lpfc/lpfc_init.c
37087 +++ b/drivers/scsi/lpfc/lpfc_init.c
37088 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37089 "misc_register returned with status %d", error);
37090
37091 if (lpfc_enable_npiv) {
37092 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37093 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37094 + pax_open_kernel();
37095 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37096 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37097 + pax_close_kernel();
37098 }
37099 lpfc_transport_template =
37100 fc_attach_transport(&lpfc_transport_functions);
37101 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37102 index 925975d..0f1fc07 100644
37103 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37104 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37105 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37106 uint32_t evt_posted;
37107
37108 spin_lock_irqsave(&phba->hbalock, flags);
37109 - atomic_inc(&phba->num_rsrc_err);
37110 + atomic_inc_unchecked(&phba->num_rsrc_err);
37111 phba->last_rsrc_error_time = jiffies;
37112
37113 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37114 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37115 unsigned long flags;
37116 struct lpfc_hba *phba = vport->phba;
37117 uint32_t evt_posted;
37118 - atomic_inc(&phba->num_cmd_success);
37119 + atomic_inc_unchecked(&phba->num_cmd_success);
37120
37121 if (vport->cfg_lun_queue_depth <= queue_depth)
37122 return;
37123 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37124 unsigned long num_rsrc_err, num_cmd_success;
37125 int i;
37126
37127 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37128 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37129 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37130 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37131
37132 /*
37133 * The error and success command counters are global per
37134 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37135 }
37136 }
37137 lpfc_destroy_vport_work_array(phba, vports);
37138 - atomic_set(&phba->num_rsrc_err, 0);
37139 - atomic_set(&phba->num_cmd_success, 0);
37140 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37141 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37142 }
37143
37144 /**
37145 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37146 }
37147 }
37148 lpfc_destroy_vport_work_array(phba, vports);
37149 - atomic_set(&phba->num_rsrc_err, 0);
37150 - atomic_set(&phba->num_cmd_success, 0);
37151 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37152 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37153 }
37154
37155 /**
37156 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37157 index ea8a0b4..812a124 100644
37158 --- a/drivers/scsi/pmcraid.c
37159 +++ b/drivers/scsi/pmcraid.c
37160 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37161 res->scsi_dev = scsi_dev;
37162 scsi_dev->hostdata = res;
37163 res->change_detected = 0;
37164 - atomic_set(&res->read_failures, 0);
37165 - atomic_set(&res->write_failures, 0);
37166 + atomic_set_unchecked(&res->read_failures, 0);
37167 + atomic_set_unchecked(&res->write_failures, 0);
37168 rc = 0;
37169 }
37170 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37171 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37172
37173 /* If this was a SCSI read/write command keep count of errors */
37174 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37175 - atomic_inc(&res->read_failures);
37176 + atomic_inc_unchecked(&res->read_failures);
37177 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37178 - atomic_inc(&res->write_failures);
37179 + atomic_inc_unchecked(&res->write_failures);
37180
37181 if (!RES_IS_GSCSI(res->cfg_entry) &&
37182 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37183 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37184 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37185 * hrrq_id assigned here in queuecommand
37186 */
37187 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37188 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37189 pinstance->num_hrrq;
37190 cmd->cmd_done = pmcraid_io_done;
37191
37192 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37193 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37194 * hrrq_id assigned here in queuecommand
37195 */
37196 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37197 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37198 pinstance->num_hrrq;
37199
37200 if (request_size) {
37201 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37202
37203 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37204 /* add resources only after host is added into system */
37205 - if (!atomic_read(&pinstance->expose_resources))
37206 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37207 return;
37208
37209 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37210 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37211 init_waitqueue_head(&pinstance->reset_wait_q);
37212
37213 atomic_set(&pinstance->outstanding_cmds, 0);
37214 - atomic_set(&pinstance->last_message_id, 0);
37215 - atomic_set(&pinstance->expose_resources, 0);
37216 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37217 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37218
37219 INIT_LIST_HEAD(&pinstance->free_res_q);
37220 INIT_LIST_HEAD(&pinstance->used_res_q);
37221 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37222 /* Schedule worker thread to handle CCN and take care of adding and
37223 * removing devices to OS
37224 */
37225 - atomic_set(&pinstance->expose_resources, 1);
37226 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37227 schedule_work(&pinstance->worker_q);
37228 return rc;
37229
37230 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37231 index e1d150f..6c6df44 100644
37232 --- a/drivers/scsi/pmcraid.h
37233 +++ b/drivers/scsi/pmcraid.h
37234 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37235 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37236
37237 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37238 - atomic_t last_message_id;
37239 + atomic_unchecked_t last_message_id;
37240
37241 /* configuration table */
37242 struct pmcraid_config_table *cfg_table;
37243 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37244 atomic_t outstanding_cmds;
37245
37246 /* should add/delete resources to mid-layer now ?*/
37247 - atomic_t expose_resources;
37248 + atomic_unchecked_t expose_resources;
37249
37250
37251
37252 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37253 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37254 };
37255 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37256 - atomic_t read_failures; /* count of failed READ commands */
37257 - atomic_t write_failures; /* count of failed WRITE commands */
37258 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37259 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37260
37261 /* To indicate add/delete/modify during CCN */
37262 u8 change_detected;
37263 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37264 index 5ab9530..2dd80f7 100644
37265 --- a/drivers/scsi/qla2xxx/qla_attr.c
37266 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37267 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37268 return 0;
37269 }
37270
37271 -struct fc_function_template qla2xxx_transport_functions = {
37272 +fc_function_template_no_const qla2xxx_transport_functions = {
37273
37274 .show_host_node_name = 1,
37275 .show_host_port_name = 1,
37276 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37277 .bsg_timeout = qla24xx_bsg_timeout,
37278 };
37279
37280 -struct fc_function_template qla2xxx_transport_vport_functions = {
37281 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37282
37283 .show_host_node_name = 1,
37284 .show_host_port_name = 1,
37285 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37286 index 39007f5..7fafc64 100644
37287 --- a/drivers/scsi/qla2xxx/qla_def.h
37288 +++ b/drivers/scsi/qla2xxx/qla_def.h
37289 @@ -2284,7 +2284,7 @@ struct isp_operations {
37290 int (*start_scsi) (srb_t *);
37291 int (*abort_isp) (struct scsi_qla_host *);
37292 int (*iospace_config)(struct qla_hw_data*);
37293 -};
37294 +} __no_const;
37295
37296 /* MSI-X Support *************************************************************/
37297
37298 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37299 index 9eacd2d..d79629c 100644
37300 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37301 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37302 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37303 struct device_attribute;
37304 extern struct device_attribute *qla2x00_host_attrs[];
37305 struct fc_function_template;
37306 -extern struct fc_function_template qla2xxx_transport_functions;
37307 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37308 +extern fc_function_template_no_const qla2xxx_transport_functions;
37309 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37310 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37311 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37312 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37313 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37314 index 7fdba7f..1b4b2c2 100644
37315 --- a/drivers/scsi/qla4xxx/ql4_def.h
37316 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37317 @@ -268,7 +268,7 @@ struct ddb_entry {
37318 * (4000 only) */
37319 atomic_t relogin_timer; /* Max Time to wait for
37320 * relogin to complete */
37321 - atomic_t relogin_retry_count; /* Num of times relogin has been
37322 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37323 * retried */
37324 uint32_t default_time2wait; /* Default Min time between
37325 * relogins (+aens) */
37326 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37327 index 9da4266..377b3b6 100644
37328 --- a/drivers/scsi/qla4xxx/ql4_os.c
37329 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37330 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37331 */
37332 if (!iscsi_is_session_online(cls_sess)) {
37333 /* Reset retry relogin timer */
37334 - atomic_inc(&ddb_entry->relogin_retry_count);
37335 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37336 DEBUG2(ql4_printk(KERN_INFO, ha,
37337 "%s: index[%d] relogin timed out-retrying"
37338 " relogin (%d), retry (%d)\n", __func__,
37339 ddb_entry->fw_ddb_index,
37340 - atomic_read(&ddb_entry->relogin_retry_count),
37341 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37342 ddb_entry->default_time2wait + 4));
37343 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37344 atomic_set(&ddb_entry->retry_relogin_timer,
37345 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37346
37347 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37348 atomic_set(&ddb_entry->relogin_timer, 0);
37349 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37350 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37351 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37352 ddb_entry->default_relogin_timeout =
37353 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37354 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37355 index 2936b44..546ecdb 100644
37356 --- a/drivers/scsi/scsi.c
37357 +++ b/drivers/scsi/scsi.c
37358 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37359 unsigned long timeout;
37360 int rtn = 0;
37361
37362 - atomic_inc(&cmd->device->iorequest_cnt);
37363 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37364
37365 /* check if the device is still usable */
37366 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37367 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37368 index faa790f..7e351ddd 100644
37369 --- a/drivers/scsi/scsi_lib.c
37370 +++ b/drivers/scsi/scsi_lib.c
37371 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37372 shost = sdev->host;
37373 scsi_init_cmd_errh(cmd);
37374 cmd->result = DID_NO_CONNECT << 16;
37375 - atomic_inc(&cmd->device->iorequest_cnt);
37376 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37377
37378 /*
37379 * SCSI request completion path will do scsi_device_unbusy(),
37380 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37381
37382 INIT_LIST_HEAD(&cmd->eh_entry);
37383
37384 - atomic_inc(&cmd->device->iodone_cnt);
37385 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37386 if (cmd->result)
37387 - atomic_inc(&cmd->device->ioerr_cnt);
37388 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37389
37390 disposition = scsi_decide_disposition(cmd);
37391 if (disposition != SUCCESS &&
37392 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37393 index ce5224c..8c6d071 100644
37394 --- a/drivers/scsi/scsi_sysfs.c
37395 +++ b/drivers/scsi/scsi_sysfs.c
37396 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37397 char *buf) \
37398 { \
37399 struct scsi_device *sdev = to_scsi_device(dev); \
37400 - unsigned long long count = atomic_read(&sdev->field); \
37401 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37402 return snprintf(buf, 20, "0x%llx\n", count); \
37403 } \
37404 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37405 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37406 index 84a1fdf..693b0d6 100644
37407 --- a/drivers/scsi/scsi_tgt_lib.c
37408 +++ b/drivers/scsi/scsi_tgt_lib.c
37409 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37410 int err;
37411
37412 dprintk("%lx %u\n", uaddr, len);
37413 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37414 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37415 if (err) {
37416 /*
37417 * TODO: need to fixup sg_tablesize, max_segment_size,
37418 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37419 index e894ca7..de9d7660 100644
37420 --- a/drivers/scsi/scsi_transport_fc.c
37421 +++ b/drivers/scsi/scsi_transport_fc.c
37422 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37423 * Netlink Infrastructure
37424 */
37425
37426 -static atomic_t fc_event_seq;
37427 +static atomic_unchecked_t fc_event_seq;
37428
37429 /**
37430 * fc_get_event_number - Obtain the next sequential FC event number
37431 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37432 u32
37433 fc_get_event_number(void)
37434 {
37435 - return atomic_add_return(1, &fc_event_seq);
37436 + return atomic_add_return_unchecked(1, &fc_event_seq);
37437 }
37438 EXPORT_SYMBOL(fc_get_event_number);
37439
37440 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37441 {
37442 int error;
37443
37444 - atomic_set(&fc_event_seq, 0);
37445 + atomic_set_unchecked(&fc_event_seq, 0);
37446
37447 error = transport_class_register(&fc_host_class);
37448 if (error)
37449 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37450 char *cp;
37451
37452 *val = simple_strtoul(buf, &cp, 0);
37453 - if ((*cp && (*cp != '\n')) || (*val < 0))
37454 + if (*cp && (*cp != '\n'))
37455 return -EINVAL;
37456 /*
37457 * Check for overflow; dev_loss_tmo is u32
37458 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37459 index fa1dfaa..4bb620c 100644
37460 --- a/drivers/scsi/scsi_transport_iscsi.c
37461 +++ b/drivers/scsi/scsi_transport_iscsi.c
37462 @@ -79,7 +79,7 @@ struct iscsi_internal {
37463 struct transport_container session_cont;
37464 };
37465
37466 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37467 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37468 static struct workqueue_struct *iscsi_eh_timer_workq;
37469
37470 static DEFINE_IDA(iscsi_sess_ida);
37471 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37472 int err;
37473
37474 ihost = shost->shost_data;
37475 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37476 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37477
37478 if (target_id == ISCSI_MAX_TARGET) {
37479 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37480 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37481 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37482 ISCSI_TRANSPORT_VERSION);
37483
37484 - atomic_set(&iscsi_session_nr, 0);
37485 + atomic_set_unchecked(&iscsi_session_nr, 0);
37486
37487 err = class_register(&iscsi_transport_class);
37488 if (err)
37489 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37490 index 21a045e..ec89e03 100644
37491 --- a/drivers/scsi/scsi_transport_srp.c
37492 +++ b/drivers/scsi/scsi_transport_srp.c
37493 @@ -33,7 +33,7 @@
37494 #include "scsi_transport_srp_internal.h"
37495
37496 struct srp_host_attrs {
37497 - atomic_t next_port_id;
37498 + atomic_unchecked_t next_port_id;
37499 };
37500 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37501
37502 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37503 struct Scsi_Host *shost = dev_to_shost(dev);
37504 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37505
37506 - atomic_set(&srp_host->next_port_id, 0);
37507 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37508 return 0;
37509 }
37510
37511 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37512 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37513 rport->roles = ids->roles;
37514
37515 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37516 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37517 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37518
37519 transport_setup_device(&rport->dev);
37520 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37521 index 4df73e5..b691c58 100644
37522 --- a/drivers/scsi/sd.c
37523 +++ b/drivers/scsi/sd.c
37524 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37525 sdkp->disk = gd;
37526 sdkp->index = index;
37527 atomic_set(&sdkp->openers, 0);
37528 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37529 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37530
37531 if (!sdp->request_queue->rq_timeout) {
37532 if (sdp->type != TYPE_MOD)
37533 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37534 index 9c5c5f2..8414557 100644
37535 --- a/drivers/scsi/sg.c
37536 +++ b/drivers/scsi/sg.c
37537 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37538 sdp->disk->disk_name,
37539 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37540 NULL,
37541 - (char *)arg);
37542 + (char __user *)arg);
37543 case BLKTRACESTART:
37544 return blk_trace_startstop(sdp->device->request_queue, 1);
37545 case BLKTRACESTOP:
37546 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37547 index 84c2861..ece0a31 100644
37548 --- a/drivers/spi/spi.c
37549 +++ b/drivers/spi/spi.c
37550 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37551 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37552
37553 /* portable code must never pass more than 32 bytes */
37554 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37555 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37556
37557 static u8 *buf;
37558
37559 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37560 index 34afc16..ffe44dd 100644
37561 --- a/drivers/staging/octeon/ethernet-rx.c
37562 +++ b/drivers/staging/octeon/ethernet-rx.c
37563 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37564 /* Increment RX stats for virtual ports */
37565 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37566 #ifdef CONFIG_64BIT
37567 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37568 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37569 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37570 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37571 #else
37572 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37573 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37574 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37575 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37576 #endif
37577 }
37578 netif_receive_skb(skb);
37579 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37580 dev->name);
37581 */
37582 #ifdef CONFIG_64BIT
37583 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37584 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37585 #else
37586 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37587 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37588 #endif
37589 dev_kfree_skb_irq(skb);
37590 }
37591 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37592 index 683bedc..86dba9a 100644
37593 --- a/drivers/staging/octeon/ethernet.c
37594 +++ b/drivers/staging/octeon/ethernet.c
37595 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37596 * since the RX tasklet also increments it.
37597 */
37598 #ifdef CONFIG_64BIT
37599 - atomic64_add(rx_status.dropped_packets,
37600 - (atomic64_t *)&priv->stats.rx_dropped);
37601 + atomic64_add_unchecked(rx_status.dropped_packets,
37602 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37603 #else
37604 - atomic_add(rx_status.dropped_packets,
37605 - (atomic_t *)&priv->stats.rx_dropped);
37606 + atomic_add_unchecked(rx_status.dropped_packets,
37607 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37608 #endif
37609 }
37610
37611 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37612 index dc23395..cf7e9b1 100644
37613 --- a/drivers/staging/rtl8712/rtl871x_io.h
37614 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37615 @@ -108,7 +108,7 @@ struct _io_ops {
37616 u8 *pmem);
37617 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37618 u8 *pmem);
37619 -};
37620 +} __no_const;
37621
37622 struct io_req {
37623 struct list_head list;
37624 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37625 index c7b5e8b..783d6cb 100644
37626 --- a/drivers/staging/sbe-2t3e3/netdev.c
37627 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37628 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37629 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37630
37631 if (rlen)
37632 - if (copy_to_user(data, &resp, rlen))
37633 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37634 return -EFAULT;
37635
37636 return 0;
37637 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37638 index 5d89c0f..9261317 100644
37639 --- a/drivers/staging/usbip/usbip_common.h
37640 +++ b/drivers/staging/usbip/usbip_common.h
37641 @@ -289,7 +289,7 @@ struct usbip_device {
37642 void (*shutdown)(struct usbip_device *);
37643 void (*reset)(struct usbip_device *);
37644 void (*unusable)(struct usbip_device *);
37645 - } eh_ops;
37646 + } __no_const eh_ops;
37647 };
37648
37649 #define kthread_get_run(threadfn, data, namefmt, ...) \
37650 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37651 index c66b8b3..a4a035b 100644
37652 --- a/drivers/staging/usbip/vhci.h
37653 +++ b/drivers/staging/usbip/vhci.h
37654 @@ -83,7 +83,7 @@ struct vhci_hcd {
37655 unsigned resuming:1;
37656 unsigned long re_timeout;
37657
37658 - atomic_t seqnum;
37659 + atomic_unchecked_t seqnum;
37660
37661 /*
37662 * NOTE:
37663 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37664 index 12a9a5f..afd8295 100644
37665 --- a/drivers/staging/usbip/vhci_hcd.c
37666 +++ b/drivers/staging/usbip/vhci_hcd.c
37667 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37668 return;
37669 }
37670
37671 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37672 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37673 if (priv->seqnum == 0xffff)
37674 dev_info(&urb->dev->dev, "seqnum max\n");
37675
37676 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37677 return -ENOMEM;
37678 }
37679
37680 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37681 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37682 if (unlink->seqnum == 0xffff)
37683 pr_info("seqnum max\n");
37684
37685 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37686 vdev->rhport = rhport;
37687 }
37688
37689 - atomic_set(&vhci->seqnum, 0);
37690 + atomic_set_unchecked(&vhci->seqnum, 0);
37691 spin_lock_init(&vhci->lock);
37692
37693 hcd->power_budget = 0; /* no limit */
37694 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37695 index f0eaf04..5a82e06 100644
37696 --- a/drivers/staging/usbip/vhci_rx.c
37697 +++ b/drivers/staging/usbip/vhci_rx.c
37698 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37699 if (!urb) {
37700 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37701 pr_info("max seqnum %d\n",
37702 - atomic_read(&the_controller->seqnum));
37703 + atomic_read_unchecked(&the_controller->seqnum));
37704 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37705 return;
37706 }
37707 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37708 index 6ac6f45..1b208ba 100644
37709 --- a/drivers/staging/vt6655/hostap.c
37710 +++ b/drivers/staging/vt6655/hostap.c
37711 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37712 *
37713 */
37714
37715 +static net_device_ops_no_const apdev_netdev_ops;
37716 +
37717 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37718 {
37719 PSDevice apdev_priv;
37720 struct net_device *dev = pDevice->dev;
37721 int ret;
37722 - const struct net_device_ops apdev_netdev_ops = {
37723 - .ndo_start_xmit = pDevice->tx_80211,
37724 - };
37725
37726 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37727
37728 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37729 *apdev_priv = *pDevice;
37730 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37731
37732 + /* only half broken now */
37733 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37734 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37735
37736 pDevice->apdev->type = ARPHRD_IEEE80211;
37737 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37738 index 682002a..35ed5cf 100644
37739 --- a/drivers/staging/vt6656/hostap.c
37740 +++ b/drivers/staging/vt6656/hostap.c
37741 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37742 *
37743 */
37744
37745 +static net_device_ops_no_const apdev_netdev_ops;
37746 +
37747 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37748 {
37749 PSDevice apdev_priv;
37750 struct net_device *dev = pDevice->dev;
37751 int ret;
37752 - const struct net_device_ops apdev_netdev_ops = {
37753 - .ndo_start_xmit = pDevice->tx_80211,
37754 - };
37755
37756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37757
37758 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37759 *apdev_priv = *pDevice;
37760 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37761
37762 + /* only half broken now */
37763 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37764 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37765
37766 pDevice->apdev->type = ARPHRD_IEEE80211;
37767 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37768 index 7843dfd..3db105f 100644
37769 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37770 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37771 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37772
37773 struct usbctlx_completor {
37774 int (*complete) (struct usbctlx_completor *);
37775 -};
37776 +} __no_const;
37777
37778 static int
37779 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37780 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37781 index eaa9021..43f023b 100644
37782 --- a/drivers/staging/zcache/tmem.c
37783 +++ b/drivers/staging/zcache/tmem.c
37784 @@ -39,7 +39,7 @@
37785 * A tmem host implementation must use this function to register callbacks
37786 * for memory allocation.
37787 */
37788 -static struct tmem_hostops tmem_hostops;
37789 +static tmem_hostops_no_const tmem_hostops;
37790
37791 static void tmem_objnode_tree_init(void);
37792
37793 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37794 * A tmem host implementation must use this function to register
37795 * callbacks for a page-accessible memory (PAM) implementation
37796 */
37797 -static struct tmem_pamops tmem_pamops;
37798 +static tmem_pamops_no_const tmem_pamops;
37799
37800 void tmem_register_pamops(struct tmem_pamops *m)
37801 {
37802 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37803 index 0d4aa82..f7832d4 100644
37804 --- a/drivers/staging/zcache/tmem.h
37805 +++ b/drivers/staging/zcache/tmem.h
37806 @@ -180,6 +180,7 @@ struct tmem_pamops {
37807 void (*new_obj)(struct tmem_obj *);
37808 int (*replace_in_obj)(void *, struct tmem_obj *);
37809 };
37810 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37811 extern void tmem_register_pamops(struct tmem_pamops *m);
37812
37813 /* memory allocation methods provided by the host implementation */
37814 @@ -189,6 +190,7 @@ struct tmem_hostops {
37815 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37816 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37817 };
37818 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37819 extern void tmem_register_hostops(struct tmem_hostops *m);
37820
37821 /* core tmem accessor functions */
37822 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37823 index 269f544..32def0d 100644
37824 --- a/drivers/target/target_core_transport.c
37825 +++ b/drivers/target/target_core_transport.c
37826 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37827 spin_lock_init(&dev->se_port_lock);
37828 spin_lock_init(&dev->se_tmr_lock);
37829 spin_lock_init(&dev->qf_cmd_lock);
37830 - atomic_set(&dev->dev_ordered_id, 0);
37831 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37832
37833 se_dev_set_default_attribs(dev, dev_limits);
37834
37835 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37836 * Used to determine when ORDERED commands should go from
37837 * Dormant to Active status.
37838 */
37839 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37840 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37841 smp_mb__after_atomic_inc();
37842 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37843 cmd->se_ordered_id, cmd->sam_task_attr,
37844 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37845 index e61cabd..7617d26 100644
37846 --- a/drivers/tty/cyclades.c
37847 +++ b/drivers/tty/cyclades.c
37848 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37849 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37850 info->port.count);
37851 #endif
37852 - info->port.count++;
37853 + atomic_inc(&info->port.count);
37854 #ifdef CY_DEBUG_COUNT
37855 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37856 - current->pid, info->port.count);
37857 + current->pid, atomic_read(&info->port.count));
37858 #endif
37859
37860 /*
37861 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37862 for (j = 0; j < cy_card[i].nports; j++) {
37863 info = &cy_card[i].ports[j];
37864
37865 - if (info->port.count) {
37866 + if (atomic_read(&info->port.count)) {
37867 /* XXX is the ldisc num worth this? */
37868 struct tty_struct *tty;
37869 struct tty_ldisc *ld;
37870 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37871 index 2d691eb..be02ebd 100644
37872 --- a/drivers/tty/hvc/hvc_console.c
37873 +++ b/drivers/tty/hvc/hvc_console.c
37874 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37875
37876 spin_lock_irqsave(&hp->port.lock, flags);
37877 /* Check and then increment for fast path open. */
37878 - if (hp->port.count++ > 0) {
37879 + if (atomic_inc_return(&hp->port.count) > 1) {
37880 spin_unlock_irqrestore(&hp->port.lock, flags);
37881 hvc_kick();
37882 return 0;
37883 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37884
37885 spin_lock_irqsave(&hp->port.lock, flags);
37886
37887 - if (--hp->port.count == 0) {
37888 + if (atomic_dec_return(&hp->port.count) == 0) {
37889 spin_unlock_irqrestore(&hp->port.lock, flags);
37890 /* We are done with the tty pointer now. */
37891 tty_port_tty_set(&hp->port, NULL);
37892 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37893 */
37894 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37895 } else {
37896 - if (hp->port.count < 0)
37897 + if (atomic_read(&hp->port.count) < 0)
37898 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37899 - hp->vtermno, hp->port.count);
37900 + hp->vtermno, atomic_read(&hp->port.count));
37901 spin_unlock_irqrestore(&hp->port.lock, flags);
37902 }
37903
37904 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37905 * open->hangup case this can be called after the final close so prevent
37906 * that from happening for now.
37907 */
37908 - if (hp->port.count <= 0) {
37909 + if (atomic_read(&hp->port.count) <= 0) {
37910 spin_unlock_irqrestore(&hp->port.lock, flags);
37911 return;
37912 }
37913
37914 - temp_open_count = hp->port.count;
37915 - hp->port.count = 0;
37916 + temp_open_count = atomic_read(&hp->port.count);
37917 + atomic_set(&hp->port.count, 0);
37918 spin_unlock_irqrestore(&hp->port.lock, flags);
37919 tty_port_tty_set(&hp->port, NULL);
37920
37921 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37922 return -EPIPE;
37923
37924 /* FIXME what's this (unprotected) check for? */
37925 - if (hp->port.count <= 0)
37926 + if (atomic_read(&hp->port.count) <= 0)
37927 return -EIO;
37928
37929 spin_lock_irqsave(&hp->lock, flags);
37930 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37931 index d56788c..12d8f85 100644
37932 --- a/drivers/tty/hvc/hvcs.c
37933 +++ b/drivers/tty/hvc/hvcs.c
37934 @@ -83,6 +83,7 @@
37935 #include <asm/hvcserver.h>
37936 #include <asm/uaccess.h>
37937 #include <asm/vio.h>
37938 +#include <asm/local.h>
37939
37940 /*
37941 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37942 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37943
37944 spin_lock_irqsave(&hvcsd->lock, flags);
37945
37946 - if (hvcsd->port.count > 0) {
37947 + if (atomic_read(&hvcsd->port.count) > 0) {
37948 spin_unlock_irqrestore(&hvcsd->lock, flags);
37949 printk(KERN_INFO "HVCS: vterm state unchanged. "
37950 "The hvcs device node is still in use.\n");
37951 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37952 if ((retval = hvcs_partner_connect(hvcsd)))
37953 goto error_release;
37954
37955 - hvcsd->port.count = 1;
37956 + atomic_set(&hvcsd->port.count, 1);
37957 hvcsd->port.tty = tty;
37958 tty->driver_data = hvcsd;
37959
37960 @@ -1168,7 +1169,7 @@ fast_open:
37961
37962 spin_lock_irqsave(&hvcsd->lock, flags);
37963 tty_port_get(&hvcsd->port);
37964 - hvcsd->port.count++;
37965 + atomic_inc(&hvcsd->port.count);
37966 hvcsd->todo_mask |= HVCS_SCHED_READ;
37967 spin_unlock_irqrestore(&hvcsd->lock, flags);
37968
37969 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37970 hvcsd = tty->driver_data;
37971
37972 spin_lock_irqsave(&hvcsd->lock, flags);
37973 - if (--hvcsd->port.count == 0) {
37974 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37975
37976 vio_disable_interrupts(hvcsd->vdev);
37977
37978 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37979 free_irq(irq, hvcsd);
37980 tty_port_put(&hvcsd->port);
37981 return;
37982 - } else if (hvcsd->port.count < 0) {
37983 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37984 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37985 " is missmanaged.\n",
37986 - hvcsd->vdev->unit_address, hvcsd->port.count);
37987 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37988 }
37989
37990 spin_unlock_irqrestore(&hvcsd->lock, flags);
37991 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37992
37993 spin_lock_irqsave(&hvcsd->lock, flags);
37994 /* Preserve this so that we know how many kref refs to put */
37995 - temp_open_count = hvcsd->port.count;
37996 + temp_open_count = atomic_read(&hvcsd->port.count);
37997
37998 /*
37999 * Don't kref put inside the spinlock because the destruction
38000 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38001 tty->driver_data = NULL;
38002 hvcsd->port.tty = NULL;
38003
38004 - hvcsd->port.count = 0;
38005 + atomic_set(&hvcsd->port.count, 0);
38006
38007 /* This will drop any buffered data on the floor which is OK in a hangup
38008 * scenario. */
38009 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38010 * the middle of a write operation? This is a crummy place to do this
38011 * but we want to keep it all in the spinlock.
38012 */
38013 - if (hvcsd->port.count <= 0) {
38014 + if (atomic_read(&hvcsd->port.count) <= 0) {
38015 spin_unlock_irqrestore(&hvcsd->lock, flags);
38016 return -ENODEV;
38017 }
38018 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38019 {
38020 struct hvcs_struct *hvcsd = tty->driver_data;
38021
38022 - if (!hvcsd || hvcsd->port.count <= 0)
38023 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38024 return 0;
38025
38026 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38027 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38028 index f8b5fa0..4ba9f89 100644
38029 --- a/drivers/tty/ipwireless/tty.c
38030 +++ b/drivers/tty/ipwireless/tty.c
38031 @@ -29,6 +29,7 @@
38032 #include <linux/tty_driver.h>
38033 #include <linux/tty_flip.h>
38034 #include <linux/uaccess.h>
38035 +#include <asm/local.h>
38036
38037 #include "tty.h"
38038 #include "network.h"
38039 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38040 mutex_unlock(&tty->ipw_tty_mutex);
38041 return -ENODEV;
38042 }
38043 - if (tty->port.count == 0)
38044 + if (atomic_read(&tty->port.count) == 0)
38045 tty->tx_bytes_queued = 0;
38046
38047 - tty->port.count++;
38048 + atomic_inc(&tty->port.count);
38049
38050 tty->port.tty = linux_tty;
38051 linux_tty->driver_data = tty;
38052 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38053
38054 static void do_ipw_close(struct ipw_tty *tty)
38055 {
38056 - tty->port.count--;
38057 -
38058 - if (tty->port.count == 0) {
38059 + if (atomic_dec_return(&tty->port.count) == 0) {
38060 struct tty_struct *linux_tty = tty->port.tty;
38061
38062 if (linux_tty != NULL) {
38063 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38064 return;
38065
38066 mutex_lock(&tty->ipw_tty_mutex);
38067 - if (tty->port.count == 0) {
38068 + if (atomic_read(&tty->port.count) == 0) {
38069 mutex_unlock(&tty->ipw_tty_mutex);
38070 return;
38071 }
38072 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38073 return;
38074 }
38075
38076 - if (!tty->port.count) {
38077 + if (!atomic_read(&tty->port.count)) {
38078 mutex_unlock(&tty->ipw_tty_mutex);
38079 return;
38080 }
38081 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38082 return -ENODEV;
38083
38084 mutex_lock(&tty->ipw_tty_mutex);
38085 - if (!tty->port.count) {
38086 + if (!atomic_read(&tty->port.count)) {
38087 mutex_unlock(&tty->ipw_tty_mutex);
38088 return -EINVAL;
38089 }
38090 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38091 if (!tty)
38092 return -ENODEV;
38093
38094 - if (!tty->port.count)
38095 + if (!atomic_read(&tty->port.count))
38096 return -EINVAL;
38097
38098 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38099 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38100 if (!tty)
38101 return 0;
38102
38103 - if (!tty->port.count)
38104 + if (!atomic_read(&tty->port.count))
38105 return 0;
38106
38107 return tty->tx_bytes_queued;
38108 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38109 if (!tty)
38110 return -ENODEV;
38111
38112 - if (!tty->port.count)
38113 + if (!atomic_read(&tty->port.count))
38114 return -EINVAL;
38115
38116 return get_control_lines(tty);
38117 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38118 if (!tty)
38119 return -ENODEV;
38120
38121 - if (!tty->port.count)
38122 + if (!atomic_read(&tty->port.count))
38123 return -EINVAL;
38124
38125 return set_control_lines(tty, set, clear);
38126 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38127 if (!tty)
38128 return -ENODEV;
38129
38130 - if (!tty->port.count)
38131 + if (!atomic_read(&tty->port.count))
38132 return -EINVAL;
38133
38134 /* FIXME: Exactly how is the tty object locked here .. */
38135 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38136 * are gone */
38137 mutex_lock(&ttyj->ipw_tty_mutex);
38138 }
38139 - while (ttyj->port.count)
38140 + while (atomic_read(&ttyj->port.count))
38141 do_ipw_close(ttyj);
38142 ipwireless_disassociate_network_ttys(network,
38143 ttyj->channel_idx);
38144 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38145 index 324467d..504cc25 100644
38146 --- a/drivers/tty/moxa.c
38147 +++ b/drivers/tty/moxa.c
38148 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38149 }
38150
38151 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38152 - ch->port.count++;
38153 + atomic_inc(&ch->port.count);
38154 tty->driver_data = ch;
38155 tty_port_tty_set(&ch->port, tty);
38156 mutex_lock(&ch->port.mutex);
38157 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38158 index 90dff82..08119c3 100644
38159 --- a/drivers/tty/n_gsm.c
38160 +++ b/drivers/tty/n_gsm.c
38161 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38162 kref_init(&dlci->ref);
38163 mutex_init(&dlci->mutex);
38164 dlci->fifo = &dlci->_fifo;
38165 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38166 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38167 kfree(dlci);
38168 return NULL;
38169 }
38170 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38171 if (dlci == NULL)
38172 return -ENOMEM;
38173 port = &dlci->port;
38174 - port->count++;
38175 + atomic_inc(&port->count);
38176 tty->driver_data = dlci;
38177 dlci_get(dlci);
38178 dlci_get(dlci->gsm->dlci[0]);
38179 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38180 index 26f0d0e..b7c4273 100644
38181 --- a/drivers/tty/n_tty.c
38182 +++ b/drivers/tty/n_tty.c
38183 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38184 {
38185 *ops = tty_ldisc_N_TTY;
38186 ops->owner = NULL;
38187 - ops->refcount = ops->flags = 0;
38188 + atomic_set(&ops->refcount, 0);
38189 + ops->flags = 0;
38190 }
38191 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38192 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38193 index 5505ffc..7affff9 100644
38194 --- a/drivers/tty/pty.c
38195 +++ b/drivers/tty/pty.c
38196 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38197 panic("Couldn't register Unix98 pts driver");
38198
38199 /* Now create the /dev/ptmx special device */
38200 + pax_open_kernel();
38201 tty_default_fops(&ptmx_fops);
38202 - ptmx_fops.open = ptmx_open;
38203 + *(void **)&ptmx_fops.open = ptmx_open;
38204 + pax_close_kernel();
38205
38206 cdev_init(&ptmx_cdev, &ptmx_fops);
38207 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38208 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38209 index 777d5f9..56d67ca 100644
38210 --- a/drivers/tty/rocket.c
38211 +++ b/drivers/tty/rocket.c
38212 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38213 tty->driver_data = info;
38214 tty_port_tty_set(port, tty);
38215
38216 - if (port->count++ == 0) {
38217 + if (atomic_inc_return(&port->count) == 1) {
38218 atomic_inc(&rp_num_ports_open);
38219
38220 #ifdef ROCKET_DEBUG_OPEN
38221 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38222 #endif
38223 }
38224 #ifdef ROCKET_DEBUG_OPEN
38225 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38226 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38227 #endif
38228
38229 /*
38230 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38231 spin_unlock_irqrestore(&info->port.lock, flags);
38232 return;
38233 }
38234 - if (info->port.count)
38235 + if (atomic_read(&info->port.count))
38236 atomic_dec(&rp_num_ports_open);
38237 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38238 spin_unlock_irqrestore(&info->port.lock, flags);
38239 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38240 index 2b42a01..32a2ed3 100644
38241 --- a/drivers/tty/serial/kgdboc.c
38242 +++ b/drivers/tty/serial/kgdboc.c
38243 @@ -24,8 +24,9 @@
38244 #define MAX_CONFIG_LEN 40
38245
38246 static struct kgdb_io kgdboc_io_ops;
38247 +static struct kgdb_io kgdboc_io_ops_console;
38248
38249 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38250 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38251 static int configured = -1;
38252
38253 static char config[MAX_CONFIG_LEN];
38254 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38255 kgdboc_unregister_kbd();
38256 if (configured == 1)
38257 kgdb_unregister_io_module(&kgdboc_io_ops);
38258 + else if (configured == 2)
38259 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38260 }
38261
38262 static int configure_kgdboc(void)
38263 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38264 int err;
38265 char *cptr = config;
38266 struct console *cons;
38267 + int is_console = 0;
38268
38269 err = kgdboc_option_setup(config);
38270 if (err || !strlen(config) || isspace(config[0]))
38271 goto noconfig;
38272
38273 err = -ENODEV;
38274 - kgdboc_io_ops.is_console = 0;
38275 kgdb_tty_driver = NULL;
38276
38277 kgdboc_use_kms = 0;
38278 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38279 int idx;
38280 if (cons->device && cons->device(cons, &idx) == p &&
38281 idx == tty_line) {
38282 - kgdboc_io_ops.is_console = 1;
38283 + is_console = 1;
38284 break;
38285 }
38286 cons = cons->next;
38287 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38288 kgdb_tty_line = tty_line;
38289
38290 do_register:
38291 - err = kgdb_register_io_module(&kgdboc_io_ops);
38292 + if (is_console) {
38293 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38294 + configured = 2;
38295 + } else {
38296 + err = kgdb_register_io_module(&kgdboc_io_ops);
38297 + configured = 1;
38298 + }
38299 if (err)
38300 goto noconfig;
38301
38302 - configured = 1;
38303 -
38304 return 0;
38305
38306 noconfig:
38307 @@ -213,7 +220,7 @@ noconfig:
38308 static int __init init_kgdboc(void)
38309 {
38310 /* Already configured? */
38311 - if (configured == 1)
38312 + if (configured >= 1)
38313 return 0;
38314
38315 return configure_kgdboc();
38316 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38317 if (config[len - 1] == '\n')
38318 config[len - 1] = '\0';
38319
38320 - if (configured == 1)
38321 + if (configured >= 1)
38322 cleanup_kgdboc();
38323
38324 /* Go and configure with the new params. */
38325 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38326 .post_exception = kgdboc_post_exp_handler,
38327 };
38328
38329 +static struct kgdb_io kgdboc_io_ops_console = {
38330 + .name = "kgdboc",
38331 + .read_char = kgdboc_get_char,
38332 + .write_char = kgdboc_put_char,
38333 + .pre_exception = kgdboc_pre_exp_handler,
38334 + .post_exception = kgdboc_post_exp_handler,
38335 + .is_console = 1
38336 +};
38337 +
38338 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38339 /* This is only available if kgdboc is a built in for early debugging */
38340 static int __init kgdboc_early_init(char *opt)
38341 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38342 index a21dc8e..fe43e9e 100644
38343 --- a/drivers/tty/serial/serial_core.c
38344 +++ b/drivers/tty/serial/serial_core.c
38345 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38346 uart_flush_buffer(tty);
38347 uart_shutdown(tty, state);
38348 spin_lock_irqsave(&port->lock, flags);
38349 - port->count = 0;
38350 + atomic_set(&port->count, 0);
38351 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38352 spin_unlock_irqrestore(&port->lock, flags);
38353 tty_port_tty_set(port, NULL);
38354 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38355 goto end;
38356 }
38357
38358 - port->count++;
38359 + atomic_inc(&port->count);
38360 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38361 retval = -ENXIO;
38362 goto err_dec_count;
38363 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38364 /*
38365 * Make sure the device is in D0 state.
38366 */
38367 - if (port->count == 1)
38368 + if (atomic_read(&port->count) == 1)
38369 uart_change_pm(state, 0);
38370
38371 /*
38372 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38373 end:
38374 return retval;
38375 err_dec_count:
38376 - port->count--;
38377 + atomic_inc(&port->count);
38378 mutex_unlock(&port->mutex);
38379 goto end;
38380 }
38381 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38382 index 593d40a..bdc61f3 100644
38383 --- a/drivers/tty/synclink.c
38384 +++ b/drivers/tty/synclink.c
38385 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38386
38387 if (debug_level >= DEBUG_LEVEL_INFO)
38388 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38389 - __FILE__,__LINE__, info->device_name, info->port.count);
38390 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38391
38392 if (tty_port_close_start(&info->port, tty, filp) == 0)
38393 goto cleanup;
38394 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38395 cleanup:
38396 if (debug_level >= DEBUG_LEVEL_INFO)
38397 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38398 - tty->driver->name, info->port.count);
38399 + tty->driver->name, atomic_read(&info->port.count));
38400
38401 } /* end of mgsl_close() */
38402
38403 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38404
38405 mgsl_flush_buffer(tty);
38406 shutdown(info);
38407 -
38408 - info->port.count = 0;
38409 +
38410 + atomic_set(&info->port.count, 0);
38411 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38412 info->port.tty = NULL;
38413
38414 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38415
38416 if (debug_level >= DEBUG_LEVEL_INFO)
38417 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38418 - __FILE__,__LINE__, tty->driver->name, port->count );
38419 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38420
38421 spin_lock_irqsave(&info->irq_spinlock, flags);
38422 if (!tty_hung_up_p(filp)) {
38423 extra_count = true;
38424 - port->count--;
38425 + atomic_dec(&port->count);
38426 }
38427 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38428 port->blocked_open++;
38429 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38430
38431 if (debug_level >= DEBUG_LEVEL_INFO)
38432 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38433 - __FILE__,__LINE__, tty->driver->name, port->count );
38434 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38435
38436 tty_unlock();
38437 schedule();
38438 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38439
38440 /* FIXME: Racy on hangup during close wait */
38441 if (extra_count)
38442 - port->count++;
38443 + atomic_inc(&port->count);
38444 port->blocked_open--;
38445
38446 if (debug_level >= DEBUG_LEVEL_INFO)
38447 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38448 - __FILE__,__LINE__, tty->driver->name, port->count );
38449 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38450
38451 if (!retval)
38452 port->flags |= ASYNC_NORMAL_ACTIVE;
38453 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38454
38455 if (debug_level >= DEBUG_LEVEL_INFO)
38456 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38457 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38458 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38459
38460 /* If port is closing, signal caller to try again */
38461 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38462 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38463 spin_unlock_irqrestore(&info->netlock, flags);
38464 goto cleanup;
38465 }
38466 - info->port.count++;
38467 + atomic_inc(&info->port.count);
38468 spin_unlock_irqrestore(&info->netlock, flags);
38469
38470 - if (info->port.count == 1) {
38471 + if (atomic_read(&info->port.count) == 1) {
38472 /* 1st open on this device, init hardware */
38473 retval = startup(info);
38474 if (retval < 0)
38475 @@ -3444,8 +3444,8 @@ cleanup:
38476 if (retval) {
38477 if (tty->count == 1)
38478 info->port.tty = NULL; /* tty layer will release tty struct */
38479 - if(info->port.count)
38480 - info->port.count--;
38481 + if (atomic_read(&info->port.count))
38482 + atomic_dec(&info->port.count);
38483 }
38484
38485 return retval;
38486 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38487 unsigned short new_crctype;
38488
38489 /* return error if TTY interface open */
38490 - if (info->port.count)
38491 + if (atomic_read(&info->port.count))
38492 return -EBUSY;
38493
38494 switch (encoding)
38495 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38496
38497 /* arbitrate between network and tty opens */
38498 spin_lock_irqsave(&info->netlock, flags);
38499 - if (info->port.count != 0 || info->netcount != 0) {
38500 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38501 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38502 spin_unlock_irqrestore(&info->netlock, flags);
38503 return -EBUSY;
38504 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38505 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38506
38507 /* return error if TTY interface open */
38508 - if (info->port.count)
38509 + if (atomic_read(&info->port.count))
38510 return -EBUSY;
38511
38512 if (cmd != SIOCWANDEV)
38513 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38514 index aa1debf..9297a16 100644
38515 --- a/drivers/tty/synclink_gt.c
38516 +++ b/drivers/tty/synclink_gt.c
38517 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38518 tty->driver_data = info;
38519 info->port.tty = tty;
38520
38521 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38522 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38523
38524 /* If port is closing, signal caller to try again */
38525 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38526 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38527 mutex_unlock(&info->port.mutex);
38528 goto cleanup;
38529 }
38530 - info->port.count++;
38531 + atomic_inc(&info->port.count);
38532 spin_unlock_irqrestore(&info->netlock, flags);
38533
38534 - if (info->port.count == 1) {
38535 + if (atomic_read(&info->port.count) == 1) {
38536 /* 1st open on this device, init hardware */
38537 retval = startup(info);
38538 if (retval < 0) {
38539 @@ -716,8 +716,8 @@ cleanup:
38540 if (retval) {
38541 if (tty->count == 1)
38542 info->port.tty = NULL; /* tty layer will release tty struct */
38543 - if(info->port.count)
38544 - info->port.count--;
38545 + if(atomic_read(&info->port.count))
38546 + atomic_dec(&info->port.count);
38547 }
38548
38549 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38550 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38551
38552 if (sanity_check(info, tty->name, "close"))
38553 return;
38554 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38555 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38556
38557 if (tty_port_close_start(&info->port, tty, filp) == 0)
38558 goto cleanup;
38559 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38560 tty_port_close_end(&info->port, tty);
38561 info->port.tty = NULL;
38562 cleanup:
38563 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38564 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38565 }
38566
38567 static void hangup(struct tty_struct *tty)
38568 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38569 shutdown(info);
38570
38571 spin_lock_irqsave(&info->port.lock, flags);
38572 - info->port.count = 0;
38573 + atomic_set(&info->port.count, 0);
38574 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38575 info->port.tty = NULL;
38576 spin_unlock_irqrestore(&info->port.lock, flags);
38577 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38578 unsigned short new_crctype;
38579
38580 /* return error if TTY interface open */
38581 - if (info->port.count)
38582 + if (atomic_read(&info->port.count))
38583 return -EBUSY;
38584
38585 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38586 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38587
38588 /* arbitrate between network and tty opens */
38589 spin_lock_irqsave(&info->netlock, flags);
38590 - if (info->port.count != 0 || info->netcount != 0) {
38591 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38592 DBGINFO(("%s hdlc_open busy\n", dev->name));
38593 spin_unlock_irqrestore(&info->netlock, flags);
38594 return -EBUSY;
38595 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38596 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38597
38598 /* return error if TTY interface open */
38599 - if (info->port.count)
38600 + if (atomic_read(&info->port.count))
38601 return -EBUSY;
38602
38603 if (cmd != SIOCWANDEV)
38604 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38605 if (port == NULL)
38606 continue;
38607 spin_lock(&port->lock);
38608 - if ((port->port.count || port->netcount) &&
38609 + if ((atomic_read(&port->port.count) || port->netcount) &&
38610 port->pending_bh && !port->bh_running &&
38611 !port->bh_requested) {
38612 DBGISR(("%s bh queued\n", port->device_name));
38613 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38614 spin_lock_irqsave(&info->lock, flags);
38615 if (!tty_hung_up_p(filp)) {
38616 extra_count = true;
38617 - port->count--;
38618 + atomic_dec(&port->count);
38619 }
38620 spin_unlock_irqrestore(&info->lock, flags);
38621 port->blocked_open++;
38622 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38623 remove_wait_queue(&port->open_wait, &wait);
38624
38625 if (extra_count)
38626 - port->count++;
38627 + atomic_inc(&port->count);
38628 port->blocked_open--;
38629
38630 if (!retval)
38631 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38632 index a3dddc1..8905ab2 100644
38633 --- a/drivers/tty/synclinkmp.c
38634 +++ b/drivers/tty/synclinkmp.c
38635 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38636
38637 if (debug_level >= DEBUG_LEVEL_INFO)
38638 printk("%s(%d):%s open(), old ref count = %d\n",
38639 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38640 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38641
38642 /* If port is closing, signal caller to try again */
38643 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38644 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38645 spin_unlock_irqrestore(&info->netlock, flags);
38646 goto cleanup;
38647 }
38648 - info->port.count++;
38649 + atomic_inc(&info->port.count);
38650 spin_unlock_irqrestore(&info->netlock, flags);
38651
38652 - if (info->port.count == 1) {
38653 + if (atomic_read(&info->port.count) == 1) {
38654 /* 1st open on this device, init hardware */
38655 retval = startup(info);
38656 if (retval < 0)
38657 @@ -788,8 +788,8 @@ cleanup:
38658 if (retval) {
38659 if (tty->count == 1)
38660 info->port.tty = NULL; /* tty layer will release tty struct */
38661 - if(info->port.count)
38662 - info->port.count--;
38663 + if(atomic_read(&info->port.count))
38664 + atomic_dec(&info->port.count);
38665 }
38666
38667 return retval;
38668 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38669
38670 if (debug_level >= DEBUG_LEVEL_INFO)
38671 printk("%s(%d):%s close() entry, count=%d\n",
38672 - __FILE__,__LINE__, info->device_name, info->port.count);
38673 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38674
38675 if (tty_port_close_start(&info->port, tty, filp) == 0)
38676 goto cleanup;
38677 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38678 cleanup:
38679 if (debug_level >= DEBUG_LEVEL_INFO)
38680 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38681 - tty->driver->name, info->port.count);
38682 + tty->driver->name, atomic_read(&info->port.count));
38683 }
38684
38685 /* Called by tty_hangup() when a hangup is signaled.
38686 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38687 shutdown(info);
38688
38689 spin_lock_irqsave(&info->port.lock, flags);
38690 - info->port.count = 0;
38691 + atomic_set(&info->port.count, 0);
38692 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38693 info->port.tty = NULL;
38694 spin_unlock_irqrestore(&info->port.lock, flags);
38695 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38696 unsigned short new_crctype;
38697
38698 /* return error if TTY interface open */
38699 - if (info->port.count)
38700 + if (atomic_read(&info->port.count))
38701 return -EBUSY;
38702
38703 switch (encoding)
38704 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38705
38706 /* arbitrate between network and tty opens */
38707 spin_lock_irqsave(&info->netlock, flags);
38708 - if (info->port.count != 0 || info->netcount != 0) {
38709 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38710 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38711 spin_unlock_irqrestore(&info->netlock, flags);
38712 return -EBUSY;
38713 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38714 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38715
38716 /* return error if TTY interface open */
38717 - if (info->port.count)
38718 + if (atomic_read(&info->port.count))
38719 return -EBUSY;
38720
38721 if (cmd != SIOCWANDEV)
38722 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38723 * do not request bottom half processing if the
38724 * device is not open in a normal mode.
38725 */
38726 - if ( port && (port->port.count || port->netcount) &&
38727 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38728 port->pending_bh && !port->bh_running &&
38729 !port->bh_requested ) {
38730 if ( debug_level >= DEBUG_LEVEL_ISR )
38731 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38732
38733 if (debug_level >= DEBUG_LEVEL_INFO)
38734 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38735 - __FILE__,__LINE__, tty->driver->name, port->count );
38736 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38737
38738 spin_lock_irqsave(&info->lock, flags);
38739 if (!tty_hung_up_p(filp)) {
38740 extra_count = true;
38741 - port->count--;
38742 + atomic_dec(&port->count);
38743 }
38744 spin_unlock_irqrestore(&info->lock, flags);
38745 port->blocked_open++;
38746 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38747
38748 if (debug_level >= DEBUG_LEVEL_INFO)
38749 printk("%s(%d):%s block_til_ready() count=%d\n",
38750 - __FILE__,__LINE__, tty->driver->name, port->count );
38751 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38752
38753 tty_unlock();
38754 schedule();
38755 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38756 remove_wait_queue(&port->open_wait, &wait);
38757
38758 if (extra_count)
38759 - port->count++;
38760 + atomic_inc(&port->count);
38761 port->blocked_open--;
38762
38763 if (debug_level >= DEBUG_LEVEL_INFO)
38764 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38765 - __FILE__,__LINE__, tty->driver->name, port->count );
38766 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38767
38768 if (!retval)
38769 port->flags |= ASYNC_NORMAL_ACTIVE;
38770 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38771 index 05728894..b9d44c6 100644
38772 --- a/drivers/tty/sysrq.c
38773 +++ b/drivers/tty/sysrq.c
38774 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38775 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38776 size_t count, loff_t *ppos)
38777 {
38778 - if (count) {
38779 + if (count && capable(CAP_SYS_ADMIN)) {
38780 char c;
38781
38782 if (get_user(c, buf))
38783 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38784 index b425c79..08a3f06 100644
38785 --- a/drivers/tty/tty_io.c
38786 +++ b/drivers/tty/tty_io.c
38787 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38788
38789 void tty_default_fops(struct file_operations *fops)
38790 {
38791 - *fops = tty_fops;
38792 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38793 }
38794
38795 /*
38796 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38797 index 6f99c99..8947bc4 100644
38798 --- a/drivers/tty/tty_ldisc.c
38799 +++ b/drivers/tty/tty_ldisc.c
38800 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38801 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38802 struct tty_ldisc_ops *ldo = ld->ops;
38803
38804 - ldo->refcount--;
38805 + atomic_dec(&ldo->refcount);
38806 module_put(ldo->owner);
38807 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38808
38809 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38810 spin_lock_irqsave(&tty_ldisc_lock, flags);
38811 tty_ldiscs[disc] = new_ldisc;
38812 new_ldisc->num = disc;
38813 - new_ldisc->refcount = 0;
38814 + atomic_set(&new_ldisc->refcount, 0);
38815 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38816
38817 return ret;
38818 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38819 return -EINVAL;
38820
38821 spin_lock_irqsave(&tty_ldisc_lock, flags);
38822 - if (tty_ldiscs[disc]->refcount)
38823 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38824 ret = -EBUSY;
38825 else
38826 tty_ldiscs[disc] = NULL;
38827 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38828 if (ldops) {
38829 ret = ERR_PTR(-EAGAIN);
38830 if (try_module_get(ldops->owner)) {
38831 - ldops->refcount++;
38832 + atomic_inc(&ldops->refcount);
38833 ret = ldops;
38834 }
38835 }
38836 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38837 unsigned long flags;
38838
38839 spin_lock_irqsave(&tty_ldisc_lock, flags);
38840 - ldops->refcount--;
38841 + atomic_dec(&ldops->refcount);
38842 module_put(ldops->owner);
38843 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38844 }
38845 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38846 index bf6e238..d401c04 100644
38847 --- a/drivers/tty/tty_port.c
38848 +++ b/drivers/tty/tty_port.c
38849 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38850 unsigned long flags;
38851
38852 spin_lock_irqsave(&port->lock, flags);
38853 - port->count = 0;
38854 + atomic_set(&port->count, 0);
38855 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38856 if (port->tty) {
38857 set_bit(TTY_IO_ERROR, &port->tty->flags);
38858 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38859 /* The port lock protects the port counts */
38860 spin_lock_irqsave(&port->lock, flags);
38861 if (!tty_hung_up_p(filp))
38862 - port->count--;
38863 + atomic_dec(&port->count);
38864 port->blocked_open++;
38865 spin_unlock_irqrestore(&port->lock, flags);
38866
38867 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38868 we must not mess that up further */
38869 spin_lock_irqsave(&port->lock, flags);
38870 if (!tty_hung_up_p(filp))
38871 - port->count++;
38872 + atomic_inc(&port->count);
38873 port->blocked_open--;
38874 if (retval == 0)
38875 port->flags |= ASYNC_NORMAL_ACTIVE;
38876 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38877 return 0;
38878 }
38879
38880 - if (tty->count == 1 && port->count != 1) {
38881 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38882 printk(KERN_WARNING
38883 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38884 - port->count);
38885 - port->count = 1;
38886 + atomic_read(&port->count));
38887 + atomic_set(&port->count, 1);
38888 }
38889 - if (--port->count < 0) {
38890 + if (atomic_dec_return(&port->count) < 0) {
38891 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38892 - port->count);
38893 - port->count = 0;
38894 + atomic_read(&port->count));
38895 + atomic_set(&port->count, 0);
38896 }
38897
38898 - if (port->count) {
38899 + if (atomic_read(&port->count)) {
38900 spin_unlock_irqrestore(&port->lock, flags);
38901 if (port->ops->drop)
38902 port->ops->drop(port);
38903 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38904 {
38905 spin_lock_irq(&port->lock);
38906 if (!tty_hung_up_p(filp))
38907 - ++port->count;
38908 + atomic_inc(&port->count);
38909 spin_unlock_irq(&port->lock);
38910 tty_port_tty_set(port, tty);
38911
38912 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38913 index 770a854..e5d3db3 100644
38914 --- a/drivers/tty/vt/keyboard.c
38915 +++ b/drivers/tty/vt/keyboard.c
38916 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38917 kbd->kbdmode == VC_OFF) &&
38918 value != KVAL(K_SAK))
38919 return; /* SAK is allowed even in raw mode */
38920 +
38921 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38922 + {
38923 + void *func = fn_handler[value];
38924 + if (func == fn_show_state || func == fn_show_ptregs ||
38925 + func == fn_show_mem)
38926 + return;
38927 + }
38928 +#endif
38929 +
38930 fn_handler[value](vc);
38931 }
38932
38933 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38934 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38935 return -EFAULT;
38936
38937 - if (!capable(CAP_SYS_TTY_CONFIG))
38938 - perm = 0;
38939 -
38940 switch (cmd) {
38941 case KDGKBENT:
38942 /* Ensure another thread doesn't free it under us */
38943 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38944 spin_unlock_irqrestore(&kbd_event_lock, flags);
38945 return put_user(val, &user_kbe->kb_value);
38946 case KDSKBENT:
38947 + if (!capable(CAP_SYS_TTY_CONFIG))
38948 + perm = 0;
38949 +
38950 if (!perm)
38951 return -EPERM;
38952 if (!i && v == K_NOSUCHMAP) {
38953 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38954 int i, j, k;
38955 int ret;
38956
38957 - if (!capable(CAP_SYS_TTY_CONFIG))
38958 - perm = 0;
38959 -
38960 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38961 if (!kbs) {
38962 ret = -ENOMEM;
38963 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38964 kfree(kbs);
38965 return ((p && *p) ? -EOVERFLOW : 0);
38966 case KDSKBSENT:
38967 + if (!capable(CAP_SYS_TTY_CONFIG))
38968 + perm = 0;
38969 +
38970 if (!perm) {
38971 ret = -EPERM;
38972 goto reterr;
38973 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38974 index a783d53..cb30d94 100644
38975 --- a/drivers/uio/uio.c
38976 +++ b/drivers/uio/uio.c
38977 @@ -25,6 +25,7 @@
38978 #include <linux/kobject.h>
38979 #include <linux/cdev.h>
38980 #include <linux/uio_driver.h>
38981 +#include <asm/local.h>
38982
38983 #define UIO_MAX_DEVICES (1U << MINORBITS)
38984
38985 @@ -32,10 +33,10 @@ struct uio_device {
38986 struct module *owner;
38987 struct device *dev;
38988 int minor;
38989 - atomic_t event;
38990 + atomic_unchecked_t event;
38991 struct fasync_struct *async_queue;
38992 wait_queue_head_t wait;
38993 - int vma_count;
38994 + local_t vma_count;
38995 struct uio_info *info;
38996 struct kobject *map_dir;
38997 struct kobject *portio_dir;
38998 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38999 struct device_attribute *attr, char *buf)
39000 {
39001 struct uio_device *idev = dev_get_drvdata(dev);
39002 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39003 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39004 }
39005
39006 static struct device_attribute uio_class_attributes[] = {
39007 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39008 {
39009 struct uio_device *idev = info->uio_dev;
39010
39011 - atomic_inc(&idev->event);
39012 + atomic_inc_unchecked(&idev->event);
39013 wake_up_interruptible(&idev->wait);
39014 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39015 }
39016 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39017 }
39018
39019 listener->dev = idev;
39020 - listener->event_count = atomic_read(&idev->event);
39021 + listener->event_count = atomic_read_unchecked(&idev->event);
39022 filep->private_data = listener;
39023
39024 if (idev->info->open) {
39025 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39026 return -EIO;
39027
39028 poll_wait(filep, &idev->wait, wait);
39029 - if (listener->event_count != atomic_read(&idev->event))
39030 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39031 return POLLIN | POLLRDNORM;
39032 return 0;
39033 }
39034 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39035 do {
39036 set_current_state(TASK_INTERRUPTIBLE);
39037
39038 - event_count = atomic_read(&idev->event);
39039 + event_count = atomic_read_unchecked(&idev->event);
39040 if (event_count != listener->event_count) {
39041 if (copy_to_user(buf, &event_count, count))
39042 retval = -EFAULT;
39043 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39044 static void uio_vma_open(struct vm_area_struct *vma)
39045 {
39046 struct uio_device *idev = vma->vm_private_data;
39047 - idev->vma_count++;
39048 + local_inc(&idev->vma_count);
39049 }
39050
39051 static void uio_vma_close(struct vm_area_struct *vma)
39052 {
39053 struct uio_device *idev = vma->vm_private_data;
39054 - idev->vma_count--;
39055 + local_dec(&idev->vma_count);
39056 }
39057
39058 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39059 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39060 idev->owner = owner;
39061 idev->info = info;
39062 init_waitqueue_head(&idev->wait);
39063 - atomic_set(&idev->event, 0);
39064 + atomic_set_unchecked(&idev->event, 0);
39065
39066 ret = uio_get_minor(idev);
39067 if (ret)
39068 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39069 index b7eb86a..36d28af 100644
39070 --- a/drivers/usb/atm/cxacru.c
39071 +++ b/drivers/usb/atm/cxacru.c
39072 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39073 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39074 if (ret < 2)
39075 return -EINVAL;
39076 - if (index < 0 || index > 0x7f)
39077 + if (index > 0x7f)
39078 return -EINVAL;
39079 pos += tmp;
39080
39081 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39082 index ee62b35..b663594 100644
39083 --- a/drivers/usb/atm/usbatm.c
39084 +++ b/drivers/usb/atm/usbatm.c
39085 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39086 if (printk_ratelimit())
39087 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39088 __func__, vpi, vci);
39089 - atomic_inc(&vcc->stats->rx_err);
39090 + atomic_inc_unchecked(&vcc->stats->rx_err);
39091 return;
39092 }
39093
39094 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39095 if (length > ATM_MAX_AAL5_PDU) {
39096 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39097 __func__, length, vcc);
39098 - atomic_inc(&vcc->stats->rx_err);
39099 + atomic_inc_unchecked(&vcc->stats->rx_err);
39100 goto out;
39101 }
39102
39103 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39104 if (sarb->len < pdu_length) {
39105 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39106 __func__, pdu_length, sarb->len, vcc);
39107 - atomic_inc(&vcc->stats->rx_err);
39108 + atomic_inc_unchecked(&vcc->stats->rx_err);
39109 goto out;
39110 }
39111
39112 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39113 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39114 __func__, vcc);
39115 - atomic_inc(&vcc->stats->rx_err);
39116 + atomic_inc_unchecked(&vcc->stats->rx_err);
39117 goto out;
39118 }
39119
39120 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39121 if (printk_ratelimit())
39122 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39123 __func__, length);
39124 - atomic_inc(&vcc->stats->rx_drop);
39125 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39126 goto out;
39127 }
39128
39129 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39130
39131 vcc->push(vcc, skb);
39132
39133 - atomic_inc(&vcc->stats->rx);
39134 + atomic_inc_unchecked(&vcc->stats->rx);
39135 out:
39136 skb_trim(sarb, 0);
39137 }
39138 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39139 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39140
39141 usbatm_pop(vcc, skb);
39142 - atomic_inc(&vcc->stats->tx);
39143 + atomic_inc_unchecked(&vcc->stats->tx);
39144
39145 skb = skb_dequeue(&instance->sndqueue);
39146 }
39147 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39148 if (!left--)
39149 return sprintf(page,
39150 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39151 - atomic_read(&atm_dev->stats.aal5.tx),
39152 - atomic_read(&atm_dev->stats.aal5.tx_err),
39153 - atomic_read(&atm_dev->stats.aal5.rx),
39154 - atomic_read(&atm_dev->stats.aal5.rx_err),
39155 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39156 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39157 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39158 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39159 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39160 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39161
39162 if (!left--) {
39163 if (instance->disconnected)
39164 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39165 index 3440812..2a4ef1f 100644
39166 --- a/drivers/usb/core/devices.c
39167 +++ b/drivers/usb/core/devices.c
39168 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39169 * time it gets called.
39170 */
39171 static struct device_connect_event {
39172 - atomic_t count;
39173 + atomic_unchecked_t count;
39174 wait_queue_head_t wait;
39175 } device_event = {
39176 .count = ATOMIC_INIT(1),
39177 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39178
39179 void usbfs_conn_disc_event(void)
39180 {
39181 - atomic_add(2, &device_event.count);
39182 + atomic_add_unchecked(2, &device_event.count);
39183 wake_up(&device_event.wait);
39184 }
39185
39186 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39187
39188 poll_wait(file, &device_event.wait, wait);
39189
39190 - event_count = atomic_read(&device_event.count);
39191 + event_count = atomic_read_unchecked(&device_event.count);
39192 if (file->f_version != event_count) {
39193 file->f_version = event_count;
39194 return POLLIN | POLLRDNORM;
39195 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39196 index 89dcf15..481800b 100644
39197 --- a/drivers/usb/early/ehci-dbgp.c
39198 +++ b/drivers/usb/early/ehci-dbgp.c
39199 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39200
39201 #ifdef CONFIG_KGDB
39202 static struct kgdb_io kgdbdbgp_io_ops;
39203 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39204 +static struct kgdb_io kgdbdbgp_io_ops_console;
39205 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39206 #else
39207 #define dbgp_kgdb_mode (0)
39208 #endif
39209 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39210 .write_char = kgdbdbgp_write_char,
39211 };
39212
39213 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39214 + .name = "kgdbdbgp",
39215 + .read_char = kgdbdbgp_read_char,
39216 + .write_char = kgdbdbgp_write_char,
39217 + .is_console = 1
39218 +};
39219 +
39220 static int kgdbdbgp_wait_time;
39221
39222 static int __init kgdbdbgp_parse_config(char *str)
39223 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39224 ptr++;
39225 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39226 }
39227 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39228 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39229 + if (early_dbgp_console.index != -1)
39230 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39231 + else
39232 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39233
39234 return 0;
39235 }
39236 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39237 index da6d479..80ed10b 100644
39238 --- a/drivers/usb/gadget/u_serial.c
39239 +++ b/drivers/usb/gadget/u_serial.c
39240 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39241 spin_lock_irq(&port->port_lock);
39242
39243 /* already open? Great. */
39244 - if (port->port.count) {
39245 + if (atomic_read(&port->port.count)) {
39246 status = 0;
39247 - port->port.count++;
39248 + atomic_inc(&port->port.count);
39249
39250 /* currently opening/closing? wait ... */
39251 } else if (port->openclose) {
39252 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39253 tty->driver_data = port;
39254 port->port.tty = tty;
39255
39256 - port->port.count = 1;
39257 + atomic_set(&port->port.count, 1);
39258 port->openclose = false;
39259
39260 /* if connected, start the I/O stream */
39261 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39262
39263 spin_lock_irq(&port->port_lock);
39264
39265 - if (port->port.count != 1) {
39266 - if (port->port.count == 0)
39267 + if (atomic_read(&port->port.count) != 1) {
39268 + if (atomic_read(&port->port.count) == 0)
39269 WARN_ON(1);
39270 else
39271 - --port->port.count;
39272 + atomic_dec(&port->port.count);
39273 goto exit;
39274 }
39275
39276 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39277 * and sleep if necessary
39278 */
39279 port->openclose = true;
39280 - port->port.count = 0;
39281 + atomic_set(&port->port.count, 0);
39282
39283 gser = port->port_usb;
39284 if (gser && gser->disconnect)
39285 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39286 int cond;
39287
39288 spin_lock_irq(&port->port_lock);
39289 - cond = (port->port.count == 0) && !port->openclose;
39290 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39291 spin_unlock_irq(&port->port_lock);
39292 return cond;
39293 }
39294 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39295 /* if it's already open, start I/O ... and notify the serial
39296 * protocol about open/close status (connect/disconnect).
39297 */
39298 - if (port->port.count) {
39299 + if (atomic_read(&port->port.count)) {
39300 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39301 gs_start_io(port);
39302 if (gser->connect)
39303 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39304
39305 port->port_usb = NULL;
39306 gser->ioport = NULL;
39307 - if (port->port.count > 0 || port->openclose) {
39308 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39309 wake_up_interruptible(&port->drain_wait);
39310 if (port->port.tty)
39311 tty_hangup(port->port.tty);
39312 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39313
39314 /* finally, free any unused/unusable I/O buffers */
39315 spin_lock_irqsave(&port->port_lock, flags);
39316 - if (port->port.count == 0 && !port->openclose)
39317 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39318 gs_buf_free(&port->port_write_buf);
39319 gs_free_requests(gser->out, &port->read_pool, NULL);
39320 gs_free_requests(gser->out, &port->read_queue, NULL);
39321 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39322 index b9cca6d..75c75df 100644
39323 --- a/drivers/usb/serial/console.c
39324 +++ b/drivers/usb/serial/console.c
39325 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39326
39327 info->port = port;
39328
39329 - ++port->port.count;
39330 + atomic_inc(&port->port.count);
39331 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39332 if (serial->type->set_termios) {
39333 /*
39334 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39335 }
39336 /* Now that any required fake tty operations are completed restore
39337 * the tty port count */
39338 - --port->port.count;
39339 + atomic_dec(&port->port.count);
39340 /* The console is special in terms of closing the device so
39341 * indicate this port is now acting as a system console. */
39342 port->port.console = 1;
39343 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39344 free_tty:
39345 kfree(tty);
39346 reset_open_count:
39347 - port->port.count = 0;
39348 + atomic_set(&port->port.count, 0);
39349 usb_autopm_put_interface(serial->interface);
39350 error_get_interface:
39351 usb_serial_put(serial);
39352 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39353 index d6bea3e..60b250e 100644
39354 --- a/drivers/usb/wusbcore/wa-hc.h
39355 +++ b/drivers/usb/wusbcore/wa-hc.h
39356 @@ -192,7 +192,7 @@ struct wahc {
39357 struct list_head xfer_delayed_list;
39358 spinlock_t xfer_list_lock;
39359 struct work_struct xfer_work;
39360 - atomic_t xfer_id_count;
39361 + atomic_unchecked_t xfer_id_count;
39362 };
39363
39364
39365 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39366 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39367 spin_lock_init(&wa->xfer_list_lock);
39368 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39369 - atomic_set(&wa->xfer_id_count, 1);
39370 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39371 }
39372
39373 /**
39374 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39375 index 57c01ab..8a05959 100644
39376 --- a/drivers/usb/wusbcore/wa-xfer.c
39377 +++ b/drivers/usb/wusbcore/wa-xfer.c
39378 @@ -296,7 +296,7 @@ out:
39379 */
39380 static void wa_xfer_id_init(struct wa_xfer *xfer)
39381 {
39382 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39383 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39384 }
39385
39386 /*
39387 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39388 index ef82a0d..da8a0b3 100644
39389 --- a/drivers/vhost/vhost.c
39390 +++ b/drivers/vhost/vhost.c
39391 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39392 return 0;
39393 }
39394
39395 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39396 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39397 {
39398 struct file *eventfp, *filep = NULL,
39399 *pollstart = NULL, *pollstop = NULL;
39400 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39401 index 747442d..7c0c434 100644
39402 --- a/drivers/video/aty/aty128fb.c
39403 +++ b/drivers/video/aty/aty128fb.c
39404 @@ -149,7 +149,7 @@ enum {
39405 };
39406
39407 /* Must match above enum */
39408 -static const char *r128_family[] __devinitdata = {
39409 +static const char *r128_family[] __devinitconst = {
39410 "AGP",
39411 "PCI",
39412 "PRO AGP",
39413 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39414 index 5c3960d..15cf8fc 100644
39415 --- a/drivers/video/fbcmap.c
39416 +++ b/drivers/video/fbcmap.c
39417 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39418 rc = -ENODEV;
39419 goto out;
39420 }
39421 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39422 - !info->fbops->fb_setcmap)) {
39423 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39424 rc = -EINVAL;
39425 goto out1;
39426 }
39427 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39428 index 0dff12a..2ef47b3 100644
39429 --- a/drivers/video/fbmem.c
39430 +++ b/drivers/video/fbmem.c
39431 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39432 image->dx += image->width + 8;
39433 }
39434 } else if (rotate == FB_ROTATE_UD) {
39435 - for (x = 0; x < num && image->dx >= 0; x++) {
39436 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39437 info->fbops->fb_imageblit(info, image);
39438 image->dx -= image->width + 8;
39439 }
39440 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39441 image->dy += image->height + 8;
39442 }
39443 } else if (rotate == FB_ROTATE_CCW) {
39444 - for (x = 0; x < num && image->dy >= 0; x++) {
39445 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39446 info->fbops->fb_imageblit(info, image);
39447 image->dy -= image->height + 8;
39448 }
39449 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39450 return -EFAULT;
39451 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39452 return -EINVAL;
39453 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39454 + if (con2fb.framebuffer >= FB_MAX)
39455 return -EINVAL;
39456 if (!registered_fb[con2fb.framebuffer])
39457 request_module("fb%d", con2fb.framebuffer);
39458 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39459 index 5a5d092..265c5ed 100644
39460 --- a/drivers/video/geode/gx1fb_core.c
39461 +++ b/drivers/video/geode/gx1fb_core.c
39462 @@ -29,7 +29,7 @@ static int crt_option = 1;
39463 static char panel_option[32] = "";
39464
39465 /* Modes relevant to the GX1 (taken from modedb.c) */
39466 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39467 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39468 /* 640x480-60 VESA */
39469 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39470 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39471 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39472 index 0fad23f..0e9afa4 100644
39473 --- a/drivers/video/gxt4500.c
39474 +++ b/drivers/video/gxt4500.c
39475 @@ -156,7 +156,7 @@ struct gxt4500_par {
39476 static char *mode_option;
39477
39478 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39479 -static const struct fb_videomode defaultmode __devinitdata = {
39480 +static const struct fb_videomode defaultmode __devinitconst = {
39481 .refresh = 60,
39482 .xres = 1280,
39483 .yres = 1024,
39484 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39485 return 0;
39486 }
39487
39488 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39489 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39490 .id = "IBM GXT4500P",
39491 .type = FB_TYPE_PACKED_PIXELS,
39492 .visual = FB_VISUAL_PSEUDOCOLOR,
39493 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39494 index 7672d2e..b56437f 100644
39495 --- a/drivers/video/i810/i810_accel.c
39496 +++ b/drivers/video/i810/i810_accel.c
39497 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39498 }
39499 }
39500 printk("ringbuffer lockup!!!\n");
39501 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39502 i810_report_error(mmio);
39503 par->dev_flags |= LOCKUP;
39504 info->pixmap.scan_align = 1;
39505 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39506 index b83f361..2b05a91 100644
39507 --- a/drivers/video/i810/i810_main.c
39508 +++ b/drivers/video/i810/i810_main.c
39509 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39510 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39511
39512 /* PCI */
39513 -static const char *i810_pci_list[] __devinitdata = {
39514 +static const char *i810_pci_list[] __devinitconst = {
39515 "Intel(R) 810 Framebuffer Device" ,
39516 "Intel(R) 810-DC100 Framebuffer Device" ,
39517 "Intel(R) 810E Framebuffer Device" ,
39518 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39519 index de36693..3c63fc2 100644
39520 --- a/drivers/video/jz4740_fb.c
39521 +++ b/drivers/video/jz4740_fb.c
39522 @@ -136,7 +136,7 @@ struct jzfb {
39523 uint32_t pseudo_palette[16];
39524 };
39525
39526 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39527 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39528 .id = "JZ4740 FB",
39529 .type = FB_TYPE_PACKED_PIXELS,
39530 .visual = FB_VISUAL_TRUECOLOR,
39531 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39532 index 3c14e43..eafa544 100644
39533 --- a/drivers/video/logo/logo_linux_clut224.ppm
39534 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39535 @@ -1,1604 +1,1123 @@
39536 P3
39537 -# Standard 224-color Linux logo
39538 80 80
39539 255
39540 - 0 0 0 0 0 0 0 0 0 0 0 0
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 6 6 6 10 10 10 10 10 10
39550 - 10 10 10 6 6 6 6 6 6 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
39569 - 22 22 22 26 26 26 30 30 30 34 34 34
39570 - 30 30 30 30 30 30 26 26 26 18 18 18
39571 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0 0 0 0 0
39588 - 6 6 6 14 14 14 26 26 26 42 42 42
39589 - 54 54 54 66 66 66 78 78 78 78 78 78
39590 - 78 78 78 74 74 74 66 66 66 54 54 54
39591 - 42 42 42 26 26 26 18 18 18 10 10 10
39592 - 6 6 6 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 0 0 0 0 0 0
39595 - 0 0 0 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 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 1 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 0 0 0 0 0 0 0 10 10 10
39608 - 22 22 22 42 42 42 66 66 66 86 86 86
39609 - 66 66 66 38 38 38 38 38 38 22 22 22
39610 - 26 26 26 34 34 34 54 54 54 66 66 66
39611 - 86 86 86 70 70 70 46 46 46 26 26 26
39612 - 14 14 14 6 6 6 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 0 0 0 0 0 0
39615 - 0 0 0 0 0 0 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 10 10 10 26 26 26
39628 - 50 50 50 82 82 82 58 58 58 6 6 6
39629 - 2 2 6 2 2 6 2 2 6 2 2 6
39630 - 2 2 6 2 2 6 2 2 6 2 2 6
39631 - 6 6 6 54 54 54 86 86 86 66 66 66
39632 - 38 38 38 18 18 18 6 6 6 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
39648 - 78 78 78 34 34 34 2 2 6 2 2 6
39649 - 2 2 6 2 2 6 2 2 6 2 2 6
39650 - 2 2 6 2 2 6 2 2 6 2 2 6
39651 - 2 2 6 2 2 6 6 6 6 70 70 70
39652 - 78 78 78 46 46 46 22 22 22 6 6 6
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
39668 - 26 26 26 2 2 6 2 2 6 2 2 6
39669 - 2 2 6 2 2 6 2 2 6 2 2 6
39670 - 2 2 6 2 2 6 2 2 6 14 14 14
39671 - 46 46 46 34 34 34 6 6 6 2 2 6
39672 - 42 42 42 78 78 78 42 42 42 18 18 18
39673 - 6 6 6 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 0 0 0 0 0 0 0
39675 - 0 0 0 0 0 0 0 0 0 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 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 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
39688 - 2 2 6 2 2 6 2 2 6 2 2 6
39689 - 2 2 6 2 2 6 2 2 6 2 2 6
39690 - 2 2 6 2 2 6 2 2 6 26 26 26
39691 - 86 86 86 101 101 101 46 46 46 10 10 10
39692 - 2 2 6 58 58 58 70 70 70 34 34 34
39693 - 10 10 10 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 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 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
39708 - 2 2 6 2 2 6 2 2 6 2 2 6
39709 - 2 2 6 2 2 6 2 2 6 2 2 6
39710 - 2 2 6 2 2 6 2 2 6 30 30 30
39711 - 94 94 94 94 94 94 58 58 58 26 26 26
39712 - 2 2 6 6 6 6 78 78 78 54 54 54
39713 - 22 22 22 6 6 6 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 0 0 0
39715 - 0 0 0 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 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 6 6 6
39727 - 22 22 22 62 62 62 62 62 62 2 2 6
39728 - 2 2 6 2 2 6 2 2 6 2 2 6
39729 - 2 2 6 2 2 6 2 2 6 2 2 6
39730 - 2 2 6 2 2 6 2 2 6 26 26 26
39731 - 54 54 54 38 38 38 18 18 18 10 10 10
39732 - 2 2 6 2 2 6 34 34 34 82 82 82
39733 - 38 38 38 14 14 14 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 1 0 0 1 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 6 6 6
39747 - 30 30 30 78 78 78 30 30 30 2 2 6
39748 - 2 2 6 2 2 6 2 2 6 2 2 6
39749 - 2 2 6 2 2 6 2 2 6 2 2 6
39750 - 2 2 6 2 2 6 2 2 6 10 10 10
39751 - 10 10 10 2 2 6 2 2 6 2 2 6
39752 - 2 2 6 2 2 6 2 2 6 78 78 78
39753 - 50 50 50 18 18 18 6 6 6 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 1 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 10 10 10
39767 - 38 38 38 86 86 86 14 14 14 2 2 6
39768 - 2 2 6 2 2 6 2 2 6 2 2 6
39769 - 2 2 6 2 2 6 2 2 6 2 2 6
39770 - 2 2 6 2 2 6 2 2 6 2 2 6
39771 - 2 2 6 2 2 6 2 2 6 2 2 6
39772 - 2 2 6 2 2 6 2 2 6 54 54 54
39773 - 66 66 66 26 26 26 6 6 6 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 1 0 0 1 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 14 14 14
39787 - 42 42 42 82 82 82 2 2 6 2 2 6
39788 - 2 2 6 6 6 6 10 10 10 2 2 6
39789 - 2 2 6 2 2 6 2 2 6 2 2 6
39790 - 2 2 6 2 2 6 2 2 6 6 6 6
39791 - 14 14 14 10 10 10 2 2 6 2 2 6
39792 - 2 2 6 2 2 6 2 2 6 18 18 18
39793 - 82 82 82 34 34 34 10 10 10 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 1 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 14 14 14
39807 - 46 46 46 86 86 86 2 2 6 2 2 6
39808 - 6 6 6 6 6 6 22 22 22 34 34 34
39809 - 6 6 6 2 2 6 2 2 6 2 2 6
39810 - 2 2 6 2 2 6 18 18 18 34 34 34
39811 - 10 10 10 50 50 50 22 22 22 2 2 6
39812 - 2 2 6 2 2 6 2 2 6 10 10 10
39813 - 86 86 86 42 42 42 14 14 14 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39827 - 46 46 46 86 86 86 2 2 6 2 2 6
39828 - 38 38 38 116 116 116 94 94 94 22 22 22
39829 - 22 22 22 2 2 6 2 2 6 2 2 6
39830 - 14 14 14 86 86 86 138 138 138 162 162 162
39831 -154 154 154 38 38 38 26 26 26 6 6 6
39832 - 2 2 6 2 2 6 2 2 6 2 2 6
39833 - 86 86 86 46 46 46 14 14 14 0 0 0
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 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 14 14 14
39847 - 46 46 46 86 86 86 2 2 6 14 14 14
39848 -134 134 134 198 198 198 195 195 195 116 116 116
39849 - 10 10 10 2 2 6 2 2 6 6 6 6
39850 -101 98 89 187 187 187 210 210 210 218 218 218
39851 -214 214 214 134 134 134 14 14 14 6 6 6
39852 - 2 2 6 2 2 6 2 2 6 2 2 6
39853 - 86 86 86 50 50 50 18 18 18 6 6 6
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 1 0 0 0
39861 - 0 0 1 0 0 1 0 0 1 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 14 14 14
39867 - 46 46 46 86 86 86 2 2 6 54 54 54
39868 -218 218 218 195 195 195 226 226 226 246 246 246
39869 - 58 58 58 2 2 6 2 2 6 30 30 30
39870 -210 210 210 253 253 253 174 174 174 123 123 123
39871 -221 221 221 234 234 234 74 74 74 2 2 6
39872 - 2 2 6 2 2 6 2 2 6 2 2 6
39873 - 70 70 70 58 58 58 22 22 22 6 6 6
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 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 14 14 14
39887 - 46 46 46 82 82 82 2 2 6 106 106 106
39888 -170 170 170 26 26 26 86 86 86 226 226 226
39889 -123 123 123 10 10 10 14 14 14 46 46 46
39890 -231 231 231 190 190 190 6 6 6 70 70 70
39891 - 90 90 90 238 238 238 158 158 158 2 2 6
39892 - 2 2 6 2 2 6 2 2 6 2 2 6
39893 - 70 70 70 58 58 58 22 22 22 6 6 6
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 0 0 0
39900 - 0 0 0 0 0 0 0 0 1 0 0 0
39901 - 0 0 1 0 0 1 0 0 1 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 14 14 14
39907 - 42 42 42 86 86 86 6 6 6 116 116 116
39908 -106 106 106 6 6 6 70 70 70 149 149 149
39909 -128 128 128 18 18 18 38 38 38 54 54 54
39910 -221 221 221 106 106 106 2 2 6 14 14 14
39911 - 46 46 46 190 190 190 198 198 198 2 2 6
39912 - 2 2 6 2 2 6 2 2 6 2 2 6
39913 - 74 74 74 62 62 62 22 22 22 6 6 6
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 1 0 0 0
39921 - 0 0 1 0 0 0 0 0 1 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 14 14 14
39927 - 42 42 42 94 94 94 14 14 14 101 101 101
39928 -128 128 128 2 2 6 18 18 18 116 116 116
39929 -118 98 46 121 92 8 121 92 8 98 78 10
39930 -162 162 162 106 106 106 2 2 6 2 2 6
39931 - 2 2 6 195 195 195 195 195 195 6 6 6
39932 - 2 2 6 2 2 6 2 2 6 2 2 6
39933 - 74 74 74 62 62 62 22 22 22 6 6 6
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 0 0 0
39940 - 0 0 0 0 0 0 0 0 1 0 0 1
39941 - 0 0 1 0 0 0 0 0 1 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 10 10 10
39947 - 38 38 38 90 90 90 14 14 14 58 58 58
39948 -210 210 210 26 26 26 54 38 6 154 114 10
39949 -226 170 11 236 186 11 225 175 15 184 144 12
39950 -215 174 15 175 146 61 37 26 9 2 2 6
39951 - 70 70 70 246 246 246 138 138 138 2 2 6
39952 - 2 2 6 2 2 6 2 2 6 2 2 6
39953 - 70 70 70 66 66 66 26 26 26 6 6 6
39954 - 0 0 0 0 0 0 0 0 0 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39967 - 38 38 38 86 86 86 14 14 14 10 10 10
39968 -195 195 195 188 164 115 192 133 9 225 175 15
39969 -239 182 13 234 190 10 232 195 16 232 200 30
39970 -245 207 45 241 208 19 232 195 16 184 144 12
39971 -218 194 134 211 206 186 42 42 42 2 2 6
39972 - 2 2 6 2 2 6 2 2 6 2 2 6
39973 - 50 50 50 74 74 74 30 30 30 6 6 6
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 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 10 10 10
39987 - 34 34 34 86 86 86 14 14 14 2 2 6
39988 -121 87 25 192 133 9 219 162 10 239 182 13
39989 -236 186 11 232 195 16 241 208 19 244 214 54
39990 -246 218 60 246 218 38 246 215 20 241 208 19
39991 -241 208 19 226 184 13 121 87 25 2 2 6
39992 - 2 2 6 2 2 6 2 2 6 2 2 6
39993 - 50 50 50 82 82 82 34 34 34 10 10 10
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 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 10 10 10
40007 - 34 34 34 82 82 82 30 30 30 61 42 6
40008 -180 123 7 206 145 10 230 174 11 239 182 13
40009 -234 190 10 238 202 15 241 208 19 246 218 74
40010 -246 218 38 246 215 20 246 215 20 246 215 20
40011 -226 184 13 215 174 15 184 144 12 6 6 6
40012 - 2 2 6 2 2 6 2 2 6 2 2 6
40013 - 26 26 26 94 94 94 42 42 42 14 14 14
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40027 - 30 30 30 78 78 78 50 50 50 104 69 6
40028 -192 133 9 216 158 10 236 178 12 236 186 11
40029 -232 195 16 241 208 19 244 214 54 245 215 43
40030 -246 215 20 246 215 20 241 208 19 198 155 10
40031 -200 144 11 216 158 10 156 118 10 2 2 6
40032 - 2 2 6 2 2 6 2 2 6 2 2 6
40033 - 6 6 6 90 90 90 54 54 54 18 18 18
40034 - 6 6 6 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40047 - 30 30 30 78 78 78 46 46 46 22 22 22
40048 -137 92 6 210 162 10 239 182 13 238 190 10
40049 -238 202 15 241 208 19 246 215 20 246 215 20
40050 -241 208 19 203 166 17 185 133 11 210 150 10
40051 -216 158 10 210 150 10 102 78 10 2 2 6
40052 - 6 6 6 54 54 54 14 14 14 2 2 6
40053 - 2 2 6 62 62 62 74 74 74 30 30 30
40054 - 10 10 10 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40067 - 34 34 34 78 78 78 50 50 50 6 6 6
40068 - 94 70 30 139 102 15 190 146 13 226 184 13
40069 -232 200 30 232 195 16 215 174 15 190 146 13
40070 -168 122 10 192 133 9 210 150 10 213 154 11
40071 -202 150 34 182 157 106 101 98 89 2 2 6
40072 - 2 2 6 78 78 78 116 116 116 58 58 58
40073 - 2 2 6 22 22 22 90 90 90 46 46 46
40074 - 18 18 18 6 6 6 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 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 10 10 10
40087 - 38 38 38 86 86 86 50 50 50 6 6 6
40088 -128 128 128 174 154 114 156 107 11 168 122 10
40089 -198 155 10 184 144 12 197 138 11 200 144 11
40090 -206 145 10 206 145 10 197 138 11 188 164 115
40091 -195 195 195 198 198 198 174 174 174 14 14 14
40092 - 2 2 6 22 22 22 116 116 116 116 116 116
40093 - 22 22 22 2 2 6 74 74 74 70 70 70
40094 - 30 30 30 10 10 10 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
40107 - 50 50 50 101 101 101 26 26 26 10 10 10
40108 -138 138 138 190 190 190 174 154 114 156 107 11
40109 -197 138 11 200 144 11 197 138 11 192 133 9
40110 -180 123 7 190 142 34 190 178 144 187 187 187
40111 -202 202 202 221 221 221 214 214 214 66 66 66
40112 - 2 2 6 2 2 6 50 50 50 62 62 62
40113 - 6 6 6 2 2 6 10 10 10 90 90 90
40114 - 50 50 50 18 18 18 6 6 6 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
40127 - 74 74 74 74 74 74 2 2 6 6 6 6
40128 -144 144 144 198 198 198 190 190 190 178 166 146
40129 -154 121 60 156 107 11 156 107 11 168 124 44
40130 -174 154 114 187 187 187 190 190 190 210 210 210
40131 -246 246 246 253 253 253 253 253 253 182 182 182
40132 - 6 6 6 2 2 6 2 2 6 2 2 6
40133 - 2 2 6 2 2 6 2 2 6 62 62 62
40134 - 74 74 74 34 34 34 14 14 14 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
40147 - 94 94 94 18 18 18 2 2 6 46 46 46
40148 -234 234 234 221 221 221 190 190 190 190 190 190
40149 -190 190 190 187 187 187 187 187 187 190 190 190
40150 -190 190 190 195 195 195 214 214 214 242 242 242
40151 -253 253 253 253 253 253 253 253 253 253 253 253
40152 - 82 82 82 2 2 6 2 2 6 2 2 6
40153 - 2 2 6 2 2 6 2 2 6 14 14 14
40154 - 86 86 86 54 54 54 22 22 22 6 6 6
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
40167 - 46 46 46 18 18 18 6 6 6 182 182 182
40168 -253 253 253 246 246 246 206 206 206 190 190 190
40169 -190 190 190 190 190 190 190 190 190 190 190 190
40170 -206 206 206 231 231 231 250 250 250 253 253 253
40171 -253 253 253 253 253 253 253 253 253 253 253 253
40172 -202 202 202 14 14 14 2 2 6 2 2 6
40173 - 2 2 6 2 2 6 2 2 6 2 2 6
40174 - 42 42 42 86 86 86 42 42 42 18 18 18
40175 - 6 6 6 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 6 6 6
40186 - 14 14 14 38 38 38 74 74 74 66 66 66
40187 - 2 2 6 6 6 6 90 90 90 250 250 250
40188 -253 253 253 253 253 253 238 238 238 198 198 198
40189 -190 190 190 190 190 190 195 195 195 221 221 221
40190 -246 246 246 253 253 253 253 253 253 253 253 253
40191 -253 253 253 253 253 253 253 253 253 253 253 253
40192 -253 253 253 82 82 82 2 2 6 2 2 6
40193 - 2 2 6 2 2 6 2 2 6 2 2 6
40194 - 2 2 6 78 78 78 70 70 70 34 34 34
40195 - 14 14 14 6 6 6 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 14 14 14
40206 - 34 34 34 66 66 66 78 78 78 6 6 6
40207 - 2 2 6 18 18 18 218 218 218 253 253 253
40208 -253 253 253 253 253 253 253 253 253 246 246 246
40209 -226 226 226 231 231 231 246 246 246 253 253 253
40210 -253 253 253 253 253 253 253 253 253 253 253 253
40211 -253 253 253 253 253 253 253 253 253 253 253 253
40212 -253 253 253 178 178 178 2 2 6 2 2 6
40213 - 2 2 6 2 2 6 2 2 6 2 2 6
40214 - 2 2 6 18 18 18 90 90 90 62 62 62
40215 - 30 30 30 10 10 10 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 10 10 10 26 26 26
40226 - 58 58 58 90 90 90 18 18 18 2 2 6
40227 - 2 2 6 110 110 110 253 253 253 253 253 253
40228 -253 253 253 253 253 253 253 253 253 253 253 253
40229 -250 250 250 253 253 253 253 253 253 253 253 253
40230 -253 253 253 253 253 253 253 253 253 253 253 253
40231 -253 253 253 253 253 253 253 253 253 253 253 253
40232 -253 253 253 231 231 231 18 18 18 2 2 6
40233 - 2 2 6 2 2 6 2 2 6 2 2 6
40234 - 2 2 6 2 2 6 18 18 18 94 94 94
40235 - 54 54 54 26 26 26 10 10 10 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 6 6 6 22 22 22 50 50 50
40246 - 90 90 90 26 26 26 2 2 6 2 2 6
40247 - 14 14 14 195 195 195 250 250 250 253 253 253
40248 -253 253 253 253 253 253 253 253 253 253 253 253
40249 -253 253 253 253 253 253 253 253 253 253 253 253
40250 -253 253 253 253 253 253 253 253 253 253 253 253
40251 -253 253 253 253 253 253 253 253 253 253 253 253
40252 -250 250 250 242 242 242 54 54 54 2 2 6
40253 - 2 2 6 2 2 6 2 2 6 2 2 6
40254 - 2 2 6 2 2 6 2 2 6 38 38 38
40255 - 86 86 86 50 50 50 22 22 22 6 6 6
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 6 6 6 14 14 14 38 38 38 82 82 82
40266 - 34 34 34 2 2 6 2 2 6 2 2 6
40267 - 42 42 42 195 195 195 246 246 246 253 253 253
40268 -253 253 253 253 253 253 253 253 253 250 250 250
40269 -242 242 242 242 242 242 250 250 250 253 253 253
40270 -253 253 253 253 253 253 253 253 253 253 253 253
40271 -253 253 253 250 250 250 246 246 246 238 238 238
40272 -226 226 226 231 231 231 101 101 101 6 6 6
40273 - 2 2 6 2 2 6 2 2 6 2 2 6
40274 - 2 2 6 2 2 6 2 2 6 2 2 6
40275 - 38 38 38 82 82 82 42 42 42 14 14 14
40276 - 6 6 6 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 10 10 10 26 26 26 62 62 62 66 66 66
40286 - 2 2 6 2 2 6 2 2 6 6 6 6
40287 - 70 70 70 170 170 170 206 206 206 234 234 234
40288 -246 246 246 250 250 250 250 250 250 238 238 238
40289 -226 226 226 231 231 231 238 238 238 250 250 250
40290 -250 250 250 250 250 250 246 246 246 231 231 231
40291 -214 214 214 206 206 206 202 202 202 202 202 202
40292 -198 198 198 202 202 202 182 182 182 18 18 18
40293 - 2 2 6 2 2 6 2 2 6 2 2 6
40294 - 2 2 6 2 2 6 2 2 6 2 2 6
40295 - 2 2 6 62 62 62 66 66 66 30 30 30
40296 - 10 10 10 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 14 14 14 42 42 42 82 82 82 18 18 18
40306 - 2 2 6 2 2 6 2 2 6 10 10 10
40307 - 94 94 94 182 182 182 218 218 218 242 242 242
40308 -250 250 250 253 253 253 253 253 253 250 250 250
40309 -234 234 234 253 253 253 253 253 253 253 253 253
40310 -253 253 253 253 253 253 253 253 253 246 246 246
40311 -238 238 238 226 226 226 210 210 210 202 202 202
40312 -195 195 195 195 195 195 210 210 210 158 158 158
40313 - 6 6 6 14 14 14 50 50 50 14 14 14
40314 - 2 2 6 2 2 6 2 2 6 2 2 6
40315 - 2 2 6 6 6 6 86 86 86 46 46 46
40316 - 18 18 18 6 6 6 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 6 6 6
40325 - 22 22 22 54 54 54 70 70 70 2 2 6
40326 - 2 2 6 10 10 10 2 2 6 22 22 22
40327 -166 166 166 231 231 231 250 250 250 253 253 253
40328 -253 253 253 253 253 253 253 253 253 250 250 250
40329 -242 242 242 253 253 253 253 253 253 253 253 253
40330 -253 253 253 253 253 253 253 253 253 253 253 253
40331 -253 253 253 253 253 253 253 253 253 246 246 246
40332 -231 231 231 206 206 206 198 198 198 226 226 226
40333 - 94 94 94 2 2 6 6 6 6 38 38 38
40334 - 30 30 30 2 2 6 2 2 6 2 2 6
40335 - 2 2 6 2 2 6 62 62 62 66 66 66
40336 - 26 26 26 10 10 10 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 10 10 10
40345 - 30 30 30 74 74 74 50 50 50 2 2 6
40346 - 26 26 26 26 26 26 2 2 6 106 106 106
40347 -238 238 238 253 253 253 253 253 253 253 253 253
40348 -253 253 253 253 253 253 253 253 253 253 253 253
40349 -253 253 253 253 253 253 253 253 253 253 253 253
40350 -253 253 253 253 253 253 253 253 253 253 253 253
40351 -253 253 253 253 253 253 253 253 253 253 253 253
40352 -253 253 253 246 246 246 218 218 218 202 202 202
40353 -210 210 210 14 14 14 2 2 6 2 2 6
40354 - 30 30 30 22 22 22 2 2 6 2 2 6
40355 - 2 2 6 2 2 6 18 18 18 86 86 86
40356 - 42 42 42 14 14 14 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 14 14 14
40365 - 42 42 42 90 90 90 22 22 22 2 2 6
40366 - 42 42 42 2 2 6 18 18 18 218 218 218
40367 -253 253 253 253 253 253 253 253 253 253 253 253
40368 -253 253 253 253 253 253 253 253 253 253 253 253
40369 -253 253 253 253 253 253 253 253 253 253 253 253
40370 -253 253 253 253 253 253 253 253 253 253 253 253
40371 -253 253 253 253 253 253 253 253 253 253 253 253
40372 -253 253 253 253 253 253 250 250 250 221 221 221
40373 -218 218 218 101 101 101 2 2 6 14 14 14
40374 - 18 18 18 38 38 38 10 10 10 2 2 6
40375 - 2 2 6 2 2 6 2 2 6 78 78 78
40376 - 58 58 58 22 22 22 6 6 6 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 6 6 6 18 18 18
40385 - 54 54 54 82 82 82 2 2 6 26 26 26
40386 - 22 22 22 2 2 6 123 123 123 253 253 253
40387 -253 253 253 253 253 253 253 253 253 253 253 253
40388 -253 253 253 253 253 253 253 253 253 253 253 253
40389 -253 253 253 253 253 253 253 253 253 253 253 253
40390 -253 253 253 253 253 253 253 253 253 253 253 253
40391 -253 253 253 253 253 253 253 253 253 253 253 253
40392 -253 253 253 253 253 253 253 253 253 250 250 250
40393 -238 238 238 198 198 198 6 6 6 38 38 38
40394 - 58 58 58 26 26 26 38 38 38 2 2 6
40395 - 2 2 6 2 2 6 2 2 6 46 46 46
40396 - 78 78 78 30 30 30 10 10 10 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 10 10 10 30 30 30
40405 - 74 74 74 58 58 58 2 2 6 42 42 42
40406 - 2 2 6 22 22 22 231 231 231 253 253 253
40407 -253 253 253 253 253 253 253 253 253 253 253 253
40408 -253 253 253 253 253 253 253 253 253 250 250 250
40409 -253 253 253 253 253 253 253 253 253 253 253 253
40410 -253 253 253 253 253 253 253 253 253 253 253 253
40411 -253 253 253 253 253 253 253 253 253 253 253 253
40412 -253 253 253 253 253 253 253 253 253 253 253 253
40413 -253 253 253 246 246 246 46 46 46 38 38 38
40414 - 42 42 42 14 14 14 38 38 38 14 14 14
40415 - 2 2 6 2 2 6 2 2 6 6 6 6
40416 - 86 86 86 46 46 46 14 14 14 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 6 6 6 14 14 14 42 42 42
40425 - 90 90 90 18 18 18 18 18 18 26 26 26
40426 - 2 2 6 116 116 116 253 253 253 253 253 253
40427 -253 253 253 253 253 253 253 253 253 253 253 253
40428 -253 253 253 253 253 253 250 250 250 238 238 238
40429 -253 253 253 253 253 253 253 253 253 253 253 253
40430 -253 253 253 253 253 253 253 253 253 253 253 253
40431 -253 253 253 253 253 253 253 253 253 253 253 253
40432 -253 253 253 253 253 253 253 253 253 253 253 253
40433 -253 253 253 253 253 253 94 94 94 6 6 6
40434 - 2 2 6 2 2 6 10 10 10 34 34 34
40435 - 2 2 6 2 2 6 2 2 6 2 2 6
40436 - 74 74 74 58 58 58 22 22 22 6 6 6
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 0 0 0 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 10 10 10 26 26 26 66 66 66
40445 - 82 82 82 2 2 6 38 38 38 6 6 6
40446 - 14 14 14 210 210 210 253 253 253 253 253 253
40447 -253 253 253 253 253 253 253 253 253 253 253 253
40448 -253 253 253 253 253 253 246 246 246 242 242 242
40449 -253 253 253 253 253 253 253 253 253 253 253 253
40450 -253 253 253 253 253 253 253 253 253 253 253 253
40451 -253 253 253 253 253 253 253 253 253 253 253 253
40452 -253 253 253 253 253 253 253 253 253 253 253 253
40453 -253 253 253 253 253 253 144 144 144 2 2 6
40454 - 2 2 6 2 2 6 2 2 6 46 46 46
40455 - 2 2 6 2 2 6 2 2 6 2 2 6
40456 - 42 42 42 74 74 74 30 30 30 10 10 10
40457 - 0 0 0 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 0 0 0
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 6 6 6 14 14 14 42 42 42 90 90 90
40465 - 26 26 26 6 6 6 42 42 42 2 2 6
40466 - 74 74 74 250 250 250 253 253 253 253 253 253
40467 -253 253 253 253 253 253 253 253 253 253 253 253
40468 -253 253 253 253 253 253 242 242 242 242 242 242
40469 -253 253 253 253 253 253 253 253 253 253 253 253
40470 -253 253 253 253 253 253 253 253 253 253 253 253
40471 -253 253 253 253 253 253 253 253 253 253 253 253
40472 -253 253 253 253 253 253 253 253 253 253 253 253
40473 -253 253 253 253 253 253 182 182 182 2 2 6
40474 - 2 2 6 2 2 6 2 2 6 46 46 46
40475 - 2 2 6 2 2 6 2 2 6 2 2 6
40476 - 10 10 10 86 86 86 38 38 38 10 10 10
40477 - 0 0 0 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 0 0 0
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 10 10 10 26 26 26 66 66 66 82 82 82
40485 - 2 2 6 22 22 22 18 18 18 2 2 6
40486 -149 149 149 253 253 253 253 253 253 253 253 253
40487 -253 253 253 253 253 253 253 253 253 253 253 253
40488 -253 253 253 253 253 253 234 234 234 242 242 242
40489 -253 253 253 253 253 253 253 253 253 253 253 253
40490 -253 253 253 253 253 253 253 253 253 253 253 253
40491 -253 253 253 253 253 253 253 253 253 253 253 253
40492 -253 253 253 253 253 253 253 253 253 253 253 253
40493 -253 253 253 253 253 253 206 206 206 2 2 6
40494 - 2 2 6 2 2 6 2 2 6 38 38 38
40495 - 2 2 6 2 2 6 2 2 6 2 2 6
40496 - 6 6 6 86 86 86 46 46 46 14 14 14
40497 - 0 0 0 0 0 0 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 6 6 6
40504 - 18 18 18 46 46 46 86 86 86 18 18 18
40505 - 2 2 6 34 34 34 10 10 10 6 6 6
40506 -210 210 210 253 253 253 253 253 253 253 253 253
40507 -253 253 253 253 253 253 253 253 253 253 253 253
40508 -253 253 253 253 253 253 234 234 234 242 242 242
40509 -253 253 253 253 253 253 253 253 253 253 253 253
40510 -253 253 253 253 253 253 253 253 253 253 253 253
40511 -253 253 253 253 253 253 253 253 253 253 253 253
40512 -253 253 253 253 253 253 253 253 253 253 253 253
40513 -253 253 253 253 253 253 221 221 221 6 6 6
40514 - 2 2 6 2 2 6 6 6 6 30 30 30
40515 - 2 2 6 2 2 6 2 2 6 2 2 6
40516 - 2 2 6 82 82 82 54 54 54 18 18 18
40517 - 6 6 6 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 0 0 0
40523 - 0 0 0 0 0 0 0 0 0 10 10 10
40524 - 26 26 26 66 66 66 62 62 62 2 2 6
40525 - 2 2 6 38 38 38 10 10 10 26 26 26
40526 -238 238 238 253 253 253 253 253 253 253 253 253
40527 -253 253 253 253 253 253 253 253 253 253 253 253
40528 -253 253 253 253 253 253 231 231 231 238 238 238
40529 -253 253 253 253 253 253 253 253 253 253 253 253
40530 -253 253 253 253 253 253 253 253 253 253 253 253
40531 -253 253 253 253 253 253 253 253 253 253 253 253
40532 -253 253 253 253 253 253 253 253 253 253 253 253
40533 -253 253 253 253 253 253 231 231 231 6 6 6
40534 - 2 2 6 2 2 6 10 10 10 30 30 30
40535 - 2 2 6 2 2 6 2 2 6 2 2 6
40536 - 2 2 6 66 66 66 58 58 58 22 22 22
40537 - 6 6 6 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 0 0 0 0 0 0
40543 - 0 0 0 0 0 0 0 0 0 10 10 10
40544 - 38 38 38 78 78 78 6 6 6 2 2 6
40545 - 2 2 6 46 46 46 14 14 14 42 42 42
40546 -246 246 246 253 253 253 253 253 253 253 253 253
40547 -253 253 253 253 253 253 253 253 253 253 253 253
40548 -253 253 253 253 253 253 231 231 231 242 242 242
40549 -253 253 253 253 253 253 253 253 253 253 253 253
40550 -253 253 253 253 253 253 253 253 253 253 253 253
40551 -253 253 253 253 253 253 253 253 253 253 253 253
40552 -253 253 253 253 253 253 253 253 253 253 253 253
40553 -253 253 253 253 253 253 234 234 234 10 10 10
40554 - 2 2 6 2 2 6 22 22 22 14 14 14
40555 - 2 2 6 2 2 6 2 2 6 2 2 6
40556 - 2 2 6 66 66 66 62 62 62 22 22 22
40557 - 6 6 6 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 0 0 0 0 0 0 0 0 0
40563 - 0 0 0 0 0 0 6 6 6 18 18 18
40564 - 50 50 50 74 74 74 2 2 6 2 2 6
40565 - 14 14 14 70 70 70 34 34 34 62 62 62
40566 -250 250 250 253 253 253 253 253 253 253 253 253
40567 -253 253 253 253 253 253 253 253 253 253 253 253
40568 -253 253 253 253 253 253 231 231 231 246 246 246
40569 -253 253 253 253 253 253 253 253 253 253 253 253
40570 -253 253 253 253 253 253 253 253 253 253 253 253
40571 -253 253 253 253 253 253 253 253 253 253 253 253
40572 -253 253 253 253 253 253 253 253 253 253 253 253
40573 -253 253 253 253 253 253 234 234 234 14 14 14
40574 - 2 2 6 2 2 6 30 30 30 2 2 6
40575 - 2 2 6 2 2 6 2 2 6 2 2 6
40576 - 2 2 6 66 66 66 62 62 62 22 22 22
40577 - 6 6 6 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 - 0 0 0 0 0 0 0 0 0 0 0 0
40583 - 0 0 0 0 0 0 6 6 6 18 18 18
40584 - 54 54 54 62 62 62 2 2 6 2 2 6
40585 - 2 2 6 30 30 30 46 46 46 70 70 70
40586 -250 250 250 253 253 253 253 253 253 253 253 253
40587 -253 253 253 253 253 253 253 253 253 253 253 253
40588 -253 253 253 253 253 253 231 231 231 246 246 246
40589 -253 253 253 253 253 253 253 253 253 253 253 253
40590 -253 253 253 253 253 253 253 253 253 253 253 253
40591 -253 253 253 253 253 253 253 253 253 253 253 253
40592 -253 253 253 253 253 253 253 253 253 253 253 253
40593 -253 253 253 253 253 253 226 226 226 10 10 10
40594 - 2 2 6 6 6 6 30 30 30 2 2 6
40595 - 2 2 6 2 2 6 2 2 6 2 2 6
40596 - 2 2 6 66 66 66 58 58 58 22 22 22
40597 - 6 6 6 0 0 0 0 0 0 0 0 0
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 0 0 0 0 0 0 0 0 0 0 0 0
40602 - 0 0 0 0 0 0 0 0 0 0 0 0
40603 - 0 0 0 0 0 0 6 6 6 22 22 22
40604 - 58 58 58 62 62 62 2 2 6 2 2 6
40605 - 2 2 6 2 2 6 30 30 30 78 78 78
40606 -250 250 250 253 253 253 253 253 253 253 253 253
40607 -253 253 253 253 253 253 253 253 253 253 253 253
40608 -253 253 253 253 253 253 231 231 231 246 246 246
40609 -253 253 253 253 253 253 253 253 253 253 253 253
40610 -253 253 253 253 253 253 253 253 253 253 253 253
40611 -253 253 253 253 253 253 253 253 253 253 253 253
40612 -253 253 253 253 253 253 253 253 253 253 253 253
40613 -253 253 253 253 253 253 206 206 206 2 2 6
40614 - 22 22 22 34 34 34 18 14 6 22 22 22
40615 - 26 26 26 18 18 18 6 6 6 2 2 6
40616 - 2 2 6 82 82 82 54 54 54 18 18 18
40617 - 6 6 6 0 0 0 0 0 0 0 0 0
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 0 0 0 0 0 0 0 0 0 0 0 0
40622 - 0 0 0 0 0 0 0 0 0 0 0 0
40623 - 0 0 0 0 0 0 6 6 6 26 26 26
40624 - 62 62 62 106 106 106 74 54 14 185 133 11
40625 -210 162 10 121 92 8 6 6 6 62 62 62
40626 -238 238 238 253 253 253 253 253 253 253 253 253
40627 -253 253 253 253 253 253 253 253 253 253 253 253
40628 -253 253 253 253 253 253 231 231 231 246 246 246
40629 -253 253 253 253 253 253 253 253 253 253 253 253
40630 -253 253 253 253 253 253 253 253 253 253 253 253
40631 -253 253 253 253 253 253 253 253 253 253 253 253
40632 -253 253 253 253 253 253 253 253 253 253 253 253
40633 -253 253 253 253 253 253 158 158 158 18 18 18
40634 - 14 14 14 2 2 6 2 2 6 2 2 6
40635 - 6 6 6 18 18 18 66 66 66 38 38 38
40636 - 6 6 6 94 94 94 50 50 50 18 18 18
40637 - 6 6 6 0 0 0 0 0 0 0 0 0
40638 - 0 0 0 0 0 0 0 0 0 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 0 0 0 0 0 0 0 0 0
40642 - 0 0 0 0 0 0 0 0 0 6 6 6
40643 - 10 10 10 10 10 10 18 18 18 38 38 38
40644 - 78 78 78 142 134 106 216 158 10 242 186 14
40645 -246 190 14 246 190 14 156 118 10 10 10 10
40646 - 90 90 90 238 238 238 253 253 253 253 253 253
40647 -253 253 253 253 253 253 253 253 253 253 253 253
40648 -253 253 253 253 253 253 231 231 231 250 250 250
40649 -253 253 253 253 253 253 253 253 253 253 253 253
40650 -253 253 253 253 253 253 253 253 253 253 253 253
40651 -253 253 253 253 253 253 253 253 253 253 253 253
40652 -253 253 253 253 253 253 253 253 253 246 230 190
40653 -238 204 91 238 204 91 181 142 44 37 26 9
40654 - 2 2 6 2 2 6 2 2 6 2 2 6
40655 - 2 2 6 2 2 6 38 38 38 46 46 46
40656 - 26 26 26 106 106 106 54 54 54 18 18 18
40657 - 6 6 6 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 0 0 0
40662 - 0 0 0 6 6 6 14 14 14 22 22 22
40663 - 30 30 30 38 38 38 50 50 50 70 70 70
40664 -106 106 106 190 142 34 226 170 11 242 186 14
40665 -246 190 14 246 190 14 246 190 14 154 114 10
40666 - 6 6 6 74 74 74 226 226 226 253 253 253
40667 -253 253 253 253 253 253 253 253 253 253 253 253
40668 -253 253 253 253 253 253 231 231 231 250 250 250
40669 -253 253 253 253 253 253 253 253 253 253 253 253
40670 -253 253 253 253 253 253 253 253 253 253 253 253
40671 -253 253 253 253 253 253 253 253 253 253 253 253
40672 -253 253 253 253 253 253 253 253 253 228 184 62
40673 -241 196 14 241 208 19 232 195 16 38 30 10
40674 - 2 2 6 2 2 6 2 2 6 2 2 6
40675 - 2 2 6 6 6 6 30 30 30 26 26 26
40676 -203 166 17 154 142 90 66 66 66 26 26 26
40677 - 6 6 6 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 0 0 0 0 0 0 0 0 0
40681 - 0 0 0 0 0 0 0 0 0 0 0 0
40682 - 6 6 6 18 18 18 38 38 38 58 58 58
40683 - 78 78 78 86 86 86 101 101 101 123 123 123
40684 -175 146 61 210 150 10 234 174 13 246 186 14
40685 -246 190 14 246 190 14 246 190 14 238 190 10
40686 -102 78 10 2 2 6 46 46 46 198 198 198
40687 -253 253 253 253 253 253 253 253 253 253 253 253
40688 -253 253 253 253 253 253 234 234 234 242 242 242
40689 -253 253 253 253 253 253 253 253 253 253 253 253
40690 -253 253 253 253 253 253 253 253 253 253 253 253
40691 -253 253 253 253 253 253 253 253 253 253 253 253
40692 -253 253 253 253 253 253 253 253 253 224 178 62
40693 -242 186 14 241 196 14 210 166 10 22 18 6
40694 - 2 2 6 2 2 6 2 2 6 2 2 6
40695 - 2 2 6 2 2 6 6 6 6 121 92 8
40696 -238 202 15 232 195 16 82 82 82 34 34 34
40697 - 10 10 10 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 0 0 0
40701 - 0 0 0 0 0 0 0 0 0 0 0 0
40702 - 14 14 14 38 38 38 70 70 70 154 122 46
40703 -190 142 34 200 144 11 197 138 11 197 138 11
40704 -213 154 11 226 170 11 242 186 14 246 190 14
40705 -246 190 14 246 190 14 246 190 14 246 190 14
40706 -225 175 15 46 32 6 2 2 6 22 22 22
40707 -158 158 158 250 250 250 253 253 253 253 253 253
40708 -253 253 253 253 253 253 253 253 253 253 253 253
40709 -253 253 253 253 253 253 253 253 253 253 253 253
40710 -253 253 253 253 253 253 253 253 253 253 253 253
40711 -253 253 253 253 253 253 253 253 253 253 253 253
40712 -253 253 253 250 250 250 242 242 242 224 178 62
40713 -239 182 13 236 186 11 213 154 11 46 32 6
40714 - 2 2 6 2 2 6 2 2 6 2 2 6
40715 - 2 2 6 2 2 6 61 42 6 225 175 15
40716 -238 190 10 236 186 11 112 100 78 42 42 42
40717 - 14 14 14 0 0 0 0 0 0 0 0 0
40718 - 0 0 0 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 0 0 0 0 0 0
40721 - 0 0 0 0 0 0 0 0 0 6 6 6
40722 - 22 22 22 54 54 54 154 122 46 213 154 11
40723 -226 170 11 230 174 11 226 170 11 226 170 11
40724 -236 178 12 242 186 14 246 190 14 246 190 14
40725 -246 190 14 246 190 14 246 190 14 246 190 14
40726 -241 196 14 184 144 12 10 10 10 2 2 6
40727 - 6 6 6 116 116 116 242 242 242 253 253 253
40728 -253 253 253 253 253 253 253 253 253 253 253 253
40729 -253 253 253 253 253 253 253 253 253 253 253 253
40730 -253 253 253 253 253 253 253 253 253 253 253 253
40731 -253 253 253 253 253 253 253 253 253 253 253 253
40732 -253 253 253 231 231 231 198 198 198 214 170 54
40733 -236 178 12 236 178 12 210 150 10 137 92 6
40734 - 18 14 6 2 2 6 2 2 6 2 2 6
40735 - 6 6 6 70 47 6 200 144 11 236 178 12
40736 -239 182 13 239 182 13 124 112 88 58 58 58
40737 - 22 22 22 6 6 6 0 0 0 0 0 0
40738 - 0 0 0 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 0 0 0 0 0 0 10 10 10
40742 - 30 30 30 70 70 70 180 133 36 226 170 11
40743 -239 182 13 242 186 14 242 186 14 246 186 14
40744 -246 190 14 246 190 14 246 190 14 246 190 14
40745 -246 190 14 246 190 14 246 190 14 246 190 14
40746 -246 190 14 232 195 16 98 70 6 2 2 6
40747 - 2 2 6 2 2 6 66 66 66 221 221 221
40748 -253 253 253 253 253 253 253 253 253 253 253 253
40749 -253 253 253 253 253 253 253 253 253 253 253 253
40750 -253 253 253 253 253 253 253 253 253 253 253 253
40751 -253 253 253 253 253 253 253 253 253 253 253 253
40752 -253 253 253 206 206 206 198 198 198 214 166 58
40753 -230 174 11 230 174 11 216 158 10 192 133 9
40754 -163 110 8 116 81 8 102 78 10 116 81 8
40755 -167 114 7 197 138 11 226 170 11 239 182 13
40756 -242 186 14 242 186 14 162 146 94 78 78 78
40757 - 34 34 34 14 14 14 6 6 6 0 0 0
40758 - 0 0 0 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 0 0 0
40761 - 0 0 0 0 0 0 0 0 0 6 6 6
40762 - 30 30 30 78 78 78 190 142 34 226 170 11
40763 -239 182 13 246 190 14 246 190 14 246 190 14
40764 -246 190 14 246 190 14 246 190 14 246 190 14
40765 -246 190 14 246 190 14 246 190 14 246 190 14
40766 -246 190 14 241 196 14 203 166 17 22 18 6
40767 - 2 2 6 2 2 6 2 2 6 38 38 38
40768 -218 218 218 253 253 253 253 253 253 253 253 253
40769 -253 253 253 253 253 253 253 253 253 253 253 253
40770 -253 253 253 253 253 253 253 253 253 253 253 253
40771 -253 253 253 253 253 253 253 253 253 253 253 253
40772 -250 250 250 206 206 206 198 198 198 202 162 69
40773 -226 170 11 236 178 12 224 166 10 210 150 10
40774 -200 144 11 197 138 11 192 133 9 197 138 11
40775 -210 150 10 226 170 11 242 186 14 246 190 14
40776 -246 190 14 246 186 14 225 175 15 124 112 88
40777 - 62 62 62 30 30 30 14 14 14 6 6 6
40778 - 0 0 0 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 0 0 0 10 10 10
40782 - 30 30 30 78 78 78 174 135 50 224 166 10
40783 -239 182 13 246 190 14 246 190 14 246 190 14
40784 -246 190 14 246 190 14 246 190 14 246 190 14
40785 -246 190 14 246 190 14 246 190 14 246 190 14
40786 -246 190 14 246 190 14 241 196 14 139 102 15
40787 - 2 2 6 2 2 6 2 2 6 2 2 6
40788 - 78 78 78 250 250 250 253 253 253 253 253 253
40789 -253 253 253 253 253 253 253 253 253 253 253 253
40790 -253 253 253 253 253 253 253 253 253 253 253 253
40791 -253 253 253 253 253 253 253 253 253 253 253 253
40792 -250 250 250 214 214 214 198 198 198 190 150 46
40793 -219 162 10 236 178 12 234 174 13 224 166 10
40794 -216 158 10 213 154 11 213 154 11 216 158 10
40795 -226 170 11 239 182 13 246 190 14 246 190 14
40796 -246 190 14 246 190 14 242 186 14 206 162 42
40797 -101 101 101 58 58 58 30 30 30 14 14 14
40798 - 6 6 6 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 0 0 0
40801 - 0 0 0 0 0 0 0 0 0 10 10 10
40802 - 30 30 30 74 74 74 174 135 50 216 158 10
40803 -236 178 12 246 190 14 246 190 14 246 190 14
40804 -246 190 14 246 190 14 246 190 14 246 190 14
40805 -246 190 14 246 190 14 246 190 14 246 190 14
40806 -246 190 14 246 190 14 241 196 14 226 184 13
40807 - 61 42 6 2 2 6 2 2 6 2 2 6
40808 - 22 22 22 238 238 238 253 253 253 253 253 253
40809 -253 253 253 253 253 253 253 253 253 253 253 253
40810 -253 253 253 253 253 253 253 253 253 253 253 253
40811 -253 253 253 253 253 253 253 253 253 253 253 253
40812 -253 253 253 226 226 226 187 187 187 180 133 36
40813 -216 158 10 236 178 12 239 182 13 236 178 12
40814 -230 174 11 226 170 11 226 170 11 230 174 11
40815 -236 178 12 242 186 14 246 190 14 246 190 14
40816 -246 190 14 246 190 14 246 186 14 239 182 13
40817 -206 162 42 106 106 106 66 66 66 34 34 34
40818 - 14 14 14 6 6 6 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 0 0 0 0 0 0 0 0 0 0 0 0
40821 - 0 0 0 0 0 0 0 0 0 6 6 6
40822 - 26 26 26 70 70 70 163 133 67 213 154 11
40823 -236 178 12 246 190 14 246 190 14 246 190 14
40824 -246 190 14 246 190 14 246 190 14 246 190 14
40825 -246 190 14 246 190 14 246 190 14 246 190 14
40826 -246 190 14 246 190 14 246 190 14 241 196 14
40827 -190 146 13 18 14 6 2 2 6 2 2 6
40828 - 46 46 46 246 246 246 253 253 253 253 253 253
40829 -253 253 253 253 253 253 253 253 253 253 253 253
40830 -253 253 253 253 253 253 253 253 253 253 253 253
40831 -253 253 253 253 253 253 253 253 253 253 253 253
40832 -253 253 253 221 221 221 86 86 86 156 107 11
40833 -216 158 10 236 178 12 242 186 14 246 186 14
40834 -242 186 14 239 182 13 239 182 13 242 186 14
40835 -242 186 14 246 186 14 246 190 14 246 190 14
40836 -246 190 14 246 190 14 246 190 14 246 190 14
40837 -242 186 14 225 175 15 142 122 72 66 66 66
40838 - 30 30 30 10 10 10 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 0 0 0
40840 - 0 0 0 0 0 0 0 0 0 0 0 0
40841 - 0 0 0 0 0 0 0 0 0 6 6 6
40842 - 26 26 26 70 70 70 163 133 67 210 150 10
40843 -236 178 12 246 190 14 246 190 14 246 190 14
40844 -246 190 14 246 190 14 246 190 14 246 190 14
40845 -246 190 14 246 190 14 246 190 14 246 190 14
40846 -246 190 14 246 190 14 246 190 14 246 190 14
40847 -232 195 16 121 92 8 34 34 34 106 106 106
40848 -221 221 221 253 253 253 253 253 253 253 253 253
40849 -253 253 253 253 253 253 253 253 253 253 253 253
40850 -253 253 253 253 253 253 253 253 253 253 253 253
40851 -253 253 253 253 253 253 253 253 253 253 253 253
40852 -242 242 242 82 82 82 18 14 6 163 110 8
40853 -216 158 10 236 178 12 242 186 14 246 190 14
40854 -246 190 14 246 190 14 246 190 14 246 190 14
40855 -246 190 14 246 190 14 246 190 14 246 190 14
40856 -246 190 14 246 190 14 246 190 14 246 190 14
40857 -246 190 14 246 190 14 242 186 14 163 133 67
40858 - 46 46 46 18 18 18 6 6 6 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 0 0 0
40860 - 0 0 0 0 0 0 0 0 0 0 0 0
40861 - 0 0 0 0 0 0 0 0 0 10 10 10
40862 - 30 30 30 78 78 78 163 133 67 210 150 10
40863 -236 178 12 246 186 14 246 190 14 246 190 14
40864 -246 190 14 246 190 14 246 190 14 246 190 14
40865 -246 190 14 246 190 14 246 190 14 246 190 14
40866 -246 190 14 246 190 14 246 190 14 246 190 14
40867 -241 196 14 215 174 15 190 178 144 253 253 253
40868 -253 253 253 253 253 253 253 253 253 253 253 253
40869 -253 253 253 253 253 253 253 253 253 253 253 253
40870 -253 253 253 253 253 253 253 253 253 253 253 253
40871 -253 253 253 253 253 253 253 253 253 218 218 218
40872 - 58 58 58 2 2 6 22 18 6 167 114 7
40873 -216 158 10 236 178 12 246 186 14 246 190 14
40874 -246 190 14 246 190 14 246 190 14 246 190 14
40875 -246 190 14 246 190 14 246 190 14 246 190 14
40876 -246 190 14 246 190 14 246 190 14 246 190 14
40877 -246 190 14 246 186 14 242 186 14 190 150 46
40878 - 54 54 54 22 22 22 6 6 6 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 0 0 0
40880 - 0 0 0 0 0 0 0 0 0 0 0 0
40881 - 0 0 0 0 0 0 0 0 0 14 14 14
40882 - 38 38 38 86 86 86 180 133 36 213 154 11
40883 -236 178 12 246 186 14 246 190 14 246 190 14
40884 -246 190 14 246 190 14 246 190 14 246 190 14
40885 -246 190 14 246 190 14 246 190 14 246 190 14
40886 -246 190 14 246 190 14 246 190 14 246 190 14
40887 -246 190 14 232 195 16 190 146 13 214 214 214
40888 -253 253 253 253 253 253 253 253 253 253 253 253
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -253 253 253 253 253 253 253 253 253 253 253 253
40891 -253 253 253 250 250 250 170 170 170 26 26 26
40892 - 2 2 6 2 2 6 37 26 9 163 110 8
40893 -219 162 10 239 182 13 246 186 14 246 190 14
40894 -246 190 14 246 190 14 246 190 14 246 190 14
40895 -246 190 14 246 190 14 246 190 14 246 190 14
40896 -246 190 14 246 190 14 246 190 14 246 190 14
40897 -246 186 14 236 178 12 224 166 10 142 122 72
40898 - 46 46 46 18 18 18 6 6 6 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 0 0 0
40900 - 0 0 0 0 0 0 0 0 0 0 0 0
40901 - 0 0 0 0 0 0 6 6 6 18 18 18
40902 - 50 50 50 109 106 95 192 133 9 224 166 10
40903 -242 186 14 246 190 14 246 190 14 246 190 14
40904 -246 190 14 246 190 14 246 190 14 246 190 14
40905 -246 190 14 246 190 14 246 190 14 246 190 14
40906 -246 190 14 246 190 14 246 190 14 246 190 14
40907 -242 186 14 226 184 13 210 162 10 142 110 46
40908 -226 226 226 253 253 253 253 253 253 253 253 253
40909 -253 253 253 253 253 253 253 253 253 253 253 253
40910 -253 253 253 253 253 253 253 253 253 253 253 253
40911 -198 198 198 66 66 66 2 2 6 2 2 6
40912 - 2 2 6 2 2 6 50 34 6 156 107 11
40913 -219 162 10 239 182 13 246 186 14 246 190 14
40914 -246 190 14 246 190 14 246 190 14 246 190 14
40915 -246 190 14 246 190 14 246 190 14 246 190 14
40916 -246 190 14 246 190 14 246 190 14 242 186 14
40917 -234 174 13 213 154 11 154 122 46 66 66 66
40918 - 30 30 30 10 10 10 0 0 0 0 0 0
40919 - 0 0 0 0 0 0 0 0 0 0 0 0
40920 - 0 0 0 0 0 0 0 0 0 0 0 0
40921 - 0 0 0 0 0 0 6 6 6 22 22 22
40922 - 58 58 58 154 121 60 206 145 10 234 174 13
40923 -242 186 14 246 186 14 246 190 14 246 190 14
40924 -246 190 14 246 190 14 246 190 14 246 190 14
40925 -246 190 14 246 190 14 246 190 14 246 190 14
40926 -246 190 14 246 190 14 246 190 14 246 190 14
40927 -246 186 14 236 178 12 210 162 10 163 110 8
40928 - 61 42 6 138 138 138 218 218 218 250 250 250
40929 -253 253 253 253 253 253 253 253 253 250 250 250
40930 -242 242 242 210 210 210 144 144 144 66 66 66
40931 - 6 6 6 2 2 6 2 2 6 2 2 6
40932 - 2 2 6 2 2 6 61 42 6 163 110 8
40933 -216 158 10 236 178 12 246 190 14 246 190 14
40934 -246 190 14 246 190 14 246 190 14 246 190 14
40935 -246 190 14 246 190 14 246 190 14 246 190 14
40936 -246 190 14 239 182 13 230 174 11 216 158 10
40937 -190 142 34 124 112 88 70 70 70 38 38 38
40938 - 18 18 18 6 6 6 0 0 0 0 0 0
40939 - 0 0 0 0 0 0 0 0 0 0 0 0
40940 - 0 0 0 0 0 0 0 0 0 0 0 0
40941 - 0 0 0 0 0 0 6 6 6 22 22 22
40942 - 62 62 62 168 124 44 206 145 10 224 166 10
40943 -236 178 12 239 182 13 242 186 14 242 186 14
40944 -246 186 14 246 190 14 246 190 14 246 190 14
40945 -246 190 14 246 190 14 246 190 14 246 190 14
40946 -246 190 14 246 190 14 246 190 14 246 190 14
40947 -246 190 14 236 178 12 216 158 10 175 118 6
40948 - 80 54 7 2 2 6 6 6 6 30 30 30
40949 - 54 54 54 62 62 62 50 50 50 38 38 38
40950 - 14 14 14 2 2 6 2 2 6 2 2 6
40951 - 2 2 6 2 2 6 2 2 6 2 2 6
40952 - 2 2 6 6 6 6 80 54 7 167 114 7
40953 -213 154 11 236 178 12 246 190 14 246 190 14
40954 -246 190 14 246 190 14 246 190 14 246 190 14
40955 -246 190 14 242 186 14 239 182 13 239 182 13
40956 -230 174 11 210 150 10 174 135 50 124 112 88
40957 - 82 82 82 54 54 54 34 34 34 18 18 18
40958 - 6 6 6 0 0 0 0 0 0 0 0 0
40959 - 0 0 0 0 0 0 0 0 0 0 0 0
40960 - 0 0 0 0 0 0 0 0 0 0 0 0
40961 - 0 0 0 0 0 0 6 6 6 18 18 18
40962 - 50 50 50 158 118 36 192 133 9 200 144 11
40963 -216 158 10 219 162 10 224 166 10 226 170 11
40964 -230 174 11 236 178 12 239 182 13 239 182 13
40965 -242 186 14 246 186 14 246 190 14 246 190 14
40966 -246 190 14 246 190 14 246 190 14 246 190 14
40967 -246 186 14 230 174 11 210 150 10 163 110 8
40968 -104 69 6 10 10 10 2 2 6 2 2 6
40969 - 2 2 6 2 2 6 2 2 6 2 2 6
40970 - 2 2 6 2 2 6 2 2 6 2 2 6
40971 - 2 2 6 2 2 6 2 2 6 2 2 6
40972 - 2 2 6 6 6 6 91 60 6 167 114 7
40973 -206 145 10 230 174 11 242 186 14 246 190 14
40974 -246 190 14 246 190 14 246 186 14 242 186 14
40975 -239 182 13 230 174 11 224 166 10 213 154 11
40976 -180 133 36 124 112 88 86 86 86 58 58 58
40977 - 38 38 38 22 22 22 10 10 10 6 6 6
40978 - 0 0 0 0 0 0 0 0 0 0 0 0
40979 - 0 0 0 0 0 0 0 0 0 0 0 0
40980 - 0 0 0 0 0 0 0 0 0 0 0 0
40981 - 0 0 0 0 0 0 0 0 0 14 14 14
40982 - 34 34 34 70 70 70 138 110 50 158 118 36
40983 -167 114 7 180 123 7 192 133 9 197 138 11
40984 -200 144 11 206 145 10 213 154 11 219 162 10
40985 -224 166 10 230 174 11 239 182 13 242 186 14
40986 -246 186 14 246 186 14 246 186 14 246 186 14
40987 -239 182 13 216 158 10 185 133 11 152 99 6
40988 -104 69 6 18 14 6 2 2 6 2 2 6
40989 - 2 2 6 2 2 6 2 2 6 2 2 6
40990 - 2 2 6 2 2 6 2 2 6 2 2 6
40991 - 2 2 6 2 2 6 2 2 6 2 2 6
40992 - 2 2 6 6 6 6 80 54 7 152 99 6
40993 -192 133 9 219 162 10 236 178 12 239 182 13
40994 -246 186 14 242 186 14 239 182 13 236 178 12
40995 -224 166 10 206 145 10 192 133 9 154 121 60
40996 - 94 94 94 62 62 62 42 42 42 22 22 22
40997 - 14 14 14 6 6 6 0 0 0 0 0 0
40998 - 0 0 0 0 0 0 0 0 0 0 0 0
40999 - 0 0 0 0 0 0 0 0 0 0 0 0
41000 - 0 0 0 0 0 0 0 0 0 0 0 0
41001 - 0 0 0 0 0 0 0 0 0 6 6 6
41002 - 18 18 18 34 34 34 58 58 58 78 78 78
41003 -101 98 89 124 112 88 142 110 46 156 107 11
41004 -163 110 8 167 114 7 175 118 6 180 123 7
41005 -185 133 11 197 138 11 210 150 10 219 162 10
41006 -226 170 11 236 178 12 236 178 12 234 174 13
41007 -219 162 10 197 138 11 163 110 8 130 83 6
41008 - 91 60 6 10 10 10 2 2 6 2 2 6
41009 - 18 18 18 38 38 38 38 38 38 38 38 38
41010 - 38 38 38 38 38 38 38 38 38 38 38 38
41011 - 38 38 38 38 38 38 26 26 26 2 2 6
41012 - 2 2 6 6 6 6 70 47 6 137 92 6
41013 -175 118 6 200 144 11 219 162 10 230 174 11
41014 -234 174 13 230 174 11 219 162 10 210 150 10
41015 -192 133 9 163 110 8 124 112 88 82 82 82
41016 - 50 50 50 30 30 30 14 14 14 6 6 6
41017 - 0 0 0 0 0 0 0 0 0 0 0 0
41018 - 0 0 0 0 0 0 0 0 0 0 0 0
41019 - 0 0 0 0 0 0 0 0 0 0 0 0
41020 - 0 0 0 0 0 0 0 0 0 0 0 0
41021 - 0 0 0 0 0 0 0 0 0 0 0 0
41022 - 6 6 6 14 14 14 22 22 22 34 34 34
41023 - 42 42 42 58 58 58 74 74 74 86 86 86
41024 -101 98 89 122 102 70 130 98 46 121 87 25
41025 -137 92 6 152 99 6 163 110 8 180 123 7
41026 -185 133 11 197 138 11 206 145 10 200 144 11
41027 -180 123 7 156 107 11 130 83 6 104 69 6
41028 - 50 34 6 54 54 54 110 110 110 101 98 89
41029 - 86 86 86 82 82 82 78 78 78 78 78 78
41030 - 78 78 78 78 78 78 78 78 78 78 78 78
41031 - 78 78 78 82 82 82 86 86 86 94 94 94
41032 -106 106 106 101 101 101 86 66 34 124 80 6
41033 -156 107 11 180 123 7 192 133 9 200 144 11
41034 -206 145 10 200 144 11 192 133 9 175 118 6
41035 -139 102 15 109 106 95 70 70 70 42 42 42
41036 - 22 22 22 10 10 10 0 0 0 0 0 0
41037 - 0 0 0 0 0 0 0 0 0 0 0 0
41038 - 0 0 0 0 0 0 0 0 0 0 0 0
41039 - 0 0 0 0 0 0 0 0 0 0 0 0
41040 - 0 0 0 0 0 0 0 0 0 0 0 0
41041 - 0 0 0 0 0 0 0 0 0 0 0 0
41042 - 0 0 0 0 0 0 6 6 6 10 10 10
41043 - 14 14 14 22 22 22 30 30 30 38 38 38
41044 - 50 50 50 62 62 62 74 74 74 90 90 90
41045 -101 98 89 112 100 78 121 87 25 124 80 6
41046 -137 92 6 152 99 6 152 99 6 152 99 6
41047 -138 86 6 124 80 6 98 70 6 86 66 30
41048 -101 98 89 82 82 82 58 58 58 46 46 46
41049 - 38 38 38 34 34 34 34 34 34 34 34 34
41050 - 34 34 34 34 34 34 34 34 34 34 34 34
41051 - 34 34 34 34 34 34 38 38 38 42 42 42
41052 - 54 54 54 82 82 82 94 86 76 91 60 6
41053 -134 86 6 156 107 11 167 114 7 175 118 6
41054 -175 118 6 167 114 7 152 99 6 121 87 25
41055 -101 98 89 62 62 62 34 34 34 18 18 18
41056 - 6 6 6 0 0 0 0 0 0 0 0 0
41057 - 0 0 0 0 0 0 0 0 0 0 0 0
41058 - 0 0 0 0 0 0 0 0 0 0 0 0
41059 - 0 0 0 0 0 0 0 0 0 0 0 0
41060 - 0 0 0 0 0 0 0 0 0 0 0 0
41061 - 0 0 0 0 0 0 0 0 0 0 0 0
41062 - 0 0 0 0 0 0 0 0 0 0 0 0
41063 - 0 0 0 6 6 6 6 6 6 10 10 10
41064 - 18 18 18 22 22 22 30 30 30 42 42 42
41065 - 50 50 50 66 66 66 86 86 86 101 98 89
41066 -106 86 58 98 70 6 104 69 6 104 69 6
41067 -104 69 6 91 60 6 82 62 34 90 90 90
41068 - 62 62 62 38 38 38 22 22 22 14 14 14
41069 - 10 10 10 10 10 10 10 10 10 10 10 10
41070 - 10 10 10 10 10 10 6 6 6 10 10 10
41071 - 10 10 10 10 10 10 10 10 10 14 14 14
41072 - 22 22 22 42 42 42 70 70 70 89 81 66
41073 - 80 54 7 104 69 6 124 80 6 137 92 6
41074 -134 86 6 116 81 8 100 82 52 86 86 86
41075 - 58 58 58 30 30 30 14 14 14 6 6 6
41076 - 0 0 0 0 0 0 0 0 0 0 0 0
41077 - 0 0 0 0 0 0 0 0 0 0 0 0
41078 - 0 0 0 0 0 0 0 0 0 0 0 0
41079 - 0 0 0 0 0 0 0 0 0 0 0 0
41080 - 0 0 0 0 0 0 0 0 0 0 0 0
41081 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
41085 - 18 18 18 26 26 26 38 38 38 54 54 54
41086 - 70 70 70 86 86 86 94 86 76 89 81 66
41087 - 89 81 66 86 86 86 74 74 74 50 50 50
41088 - 30 30 30 14 14 14 6 6 6 0 0 0
41089 - 0 0 0 0 0 0 0 0 0 0 0 0
41090 - 0 0 0 0 0 0 0 0 0 0 0 0
41091 - 0 0 0 0 0 0 0 0 0 0 0 0
41092 - 6 6 6 18 18 18 34 34 34 58 58 58
41093 - 82 82 82 89 81 66 89 81 66 89 81 66
41094 - 94 86 66 94 86 76 74 74 74 50 50 50
41095 - 26 26 26 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41099 - 0 0 0 0 0 0 0 0 0 0 0 0
41100 - 0 0 0 0 0 0 0 0 0 0 0 0
41101 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
41106 - 30 30 30 38 38 38 46 46 46 54 54 54
41107 - 50 50 50 42 42 42 30 30 30 18 18 18
41108 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41112 - 0 0 0 6 6 6 14 14 14 26 26 26
41113 - 38 38 38 50 50 50 58 58 58 58 58 58
41114 - 54 54 54 42 42 42 30 30 30 18 18 18
41115 - 10 10 10 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 0 0 0 0 0 0 0 0 0
41119 - 0 0 0 0 0 0 0 0 0 0 0 0
41120 - 0 0 0 0 0 0 0 0 0 0 0 0
41121 - 0 0 0 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 6 6 6
41126 - 6 6 6 10 10 10 14 14 14 18 18 18
41127 - 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0
41132 - 0 0 0 0 0 0 0 0 0 6 6 6
41133 - 14 14 14 18 18 18 22 22 22 22 22 22
41134 - 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0
41139 - 0 0 0 0 0 0 0 0 0 0 0 0
41140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 3 3 3 0 0 0 0 0 0
41229 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
41234 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41235 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 4 4 4 4 4 4
41240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41243 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41244 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
41248 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41249 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41250 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +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 4 4 4 4 4 4 4 4 4 4 4 4
41254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41257 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41258 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
41262 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41263 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41264 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41265 +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 4 4 4 4 4 4 4 4 4 4 4 4
41268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41270 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41271 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41272 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
41275 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41276 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41277 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41278 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41279 +4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41284 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41285 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41286 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41287 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41289 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41290 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41291 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41292 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41297 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41298 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41299 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41300 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41301 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41302 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41303 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41304 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41305 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41306 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41307 +4 4 4 4 4 4
41308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41311 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41312 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41313 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41314 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41315 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41316 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41317 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41318 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41319 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41320 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41325 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41326 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41327 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41328 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41329 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41330 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41331 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41332 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41333 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41334 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41339 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41340 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41341 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41342 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41343 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41344 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41345 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41346 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41347 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41348 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41353 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41354 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41355 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41356 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41357 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41358 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41359 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41360 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41361 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41362 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41363 +4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41366 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41367 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41368 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41369 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41370 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41371 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41372 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41373 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41374 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41375 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41376 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41377 +4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41380 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41381 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41382 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41383 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41384 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41385 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41386 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41387 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41388 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41389 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41390 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41391 +0 0 0 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41393 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41394 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41395 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41396 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41397 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41398 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41399 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41400 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41401 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41402 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41403 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41404 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41405 +2 0 0 0 0 0
41406 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41407 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41408 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41409 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41410 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41411 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41412 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41413 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41414 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41415 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41416 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41417 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41418 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41419 +37 38 37 0 0 0
41420 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41421 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41422 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41423 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41424 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41425 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41426 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41427 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41428 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41429 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41430 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41431 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41432 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41433 +85 115 134 4 0 0
41434 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41435 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41436 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41437 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41438 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41439 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41440 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41441 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41442 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41443 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41444 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41445 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41446 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41447 +60 73 81 4 0 0
41448 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41449 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41450 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41451 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41452 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41453 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41454 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41455 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41456 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41457 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41458 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41459 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41460 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41461 +16 19 21 4 0 0
41462 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41463 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41464 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41465 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41466 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41467 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41468 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41469 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41470 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41471 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41472 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41473 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41474 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41475 +4 0 0 4 3 3
41476 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41477 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41478 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41480 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41481 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41482 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41483 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41484 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41485 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41486 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41487 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41488 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41489 +3 2 2 4 4 4
41490 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41491 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41492 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41493 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41494 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41495 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41496 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41497 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41498 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41499 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41500 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41501 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41502 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41503 +4 4 4 4 4 4
41504 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41505 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41506 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41507 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41508 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41509 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41510 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41511 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41512 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41513 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41514 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41515 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41516 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41517 +4 4 4 4 4 4
41518 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41519 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41520 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41521 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41522 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41523 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41524 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41525 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41526 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41527 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41528 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41529 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41530 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41531 +5 5 5 5 5 5
41532 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41533 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41534 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41535 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41536 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41537 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41538 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41539 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41540 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41541 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41542 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41543 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41544 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41545 +5 5 5 4 4 4
41546 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41547 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41548 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41549 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41550 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41551 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41552 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41553 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41554 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41555 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41556 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41557 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559 +4 4 4 4 4 4
41560 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41561 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41562 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41563 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41564 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41565 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41566 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41567 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41568 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41569 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41570 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41571 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41573 +4 4 4 4 4 4
41574 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41575 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41576 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41577 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41578 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41579 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41580 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41581 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41582 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41583 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41584 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587 +4 4 4 4 4 4
41588 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41589 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41590 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41591 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41592 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41593 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41594 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41595 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41596 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41597 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41598 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601 +4 4 4 4 4 4
41602 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41603 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41604 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41605 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41606 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41607 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41608 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41609 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41610 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41611 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41612 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41615 +4 4 4 4 4 4
41616 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41617 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41618 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41619 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41620 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41621 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41622 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41623 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41624 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41625 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41626 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41629 +4 4 4 4 4 4
41630 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41631 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41632 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41633 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41634 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41635 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41636 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41637 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41638 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41639 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41640 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41643 +4 4 4 4 4 4
41644 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41645 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41646 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41647 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41648 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41649 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41650 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41651 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41652 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41653 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41654 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41657 +4 4 4 4 4 4
41658 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41659 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41660 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41661 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41662 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41663 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41664 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41665 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41666 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41667 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41668 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41671 +4 4 4 4 4 4
41672 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41673 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41674 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41675 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41676 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41677 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41678 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41679 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41680 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41681 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41682 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685 +4 4 4 4 4 4
41686 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41687 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41688 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41689 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41690 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41691 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41692 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41693 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41694 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41695 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41696 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41699 +4 4 4 4 4 4
41700 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41701 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41702 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41703 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41704 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41705 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41706 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41707 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41708 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41709 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41710 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41713 +4 4 4 4 4 4
41714 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41715 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41716 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41717 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41718 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41719 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41720 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41721 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41722 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41723 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41724 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727 +4 4 4 4 4 4
41728 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41729 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41730 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41731 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41732 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41733 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41734 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41735 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41736 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41737 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41738 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741 +4 4 4 4 4 4
41742 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41743 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41744 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41745 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41746 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41747 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41748 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41749 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41750 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41751 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41752 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755 +4 4 4 4 4 4
41756 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41757 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41758 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41759 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41760 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41761 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41762 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41763 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41764 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41765 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41766 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769 +4 4 4 4 4 4
41770 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41771 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41772 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41773 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41774 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41775 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41776 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41777 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41778 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41779 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41780 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41783 +4 4 4 4 4 4
41784 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41785 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41786 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41787 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41788 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41789 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41790 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41791 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41792 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41793 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41794 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41797 +4 4 4 4 4 4
41798 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41799 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41800 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41801 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41802 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41803 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41804 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41805 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41806 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41807 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41808 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41809 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811 +4 4 4 4 4 4
41812 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41813 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41814 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41815 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41816 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41817 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41818 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41819 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41820 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41821 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41822 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41823 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41825 +4 4 4 4 4 4
41826 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41827 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41828 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41829 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41830 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41831 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41832 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41833 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41834 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41835 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41836 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41837 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41839 +4 4 4 4 4 4
41840 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41841 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41842 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41843 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41844 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41845 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41846 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41847 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41848 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41849 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41850 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41851 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41853 +4 4 4 4 4 4
41854 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41855 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41856 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41857 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41858 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41859 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41860 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41861 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41862 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41863 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41864 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41865 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41867 +4 4 4 4 4 4
41868 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41869 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41870 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41871 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41872 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41873 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41874 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41875 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41876 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41877 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41878 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41881 +4 4 4 4 4 4
41882 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41883 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41884 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41886 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41887 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41888 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41889 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41890 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41891 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41892 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41895 +4 4 4 4 4 4
41896 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41897 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41898 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41899 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41900 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41901 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41902 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41903 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41904 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41905 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41906 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41909 +4 4 4 4 4 4
41910 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41911 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41912 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41913 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41914 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41915 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41916 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41917 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41918 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41919 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41920 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41923 +4 4 4 4 4 4
41924 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41925 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41926 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41927 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41929 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41930 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41931 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41932 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41933 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41934 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41937 +4 4 4 4 4 4
41938 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41939 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41940 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41941 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41942 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41943 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41944 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41945 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41946 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41947 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41948 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41951 +4 4 4 4 4 4
41952 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41953 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41954 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41955 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41956 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41957 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41958 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41959 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41960 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41961 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41965 +4 4 4 4 4 4
41966 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41967 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41968 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41969 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41970 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41971 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41972 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41973 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41974 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41975 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41979 +4 4 4 4 4 4
41980 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41981 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41982 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41983 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41984 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41985 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41986 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41987 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41988 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41989 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41993 +4 4 4 4 4 4
41994 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41995 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41996 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41997 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41998 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41999 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42000 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42001 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42002 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42003 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42007 +4 4 4 4 4 4
42008 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42009 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42010 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42011 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42012 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42013 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42014 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42015 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42016 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42021 +4 4 4 4 4 4
42022 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42023 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42024 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42025 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42026 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42027 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42028 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42029 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42030 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42035 +4 4 4 4 4 4
42036 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42037 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42038 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42039 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42040 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42041 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42042 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42043 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42044 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42049 +4 4 4 4 4 4
42050 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42051 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42052 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42053 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42054 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42055 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42056 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42057 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42063 +4 4 4 4 4 4
42064 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42065 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42066 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42067 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42068 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42069 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42070 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42071 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42077 +4 4 4 4 4 4
42078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42079 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42080 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42081 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42082 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42083 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42084 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42085 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42091 +4 4 4 4 4 4
42092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42093 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42094 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42095 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42096 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42097 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42098 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42099 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42105 +4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
42108 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42109 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42110 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42111 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42112 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42113 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42119 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42123 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42124 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42125 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42126 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42127 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42133 +4 4 4 4 4 4
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 5 5 5
42137 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42138 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42139 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42140 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4
42143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42147 +4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42152 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42153 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42154 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42161 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
42166 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42167 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42168 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42175 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
42180 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42181 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42182 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
42186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42189 +4 4 4 4 4 4
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 5 5 5
42194 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42195 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42196 +6 6 6 4 3 3 5 5 5 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 4 4 4
42200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42209 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42210 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42223 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42224 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4
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 5 5 5 4 3 3 6 6 6
42237 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4
42243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4
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 5 5 5 4 3 3
42251 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4
42257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42259 +4 4 4 4 4 4
42260 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42261 index 38fcfff..0072dcd 100644
42262 --- a/drivers/video/udlfb.c
42263 +++ b/drivers/video/udlfb.c
42264 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42265 dlfb_urb_completion(urb);
42266
42267 error:
42268 - atomic_add(bytes_sent, &dev->bytes_sent);
42269 - atomic_add(bytes_identical, &dev->bytes_identical);
42270 - atomic_add(width*height*2, &dev->bytes_rendered);
42271 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42272 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42273 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42274 end_cycles = get_cycles();
42275 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42276 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42277 >> 10)), /* Kcycles */
42278 &dev->cpu_kcycles_used);
42279
42280 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42281 dlfb_urb_completion(urb);
42282
42283 error:
42284 - atomic_add(bytes_sent, &dev->bytes_sent);
42285 - atomic_add(bytes_identical, &dev->bytes_identical);
42286 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42287 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42288 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42289 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42290 end_cycles = get_cycles();
42291 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42292 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42293 >> 10)), /* Kcycles */
42294 &dev->cpu_kcycles_used);
42295 }
42296 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42297 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42298 struct dlfb_data *dev = fb_info->par;
42299 return snprintf(buf, PAGE_SIZE, "%u\n",
42300 - atomic_read(&dev->bytes_rendered));
42301 + atomic_read_unchecked(&dev->bytes_rendered));
42302 }
42303
42304 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42305 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42306 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42307 struct dlfb_data *dev = fb_info->par;
42308 return snprintf(buf, PAGE_SIZE, "%u\n",
42309 - atomic_read(&dev->bytes_identical));
42310 + atomic_read_unchecked(&dev->bytes_identical));
42311 }
42312
42313 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42314 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42315 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42316 struct dlfb_data *dev = fb_info->par;
42317 return snprintf(buf, PAGE_SIZE, "%u\n",
42318 - atomic_read(&dev->bytes_sent));
42319 + atomic_read_unchecked(&dev->bytes_sent));
42320 }
42321
42322 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42323 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42324 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42325 struct dlfb_data *dev = fb_info->par;
42326 return snprintf(buf, PAGE_SIZE, "%u\n",
42327 - atomic_read(&dev->cpu_kcycles_used));
42328 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42329 }
42330
42331 static ssize_t edid_show(
42332 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42333 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42334 struct dlfb_data *dev = fb_info->par;
42335
42336 - atomic_set(&dev->bytes_rendered, 0);
42337 - atomic_set(&dev->bytes_identical, 0);
42338 - atomic_set(&dev->bytes_sent, 0);
42339 - atomic_set(&dev->cpu_kcycles_used, 0);
42340 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42341 + atomic_set_unchecked(&dev->bytes_identical, 0);
42342 + atomic_set_unchecked(&dev->bytes_sent, 0);
42343 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42344
42345 return count;
42346 }
42347 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42348 index b0e2a42..e2df3ad 100644
42349 --- a/drivers/video/uvesafb.c
42350 +++ b/drivers/video/uvesafb.c
42351 @@ -19,6 +19,7 @@
42352 #include <linux/io.h>
42353 #include <linux/mutex.h>
42354 #include <linux/slab.h>
42355 +#include <linux/moduleloader.h>
42356 #include <video/edid.h>
42357 #include <video/uvesafb.h>
42358 #ifdef CONFIG_X86
42359 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42360 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42361 par->pmi_setpal = par->ypan = 0;
42362 } else {
42363 +
42364 +#ifdef CONFIG_PAX_KERNEXEC
42365 +#ifdef CONFIG_MODULES
42366 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42367 +#endif
42368 + if (!par->pmi_code) {
42369 + par->pmi_setpal = par->ypan = 0;
42370 + return 0;
42371 + }
42372 +#endif
42373 +
42374 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42375 + task->t.regs.edi);
42376 +
42377 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42378 + pax_open_kernel();
42379 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42380 + pax_close_kernel();
42381 +
42382 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42383 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42384 +#else
42385 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42386 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42387 +#endif
42388 +
42389 printk(KERN_INFO "uvesafb: protected mode interface info at "
42390 "%04x:%04x\n",
42391 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42392 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42393 par->ypan = ypan;
42394
42395 if (par->pmi_setpal || par->ypan) {
42396 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42397 if (__supported_pte_mask & _PAGE_NX) {
42398 par->pmi_setpal = par->ypan = 0;
42399 printk(KERN_WARNING "uvesafb: NX protection is actively."
42400 "We have better not to use the PMI.\n");
42401 - } else {
42402 + } else
42403 +#endif
42404 uvesafb_vbe_getpmi(task, par);
42405 - }
42406 }
42407 #else
42408 /* The protected mode interface is not available on non-x86. */
42409 @@ -1836,6 +1860,11 @@ out:
42410 if (par->vbe_modes)
42411 kfree(par->vbe_modes);
42412
42413 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42414 + if (par->pmi_code)
42415 + module_free_exec(NULL, par->pmi_code);
42416 +#endif
42417 +
42418 framebuffer_release(info);
42419 return err;
42420 }
42421 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42422 kfree(par->vbe_state_orig);
42423 if (par->vbe_state_saved)
42424 kfree(par->vbe_state_saved);
42425 +
42426 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42427 + if (par->pmi_code)
42428 + module_free_exec(NULL, par->pmi_code);
42429 +#endif
42430 +
42431 }
42432
42433 framebuffer_release(info);
42434 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42435 index 501b340..86bd4cf 100644
42436 --- a/drivers/video/vesafb.c
42437 +++ b/drivers/video/vesafb.c
42438 @@ -9,6 +9,7 @@
42439 */
42440
42441 #include <linux/module.h>
42442 +#include <linux/moduleloader.h>
42443 #include <linux/kernel.h>
42444 #include <linux/errno.h>
42445 #include <linux/string.h>
42446 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42447 static int vram_total __initdata; /* Set total amount of memory */
42448 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42449 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42450 -static void (*pmi_start)(void) __read_mostly;
42451 -static void (*pmi_pal) (void) __read_mostly;
42452 +static void (*pmi_start)(void) __read_only;
42453 +static void (*pmi_pal) (void) __read_only;
42454 static int depth __read_mostly;
42455 static int vga_compat __read_mostly;
42456 /* --------------------------------------------------------------------- */
42457 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42458 unsigned int size_vmode;
42459 unsigned int size_remap;
42460 unsigned int size_total;
42461 + void *pmi_code = NULL;
42462
42463 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42464 return -ENODEV;
42465 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42466 size_remap = size_total;
42467 vesafb_fix.smem_len = size_remap;
42468
42469 -#ifndef __i386__
42470 - screen_info.vesapm_seg = 0;
42471 -#endif
42472 -
42473 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42474 printk(KERN_WARNING
42475 "vesafb: cannot reserve video memory at 0x%lx\n",
42476 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42477 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42478 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42479
42480 +#ifdef __i386__
42481 +
42482 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42483 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42484 + if (!pmi_code)
42485 +#elif !defined(CONFIG_PAX_KERNEXEC)
42486 + if (0)
42487 +#endif
42488 +
42489 +#endif
42490 + screen_info.vesapm_seg = 0;
42491 +
42492 if (screen_info.vesapm_seg) {
42493 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42494 - screen_info.vesapm_seg,screen_info.vesapm_off);
42495 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42496 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42497 }
42498
42499 if (screen_info.vesapm_seg < 0xc000)
42500 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42501
42502 if (ypan || pmi_setpal) {
42503 unsigned short *pmi_base;
42504 +
42505 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42506 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42507 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42508 +
42509 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42510 + pax_open_kernel();
42511 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42512 +#else
42513 + pmi_code = pmi_base;
42514 +#endif
42515 +
42516 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42517 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42518 +
42519 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42520 + pmi_start = ktva_ktla(pmi_start);
42521 + pmi_pal = ktva_ktla(pmi_pal);
42522 + pax_close_kernel();
42523 +#endif
42524 +
42525 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42526 if (pmi_base[3]) {
42527 printk(KERN_INFO "vesafb: pmi: ports = ");
42528 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42529 info->node, info->fix.id);
42530 return 0;
42531 err:
42532 +
42533 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42534 + module_free_exec(NULL, pmi_code);
42535 +#endif
42536 +
42537 if (info->screen_base)
42538 iounmap(info->screen_base);
42539 framebuffer_release(info);
42540 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42541 index 88714ae..16c2e11 100644
42542 --- a/drivers/video/via/via_clock.h
42543 +++ b/drivers/video/via/via_clock.h
42544 @@ -56,7 +56,7 @@ struct via_clock {
42545
42546 void (*set_engine_pll_state)(u8 state);
42547 void (*set_engine_pll)(struct via_pll_config config);
42548 -};
42549 +} __no_const;
42550
42551
42552 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42553 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42554 index 453db0c..604973e 100644
42555 --- a/drivers/virtio/virtio_mmio.c
42556 +++ b/drivers/virtio/virtio_mmio.c
42557 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42558
42559 resources[0].end = memparse(device, &str) - 1;
42560
42561 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42562 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42563 &base, &resources[1].start, &consumed,
42564 &vm_cmdline_id, &consumed);
42565
42566 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42567 index e56c934..fc22f4b 100644
42568 --- a/drivers/xen/xen-pciback/conf_space.h
42569 +++ b/drivers/xen/xen-pciback/conf_space.h
42570 @@ -44,15 +44,15 @@ struct config_field {
42571 struct {
42572 conf_dword_write write;
42573 conf_dword_read read;
42574 - } dw;
42575 + } __no_const dw;
42576 struct {
42577 conf_word_write write;
42578 conf_word_read read;
42579 - } w;
42580 + } __no_const w;
42581 struct {
42582 conf_byte_write write;
42583 conf_byte_read read;
42584 - } b;
42585 + } __no_const b;
42586 } u;
42587 struct list_head list;
42588 };
42589 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42590 index cbf9dbb..35c3af7 100644
42591 --- a/fs/9p/vfs_inode.c
42592 +++ b/fs/9p/vfs_inode.c
42593 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42594 void
42595 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42596 {
42597 - char *s = nd_get_link(nd);
42598 + const char *s = nd_get_link(nd);
42599
42600 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42601 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42602 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42603 index 0225742..1cd4732 100644
42604 --- a/fs/Kconfig.binfmt
42605 +++ b/fs/Kconfig.binfmt
42606 @@ -89,7 +89,7 @@ config HAVE_AOUT
42607
42608 config BINFMT_AOUT
42609 tristate "Kernel support for a.out and ECOFF binaries"
42610 - depends on HAVE_AOUT
42611 + depends on HAVE_AOUT && BROKEN
42612 ---help---
42613 A.out (Assembler.OUTput) is a set of formats for libraries and
42614 executables used in the earliest versions of UNIX. Linux used
42615 diff --git a/fs/aio.c b/fs/aio.c
42616 index 71f613c..9d01f1f 100644
42617 --- a/fs/aio.c
42618 +++ b/fs/aio.c
42619 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42620 size += sizeof(struct io_event) * nr_events;
42621 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42622
42623 - if (nr_pages < 0)
42624 + if (nr_pages <= 0)
42625 return -EINVAL;
42626
42627 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42628 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42629 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42630 {
42631 ssize_t ret;
42632 + struct iovec iovstack;
42633
42634 #ifdef CONFIG_COMPAT
42635 if (compat)
42636 ret = compat_rw_copy_check_uvector(type,
42637 (struct compat_iovec __user *)kiocb->ki_buf,
42638 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42639 + kiocb->ki_nbytes, 1, &iovstack,
42640 &kiocb->ki_iovec);
42641 else
42642 #endif
42643 ret = rw_copy_check_uvector(type,
42644 (struct iovec __user *)kiocb->ki_buf,
42645 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42646 + kiocb->ki_nbytes, 1, &iovstack,
42647 &kiocb->ki_iovec);
42648 if (ret < 0)
42649 goto out;
42650 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42651 if (ret < 0)
42652 goto out;
42653
42654 + if (kiocb->ki_iovec == &iovstack) {
42655 + kiocb->ki_inline_vec = iovstack;
42656 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42657 + }
42658 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42659 kiocb->ki_cur_seg = 0;
42660 /* ki_nbytes/left now reflect bytes instead of segs */
42661 diff --git a/fs/attr.c b/fs/attr.c
42662 index 29e38a1..2bc037b 100644
42663 --- a/fs/attr.c
42664 +++ b/fs/attr.c
42665 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42666 unsigned long limit;
42667
42668 limit = rlimit(RLIMIT_FSIZE);
42669 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42670 if (limit != RLIM_INFINITY && offset > limit)
42671 goto out_sig;
42672 if (offset > inode->i_sb->s_maxbytes)
42673 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42674 index da8876d..4456166 100644
42675 --- a/fs/autofs4/waitq.c
42676 +++ b/fs/autofs4/waitq.c
42677 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42678 {
42679 unsigned long sigpipe, flags;
42680 mm_segment_t fs;
42681 - const char *data = (const char *)addr;
42682 + const char __user *data = (const char __force_user *)addr;
42683 ssize_t wr = 0;
42684
42685 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42686 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42687 return 1;
42688 }
42689
42690 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42691 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42692 +#endif
42693 +
42694 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42695 enum autofs_notify notify)
42696 {
42697 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42698
42699 /* If this is a direct mount request create a dummy name */
42700 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42701 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42702 + /* this name does get written to userland via autofs4_write() */
42703 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42704 +#else
42705 qstr.len = sprintf(name, "%p", dentry);
42706 +#endif
42707 else {
42708 qstr.len = autofs4_getpath(sbi, dentry, &name);
42709 if (!qstr.len) {
42710 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42711 index cf7f3c6..f61080d 100644
42712 --- a/fs/befs/linuxvfs.c
42713 +++ b/fs/befs/linuxvfs.c
42714 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42715 {
42716 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42717 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42718 - char *link = nd_get_link(nd);
42719 + const char *link = nd_get_link(nd);
42720 if (!IS_ERR(link))
42721 kfree(link);
42722 }
42723 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42724 index d146e18..12d1bd1 100644
42725 --- a/fs/binfmt_aout.c
42726 +++ b/fs/binfmt_aout.c
42727 @@ -16,6 +16,7 @@
42728 #include <linux/string.h>
42729 #include <linux/fs.h>
42730 #include <linux/file.h>
42731 +#include <linux/security.h>
42732 #include <linux/stat.h>
42733 #include <linux/fcntl.h>
42734 #include <linux/ptrace.h>
42735 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42736 #endif
42737 # define START_STACK(u) ((void __user *)u.start_stack)
42738
42739 + memset(&dump, 0, sizeof(dump));
42740 +
42741 fs = get_fs();
42742 set_fs(KERNEL_DS);
42743 has_dumped = 1;
42744 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42745
42746 /* If the size of the dump file exceeds the rlimit, then see what would happen
42747 if we wrote the stack, but not the data area. */
42748 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42749 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42750 dump.u_dsize = 0;
42751
42752 /* Make sure we have enough room to write the stack and data areas. */
42753 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42754 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42755 dump.u_ssize = 0;
42756
42757 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42758 rlim = rlimit(RLIMIT_DATA);
42759 if (rlim >= RLIM_INFINITY)
42760 rlim = ~0;
42761 +
42762 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42763 if (ex.a_data + ex.a_bss > rlim)
42764 return -ENOMEM;
42765
42766 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42767
42768 install_exec_creds(bprm);
42769
42770 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42771 + current->mm->pax_flags = 0UL;
42772 +#endif
42773 +
42774 +#ifdef CONFIG_PAX_PAGEEXEC
42775 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42776 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42777 +
42778 +#ifdef CONFIG_PAX_EMUTRAMP
42779 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42780 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42781 +#endif
42782 +
42783 +#ifdef CONFIG_PAX_MPROTECT
42784 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42785 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42786 +#endif
42787 +
42788 + }
42789 +#endif
42790 +
42791 if (N_MAGIC(ex) == OMAGIC) {
42792 unsigned long text_addr, map_size;
42793 loff_t pos;
42794 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42795 }
42796
42797 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42798 - PROT_READ | PROT_WRITE | PROT_EXEC,
42799 + PROT_READ | PROT_WRITE,
42800 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42801 fd_offset + ex.a_text);
42802 if (error != N_DATADDR(ex)) {
42803 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42804 index 0225fdd..08bda99 100644
42805 --- a/fs/binfmt_elf.c
42806 +++ b/fs/binfmt_elf.c
42807 @@ -32,6 +32,7 @@
42808 #include <linux/elf.h>
42809 #include <linux/utsname.h>
42810 #include <linux/coredump.h>
42811 +#include <linux/xattr.h>
42812 #include <asm/uaccess.h>
42813 #include <asm/param.h>
42814 #include <asm/page.h>
42815 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42816 #define elf_core_dump NULL
42817 #endif
42818
42819 +#ifdef CONFIG_PAX_MPROTECT
42820 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42821 +#endif
42822 +
42823 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42824 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42825 #else
42826 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42827 .load_binary = load_elf_binary,
42828 .load_shlib = load_elf_library,
42829 .core_dump = elf_core_dump,
42830 +
42831 +#ifdef CONFIG_PAX_MPROTECT
42832 + .handle_mprotect= elf_handle_mprotect,
42833 +#endif
42834 +
42835 .min_coredump = ELF_EXEC_PAGESIZE,
42836 };
42837
42838 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42839
42840 static int set_brk(unsigned long start, unsigned long end)
42841 {
42842 + unsigned long e = end;
42843 +
42844 start = ELF_PAGEALIGN(start);
42845 end = ELF_PAGEALIGN(end);
42846 if (end > start) {
42847 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42848 if (BAD_ADDR(addr))
42849 return addr;
42850 }
42851 - current->mm->start_brk = current->mm->brk = end;
42852 + current->mm->start_brk = current->mm->brk = e;
42853 return 0;
42854 }
42855
42856 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42857 elf_addr_t __user *u_rand_bytes;
42858 const char *k_platform = ELF_PLATFORM;
42859 const char *k_base_platform = ELF_BASE_PLATFORM;
42860 - unsigned char k_rand_bytes[16];
42861 + u32 k_rand_bytes[4];
42862 int items;
42863 elf_addr_t *elf_info;
42864 int ei_index = 0;
42865 const struct cred *cred = current_cred();
42866 struct vm_area_struct *vma;
42867 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42868
42869 /*
42870 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42871 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42872 * Generate 16 random bytes for userspace PRNG seeding.
42873 */
42874 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42875 - u_rand_bytes = (elf_addr_t __user *)
42876 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42877 + srandom32(k_rand_bytes[0] ^ random32());
42878 + srandom32(k_rand_bytes[1] ^ random32());
42879 + srandom32(k_rand_bytes[2] ^ random32());
42880 + srandom32(k_rand_bytes[3] ^ random32());
42881 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42882 + u_rand_bytes = (elf_addr_t __user *) p;
42883 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42884 return -EFAULT;
42885
42886 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42887 return -EFAULT;
42888 current->mm->env_end = p;
42889
42890 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42891 +
42892 /* Put the elf_info on the stack in the right place. */
42893 sp = (elf_addr_t __user *)envp + 1;
42894 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42895 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42896 return -EFAULT;
42897 return 0;
42898 }
42899 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
42900 an ELF header */
42901
42902 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42903 - struct file *interpreter, unsigned long *interp_map_addr,
42904 - unsigned long no_base)
42905 + struct file *interpreter, unsigned long no_base)
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 +445,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 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42931 map_addr = elf_map(interpreter, load_addr + vaddr,
42932 eppnt, elf_prot, elf_type, total_size);
42933 total_size = 0;
42934 - if (!*interp_map_addr)
42935 - *interp_map_addr = map_addr;
42936 error = map_addr;
42937 if (BAD_ADDR(map_addr))
42938 goto out_close;
42939 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42940 k = load_addr + eppnt->p_vaddr;
42941 if (BAD_ADDR(k) ||
42942 eppnt->p_filesz > eppnt->p_memsz ||
42943 - eppnt->p_memsz > TASK_SIZE ||
42944 - TASK_SIZE - eppnt->p_memsz < k) {
42945 + eppnt->p_memsz > pax_task_size ||
42946 + pax_task_size - eppnt->p_memsz < k) {
42947 error = -ENOMEM;
42948 goto out_close;
42949 }
42950 @@ -523,6 +544,311 @@ out:
42951 return error;
42952 }
42953
42954 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42955 +#ifdef CONFIG_PAX_SOFTMODE
42956 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42957 +{
42958 + unsigned long pax_flags = 0UL;
42959 +
42960 +#ifdef CONFIG_PAX_PAGEEXEC
42961 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42962 + pax_flags |= MF_PAX_PAGEEXEC;
42963 +#endif
42964 +
42965 +#ifdef CONFIG_PAX_SEGMEXEC
42966 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42967 + pax_flags |= MF_PAX_SEGMEXEC;
42968 +#endif
42969 +
42970 +#ifdef CONFIG_PAX_EMUTRAMP
42971 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42972 + pax_flags |= MF_PAX_EMUTRAMP;
42973 +#endif
42974 +
42975 +#ifdef CONFIG_PAX_MPROTECT
42976 + if (elf_phdata->p_flags & PF_MPROTECT)
42977 + pax_flags |= MF_PAX_MPROTECT;
42978 +#endif
42979 +
42980 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42981 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42982 + pax_flags |= MF_PAX_RANDMMAP;
42983 +#endif
42984 +
42985 + return pax_flags;
42986 +}
42987 +#endif
42988 +
42989 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42990 +{
42991 + unsigned long pax_flags = 0UL;
42992 +
42993 +#ifdef CONFIG_PAX_PAGEEXEC
42994 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42995 + pax_flags |= MF_PAX_PAGEEXEC;
42996 +#endif
42997 +
42998 +#ifdef CONFIG_PAX_SEGMEXEC
42999 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43000 + pax_flags |= MF_PAX_SEGMEXEC;
43001 +#endif
43002 +
43003 +#ifdef CONFIG_PAX_EMUTRAMP
43004 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43005 + pax_flags |= MF_PAX_EMUTRAMP;
43006 +#endif
43007 +
43008 +#ifdef CONFIG_PAX_MPROTECT
43009 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43010 + pax_flags |= MF_PAX_MPROTECT;
43011 +#endif
43012 +
43013 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43014 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43015 + pax_flags |= MF_PAX_RANDMMAP;
43016 +#endif
43017 +
43018 + return pax_flags;
43019 +}
43020 +#endif
43021 +
43022 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43023 +#ifdef CONFIG_PAX_SOFTMODE
43024 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43025 +{
43026 + unsigned long pax_flags = 0UL;
43027 +
43028 +#ifdef CONFIG_PAX_PAGEEXEC
43029 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43030 + pax_flags |= MF_PAX_PAGEEXEC;
43031 +#endif
43032 +
43033 +#ifdef CONFIG_PAX_SEGMEXEC
43034 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43035 + pax_flags |= MF_PAX_SEGMEXEC;
43036 +#endif
43037 +
43038 +#ifdef CONFIG_PAX_EMUTRAMP
43039 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43040 + pax_flags |= MF_PAX_EMUTRAMP;
43041 +#endif
43042 +
43043 +#ifdef CONFIG_PAX_MPROTECT
43044 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43045 + pax_flags |= MF_PAX_MPROTECT;
43046 +#endif
43047 +
43048 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43049 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43050 + pax_flags |= MF_PAX_RANDMMAP;
43051 +#endif
43052 +
43053 + return pax_flags;
43054 +}
43055 +#endif
43056 +
43057 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43058 +{
43059 + unsigned long pax_flags = 0UL;
43060 +
43061 +#ifdef CONFIG_PAX_PAGEEXEC
43062 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43063 + pax_flags |= MF_PAX_PAGEEXEC;
43064 +#endif
43065 +
43066 +#ifdef CONFIG_PAX_SEGMEXEC
43067 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43068 + pax_flags |= MF_PAX_SEGMEXEC;
43069 +#endif
43070 +
43071 +#ifdef CONFIG_PAX_EMUTRAMP
43072 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43073 + pax_flags |= MF_PAX_EMUTRAMP;
43074 +#endif
43075 +
43076 +#ifdef CONFIG_PAX_MPROTECT
43077 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43078 + pax_flags |= MF_PAX_MPROTECT;
43079 +#endif
43080 +
43081 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43082 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43083 + pax_flags |= MF_PAX_RANDMMAP;
43084 +#endif
43085 +
43086 + return pax_flags;
43087 +}
43088 +#endif
43089 +
43090 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43091 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43092 +{
43093 + unsigned long pax_flags = 0UL;
43094 +
43095 +#ifdef CONFIG_PAX_EI_PAX
43096 +
43097 +#ifdef CONFIG_PAX_PAGEEXEC
43098 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43099 + pax_flags |= MF_PAX_PAGEEXEC;
43100 +#endif
43101 +
43102 +#ifdef CONFIG_PAX_SEGMEXEC
43103 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43104 + pax_flags |= MF_PAX_SEGMEXEC;
43105 +#endif
43106 +
43107 +#ifdef CONFIG_PAX_EMUTRAMP
43108 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43109 + pax_flags |= MF_PAX_EMUTRAMP;
43110 +#endif
43111 +
43112 +#ifdef CONFIG_PAX_MPROTECT
43113 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43114 + pax_flags |= MF_PAX_MPROTECT;
43115 +#endif
43116 +
43117 +#ifdef CONFIG_PAX_ASLR
43118 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43119 + pax_flags |= MF_PAX_RANDMMAP;
43120 +#endif
43121 +
43122 +#else
43123 +
43124 +#ifdef CONFIG_PAX_PAGEEXEC
43125 + pax_flags |= MF_PAX_PAGEEXEC;
43126 +#endif
43127 +
43128 +#ifdef CONFIG_PAX_SEGMEXEC
43129 + pax_flags |= MF_PAX_SEGMEXEC;
43130 +#endif
43131 +
43132 +#ifdef CONFIG_PAX_MPROTECT
43133 + pax_flags |= MF_PAX_MPROTECT;
43134 +#endif
43135 +
43136 +#ifdef CONFIG_PAX_RANDMMAP
43137 + if (randomize_va_space)
43138 + pax_flags |= MF_PAX_RANDMMAP;
43139 +#endif
43140 +
43141 +#endif
43142 +
43143 + return pax_flags;
43144 +}
43145 +
43146 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43147 +{
43148 +
43149 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43150 + unsigned long i;
43151 +
43152 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43153 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43154 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43155 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43156 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43157 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43158 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43159 + return ~0UL;
43160 +
43161 +#ifdef CONFIG_PAX_SOFTMODE
43162 + if (pax_softmode)
43163 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43164 + else
43165 +#endif
43166 +
43167 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43168 + break;
43169 + }
43170 +#endif
43171 +
43172 + return ~0UL;
43173 +}
43174 +
43175 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43176 +{
43177 +
43178 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43179 + ssize_t xattr_size, i;
43180 + unsigned char xattr_value[5];
43181 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43182 +
43183 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43184 + if (xattr_size <= 0)
43185 + return ~0UL;
43186 +
43187 + for (i = 0; i < xattr_size; i++)
43188 + switch (xattr_value[i]) {
43189 + default:
43190 + return ~0UL;
43191 +
43192 +#define parse_flag(option1, option2, flag) \
43193 + case option1: \
43194 + pax_flags_hardmode |= MF_PAX_##flag; \
43195 + break; \
43196 + case option2: \
43197 + pax_flags_softmode |= MF_PAX_##flag; \
43198 + break;
43199 +
43200 + parse_flag('p', 'P', PAGEEXEC);
43201 + parse_flag('e', 'E', EMUTRAMP);
43202 + parse_flag('m', 'M', MPROTECT);
43203 + parse_flag('r', 'R', RANDMMAP);
43204 + parse_flag('s', 'S', SEGMEXEC);
43205 +
43206 +#undef parse_flag
43207 + }
43208 +
43209 + if (pax_flags_hardmode & pax_flags_softmode)
43210 + return ~0UL;
43211 +
43212 +#ifdef CONFIG_PAX_SOFTMODE
43213 + if (pax_softmode)
43214 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43215 + else
43216 +#endif
43217 +
43218 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43219 +#else
43220 + return ~0UL;
43221 +#endif
43222 +
43223 +}
43224 +
43225 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43226 +{
43227 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43228 +
43229 + pax_flags = pax_parse_ei_pax(elf_ex);
43230 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43231 + xattr_pax_flags = pax_parse_xattr_pax(file);
43232 +
43233 + if (pt_pax_flags == ~0UL)
43234 + pt_pax_flags = xattr_pax_flags;
43235 + else if (xattr_pax_flags == ~0UL)
43236 + xattr_pax_flags = pt_pax_flags;
43237 + if (pt_pax_flags != xattr_pax_flags)
43238 + return -EINVAL;
43239 + if (pt_pax_flags != ~0UL)
43240 + pax_flags = pt_pax_flags;
43241 +
43242 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43243 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43244 + if ((__supported_pte_mask & _PAGE_NX))
43245 + pax_flags &= ~MF_PAX_SEGMEXEC;
43246 + else
43247 + pax_flags &= ~MF_PAX_PAGEEXEC;
43248 + }
43249 +#endif
43250 +
43251 + if (0 > pax_check_flags(&pax_flags))
43252 + return -EINVAL;
43253 +
43254 + current->mm->pax_flags = pax_flags;
43255 + return 0;
43256 +}
43257 +#endif
43258 +
43259 /*
43260 * These are the functions used to load ELF style executables and shared
43261 * libraries. There is no binary dependent code anywhere else.
43262 @@ -539,6 +865,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43263 {
43264 unsigned int random_variable = 0;
43265
43266 +#ifdef CONFIG_PAX_RANDUSTACK
43267 + if (randomize_va_space)
43268 + return stack_top - current->mm->delta_stack;
43269 +#endif
43270 +
43271 if ((current->flags & PF_RANDOMIZE) &&
43272 !(current->personality & ADDR_NO_RANDOMIZE)) {
43273 random_variable = get_random_int() & STACK_RND_MASK;
43274 @@ -557,7 +888,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43275 unsigned long load_addr = 0, load_bias = 0;
43276 int load_addr_set = 0;
43277 char * elf_interpreter = NULL;
43278 - unsigned long error;
43279 + unsigned long error = 0;
43280 struct elf_phdr *elf_ppnt, *elf_phdata;
43281 unsigned long elf_bss, elf_brk;
43282 int retval, i;
43283 @@ -567,11 +898,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43284 unsigned long start_code, end_code, start_data, end_data;
43285 unsigned long reloc_func_desc __maybe_unused = 0;
43286 int executable_stack = EXSTACK_DEFAULT;
43287 - unsigned long def_flags = 0;
43288 struct {
43289 struct elfhdr elf_ex;
43290 struct elfhdr interp_elf_ex;
43291 } *loc;
43292 + unsigned long pax_task_size = TASK_SIZE;
43293
43294 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43295 if (!loc) {
43296 @@ -707,11 +1038,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43297 goto out_free_dentry;
43298
43299 /* OK, This is the point of no return */
43300 - current->mm->def_flags = def_flags;
43301 +
43302 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43303 + current->mm->pax_flags = 0UL;
43304 +#endif
43305 +
43306 +#ifdef CONFIG_PAX_DLRESOLVE
43307 + current->mm->call_dl_resolve = 0UL;
43308 +#endif
43309 +
43310 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43311 + current->mm->call_syscall = 0UL;
43312 +#endif
43313 +
43314 +#ifdef CONFIG_PAX_ASLR
43315 + current->mm->delta_mmap = 0UL;
43316 + current->mm->delta_stack = 0UL;
43317 +#endif
43318 +
43319 + current->mm->def_flags = 0;
43320 +
43321 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43322 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43323 + send_sig(SIGKILL, current, 0);
43324 + goto out_free_dentry;
43325 + }
43326 +#endif
43327 +
43328 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43329 + pax_set_initial_flags(bprm);
43330 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43331 + if (pax_set_initial_flags_func)
43332 + (pax_set_initial_flags_func)(bprm);
43333 +#endif
43334 +
43335 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43336 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43337 + current->mm->context.user_cs_limit = PAGE_SIZE;
43338 + current->mm->def_flags |= VM_PAGEEXEC;
43339 + }
43340 +#endif
43341 +
43342 +#ifdef CONFIG_PAX_SEGMEXEC
43343 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43344 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43345 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43346 + pax_task_size = SEGMEXEC_TASK_SIZE;
43347 + current->mm->def_flags |= VM_NOHUGEPAGE;
43348 + }
43349 +#endif
43350 +
43351 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43352 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43353 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43354 + put_cpu();
43355 + }
43356 +#endif
43357
43358 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43359 may depend on the personality. */
43360 SET_PERSONALITY(loc->elf_ex);
43361 +
43362 +#ifdef CONFIG_PAX_ASLR
43363 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43364 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43365 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43366 + }
43367 +#endif
43368 +
43369 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43370 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43371 + executable_stack = EXSTACK_DISABLE_X;
43372 + current->personality &= ~READ_IMPLIES_EXEC;
43373 + } else
43374 +#endif
43375 +
43376 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43377 current->personality |= READ_IMPLIES_EXEC;
43378
43379 @@ -802,6 +1203,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43380 #else
43381 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43382 #endif
43383 +
43384 +#ifdef CONFIG_PAX_RANDMMAP
43385 + /* PaX: randomize base address at the default exe base if requested */
43386 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43387 +#ifdef CONFIG_SPARC64
43388 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43389 +#else
43390 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43391 +#endif
43392 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43393 + elf_flags |= MAP_FIXED;
43394 + }
43395 +#endif
43396 +
43397 }
43398
43399 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43400 @@ -834,9 +1249,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43401 * allowed task size. Note that p_filesz must always be
43402 * <= p_memsz so it is only necessary to check p_memsz.
43403 */
43404 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43405 - elf_ppnt->p_memsz > TASK_SIZE ||
43406 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43407 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43408 + elf_ppnt->p_memsz > pax_task_size ||
43409 + pax_task_size - elf_ppnt->p_memsz < k) {
43410 /* set_brk can never work. Avoid overflows. */
43411 send_sig(SIGKILL, current, 0);
43412 retval = -EINVAL;
43413 @@ -875,17 +1290,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43414 goto out_free_dentry;
43415 }
43416 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43417 - send_sig(SIGSEGV, current, 0);
43418 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43419 - goto out_free_dentry;
43420 + /*
43421 + * This bss-zeroing can fail if the ELF
43422 + * file specifies odd protections. So
43423 + * we don't check the return value
43424 + */
43425 }
43426
43427 +#ifdef CONFIG_PAX_RANDMMAP
43428 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43429 + unsigned long start, size;
43430 +
43431 + start = ELF_PAGEALIGN(elf_brk);
43432 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43433 + down_read(&current->mm->mmap_sem);
43434 + retval = -ENOMEM;
43435 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43436 + unsigned long prot = PROT_NONE;
43437 +
43438 + up_read(&current->mm->mmap_sem);
43439 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43440 +// if (current->personality & ADDR_NO_RANDOMIZE)
43441 +// prot = PROT_READ;
43442 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43443 + retval = IS_ERR_VALUE(start) ? start : 0;
43444 + } else
43445 + up_read(&current->mm->mmap_sem);
43446 + if (retval == 0)
43447 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43448 + if (retval < 0) {
43449 + send_sig(SIGKILL, current, 0);
43450 + goto out_free_dentry;
43451 + }
43452 + }
43453 +#endif
43454 +
43455 if (elf_interpreter) {
43456 - unsigned long uninitialized_var(interp_map_addr);
43457 -
43458 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43459 interpreter,
43460 - &interp_map_addr,
43461 load_bias);
43462 if (!IS_ERR((void *)elf_entry)) {
43463 /*
43464 @@ -1107,7 +1549,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43465 * Decide what to dump of a segment, part, all or none.
43466 */
43467 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43468 - unsigned long mm_flags)
43469 + unsigned long mm_flags, long signr)
43470 {
43471 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43472
43473 @@ -1144,7 +1586,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43474 if (vma->vm_file == NULL)
43475 return 0;
43476
43477 - if (FILTER(MAPPED_PRIVATE))
43478 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43479 goto whole;
43480
43481 /*
43482 @@ -1366,9 +1808,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43483 {
43484 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43485 int i = 0;
43486 - do
43487 + do {
43488 i += 2;
43489 - while (auxv[i - 2] != AT_NULL);
43490 + } while (auxv[i - 2] != AT_NULL);
43491 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43492 }
43493
43494 @@ -1879,14 +2321,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43495 }
43496
43497 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43498 - unsigned long mm_flags)
43499 + struct coredump_params *cprm)
43500 {
43501 struct vm_area_struct *vma;
43502 size_t size = 0;
43503
43504 for (vma = first_vma(current, gate_vma); vma != NULL;
43505 vma = next_vma(vma, gate_vma))
43506 - size += vma_dump_size(vma, mm_flags);
43507 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43508 return size;
43509 }
43510
43511 @@ -1980,7 +2422,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43512
43513 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43514
43515 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43516 + offset += elf_core_vma_data_size(gate_vma, cprm);
43517 offset += elf_core_extra_data_size();
43518 e_shoff = offset;
43519
43520 @@ -1994,10 +2436,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43521 offset = dataoff;
43522
43523 size += sizeof(*elf);
43524 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43525 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43526 goto end_coredump;
43527
43528 size += sizeof(*phdr4note);
43529 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43530 if (size > cprm->limit
43531 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43532 goto end_coredump;
43533 @@ -2011,7 +2455,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43534 phdr.p_offset = offset;
43535 phdr.p_vaddr = vma->vm_start;
43536 phdr.p_paddr = 0;
43537 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43538 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43539 phdr.p_memsz = vma->vm_end - vma->vm_start;
43540 offset += phdr.p_filesz;
43541 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43542 @@ -2022,6 +2466,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43543 phdr.p_align = ELF_EXEC_PAGESIZE;
43544
43545 size += sizeof(phdr);
43546 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43547 if (size > cprm->limit
43548 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43549 goto end_coredump;
43550 @@ -2046,7 +2491,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43551 unsigned long addr;
43552 unsigned long end;
43553
43554 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43555 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43556
43557 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43558 struct page *page;
43559 @@ -2055,6 +2500,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43560 page = get_dump_page(addr);
43561 if (page) {
43562 void *kaddr = kmap(page);
43563 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43564 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43565 !dump_write(cprm->file, kaddr,
43566 PAGE_SIZE);
43567 @@ -2072,6 +2518,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43568
43569 if (e_phnum == PN_XNUM) {
43570 size += sizeof(*shdr4extnum);
43571 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43572 if (size > cprm->limit
43573 || !dump_write(cprm->file, shdr4extnum,
43574 sizeof(*shdr4extnum)))
43575 @@ -2092,6 +2539,97 @@ out:
43576
43577 #endif /* CONFIG_ELF_CORE */
43578
43579 +#ifdef CONFIG_PAX_MPROTECT
43580 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43581 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43582 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43583 + *
43584 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43585 + * basis because we want to allow the common case and not the special ones.
43586 + */
43587 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43588 +{
43589 + struct elfhdr elf_h;
43590 + struct elf_phdr elf_p;
43591 + unsigned long i;
43592 + unsigned long oldflags;
43593 + bool is_textrel_rw, is_textrel_rx, is_relro;
43594 +
43595 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43596 + return;
43597 +
43598 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43599 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43600 +
43601 +#ifdef CONFIG_PAX_ELFRELOCS
43602 + /* possible TEXTREL */
43603 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43604 + 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);
43605 +#else
43606 + is_textrel_rw = false;
43607 + is_textrel_rx = false;
43608 +#endif
43609 +
43610 + /* possible RELRO */
43611 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43612 +
43613 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43614 + return;
43615 +
43616 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43617 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43618 +
43619 +#ifdef CONFIG_PAX_ETEXECRELOCS
43620 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43621 +#else
43622 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43623 +#endif
43624 +
43625 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43626 + !elf_check_arch(&elf_h) ||
43627 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43628 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43629 + return;
43630 +
43631 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43632 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43633 + return;
43634 + switch (elf_p.p_type) {
43635 + case PT_DYNAMIC:
43636 + if (!is_textrel_rw && !is_textrel_rx)
43637 + continue;
43638 + i = 0UL;
43639 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43640 + elf_dyn dyn;
43641 +
43642 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43643 + return;
43644 + if (dyn.d_tag == DT_NULL)
43645 + return;
43646 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43647 + gr_log_textrel(vma);
43648 + if (is_textrel_rw)
43649 + vma->vm_flags |= VM_MAYWRITE;
43650 + else
43651 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43652 + vma->vm_flags &= ~VM_MAYWRITE;
43653 + return;
43654 + }
43655 + i++;
43656 + }
43657 + return;
43658 +
43659 + case PT_GNU_RELRO:
43660 + if (!is_relro)
43661 + continue;
43662 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43663 + vma->vm_flags &= ~VM_MAYWRITE;
43664 + return;
43665 + }
43666 + }
43667 +}
43668 +#endif
43669 +
43670 static int __init init_elf_binfmt(void)
43671 {
43672 register_binfmt(&elf_format);
43673 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43674 index 178cb70..8972997 100644
43675 --- a/fs/binfmt_flat.c
43676 +++ b/fs/binfmt_flat.c
43677 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43678 realdatastart = (unsigned long) -ENOMEM;
43679 printk("Unable to allocate RAM for process data, errno %d\n",
43680 (int)-realdatastart);
43681 + down_write(&current->mm->mmap_sem);
43682 vm_munmap(textpos, text_len);
43683 + up_write(&current->mm->mmap_sem);
43684 ret = realdatastart;
43685 goto err;
43686 }
43687 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43688 }
43689 if (IS_ERR_VALUE(result)) {
43690 printk("Unable to read data+bss, errno %d\n", (int)-result);
43691 + down_write(&current->mm->mmap_sem);
43692 vm_munmap(textpos, text_len);
43693 vm_munmap(realdatastart, len);
43694 + up_write(&current->mm->mmap_sem);
43695 ret = result;
43696 goto err;
43697 }
43698 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43699 }
43700 if (IS_ERR_VALUE(result)) {
43701 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43702 + down_write(&current->mm->mmap_sem);
43703 vm_munmap(textpos, text_len + data_len + extra +
43704 MAX_SHARED_LIBS * sizeof(unsigned long));
43705 + up_write(&current->mm->mmap_sem);
43706 ret = result;
43707 goto err;
43708 }
43709 diff --git a/fs/bio.c b/fs/bio.c
43710 index 71072ab..439851b 100644
43711 --- a/fs/bio.c
43712 +++ b/fs/bio.c
43713 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43714 /*
43715 * Overflow, abort
43716 */
43717 - if (end < start)
43718 + if (end < start || end - start > INT_MAX - nr_pages)
43719 return ERR_PTR(-EINVAL);
43720
43721 nr_pages += end - start;
43722 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43723 /*
43724 * Overflow, abort
43725 */
43726 - if (end < start)
43727 + if (end < start || end - start > INT_MAX - nr_pages)
43728 return ERR_PTR(-EINVAL);
43729
43730 nr_pages += end - start;
43731 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43732 const int read = bio_data_dir(bio) == READ;
43733 struct bio_map_data *bmd = bio->bi_private;
43734 int i;
43735 - char *p = bmd->sgvecs[0].iov_base;
43736 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43737
43738 __bio_for_each_segment(bvec, bio, i, 0) {
43739 char *addr = page_address(bvec->bv_page);
43740 diff --git a/fs/block_dev.c b/fs/block_dev.c
43741 index 38e721b..7a9c5bc 100644
43742 --- a/fs/block_dev.c
43743 +++ b/fs/block_dev.c
43744 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43745 else if (bdev->bd_contains == bdev)
43746 return true; /* is a whole device which isn't held */
43747
43748 - else if (whole->bd_holder == bd_may_claim)
43749 + else if (whole->bd_holder == (void *)bd_may_claim)
43750 return true; /* is a partition of a device that is being partitioned */
43751 else if (whole->bd_holder != NULL)
43752 return false; /* is a partition of a held device */
43753 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43754 index 9197e2e..7f731f8 100644
43755 --- a/fs/btrfs/check-integrity.c
43756 +++ b/fs/btrfs/check-integrity.c
43757 @@ -155,7 +155,7 @@ struct btrfsic_block {
43758 union {
43759 bio_end_io_t *bio;
43760 bh_end_io_t *bh;
43761 - } orig_bio_bh_end_io;
43762 + } __no_const orig_bio_bh_end_io;
43763 int submit_bio_bh_rw;
43764 u64 flush_gen; /* only valid if !never_written */
43765 };
43766 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43767 index 6d183f6..f47cc7a 100644
43768 --- a/fs/btrfs/ctree.c
43769 +++ b/fs/btrfs/ctree.c
43770 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43771 free_extent_buffer(buf);
43772 add_root_to_dirty_list(root);
43773 } else {
43774 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43775 - parent_start = parent->start;
43776 - else
43777 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43778 + if (parent)
43779 + parent_start = parent->start;
43780 + else
43781 + parent_start = 0;
43782 + } else
43783 parent_start = 0;
43784
43785 WARN_ON(trans->transid != btrfs_header_generation(parent));
43786 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43787 index ec154f9..bf617a7 100644
43788 --- a/fs/btrfs/inode.c
43789 +++ b/fs/btrfs/inode.c
43790 @@ -7126,7 +7126,7 @@ fail:
43791 return -ENOMEM;
43792 }
43793
43794 -static int btrfs_getattr(struct vfsmount *mnt,
43795 +int btrfs_getattr(struct vfsmount *mnt,
43796 struct dentry *dentry, struct kstat *stat)
43797 {
43798 struct inode *inode = dentry->d_inode;
43799 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43800 return 0;
43801 }
43802
43803 +EXPORT_SYMBOL(btrfs_getattr);
43804 +
43805 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43806 +{
43807 + return BTRFS_I(inode)->root->anon_dev;
43808 +}
43809 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43810 +
43811 /*
43812 * If a file is moved, it will inherit the cow and compression flags of the new
43813 * directory.
43814 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43815 index 9df50fa..6cd20d0 100644
43816 --- a/fs/btrfs/ioctl.c
43817 +++ b/fs/btrfs/ioctl.c
43818 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43819 for (i = 0; i < num_types; i++) {
43820 struct btrfs_space_info *tmp;
43821
43822 + /* Don't copy in more than we allocated */
43823 if (!slot_count)
43824 break;
43825
43826 + slot_count--;
43827 +
43828 info = NULL;
43829 rcu_read_lock();
43830 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43831 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43832 memcpy(dest, &space, sizeof(space));
43833 dest++;
43834 space_args.total_spaces++;
43835 - slot_count--;
43836 }
43837 - if (!slot_count)
43838 - break;
43839 }
43840 up_read(&info->groups_sem);
43841 }
43842 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43843 index 4da0865..01c4778 100644
43844 --- a/fs/btrfs/relocation.c
43845 +++ b/fs/btrfs/relocation.c
43846 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43847 }
43848 spin_unlock(&rc->reloc_root_tree.lock);
43849
43850 - BUG_ON((struct btrfs_root *)node->data != root);
43851 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43852
43853 if (!del) {
43854 spin_lock(&rc->reloc_root_tree.lock);
43855 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43856 index 622f469..e8d2d55 100644
43857 --- a/fs/cachefiles/bind.c
43858 +++ b/fs/cachefiles/bind.c
43859 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43860 args);
43861
43862 /* start by checking things over */
43863 - ASSERT(cache->fstop_percent >= 0 &&
43864 - cache->fstop_percent < cache->fcull_percent &&
43865 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43866 cache->fcull_percent < cache->frun_percent &&
43867 cache->frun_percent < 100);
43868
43869 - ASSERT(cache->bstop_percent >= 0 &&
43870 - cache->bstop_percent < cache->bcull_percent &&
43871 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43872 cache->bcull_percent < cache->brun_percent &&
43873 cache->brun_percent < 100);
43874
43875 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43876 index 0a1467b..6a53245 100644
43877 --- a/fs/cachefiles/daemon.c
43878 +++ b/fs/cachefiles/daemon.c
43879 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43880 if (n > buflen)
43881 return -EMSGSIZE;
43882
43883 - if (copy_to_user(_buffer, buffer, n) != 0)
43884 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43885 return -EFAULT;
43886
43887 return n;
43888 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43889 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43890 return -EIO;
43891
43892 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43893 + if (datalen > PAGE_SIZE - 1)
43894 return -EOPNOTSUPP;
43895
43896 /* drag the command string into the kernel so we can parse it */
43897 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43898 if (args[0] != '%' || args[1] != '\0')
43899 return -EINVAL;
43900
43901 - if (fstop < 0 || fstop >= cache->fcull_percent)
43902 + if (fstop >= cache->fcull_percent)
43903 return cachefiles_daemon_range_error(cache, args);
43904
43905 cache->fstop_percent = fstop;
43906 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43907 if (args[0] != '%' || args[1] != '\0')
43908 return -EINVAL;
43909
43910 - if (bstop < 0 || bstop >= cache->bcull_percent)
43911 + if (bstop >= cache->bcull_percent)
43912 return cachefiles_daemon_range_error(cache, args);
43913
43914 cache->bstop_percent = bstop;
43915 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43916 index bd6bc1b..b627b53 100644
43917 --- a/fs/cachefiles/internal.h
43918 +++ b/fs/cachefiles/internal.h
43919 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43920 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43921 struct rb_root active_nodes; /* active nodes (can't be culled) */
43922 rwlock_t active_lock; /* lock for active_nodes */
43923 - atomic_t gravecounter; /* graveyard uniquifier */
43924 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43925 unsigned frun_percent; /* when to stop culling (% files) */
43926 unsigned fcull_percent; /* when to start culling (% files) */
43927 unsigned fstop_percent; /* when to stop allocating (% files) */
43928 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43929 * proc.c
43930 */
43931 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43932 -extern atomic_t cachefiles_lookup_histogram[HZ];
43933 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43934 -extern atomic_t cachefiles_create_histogram[HZ];
43935 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43936 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43937 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43938
43939 extern int __init cachefiles_proc_init(void);
43940 extern void cachefiles_proc_cleanup(void);
43941 static inline
43942 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43943 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43944 {
43945 unsigned long jif = jiffies - start_jif;
43946 if (jif >= HZ)
43947 jif = HZ - 1;
43948 - atomic_inc(&histogram[jif]);
43949 + atomic_inc_unchecked(&histogram[jif]);
43950 }
43951
43952 #else
43953 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43954 index b0b5f7c..039bb26 100644
43955 --- a/fs/cachefiles/namei.c
43956 +++ b/fs/cachefiles/namei.c
43957 @@ -318,7 +318,7 @@ try_again:
43958 /* first step is to make up a grave dentry in the graveyard */
43959 sprintf(nbuffer, "%08x%08x",
43960 (uint32_t) get_seconds(),
43961 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43962 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43963
43964 /* do the multiway lock magic */
43965 trap = lock_rename(cache->graveyard, dir);
43966 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43967 index eccd339..4c1d995 100644
43968 --- a/fs/cachefiles/proc.c
43969 +++ b/fs/cachefiles/proc.c
43970 @@ -14,9 +14,9 @@
43971 #include <linux/seq_file.h>
43972 #include "internal.h"
43973
43974 -atomic_t cachefiles_lookup_histogram[HZ];
43975 -atomic_t cachefiles_mkdir_histogram[HZ];
43976 -atomic_t cachefiles_create_histogram[HZ];
43977 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43978 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43979 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43980
43981 /*
43982 * display the latency histogram
43983 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43984 return 0;
43985 default:
43986 index = (unsigned long) v - 3;
43987 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43988 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43989 - z = atomic_read(&cachefiles_create_histogram[index]);
43990 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43991 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43992 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43993 if (x == 0 && y == 0 && z == 0)
43994 return 0;
43995
43996 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43997 index c994691..2a1537f 100644
43998 --- a/fs/cachefiles/rdwr.c
43999 +++ b/fs/cachefiles/rdwr.c
44000 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44001 old_fs = get_fs();
44002 set_fs(KERNEL_DS);
44003 ret = file->f_op->write(
44004 - file, (const void __user *) data, len, &pos);
44005 + file, (const void __force_user *) data, len, &pos);
44006 set_fs(old_fs);
44007 kunmap(page);
44008 if (ret != len)
44009 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44010 index e5b7731..b9c59fb 100644
44011 --- a/fs/ceph/dir.c
44012 +++ b/fs/ceph/dir.c
44013 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44014 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44015 struct ceph_mds_client *mdsc = fsc->mdsc;
44016 unsigned frag = fpos_frag(filp->f_pos);
44017 - int off = fpos_off(filp->f_pos);
44018 + unsigned int off = fpos_off(filp->f_pos);
44019 int err;
44020 u32 ftype;
44021 struct ceph_mds_reply_info_parsed *rinfo;
44022 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44023 index d9ea6ed..1e6c8ac 100644
44024 --- a/fs/cifs/cifs_debug.c
44025 +++ b/fs/cifs/cifs_debug.c
44026 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44027
44028 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44029 #ifdef CONFIG_CIFS_STATS2
44030 - atomic_set(&totBufAllocCount, 0);
44031 - atomic_set(&totSmBufAllocCount, 0);
44032 + atomic_set_unchecked(&totBufAllocCount, 0);
44033 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44034 #endif /* CONFIG_CIFS_STATS2 */
44035 spin_lock(&cifs_tcp_ses_lock);
44036 list_for_each(tmp1, &cifs_tcp_ses_list) {
44037 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44038 tcon = list_entry(tmp3,
44039 struct cifs_tcon,
44040 tcon_list);
44041 - atomic_set(&tcon->num_smbs_sent, 0);
44042 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44043 if (server->ops->clear_stats)
44044 server->ops->clear_stats(tcon);
44045 }
44046 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44047 smBufAllocCount.counter, cifs_min_small);
44048 #ifdef CONFIG_CIFS_STATS2
44049 seq_printf(m, "Total Large %d Small %d Allocations\n",
44050 - atomic_read(&totBufAllocCount),
44051 - atomic_read(&totSmBufAllocCount));
44052 + atomic_read_unchecked(&totBufAllocCount),
44053 + atomic_read_unchecked(&totSmBufAllocCount));
44054 #endif /* CONFIG_CIFS_STATS2 */
44055
44056 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44057 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44058 if (tcon->need_reconnect)
44059 seq_puts(m, "\tDISCONNECTED ");
44060 seq_printf(m, "\nSMBs: %d",
44061 - atomic_read(&tcon->num_smbs_sent));
44062 + atomic_read_unchecked(&tcon->num_smbs_sent));
44063 if (server->ops->print_stats)
44064 server->ops->print_stats(m, tcon);
44065 }
44066 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44067 index db8a404..c712e2e 100644
44068 --- a/fs/cifs/cifsfs.c
44069 +++ b/fs/cifs/cifsfs.c
44070 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44071 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44072 cifs_req_cachep = kmem_cache_create("cifs_request",
44073 CIFSMaxBufSize + max_hdr_size, 0,
44074 - SLAB_HWCACHE_ALIGN, NULL);
44075 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44076 if (cifs_req_cachep == NULL)
44077 return -ENOMEM;
44078
44079 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44080 efficient to alloc 1 per page off the slab compared to 17K (5page)
44081 alloc of large cifs buffers even when page debugging is on */
44082 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44083 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44084 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44085 NULL);
44086 if (cifs_sm_req_cachep == NULL) {
44087 mempool_destroy(cifs_req_poolp);
44088 @@ -1115,8 +1115,8 @@ init_cifs(void)
44089 atomic_set(&bufAllocCount, 0);
44090 atomic_set(&smBufAllocCount, 0);
44091 #ifdef CONFIG_CIFS_STATS2
44092 - atomic_set(&totBufAllocCount, 0);
44093 - atomic_set(&totSmBufAllocCount, 0);
44094 + atomic_set_unchecked(&totBufAllocCount, 0);
44095 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44096 #endif /* CONFIG_CIFS_STATS2 */
44097
44098 atomic_set(&midCount, 0);
44099 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44100 index 977dc0e..ba48ab9 100644
44101 --- a/fs/cifs/cifsglob.h
44102 +++ b/fs/cifs/cifsglob.h
44103 @@ -590,35 +590,35 @@ struct cifs_tcon {
44104 __u16 Flags; /* optional support bits */
44105 enum statusEnum tidStatus;
44106 #ifdef CONFIG_CIFS_STATS
44107 - atomic_t num_smbs_sent;
44108 + atomic_unchecked_t num_smbs_sent;
44109 union {
44110 struct {
44111 - atomic_t num_writes;
44112 - atomic_t num_reads;
44113 - atomic_t num_flushes;
44114 - atomic_t num_oplock_brks;
44115 - atomic_t num_opens;
44116 - atomic_t num_closes;
44117 - atomic_t num_deletes;
44118 - atomic_t num_mkdirs;
44119 - atomic_t num_posixopens;
44120 - atomic_t num_posixmkdirs;
44121 - atomic_t num_rmdirs;
44122 - atomic_t num_renames;
44123 - atomic_t num_t2renames;
44124 - atomic_t num_ffirst;
44125 - atomic_t num_fnext;
44126 - atomic_t num_fclose;
44127 - atomic_t num_hardlinks;
44128 - atomic_t num_symlinks;
44129 - atomic_t num_locks;
44130 - atomic_t num_acl_get;
44131 - atomic_t num_acl_set;
44132 + atomic_unchecked_t num_writes;
44133 + atomic_unchecked_t num_reads;
44134 + atomic_unchecked_t num_flushes;
44135 + atomic_unchecked_t num_oplock_brks;
44136 + atomic_unchecked_t num_opens;
44137 + atomic_unchecked_t num_closes;
44138 + atomic_unchecked_t num_deletes;
44139 + atomic_unchecked_t num_mkdirs;
44140 + atomic_unchecked_t num_posixopens;
44141 + atomic_unchecked_t num_posixmkdirs;
44142 + atomic_unchecked_t num_rmdirs;
44143 + atomic_unchecked_t num_renames;
44144 + atomic_unchecked_t num_t2renames;
44145 + atomic_unchecked_t num_ffirst;
44146 + atomic_unchecked_t num_fnext;
44147 + atomic_unchecked_t num_fclose;
44148 + atomic_unchecked_t num_hardlinks;
44149 + atomic_unchecked_t num_symlinks;
44150 + atomic_unchecked_t num_locks;
44151 + atomic_unchecked_t num_acl_get;
44152 + atomic_unchecked_t num_acl_set;
44153 } cifs_stats;
44154 #ifdef CONFIG_CIFS_SMB2
44155 struct {
44156 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44157 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44158 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44159 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44160 } smb2_stats;
44161 #endif /* CONFIG_CIFS_SMB2 */
44162 } stats;
44163 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44164 }
44165
44166 #ifdef CONFIG_CIFS_STATS
44167 -#define cifs_stats_inc atomic_inc
44168 +#define cifs_stats_inc atomic_inc_unchecked
44169
44170 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44171 unsigned int bytes)
44172 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44173 /* Various Debug counters */
44174 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44175 #ifdef CONFIG_CIFS_STATS2
44176 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44177 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44178 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44179 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44180 #endif
44181 GLOBAL_EXTERN atomic_t smBufAllocCount;
44182 GLOBAL_EXTERN atomic_t midCount;
44183 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44184 index e6ce3b1..adc21fd 100644
44185 --- a/fs/cifs/link.c
44186 +++ b/fs/cifs/link.c
44187 @@ -602,7 +602,7 @@ symlink_exit:
44188
44189 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44190 {
44191 - char *p = nd_get_link(nd);
44192 + const char *p = nd_get_link(nd);
44193 if (!IS_ERR(p))
44194 kfree(p);
44195 }
44196 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44197 index ce41fee..ac0d27a 100644
44198 --- a/fs/cifs/misc.c
44199 +++ b/fs/cifs/misc.c
44200 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44201 memset(ret_buf, 0, buf_size + 3);
44202 atomic_inc(&bufAllocCount);
44203 #ifdef CONFIG_CIFS_STATS2
44204 - atomic_inc(&totBufAllocCount);
44205 + atomic_inc_unchecked(&totBufAllocCount);
44206 #endif /* CONFIG_CIFS_STATS2 */
44207 }
44208
44209 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44210 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44211 atomic_inc(&smBufAllocCount);
44212 #ifdef CONFIG_CIFS_STATS2
44213 - atomic_inc(&totSmBufAllocCount);
44214 + atomic_inc_unchecked(&totSmBufAllocCount);
44215 #endif /* CONFIG_CIFS_STATS2 */
44216
44217 }
44218 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44219 index 3129ac7..cc4a948 100644
44220 --- a/fs/cifs/smb1ops.c
44221 +++ b/fs/cifs/smb1ops.c
44222 @@ -524,27 +524,27 @@ static void
44223 cifs_clear_stats(struct cifs_tcon *tcon)
44224 {
44225 #ifdef CONFIG_CIFS_STATS
44226 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44227 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44228 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44229 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44230 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44231 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44232 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44233 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44234 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44235 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44236 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44237 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44238 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44239 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44240 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44241 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44242 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44243 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44244 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44245 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44246 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44247 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44248 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44249 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44250 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44251 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44252 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44253 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44254 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44255 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44256 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44257 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44258 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44259 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44260 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44261 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44262 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44263 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44264 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44265 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44266 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44267 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44268 #endif
44269 }
44270
44271 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44272 {
44273 #ifdef CONFIG_CIFS_STATS
44274 seq_printf(m, " Oplocks breaks: %d",
44275 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44276 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44277 seq_printf(m, "\nReads: %d Bytes: %llu",
44278 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44279 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44280 (long long)(tcon->bytes_read));
44281 seq_printf(m, "\nWrites: %d Bytes: %llu",
44282 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44283 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44284 (long long)(tcon->bytes_written));
44285 seq_printf(m, "\nFlushes: %d",
44286 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44287 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44288 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44289 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44290 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44291 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44292 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44293 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44294 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44295 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44296 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44297 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44298 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44299 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44300 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44301 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44302 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44303 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44304 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44305 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44306 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44307 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44308 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44309 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44310 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44311 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44312 seq_printf(m, "\nRenames: %d T2 Renames %d",
44313 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44314 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44315 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44316 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44317 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44318 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44319 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44320 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44321 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44322 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44323 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44324 #endif
44325 }
44326
44327 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44328 index 826209b..fa460f4 100644
44329 --- a/fs/cifs/smb2ops.c
44330 +++ b/fs/cifs/smb2ops.c
44331 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44332 #ifdef CONFIG_CIFS_STATS
44333 int i;
44334 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44335 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44336 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44337 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44338 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44339 }
44340 #endif
44341 }
44342 @@ -229,66 +229,66 @@ static void
44343 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44344 {
44345 #ifdef CONFIG_CIFS_STATS
44346 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44347 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44348 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44349 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44350 seq_printf(m, "\nNegotiates: %d sent %d failed",
44351 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44352 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44353 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44354 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44355 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44356 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44357 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44358 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44359 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44360 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44361 seq_printf(m, "\nLogoffs: %d sent %d failed",
44362 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44363 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44364 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44365 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44366 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44367 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44368 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44369 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44370 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44371 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44372 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44373 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44374 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44375 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44376 seq_printf(m, "\nCreates: %d sent %d failed",
44377 - atomic_read(&sent[SMB2_CREATE_HE]),
44378 - atomic_read(&failed[SMB2_CREATE_HE]));
44379 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44380 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44381 seq_printf(m, "\nCloses: %d sent %d failed",
44382 - atomic_read(&sent[SMB2_CLOSE_HE]),
44383 - atomic_read(&failed[SMB2_CLOSE_HE]));
44384 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44385 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44386 seq_printf(m, "\nFlushes: %d sent %d failed",
44387 - atomic_read(&sent[SMB2_FLUSH_HE]),
44388 - atomic_read(&failed[SMB2_FLUSH_HE]));
44389 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44390 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44391 seq_printf(m, "\nReads: %d sent %d failed",
44392 - atomic_read(&sent[SMB2_READ_HE]),
44393 - atomic_read(&failed[SMB2_READ_HE]));
44394 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44395 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44396 seq_printf(m, "\nWrites: %d sent %d failed",
44397 - atomic_read(&sent[SMB2_WRITE_HE]),
44398 - atomic_read(&failed[SMB2_WRITE_HE]));
44399 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44400 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44401 seq_printf(m, "\nLocks: %d sent %d failed",
44402 - atomic_read(&sent[SMB2_LOCK_HE]),
44403 - atomic_read(&failed[SMB2_LOCK_HE]));
44404 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44405 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44406 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44407 - atomic_read(&sent[SMB2_IOCTL_HE]),
44408 - atomic_read(&failed[SMB2_IOCTL_HE]));
44409 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44410 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44411 seq_printf(m, "\nCancels: %d sent %d failed",
44412 - atomic_read(&sent[SMB2_CANCEL_HE]),
44413 - atomic_read(&failed[SMB2_CANCEL_HE]));
44414 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44415 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44416 seq_printf(m, "\nEchos: %d sent %d failed",
44417 - atomic_read(&sent[SMB2_ECHO_HE]),
44418 - atomic_read(&failed[SMB2_ECHO_HE]));
44419 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44420 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44421 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44422 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44423 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44424 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44425 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44426 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44427 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44428 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44429 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44430 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44431 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44432 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44433 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44434 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44435 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44436 seq_printf(m, "\nSetInfos: %d sent %d failed",
44437 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44438 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44439 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44440 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44441 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44442 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44443 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44444 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44445 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44446 #endif
44447 }
44448
44449 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44450 index 958ae0e..505c9d0 100644
44451 --- a/fs/coda/cache.c
44452 +++ b/fs/coda/cache.c
44453 @@ -24,7 +24,7 @@
44454 #include "coda_linux.h"
44455 #include "coda_cache.h"
44456
44457 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44458 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44459
44460 /* replace or extend an acl cache hit */
44461 void coda_cache_enter(struct inode *inode, int mask)
44462 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44463 struct coda_inode_info *cii = ITOC(inode);
44464
44465 spin_lock(&cii->c_lock);
44466 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44467 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44468 if (cii->c_uid != current_fsuid()) {
44469 cii->c_uid = current_fsuid();
44470 cii->c_cached_perm = mask;
44471 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44472 {
44473 struct coda_inode_info *cii = ITOC(inode);
44474 spin_lock(&cii->c_lock);
44475 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44476 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44477 spin_unlock(&cii->c_lock);
44478 }
44479
44480 /* remove all acl caches */
44481 void coda_cache_clear_all(struct super_block *sb)
44482 {
44483 - atomic_inc(&permission_epoch);
44484 + atomic_inc_unchecked(&permission_epoch);
44485 }
44486
44487
44488 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44489 spin_lock(&cii->c_lock);
44490 hit = (mask & cii->c_cached_perm) == mask &&
44491 cii->c_uid == current_fsuid() &&
44492 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44493 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44494 spin_unlock(&cii->c_lock);
44495
44496 return hit;
44497 diff --git a/fs/compat.c b/fs/compat.c
44498 index 1bdb350..9f28287 100644
44499 --- a/fs/compat.c
44500 +++ b/fs/compat.c
44501 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44502
44503 set_fs(KERNEL_DS);
44504 /* The __user pointer cast is valid because of the set_fs() */
44505 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44506 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44507 set_fs(oldfs);
44508 /* truncating is ok because it's a user address */
44509 if (!ret)
44510 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44511 goto out;
44512
44513 ret = -EINVAL;
44514 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44515 + if (nr_segs > UIO_MAXIOV)
44516 goto out;
44517 if (nr_segs > fast_segs) {
44518 ret = -ENOMEM;
44519 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44520
44521 struct compat_readdir_callback {
44522 struct compat_old_linux_dirent __user *dirent;
44523 + struct file * file;
44524 int result;
44525 };
44526
44527 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44528 buf->result = -EOVERFLOW;
44529 return -EOVERFLOW;
44530 }
44531 +
44532 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44533 + return 0;
44534 +
44535 buf->result++;
44536 dirent = buf->dirent;
44537 if (!access_ok(VERIFY_WRITE, dirent,
44538 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44539
44540 buf.result = 0;
44541 buf.dirent = dirent;
44542 + buf.file = file;
44543
44544 error = vfs_readdir(file, compat_fillonedir, &buf);
44545 if (buf.result)
44546 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44547 struct compat_getdents_callback {
44548 struct compat_linux_dirent __user *current_dir;
44549 struct compat_linux_dirent __user *previous;
44550 + struct file * file;
44551 int count;
44552 int error;
44553 };
44554 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44555 buf->error = -EOVERFLOW;
44556 return -EOVERFLOW;
44557 }
44558 +
44559 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44560 + return 0;
44561 +
44562 dirent = buf->previous;
44563 if (dirent) {
44564 if (__put_user(offset, &dirent->d_off))
44565 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44566 buf.previous = NULL;
44567 buf.count = count;
44568 buf.error = 0;
44569 + buf.file = file;
44570
44571 error = vfs_readdir(file, compat_filldir, &buf);
44572 if (error >= 0)
44573 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44574 struct compat_getdents_callback64 {
44575 struct linux_dirent64 __user *current_dir;
44576 struct linux_dirent64 __user *previous;
44577 + struct file * file;
44578 int count;
44579 int error;
44580 };
44581 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44582 buf->error = -EINVAL; /* only used if we fail.. */
44583 if (reclen > buf->count)
44584 return -EINVAL;
44585 +
44586 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44587 + return 0;
44588 +
44589 dirent = buf->previous;
44590
44591 if (dirent) {
44592 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44593 buf.previous = NULL;
44594 buf.count = count;
44595 buf.error = 0;
44596 + buf.file = file;
44597
44598 error = vfs_readdir(file, compat_filldir64, &buf);
44599 if (error >= 0)
44600 error = buf.error;
44601 lastdirent = buf.previous;
44602 if (lastdirent) {
44603 - typeof(lastdirent->d_off) d_off = file->f_pos;
44604 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44605 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44606 error = -EFAULT;
44607 else
44608 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44609 index 112e45a..b59845b 100644
44610 --- a/fs/compat_binfmt_elf.c
44611 +++ b/fs/compat_binfmt_elf.c
44612 @@ -30,11 +30,13 @@
44613 #undef elf_phdr
44614 #undef elf_shdr
44615 #undef elf_note
44616 +#undef elf_dyn
44617 #undef elf_addr_t
44618 #define elfhdr elf32_hdr
44619 #define elf_phdr elf32_phdr
44620 #define elf_shdr elf32_shdr
44621 #define elf_note elf32_note
44622 +#define elf_dyn Elf32_Dyn
44623 #define elf_addr_t Elf32_Addr
44624
44625 /*
44626 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44627 index debdfe0..75d31d4 100644
44628 --- a/fs/compat_ioctl.c
44629 +++ b/fs/compat_ioctl.c
44630 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44631
44632 err = get_user(palp, &up->palette);
44633 err |= get_user(length, &up->length);
44634 + if (err)
44635 + return -EFAULT;
44636
44637 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44638 err = put_user(compat_ptr(palp), &up_native->palette);
44639 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44640 return -EFAULT;
44641 if (__get_user(udata, &ss32->iomem_base))
44642 return -EFAULT;
44643 - ss.iomem_base = compat_ptr(udata);
44644 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44645 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44646 __get_user(ss.port_high, &ss32->port_high))
44647 return -EFAULT;
44648 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44649 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44650 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44651 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44652 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44653 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44654 return -EFAULT;
44655
44656 return ioctl_preallocate(file, p);
44657 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44658 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44659 {
44660 unsigned int a, b;
44661 - a = *(unsigned int *)p;
44662 - b = *(unsigned int *)q;
44663 + a = *(const unsigned int *)p;
44664 + b = *(const unsigned int *)q;
44665 if (a > b)
44666 return 1;
44667 if (a < b)
44668 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44669 index 7414ae2..d98ad6d 100644
44670 --- a/fs/configfs/dir.c
44671 +++ b/fs/configfs/dir.c
44672 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44673 }
44674 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44675 struct configfs_dirent *next;
44676 - const char * name;
44677 + const unsigned char * name;
44678 + char d_name[sizeof(next->s_dentry->d_iname)];
44679 int len;
44680 struct inode *inode = NULL;
44681
44682 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44683 continue;
44684
44685 name = configfs_get_name(next);
44686 - len = strlen(name);
44687 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44688 + len = next->s_dentry->d_name.len;
44689 + memcpy(d_name, name, len);
44690 + name = d_name;
44691 + } else
44692 + len = strlen(name);
44693
44694 /*
44695 * We'll have a dentry and an inode for
44696 diff --git a/fs/dcache.c b/fs/dcache.c
44697 index 693f95b..95f1223 100644
44698 --- a/fs/dcache.c
44699 +++ b/fs/dcache.c
44700 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44701 mempages -= reserve;
44702
44703 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44704 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44705 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44706
44707 dcache_init();
44708 inode_init();
44709 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44710 index 4733eab..71ef6fa 100644
44711 --- a/fs/debugfs/inode.c
44712 +++ b/fs/debugfs/inode.c
44713 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44714 */
44715 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44716 {
44717 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44718 + return __create_file(name, S_IFDIR | S_IRWXU,
44719 +#else
44720 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44721 +#endif
44722 parent, NULL, NULL);
44723 }
44724 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44725 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44726 index cc7709e..7e7211f 100644
44727 --- a/fs/ecryptfs/inode.c
44728 +++ b/fs/ecryptfs/inode.c
44729 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44730 old_fs = get_fs();
44731 set_fs(get_ds());
44732 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44733 - (char __user *)lower_buf,
44734 + (char __force_user *)lower_buf,
44735 PATH_MAX);
44736 set_fs(old_fs);
44737 if (rc < 0)
44738 @@ -706,7 +706,7 @@ out:
44739 static void
44740 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44741 {
44742 - char *buf = nd_get_link(nd);
44743 + const char *buf = nd_get_link(nd);
44744 if (!IS_ERR(buf)) {
44745 /* Free the char* */
44746 kfree(buf);
44747 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44748 index 412e6ed..4292d22 100644
44749 --- a/fs/ecryptfs/miscdev.c
44750 +++ b/fs/ecryptfs/miscdev.c
44751 @@ -315,7 +315,7 @@ check_list:
44752 goto out_unlock_msg_ctx;
44753 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44754 if (msg_ctx->msg) {
44755 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44756 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44757 goto out_unlock_msg_ctx;
44758 i += packet_length_size;
44759 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44760 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44761 index b2a34a1..162fa69 100644
44762 --- a/fs/ecryptfs/read_write.c
44763 +++ b/fs/ecryptfs/read_write.c
44764 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44765 return -EIO;
44766 fs_save = get_fs();
44767 set_fs(get_ds());
44768 - rc = vfs_write(lower_file, data, size, &offset);
44769 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44770 set_fs(fs_save);
44771 mark_inode_dirty_sync(ecryptfs_inode);
44772 return rc;
44773 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44774 return -EIO;
44775 fs_save = get_fs();
44776 set_fs(get_ds());
44777 - rc = vfs_read(lower_file, data, size, &offset);
44778 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44779 set_fs(fs_save);
44780 return rc;
44781 }
44782 diff --git a/fs/exec.c b/fs/exec.c
44783 index 574cf4d..dfe774a 100644
44784 --- a/fs/exec.c
44785 +++ b/fs/exec.c
44786 @@ -55,6 +55,15 @@
44787 #include <linux/pipe_fs_i.h>
44788 #include <linux/oom.h>
44789 #include <linux/compat.h>
44790 +#include <linux/random.h>
44791 +#include <linux/seq_file.h>
44792 +
44793 +#ifdef CONFIG_PAX_REFCOUNT
44794 +#include <linux/kallsyms.h>
44795 +#include <linux/kdebug.h>
44796 +#endif
44797 +
44798 +#include <trace/events/fs.h>
44799
44800 #include <asm/uaccess.h>
44801 #include <asm/mmu_context.h>
44802 @@ -66,6 +75,18 @@
44803
44804 #include <trace/events/sched.h>
44805
44806 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44807 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44808 +{
44809 + 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");
44810 +}
44811 +#endif
44812 +
44813 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44814 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44815 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44816 +#endif
44817 +
44818 int core_uses_pid;
44819 char core_pattern[CORENAME_MAX_SIZE] = "core";
44820 unsigned int core_pipe_limit;
44821 @@ -75,7 +96,7 @@ struct core_name {
44822 char *corename;
44823 int used, size;
44824 };
44825 -static atomic_t call_count = ATOMIC_INIT(1);
44826 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44827
44828 /* The maximal length of core_pattern is also specified in sysctl.c */
44829
44830 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44831 int write)
44832 {
44833 struct page *page;
44834 - int ret;
44835
44836 -#ifdef CONFIG_STACK_GROWSUP
44837 - if (write) {
44838 - ret = expand_downwards(bprm->vma, pos);
44839 - if (ret < 0)
44840 - return NULL;
44841 - }
44842 -#endif
44843 - ret = get_user_pages(current, bprm->mm, pos,
44844 - 1, write, 1, &page, NULL);
44845 - if (ret <= 0)
44846 + if (0 > expand_downwards(bprm->vma, pos))
44847 + return NULL;
44848 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44849 return NULL;
44850
44851 if (write) {
44852 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44853 if (size <= ARG_MAX)
44854 return page;
44855
44856 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44857 + // only allow 512KB for argv+env on suid/sgid binaries
44858 + // to prevent easy ASLR exhaustion
44859 + if (((bprm->cred->euid != current_euid()) ||
44860 + (bprm->cred->egid != current_egid())) &&
44861 + (size > (512 * 1024))) {
44862 + put_page(page);
44863 + return NULL;
44864 + }
44865 +#endif
44866 +
44867 /*
44868 * Limit to 1/4-th the stack size for the argv+env strings.
44869 * This ensures that:
44870 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44871 vma->vm_end = STACK_TOP_MAX;
44872 vma->vm_start = vma->vm_end - PAGE_SIZE;
44873 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44874 +
44875 +#ifdef CONFIG_PAX_SEGMEXEC
44876 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44877 +#endif
44878 +
44879 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44880 INIT_LIST_HEAD(&vma->anon_vma_chain);
44881
44882 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44883 mm->stack_vm = mm->total_vm = 1;
44884 up_write(&mm->mmap_sem);
44885 bprm->p = vma->vm_end - sizeof(void *);
44886 +
44887 +#ifdef CONFIG_PAX_RANDUSTACK
44888 + if (randomize_va_space)
44889 + bprm->p ^= random32() & ~PAGE_MASK;
44890 +#endif
44891 +
44892 return 0;
44893 err:
44894 up_write(&mm->mmap_sem);
44895 @@ -395,19 +430,7 @@ err:
44896 return err;
44897 }
44898
44899 -struct user_arg_ptr {
44900 -#ifdef CONFIG_COMPAT
44901 - bool is_compat;
44902 -#endif
44903 - union {
44904 - const char __user *const __user *native;
44905 -#ifdef CONFIG_COMPAT
44906 - compat_uptr_t __user *compat;
44907 -#endif
44908 - } ptr;
44909 -};
44910 -
44911 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44912 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44913 {
44914 const char __user *native;
44915
44916 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44917 compat_uptr_t compat;
44918
44919 if (get_user(compat, argv.ptr.compat + nr))
44920 - return ERR_PTR(-EFAULT);
44921 + return (const char __force_user *)ERR_PTR(-EFAULT);
44922
44923 return compat_ptr(compat);
44924 }
44925 #endif
44926
44927 if (get_user(native, argv.ptr.native + nr))
44928 - return ERR_PTR(-EFAULT);
44929 + return (const char __force_user *)ERR_PTR(-EFAULT);
44930
44931 return native;
44932 }
44933 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44934 if (!p)
44935 break;
44936
44937 - if (IS_ERR(p))
44938 + if (IS_ERR((const char __force_kernel *)p))
44939 return -EFAULT;
44940
44941 if (i++ >= max)
44942 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44943
44944 ret = -EFAULT;
44945 str = get_user_arg_ptr(argv, argc);
44946 - if (IS_ERR(str))
44947 + if (IS_ERR((const char __force_kernel *)str))
44948 goto out;
44949
44950 len = strnlen_user(str, MAX_ARG_STRLEN);
44951 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44952 int r;
44953 mm_segment_t oldfs = get_fs();
44954 struct user_arg_ptr argv = {
44955 - .ptr.native = (const char __user *const __user *)__argv,
44956 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44957 };
44958
44959 set_fs(KERNEL_DS);
44960 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44961 unsigned long new_end = old_end - shift;
44962 struct mmu_gather tlb;
44963
44964 - BUG_ON(new_start > new_end);
44965 + if (new_start >= new_end || new_start < mmap_min_addr)
44966 + return -ENOMEM;
44967
44968 /*
44969 * ensure there are no vmas between where we want to go
44970 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44971 if (vma != find_vma(mm, new_start))
44972 return -EFAULT;
44973
44974 +#ifdef CONFIG_PAX_SEGMEXEC
44975 + BUG_ON(pax_find_mirror_vma(vma));
44976 +#endif
44977 +
44978 /*
44979 * cover the whole range: [new_start, old_end)
44980 */
44981 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44982 stack_top = arch_align_stack(stack_top);
44983 stack_top = PAGE_ALIGN(stack_top);
44984
44985 - if (unlikely(stack_top < mmap_min_addr) ||
44986 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44987 - return -ENOMEM;
44988 -
44989 stack_shift = vma->vm_end - stack_top;
44990
44991 bprm->p -= stack_shift;
44992 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44993 bprm->exec -= stack_shift;
44994
44995 down_write(&mm->mmap_sem);
44996 +
44997 + /* Move stack pages down in memory. */
44998 + if (stack_shift) {
44999 + ret = shift_arg_pages(vma, stack_shift);
45000 + if (ret)
45001 + goto out_unlock;
45002 + }
45003 +
45004 vm_flags = VM_STACK_FLAGS;
45005
45006 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45007 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45008 + vm_flags &= ~VM_EXEC;
45009 +
45010 +#ifdef CONFIG_PAX_MPROTECT
45011 + if (mm->pax_flags & MF_PAX_MPROTECT)
45012 + vm_flags &= ~VM_MAYEXEC;
45013 +#endif
45014 +
45015 + }
45016 +#endif
45017 +
45018 /*
45019 * Adjust stack execute permissions; explicitly enable for
45020 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45021 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45022 goto out_unlock;
45023 BUG_ON(prev != vma);
45024
45025 - /* Move stack pages down in memory. */
45026 - if (stack_shift) {
45027 - ret = shift_arg_pages(vma, stack_shift);
45028 - if (ret)
45029 - goto out_unlock;
45030 - }
45031 -
45032 /* mprotect_fixup is overkill to remove the temporary stack flags */
45033 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45034
45035 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45036
45037 fsnotify_open(file);
45038
45039 + trace_open_exec(name);
45040 +
45041 err = deny_write_access(file);
45042 if (err)
45043 goto exit;
45044 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45045 old_fs = get_fs();
45046 set_fs(get_ds());
45047 /* The cast to a user pointer is valid due to the set_fs() */
45048 - result = vfs_read(file, (void __user *)addr, count, &pos);
45049 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45050 set_fs(old_fs);
45051 return result;
45052 }
45053 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45054 }
45055 rcu_read_unlock();
45056
45057 - if (p->fs->users > n_fs) {
45058 + if (atomic_read(&p->fs->users) > n_fs) {
45059 bprm->unsafe |= LSM_UNSAFE_SHARE;
45060 } else {
45061 res = -EAGAIN;
45062 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45063
45064 EXPORT_SYMBOL(search_binary_handler);
45065
45066 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45067 +static DEFINE_PER_CPU(u64, exec_counter);
45068 +static int __init init_exec_counters(void)
45069 +{
45070 + unsigned int cpu;
45071 +
45072 + for_each_possible_cpu(cpu) {
45073 + per_cpu(exec_counter, cpu) = (u64)cpu;
45074 + }
45075 +
45076 + return 0;
45077 +}
45078 +early_initcall(init_exec_counters);
45079 +static inline void increment_exec_counter(void)
45080 +{
45081 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45082 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45083 +}
45084 +#else
45085 +static inline void increment_exec_counter(void) {}
45086 +#endif
45087 +
45088 /*
45089 * sys_execve() executes a new program.
45090 */
45091 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45092 struct user_arg_ptr envp,
45093 struct pt_regs *regs)
45094 {
45095 +#ifdef CONFIG_GRKERNSEC
45096 + struct file *old_exec_file;
45097 + struct acl_subject_label *old_acl;
45098 + struct rlimit old_rlim[RLIM_NLIMITS];
45099 +#endif
45100 struct linux_binprm *bprm;
45101 struct file *file;
45102 struct files_struct *displaced;
45103 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45104 int retval;
45105 const struct cred *cred = current_cred();
45106
45107 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45108 +
45109 /*
45110 * We move the actual failure in case of RLIMIT_NPROC excess from
45111 * set*uid() to execve() because too many poorly written programs
45112 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45113 if (IS_ERR(file))
45114 goto out_unmark;
45115
45116 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45117 + retval = -EPERM;
45118 + goto out_file;
45119 + }
45120 +
45121 sched_exec();
45122
45123 bprm->file = file;
45124 bprm->filename = filename;
45125 bprm->interp = filename;
45126
45127 + if (gr_process_user_ban()) {
45128 + retval = -EPERM;
45129 + goto out_file;
45130 + }
45131 +
45132 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45133 + retval = -EACCES;
45134 + goto out_file;
45135 + }
45136 +
45137 retval = bprm_mm_init(bprm);
45138 if (retval)
45139 goto out_file;
45140 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45141 if (retval < 0)
45142 goto out;
45143
45144 +#ifdef CONFIG_GRKERNSEC
45145 + old_acl = current->acl;
45146 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45147 + old_exec_file = current->exec_file;
45148 + get_file(file);
45149 + current->exec_file = file;
45150 +#endif
45151 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45152 + /* limit suid stack to 8MB
45153 + we saved the old limits above and will restore them if this exec fails
45154 + */
45155 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45156 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45157 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45158 +#endif
45159 +
45160 + if (!gr_tpe_allow(file)) {
45161 + retval = -EACCES;
45162 + goto out_fail;
45163 + }
45164 +
45165 + if (gr_check_crash_exec(file)) {
45166 + retval = -EACCES;
45167 + goto out_fail;
45168 + }
45169 +
45170 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45171 + bprm->unsafe);
45172 + if (retval < 0)
45173 + goto out_fail;
45174 +
45175 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45176 if (retval < 0)
45177 - goto out;
45178 + goto out_fail;
45179
45180 bprm->exec = bprm->p;
45181 retval = copy_strings(bprm->envc, envp, bprm);
45182 if (retval < 0)
45183 - goto out;
45184 + goto out_fail;
45185
45186 retval = copy_strings(bprm->argc, argv, bprm);
45187 if (retval < 0)
45188 - goto out;
45189 + goto out_fail;
45190 +
45191 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45192 +
45193 + gr_handle_exec_args(bprm, argv);
45194
45195 retval = search_binary_handler(bprm,regs);
45196 if (retval < 0)
45197 - goto out;
45198 + goto out_fail;
45199 +#ifdef CONFIG_GRKERNSEC
45200 + if (old_exec_file)
45201 + fput(old_exec_file);
45202 +#endif
45203
45204 /* execve succeeded */
45205 +
45206 + increment_exec_counter();
45207 current->fs->in_exec = 0;
45208 current->in_execve = 0;
45209 acct_update_integrals(current);
45210 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45211 put_files_struct(displaced);
45212 return retval;
45213
45214 +out_fail:
45215 +#ifdef CONFIG_GRKERNSEC
45216 + current->acl = old_acl;
45217 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45218 + fput(current->exec_file);
45219 + current->exec_file = old_exec_file;
45220 +#endif
45221 +
45222 out:
45223 if (bprm->mm) {
45224 acct_arg_size(bprm, 0);
45225 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45226 {
45227 char *old_corename = cn->corename;
45228
45229 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45230 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45231 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45232
45233 if (!cn->corename) {
45234 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45235 int pid_in_pattern = 0;
45236 int err = 0;
45237
45238 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45239 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45240 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45241 cn->used = 0;
45242
45243 @@ -1830,6 +1962,250 @@ out:
45244 return ispipe;
45245 }
45246
45247 +int pax_check_flags(unsigned long *flags)
45248 +{
45249 + int retval = 0;
45250 +
45251 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45252 + if (*flags & MF_PAX_SEGMEXEC)
45253 + {
45254 + *flags &= ~MF_PAX_SEGMEXEC;
45255 + retval = -EINVAL;
45256 + }
45257 +#endif
45258 +
45259 + if ((*flags & MF_PAX_PAGEEXEC)
45260 +
45261 +#ifdef CONFIG_PAX_PAGEEXEC
45262 + && (*flags & MF_PAX_SEGMEXEC)
45263 +#endif
45264 +
45265 + )
45266 + {
45267 + *flags &= ~MF_PAX_PAGEEXEC;
45268 + retval = -EINVAL;
45269 + }
45270 +
45271 + if ((*flags & MF_PAX_MPROTECT)
45272 +
45273 +#ifdef CONFIG_PAX_MPROTECT
45274 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45275 +#endif
45276 +
45277 + )
45278 + {
45279 + *flags &= ~MF_PAX_MPROTECT;
45280 + retval = -EINVAL;
45281 + }
45282 +
45283 + if ((*flags & MF_PAX_EMUTRAMP)
45284 +
45285 +#ifdef CONFIG_PAX_EMUTRAMP
45286 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45287 +#endif
45288 +
45289 + )
45290 + {
45291 + *flags &= ~MF_PAX_EMUTRAMP;
45292 + retval = -EINVAL;
45293 + }
45294 +
45295 + return retval;
45296 +}
45297 +
45298 +EXPORT_SYMBOL(pax_check_flags);
45299 +
45300 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45301 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45302 +{
45303 + struct task_struct *tsk = current;
45304 + struct mm_struct *mm = current->mm;
45305 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45306 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45307 + char *path_exec = NULL;
45308 + char *path_fault = NULL;
45309 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45310 +
45311 + if (buffer_exec && buffer_fault) {
45312 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45313 +
45314 + down_read(&mm->mmap_sem);
45315 + vma = mm->mmap;
45316 + while (vma && (!vma_exec || !vma_fault)) {
45317 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45318 + vma_exec = vma;
45319 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45320 + vma_fault = vma;
45321 + vma = vma->vm_next;
45322 + }
45323 + if (vma_exec) {
45324 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45325 + if (IS_ERR(path_exec))
45326 + path_exec = "<path too long>";
45327 + else {
45328 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45329 + if (path_exec) {
45330 + *path_exec = 0;
45331 + path_exec = buffer_exec;
45332 + } else
45333 + path_exec = "<path too long>";
45334 + }
45335 + }
45336 + if (vma_fault) {
45337 + start = vma_fault->vm_start;
45338 + end = vma_fault->vm_end;
45339 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45340 + if (vma_fault->vm_file) {
45341 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45342 + if (IS_ERR(path_fault))
45343 + path_fault = "<path too long>";
45344 + else {
45345 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45346 + if (path_fault) {
45347 + *path_fault = 0;
45348 + path_fault = buffer_fault;
45349 + } else
45350 + path_fault = "<path too long>";
45351 + }
45352 + } else
45353 + path_fault = "<anonymous mapping>";
45354 + }
45355 + up_read(&mm->mmap_sem);
45356 + }
45357 + if (tsk->signal->curr_ip)
45358 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45359 + else
45360 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45361 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45362 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45363 + task_uid(tsk), task_euid(tsk), pc, sp);
45364 + free_page((unsigned long)buffer_exec);
45365 + free_page((unsigned long)buffer_fault);
45366 + pax_report_insns(regs, pc, sp);
45367 + do_coredump(SIGKILL, SIGKILL, regs);
45368 +}
45369 +#endif
45370 +
45371 +#ifdef CONFIG_PAX_REFCOUNT
45372 +void pax_report_refcount_overflow(struct pt_regs *regs)
45373 +{
45374 + if (current->signal->curr_ip)
45375 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45376 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45377 + else
45378 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45379 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45380 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45381 + show_regs(regs);
45382 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45383 +}
45384 +#endif
45385 +
45386 +#ifdef CONFIG_PAX_USERCOPY
45387 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45388 +static noinline int check_stack_object(const void *obj, unsigned long len)
45389 +{
45390 + const void * const stack = task_stack_page(current);
45391 + const void * const stackend = stack + THREAD_SIZE;
45392 +
45393 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45394 + const void *frame = NULL;
45395 + const void *oldframe;
45396 +#endif
45397 +
45398 + if (obj + len < obj)
45399 + return -1;
45400 +
45401 + if (obj + len <= stack || stackend <= obj)
45402 + return 0;
45403 +
45404 + if (obj < stack || stackend < obj + len)
45405 + return -1;
45406 +
45407 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45408 + oldframe = __builtin_frame_address(1);
45409 + if (oldframe)
45410 + frame = __builtin_frame_address(2);
45411 + /*
45412 + low ----------------------------------------------> high
45413 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45414 + ^----------------^
45415 + allow copies only within here
45416 + */
45417 + while (stack <= frame && frame < stackend) {
45418 + /* if obj + len extends past the last frame, this
45419 + check won't pass and the next frame will be 0,
45420 + causing us to bail out and correctly report
45421 + the copy as invalid
45422 + */
45423 + if (obj + len <= frame)
45424 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45425 + oldframe = frame;
45426 + frame = *(const void * const *)frame;
45427 + }
45428 + return -1;
45429 +#else
45430 + return 1;
45431 +#endif
45432 +}
45433 +
45434 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45435 +{
45436 + if (current->signal->curr_ip)
45437 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45438 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45439 + else
45440 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45441 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45442 + dump_stack();
45443 + gr_handle_kernel_exploit();
45444 + do_group_exit(SIGKILL);
45445 +}
45446 +#endif
45447 +
45448 +void check_object_size(const void *ptr, unsigned long n, bool to)
45449 +{
45450 +
45451 +#ifdef CONFIG_PAX_USERCOPY
45452 + const char *type;
45453 +
45454 + if (!n)
45455 + return;
45456 +
45457 + type = check_heap_object(ptr, n, to);
45458 + if (!type) {
45459 + if (check_stack_object(ptr, n) != -1)
45460 + return;
45461 + type = "<process stack>";
45462 + }
45463 +
45464 + pax_report_usercopy(ptr, n, to, type);
45465 +#endif
45466 +
45467 +}
45468 +EXPORT_SYMBOL(check_object_size);
45469 +
45470 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45471 +void pax_track_stack(void)
45472 +{
45473 + unsigned long sp = (unsigned long)&sp;
45474 + if (sp < current_thread_info()->lowest_stack &&
45475 + sp > (unsigned long)task_stack_page(current))
45476 + current_thread_info()->lowest_stack = sp;
45477 +}
45478 +EXPORT_SYMBOL(pax_track_stack);
45479 +#endif
45480 +
45481 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45482 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45483 +{
45484 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45485 + dump_stack();
45486 + do_group_exit(SIGKILL);
45487 +}
45488 +EXPORT_SYMBOL(report_size_overflow);
45489 +#endif
45490 +
45491 static int zap_process(struct task_struct *start, int exit_code)
45492 {
45493 struct task_struct *t;
45494 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45495 pipe = file->f_path.dentry->d_inode->i_pipe;
45496
45497 pipe_lock(pipe);
45498 - pipe->readers++;
45499 - pipe->writers--;
45500 + atomic_inc(&pipe->readers);
45501 + atomic_dec(&pipe->writers);
45502
45503 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45504 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45505 wake_up_interruptible_sync(&pipe->wait);
45506 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45507 pipe_wait(pipe);
45508 }
45509
45510 - pipe->readers--;
45511 - pipe->writers++;
45512 + atomic_dec(&pipe->readers);
45513 + atomic_inc(&pipe->writers);
45514 pipe_unlock(pipe);
45515
45516 }
45517 @@ -2105,7 +2481,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45518 int flag = 0;
45519 int ispipe;
45520 bool need_nonrelative = false;
45521 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45522 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45523 struct coredump_params cprm = {
45524 .signr = signr,
45525 .regs = regs,
45526 @@ -2120,6 +2496,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45527
45528 audit_core_dumps(signr);
45529
45530 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45531 + gr_handle_brute_attach(current, cprm.mm_flags);
45532 +
45533 binfmt = mm->binfmt;
45534 if (!binfmt || !binfmt->core_dump)
45535 goto fail;
45536 @@ -2190,7 +2569,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45537 }
45538 cprm.limit = RLIM_INFINITY;
45539
45540 - dump_count = atomic_inc_return(&core_dump_count);
45541 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45542 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45543 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45544 task_tgid_vnr(current), current->comm);
45545 @@ -2217,6 +2596,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45546 } else {
45547 struct inode *inode;
45548
45549 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45550 +
45551 if (cprm.limit < binfmt->min_coredump)
45552 goto fail_unlock;
45553
45554 @@ -2268,7 +2649,7 @@ close_fail:
45555 filp_close(cprm.file, NULL);
45556 fail_dropcount:
45557 if (ispipe)
45558 - atomic_dec(&core_dump_count);
45559 + atomic_dec_unchecked(&core_dump_count);
45560 fail_unlock:
45561 kfree(cn.corename);
45562 fail_corename:
45563 @@ -2287,7 +2668,7 @@ fail:
45564 */
45565 int dump_write(struct file *file, const void *addr, int nr)
45566 {
45567 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45568 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45569 }
45570 EXPORT_SYMBOL(dump_write);
45571
45572 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45573 index 376aa77..59a129c 100644
45574 --- a/fs/ext2/balloc.c
45575 +++ b/fs/ext2/balloc.c
45576 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45577
45578 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45579 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45580 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45581 + if (free_blocks < root_blocks + 1 &&
45582 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45583 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45584 - !in_group_p (sbi->s_resgid))) {
45585 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45586 return 0;
45587 }
45588 return 1;
45589 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45590 index 90d901f..159975f 100644
45591 --- a/fs/ext3/balloc.c
45592 +++ b/fs/ext3/balloc.c
45593 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45594
45595 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45596 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45597 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45598 + if (free_blocks < root_blocks + 1 &&
45599 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45600 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45601 - !in_group_p (sbi->s_resgid))) {
45602 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45603 return 0;
45604 }
45605 return 1;
45606 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45607 index cf18217..8f6b9c3 100644
45608 --- a/fs/ext4/balloc.c
45609 +++ b/fs/ext4/balloc.c
45610 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45611 /* Hm, nope. Are (enough) root reserved clusters available? */
45612 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45613 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45614 - capable(CAP_SYS_RESOURCE) ||
45615 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45616 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45617 + capable_nolog(CAP_SYS_RESOURCE)) {
45618
45619 if (free_clusters >= (nclusters + dirty_clusters))
45620 return 1;
45621 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45622 index 5c69f2b..05dec7f 100644
45623 --- a/fs/ext4/ext4.h
45624 +++ b/fs/ext4/ext4.h
45625 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45626 unsigned long s_mb_last_start;
45627
45628 /* stats for buddy allocator */
45629 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45630 - atomic_t s_bal_success; /* we found long enough chunks */
45631 - atomic_t s_bal_allocated; /* in blocks */
45632 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45633 - atomic_t s_bal_goals; /* goal hits */
45634 - atomic_t s_bal_breaks; /* too long searches */
45635 - atomic_t s_bal_2orders; /* 2^order hits */
45636 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45637 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45638 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45639 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45640 + atomic_unchecked_t s_bal_goals; /* goal hits */
45641 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45642 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45643 spinlock_t s_bal_lock;
45644 unsigned long s_mb_buddies_generated;
45645 unsigned long long s_mb_generation_time;
45646 - atomic_t s_mb_lost_chunks;
45647 - atomic_t s_mb_preallocated;
45648 - atomic_t s_mb_discarded;
45649 + atomic_unchecked_t s_mb_lost_chunks;
45650 + atomic_unchecked_t s_mb_preallocated;
45651 + atomic_unchecked_t s_mb_discarded;
45652 atomic_t s_lock_busy;
45653
45654 /* locality groups */
45655 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45656 index b26410c..7383d90 100644
45657 --- a/fs/ext4/mballoc.c
45658 +++ b/fs/ext4/mballoc.c
45659 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45660 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45661
45662 if (EXT4_SB(sb)->s_mb_stats)
45663 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45664 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45665
45666 break;
45667 }
45668 @@ -2040,7 +2040,7 @@ repeat:
45669 ac->ac_status = AC_STATUS_CONTINUE;
45670 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45671 cr = 3;
45672 - atomic_inc(&sbi->s_mb_lost_chunks);
45673 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45674 goto repeat;
45675 }
45676 }
45677 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45678 if (sbi->s_mb_stats) {
45679 ext4_msg(sb, KERN_INFO,
45680 "mballoc: %u blocks %u reqs (%u success)",
45681 - atomic_read(&sbi->s_bal_allocated),
45682 - atomic_read(&sbi->s_bal_reqs),
45683 - atomic_read(&sbi->s_bal_success));
45684 + atomic_read_unchecked(&sbi->s_bal_allocated),
45685 + atomic_read_unchecked(&sbi->s_bal_reqs),
45686 + atomic_read_unchecked(&sbi->s_bal_success));
45687 ext4_msg(sb, KERN_INFO,
45688 "mballoc: %u extents scanned, %u goal hits, "
45689 "%u 2^N hits, %u breaks, %u lost",
45690 - atomic_read(&sbi->s_bal_ex_scanned),
45691 - atomic_read(&sbi->s_bal_goals),
45692 - atomic_read(&sbi->s_bal_2orders),
45693 - atomic_read(&sbi->s_bal_breaks),
45694 - atomic_read(&sbi->s_mb_lost_chunks));
45695 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45696 + atomic_read_unchecked(&sbi->s_bal_goals),
45697 + atomic_read_unchecked(&sbi->s_bal_2orders),
45698 + atomic_read_unchecked(&sbi->s_bal_breaks),
45699 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45700 ext4_msg(sb, KERN_INFO,
45701 "mballoc: %lu generated and it took %Lu",
45702 sbi->s_mb_buddies_generated,
45703 sbi->s_mb_generation_time);
45704 ext4_msg(sb, KERN_INFO,
45705 "mballoc: %u preallocated, %u discarded",
45706 - atomic_read(&sbi->s_mb_preallocated),
45707 - atomic_read(&sbi->s_mb_discarded));
45708 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45709 + atomic_read_unchecked(&sbi->s_mb_discarded));
45710 }
45711
45712 free_percpu(sbi->s_locality_groups);
45713 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45714 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45715
45716 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45717 - atomic_inc(&sbi->s_bal_reqs);
45718 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45719 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45720 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45721 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45722 - atomic_inc(&sbi->s_bal_success);
45723 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45724 + atomic_inc_unchecked(&sbi->s_bal_success);
45725 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45726 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45727 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45728 - atomic_inc(&sbi->s_bal_goals);
45729 + atomic_inc_unchecked(&sbi->s_bal_goals);
45730 if (ac->ac_found > sbi->s_mb_max_to_scan)
45731 - atomic_inc(&sbi->s_bal_breaks);
45732 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45733 }
45734
45735 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45736 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45737 trace_ext4_mb_new_inode_pa(ac, pa);
45738
45739 ext4_mb_use_inode_pa(ac, pa);
45740 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45741 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45742
45743 ei = EXT4_I(ac->ac_inode);
45744 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45745 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45746 trace_ext4_mb_new_group_pa(ac, pa);
45747
45748 ext4_mb_use_group_pa(ac, pa);
45749 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45750 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45751
45752 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45753 lg = ac->ac_lg;
45754 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45755 * from the bitmap and continue.
45756 */
45757 }
45758 - atomic_add(free, &sbi->s_mb_discarded);
45759 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45760
45761 return err;
45762 }
45763 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45764 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45765 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45766 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45767 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45768 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45769 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45770
45771 return 0;
45772 diff --git a/fs/fcntl.c b/fs/fcntl.c
45773 index 887b5ba..0e3f2c3 100644
45774 --- a/fs/fcntl.c
45775 +++ b/fs/fcntl.c
45776 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45777 if (err)
45778 return err;
45779
45780 + if (gr_handle_chroot_fowner(pid, type))
45781 + return -ENOENT;
45782 + if (gr_check_protected_task_fowner(pid, type))
45783 + return -EACCES;
45784 +
45785 f_modown(filp, pid, type, force);
45786 return 0;
45787 }
45788 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45789
45790 static int f_setown_ex(struct file *filp, unsigned long arg)
45791 {
45792 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45793 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45794 struct f_owner_ex owner;
45795 struct pid *pid;
45796 int type;
45797 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45798
45799 static int f_getown_ex(struct file *filp, unsigned long arg)
45800 {
45801 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45802 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45803 struct f_owner_ex owner;
45804 int ret = 0;
45805
45806 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45807 switch (cmd) {
45808 case F_DUPFD:
45809 case F_DUPFD_CLOEXEC:
45810 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45811 if (arg >= rlimit(RLIMIT_NOFILE))
45812 break;
45813 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45814 diff --git a/fs/fifo.c b/fs/fifo.c
45815 index cf6f434..3d7942c 100644
45816 --- a/fs/fifo.c
45817 +++ b/fs/fifo.c
45818 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45819 */
45820 filp->f_op = &read_pipefifo_fops;
45821 pipe->r_counter++;
45822 - if (pipe->readers++ == 0)
45823 + if (atomic_inc_return(&pipe->readers) == 1)
45824 wake_up_partner(inode);
45825
45826 - if (!pipe->writers) {
45827 + if (!atomic_read(&pipe->writers)) {
45828 if ((filp->f_flags & O_NONBLOCK)) {
45829 /* suppress POLLHUP until we have
45830 * seen a writer */
45831 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45832 * errno=ENXIO when there is no process reading the FIFO.
45833 */
45834 ret = -ENXIO;
45835 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45836 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45837 goto err;
45838
45839 filp->f_op = &write_pipefifo_fops;
45840 pipe->w_counter++;
45841 - if (!pipe->writers++)
45842 + if (atomic_inc_return(&pipe->writers) == 1)
45843 wake_up_partner(inode);
45844
45845 - if (!pipe->readers) {
45846 + if (!atomic_read(&pipe->readers)) {
45847 if (wait_for_partner(inode, &pipe->r_counter))
45848 goto err_wr;
45849 }
45850 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45851 */
45852 filp->f_op = &rdwr_pipefifo_fops;
45853
45854 - pipe->readers++;
45855 - pipe->writers++;
45856 + atomic_inc(&pipe->readers);
45857 + atomic_inc(&pipe->writers);
45858 pipe->r_counter++;
45859 pipe->w_counter++;
45860 - if (pipe->readers == 1 || pipe->writers == 1)
45861 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45862 wake_up_partner(inode);
45863 break;
45864
45865 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45866 return 0;
45867
45868 err_rd:
45869 - if (!--pipe->readers)
45870 + if (atomic_dec_and_test(&pipe->readers))
45871 wake_up_interruptible(&pipe->wait);
45872 ret = -ERESTARTSYS;
45873 goto err;
45874
45875 err_wr:
45876 - if (!--pipe->writers)
45877 + if (atomic_dec_and_test(&pipe->writers))
45878 wake_up_interruptible(&pipe->wait);
45879 ret = -ERESTARTSYS;
45880 goto err;
45881
45882 err:
45883 - if (!pipe->readers && !pipe->writers)
45884 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45885 free_pipe_info(inode);
45886
45887 err_nocleanup:
45888 diff --git a/fs/file.c b/fs/file.c
45889 index ba3f605..fade102 100644
45890 --- a/fs/file.c
45891 +++ b/fs/file.c
45892 @@ -15,6 +15,7 @@
45893 #include <linux/slab.h>
45894 #include <linux/vmalloc.h>
45895 #include <linux/file.h>
45896 +#include <linux/security.h>
45897 #include <linux/fdtable.h>
45898 #include <linux/bitops.h>
45899 #include <linux/interrupt.h>
45900 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45901 * N.B. For clone tasks sharing a files structure, this test
45902 * will limit the total number of files that can be opened.
45903 */
45904 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45905 if (nr >= rlimit(RLIMIT_NOFILE))
45906 return -EMFILE;
45907
45908 diff --git a/fs/filesystems.c b/fs/filesystems.c
45909 index 96f2428..f5eeb8e 100644
45910 --- a/fs/filesystems.c
45911 +++ b/fs/filesystems.c
45912 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45913 int len = dot ? dot - name : strlen(name);
45914
45915 fs = __get_fs_type(name, len);
45916 +
45917 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45918 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45919 +#else
45920 if (!fs && (request_module("%.*s", len, name) == 0))
45921 +#endif
45922 fs = __get_fs_type(name, len);
45923
45924 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45925 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45926 index 5df4775..9d9336f 100644
45927 --- a/fs/fs_struct.c
45928 +++ b/fs/fs_struct.c
45929 @@ -4,6 +4,7 @@
45930 #include <linux/path.h>
45931 #include <linux/slab.h>
45932 #include <linux/fs_struct.h>
45933 +#include <linux/grsecurity.h>
45934 #include "internal.h"
45935
45936 /*
45937 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45938 write_seqcount_begin(&fs->seq);
45939 old_root = fs->root;
45940 fs->root = *path;
45941 + gr_set_chroot_entries(current, path);
45942 write_seqcount_end(&fs->seq);
45943 spin_unlock(&fs->lock);
45944 if (old_root.dentry)
45945 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45946 return 1;
45947 }
45948
45949 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45950 +{
45951 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45952 + return 0;
45953 + *p = *new;
45954 +
45955 + /* This function is only called from pivot_root(). Leave our
45956 + gr_chroot_dentry and is_chrooted flags as-is, so that a
45957 + pivoted root isn't treated as a chroot
45958 + */
45959 + //gr_set_chroot_entries(task, new);
45960 +
45961 + return 1;
45962 +}
45963 +
45964 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45965 {
45966 struct task_struct *g, *p;
45967 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45968 int hits = 0;
45969 spin_lock(&fs->lock);
45970 write_seqcount_begin(&fs->seq);
45971 - hits += replace_path(&fs->root, old_root, new_root);
45972 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45973 hits += replace_path(&fs->pwd, old_root, new_root);
45974 write_seqcount_end(&fs->seq);
45975 while (hits--) {
45976 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
45977 task_lock(tsk);
45978 spin_lock(&fs->lock);
45979 tsk->fs = NULL;
45980 - kill = !--fs->users;
45981 + gr_clear_chroot_entries(tsk);
45982 + kill = !atomic_dec_return(&fs->users);
45983 spin_unlock(&fs->lock);
45984 task_unlock(tsk);
45985 if (kill)
45986 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45987 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45988 /* We don't need to lock fs - think why ;-) */
45989 if (fs) {
45990 - fs->users = 1;
45991 + atomic_set(&fs->users, 1);
45992 fs->in_exec = 0;
45993 spin_lock_init(&fs->lock);
45994 seqcount_init(&fs->seq);
45995 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45996 spin_lock(&old->lock);
45997 fs->root = old->root;
45998 path_get(&fs->root);
45999 + /* instead of calling gr_set_chroot_entries here,
46000 + we call it from every caller of this function
46001 + */
46002 fs->pwd = old->pwd;
46003 path_get(&fs->pwd);
46004 spin_unlock(&old->lock);
46005 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46006
46007 task_lock(current);
46008 spin_lock(&fs->lock);
46009 - kill = !--fs->users;
46010 + kill = !atomic_dec_return(&fs->users);
46011 current->fs = new_fs;
46012 + gr_set_chroot_entries(current, &new_fs->root);
46013 spin_unlock(&fs->lock);
46014 task_unlock(current);
46015
46016 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46017
46018 int current_umask(void)
46019 {
46020 - return current->fs->umask;
46021 + return current->fs->umask | gr_acl_umask();
46022 }
46023 EXPORT_SYMBOL(current_umask);
46024
46025 /* to be mentioned only in INIT_TASK */
46026 struct fs_struct init_fs = {
46027 - .users = 1,
46028 + .users = ATOMIC_INIT(1),
46029 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46030 .seq = SEQCNT_ZERO,
46031 .umask = 0022,
46032 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46033 task_lock(current);
46034
46035 spin_lock(&init_fs.lock);
46036 - init_fs.users++;
46037 + atomic_inc(&init_fs.users);
46038 spin_unlock(&init_fs.lock);
46039
46040 spin_lock(&fs->lock);
46041 current->fs = &init_fs;
46042 - kill = !--fs->users;
46043 + gr_set_chroot_entries(current, &current->fs->root);
46044 + kill = !atomic_dec_return(&fs->users);
46045 spin_unlock(&fs->lock);
46046
46047 task_unlock(current);
46048 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46049 index 9905350..02eaec4 100644
46050 --- a/fs/fscache/cookie.c
46051 +++ b/fs/fscache/cookie.c
46052 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46053 parent ? (char *) parent->def->name : "<no-parent>",
46054 def->name, netfs_data);
46055
46056 - fscache_stat(&fscache_n_acquires);
46057 + fscache_stat_unchecked(&fscache_n_acquires);
46058
46059 /* if there's no parent cookie, then we don't create one here either */
46060 if (!parent) {
46061 - fscache_stat(&fscache_n_acquires_null);
46062 + fscache_stat_unchecked(&fscache_n_acquires_null);
46063 _leave(" [no parent]");
46064 return NULL;
46065 }
46066 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46067 /* allocate and initialise a cookie */
46068 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46069 if (!cookie) {
46070 - fscache_stat(&fscache_n_acquires_oom);
46071 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46072 _leave(" [ENOMEM]");
46073 return NULL;
46074 }
46075 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46076
46077 switch (cookie->def->type) {
46078 case FSCACHE_COOKIE_TYPE_INDEX:
46079 - fscache_stat(&fscache_n_cookie_index);
46080 + fscache_stat_unchecked(&fscache_n_cookie_index);
46081 break;
46082 case FSCACHE_COOKIE_TYPE_DATAFILE:
46083 - fscache_stat(&fscache_n_cookie_data);
46084 + fscache_stat_unchecked(&fscache_n_cookie_data);
46085 break;
46086 default:
46087 - fscache_stat(&fscache_n_cookie_special);
46088 + fscache_stat_unchecked(&fscache_n_cookie_special);
46089 break;
46090 }
46091
46092 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46093 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46094 atomic_dec(&parent->n_children);
46095 __fscache_cookie_put(cookie);
46096 - fscache_stat(&fscache_n_acquires_nobufs);
46097 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46098 _leave(" = NULL");
46099 return NULL;
46100 }
46101 }
46102
46103 - fscache_stat(&fscache_n_acquires_ok);
46104 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46105 _leave(" = %p", cookie);
46106 return cookie;
46107 }
46108 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46109 cache = fscache_select_cache_for_object(cookie->parent);
46110 if (!cache) {
46111 up_read(&fscache_addremove_sem);
46112 - fscache_stat(&fscache_n_acquires_no_cache);
46113 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46114 _leave(" = -ENOMEDIUM [no cache]");
46115 return -ENOMEDIUM;
46116 }
46117 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46118 object = cache->ops->alloc_object(cache, cookie);
46119 fscache_stat_d(&fscache_n_cop_alloc_object);
46120 if (IS_ERR(object)) {
46121 - fscache_stat(&fscache_n_object_no_alloc);
46122 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46123 ret = PTR_ERR(object);
46124 goto error;
46125 }
46126
46127 - fscache_stat(&fscache_n_object_alloc);
46128 + fscache_stat_unchecked(&fscache_n_object_alloc);
46129
46130 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46131
46132 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46133 struct fscache_object *object;
46134 struct hlist_node *_p;
46135
46136 - fscache_stat(&fscache_n_updates);
46137 + fscache_stat_unchecked(&fscache_n_updates);
46138
46139 if (!cookie) {
46140 - fscache_stat(&fscache_n_updates_null);
46141 + fscache_stat_unchecked(&fscache_n_updates_null);
46142 _leave(" [no cookie]");
46143 return;
46144 }
46145 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46146 struct fscache_object *object;
46147 unsigned long event;
46148
46149 - fscache_stat(&fscache_n_relinquishes);
46150 + fscache_stat_unchecked(&fscache_n_relinquishes);
46151 if (retire)
46152 - fscache_stat(&fscache_n_relinquishes_retire);
46153 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46154
46155 if (!cookie) {
46156 - fscache_stat(&fscache_n_relinquishes_null);
46157 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46158 _leave(" [no cookie]");
46159 return;
46160 }
46161 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46162
46163 /* wait for the cookie to finish being instantiated (or to fail) */
46164 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46165 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46166 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46167 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46168 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46169 }
46170 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46171 index f6aad48..88dcf26 100644
46172 --- a/fs/fscache/internal.h
46173 +++ b/fs/fscache/internal.h
46174 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46175 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46176 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46177
46178 -extern atomic_t fscache_n_op_pend;
46179 -extern atomic_t fscache_n_op_run;
46180 -extern atomic_t fscache_n_op_enqueue;
46181 -extern atomic_t fscache_n_op_deferred_release;
46182 -extern atomic_t fscache_n_op_release;
46183 -extern atomic_t fscache_n_op_gc;
46184 -extern atomic_t fscache_n_op_cancelled;
46185 -extern atomic_t fscache_n_op_rejected;
46186 +extern atomic_unchecked_t fscache_n_op_pend;
46187 +extern atomic_unchecked_t fscache_n_op_run;
46188 +extern atomic_unchecked_t fscache_n_op_enqueue;
46189 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46190 +extern atomic_unchecked_t fscache_n_op_release;
46191 +extern atomic_unchecked_t fscache_n_op_gc;
46192 +extern atomic_unchecked_t fscache_n_op_cancelled;
46193 +extern atomic_unchecked_t fscache_n_op_rejected;
46194
46195 -extern atomic_t fscache_n_attr_changed;
46196 -extern atomic_t fscache_n_attr_changed_ok;
46197 -extern atomic_t fscache_n_attr_changed_nobufs;
46198 -extern atomic_t fscache_n_attr_changed_nomem;
46199 -extern atomic_t fscache_n_attr_changed_calls;
46200 +extern atomic_unchecked_t fscache_n_attr_changed;
46201 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46202 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46203 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46204 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46205
46206 -extern atomic_t fscache_n_allocs;
46207 -extern atomic_t fscache_n_allocs_ok;
46208 -extern atomic_t fscache_n_allocs_wait;
46209 -extern atomic_t fscache_n_allocs_nobufs;
46210 -extern atomic_t fscache_n_allocs_intr;
46211 -extern atomic_t fscache_n_allocs_object_dead;
46212 -extern atomic_t fscache_n_alloc_ops;
46213 -extern atomic_t fscache_n_alloc_op_waits;
46214 +extern atomic_unchecked_t fscache_n_allocs;
46215 +extern atomic_unchecked_t fscache_n_allocs_ok;
46216 +extern atomic_unchecked_t fscache_n_allocs_wait;
46217 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46218 +extern atomic_unchecked_t fscache_n_allocs_intr;
46219 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46220 +extern atomic_unchecked_t fscache_n_alloc_ops;
46221 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46222
46223 -extern atomic_t fscache_n_retrievals;
46224 -extern atomic_t fscache_n_retrievals_ok;
46225 -extern atomic_t fscache_n_retrievals_wait;
46226 -extern atomic_t fscache_n_retrievals_nodata;
46227 -extern atomic_t fscache_n_retrievals_nobufs;
46228 -extern atomic_t fscache_n_retrievals_intr;
46229 -extern atomic_t fscache_n_retrievals_nomem;
46230 -extern atomic_t fscache_n_retrievals_object_dead;
46231 -extern atomic_t fscache_n_retrieval_ops;
46232 -extern atomic_t fscache_n_retrieval_op_waits;
46233 +extern atomic_unchecked_t fscache_n_retrievals;
46234 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46235 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46236 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46237 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46238 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46239 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46240 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46241 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46242 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46243
46244 -extern atomic_t fscache_n_stores;
46245 -extern atomic_t fscache_n_stores_ok;
46246 -extern atomic_t fscache_n_stores_again;
46247 -extern atomic_t fscache_n_stores_nobufs;
46248 -extern atomic_t fscache_n_stores_oom;
46249 -extern atomic_t fscache_n_store_ops;
46250 -extern atomic_t fscache_n_store_calls;
46251 -extern atomic_t fscache_n_store_pages;
46252 -extern atomic_t fscache_n_store_radix_deletes;
46253 -extern atomic_t fscache_n_store_pages_over_limit;
46254 +extern atomic_unchecked_t fscache_n_stores;
46255 +extern atomic_unchecked_t fscache_n_stores_ok;
46256 +extern atomic_unchecked_t fscache_n_stores_again;
46257 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46258 +extern atomic_unchecked_t fscache_n_stores_oom;
46259 +extern atomic_unchecked_t fscache_n_store_ops;
46260 +extern atomic_unchecked_t fscache_n_store_calls;
46261 +extern atomic_unchecked_t fscache_n_store_pages;
46262 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46263 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46264
46265 -extern atomic_t fscache_n_store_vmscan_not_storing;
46266 -extern atomic_t fscache_n_store_vmscan_gone;
46267 -extern atomic_t fscache_n_store_vmscan_busy;
46268 -extern atomic_t fscache_n_store_vmscan_cancelled;
46269 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46270 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46271 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46272 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46273
46274 -extern atomic_t fscache_n_marks;
46275 -extern atomic_t fscache_n_uncaches;
46276 +extern atomic_unchecked_t fscache_n_marks;
46277 +extern atomic_unchecked_t fscache_n_uncaches;
46278
46279 -extern atomic_t fscache_n_acquires;
46280 -extern atomic_t fscache_n_acquires_null;
46281 -extern atomic_t fscache_n_acquires_no_cache;
46282 -extern atomic_t fscache_n_acquires_ok;
46283 -extern atomic_t fscache_n_acquires_nobufs;
46284 -extern atomic_t fscache_n_acquires_oom;
46285 +extern atomic_unchecked_t fscache_n_acquires;
46286 +extern atomic_unchecked_t fscache_n_acquires_null;
46287 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46288 +extern atomic_unchecked_t fscache_n_acquires_ok;
46289 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46290 +extern atomic_unchecked_t fscache_n_acquires_oom;
46291
46292 -extern atomic_t fscache_n_updates;
46293 -extern atomic_t fscache_n_updates_null;
46294 -extern atomic_t fscache_n_updates_run;
46295 +extern atomic_unchecked_t fscache_n_updates;
46296 +extern atomic_unchecked_t fscache_n_updates_null;
46297 +extern atomic_unchecked_t fscache_n_updates_run;
46298
46299 -extern atomic_t fscache_n_relinquishes;
46300 -extern atomic_t fscache_n_relinquishes_null;
46301 -extern atomic_t fscache_n_relinquishes_waitcrt;
46302 -extern atomic_t fscache_n_relinquishes_retire;
46303 +extern atomic_unchecked_t fscache_n_relinquishes;
46304 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46305 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46306 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46307
46308 -extern atomic_t fscache_n_cookie_index;
46309 -extern atomic_t fscache_n_cookie_data;
46310 -extern atomic_t fscache_n_cookie_special;
46311 +extern atomic_unchecked_t fscache_n_cookie_index;
46312 +extern atomic_unchecked_t fscache_n_cookie_data;
46313 +extern atomic_unchecked_t fscache_n_cookie_special;
46314
46315 -extern atomic_t fscache_n_object_alloc;
46316 -extern atomic_t fscache_n_object_no_alloc;
46317 -extern atomic_t fscache_n_object_lookups;
46318 -extern atomic_t fscache_n_object_lookups_negative;
46319 -extern atomic_t fscache_n_object_lookups_positive;
46320 -extern atomic_t fscache_n_object_lookups_timed_out;
46321 -extern atomic_t fscache_n_object_created;
46322 -extern atomic_t fscache_n_object_avail;
46323 -extern atomic_t fscache_n_object_dead;
46324 +extern atomic_unchecked_t fscache_n_object_alloc;
46325 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46326 +extern atomic_unchecked_t fscache_n_object_lookups;
46327 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46328 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46329 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46330 +extern atomic_unchecked_t fscache_n_object_created;
46331 +extern atomic_unchecked_t fscache_n_object_avail;
46332 +extern atomic_unchecked_t fscache_n_object_dead;
46333
46334 -extern atomic_t fscache_n_checkaux_none;
46335 -extern atomic_t fscache_n_checkaux_okay;
46336 -extern atomic_t fscache_n_checkaux_update;
46337 -extern atomic_t fscache_n_checkaux_obsolete;
46338 +extern atomic_unchecked_t fscache_n_checkaux_none;
46339 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46340 +extern atomic_unchecked_t fscache_n_checkaux_update;
46341 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46342
46343 extern atomic_t fscache_n_cop_alloc_object;
46344 extern atomic_t fscache_n_cop_lookup_object;
46345 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46346 atomic_inc(stat);
46347 }
46348
46349 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46350 +{
46351 + atomic_inc_unchecked(stat);
46352 +}
46353 +
46354 static inline void fscache_stat_d(atomic_t *stat)
46355 {
46356 atomic_dec(stat);
46357 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46358
46359 #define __fscache_stat(stat) (NULL)
46360 #define fscache_stat(stat) do {} while (0)
46361 +#define fscache_stat_unchecked(stat) do {} while (0)
46362 #define fscache_stat_d(stat) do {} while (0)
46363 #endif
46364
46365 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46366 index b6b897c..0ffff9c 100644
46367 --- a/fs/fscache/object.c
46368 +++ b/fs/fscache/object.c
46369 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46370 /* update the object metadata on disk */
46371 case FSCACHE_OBJECT_UPDATING:
46372 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46373 - fscache_stat(&fscache_n_updates_run);
46374 + fscache_stat_unchecked(&fscache_n_updates_run);
46375 fscache_stat(&fscache_n_cop_update_object);
46376 object->cache->ops->update_object(object);
46377 fscache_stat_d(&fscache_n_cop_update_object);
46378 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46379 spin_lock(&object->lock);
46380 object->state = FSCACHE_OBJECT_DEAD;
46381 spin_unlock(&object->lock);
46382 - fscache_stat(&fscache_n_object_dead);
46383 + fscache_stat_unchecked(&fscache_n_object_dead);
46384 goto terminal_transit;
46385
46386 /* handle the parent cache of this object being withdrawn from
46387 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46388 spin_lock(&object->lock);
46389 object->state = FSCACHE_OBJECT_DEAD;
46390 spin_unlock(&object->lock);
46391 - fscache_stat(&fscache_n_object_dead);
46392 + fscache_stat_unchecked(&fscache_n_object_dead);
46393 goto terminal_transit;
46394
46395 /* complain about the object being woken up once it is
46396 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46397 parent->cookie->def->name, cookie->def->name,
46398 object->cache->tag->name);
46399
46400 - fscache_stat(&fscache_n_object_lookups);
46401 + fscache_stat_unchecked(&fscache_n_object_lookups);
46402 fscache_stat(&fscache_n_cop_lookup_object);
46403 ret = object->cache->ops->lookup_object(object);
46404 fscache_stat_d(&fscache_n_cop_lookup_object);
46405 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46406 if (ret == -ETIMEDOUT) {
46407 /* probably stuck behind another object, so move this one to
46408 * the back of the queue */
46409 - fscache_stat(&fscache_n_object_lookups_timed_out);
46410 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46411 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46412 }
46413
46414 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46415
46416 spin_lock(&object->lock);
46417 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46418 - fscache_stat(&fscache_n_object_lookups_negative);
46419 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46420
46421 /* transit here to allow write requests to begin stacking up
46422 * and read requests to begin returning ENODATA */
46423 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46424 * result, in which case there may be data available */
46425 spin_lock(&object->lock);
46426 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46427 - fscache_stat(&fscache_n_object_lookups_positive);
46428 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46429
46430 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46431
46432 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46433 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46434 } else {
46435 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46436 - fscache_stat(&fscache_n_object_created);
46437 + fscache_stat_unchecked(&fscache_n_object_created);
46438
46439 object->state = FSCACHE_OBJECT_AVAILABLE;
46440 spin_unlock(&object->lock);
46441 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46442 fscache_enqueue_dependents(object);
46443
46444 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46445 - fscache_stat(&fscache_n_object_avail);
46446 + fscache_stat_unchecked(&fscache_n_object_avail);
46447
46448 _leave("");
46449 }
46450 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46451 enum fscache_checkaux result;
46452
46453 if (!object->cookie->def->check_aux) {
46454 - fscache_stat(&fscache_n_checkaux_none);
46455 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46456 return FSCACHE_CHECKAUX_OKAY;
46457 }
46458
46459 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46460 switch (result) {
46461 /* entry okay as is */
46462 case FSCACHE_CHECKAUX_OKAY:
46463 - fscache_stat(&fscache_n_checkaux_okay);
46464 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46465 break;
46466
46467 /* entry requires update */
46468 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46469 - fscache_stat(&fscache_n_checkaux_update);
46470 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46471 break;
46472
46473 /* entry requires deletion */
46474 case FSCACHE_CHECKAUX_OBSOLETE:
46475 - fscache_stat(&fscache_n_checkaux_obsolete);
46476 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46477 break;
46478
46479 default:
46480 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46481 index 30afdfa..2256596 100644
46482 --- a/fs/fscache/operation.c
46483 +++ b/fs/fscache/operation.c
46484 @@ -17,7 +17,7 @@
46485 #include <linux/slab.h>
46486 #include "internal.h"
46487
46488 -atomic_t fscache_op_debug_id;
46489 +atomic_unchecked_t fscache_op_debug_id;
46490 EXPORT_SYMBOL(fscache_op_debug_id);
46491
46492 /**
46493 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46494 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46495 ASSERTCMP(atomic_read(&op->usage), >, 0);
46496
46497 - fscache_stat(&fscache_n_op_enqueue);
46498 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46499 switch (op->flags & FSCACHE_OP_TYPE) {
46500 case FSCACHE_OP_ASYNC:
46501 _debug("queue async");
46502 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46503 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46504 if (op->processor)
46505 fscache_enqueue_operation(op);
46506 - fscache_stat(&fscache_n_op_run);
46507 + fscache_stat_unchecked(&fscache_n_op_run);
46508 }
46509
46510 /*
46511 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46512 if (object->n_ops > 1) {
46513 atomic_inc(&op->usage);
46514 list_add_tail(&op->pend_link, &object->pending_ops);
46515 - fscache_stat(&fscache_n_op_pend);
46516 + fscache_stat_unchecked(&fscache_n_op_pend);
46517 } else if (!list_empty(&object->pending_ops)) {
46518 atomic_inc(&op->usage);
46519 list_add_tail(&op->pend_link, &object->pending_ops);
46520 - fscache_stat(&fscache_n_op_pend);
46521 + fscache_stat_unchecked(&fscache_n_op_pend);
46522 fscache_start_operations(object);
46523 } else {
46524 ASSERTCMP(object->n_in_progress, ==, 0);
46525 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46526 object->n_exclusive++; /* reads and writes must wait */
46527 atomic_inc(&op->usage);
46528 list_add_tail(&op->pend_link, &object->pending_ops);
46529 - fscache_stat(&fscache_n_op_pend);
46530 + fscache_stat_unchecked(&fscache_n_op_pend);
46531 ret = 0;
46532 } else {
46533 /* not allowed to submit ops in any other state */
46534 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46535 if (object->n_exclusive > 0) {
46536 atomic_inc(&op->usage);
46537 list_add_tail(&op->pend_link, &object->pending_ops);
46538 - fscache_stat(&fscache_n_op_pend);
46539 + fscache_stat_unchecked(&fscache_n_op_pend);
46540 } else if (!list_empty(&object->pending_ops)) {
46541 atomic_inc(&op->usage);
46542 list_add_tail(&op->pend_link, &object->pending_ops);
46543 - fscache_stat(&fscache_n_op_pend);
46544 + fscache_stat_unchecked(&fscache_n_op_pend);
46545 fscache_start_operations(object);
46546 } else {
46547 ASSERTCMP(object->n_exclusive, ==, 0);
46548 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46549 object->n_ops++;
46550 atomic_inc(&op->usage);
46551 list_add_tail(&op->pend_link, &object->pending_ops);
46552 - fscache_stat(&fscache_n_op_pend);
46553 + fscache_stat_unchecked(&fscache_n_op_pend);
46554 ret = 0;
46555 } else if (object->state == FSCACHE_OBJECT_DYING ||
46556 object->state == FSCACHE_OBJECT_LC_DYING ||
46557 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46558 - fscache_stat(&fscache_n_op_rejected);
46559 + fscache_stat_unchecked(&fscache_n_op_rejected);
46560 ret = -ENOBUFS;
46561 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46562 fscache_report_unexpected_submission(object, op, ostate);
46563 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46564
46565 ret = -EBUSY;
46566 if (!list_empty(&op->pend_link)) {
46567 - fscache_stat(&fscache_n_op_cancelled);
46568 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46569 list_del_init(&op->pend_link);
46570 object->n_ops--;
46571 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46572 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46573 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46574 BUG();
46575
46576 - fscache_stat(&fscache_n_op_release);
46577 + fscache_stat_unchecked(&fscache_n_op_release);
46578
46579 if (op->release) {
46580 op->release(op);
46581 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46582 * lock, and defer it otherwise */
46583 if (!spin_trylock(&object->lock)) {
46584 _debug("defer put");
46585 - fscache_stat(&fscache_n_op_deferred_release);
46586 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46587
46588 cache = object->cache;
46589 spin_lock(&cache->op_gc_list_lock);
46590 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46591
46592 _debug("GC DEFERRED REL OBJ%x OP%x",
46593 object->debug_id, op->debug_id);
46594 - fscache_stat(&fscache_n_op_gc);
46595 + fscache_stat_unchecked(&fscache_n_op_gc);
46596
46597 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46598
46599 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46600 index 3f7a59b..cf196cc 100644
46601 --- a/fs/fscache/page.c
46602 +++ b/fs/fscache/page.c
46603 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46604 val = radix_tree_lookup(&cookie->stores, page->index);
46605 if (!val) {
46606 rcu_read_unlock();
46607 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46608 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46609 __fscache_uncache_page(cookie, page);
46610 return true;
46611 }
46612 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46613 spin_unlock(&cookie->stores_lock);
46614
46615 if (xpage) {
46616 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46617 - fscache_stat(&fscache_n_store_radix_deletes);
46618 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46619 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46620 ASSERTCMP(xpage, ==, page);
46621 } else {
46622 - fscache_stat(&fscache_n_store_vmscan_gone);
46623 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46624 }
46625
46626 wake_up_bit(&cookie->flags, 0);
46627 @@ -107,7 +107,7 @@ page_busy:
46628 /* we might want to wait here, but that could deadlock the allocator as
46629 * the work threads writing to the cache may all end up sleeping
46630 * on memory allocation */
46631 - fscache_stat(&fscache_n_store_vmscan_busy);
46632 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46633 return false;
46634 }
46635 EXPORT_SYMBOL(__fscache_maybe_release_page);
46636 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46637 FSCACHE_COOKIE_STORING_TAG);
46638 if (!radix_tree_tag_get(&cookie->stores, page->index,
46639 FSCACHE_COOKIE_PENDING_TAG)) {
46640 - fscache_stat(&fscache_n_store_radix_deletes);
46641 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46642 xpage = radix_tree_delete(&cookie->stores, page->index);
46643 }
46644 spin_unlock(&cookie->stores_lock);
46645 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46646
46647 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46648
46649 - fscache_stat(&fscache_n_attr_changed_calls);
46650 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46651
46652 if (fscache_object_is_active(object)) {
46653 fscache_stat(&fscache_n_cop_attr_changed);
46654 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46655
46656 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46657
46658 - fscache_stat(&fscache_n_attr_changed);
46659 + fscache_stat_unchecked(&fscache_n_attr_changed);
46660
46661 op = kzalloc(sizeof(*op), GFP_KERNEL);
46662 if (!op) {
46663 - fscache_stat(&fscache_n_attr_changed_nomem);
46664 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46665 _leave(" = -ENOMEM");
46666 return -ENOMEM;
46667 }
46668 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46669 if (fscache_submit_exclusive_op(object, op) < 0)
46670 goto nobufs;
46671 spin_unlock(&cookie->lock);
46672 - fscache_stat(&fscache_n_attr_changed_ok);
46673 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46674 fscache_put_operation(op);
46675 _leave(" = 0");
46676 return 0;
46677 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46678 nobufs:
46679 spin_unlock(&cookie->lock);
46680 kfree(op);
46681 - fscache_stat(&fscache_n_attr_changed_nobufs);
46682 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46683 _leave(" = %d", -ENOBUFS);
46684 return -ENOBUFS;
46685 }
46686 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46687 /* allocate a retrieval operation and attempt to submit it */
46688 op = kzalloc(sizeof(*op), GFP_NOIO);
46689 if (!op) {
46690 - fscache_stat(&fscache_n_retrievals_nomem);
46691 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46692 return NULL;
46693 }
46694
46695 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46696 return 0;
46697 }
46698
46699 - fscache_stat(&fscache_n_retrievals_wait);
46700 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46701
46702 jif = jiffies;
46703 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46704 fscache_wait_bit_interruptible,
46705 TASK_INTERRUPTIBLE) != 0) {
46706 - fscache_stat(&fscache_n_retrievals_intr);
46707 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46708 _leave(" = -ERESTARTSYS");
46709 return -ERESTARTSYS;
46710 }
46711 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46712 */
46713 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46714 struct fscache_retrieval *op,
46715 - atomic_t *stat_op_waits,
46716 - atomic_t *stat_object_dead)
46717 + atomic_unchecked_t *stat_op_waits,
46718 + atomic_unchecked_t *stat_object_dead)
46719 {
46720 int ret;
46721
46722 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46723 goto check_if_dead;
46724
46725 _debug(">>> WT");
46726 - fscache_stat(stat_op_waits);
46727 + fscache_stat_unchecked(stat_op_waits);
46728 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46729 fscache_wait_bit_interruptible,
46730 TASK_INTERRUPTIBLE) < 0) {
46731 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46732
46733 check_if_dead:
46734 if (unlikely(fscache_object_is_dead(object))) {
46735 - fscache_stat(stat_object_dead);
46736 + fscache_stat_unchecked(stat_object_dead);
46737 return -ENOBUFS;
46738 }
46739 return 0;
46740 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46741
46742 _enter("%p,%p,,,", cookie, page);
46743
46744 - fscache_stat(&fscache_n_retrievals);
46745 + fscache_stat_unchecked(&fscache_n_retrievals);
46746
46747 if (hlist_empty(&cookie->backing_objects))
46748 goto nobufs;
46749 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46750 goto nobufs_unlock;
46751 spin_unlock(&cookie->lock);
46752
46753 - fscache_stat(&fscache_n_retrieval_ops);
46754 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46755
46756 /* pin the netfs read context in case we need to do the actual netfs
46757 * read because we've encountered a cache read failure */
46758 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46759
46760 error:
46761 if (ret == -ENOMEM)
46762 - fscache_stat(&fscache_n_retrievals_nomem);
46763 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46764 else if (ret == -ERESTARTSYS)
46765 - fscache_stat(&fscache_n_retrievals_intr);
46766 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46767 else if (ret == -ENODATA)
46768 - fscache_stat(&fscache_n_retrievals_nodata);
46769 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46770 else if (ret < 0)
46771 - fscache_stat(&fscache_n_retrievals_nobufs);
46772 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46773 else
46774 - fscache_stat(&fscache_n_retrievals_ok);
46775 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46776
46777 fscache_put_retrieval(op);
46778 _leave(" = %d", ret);
46779 @@ -429,7 +429,7 @@ nobufs_unlock:
46780 spin_unlock(&cookie->lock);
46781 kfree(op);
46782 nobufs:
46783 - fscache_stat(&fscache_n_retrievals_nobufs);
46784 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46785 _leave(" = -ENOBUFS");
46786 return -ENOBUFS;
46787 }
46788 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46789
46790 _enter("%p,,%d,,,", cookie, *nr_pages);
46791
46792 - fscache_stat(&fscache_n_retrievals);
46793 + fscache_stat_unchecked(&fscache_n_retrievals);
46794
46795 if (hlist_empty(&cookie->backing_objects))
46796 goto nobufs;
46797 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46798 goto nobufs_unlock;
46799 spin_unlock(&cookie->lock);
46800
46801 - fscache_stat(&fscache_n_retrieval_ops);
46802 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46803
46804 /* pin the netfs read context in case we need to do the actual netfs
46805 * read because we've encountered a cache read failure */
46806 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46807
46808 error:
46809 if (ret == -ENOMEM)
46810 - fscache_stat(&fscache_n_retrievals_nomem);
46811 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46812 else if (ret == -ERESTARTSYS)
46813 - fscache_stat(&fscache_n_retrievals_intr);
46814 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46815 else if (ret == -ENODATA)
46816 - fscache_stat(&fscache_n_retrievals_nodata);
46817 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46818 else if (ret < 0)
46819 - fscache_stat(&fscache_n_retrievals_nobufs);
46820 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46821 else
46822 - fscache_stat(&fscache_n_retrievals_ok);
46823 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46824
46825 fscache_put_retrieval(op);
46826 _leave(" = %d", ret);
46827 @@ -545,7 +545,7 @@ nobufs_unlock:
46828 spin_unlock(&cookie->lock);
46829 kfree(op);
46830 nobufs:
46831 - fscache_stat(&fscache_n_retrievals_nobufs);
46832 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46833 _leave(" = -ENOBUFS");
46834 return -ENOBUFS;
46835 }
46836 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46837
46838 _enter("%p,%p,,,", cookie, page);
46839
46840 - fscache_stat(&fscache_n_allocs);
46841 + fscache_stat_unchecked(&fscache_n_allocs);
46842
46843 if (hlist_empty(&cookie->backing_objects))
46844 goto nobufs;
46845 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46846 goto nobufs_unlock;
46847 spin_unlock(&cookie->lock);
46848
46849 - fscache_stat(&fscache_n_alloc_ops);
46850 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46851
46852 ret = fscache_wait_for_retrieval_activation(
46853 object, op,
46854 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46855
46856 error:
46857 if (ret == -ERESTARTSYS)
46858 - fscache_stat(&fscache_n_allocs_intr);
46859 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46860 else if (ret < 0)
46861 - fscache_stat(&fscache_n_allocs_nobufs);
46862 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46863 else
46864 - fscache_stat(&fscache_n_allocs_ok);
46865 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46866
46867 fscache_put_retrieval(op);
46868 _leave(" = %d", ret);
46869 @@ -625,7 +625,7 @@ nobufs_unlock:
46870 spin_unlock(&cookie->lock);
46871 kfree(op);
46872 nobufs:
46873 - fscache_stat(&fscache_n_allocs_nobufs);
46874 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46875 _leave(" = -ENOBUFS");
46876 return -ENOBUFS;
46877 }
46878 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46879
46880 spin_lock(&cookie->stores_lock);
46881
46882 - fscache_stat(&fscache_n_store_calls);
46883 + fscache_stat_unchecked(&fscache_n_store_calls);
46884
46885 /* find a page to store */
46886 page = NULL;
46887 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46888 page = results[0];
46889 _debug("gang %d [%lx]", n, page->index);
46890 if (page->index > op->store_limit) {
46891 - fscache_stat(&fscache_n_store_pages_over_limit);
46892 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46893 goto superseded;
46894 }
46895
46896 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46897 spin_unlock(&cookie->stores_lock);
46898 spin_unlock(&object->lock);
46899
46900 - fscache_stat(&fscache_n_store_pages);
46901 + fscache_stat_unchecked(&fscache_n_store_pages);
46902 fscache_stat(&fscache_n_cop_write_page);
46903 ret = object->cache->ops->write_page(op, page);
46904 fscache_stat_d(&fscache_n_cop_write_page);
46905 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46906 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46907 ASSERT(PageFsCache(page));
46908
46909 - fscache_stat(&fscache_n_stores);
46910 + fscache_stat_unchecked(&fscache_n_stores);
46911
46912 op = kzalloc(sizeof(*op), GFP_NOIO);
46913 if (!op)
46914 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46915 spin_unlock(&cookie->stores_lock);
46916 spin_unlock(&object->lock);
46917
46918 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46919 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46920 op->store_limit = object->store_limit;
46921
46922 if (fscache_submit_op(object, &op->op) < 0)
46923 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46924
46925 spin_unlock(&cookie->lock);
46926 radix_tree_preload_end();
46927 - fscache_stat(&fscache_n_store_ops);
46928 - fscache_stat(&fscache_n_stores_ok);
46929 + fscache_stat_unchecked(&fscache_n_store_ops);
46930 + fscache_stat_unchecked(&fscache_n_stores_ok);
46931
46932 /* the work queue now carries its own ref on the object */
46933 fscache_put_operation(&op->op);
46934 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46935 return 0;
46936
46937 already_queued:
46938 - fscache_stat(&fscache_n_stores_again);
46939 + fscache_stat_unchecked(&fscache_n_stores_again);
46940 already_pending:
46941 spin_unlock(&cookie->stores_lock);
46942 spin_unlock(&object->lock);
46943 spin_unlock(&cookie->lock);
46944 radix_tree_preload_end();
46945 kfree(op);
46946 - fscache_stat(&fscache_n_stores_ok);
46947 + fscache_stat_unchecked(&fscache_n_stores_ok);
46948 _leave(" = 0");
46949 return 0;
46950
46951 @@ -851,14 +851,14 @@ nobufs:
46952 spin_unlock(&cookie->lock);
46953 radix_tree_preload_end();
46954 kfree(op);
46955 - fscache_stat(&fscache_n_stores_nobufs);
46956 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46957 _leave(" = -ENOBUFS");
46958 return -ENOBUFS;
46959
46960 nomem_free:
46961 kfree(op);
46962 nomem:
46963 - fscache_stat(&fscache_n_stores_oom);
46964 + fscache_stat_unchecked(&fscache_n_stores_oom);
46965 _leave(" = -ENOMEM");
46966 return -ENOMEM;
46967 }
46968 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46969 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46970 ASSERTCMP(page, !=, NULL);
46971
46972 - fscache_stat(&fscache_n_uncaches);
46973 + fscache_stat_unchecked(&fscache_n_uncaches);
46974
46975 /* cache withdrawal may beat us to it */
46976 if (!PageFsCache(page))
46977 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46978 unsigned long loop;
46979
46980 #ifdef CONFIG_FSCACHE_STATS
46981 - atomic_add(pagevec->nr, &fscache_n_marks);
46982 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46983 #endif
46984
46985 for (loop = 0; loop < pagevec->nr; loop++) {
46986 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46987 index 4765190..2a067f2 100644
46988 --- a/fs/fscache/stats.c
46989 +++ b/fs/fscache/stats.c
46990 @@ -18,95 +18,95 @@
46991 /*
46992 * operation counters
46993 */
46994 -atomic_t fscache_n_op_pend;
46995 -atomic_t fscache_n_op_run;
46996 -atomic_t fscache_n_op_enqueue;
46997 -atomic_t fscache_n_op_requeue;
46998 -atomic_t fscache_n_op_deferred_release;
46999 -atomic_t fscache_n_op_release;
47000 -atomic_t fscache_n_op_gc;
47001 -atomic_t fscache_n_op_cancelled;
47002 -atomic_t fscache_n_op_rejected;
47003 +atomic_unchecked_t fscache_n_op_pend;
47004 +atomic_unchecked_t fscache_n_op_run;
47005 +atomic_unchecked_t fscache_n_op_enqueue;
47006 +atomic_unchecked_t fscache_n_op_requeue;
47007 +atomic_unchecked_t fscache_n_op_deferred_release;
47008 +atomic_unchecked_t fscache_n_op_release;
47009 +atomic_unchecked_t fscache_n_op_gc;
47010 +atomic_unchecked_t fscache_n_op_cancelled;
47011 +atomic_unchecked_t fscache_n_op_rejected;
47012
47013 -atomic_t fscache_n_attr_changed;
47014 -atomic_t fscache_n_attr_changed_ok;
47015 -atomic_t fscache_n_attr_changed_nobufs;
47016 -atomic_t fscache_n_attr_changed_nomem;
47017 -atomic_t fscache_n_attr_changed_calls;
47018 +atomic_unchecked_t fscache_n_attr_changed;
47019 +atomic_unchecked_t fscache_n_attr_changed_ok;
47020 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47021 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47022 +atomic_unchecked_t fscache_n_attr_changed_calls;
47023
47024 -atomic_t fscache_n_allocs;
47025 -atomic_t fscache_n_allocs_ok;
47026 -atomic_t fscache_n_allocs_wait;
47027 -atomic_t fscache_n_allocs_nobufs;
47028 -atomic_t fscache_n_allocs_intr;
47029 -atomic_t fscache_n_allocs_object_dead;
47030 -atomic_t fscache_n_alloc_ops;
47031 -atomic_t fscache_n_alloc_op_waits;
47032 +atomic_unchecked_t fscache_n_allocs;
47033 +atomic_unchecked_t fscache_n_allocs_ok;
47034 +atomic_unchecked_t fscache_n_allocs_wait;
47035 +atomic_unchecked_t fscache_n_allocs_nobufs;
47036 +atomic_unchecked_t fscache_n_allocs_intr;
47037 +atomic_unchecked_t fscache_n_allocs_object_dead;
47038 +atomic_unchecked_t fscache_n_alloc_ops;
47039 +atomic_unchecked_t fscache_n_alloc_op_waits;
47040
47041 -atomic_t fscache_n_retrievals;
47042 -atomic_t fscache_n_retrievals_ok;
47043 -atomic_t fscache_n_retrievals_wait;
47044 -atomic_t fscache_n_retrievals_nodata;
47045 -atomic_t fscache_n_retrievals_nobufs;
47046 -atomic_t fscache_n_retrievals_intr;
47047 -atomic_t fscache_n_retrievals_nomem;
47048 -atomic_t fscache_n_retrievals_object_dead;
47049 -atomic_t fscache_n_retrieval_ops;
47050 -atomic_t fscache_n_retrieval_op_waits;
47051 +atomic_unchecked_t fscache_n_retrievals;
47052 +atomic_unchecked_t fscache_n_retrievals_ok;
47053 +atomic_unchecked_t fscache_n_retrievals_wait;
47054 +atomic_unchecked_t fscache_n_retrievals_nodata;
47055 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47056 +atomic_unchecked_t fscache_n_retrievals_intr;
47057 +atomic_unchecked_t fscache_n_retrievals_nomem;
47058 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47059 +atomic_unchecked_t fscache_n_retrieval_ops;
47060 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47061
47062 -atomic_t fscache_n_stores;
47063 -atomic_t fscache_n_stores_ok;
47064 -atomic_t fscache_n_stores_again;
47065 -atomic_t fscache_n_stores_nobufs;
47066 -atomic_t fscache_n_stores_oom;
47067 -atomic_t fscache_n_store_ops;
47068 -atomic_t fscache_n_store_calls;
47069 -atomic_t fscache_n_store_pages;
47070 -atomic_t fscache_n_store_radix_deletes;
47071 -atomic_t fscache_n_store_pages_over_limit;
47072 +atomic_unchecked_t fscache_n_stores;
47073 +atomic_unchecked_t fscache_n_stores_ok;
47074 +atomic_unchecked_t fscache_n_stores_again;
47075 +atomic_unchecked_t fscache_n_stores_nobufs;
47076 +atomic_unchecked_t fscache_n_stores_oom;
47077 +atomic_unchecked_t fscache_n_store_ops;
47078 +atomic_unchecked_t fscache_n_store_calls;
47079 +atomic_unchecked_t fscache_n_store_pages;
47080 +atomic_unchecked_t fscache_n_store_radix_deletes;
47081 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47082
47083 -atomic_t fscache_n_store_vmscan_not_storing;
47084 -atomic_t fscache_n_store_vmscan_gone;
47085 -atomic_t fscache_n_store_vmscan_busy;
47086 -atomic_t fscache_n_store_vmscan_cancelled;
47087 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47088 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47089 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47090 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47091
47092 -atomic_t fscache_n_marks;
47093 -atomic_t fscache_n_uncaches;
47094 +atomic_unchecked_t fscache_n_marks;
47095 +atomic_unchecked_t fscache_n_uncaches;
47096
47097 -atomic_t fscache_n_acquires;
47098 -atomic_t fscache_n_acquires_null;
47099 -atomic_t fscache_n_acquires_no_cache;
47100 -atomic_t fscache_n_acquires_ok;
47101 -atomic_t fscache_n_acquires_nobufs;
47102 -atomic_t fscache_n_acquires_oom;
47103 +atomic_unchecked_t fscache_n_acquires;
47104 +atomic_unchecked_t fscache_n_acquires_null;
47105 +atomic_unchecked_t fscache_n_acquires_no_cache;
47106 +atomic_unchecked_t fscache_n_acquires_ok;
47107 +atomic_unchecked_t fscache_n_acquires_nobufs;
47108 +atomic_unchecked_t fscache_n_acquires_oom;
47109
47110 -atomic_t fscache_n_updates;
47111 -atomic_t fscache_n_updates_null;
47112 -atomic_t fscache_n_updates_run;
47113 +atomic_unchecked_t fscache_n_updates;
47114 +atomic_unchecked_t fscache_n_updates_null;
47115 +atomic_unchecked_t fscache_n_updates_run;
47116
47117 -atomic_t fscache_n_relinquishes;
47118 -atomic_t fscache_n_relinquishes_null;
47119 -atomic_t fscache_n_relinquishes_waitcrt;
47120 -atomic_t fscache_n_relinquishes_retire;
47121 +atomic_unchecked_t fscache_n_relinquishes;
47122 +atomic_unchecked_t fscache_n_relinquishes_null;
47123 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47124 +atomic_unchecked_t fscache_n_relinquishes_retire;
47125
47126 -atomic_t fscache_n_cookie_index;
47127 -atomic_t fscache_n_cookie_data;
47128 -atomic_t fscache_n_cookie_special;
47129 +atomic_unchecked_t fscache_n_cookie_index;
47130 +atomic_unchecked_t fscache_n_cookie_data;
47131 +atomic_unchecked_t fscache_n_cookie_special;
47132
47133 -atomic_t fscache_n_object_alloc;
47134 -atomic_t fscache_n_object_no_alloc;
47135 -atomic_t fscache_n_object_lookups;
47136 -atomic_t fscache_n_object_lookups_negative;
47137 -atomic_t fscache_n_object_lookups_positive;
47138 -atomic_t fscache_n_object_lookups_timed_out;
47139 -atomic_t fscache_n_object_created;
47140 -atomic_t fscache_n_object_avail;
47141 -atomic_t fscache_n_object_dead;
47142 +atomic_unchecked_t fscache_n_object_alloc;
47143 +atomic_unchecked_t fscache_n_object_no_alloc;
47144 +atomic_unchecked_t fscache_n_object_lookups;
47145 +atomic_unchecked_t fscache_n_object_lookups_negative;
47146 +atomic_unchecked_t fscache_n_object_lookups_positive;
47147 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47148 +atomic_unchecked_t fscache_n_object_created;
47149 +atomic_unchecked_t fscache_n_object_avail;
47150 +atomic_unchecked_t fscache_n_object_dead;
47151
47152 -atomic_t fscache_n_checkaux_none;
47153 -atomic_t fscache_n_checkaux_okay;
47154 -atomic_t fscache_n_checkaux_update;
47155 -atomic_t fscache_n_checkaux_obsolete;
47156 +atomic_unchecked_t fscache_n_checkaux_none;
47157 +atomic_unchecked_t fscache_n_checkaux_okay;
47158 +atomic_unchecked_t fscache_n_checkaux_update;
47159 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47160
47161 atomic_t fscache_n_cop_alloc_object;
47162 atomic_t fscache_n_cop_lookup_object;
47163 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47164 seq_puts(m, "FS-Cache statistics\n");
47165
47166 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47167 - atomic_read(&fscache_n_cookie_index),
47168 - atomic_read(&fscache_n_cookie_data),
47169 - atomic_read(&fscache_n_cookie_special));
47170 + atomic_read_unchecked(&fscache_n_cookie_index),
47171 + atomic_read_unchecked(&fscache_n_cookie_data),
47172 + atomic_read_unchecked(&fscache_n_cookie_special));
47173
47174 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47175 - atomic_read(&fscache_n_object_alloc),
47176 - atomic_read(&fscache_n_object_no_alloc),
47177 - atomic_read(&fscache_n_object_avail),
47178 - atomic_read(&fscache_n_object_dead));
47179 + atomic_read_unchecked(&fscache_n_object_alloc),
47180 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47181 + atomic_read_unchecked(&fscache_n_object_avail),
47182 + atomic_read_unchecked(&fscache_n_object_dead));
47183 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47184 - atomic_read(&fscache_n_checkaux_none),
47185 - atomic_read(&fscache_n_checkaux_okay),
47186 - atomic_read(&fscache_n_checkaux_update),
47187 - atomic_read(&fscache_n_checkaux_obsolete));
47188 + atomic_read_unchecked(&fscache_n_checkaux_none),
47189 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47190 + atomic_read_unchecked(&fscache_n_checkaux_update),
47191 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47192
47193 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47194 - atomic_read(&fscache_n_marks),
47195 - atomic_read(&fscache_n_uncaches));
47196 + atomic_read_unchecked(&fscache_n_marks),
47197 + atomic_read_unchecked(&fscache_n_uncaches));
47198
47199 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47200 " oom=%u\n",
47201 - atomic_read(&fscache_n_acquires),
47202 - atomic_read(&fscache_n_acquires_null),
47203 - atomic_read(&fscache_n_acquires_no_cache),
47204 - atomic_read(&fscache_n_acquires_ok),
47205 - atomic_read(&fscache_n_acquires_nobufs),
47206 - atomic_read(&fscache_n_acquires_oom));
47207 + atomic_read_unchecked(&fscache_n_acquires),
47208 + atomic_read_unchecked(&fscache_n_acquires_null),
47209 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47210 + atomic_read_unchecked(&fscache_n_acquires_ok),
47211 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47212 + atomic_read_unchecked(&fscache_n_acquires_oom));
47213
47214 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47215 - atomic_read(&fscache_n_object_lookups),
47216 - atomic_read(&fscache_n_object_lookups_negative),
47217 - atomic_read(&fscache_n_object_lookups_positive),
47218 - atomic_read(&fscache_n_object_created),
47219 - atomic_read(&fscache_n_object_lookups_timed_out));
47220 + atomic_read_unchecked(&fscache_n_object_lookups),
47221 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47222 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47223 + atomic_read_unchecked(&fscache_n_object_created),
47224 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47225
47226 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47227 - atomic_read(&fscache_n_updates),
47228 - atomic_read(&fscache_n_updates_null),
47229 - atomic_read(&fscache_n_updates_run));
47230 + atomic_read_unchecked(&fscache_n_updates),
47231 + atomic_read_unchecked(&fscache_n_updates_null),
47232 + atomic_read_unchecked(&fscache_n_updates_run));
47233
47234 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47235 - atomic_read(&fscache_n_relinquishes),
47236 - atomic_read(&fscache_n_relinquishes_null),
47237 - atomic_read(&fscache_n_relinquishes_waitcrt),
47238 - atomic_read(&fscache_n_relinquishes_retire));
47239 + atomic_read_unchecked(&fscache_n_relinquishes),
47240 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47241 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47242 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47243
47244 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47245 - atomic_read(&fscache_n_attr_changed),
47246 - atomic_read(&fscache_n_attr_changed_ok),
47247 - atomic_read(&fscache_n_attr_changed_nobufs),
47248 - atomic_read(&fscache_n_attr_changed_nomem),
47249 - atomic_read(&fscache_n_attr_changed_calls));
47250 + atomic_read_unchecked(&fscache_n_attr_changed),
47251 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47252 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47253 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47254 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47255
47256 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47257 - atomic_read(&fscache_n_allocs),
47258 - atomic_read(&fscache_n_allocs_ok),
47259 - atomic_read(&fscache_n_allocs_wait),
47260 - atomic_read(&fscache_n_allocs_nobufs),
47261 - atomic_read(&fscache_n_allocs_intr));
47262 + atomic_read_unchecked(&fscache_n_allocs),
47263 + atomic_read_unchecked(&fscache_n_allocs_ok),
47264 + atomic_read_unchecked(&fscache_n_allocs_wait),
47265 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47266 + atomic_read_unchecked(&fscache_n_allocs_intr));
47267 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47268 - atomic_read(&fscache_n_alloc_ops),
47269 - atomic_read(&fscache_n_alloc_op_waits),
47270 - atomic_read(&fscache_n_allocs_object_dead));
47271 + atomic_read_unchecked(&fscache_n_alloc_ops),
47272 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47273 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47274
47275 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47276 " int=%u oom=%u\n",
47277 - atomic_read(&fscache_n_retrievals),
47278 - atomic_read(&fscache_n_retrievals_ok),
47279 - atomic_read(&fscache_n_retrievals_wait),
47280 - atomic_read(&fscache_n_retrievals_nodata),
47281 - atomic_read(&fscache_n_retrievals_nobufs),
47282 - atomic_read(&fscache_n_retrievals_intr),
47283 - atomic_read(&fscache_n_retrievals_nomem));
47284 + atomic_read_unchecked(&fscache_n_retrievals),
47285 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47286 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47287 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47288 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47289 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47290 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47291 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47292 - atomic_read(&fscache_n_retrieval_ops),
47293 - atomic_read(&fscache_n_retrieval_op_waits),
47294 - atomic_read(&fscache_n_retrievals_object_dead));
47295 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47296 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47297 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47298
47299 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47300 - atomic_read(&fscache_n_stores),
47301 - atomic_read(&fscache_n_stores_ok),
47302 - atomic_read(&fscache_n_stores_again),
47303 - atomic_read(&fscache_n_stores_nobufs),
47304 - atomic_read(&fscache_n_stores_oom));
47305 + atomic_read_unchecked(&fscache_n_stores),
47306 + atomic_read_unchecked(&fscache_n_stores_ok),
47307 + atomic_read_unchecked(&fscache_n_stores_again),
47308 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47309 + atomic_read_unchecked(&fscache_n_stores_oom));
47310 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47311 - atomic_read(&fscache_n_store_ops),
47312 - atomic_read(&fscache_n_store_calls),
47313 - atomic_read(&fscache_n_store_pages),
47314 - atomic_read(&fscache_n_store_radix_deletes),
47315 - atomic_read(&fscache_n_store_pages_over_limit));
47316 + atomic_read_unchecked(&fscache_n_store_ops),
47317 + atomic_read_unchecked(&fscache_n_store_calls),
47318 + atomic_read_unchecked(&fscache_n_store_pages),
47319 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47320 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47321
47322 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47323 - atomic_read(&fscache_n_store_vmscan_not_storing),
47324 - atomic_read(&fscache_n_store_vmscan_gone),
47325 - atomic_read(&fscache_n_store_vmscan_busy),
47326 - atomic_read(&fscache_n_store_vmscan_cancelled));
47327 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47328 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47329 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47330 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47331
47332 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47333 - atomic_read(&fscache_n_op_pend),
47334 - atomic_read(&fscache_n_op_run),
47335 - atomic_read(&fscache_n_op_enqueue),
47336 - atomic_read(&fscache_n_op_cancelled),
47337 - atomic_read(&fscache_n_op_rejected));
47338 + atomic_read_unchecked(&fscache_n_op_pend),
47339 + atomic_read_unchecked(&fscache_n_op_run),
47340 + atomic_read_unchecked(&fscache_n_op_enqueue),
47341 + atomic_read_unchecked(&fscache_n_op_cancelled),
47342 + atomic_read_unchecked(&fscache_n_op_rejected));
47343 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47344 - atomic_read(&fscache_n_op_deferred_release),
47345 - atomic_read(&fscache_n_op_release),
47346 - atomic_read(&fscache_n_op_gc));
47347 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47348 + atomic_read_unchecked(&fscache_n_op_release),
47349 + atomic_read_unchecked(&fscache_n_op_gc));
47350
47351 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47352 atomic_read(&fscache_n_cop_alloc_object),
47353 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47354 index ee8d550..7189d8c 100644
47355 --- a/fs/fuse/cuse.c
47356 +++ b/fs/fuse/cuse.c
47357 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47358 INIT_LIST_HEAD(&cuse_conntbl[i]);
47359
47360 /* inherit and extend fuse_dev_operations */
47361 - cuse_channel_fops = fuse_dev_operations;
47362 - cuse_channel_fops.owner = THIS_MODULE;
47363 - cuse_channel_fops.open = cuse_channel_open;
47364 - cuse_channel_fops.release = cuse_channel_release;
47365 + pax_open_kernel();
47366 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47367 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47368 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47369 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47370 + pax_close_kernel();
47371
47372 cuse_class = class_create(THIS_MODULE, "cuse");
47373 if (IS_ERR(cuse_class))
47374 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47375 index f4246cf..b4aed1d 100644
47376 --- a/fs/fuse/dev.c
47377 +++ b/fs/fuse/dev.c
47378 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47379 ret = 0;
47380 pipe_lock(pipe);
47381
47382 - if (!pipe->readers) {
47383 + if (!atomic_read(&pipe->readers)) {
47384 send_sig(SIGPIPE, current, 0);
47385 if (!ret)
47386 ret = -EPIPE;
47387 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47388 index 324bc08..4fdd56e 100644
47389 --- a/fs/fuse/dir.c
47390 +++ b/fs/fuse/dir.c
47391 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47392 return link;
47393 }
47394
47395 -static void free_link(char *link)
47396 +static void free_link(const char *link)
47397 {
47398 if (!IS_ERR(link))
47399 free_page((unsigned long) link);
47400 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47401 index 753af3d..f7b021a 100644
47402 --- a/fs/gfs2/inode.c
47403 +++ b/fs/gfs2/inode.c
47404 @@ -1498,7 +1498,7 @@ out:
47405
47406 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47407 {
47408 - char *s = nd_get_link(nd);
47409 + const char *s = nd_get_link(nd);
47410 if (!IS_ERR(s))
47411 kfree(s);
47412 }
47413 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47414 index 8349a89..51a0254 100644
47415 --- a/fs/hugetlbfs/inode.c
47416 +++ b/fs/hugetlbfs/inode.c
47417 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47418 .kill_sb = kill_litter_super,
47419 };
47420
47421 -static struct vfsmount *hugetlbfs_vfsmount;
47422 +struct vfsmount *hugetlbfs_vfsmount;
47423
47424 static int can_do_hugetlb_shm(void)
47425 {
47426 diff --git a/fs/inode.c b/fs/inode.c
47427 index ac8d904..9f45d40 100644
47428 --- a/fs/inode.c
47429 +++ b/fs/inode.c
47430 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47431
47432 #ifdef CONFIG_SMP
47433 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47434 - static atomic_t shared_last_ino;
47435 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47436 + static atomic_unchecked_t shared_last_ino;
47437 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47438
47439 res = next - LAST_INO_BATCH;
47440 }
47441 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47442 index 4a6cf28..d3a29d3 100644
47443 --- a/fs/jffs2/erase.c
47444 +++ b/fs/jffs2/erase.c
47445 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47446 struct jffs2_unknown_node marker = {
47447 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47448 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47449 - .totlen = cpu_to_je32(c->cleanmarker_size)
47450 + .totlen = cpu_to_je32(c->cleanmarker_size),
47451 + .hdr_crc = cpu_to_je32(0)
47452 };
47453
47454 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47455 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47456 index a6597d6..41b30ec 100644
47457 --- a/fs/jffs2/wbuf.c
47458 +++ b/fs/jffs2/wbuf.c
47459 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47460 {
47461 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47462 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47463 - .totlen = constant_cpu_to_je32(8)
47464 + .totlen = constant_cpu_to_je32(8),
47465 + .hdr_crc = constant_cpu_to_je32(0)
47466 };
47467
47468 /*
47469 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47470 index c55c745..f67ee56 100644
47471 --- a/fs/jfs/super.c
47472 +++ b/fs/jfs/super.c
47473 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47474
47475 jfs_inode_cachep =
47476 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47477 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47478 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47479 init_once);
47480 if (jfs_inode_cachep == NULL)
47481 return -ENOMEM;
47482 diff --git a/fs/libfs.c b/fs/libfs.c
47483 index a74cb17..37fcbe4 100644
47484 --- a/fs/libfs.c
47485 +++ b/fs/libfs.c
47486 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47487
47488 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47489 struct dentry *next;
47490 + char d_name[sizeof(next->d_iname)];
47491 + const unsigned char *name;
47492 +
47493 next = list_entry(p, struct dentry, d_u.d_child);
47494 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47495 if (!simple_positive(next)) {
47496 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47497
47498 spin_unlock(&next->d_lock);
47499 spin_unlock(&dentry->d_lock);
47500 - if (filldir(dirent, next->d_name.name,
47501 + name = next->d_name.name;
47502 + if (name == next->d_iname) {
47503 + memcpy(d_name, name, next->d_name.len);
47504 + name = d_name;
47505 + }
47506 + if (filldir(dirent, name,
47507 next->d_name.len, filp->f_pos,
47508 next->d_inode->i_ino,
47509 dt_type(next->d_inode)) < 0)
47510 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47511 index 05d2912..760abfa 100644
47512 --- a/fs/lockd/clntproc.c
47513 +++ b/fs/lockd/clntproc.c
47514 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47515 /*
47516 * Cookie counter for NLM requests
47517 */
47518 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47519 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47520
47521 void nlmclnt_next_cookie(struct nlm_cookie *c)
47522 {
47523 - u32 cookie = atomic_inc_return(&nlm_cookie);
47524 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47525
47526 memcpy(c->data, &cookie, 4);
47527 c->len=4;
47528 diff --git a/fs/locks.c b/fs/locks.c
47529 index 7e81bfc..c3649aa 100644
47530 --- a/fs/locks.c
47531 +++ b/fs/locks.c
47532 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47533 return;
47534
47535 if (filp->f_op && filp->f_op->flock) {
47536 - struct file_lock fl = {
47537 + struct file_lock flock = {
47538 .fl_pid = current->tgid,
47539 .fl_file = filp,
47540 .fl_flags = FL_FLOCK,
47541 .fl_type = F_UNLCK,
47542 .fl_end = OFFSET_MAX,
47543 };
47544 - filp->f_op->flock(filp, F_SETLKW, &fl);
47545 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47546 - fl.fl_ops->fl_release_private(&fl);
47547 + filp->f_op->flock(filp, F_SETLKW, &flock);
47548 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47549 + flock.fl_ops->fl_release_private(&flock);
47550 }
47551
47552 lock_flocks();
47553 diff --git a/fs/namei.c b/fs/namei.c
47554 index 81bd546..80149d9 100644
47555 --- a/fs/namei.c
47556 +++ b/fs/namei.c
47557 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47558 if (ret != -EACCES)
47559 return ret;
47560
47561 +#ifdef CONFIG_GRKERNSEC
47562 + /* we'll block if we have to log due to a denied capability use */
47563 + if (mask & MAY_NOT_BLOCK)
47564 + return -ECHILD;
47565 +#endif
47566 +
47567 if (S_ISDIR(inode->i_mode)) {
47568 /* DACs are overridable for directories */
47569 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47570 - return 0;
47571 if (!(mask & MAY_WRITE))
47572 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47573 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47574 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47575 return 0;
47576 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47577 + return 0;
47578 return -EACCES;
47579 }
47580 /*
47581 + * Searching includes executable on directories, else just read.
47582 + */
47583 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47584 + if (mask == MAY_READ)
47585 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47586 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47587 + return 0;
47588 +
47589 + /*
47590 * Read/write DACs are always overridable.
47591 * Executable DACs are overridable when there is
47592 * at least one exec bit set.
47593 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47594 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47595 return 0;
47596
47597 - /*
47598 - * Searching includes executable on directories, else just read.
47599 - */
47600 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47601 - if (mask == MAY_READ)
47602 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47603 - return 0;
47604 -
47605 return -EACCES;
47606 }
47607
47608 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47609 {
47610 struct dentry *dentry = link->dentry;
47611 int error;
47612 - char *s;
47613 + const char *s;
47614
47615 BUG_ON(nd->flags & LOOKUP_RCU);
47616
47617 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47618 if (error)
47619 goto out_put_nd_path;
47620
47621 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47622 + dentry->d_inode, dentry, nd->path.mnt)) {
47623 + error = -EACCES;
47624 + goto out_put_nd_path;
47625 + }
47626 +
47627 nd->last_type = LAST_BIND;
47628 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47629 error = PTR_ERR(*p);
47630 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47631 break;
47632 res = walk_component(nd, path, &nd->last,
47633 nd->last_type, LOOKUP_FOLLOW);
47634 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47635 + res = -EACCES;
47636 put_link(nd, &link, cookie);
47637 } while (res > 0);
47638
47639 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47640 if (err)
47641 break;
47642 err = lookup_last(nd, &path);
47643 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47644 + err = -EACCES;
47645 put_link(nd, &link, cookie);
47646 }
47647 }
47648 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47649 if (!err)
47650 err = complete_walk(nd);
47651
47652 + if (!(nd->flags & LOOKUP_PARENT)) {
47653 +#ifdef CONFIG_GRKERNSEC
47654 + if (flags & LOOKUP_RCU) {
47655 + if (!err)
47656 + path_put(&nd->path);
47657 + err = -ECHILD;
47658 + } else
47659 +#endif
47660 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47661 + if (!err)
47662 + path_put(&nd->path);
47663 + err = -ENOENT;
47664 + }
47665 + }
47666 +
47667 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47668 if (!nd->inode->i_op->lookup) {
47669 path_put(&nd->path);
47670 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47671 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47672
47673 if (likely(!retval)) {
47674 + if (*name != '/' && nd->path.dentry && nd->inode) {
47675 +#ifdef CONFIG_GRKERNSEC
47676 + if (flags & LOOKUP_RCU)
47677 + return -ECHILD;
47678 +#endif
47679 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47680 + return -ENOENT;
47681 + }
47682 +
47683 if (unlikely(!audit_dummy_context())) {
47684 if (nd->path.dentry && nd->inode)
47685 audit_inode(name, nd->path.dentry);
47686 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47687 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47688 return -EPERM;
47689
47690 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47691 + return -EPERM;
47692 + if (gr_handle_rawio(inode))
47693 + return -EPERM;
47694 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47695 + return -EACCES;
47696 +
47697 return 0;
47698 }
47699
47700 @@ -2557,7 +2606,7 @@ looked_up:
47701 * cleared otherwise prior to returning.
47702 */
47703 static int lookup_open(struct nameidata *nd, struct path *path,
47704 - struct file *file,
47705 + struct path *link, struct file *file,
47706 const struct open_flags *op,
47707 bool got_write, int *opened)
47708 {
47709 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47710 /* Negative dentry, just create the file */
47711 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47712 umode_t mode = op->mode;
47713 +
47714 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47715 + error = -EACCES;
47716 + goto out_dput;
47717 + }
47718 +
47719 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47720 + error = -EACCES;
47721 + goto out_dput;
47722 + }
47723 +
47724 if (!IS_POSIXACL(dir->d_inode))
47725 mode &= ~current_umask();
47726 /*
47727 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47728 nd->flags & LOOKUP_EXCL);
47729 if (error)
47730 goto out_dput;
47731 + else
47732 + gr_handle_create(dentry, nd->path.mnt);
47733 }
47734 out_no_open:
47735 path->dentry = dentry;
47736 @@ -2627,7 +2689,7 @@ out_dput:
47737 /*
47738 * Handle the last step of open()
47739 */
47740 -static int do_last(struct nameidata *nd, struct path *path,
47741 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47742 struct file *file, const struct open_flags *op,
47743 int *opened, const char *pathname)
47744 {
47745 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47746 error = complete_walk(nd);
47747 if (error)
47748 return error;
47749 +#ifdef CONFIG_GRKERNSEC
47750 + if (nd->flags & LOOKUP_RCU) {
47751 + error = -ECHILD;
47752 + goto out;
47753 + }
47754 +#endif
47755 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47756 + error = -ENOENT;
47757 + goto out;
47758 + }
47759 audit_inode(pathname, nd->path.dentry);
47760 if (open_flag & O_CREAT) {
47761 error = -EISDIR;
47762 goto out;
47763 }
47764 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47765 + error = -EACCES;
47766 + goto out;
47767 + }
47768 goto finish_open;
47769 case LAST_BIND:
47770 error = complete_walk(nd);
47771 if (error)
47772 return error;
47773 +#ifdef CONFIG_GRKERNSEC
47774 + if (nd->flags & LOOKUP_RCU) {
47775 + error = -ECHILD;
47776 + goto out;
47777 + }
47778 +#endif
47779 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47780 + error = -ENOENT;
47781 + goto out;
47782 + }
47783 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47784 + error = -EACCES;
47785 + goto out;
47786 + }
47787 audit_inode(pathname, dir);
47788 goto finish_open;
47789 }
47790 @@ -2714,7 +2804,7 @@ retry_lookup:
47791 */
47792 }
47793 mutex_lock(&dir->d_inode->i_mutex);
47794 - error = lookup_open(nd, path, file, op, got_write, opened);
47795 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47796 mutex_unlock(&dir->d_inode->i_mutex);
47797
47798 if (error <= 0) {
47799 @@ -2738,11 +2828,28 @@ retry_lookup:
47800 goto finish_open_created;
47801 }
47802
47803 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47804 + error = -ENOENT;
47805 + goto exit_dput;
47806 + }
47807 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47808 + error = -EACCES;
47809 + goto exit_dput;
47810 + }
47811 +
47812 /*
47813 * create/update audit record if it already exists.
47814 */
47815 - if (path->dentry->d_inode)
47816 + if (path->dentry->d_inode) {
47817 + /* only check if O_CREAT is specified, all other checks need to go
47818 + into may_open */
47819 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47820 + error = -EACCES;
47821 + goto exit_dput;
47822 + }
47823 +
47824 audit_inode(pathname, path->dentry);
47825 + }
47826
47827 /*
47828 * If atomic_open() acquired write access it is dropped now due to
47829 @@ -2783,6 +2890,11 @@ finish_lookup:
47830 }
47831 }
47832 BUG_ON(inode != path->dentry->d_inode);
47833 + /* if we're resolving a symlink to another symlink */
47834 + if (link && gr_handle_symlink_owner(link, inode)) {
47835 + error = -EACCES;
47836 + goto out;
47837 + }
47838 return 1;
47839 }
47840
47841 @@ -2792,7 +2904,6 @@ finish_lookup:
47842 save_parent.dentry = nd->path.dentry;
47843 save_parent.mnt = mntget(path->mnt);
47844 nd->path.dentry = path->dentry;
47845 -
47846 }
47847 nd->inode = inode;
47848 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47849 @@ -2801,6 +2912,22 @@ finish_lookup:
47850 path_put(&save_parent);
47851 return error;
47852 }
47853 +
47854 +#ifdef CONFIG_GRKERNSEC
47855 + if (nd->flags & LOOKUP_RCU) {
47856 + error = -ECHILD;
47857 + goto out;
47858 + }
47859 +#endif
47860 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47861 + error = -ENOENT;
47862 + goto out;
47863 + }
47864 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47865 + error = -EACCES;
47866 + goto out;
47867 + }
47868 +
47869 error = -EISDIR;
47870 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47871 goto out;
47872 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47873 if (unlikely(error))
47874 goto out;
47875
47876 - error = do_last(nd, &path, file, op, &opened, pathname);
47877 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47878 while (unlikely(error > 0)) { /* trailing symlink */
47879 struct path link = path;
47880 void *cookie;
47881 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47882 error = follow_link(&link, nd, &cookie);
47883 if (unlikely(error))
47884 break;
47885 - error = do_last(nd, &path, file, op, &opened, pathname);
47886 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
47887 put_link(nd, &link, cookie);
47888 }
47889 out:
47890 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47891 goto unlock;
47892
47893 error = -EEXIST;
47894 - if (dentry->d_inode)
47895 + if (dentry->d_inode) {
47896 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47897 + error = -ENOENT;
47898 + }
47899 goto fail;
47900 + }
47901 /*
47902 * Special case - lookup gave negative, but... we had foo/bar/
47903 * From the vfs_mknod() POV we just have a negative dentry -
47904 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47905 }
47906 EXPORT_SYMBOL(user_path_create);
47907
47908 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47909 +{
47910 + char *tmp = getname(pathname);
47911 + struct dentry *res;
47912 + if (IS_ERR(tmp))
47913 + return ERR_CAST(tmp);
47914 + res = kern_path_create(dfd, tmp, path, is_dir);
47915 + if (IS_ERR(res))
47916 + putname(tmp);
47917 + else
47918 + *to = tmp;
47919 + return res;
47920 +}
47921 +
47922 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47923 {
47924 int error = may_create(dir, dentry);
47925 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47926
47927 if (!IS_POSIXACL(path.dentry->d_inode))
47928 mode &= ~current_umask();
47929 +
47930 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47931 + error = -EPERM;
47932 + goto out;
47933 + }
47934 +
47935 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47936 + error = -EACCES;
47937 + goto out;
47938 + }
47939 +
47940 error = security_path_mknod(&path, dentry, mode, dev);
47941 if (error)
47942 goto out;
47943 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47944 break;
47945 }
47946 out:
47947 + if (!error)
47948 + gr_handle_create(dentry, path.mnt);
47949 done_path_create(&path, dentry);
47950 return error;
47951 }
47952 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47953
47954 if (!IS_POSIXACL(path.dentry->d_inode))
47955 mode &= ~current_umask();
47956 +
47957 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47958 + error = -EACCES;
47959 + goto out;
47960 + }
47961 +
47962 error = security_path_mkdir(&path, dentry, mode);
47963 if (!error)
47964 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47965 + if (!error)
47966 + gr_handle_create(dentry, path.mnt);
47967 +out:
47968 done_path_create(&path, dentry);
47969 return error;
47970 }
47971 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47972 char * name;
47973 struct dentry *dentry;
47974 struct nameidata nd;
47975 + ino_t saved_ino = 0;
47976 + dev_t saved_dev = 0;
47977
47978 error = user_path_parent(dfd, pathname, &nd, &name);
47979 if (error)
47980 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
47981 error = -ENOENT;
47982 goto exit3;
47983 }
47984 +
47985 + saved_ino = dentry->d_inode->i_ino;
47986 + saved_dev = gr_get_dev_from_dentry(dentry);
47987 +
47988 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47989 + error = -EACCES;
47990 + goto exit3;
47991 + }
47992 +
47993 error = security_path_rmdir(&nd.path, dentry);
47994 if (error)
47995 goto exit3;
47996 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47997 + if (!error && (saved_dev || saved_ino))
47998 + gr_handle_delete(saved_ino, saved_dev);
47999 exit3:
48000 dput(dentry);
48001 exit2:
48002 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48003 struct dentry *dentry;
48004 struct nameidata nd;
48005 struct inode *inode = NULL;
48006 + ino_t saved_ino = 0;
48007 + dev_t saved_dev = 0;
48008
48009 error = user_path_parent(dfd, pathname, &nd, &name);
48010 if (error)
48011 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48012 if (!inode)
48013 goto slashes;
48014 ihold(inode);
48015 +
48016 + if (inode->i_nlink <= 1) {
48017 + saved_ino = inode->i_ino;
48018 + saved_dev = gr_get_dev_from_dentry(dentry);
48019 + }
48020 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48021 + error = -EACCES;
48022 + goto exit2;
48023 + }
48024 +
48025 error = security_path_unlink(&nd.path, dentry);
48026 if (error)
48027 goto exit2;
48028 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48029 + if (!error && (saved_ino || saved_dev))
48030 + gr_handle_delete(saved_ino, saved_dev);
48031 exit2:
48032 dput(dentry);
48033 }
48034 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48035 if (IS_ERR(dentry))
48036 goto out_putname;
48037
48038 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48039 + error = -EACCES;
48040 + goto out;
48041 + }
48042 +
48043 error = security_path_symlink(&path, dentry, from);
48044 if (!error)
48045 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48046 + if (!error)
48047 + gr_handle_create(dentry, path.mnt);
48048 +out:
48049 done_path_create(&path, dentry);
48050 out_putname:
48051 putname(from);
48052 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48053 {
48054 struct dentry *new_dentry;
48055 struct path old_path, new_path;
48056 + char *to = NULL;
48057 int how = 0;
48058 int error;
48059
48060 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48061 if (error)
48062 return error;
48063
48064 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48065 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48066 error = PTR_ERR(new_dentry);
48067 if (IS_ERR(new_dentry))
48068 goto out;
48069 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48070 error = may_linkat(&old_path);
48071 if (unlikely(error))
48072 goto out_dput;
48073 +
48074 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48075 + old_path.dentry->d_inode,
48076 + old_path.dentry->d_inode->i_mode, to)) {
48077 + error = -EACCES;
48078 + goto out_dput;
48079 + }
48080 +
48081 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48082 + old_path.dentry, old_path.mnt, to)) {
48083 + error = -EACCES;
48084 + goto out_dput;
48085 + }
48086 +
48087 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48088 if (error)
48089 goto out_dput;
48090 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48091 + if (!error)
48092 + gr_handle_create(new_dentry, new_path.mnt);
48093 out_dput:
48094 + putname(to);
48095 done_path_create(&new_path, new_dentry);
48096 out:
48097 path_put(&old_path);
48098 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48099 if (new_dentry == trap)
48100 goto exit5;
48101
48102 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48103 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48104 + to);
48105 + if (error)
48106 + goto exit5;
48107 +
48108 error = security_path_rename(&oldnd.path, old_dentry,
48109 &newnd.path, new_dentry);
48110 if (error)
48111 goto exit5;
48112 error = vfs_rename(old_dir->d_inode, old_dentry,
48113 new_dir->d_inode, new_dentry);
48114 + if (!error)
48115 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48116 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48117 exit5:
48118 dput(new_dentry);
48119 exit4:
48120 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48121
48122 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48123 {
48124 + char tmpbuf[64];
48125 + const char *newlink;
48126 int len;
48127
48128 len = PTR_ERR(link);
48129 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48130 len = strlen(link);
48131 if (len > (unsigned) buflen)
48132 len = buflen;
48133 - if (copy_to_user(buffer, link, len))
48134 +
48135 + if (len < sizeof(tmpbuf)) {
48136 + memcpy(tmpbuf, link, len);
48137 + newlink = tmpbuf;
48138 + } else
48139 + newlink = link;
48140 +
48141 + if (copy_to_user(buffer, newlink, len))
48142 len = -EFAULT;
48143 out:
48144 return len;
48145 diff --git a/fs/namespace.c b/fs/namespace.c
48146 index 7bdf790..eb79c4b 100644
48147 --- a/fs/namespace.c
48148 +++ b/fs/namespace.c
48149 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48150 if (!(sb->s_flags & MS_RDONLY))
48151 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48152 up_write(&sb->s_umount);
48153 +
48154 + gr_log_remount(mnt->mnt_devname, retval);
48155 +
48156 return retval;
48157 }
48158
48159 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48160 br_write_unlock(&vfsmount_lock);
48161 up_write(&namespace_sem);
48162 release_mounts(&umount_list);
48163 +
48164 + gr_log_unmount(mnt->mnt_devname, retval);
48165 +
48166 return retval;
48167 }
48168
48169 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48170 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48171 MS_STRICTATIME);
48172
48173 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48174 + retval = -EPERM;
48175 + goto dput_out;
48176 + }
48177 +
48178 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48179 + retval = -EPERM;
48180 + goto dput_out;
48181 + }
48182 +
48183 if (flags & MS_REMOUNT)
48184 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48185 data_page);
48186 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48187 dev_name, data_page);
48188 dput_out:
48189 path_put(&path);
48190 +
48191 + gr_log_mount(dev_name, dir_name, retval);
48192 +
48193 return retval;
48194 }
48195
48196 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48197 if (error)
48198 goto out2;
48199
48200 + if (gr_handle_chroot_pivot()) {
48201 + error = -EPERM;
48202 + goto out2;
48203 + }
48204 +
48205 get_fs_root(current->fs, &root);
48206 error = lock_mount(&old);
48207 if (error)
48208 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48209 index 9b47610..066975e 100644
48210 --- a/fs/nfs/inode.c
48211 +++ b/fs/nfs/inode.c
48212 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48213 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48214 }
48215
48216 -static atomic_long_t nfs_attr_generation_counter;
48217 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48218
48219 static unsigned long nfs_read_attr_generation_counter(void)
48220 {
48221 - return atomic_long_read(&nfs_attr_generation_counter);
48222 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48223 }
48224
48225 unsigned long nfs_inc_attr_generation_counter(void)
48226 {
48227 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48228 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48229 }
48230
48231 void nfs_fattr_init(struct nfs_fattr *fattr)
48232 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48233 index a9269f1..5490437 100644
48234 --- a/fs/nfsd/vfs.c
48235 +++ b/fs/nfsd/vfs.c
48236 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48237 } else {
48238 oldfs = get_fs();
48239 set_fs(KERNEL_DS);
48240 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48241 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48242 set_fs(oldfs);
48243 }
48244
48245 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48246
48247 /* Write the data. */
48248 oldfs = get_fs(); set_fs(KERNEL_DS);
48249 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48250 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48251 set_fs(oldfs);
48252 if (host_err < 0)
48253 goto out_nfserr;
48254 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48255 */
48256
48257 oldfs = get_fs(); set_fs(KERNEL_DS);
48258 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48259 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48260 set_fs(oldfs);
48261
48262 if (host_err < 0)
48263 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48264 index d438036..0ecadde 100644
48265 --- a/fs/notify/fanotify/fanotify_user.c
48266 +++ b/fs/notify/fanotify/fanotify_user.c
48267 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48268 goto out_close_fd;
48269
48270 ret = -EFAULT;
48271 - if (copy_to_user(buf, &fanotify_event_metadata,
48272 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48273 + copy_to_user(buf, &fanotify_event_metadata,
48274 fanotify_event_metadata.event_len))
48275 goto out_kill_access_response;
48276
48277 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48278 index c887b13..0fdf472 100644
48279 --- a/fs/notify/notification.c
48280 +++ b/fs/notify/notification.c
48281 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48282 * get set to 0 so it will never get 'freed'
48283 */
48284 static struct fsnotify_event *q_overflow_event;
48285 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48286 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48287
48288 /**
48289 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48290 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48291 */
48292 u32 fsnotify_get_cookie(void)
48293 {
48294 - return atomic_inc_return(&fsnotify_sync_cookie);
48295 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48296 }
48297 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48298
48299 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48300 index 99e3610..02c1068 100644
48301 --- a/fs/ntfs/dir.c
48302 +++ b/fs/ntfs/dir.c
48303 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48304 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48305 ~(s64)(ndir->itype.index.block_size - 1)));
48306 /* Bounds checks. */
48307 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48308 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48309 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48310 "inode 0x%lx or driver bug.", vdir->i_ino);
48311 goto err_out;
48312 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48313 index 1ecf464..e1ff8bf 100644
48314 --- a/fs/ntfs/file.c
48315 +++ b/fs/ntfs/file.c
48316 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48317 #endif /* NTFS_RW */
48318 };
48319
48320 -const struct file_operations ntfs_empty_file_ops = {};
48321 +const struct file_operations ntfs_empty_file_ops __read_only;
48322
48323 -const struct inode_operations ntfs_empty_inode_ops = {};
48324 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48325 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48326 index a9f78c7..ed8a381 100644
48327 --- a/fs/ocfs2/localalloc.c
48328 +++ b/fs/ocfs2/localalloc.c
48329 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48330 goto bail;
48331 }
48332
48333 - atomic_inc(&osb->alloc_stats.moves);
48334 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48335
48336 bail:
48337 if (handle)
48338 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48339 index d355e6e..578d905 100644
48340 --- a/fs/ocfs2/ocfs2.h
48341 +++ b/fs/ocfs2/ocfs2.h
48342 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48343
48344 struct ocfs2_alloc_stats
48345 {
48346 - atomic_t moves;
48347 - atomic_t local_data;
48348 - atomic_t bitmap_data;
48349 - atomic_t bg_allocs;
48350 - atomic_t bg_extends;
48351 + atomic_unchecked_t moves;
48352 + atomic_unchecked_t local_data;
48353 + atomic_unchecked_t bitmap_data;
48354 + atomic_unchecked_t bg_allocs;
48355 + atomic_unchecked_t bg_extends;
48356 };
48357
48358 enum ocfs2_local_alloc_state
48359 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48360 index f169da4..9112253 100644
48361 --- a/fs/ocfs2/suballoc.c
48362 +++ b/fs/ocfs2/suballoc.c
48363 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48364 mlog_errno(status);
48365 goto bail;
48366 }
48367 - atomic_inc(&osb->alloc_stats.bg_extends);
48368 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48369
48370 /* You should never ask for this much metadata */
48371 BUG_ON(bits_wanted >
48372 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48373 mlog_errno(status);
48374 goto bail;
48375 }
48376 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48377 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48378
48379 *suballoc_loc = res.sr_bg_blkno;
48380 *suballoc_bit_start = res.sr_bit_offset;
48381 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48382 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48383 res->sr_bits);
48384
48385 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48386 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48387
48388 BUG_ON(res->sr_bits != 1);
48389
48390 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48391 mlog_errno(status);
48392 goto bail;
48393 }
48394 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48395 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48396
48397 BUG_ON(res.sr_bits != 1);
48398
48399 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48400 cluster_start,
48401 num_clusters);
48402 if (!status)
48403 - atomic_inc(&osb->alloc_stats.local_data);
48404 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48405 } else {
48406 if (min_clusters > (osb->bitmap_cpg - 1)) {
48407 /* The only paths asking for contiguousness
48408 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48409 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48410 res.sr_bg_blkno,
48411 res.sr_bit_offset);
48412 - atomic_inc(&osb->alloc_stats.bitmap_data);
48413 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48414 *num_clusters = res.sr_bits;
48415 }
48416 }
48417 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48418 index 68f4541..89cfe6a 100644
48419 --- a/fs/ocfs2/super.c
48420 +++ b/fs/ocfs2/super.c
48421 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48422 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48423 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48424 "Stats",
48425 - atomic_read(&osb->alloc_stats.bitmap_data),
48426 - atomic_read(&osb->alloc_stats.local_data),
48427 - atomic_read(&osb->alloc_stats.bg_allocs),
48428 - atomic_read(&osb->alloc_stats.moves),
48429 - atomic_read(&osb->alloc_stats.bg_extends));
48430 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48431 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48432 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48433 + atomic_read_unchecked(&osb->alloc_stats.moves),
48434 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48435
48436 out += snprintf(buf + out, len - out,
48437 "%10s => State: %u Descriptor: %llu Size: %u bits "
48438 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48439 spin_lock_init(&osb->osb_xattr_lock);
48440 ocfs2_init_steal_slots(osb);
48441
48442 - atomic_set(&osb->alloc_stats.moves, 0);
48443 - atomic_set(&osb->alloc_stats.local_data, 0);
48444 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48445 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48446 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48447 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48448 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48449 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48450 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48451 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48452
48453 /* Copy the blockcheck stats from the superblock probe */
48454 osb->osb_ecc_stats = *stats;
48455 diff --git a/fs/open.c b/fs/open.c
48456 index e1f2cdb..3bd5f39 100644
48457 --- a/fs/open.c
48458 +++ b/fs/open.c
48459 @@ -31,6 +31,8 @@
48460 #include <linux/ima.h>
48461 #include <linux/dnotify.h>
48462
48463 +#define CREATE_TRACE_POINTS
48464 +#include <trace/events/fs.h>
48465 #include "internal.h"
48466
48467 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48468 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48469 error = locks_verify_truncate(inode, NULL, length);
48470 if (!error)
48471 error = security_path_truncate(&path);
48472 +
48473 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48474 + error = -EACCES;
48475 +
48476 if (!error)
48477 error = do_truncate(path.dentry, length, 0, NULL);
48478
48479 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48480 if (__mnt_is_readonly(path.mnt))
48481 res = -EROFS;
48482
48483 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48484 + res = -EACCES;
48485 +
48486 out_path_release:
48487 path_put(&path);
48488 out:
48489 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48490 if (error)
48491 goto dput_and_out;
48492
48493 + gr_log_chdir(path.dentry, path.mnt);
48494 +
48495 set_fs_pwd(current->fs, &path);
48496
48497 dput_and_out:
48498 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48499 goto out_putf;
48500
48501 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48502 +
48503 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48504 + error = -EPERM;
48505 +
48506 + if (!error)
48507 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48508 +
48509 if (!error)
48510 set_fs_pwd(current->fs, &file->f_path);
48511 out_putf:
48512 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48513 if (error)
48514 goto dput_and_out;
48515
48516 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48517 + goto dput_and_out;
48518 +
48519 set_fs_root(current->fs, &path);
48520 +
48521 + gr_handle_chroot_chdir(&path);
48522 +
48523 error = 0;
48524 dput_and_out:
48525 path_put(&path);
48526 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48527 if (error)
48528 return error;
48529 mutex_lock(&inode->i_mutex);
48530 +
48531 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48532 + error = -EACCES;
48533 + goto out_unlock;
48534 + }
48535 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48536 + error = -EACCES;
48537 + goto out_unlock;
48538 + }
48539 +
48540 error = security_path_chmod(path, mode);
48541 if (error)
48542 goto out_unlock;
48543 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48544 uid = make_kuid(current_user_ns(), user);
48545 gid = make_kgid(current_user_ns(), group);
48546
48547 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48548 + return -EACCES;
48549 +
48550 newattrs.ia_valid = ATTR_CTIME;
48551 if (user != (uid_t) -1) {
48552 if (!uid_valid(uid))
48553 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48554 } else {
48555 fsnotify_open(f);
48556 fd_install(fd, f);
48557 + trace_do_sys_open(tmp, flags, mode);
48558 }
48559 }
48560 putname(tmp);
48561 diff --git a/fs/pipe.c b/fs/pipe.c
48562 index 8d85d70..581036b 100644
48563 --- a/fs/pipe.c
48564 +++ b/fs/pipe.c
48565 @@ -438,9 +438,9 @@ redo:
48566 }
48567 if (bufs) /* More to do? */
48568 continue;
48569 - if (!pipe->writers)
48570 + if (!atomic_read(&pipe->writers))
48571 break;
48572 - if (!pipe->waiting_writers) {
48573 + if (!atomic_read(&pipe->waiting_writers)) {
48574 /* syscall merging: Usually we must not sleep
48575 * if O_NONBLOCK is set, or if we got some data.
48576 * But if a writer sleeps in kernel space, then
48577 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48578 mutex_lock(&inode->i_mutex);
48579 pipe = inode->i_pipe;
48580
48581 - if (!pipe->readers) {
48582 + if (!atomic_read(&pipe->readers)) {
48583 send_sig(SIGPIPE, current, 0);
48584 ret = -EPIPE;
48585 goto out;
48586 @@ -553,7 +553,7 @@ redo1:
48587 for (;;) {
48588 int bufs;
48589
48590 - if (!pipe->readers) {
48591 + if (!atomic_read(&pipe->readers)) {
48592 send_sig(SIGPIPE, current, 0);
48593 if (!ret)
48594 ret = -EPIPE;
48595 @@ -644,9 +644,9 @@ redo2:
48596 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48597 do_wakeup = 0;
48598 }
48599 - pipe->waiting_writers++;
48600 + atomic_inc(&pipe->waiting_writers);
48601 pipe_wait(pipe);
48602 - pipe->waiting_writers--;
48603 + atomic_dec(&pipe->waiting_writers);
48604 }
48605 out:
48606 mutex_unlock(&inode->i_mutex);
48607 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48608 mask = 0;
48609 if (filp->f_mode & FMODE_READ) {
48610 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48611 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48612 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48613 mask |= POLLHUP;
48614 }
48615
48616 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48617 * Most Unices do not set POLLERR for FIFOs but on Linux they
48618 * behave exactly like pipes for poll().
48619 */
48620 - if (!pipe->readers)
48621 + if (!atomic_read(&pipe->readers))
48622 mask |= POLLERR;
48623 }
48624
48625 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48626
48627 mutex_lock(&inode->i_mutex);
48628 pipe = inode->i_pipe;
48629 - pipe->readers -= decr;
48630 - pipe->writers -= decw;
48631 + atomic_sub(decr, &pipe->readers);
48632 + atomic_sub(decw, &pipe->writers);
48633
48634 - if (!pipe->readers && !pipe->writers) {
48635 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48636 free_pipe_info(inode);
48637 } else {
48638 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48639 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48640
48641 if (inode->i_pipe) {
48642 ret = 0;
48643 - inode->i_pipe->readers++;
48644 + atomic_inc(&inode->i_pipe->readers);
48645 }
48646
48647 mutex_unlock(&inode->i_mutex);
48648 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48649
48650 if (inode->i_pipe) {
48651 ret = 0;
48652 - inode->i_pipe->writers++;
48653 + atomic_inc(&inode->i_pipe->writers);
48654 }
48655
48656 mutex_unlock(&inode->i_mutex);
48657 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48658 if (inode->i_pipe) {
48659 ret = 0;
48660 if (filp->f_mode & FMODE_READ)
48661 - inode->i_pipe->readers++;
48662 + atomic_inc(&inode->i_pipe->readers);
48663 if (filp->f_mode & FMODE_WRITE)
48664 - inode->i_pipe->writers++;
48665 + atomic_inc(&inode->i_pipe->writers);
48666 }
48667
48668 mutex_unlock(&inode->i_mutex);
48669 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48670 inode->i_pipe = NULL;
48671 }
48672
48673 -static struct vfsmount *pipe_mnt __read_mostly;
48674 +struct vfsmount *pipe_mnt __read_mostly;
48675
48676 /*
48677 * pipefs_dname() is called from d_path().
48678 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48679 goto fail_iput;
48680 inode->i_pipe = pipe;
48681
48682 - pipe->readers = pipe->writers = 1;
48683 + atomic_set(&pipe->readers, 1);
48684 + atomic_set(&pipe->writers, 1);
48685 inode->i_fop = &rdwr_pipefifo_fops;
48686
48687 /*
48688 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48689 index 15af622..0e9f4467 100644
48690 --- a/fs/proc/Kconfig
48691 +++ b/fs/proc/Kconfig
48692 @@ -30,12 +30,12 @@ config PROC_FS
48693
48694 config PROC_KCORE
48695 bool "/proc/kcore support" if !ARM
48696 - depends on PROC_FS && MMU
48697 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48698
48699 config PROC_VMCORE
48700 bool "/proc/vmcore support"
48701 - depends on PROC_FS && CRASH_DUMP
48702 - default y
48703 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48704 + default n
48705 help
48706 Exports the dump image of crashed kernel in ELF format.
48707
48708 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48709 limited in memory.
48710
48711 config PROC_PAGE_MONITOR
48712 - default y
48713 - depends on PROC_FS && MMU
48714 + default n
48715 + depends on PROC_FS && MMU && !GRKERNSEC
48716 bool "Enable /proc page monitoring" if EXPERT
48717 help
48718 Various /proc files exist to monitor process memory utilization:
48719 diff --git a/fs/proc/array.c b/fs/proc/array.c
48720 index c1c207c..01ce725 100644
48721 --- a/fs/proc/array.c
48722 +++ b/fs/proc/array.c
48723 @@ -60,6 +60,7 @@
48724 #include <linux/tty.h>
48725 #include <linux/string.h>
48726 #include <linux/mman.h>
48727 +#include <linux/grsecurity.h>
48728 #include <linux/proc_fs.h>
48729 #include <linux/ioport.h>
48730 #include <linux/uaccess.h>
48731 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48732 seq_putc(m, '\n');
48733 }
48734
48735 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48736 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48737 +{
48738 + if (p->mm)
48739 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48740 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48741 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48742 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48743 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48744 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48745 + else
48746 + seq_printf(m, "PaX:\t-----\n");
48747 +}
48748 +#endif
48749 +
48750 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48751 struct pid *pid, struct task_struct *task)
48752 {
48753 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48754 task_cpus_allowed(m, task);
48755 cpuset_task_status_allowed(m, task);
48756 task_context_switch_counts(m, task);
48757 +
48758 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48759 + task_pax(m, task);
48760 +#endif
48761 +
48762 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48763 + task_grsec_rbac(m, task);
48764 +#endif
48765 +
48766 return 0;
48767 }
48768
48769 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48770 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48771 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48772 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48773 +#endif
48774 +
48775 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48776 struct pid *pid, struct task_struct *task, int whole)
48777 {
48778 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48779 char tcomm[sizeof(task->comm)];
48780 unsigned long flags;
48781
48782 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48783 + if (current->exec_id != m->exec_id) {
48784 + gr_log_badprocpid("stat");
48785 + return 0;
48786 + }
48787 +#endif
48788 +
48789 state = *get_task_state(task);
48790 vsize = eip = esp = 0;
48791 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48792 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48793 gtime = task->gtime;
48794 }
48795
48796 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48797 + if (PAX_RAND_FLAGS(mm)) {
48798 + eip = 0;
48799 + esp = 0;
48800 + wchan = 0;
48801 + }
48802 +#endif
48803 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48804 + wchan = 0;
48805 + eip =0;
48806 + esp =0;
48807 +#endif
48808 +
48809 /* scale priority and nice values from timeslices to -20..20 */
48810 /* to make it look like a "normal" Unix priority/nice value */
48811 priority = task_prio(task);
48812 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48813 seq_put_decimal_ull(m, ' ', vsize);
48814 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48815 seq_put_decimal_ull(m, ' ', rsslim);
48816 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48817 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48818 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48819 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48820 +#else
48821 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48822 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48823 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48824 +#endif
48825 seq_put_decimal_ull(m, ' ', esp);
48826 seq_put_decimal_ull(m, ' ', eip);
48827 /* The signal information here is obsolete.
48828 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48829 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48830 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48831
48832 - if (mm && permitted) {
48833 + if (mm && permitted
48834 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48835 + && !PAX_RAND_FLAGS(mm)
48836 +#endif
48837 + ) {
48838 seq_put_decimal_ull(m, ' ', mm->start_data);
48839 seq_put_decimal_ull(m, ' ', mm->end_data);
48840 seq_put_decimal_ull(m, ' ', mm->start_brk);
48841 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48842 struct pid *pid, struct task_struct *task)
48843 {
48844 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48845 - struct mm_struct *mm = get_task_mm(task);
48846 + struct mm_struct *mm;
48847
48848 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48849 + if (current->exec_id != m->exec_id) {
48850 + gr_log_badprocpid("statm");
48851 + return 0;
48852 + }
48853 +#endif
48854 + mm = get_task_mm(task);
48855 if (mm) {
48856 size = task_statm(mm, &shared, &text, &data, &resident);
48857 mmput(mm);
48858 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48859 return 0;
48860 }
48861
48862 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48863 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48864 +{
48865 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48866 +}
48867 +#endif
48868 +
48869 #ifdef CONFIG_CHECKPOINT_RESTORE
48870 static struct pid *
48871 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48872 diff --git a/fs/proc/base.c b/fs/proc/base.c
48873 index 1b6c84c..66b738b 100644
48874 --- a/fs/proc/base.c
48875 +++ b/fs/proc/base.c
48876 @@ -110,6 +110,14 @@ struct pid_entry {
48877 union proc_op op;
48878 };
48879
48880 +struct getdents_callback {
48881 + struct linux_dirent __user * current_dir;
48882 + struct linux_dirent __user * previous;
48883 + struct file * file;
48884 + int count;
48885 + int error;
48886 +};
48887 +
48888 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48889 .name = (NAME), \
48890 .len = sizeof(NAME) - 1, \
48891 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48892 if (!mm->arg_end)
48893 goto out_mm; /* Shh! No looking before we're done */
48894
48895 + if (gr_acl_handle_procpidmem(task))
48896 + goto out_mm;
48897 +
48898 len = mm->arg_end - mm->arg_start;
48899
48900 if (len > PAGE_SIZE)
48901 @@ -236,12 +247,28 @@ out:
48902 return res;
48903 }
48904
48905 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48906 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48907 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48908 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48909 +#endif
48910 +
48911 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48912 {
48913 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48914 int res = PTR_ERR(mm);
48915 if (mm && !IS_ERR(mm)) {
48916 unsigned int nwords = 0;
48917 +
48918 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48919 + /* allow if we're currently ptracing this task */
48920 + if (PAX_RAND_FLAGS(mm) &&
48921 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48922 + mmput(mm);
48923 + return 0;
48924 + }
48925 +#endif
48926 +
48927 do {
48928 nwords += 2;
48929 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48930 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48931 }
48932
48933
48934 -#ifdef CONFIG_KALLSYMS
48935 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48936 /*
48937 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48938 * Returns the resolved symbol. If that fails, simply return the address.
48939 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48940 mutex_unlock(&task->signal->cred_guard_mutex);
48941 }
48942
48943 -#ifdef CONFIG_STACKTRACE
48944 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48945
48946 #define MAX_STACK_TRACE_DEPTH 64
48947
48948 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48949 return count;
48950 }
48951
48952 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48953 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48954 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48955 {
48956 long nr;
48957 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48958 /************************************************************************/
48959
48960 /* permission checks */
48961 -static int proc_fd_access_allowed(struct inode *inode)
48962 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48963 {
48964 struct task_struct *task;
48965 int allowed = 0;
48966 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48967 */
48968 task = get_proc_task(inode);
48969 if (task) {
48970 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48971 + if (log)
48972 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48973 + else
48974 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48975 put_task_struct(task);
48976 }
48977 return allowed;
48978 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48979 struct task_struct *task,
48980 int hide_pid_min)
48981 {
48982 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48983 + return false;
48984 +
48985 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48986 + rcu_read_lock();
48987 + {
48988 + const struct cred *tmpcred = current_cred();
48989 + const struct cred *cred = __task_cred(task);
48990 +
48991 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48992 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48993 + || in_group_p(grsec_proc_gid)
48994 +#endif
48995 + ) {
48996 + rcu_read_unlock();
48997 + return true;
48998 + }
48999 + }
49000 + rcu_read_unlock();
49001 +
49002 + if (!pid->hide_pid)
49003 + return false;
49004 +#endif
49005 +
49006 if (pid->hide_pid < hide_pid_min)
49007 return true;
49008 if (in_group_p(pid->pid_gid))
49009 return true;
49010 +
49011 return ptrace_may_access(task, PTRACE_MODE_READ);
49012 }
49013
49014 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49015 put_task_struct(task);
49016
49017 if (!has_perms) {
49018 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49019 + {
49020 +#else
49021 if (pid->hide_pid == 2) {
49022 +#endif
49023 /*
49024 * Let's make getdents(), stat(), and open()
49025 * consistent with each other. If a process
49026 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49027 if (!task)
49028 return -ESRCH;
49029
49030 + if (gr_acl_handle_procpidmem(task)) {
49031 + put_task_struct(task);
49032 + return -EPERM;
49033 + }
49034 +
49035 mm = mm_access(task, mode);
49036 put_task_struct(task);
49037
49038 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49039
49040 file->private_data = mm;
49041
49042 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49043 + file->f_version = current->exec_id;
49044 +#endif
49045 +
49046 return 0;
49047 }
49048
49049 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49050 ssize_t copied;
49051 char *page;
49052
49053 +#ifdef CONFIG_GRKERNSEC
49054 + if (write)
49055 + return -EPERM;
49056 +#endif
49057 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49058 + if (file->f_version != current->exec_id) {
49059 + gr_log_badprocpid("mem");
49060 + return 0;
49061 + }
49062 +#endif
49063 +
49064 if (!mm)
49065 return 0;
49066
49067 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49068 if (!mm)
49069 return 0;
49070
49071 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49072 + if (file->f_version != current->exec_id) {
49073 + gr_log_badprocpid("environ");
49074 + return 0;
49075 + }
49076 +#endif
49077 +
49078 page = (char *)__get_free_page(GFP_TEMPORARY);
49079 if (!page)
49080 return -ENOMEM;
49081 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49082 int error = -EACCES;
49083
49084 /* Are we allowed to snoop on the tasks file descriptors? */
49085 - if (!proc_fd_access_allowed(inode))
49086 + if (!proc_fd_access_allowed(inode, 0))
49087 goto out;
49088
49089 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49090 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49091 struct path path;
49092
49093 /* Are we allowed to snoop on the tasks file descriptors? */
49094 - if (!proc_fd_access_allowed(inode))
49095 - goto out;
49096 + /* logging this is needed for learning on chromium to work properly,
49097 + but we don't want to flood the logs from 'ps' which does a readlink
49098 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49099 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49100 + */
49101 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49102 + if (!proc_fd_access_allowed(inode,0))
49103 + goto out;
49104 + } else {
49105 + if (!proc_fd_access_allowed(inode,1))
49106 + goto out;
49107 + }
49108
49109 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49110 if (error)
49111 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49112 rcu_read_lock();
49113 cred = __task_cred(task);
49114 inode->i_uid = cred->euid;
49115 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49116 + inode->i_gid = grsec_proc_gid;
49117 +#else
49118 inode->i_gid = cred->egid;
49119 +#endif
49120 rcu_read_unlock();
49121 }
49122 security_task_to_inode(task, inode);
49123 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49124 return -ENOENT;
49125 }
49126 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49127 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49128 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49129 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49130 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49131 +#endif
49132 task_dumpable(task)) {
49133 cred = __task_cred(task);
49134 stat->uid = cred->euid;
49135 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49136 + stat->gid = grsec_proc_gid;
49137 +#else
49138 stat->gid = cred->egid;
49139 +#endif
49140 }
49141 }
49142 rcu_read_unlock();
49143 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49144
49145 if (task) {
49146 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49147 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49148 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49149 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49150 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49151 +#endif
49152 task_dumpable(task)) {
49153 rcu_read_lock();
49154 cred = __task_cred(task);
49155 inode->i_uid = cred->euid;
49156 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49157 + inode->i_gid = grsec_proc_gid;
49158 +#else
49159 inode->i_gid = cred->egid;
49160 +#endif
49161 rcu_read_unlock();
49162 } else {
49163 inode->i_uid = GLOBAL_ROOT_UID;
49164 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49165 int fd = proc_fd(inode);
49166
49167 if (task) {
49168 - files = get_files_struct(task);
49169 + if (!gr_acl_handle_procpidmem(task))
49170 + files = get_files_struct(task);
49171 put_task_struct(task);
49172 }
49173 if (files) {
49174 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49175 */
49176 static int proc_fd_permission(struct inode *inode, int mask)
49177 {
49178 + struct task_struct *task;
49179 int rv = generic_permission(inode, mask);
49180 - if (rv == 0)
49181 - return 0;
49182 +
49183 if (task_pid(current) == proc_pid(inode))
49184 rv = 0;
49185 +
49186 + task = get_proc_task(inode);
49187 + if (task == NULL)
49188 + return rv;
49189 +
49190 + if (gr_acl_handle_procpidmem(task))
49191 + rv = -EACCES;
49192 +
49193 + put_task_struct(task);
49194 +
49195 return rv;
49196 }
49197
49198 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49199 if (!task)
49200 goto out_no_task;
49201
49202 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49203 + goto out;
49204 +
49205 /*
49206 * Yes, it does not scale. And it should not. Don't add
49207 * new entries into /proc/<tgid>/ without very good reasons.
49208 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49209 if (!task)
49210 goto out_no_task;
49211
49212 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49213 + goto out;
49214 +
49215 ret = 0;
49216 i = filp->f_pos;
49217 switch (i) {
49218 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49219 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49220 void *cookie)
49221 {
49222 - char *s = nd_get_link(nd);
49223 + const char *s = nd_get_link(nd);
49224 if (!IS_ERR(s))
49225 __putname(s);
49226 }
49227 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49228 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49229 #endif
49230 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49231 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49232 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49233 INF("syscall", S_IRUGO, proc_pid_syscall),
49234 #endif
49235 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49236 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49237 #ifdef CONFIG_SECURITY
49238 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49239 #endif
49240 -#ifdef CONFIG_KALLSYMS
49241 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49242 INF("wchan", S_IRUGO, proc_pid_wchan),
49243 #endif
49244 -#ifdef CONFIG_STACKTRACE
49245 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49246 ONE("stack", S_IRUGO, proc_pid_stack),
49247 #endif
49248 #ifdef CONFIG_SCHEDSTATS
49249 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49250 #ifdef CONFIG_HARDWALL
49251 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49252 #endif
49253 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49254 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49255 +#endif
49256 #ifdef CONFIG_USER_NS
49257 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49258 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49259 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49260 if (!inode)
49261 goto out;
49262
49263 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49264 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49265 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49266 + inode->i_gid = grsec_proc_gid;
49267 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49268 +#else
49269 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49270 +#endif
49271 inode->i_op = &proc_tgid_base_inode_operations;
49272 inode->i_fop = &proc_tgid_base_operations;
49273 inode->i_flags|=S_IMMUTABLE;
49274 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49275 if (!task)
49276 goto out;
49277
49278 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49279 + goto out_put_task;
49280 +
49281 result = proc_pid_instantiate(dir, dentry, task, NULL);
49282 +out_put_task:
49283 put_task_struct(task);
49284 out:
49285 return result;
49286 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49287 static int fake_filldir(void *buf, const char *name, int namelen,
49288 loff_t offset, u64 ino, unsigned d_type)
49289 {
49290 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49291 + __buf->error = -EINVAL;
49292 return 0;
49293 }
49294
49295 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49296 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49297 #endif
49298 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49299 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49300 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49301 INF("syscall", S_IRUGO, proc_pid_syscall),
49302 #endif
49303 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49304 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49305 #ifdef CONFIG_SECURITY
49306 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49307 #endif
49308 -#ifdef CONFIG_KALLSYMS
49309 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49310 INF("wchan", S_IRUGO, proc_pid_wchan),
49311 #endif
49312 -#ifdef CONFIG_STACKTRACE
49313 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49314 ONE("stack", S_IRUGO, proc_pid_stack),
49315 #endif
49316 #ifdef CONFIG_SCHEDSTATS
49317 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49318 index 82676e3..5f8518a 100644
49319 --- a/fs/proc/cmdline.c
49320 +++ b/fs/proc/cmdline.c
49321 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49322
49323 static int __init proc_cmdline_init(void)
49324 {
49325 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49326 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49327 +#else
49328 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49329 +#endif
49330 return 0;
49331 }
49332 module_init(proc_cmdline_init);
49333 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49334 index b143471..bb105e5 100644
49335 --- a/fs/proc/devices.c
49336 +++ b/fs/proc/devices.c
49337 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49338
49339 static int __init proc_devices_init(void)
49340 {
49341 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49342 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49343 +#else
49344 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49345 +#endif
49346 return 0;
49347 }
49348 module_init(proc_devices_init);
49349 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49350 index 7ac817b..c5c9eb0 100644
49351 --- a/fs/proc/inode.c
49352 +++ b/fs/proc/inode.c
49353 @@ -21,11 +21,17 @@
49354 #include <linux/seq_file.h>
49355 #include <linux/slab.h>
49356 #include <linux/mount.h>
49357 +#include <linux/grsecurity.h>
49358
49359 #include <asm/uaccess.h>
49360
49361 #include "internal.h"
49362
49363 +#ifdef CONFIG_PROC_SYSCTL
49364 +extern const struct inode_operations proc_sys_inode_operations;
49365 +extern const struct inode_operations proc_sys_dir_operations;
49366 +#endif
49367 +
49368 static void proc_evict_inode(struct inode *inode)
49369 {
49370 struct proc_dir_entry *de;
49371 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49372 ns_ops = PROC_I(inode)->ns_ops;
49373 if (ns_ops && ns_ops->put)
49374 ns_ops->put(PROC_I(inode)->ns);
49375 +
49376 +#ifdef CONFIG_PROC_SYSCTL
49377 + if (inode->i_op == &proc_sys_inode_operations ||
49378 + inode->i_op == &proc_sys_dir_operations)
49379 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49380 +#endif
49381 +
49382 }
49383
49384 static struct kmem_cache * proc_inode_cachep;
49385 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49386 if (de->mode) {
49387 inode->i_mode = de->mode;
49388 inode->i_uid = de->uid;
49389 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49390 + inode->i_gid = grsec_proc_gid;
49391 +#else
49392 inode->i_gid = de->gid;
49393 +#endif
49394 }
49395 if (de->size)
49396 inode->i_size = de->size;
49397 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49398 index e1167a1..bd24f20 100644
49399 --- a/fs/proc/internal.h
49400 +++ b/fs/proc/internal.h
49401 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49402 struct pid *pid, struct task_struct *task);
49403 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49404 struct pid *pid, struct task_struct *task);
49405 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49406 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49407 +#endif
49408 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49409
49410 extern const struct file_operations proc_tid_children_operations;
49411 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49412 index 86c67ee..cdca321 100644
49413 --- a/fs/proc/kcore.c
49414 +++ b/fs/proc/kcore.c
49415 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49416 * the addresses in the elf_phdr on our list.
49417 */
49418 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49419 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49420 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49421 + if (tsz > buflen)
49422 tsz = buflen;
49423 -
49424 +
49425 while (buflen) {
49426 struct kcore_list *m;
49427
49428 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49429 kfree(elf_buf);
49430 } else {
49431 if (kern_addr_valid(start)) {
49432 - unsigned long n;
49433 + char *elf_buf;
49434 + mm_segment_t oldfs;
49435
49436 - n = copy_to_user(buffer, (char *)start, tsz);
49437 - /*
49438 - * We cannot distinguish between fault on source
49439 - * and fault on destination. When this happens
49440 - * we clear too and hope it will trigger the
49441 - * EFAULT again.
49442 - */
49443 - if (n) {
49444 - if (clear_user(buffer + tsz - n,
49445 - n))
49446 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49447 + if (!elf_buf)
49448 + return -ENOMEM;
49449 + oldfs = get_fs();
49450 + set_fs(KERNEL_DS);
49451 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49452 + set_fs(oldfs);
49453 + if (copy_to_user(buffer, elf_buf, tsz)) {
49454 + kfree(elf_buf);
49455 return -EFAULT;
49456 + }
49457 }
49458 + set_fs(oldfs);
49459 + kfree(elf_buf);
49460 } else {
49461 if (clear_user(buffer, tsz))
49462 return -EFAULT;
49463 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49464
49465 static int open_kcore(struct inode *inode, struct file *filp)
49466 {
49467 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49468 + return -EPERM;
49469 +#endif
49470 if (!capable(CAP_SYS_RAWIO))
49471 return -EPERM;
49472 if (kcore_need_update)
49473 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49474 index 80e4645..53e5fcf 100644
49475 --- a/fs/proc/meminfo.c
49476 +++ b/fs/proc/meminfo.c
49477 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49478 vmi.used >> 10,
49479 vmi.largest_chunk >> 10
49480 #ifdef CONFIG_MEMORY_FAILURE
49481 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49482 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49483 #endif
49484 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49485 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49486 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49487 index b1822dd..df622cb 100644
49488 --- a/fs/proc/nommu.c
49489 +++ b/fs/proc/nommu.c
49490 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49491 if (len < 1)
49492 len = 1;
49493 seq_printf(m, "%*c", len, ' ');
49494 - seq_path(m, &file->f_path, "");
49495 + seq_path(m, &file->f_path, "\n\\");
49496 }
49497
49498 seq_putc(m, '\n');
49499 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49500 index fe72cd0..cb9b67d 100644
49501 --- a/fs/proc/proc_net.c
49502 +++ b/fs/proc/proc_net.c
49503 @@ -23,6 +23,7 @@
49504 #include <linux/nsproxy.h>
49505 #include <net/net_namespace.h>
49506 #include <linux/seq_file.h>
49507 +#include <linux/grsecurity.h>
49508
49509 #include "internal.h"
49510
49511 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49512 struct task_struct *task;
49513 struct nsproxy *ns;
49514 struct net *net = NULL;
49515 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49516 + const struct cred *cred = current_cred();
49517 +#endif
49518 +
49519 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49520 + if (cred->fsuid)
49521 + return net;
49522 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49523 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49524 + return net;
49525 +#endif
49526
49527 rcu_read_lock();
49528 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49529 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49530 index eb7cc91..7327a46 100644
49531 --- a/fs/proc/proc_sysctl.c
49532 +++ b/fs/proc/proc_sysctl.c
49533 @@ -12,11 +12,15 @@
49534 #include <linux/module.h>
49535 #include "internal.h"
49536
49537 +extern int gr_handle_chroot_sysctl(const int op);
49538 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49539 + const int op);
49540 +
49541 static const struct dentry_operations proc_sys_dentry_operations;
49542 static const struct file_operations proc_sys_file_operations;
49543 -static const struct inode_operations proc_sys_inode_operations;
49544 +const struct inode_operations proc_sys_inode_operations;
49545 static const struct file_operations proc_sys_dir_file_operations;
49546 -static const struct inode_operations proc_sys_dir_operations;
49547 +const struct inode_operations proc_sys_dir_operations;
49548
49549 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49550 {
49551 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49552
49553 err = NULL;
49554 d_set_d_op(dentry, &proc_sys_dentry_operations);
49555 +
49556 + gr_handle_proc_create(dentry, inode);
49557 +
49558 d_add(dentry, inode);
49559
49560 out:
49561 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49562 struct inode *inode = filp->f_path.dentry->d_inode;
49563 struct ctl_table_header *head = grab_header(inode);
49564 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49565 + int op = write ? MAY_WRITE : MAY_READ;
49566 ssize_t error;
49567 size_t res;
49568
49569 if (IS_ERR(head))
49570 return PTR_ERR(head);
49571
49572 +
49573 /*
49574 * At this point we know that the sysctl was not unregistered
49575 * and won't be until we finish.
49576 */
49577 error = -EPERM;
49578 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49579 + if (sysctl_perm(head->root, table, op))
49580 goto out;
49581
49582 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49583 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49584 if (!table->proc_handler)
49585 goto out;
49586
49587 +#ifdef CONFIG_GRKERNSEC
49588 + error = -EPERM;
49589 + if (gr_handle_chroot_sysctl(op))
49590 + goto out;
49591 + dget(filp->f_path.dentry);
49592 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49593 + dput(filp->f_path.dentry);
49594 + goto out;
49595 + }
49596 + dput(filp->f_path.dentry);
49597 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49598 + goto out;
49599 + if (write && !capable(CAP_SYS_ADMIN))
49600 + goto out;
49601 +#endif
49602 +
49603 /* careful: calling conventions are nasty here */
49604 res = count;
49605 error = table->proc_handler(table, write, buf, &res, ppos);
49606 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49607 return -ENOMEM;
49608 } else {
49609 d_set_d_op(child, &proc_sys_dentry_operations);
49610 +
49611 + gr_handle_proc_create(child, inode);
49612 +
49613 d_add(child, inode);
49614 }
49615 } else {
49616 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49617 if ((*pos)++ < file->f_pos)
49618 return 0;
49619
49620 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49621 + return 0;
49622 +
49623 if (unlikely(S_ISLNK(table->mode)))
49624 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49625 else
49626 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49627 if (IS_ERR(head))
49628 return PTR_ERR(head);
49629
49630 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49631 + return -ENOENT;
49632 +
49633 generic_fillattr(inode, stat);
49634 if (table)
49635 stat->mode = (stat->mode & S_IFMT) | table->mode;
49636 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49637 .llseek = generic_file_llseek,
49638 };
49639
49640 -static const struct inode_operations proc_sys_inode_operations = {
49641 +const struct inode_operations proc_sys_inode_operations = {
49642 .permission = proc_sys_permission,
49643 .setattr = proc_sys_setattr,
49644 .getattr = proc_sys_getattr,
49645 };
49646
49647 -static const struct inode_operations proc_sys_dir_operations = {
49648 +const struct inode_operations proc_sys_dir_operations = {
49649 .lookup = proc_sys_lookup,
49650 .permission = proc_sys_permission,
49651 .setattr = proc_sys_setattr,
49652 diff --git a/fs/proc/root.c b/fs/proc/root.c
49653 index 9a2d9fd..ddfc92a 100644
49654 --- a/fs/proc/root.c
49655 +++ b/fs/proc/root.c
49656 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49657 #ifdef CONFIG_PROC_DEVICETREE
49658 proc_device_tree_init();
49659 #endif
49660 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49661 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49662 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49663 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49664 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49665 +#endif
49666 +#else
49667 proc_mkdir("bus", NULL);
49668 +#endif
49669 proc_sys_init();
49670 }
49671
49672 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49673 index 4540b8f..1b9772f 100644
49674 --- a/fs/proc/task_mmu.c
49675 +++ b/fs/proc/task_mmu.c
49676 @@ -11,12 +11,19 @@
49677 #include <linux/rmap.h>
49678 #include <linux/swap.h>
49679 #include <linux/swapops.h>
49680 +#include <linux/grsecurity.h>
49681
49682 #include <asm/elf.h>
49683 #include <asm/uaccess.h>
49684 #include <asm/tlbflush.h>
49685 #include "internal.h"
49686
49687 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49688 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49689 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49690 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49691 +#endif
49692 +
49693 void task_mem(struct seq_file *m, struct mm_struct *mm)
49694 {
49695 unsigned long data, text, lib, swap;
49696 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49697 "VmExe:\t%8lu kB\n"
49698 "VmLib:\t%8lu kB\n"
49699 "VmPTE:\t%8lu kB\n"
49700 - "VmSwap:\t%8lu kB\n",
49701 - hiwater_vm << (PAGE_SHIFT-10),
49702 + "VmSwap:\t%8lu kB\n"
49703 +
49704 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49705 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49706 +#endif
49707 +
49708 + ,hiwater_vm << (PAGE_SHIFT-10),
49709 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49710 mm->locked_vm << (PAGE_SHIFT-10),
49711 mm->pinned_vm << (PAGE_SHIFT-10),
49712 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49713 data << (PAGE_SHIFT-10),
49714 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49715 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49716 - swap << (PAGE_SHIFT-10));
49717 + swap << (PAGE_SHIFT-10)
49718 +
49719 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49720 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49721 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49722 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49723 +#else
49724 + , mm->context.user_cs_base
49725 + , mm->context.user_cs_limit
49726 +#endif
49727 +#endif
49728 +
49729 + );
49730 }
49731
49732 unsigned long task_vsize(struct mm_struct *mm)
49733 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49734 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49735 }
49736
49737 - /* We don't show the stack guard page in /proc/maps */
49738 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49739 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49740 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49741 +#else
49742 start = vma->vm_start;
49743 - if (stack_guard_page_start(vma, start))
49744 - start += PAGE_SIZE;
49745 end = vma->vm_end;
49746 - if (stack_guard_page_end(vma, end))
49747 - end -= PAGE_SIZE;
49748 +#endif
49749
49750 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49751 start,
49752 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49753 flags & VM_WRITE ? 'w' : '-',
49754 flags & VM_EXEC ? 'x' : '-',
49755 flags & VM_MAYSHARE ? 's' : 'p',
49756 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49757 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49758 +#else
49759 pgoff,
49760 +#endif
49761 MAJOR(dev), MINOR(dev), ino, &len);
49762
49763 /*
49764 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49765 */
49766 if (file) {
49767 pad_len_spaces(m, len);
49768 - seq_path(m, &file->f_path, "\n");
49769 + seq_path(m, &file->f_path, "\n\\");
49770 goto done;
49771 }
49772
49773 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49774 * Thread stack in /proc/PID/task/TID/maps or
49775 * the main process stack.
49776 */
49777 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49778 - vma->vm_end >= mm->start_stack)) {
49779 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49780 + (vma->vm_start <= mm->start_stack &&
49781 + vma->vm_end >= mm->start_stack)) {
49782 name = "[stack]";
49783 } else {
49784 /* Thread stack in /proc/PID/maps */
49785 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49786 struct proc_maps_private *priv = m->private;
49787 struct task_struct *task = priv->task;
49788
49789 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49790 + if (current->exec_id != m->exec_id) {
49791 + gr_log_badprocpid("maps");
49792 + return 0;
49793 + }
49794 +#endif
49795 +
49796 show_map_vma(m, vma, is_pid);
49797
49798 if (m->count < m->size) /* vma is copied successfully */
49799 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49800 .private = &mss,
49801 };
49802
49803 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49804 + if (current->exec_id != m->exec_id) {
49805 + gr_log_badprocpid("smaps");
49806 + return 0;
49807 + }
49808 +#endif
49809 memset(&mss, 0, sizeof mss);
49810 - mss.vma = vma;
49811 - /* mmap_sem is held in m_start */
49812 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49813 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49814 -
49815 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49816 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49817 +#endif
49818 + mss.vma = vma;
49819 + /* mmap_sem is held in m_start */
49820 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49821 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49822 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49823 + }
49824 +#endif
49825 show_map_vma(m, vma, is_pid);
49826
49827 seq_printf(m,
49828 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49829 "KernelPageSize: %8lu kB\n"
49830 "MMUPageSize: %8lu kB\n"
49831 "Locked: %8lu kB\n",
49832 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49833 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49834 +#else
49835 (vma->vm_end - vma->vm_start) >> 10,
49836 +#endif
49837 mss.resident >> 10,
49838 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49839 mss.shared_clean >> 10,
49840 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49841 int n;
49842 char buffer[50];
49843
49844 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49845 + if (current->exec_id != m->exec_id) {
49846 + gr_log_badprocpid("numa_maps");
49847 + return 0;
49848 + }
49849 +#endif
49850 +
49851 if (!mm)
49852 return 0;
49853
49854 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49855 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49856 mpol_cond_put(pol);
49857
49858 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49859 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49860 +#else
49861 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49862 +#endif
49863
49864 if (file) {
49865 seq_printf(m, " file=");
49866 - seq_path(m, &file->f_path, "\n\t= ");
49867 + seq_path(m, &file->f_path, "\n\t\\= ");
49868 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49869 seq_printf(m, " heap");
49870 } else {
49871 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49872 index 1ccfa53..0848f95 100644
49873 --- a/fs/proc/task_nommu.c
49874 +++ b/fs/proc/task_nommu.c
49875 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49876 else
49877 bytes += kobjsize(mm);
49878
49879 - if (current->fs && current->fs->users > 1)
49880 + if (current->fs && atomic_read(&current->fs->users) > 1)
49881 sbytes += kobjsize(current->fs);
49882 else
49883 bytes += kobjsize(current->fs);
49884 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49885
49886 if (file) {
49887 pad_len_spaces(m, len);
49888 - seq_path(m, &file->f_path, "");
49889 + seq_path(m, &file->f_path, "\n\\");
49890 } else if (mm) {
49891 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49892
49893 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49894 index d67908b..d13f6a6 100644
49895 --- a/fs/quota/netlink.c
49896 +++ b/fs/quota/netlink.c
49897 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49898 void quota_send_warning(short type, unsigned int id, dev_t dev,
49899 const char warntype)
49900 {
49901 - static atomic_t seq;
49902 + static atomic_unchecked_t seq;
49903 struct sk_buff *skb;
49904 void *msg_head;
49905 int ret;
49906 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49907 "VFS: Not enough memory to send quota warning.\n");
49908 return;
49909 }
49910 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49911 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49912 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49913 if (!msg_head) {
49914 printk(KERN_ERR
49915 diff --git a/fs/readdir.c b/fs/readdir.c
49916 index 39e3370..20d446d 100644
49917 --- a/fs/readdir.c
49918 +++ b/fs/readdir.c
49919 @@ -17,6 +17,7 @@
49920 #include <linux/security.h>
49921 #include <linux/syscalls.h>
49922 #include <linux/unistd.h>
49923 +#include <linux/namei.h>
49924
49925 #include <asm/uaccess.h>
49926
49927 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49928
49929 struct readdir_callback {
49930 struct old_linux_dirent __user * dirent;
49931 + struct file * file;
49932 int result;
49933 };
49934
49935 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49936 buf->result = -EOVERFLOW;
49937 return -EOVERFLOW;
49938 }
49939 +
49940 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49941 + return 0;
49942 +
49943 buf->result++;
49944 dirent = buf->dirent;
49945 if (!access_ok(VERIFY_WRITE, dirent,
49946 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49947
49948 buf.result = 0;
49949 buf.dirent = dirent;
49950 + buf.file = file;
49951
49952 error = vfs_readdir(file, fillonedir, &buf);
49953 if (buf.result)
49954 @@ -141,6 +148,7 @@ struct linux_dirent {
49955 struct getdents_callback {
49956 struct linux_dirent __user * current_dir;
49957 struct linux_dirent __user * previous;
49958 + struct file * file;
49959 int count;
49960 int error;
49961 };
49962 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49963 buf->error = -EOVERFLOW;
49964 return -EOVERFLOW;
49965 }
49966 +
49967 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49968 + return 0;
49969 +
49970 dirent = buf->previous;
49971 if (dirent) {
49972 if (__put_user(offset, &dirent->d_off))
49973 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49974 buf.previous = NULL;
49975 buf.count = count;
49976 buf.error = 0;
49977 + buf.file = file;
49978
49979 error = vfs_readdir(file, filldir, &buf);
49980 if (error >= 0)
49981 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49982 struct getdents_callback64 {
49983 struct linux_dirent64 __user * current_dir;
49984 struct linux_dirent64 __user * previous;
49985 + struct file *file;
49986 int count;
49987 int error;
49988 };
49989 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49990 buf->error = -EINVAL; /* only used if we fail.. */
49991 if (reclen > buf->count)
49992 return -EINVAL;
49993 +
49994 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49995 + return 0;
49996 +
49997 dirent = buf->previous;
49998 if (dirent) {
49999 if (__put_user(offset, &dirent->d_off))
50000 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50001
50002 buf.current_dir = dirent;
50003 buf.previous = NULL;
50004 + buf.file = file;
50005 buf.count = count;
50006 buf.error = 0;
50007
50008 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50009 error = buf.error;
50010 lastdirent = buf.previous;
50011 if (lastdirent) {
50012 - typeof(lastdirent->d_off) d_off = file->f_pos;
50013 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50014 if (__put_user(d_off, &lastdirent->d_off))
50015 error = -EFAULT;
50016 else
50017 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50018 index 2b7882b..1c5ef48 100644
50019 --- a/fs/reiserfs/do_balan.c
50020 +++ b/fs/reiserfs/do_balan.c
50021 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50022 return;
50023 }
50024
50025 - atomic_inc(&(fs_generation(tb->tb_sb)));
50026 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50027 do_balance_starts(tb);
50028
50029 /* balance leaf returns 0 except if combining L R and S into
50030 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50031 index e60e870..f40ac16 100644
50032 --- a/fs/reiserfs/procfs.c
50033 +++ b/fs/reiserfs/procfs.c
50034 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50035 "SMALL_TAILS " : "NO_TAILS ",
50036 replay_only(sb) ? "REPLAY_ONLY " : "",
50037 convert_reiserfs(sb) ? "CONV " : "",
50038 - atomic_read(&r->s_generation_counter),
50039 + atomic_read_unchecked(&r->s_generation_counter),
50040 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50041 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50042 SF(s_good_search_by_key_reada), SF(s_bmaps),
50043 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50044 index 33215f5..c5d427a 100644
50045 --- a/fs/reiserfs/reiserfs.h
50046 +++ b/fs/reiserfs/reiserfs.h
50047 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50048 /* Comment? -Hans */
50049 wait_queue_head_t s_wait;
50050 /* To be obsoleted soon by per buffer seals.. -Hans */
50051 - atomic_t s_generation_counter; // increased by one every time the
50052 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50053 // tree gets re-balanced
50054 unsigned long s_properties; /* File system properties. Currently holds
50055 on-disk FS format */
50056 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50057 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50058
50059 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50060 -#define get_generation(s) atomic_read (&fs_generation(s))
50061 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50062 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50063 #define __fs_changed(gen,s) (gen != get_generation (s))
50064 #define fs_changed(gen,s) \
50065 diff --git a/fs/select.c b/fs/select.c
50066 index db14c78..3aae1bd 100644
50067 --- a/fs/select.c
50068 +++ b/fs/select.c
50069 @@ -20,6 +20,7 @@
50070 #include <linux/export.h>
50071 #include <linux/slab.h>
50072 #include <linux/poll.h>
50073 +#include <linux/security.h>
50074 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50075 #include <linux/file.h>
50076 #include <linux/fdtable.h>
50077 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50078 struct poll_list *walk = head;
50079 unsigned long todo = nfds;
50080
50081 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50082 if (nfds > rlimit(RLIMIT_NOFILE))
50083 return -EINVAL;
50084
50085 diff --git a/fs/seq_file.c b/fs/seq_file.c
50086 index 14cf9de..adc4d5b 100644
50087 --- a/fs/seq_file.c
50088 +++ b/fs/seq_file.c
50089 @@ -9,6 +9,7 @@
50090 #include <linux/export.h>
50091 #include <linux/seq_file.h>
50092 #include <linux/slab.h>
50093 +#include <linux/sched.h>
50094
50095 #include <asm/uaccess.h>
50096 #include <asm/page.h>
50097 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50098 memset(p, 0, sizeof(*p));
50099 mutex_init(&p->lock);
50100 p->op = op;
50101 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50102 + p->exec_id = current->exec_id;
50103 +#endif
50104
50105 /*
50106 * Wrappers around seq_open(e.g. swaps_open) need to be
50107 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50108 return 0;
50109 }
50110 if (!m->buf) {
50111 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50112 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50113 if (!m->buf)
50114 return -ENOMEM;
50115 }
50116 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50117 Eoverflow:
50118 m->op->stop(m, p);
50119 kfree(m->buf);
50120 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50121 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50122 return !m->buf ? -ENOMEM : -EAGAIN;
50123 }
50124
50125 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50126
50127 /* grab buffer if we didn't have one */
50128 if (!m->buf) {
50129 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50130 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50131 if (!m->buf)
50132 goto Enomem;
50133 }
50134 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50135 goto Fill;
50136 m->op->stop(m, p);
50137 kfree(m->buf);
50138 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50139 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50140 if (!m->buf)
50141 goto Enomem;
50142 m->count = 0;
50143 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50144 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50145 void *data)
50146 {
50147 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50148 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50149 int res = -ENOMEM;
50150
50151 if (op) {
50152 diff --git a/fs/splice.c b/fs/splice.c
50153 index 41514dd..6564a93 100644
50154 --- a/fs/splice.c
50155 +++ b/fs/splice.c
50156 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50157 pipe_lock(pipe);
50158
50159 for (;;) {
50160 - if (!pipe->readers) {
50161 + if (!atomic_read(&pipe->readers)) {
50162 send_sig(SIGPIPE, current, 0);
50163 if (!ret)
50164 ret = -EPIPE;
50165 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50166 do_wakeup = 0;
50167 }
50168
50169 - pipe->waiting_writers++;
50170 + atomic_inc(&pipe->waiting_writers);
50171 pipe_wait(pipe);
50172 - pipe->waiting_writers--;
50173 + atomic_dec(&pipe->waiting_writers);
50174 }
50175
50176 pipe_unlock(pipe);
50177 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50178 old_fs = get_fs();
50179 set_fs(get_ds());
50180 /* The cast to a user pointer is valid due to the set_fs() */
50181 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50182 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50183 set_fs(old_fs);
50184
50185 return res;
50186 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50187 old_fs = get_fs();
50188 set_fs(get_ds());
50189 /* The cast to a user pointer is valid due to the set_fs() */
50190 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50191 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50192 set_fs(old_fs);
50193
50194 return res;
50195 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50196 goto err;
50197
50198 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50199 - vec[i].iov_base = (void __user *) page_address(page);
50200 + vec[i].iov_base = (void __force_user *) page_address(page);
50201 vec[i].iov_len = this_len;
50202 spd.pages[i] = page;
50203 spd.nr_pages++;
50204 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50205 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50206 {
50207 while (!pipe->nrbufs) {
50208 - if (!pipe->writers)
50209 + if (!atomic_read(&pipe->writers))
50210 return 0;
50211
50212 - if (!pipe->waiting_writers && sd->num_spliced)
50213 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50214 return 0;
50215
50216 if (sd->flags & SPLICE_F_NONBLOCK)
50217 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50218 * out of the pipe right after the splice_to_pipe(). So set
50219 * PIPE_READERS appropriately.
50220 */
50221 - pipe->readers = 1;
50222 + atomic_set(&pipe->readers, 1);
50223
50224 current->splice_pipe = pipe;
50225 }
50226 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50227 ret = -ERESTARTSYS;
50228 break;
50229 }
50230 - if (!pipe->writers)
50231 + if (!atomic_read(&pipe->writers))
50232 break;
50233 - if (!pipe->waiting_writers) {
50234 + if (!atomic_read(&pipe->waiting_writers)) {
50235 if (flags & SPLICE_F_NONBLOCK) {
50236 ret = -EAGAIN;
50237 break;
50238 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50239 pipe_lock(pipe);
50240
50241 while (pipe->nrbufs >= pipe->buffers) {
50242 - if (!pipe->readers) {
50243 + if (!atomic_read(&pipe->readers)) {
50244 send_sig(SIGPIPE, current, 0);
50245 ret = -EPIPE;
50246 break;
50247 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50248 ret = -ERESTARTSYS;
50249 break;
50250 }
50251 - pipe->waiting_writers++;
50252 + atomic_inc(&pipe->waiting_writers);
50253 pipe_wait(pipe);
50254 - pipe->waiting_writers--;
50255 + atomic_dec(&pipe->waiting_writers);
50256 }
50257
50258 pipe_unlock(pipe);
50259 @@ -1828,14 +1828,14 @@ retry:
50260 pipe_double_lock(ipipe, opipe);
50261
50262 do {
50263 - if (!opipe->readers) {
50264 + if (!atomic_read(&opipe->readers)) {
50265 send_sig(SIGPIPE, current, 0);
50266 if (!ret)
50267 ret = -EPIPE;
50268 break;
50269 }
50270
50271 - if (!ipipe->nrbufs && !ipipe->writers)
50272 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50273 break;
50274
50275 /*
50276 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50277 pipe_double_lock(ipipe, opipe);
50278
50279 do {
50280 - if (!opipe->readers) {
50281 + if (!atomic_read(&opipe->readers)) {
50282 send_sig(SIGPIPE, current, 0);
50283 if (!ret)
50284 ret = -EPIPE;
50285 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50286 * return EAGAIN if we have the potential of some data in the
50287 * future, otherwise just return 0
50288 */
50289 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50290 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50291 ret = -EAGAIN;
50292
50293 pipe_unlock(ipipe);
50294 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50295 index 6b0bb00..75db2fe 100644
50296 --- a/fs/sysfs/dir.c
50297 +++ b/fs/sysfs/dir.c
50298 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50299 struct sysfs_dirent *sd;
50300 int rc;
50301
50302 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50303 + const char *parent_name = parent_sd->s_name;
50304 +
50305 + mode = S_IFDIR | S_IRWXU;
50306 +
50307 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50308 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50309 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50310 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50311 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50312 +#endif
50313 +
50314 /* allocate */
50315 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50316 if (!sd)
50317 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50318 index 00012e3..8392349 100644
50319 --- a/fs/sysfs/file.c
50320 +++ b/fs/sysfs/file.c
50321 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50322
50323 struct sysfs_open_dirent {
50324 atomic_t refcnt;
50325 - atomic_t event;
50326 + atomic_unchecked_t event;
50327 wait_queue_head_t poll;
50328 struct list_head buffers; /* goes through sysfs_buffer.list */
50329 };
50330 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50331 if (!sysfs_get_active(attr_sd))
50332 return -ENODEV;
50333
50334 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50335 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50336 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50337
50338 sysfs_put_active(attr_sd);
50339 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50340 return -ENOMEM;
50341
50342 atomic_set(&new_od->refcnt, 0);
50343 - atomic_set(&new_od->event, 1);
50344 + atomic_set_unchecked(&new_od->event, 1);
50345 init_waitqueue_head(&new_od->poll);
50346 INIT_LIST_HEAD(&new_od->buffers);
50347 goto retry;
50348 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50349
50350 sysfs_put_active(attr_sd);
50351
50352 - if (buffer->event != atomic_read(&od->event))
50353 + if (buffer->event != atomic_read_unchecked(&od->event))
50354 goto trigger;
50355
50356 return DEFAULT_POLLMASK;
50357 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50358
50359 od = sd->s_attr.open;
50360 if (od) {
50361 - atomic_inc(&od->event);
50362 + atomic_inc_unchecked(&od->event);
50363 wake_up_interruptible(&od->poll);
50364 }
50365
50366 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50367 index a7ac78f..02158e1 100644
50368 --- a/fs/sysfs/symlink.c
50369 +++ b/fs/sysfs/symlink.c
50370 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50371
50372 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50373 {
50374 - char *page = nd_get_link(nd);
50375 + const char *page = nd_get_link(nd);
50376 if (!IS_ERR(page))
50377 free_page((unsigned long)page);
50378 }
50379 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50380 index c175b4d..8f36a16 100644
50381 --- a/fs/udf/misc.c
50382 +++ b/fs/udf/misc.c
50383 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50384
50385 u8 udf_tag_checksum(const struct tag *t)
50386 {
50387 - u8 *data = (u8 *)t;
50388 + const u8 *data = (const u8 *)t;
50389 u8 checksum = 0;
50390 int i;
50391 for (i = 0; i < sizeof(struct tag); ++i)
50392 diff --git a/fs/utimes.c b/fs/utimes.c
50393 index fa4dbe4..e12d1b9 100644
50394 --- a/fs/utimes.c
50395 +++ b/fs/utimes.c
50396 @@ -1,6 +1,7 @@
50397 #include <linux/compiler.h>
50398 #include <linux/file.h>
50399 #include <linux/fs.h>
50400 +#include <linux/security.h>
50401 #include <linux/linkage.h>
50402 #include <linux/mount.h>
50403 #include <linux/namei.h>
50404 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50405 goto mnt_drop_write_and_out;
50406 }
50407 }
50408 +
50409 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50410 + error = -EACCES;
50411 + goto mnt_drop_write_and_out;
50412 + }
50413 +
50414 mutex_lock(&inode->i_mutex);
50415 error = notify_change(path->dentry, &newattrs);
50416 mutex_unlock(&inode->i_mutex);
50417 diff --git a/fs/xattr.c b/fs/xattr.c
50418 index 4d45b71..2ec08e10 100644
50419 --- a/fs/xattr.c
50420 +++ b/fs/xattr.c
50421 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50422 * Extended attribute SET operations
50423 */
50424 static long
50425 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50426 +setxattr(struct path *path, const char __user *name, const void __user *value,
50427 size_t size, int flags)
50428 {
50429 int error;
50430 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50431 }
50432 }
50433
50434 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50435 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50436 + error = -EACCES;
50437 + goto out;
50438 + }
50439 +
50440 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50441 out:
50442 if (vvalue)
50443 vfree(vvalue);
50444 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50445 return error;
50446 error = mnt_want_write(path.mnt);
50447 if (!error) {
50448 - error = setxattr(path.dentry, name, value, size, flags);
50449 + error = setxattr(&path, name, value, size, flags);
50450 mnt_drop_write(path.mnt);
50451 }
50452 path_put(&path);
50453 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50454 return error;
50455 error = mnt_want_write(path.mnt);
50456 if (!error) {
50457 - error = setxattr(path.dentry, name, value, size, flags);
50458 + error = setxattr(&path, name, value, size, flags);
50459 mnt_drop_write(path.mnt);
50460 }
50461 path_put(&path);
50462 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50463 {
50464 int fput_needed;
50465 struct file *f;
50466 - struct dentry *dentry;
50467 int error = -EBADF;
50468
50469 f = fget_light(fd, &fput_needed);
50470 if (!f)
50471 return error;
50472 - dentry = f->f_path.dentry;
50473 - audit_inode(NULL, dentry);
50474 + audit_inode(NULL, f->f_path.dentry);
50475 error = mnt_want_write_file(f);
50476 if (!error) {
50477 - error = setxattr(dentry, name, value, size, flags);
50478 + error = setxattr(&f->f_path, name, value, size, flags);
50479 mnt_drop_write_file(f);
50480 }
50481 fput_light(f, fput_needed);
50482 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50483 index 69d06b0..c0996e5 100644
50484 --- a/fs/xattr_acl.c
50485 +++ b/fs/xattr_acl.c
50486 @@ -17,8 +17,8 @@
50487 struct posix_acl *
50488 posix_acl_from_xattr(const void *value, size_t size)
50489 {
50490 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50491 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50492 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50493 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50494 int count;
50495 struct posix_acl *acl;
50496 struct posix_acl_entry *acl_e;
50497 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50498 index 848ffa7..1f249bf 100644
50499 --- a/fs/xfs/xfs_bmap.c
50500 +++ b/fs/xfs/xfs_bmap.c
50501 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50502 int nmap,
50503 int ret_nmap);
50504 #else
50505 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50506 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50507 #endif /* DEBUG */
50508
50509 STATIC int
50510 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50511 index 1b9fc3e..e1bdde0 100644
50512 --- a/fs/xfs/xfs_dir2_sf.c
50513 +++ b/fs/xfs/xfs_dir2_sf.c
50514 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50515 }
50516
50517 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50518 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50519 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50520 + char name[sfep->namelen];
50521 + memcpy(name, sfep->name, sfep->namelen);
50522 + if (filldir(dirent, name, sfep->namelen,
50523 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50524 + *offset = off & 0x7fffffff;
50525 + return 0;
50526 + }
50527 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50528 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50529 *offset = off & 0x7fffffff;
50530 return 0;
50531 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50532 index 0e0232c..fa5c3fe 100644
50533 --- a/fs/xfs/xfs_ioctl.c
50534 +++ b/fs/xfs/xfs_ioctl.c
50535 @@ -126,7 +126,7 @@ xfs_find_handle(
50536 }
50537
50538 error = -EFAULT;
50539 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50540 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50541 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50542 goto out_put;
50543
50544 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50545 index 4e00cf0..3374374 100644
50546 --- a/fs/xfs/xfs_iops.c
50547 +++ b/fs/xfs/xfs_iops.c
50548 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50549 struct nameidata *nd,
50550 void *p)
50551 {
50552 - char *s = nd_get_link(nd);
50553 + const char *s = nd_get_link(nd);
50554
50555 if (!IS_ERR(s))
50556 kfree(s);
50557 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50558 new file mode 100644
50559 index 0000000..d38b430
50560 --- /dev/null
50561 +++ b/grsecurity/Kconfig
50562 @@ -0,0 +1,947 @@
50563 +#
50564 +# grecurity configuration
50565 +#
50566 +menu "Memory Protections"
50567 +depends on GRKERNSEC
50568 +
50569 +config GRKERNSEC_KMEM
50570 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50571 + default y if GRKERNSEC_CONFIG_AUTO
50572 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50573 + help
50574 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50575 + be written to or read from to modify or leak the contents of the running
50576 + kernel. /dev/port will also not be allowed to be opened. If you have module
50577 + support disabled, enabling this will close up four ways that are
50578 + currently used to insert malicious code into the running kernel.
50579 + Even with all these features enabled, we still highly recommend that
50580 + you use the RBAC system, as it is still possible for an attacker to
50581 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50582 + If you are not using XFree86, you may be able to stop this additional
50583 + case by enabling the 'Disable privileged I/O' option. Though nothing
50584 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50585 + but only to video memory, which is the only writing we allow in this
50586 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50587 + not be allowed to mprotect it with PROT_WRITE later.
50588 + It is highly recommended that you say Y here if you meet all the
50589 + conditions above.
50590 +
50591 +config GRKERNSEC_VM86
50592 + bool "Restrict VM86 mode"
50593 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50594 + depends on X86_32
50595 +
50596 + help
50597 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50598 + make use of a special execution mode on 32bit x86 processors called
50599 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50600 + video cards and will still work with this option enabled. The purpose
50601 + of the option is to prevent exploitation of emulation errors in
50602 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50603 + Nearly all users should be able to enable this option.
50604 +
50605 +config GRKERNSEC_IO
50606 + bool "Disable privileged I/O"
50607 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50608 + depends on X86
50609 + select RTC_CLASS
50610 + select RTC_INTF_DEV
50611 + select RTC_DRV_CMOS
50612 +
50613 + help
50614 + If you say Y here, all ioperm and iopl calls will return an error.
50615 + Ioperm and iopl can be used to modify the running kernel.
50616 + Unfortunately, some programs need this access to operate properly,
50617 + the most notable of which are XFree86 and hwclock. hwclock can be
50618 + remedied by having RTC support in the kernel, so real-time
50619 + clock support is enabled if this option is enabled, to ensure
50620 + that hwclock operates correctly. XFree86 still will not
50621 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50622 + IF YOU USE XFree86. If you use XFree86 and you still want to
50623 + protect your kernel against modification, use the RBAC system.
50624 +
50625 +config GRKERNSEC_PROC_MEMMAP
50626 + bool "Harden ASLR against information leaks and entropy reduction"
50627 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50628 + depends on PAX_NOEXEC || PAX_ASLR
50629 + help
50630 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50631 + give no information about the addresses of its mappings if
50632 + PaX features that rely on random addresses are enabled on the task.
50633 + In addition to sanitizing this information and disabling other
50634 + dangerous sources of information, this option causes reads of sensitive
50635 + /proc/<pid> entries where the file descriptor was opened in a different
50636 + task than the one performing the read. Such attempts are logged.
50637 + This option also limits argv/env strings for suid/sgid binaries
50638 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50639 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50640 + binaries to prevent alternative mmap layouts from being abused.
50641 +
50642 + If you use PaX it is essential that you say Y here as it closes up
50643 + several holes that make full ASLR useless locally.
50644 +
50645 +config GRKERNSEC_BRUTE
50646 + bool "Deter exploit bruteforcing"
50647 + default y if GRKERNSEC_CONFIG_AUTO
50648 + help
50649 + If you say Y here, attempts to bruteforce exploits against forking
50650 + daemons such as apache or sshd, as well as against suid/sgid binaries
50651 + will be deterred. When a child of a forking daemon is killed by PaX
50652 + or crashes due to an illegal instruction or other suspicious signal,
50653 + the parent process will be delayed 30 seconds upon every subsequent
50654 + fork until the administrator is able to assess the situation and
50655 + restart the daemon.
50656 + In the suid/sgid case, the attempt is logged, the user has all their
50657 + processes terminated, and they are prevented from executing any further
50658 + processes for 15 minutes.
50659 + It is recommended that you also enable signal logging in the auditing
50660 + section so that logs are generated when a process triggers a suspicious
50661 + signal.
50662 + If the sysctl option is enabled, a sysctl option with name
50663 + "deter_bruteforce" is created.
50664 +
50665 +
50666 +config GRKERNSEC_MODHARDEN
50667 + bool "Harden module auto-loading"
50668 + default y if GRKERNSEC_CONFIG_AUTO
50669 + depends on MODULES
50670 + help
50671 + If you say Y here, module auto-loading in response to use of some
50672 + feature implemented by an unloaded module will be restricted to
50673 + root users. Enabling this option helps defend against attacks
50674 + by unprivileged users who abuse the auto-loading behavior to
50675 + cause a vulnerable module to load that is then exploited.
50676 +
50677 + If this option prevents a legitimate use of auto-loading for a
50678 + non-root user, the administrator can execute modprobe manually
50679 + with the exact name of the module mentioned in the alert log.
50680 + Alternatively, the administrator can add the module to the list
50681 + of modules loaded at boot by modifying init scripts.
50682 +
50683 + Modification of init scripts will most likely be needed on
50684 + Ubuntu servers with encrypted home directory support enabled,
50685 + as the first non-root user logging in will cause the ecb(aes),
50686 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50687 +
50688 +config GRKERNSEC_HIDESYM
50689 + bool "Hide kernel symbols"
50690 + default y if GRKERNSEC_CONFIG_AUTO
50691 + select PAX_USERCOPY_SLABS
50692 + help
50693 + If you say Y here, getting information on loaded modules, and
50694 + displaying all kernel symbols through a syscall will be restricted
50695 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50696 + /proc/kallsyms will be restricted to the root user. The RBAC
50697 + system can hide that entry even from root.
50698 +
50699 + This option also prevents leaking of kernel addresses through
50700 + several /proc entries.
50701 +
50702 + Note that this option is only effective provided the following
50703 + conditions are met:
50704 + 1) The kernel using grsecurity is not precompiled by some distribution
50705 + 2) You have also enabled GRKERNSEC_DMESG
50706 + 3) You are using the RBAC system and hiding other files such as your
50707 + kernel image and System.map. Alternatively, enabling this option
50708 + causes the permissions on /boot, /lib/modules, and the kernel
50709 + source directory to change at compile time to prevent
50710 + reading by non-root users.
50711 + If the above conditions are met, this option will aid in providing a
50712 + useful protection against local kernel exploitation of overflows
50713 + and arbitrary read/write vulnerabilities.
50714 +
50715 +config GRKERNSEC_KERN_LOCKOUT
50716 + bool "Active kernel exploit response"
50717 + default y if GRKERNSEC_CONFIG_AUTO
50718 + depends on X86 || ARM || PPC || SPARC
50719 + help
50720 + If you say Y here, when a PaX alert is triggered due to suspicious
50721 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50722 + or an OOPS occurs due to bad memory accesses, instead of just
50723 + terminating the offending process (and potentially allowing
50724 + a subsequent exploit from the same user), we will take one of two
50725 + actions:
50726 + If the user was root, we will panic the system
50727 + If the user was non-root, we will log the attempt, terminate
50728 + all processes owned by the user, then prevent them from creating
50729 + any new processes until the system is restarted
50730 + This deters repeated kernel exploitation/bruteforcing attempts
50731 + and is useful for later forensics.
50732 +
50733 +endmenu
50734 +menu "Role Based Access Control Options"
50735 +depends on GRKERNSEC
50736 +
50737 +config GRKERNSEC_RBAC_DEBUG
50738 + bool
50739 +
50740 +config GRKERNSEC_NO_RBAC
50741 + bool "Disable RBAC system"
50742 + help
50743 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50744 + preventing the RBAC system from being enabled. You should only say Y
50745 + here if you have no intention of using the RBAC system, so as to prevent
50746 + an attacker with root access from misusing the RBAC system to hide files
50747 + and processes when loadable module support and /dev/[k]mem have been
50748 + locked down.
50749 +
50750 +config GRKERNSEC_ACL_HIDEKERN
50751 + bool "Hide kernel processes"
50752 + help
50753 + If you say Y here, all kernel threads will be hidden to all
50754 + processes but those whose subject has the "view hidden processes"
50755 + flag.
50756 +
50757 +config GRKERNSEC_ACL_MAXTRIES
50758 + int "Maximum tries before password lockout"
50759 + default 3
50760 + help
50761 + This option enforces the maximum number of times a user can attempt
50762 + to authorize themselves with the grsecurity RBAC system before being
50763 + denied the ability to attempt authorization again for a specified time.
50764 + The lower the number, the harder it will be to brute-force a password.
50765 +
50766 +config GRKERNSEC_ACL_TIMEOUT
50767 + int "Time to wait after max password tries, in seconds"
50768 + default 30
50769 + help
50770 + This option specifies the time the user must wait after attempting to
50771 + authorize to the RBAC system with the maximum number of invalid
50772 + passwords. The higher the number, the harder it will be to brute-force
50773 + a password.
50774 +
50775 +endmenu
50776 +menu "Filesystem Protections"
50777 +depends on GRKERNSEC
50778 +
50779 +config GRKERNSEC_PROC
50780 + bool "Proc restrictions"
50781 + default y if GRKERNSEC_CONFIG_AUTO
50782 + help
50783 + If you say Y here, the permissions of the /proc filesystem
50784 + will be altered to enhance system security and privacy. You MUST
50785 + choose either a user only restriction or a user and group restriction.
50786 + Depending upon the option you choose, you can either restrict users to
50787 + see only the processes they themselves run, or choose a group that can
50788 + view all processes and files normally restricted to root if you choose
50789 + the "restrict to user only" option. NOTE: If you're running identd or
50790 + ntpd as a non-root user, you will have to run it as the group you
50791 + specify here.
50792 +
50793 +config GRKERNSEC_PROC_USER
50794 + bool "Restrict /proc to user only"
50795 + depends on GRKERNSEC_PROC
50796 + help
50797 + If you say Y here, non-root users will only be able to view their own
50798 + processes, and restricts them from viewing network-related information,
50799 + and viewing kernel symbol and module information.
50800 +
50801 +config GRKERNSEC_PROC_USERGROUP
50802 + bool "Allow special group"
50803 + default y if GRKERNSEC_CONFIG_AUTO
50804 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50805 + help
50806 + If you say Y here, you will be able to select a group that will be
50807 + able to view all processes and network-related information. If you've
50808 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50809 + remain hidden. This option is useful if you want to run identd as
50810 + a non-root user. The group you select may also be chosen at boot time
50811 + via "grsec_proc_gid=" on the kernel commandline.
50812 +
50813 +config GRKERNSEC_PROC_GID
50814 + int "GID for special group"
50815 + depends on GRKERNSEC_PROC_USERGROUP
50816 + default 1001
50817 +
50818 +config GRKERNSEC_PROC_ADD
50819 + bool "Additional restrictions"
50820 + default y if GRKERNSEC_CONFIG_AUTO
50821 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50822 + help
50823 + If you say Y here, additional restrictions will be placed on
50824 + /proc that keep normal users from viewing device information and
50825 + slabinfo information that could be useful for exploits.
50826 +
50827 +config GRKERNSEC_LINK
50828 + bool "Linking restrictions"
50829 + default y if GRKERNSEC_CONFIG_AUTO
50830 + help
50831 + If you say Y here, /tmp race exploits will be prevented, since users
50832 + will no longer be able to follow symlinks owned by other users in
50833 + world-writable +t directories (e.g. /tmp), unless the owner of the
50834 + symlink is the owner of the directory. users will also not be
50835 + able to hardlink to files they do not own. If the sysctl option is
50836 + enabled, a sysctl option with name "linking_restrictions" is created.
50837 +
50838 +config GRKERNSEC_SYMLINKOWN
50839 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50840 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50841 + help
50842 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50843 + that prevents it from being used as a security feature. As Apache
50844 + verifies the symlink by performing a stat() against the target of
50845 + the symlink before it is followed, an attacker can setup a symlink
50846 + to point to a same-owned file, then replace the symlink with one
50847 + that targets another user's file just after Apache "validates" the
50848 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50849 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50850 + will be in place for the group you specify. If the sysctl option
50851 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50852 + created.
50853 +
50854 +config GRKERNSEC_SYMLINKOWN_GID
50855 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50856 + depends on GRKERNSEC_SYMLINKOWN
50857 + default 1006
50858 + help
50859 + Setting this GID determines what group kernel-enforced
50860 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50861 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50862 +
50863 +config GRKERNSEC_FIFO
50864 + bool "FIFO restrictions"
50865 + default y if GRKERNSEC_CONFIG_AUTO
50866 + help
50867 + If you say Y here, users will not be able to write to FIFOs they don't
50868 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50869 + the FIFO is the same owner of the directory it's held in. If the sysctl
50870 + option is enabled, a sysctl option with name "fifo_restrictions" is
50871 + created.
50872 +
50873 +config GRKERNSEC_SYSFS_RESTRICT
50874 + bool "Sysfs/debugfs restriction"
50875 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50876 + depends on SYSFS
50877 + help
50878 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50879 + any filesystem normally mounted under it (e.g. debugfs) will be
50880 + mostly accessible only by root. These filesystems generally provide access
50881 + to hardware and debug information that isn't appropriate for unprivileged
50882 + users of the system. Sysfs and debugfs have also become a large source
50883 + of new vulnerabilities, ranging from infoleaks to local compromise.
50884 + There has been very little oversight with an eye toward security involved
50885 + in adding new exporters of information to these filesystems, so their
50886 + use is discouraged.
50887 + For reasons of compatibility, a few directories have been whitelisted
50888 + for access by non-root users:
50889 + /sys/fs/selinux
50890 + /sys/fs/fuse
50891 + /sys/devices/system/cpu
50892 +
50893 +config GRKERNSEC_ROFS
50894 + bool "Runtime read-only mount protection"
50895 + help
50896 + If you say Y here, a sysctl option with name "romount_protect" will
50897 + be created. By setting this option to 1 at runtime, filesystems
50898 + will be protected in the following ways:
50899 + * No new writable mounts will be allowed
50900 + * Existing read-only mounts won't be able to be remounted read/write
50901 + * Write operations will be denied on all block devices
50902 + This option acts independently of grsec_lock: once it is set to 1,
50903 + it cannot be turned off. Therefore, please be mindful of the resulting
50904 + behavior if this option is enabled in an init script on a read-only
50905 + filesystem. This feature is mainly intended for secure embedded systems.
50906 +
50907 +config GRKERNSEC_CHROOT
50908 + bool "Chroot jail restrictions"
50909 + default y if GRKERNSEC_CONFIG_AUTO
50910 + help
50911 + If you say Y here, you will be able to choose several options that will
50912 + make breaking out of a chrooted jail much more difficult. If you
50913 + encounter no software incompatibilities with the following options, it
50914 + is recommended that you enable each one.
50915 +
50916 +config GRKERNSEC_CHROOT_MOUNT
50917 + bool "Deny mounts"
50918 + default y if GRKERNSEC_CONFIG_AUTO
50919 + depends on GRKERNSEC_CHROOT
50920 + help
50921 + If you say Y here, processes inside a chroot will not be able to
50922 + mount or remount filesystems. If the sysctl option is enabled, a
50923 + sysctl option with name "chroot_deny_mount" is created.
50924 +
50925 +config GRKERNSEC_CHROOT_DOUBLE
50926 + bool "Deny double-chroots"
50927 + default y if GRKERNSEC_CONFIG_AUTO
50928 + depends on GRKERNSEC_CHROOT
50929 + help
50930 + If you say Y here, processes inside a chroot will not be able to chroot
50931 + again outside the chroot. This is a widely used method of breaking
50932 + out of a chroot jail and should not be allowed. If the sysctl
50933 + option is enabled, a sysctl option with name
50934 + "chroot_deny_chroot" is created.
50935 +
50936 +config GRKERNSEC_CHROOT_PIVOT
50937 + bool "Deny pivot_root in chroot"
50938 + default y if GRKERNSEC_CONFIG_AUTO
50939 + depends on GRKERNSEC_CHROOT
50940 + help
50941 + If you say Y here, processes inside a chroot will not be able to use
50942 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50943 + works similar to chroot in that it changes the root filesystem. This
50944 + function could be misused in a chrooted process to attempt to break out
50945 + of the chroot, and therefore should not be allowed. If the sysctl
50946 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50947 + created.
50948 +
50949 +config GRKERNSEC_CHROOT_CHDIR
50950 + bool "Enforce chdir(\"/\") on all chroots"
50951 + default y if GRKERNSEC_CONFIG_AUTO
50952 + depends on GRKERNSEC_CHROOT
50953 + help
50954 + If you say Y here, the current working directory of all newly-chrooted
50955 + applications will be set to the the root directory of the chroot.
50956 + The man page on chroot(2) states:
50957 + Note that this call does not change the current working
50958 + directory, so that `.' can be outside the tree rooted at
50959 + `/'. In particular, the super-user can escape from a
50960 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50961 +
50962 + It is recommended that you say Y here, since it's not known to break
50963 + any software. If the sysctl option is enabled, a sysctl option with
50964 + name "chroot_enforce_chdir" is created.
50965 +
50966 +config GRKERNSEC_CHROOT_CHMOD
50967 + bool "Deny (f)chmod +s"
50968 + default y if GRKERNSEC_CONFIG_AUTO
50969 + depends on GRKERNSEC_CHROOT
50970 + help
50971 + If you say Y here, processes inside a chroot will not be able to chmod
50972 + or fchmod files to make them have suid or sgid bits. This protects
50973 + against another published method of breaking a chroot. If the sysctl
50974 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50975 + created.
50976 +
50977 +config GRKERNSEC_CHROOT_FCHDIR
50978 + bool "Deny fchdir out of chroot"
50979 + default y if GRKERNSEC_CONFIG_AUTO
50980 + depends on GRKERNSEC_CHROOT
50981 + help
50982 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50983 + to a file descriptor of the chrooting process that points to a directory
50984 + outside the filesystem will be stopped. If the sysctl option
50985 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50986 +
50987 +config GRKERNSEC_CHROOT_MKNOD
50988 + bool "Deny mknod"
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 allowed to
50993 + mknod. The problem with using mknod inside a chroot is that it
50994 + would allow an attacker to create a device entry that is the same
50995 + as one on the physical root of your system, which could range from
50996 + anything from the console device to a device for your harddrive (which
50997 + they could then use to wipe the drive or steal data). It is recommended
50998 + that you say Y here, unless you run into software incompatibilities.
50999 + If the sysctl option is enabled, a sysctl option with name
51000 + "chroot_deny_mknod" is created.
51001 +
51002 +config GRKERNSEC_CHROOT_SHMAT
51003 + bool "Deny shmat() out of chroot"
51004 + default y if GRKERNSEC_CONFIG_AUTO
51005 + depends on GRKERNSEC_CHROOT
51006 + help
51007 + If you say Y here, processes inside a chroot will not be able to attach
51008 + to shared memory segments that were created outside of the chroot jail.
51009 + It is recommended that you say Y here. If the sysctl option is enabled,
51010 + a sysctl option with name "chroot_deny_shmat" is created.
51011 +
51012 +config GRKERNSEC_CHROOT_UNIX
51013 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51014 + default y if GRKERNSEC_CONFIG_AUTO
51015 + depends on GRKERNSEC_CHROOT
51016 + help
51017 + If you say Y here, processes inside a chroot will not be able to
51018 + connect to abstract (meaning not belonging to a filesystem) Unix
51019 + domain sockets that were bound outside of a chroot. It is recommended
51020 + that you say Y here. If the sysctl option is enabled, a sysctl option
51021 + with name "chroot_deny_unix" is created.
51022 +
51023 +config GRKERNSEC_CHROOT_FINDTASK
51024 + bool "Protect outside processes"
51025 + default y if GRKERNSEC_CONFIG_AUTO
51026 + depends on GRKERNSEC_CHROOT
51027 + help
51028 + If you say Y here, processes inside a chroot will not be able to
51029 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51030 + getsid, or view any process outside of the chroot. If the sysctl
51031 + option is enabled, a sysctl option with name "chroot_findtask" is
51032 + created.
51033 +
51034 +config GRKERNSEC_CHROOT_NICE
51035 + bool "Restrict priority changes"
51036 + default y if GRKERNSEC_CONFIG_AUTO
51037 + depends on GRKERNSEC_CHROOT
51038 + help
51039 + If you say Y here, processes inside a chroot will not be able to raise
51040 + the priority of processes in the chroot, or alter the priority of
51041 + processes outside the chroot. This provides more security than simply
51042 + removing CAP_SYS_NICE from the process' capability set. If the
51043 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51044 + is created.
51045 +
51046 +config GRKERNSEC_CHROOT_SYSCTL
51047 + bool "Deny sysctl writes"
51048 + default y if GRKERNSEC_CONFIG_AUTO
51049 + depends on GRKERNSEC_CHROOT
51050 + help
51051 + If you say Y here, an attacker in a chroot will not be able to
51052 + write to sysctl entries, either by sysctl(2) or through a /proc
51053 + interface. It is strongly recommended that you say Y here. If the
51054 + sysctl option is enabled, a sysctl option with name
51055 + "chroot_deny_sysctl" is created.
51056 +
51057 +config GRKERNSEC_CHROOT_CAPS
51058 + bool "Capability restrictions"
51059 + default y if GRKERNSEC_CONFIG_AUTO
51060 + depends on GRKERNSEC_CHROOT
51061 + help
51062 + If you say Y here, the capabilities on all processes within a
51063 + chroot jail will be lowered to stop module insertion, raw i/o,
51064 + system and net admin tasks, rebooting the system, modifying immutable
51065 + files, modifying IPC owned by another, and changing the system time.
51066 + This is left an option because it can break some apps. Disable this
51067 + if your chrooted apps are having problems performing those kinds of
51068 + tasks. If the sysctl option is enabled, a sysctl option with
51069 + name "chroot_caps" is created.
51070 +
51071 +endmenu
51072 +menu "Kernel Auditing"
51073 +depends on GRKERNSEC
51074 +
51075 +config GRKERNSEC_AUDIT_GROUP
51076 + bool "Single group for auditing"
51077 + help
51078 + If you say Y here, the exec, chdir, and (un)mount logging features
51079 + will only operate on a group you specify. This option is recommended
51080 + if you only want to watch certain users instead of having a large
51081 + amount of logs from the entire system. If the sysctl option is enabled,
51082 + a sysctl option with name "audit_group" is created.
51083 +
51084 +config GRKERNSEC_AUDIT_GID
51085 + int "GID for auditing"
51086 + depends on GRKERNSEC_AUDIT_GROUP
51087 + default 1007
51088 +
51089 +config GRKERNSEC_EXECLOG
51090 + bool "Exec logging"
51091 + help
51092 + If you say Y here, all execve() calls will be logged (since the
51093 + other exec*() calls are frontends to execve(), all execution
51094 + will be logged). Useful for shell-servers that like to keep track
51095 + of their users. If the sysctl option is enabled, a sysctl option with
51096 + name "exec_logging" is created.
51097 + WARNING: This option when enabled will produce a LOT of logs, especially
51098 + on an active system.
51099 +
51100 +config GRKERNSEC_RESLOG
51101 + bool "Resource logging"
51102 + default y if GRKERNSEC_CONFIG_AUTO
51103 + help
51104 + If you say Y here, all attempts to overstep resource limits will
51105 + be logged with the resource name, the requested size, and the current
51106 + limit. It is highly recommended that you say Y here. If the sysctl
51107 + option is enabled, a sysctl option with name "resource_logging" is
51108 + created. If the RBAC system is enabled, the sysctl value is ignored.
51109 +
51110 +config GRKERNSEC_CHROOT_EXECLOG
51111 + bool "Log execs within chroot"
51112 + help
51113 + If you say Y here, all executions inside a chroot jail will be logged
51114 + to syslog. This can cause a large amount of logs if certain
51115 + applications (eg. djb's daemontools) are installed on the system, and
51116 + is therefore left as an option. If the sysctl option is enabled, a
51117 + sysctl option with name "chroot_execlog" is created.
51118 +
51119 +config GRKERNSEC_AUDIT_PTRACE
51120 + bool "Ptrace logging"
51121 + help
51122 + If you say Y here, all attempts to attach to a process via ptrace
51123 + will be logged. If the sysctl option is enabled, a sysctl option
51124 + with name "audit_ptrace" is created.
51125 +
51126 +config GRKERNSEC_AUDIT_CHDIR
51127 + bool "Chdir logging"
51128 + help
51129 + If you say Y here, all chdir() calls will be logged. If the sysctl
51130 + option is enabled, a sysctl option with name "audit_chdir" is created.
51131 +
51132 +config GRKERNSEC_AUDIT_MOUNT
51133 + bool "(Un)Mount logging"
51134 + help
51135 + If you say Y here, all mounts and unmounts will be logged. If the
51136 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51137 + created.
51138 +
51139 +config GRKERNSEC_SIGNAL
51140 + bool "Signal logging"
51141 + default y if GRKERNSEC_CONFIG_AUTO
51142 + help
51143 + If you say Y here, certain important signals will be logged, such as
51144 + SIGSEGV, which will as a result inform you of when a error in a program
51145 + occurred, which in some cases could mean a possible exploit attempt.
51146 + If the sysctl option is enabled, a sysctl option with name
51147 + "signal_logging" is created.
51148 +
51149 +config GRKERNSEC_FORKFAIL
51150 + bool "Fork failure logging"
51151 + help
51152 + If you say Y here, all failed fork() attempts will be logged.
51153 + This could suggest a fork bomb, or someone attempting to overstep
51154 + their process limit. If the sysctl option is enabled, a sysctl option
51155 + with name "forkfail_logging" is created.
51156 +
51157 +config GRKERNSEC_TIME
51158 + bool "Time change logging"
51159 + default y if GRKERNSEC_CONFIG_AUTO
51160 + help
51161 + If you say Y here, any changes of the system clock will be logged.
51162 + If the sysctl option is enabled, a sysctl option with name
51163 + "timechange_logging" is created.
51164 +
51165 +config GRKERNSEC_PROC_IPADDR
51166 + bool "/proc/<pid>/ipaddr support"
51167 + default y if GRKERNSEC_CONFIG_AUTO
51168 + help
51169 + If you say Y here, a new entry will be added to each /proc/<pid>
51170 + directory that contains the IP address of the person using the task.
51171 + The IP is carried across local TCP and AF_UNIX stream sockets.
51172 + This information can be useful for IDS/IPSes to perform remote response
51173 + to a local attack. The entry is readable by only the owner of the
51174 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51175 + the RBAC system), and thus does not create privacy concerns.
51176 +
51177 +config GRKERNSEC_RWXMAP_LOG
51178 + bool 'Denied RWX mmap/mprotect logging'
51179 + default y if GRKERNSEC_CONFIG_AUTO
51180 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51181 + help
51182 + If you say Y here, calls to mmap() and mprotect() with explicit
51183 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51184 + denied by the PAX_MPROTECT feature. If the sysctl option is
51185 + enabled, a sysctl option with name "rwxmap_logging" is created.
51186 +
51187 +config GRKERNSEC_AUDIT_TEXTREL
51188 + bool 'ELF text relocations logging (READ HELP)'
51189 + depends on PAX_MPROTECT
51190 + help
51191 + If you say Y here, text relocations will be logged with the filename
51192 + of the offending library or binary. The purpose of the feature is
51193 + to help Linux distribution developers get rid of libraries and
51194 + binaries that need text relocations which hinder the future progress
51195 + of PaX. Only Linux distribution developers should say Y here, and
51196 + never on a production machine, as this option creates an information
51197 + leak that could aid an attacker in defeating the randomization of
51198 + a single memory region. If the sysctl option is enabled, a sysctl
51199 + option with name "audit_textrel" is created.
51200 +
51201 +endmenu
51202 +
51203 +menu "Executable Protections"
51204 +depends on GRKERNSEC
51205 +
51206 +config GRKERNSEC_DMESG
51207 + bool "Dmesg(8) restriction"
51208 + default y if GRKERNSEC_CONFIG_AUTO
51209 + help
51210 + If you say Y here, non-root users will not be able to use dmesg(8)
51211 + to view up to the last 4kb of messages in the kernel's log buffer.
51212 + The kernel's log buffer often contains kernel addresses and other
51213 + identifying information useful to an attacker in fingerprinting a
51214 + system for a targeted exploit.
51215 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51216 + created.
51217 +
51218 +config GRKERNSEC_HARDEN_PTRACE
51219 + bool "Deter ptrace-based process snooping"
51220 + default y if GRKERNSEC_CONFIG_AUTO
51221 + help
51222 + If you say Y here, TTY sniffers and other malicious monitoring
51223 + programs implemented through ptrace will be defeated. If you
51224 + have been using the RBAC system, this option has already been
51225 + enabled for several years for all users, with the ability to make
51226 + fine-grained exceptions.
51227 +
51228 + This option only affects the ability of non-root users to ptrace
51229 + processes that are not a descendent of the ptracing process.
51230 + This means that strace ./binary and gdb ./binary will still work,
51231 + but attaching to arbitrary processes will not. If the sysctl
51232 + option is enabled, a sysctl option with name "harden_ptrace" is
51233 + created.
51234 +
51235 +config GRKERNSEC_PTRACE_READEXEC
51236 + bool "Require read access to ptrace sensitive binaries"
51237 + default y if GRKERNSEC_CONFIG_AUTO
51238 + help
51239 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51240 + binaries. This option is useful in environments that
51241 + remove the read bits (e.g. file mode 4711) from suid binaries to
51242 + prevent infoleaking of their contents. This option adds
51243 + consistency to the use of that file mode, as the binary could normally
51244 + be read out when run without privileges while ptracing.
51245 +
51246 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51247 + is created.
51248 +
51249 +config GRKERNSEC_SETXID
51250 + bool "Enforce consistent multithreaded privileges"
51251 + default y if GRKERNSEC_CONFIG_AUTO
51252 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51253 + help
51254 + If you say Y here, a change from a root uid to a non-root uid
51255 + in a multithreaded application will cause the resulting uids,
51256 + gids, supplementary groups, and capabilities in that thread
51257 + to be propagated to the other threads of the process. In most
51258 + cases this is unnecessary, as glibc will emulate this behavior
51259 + on behalf of the application. Other libcs do not act in the
51260 + same way, allowing the other threads of the process to continue
51261 + running with root privileges. If the sysctl option is enabled,
51262 + a sysctl option with name "consistent_setxid" is created.
51263 +
51264 +config GRKERNSEC_TPE
51265 + bool "Trusted Path Execution (TPE)"
51266 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51267 + help
51268 + If you say Y here, you will be able to choose a gid to add to the
51269 + supplementary groups of users you want to mark as "untrusted."
51270 + These users will not be able to execute any files that are not in
51271 + root-owned directories writable only by root. If the sysctl option
51272 + is enabled, a sysctl option with name "tpe" is created.
51273 +
51274 +config GRKERNSEC_TPE_ALL
51275 + bool "Partially restrict all non-root users"
51276 + depends on GRKERNSEC_TPE
51277 + help
51278 + If you say Y here, all non-root users will be covered under
51279 + a weaker TPE restriction. This is separate from, and in addition to,
51280 + the main TPE options that you have selected elsewhere. Thus, if a
51281 + "trusted" GID is chosen, this restriction applies to even that GID.
51282 + Under this restriction, all non-root users will only be allowed to
51283 + execute files in directories they own that are not group or
51284 + world-writable, or in directories owned by root and writable only by
51285 + root. If the sysctl option is enabled, a sysctl option with name
51286 + "tpe_restrict_all" is created.
51287 +
51288 +config GRKERNSEC_TPE_INVERT
51289 + bool "Invert GID option"
51290 + depends on GRKERNSEC_TPE
51291 + help
51292 + If you say Y here, the group you specify in the TPE configuration will
51293 + decide what group TPE restrictions will be *disabled* for. This
51294 + option is useful if you want TPE restrictions to be applied to most
51295 + users on the system. If the sysctl option is enabled, a sysctl option
51296 + with name "tpe_invert" is created. Unlike other sysctl options, this
51297 + entry will default to on for backward-compatibility.
51298 +
51299 +config GRKERNSEC_TPE_GID
51300 + int
51301 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51302 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51303 +
51304 +config GRKERNSEC_TPE_UNTRUSTED_GID
51305 + int "GID for TPE-untrusted users"
51306 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51307 + default 1005
51308 + help
51309 + Setting this GID determines what group TPE restrictions will be
51310 + *enabled* for. If the sysctl option is enabled, a sysctl option
51311 + with name "tpe_gid" is created.
51312 +
51313 +config GRKERNSEC_TPE_TRUSTED_GID
51314 + int "GID for TPE-trusted users"
51315 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51316 + default 1005
51317 + help
51318 + Setting this GID determines what group TPE restrictions will be
51319 + *disabled* for. If the sysctl option is enabled, a sysctl option
51320 + with name "tpe_gid" is created.
51321 +
51322 +endmenu
51323 +menu "Network Protections"
51324 +depends on GRKERNSEC
51325 +
51326 +config GRKERNSEC_RANDNET
51327 + bool "Larger entropy pools"
51328 + default y if GRKERNSEC_CONFIG_AUTO
51329 + help
51330 + If you say Y here, the entropy pools used for many features of Linux
51331 + and grsecurity will be doubled in size. Since several grsecurity
51332 + features use additional randomness, it is recommended that you say Y
51333 + here. Saying Y here has a similar effect as modifying
51334 + /proc/sys/kernel/random/poolsize.
51335 +
51336 +config GRKERNSEC_BLACKHOLE
51337 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51338 + default y if GRKERNSEC_CONFIG_AUTO
51339 + depends on NET
51340 + help
51341 + If you say Y here, neither TCP resets nor ICMP
51342 + destination-unreachable packets will be sent in response to packets
51343 + sent to ports for which no associated listening process exists.
51344 + This feature supports both IPV4 and IPV6 and exempts the
51345 + loopback interface from blackholing. Enabling this feature
51346 + makes a host more resilient to DoS attacks and reduces network
51347 + visibility against scanners.
51348 +
51349 + The blackhole feature as-implemented is equivalent to the FreeBSD
51350 + blackhole feature, as it prevents RST responses to all packets, not
51351 + just SYNs. Under most application behavior this causes no
51352 + problems, but applications (like haproxy) may not close certain
51353 + connections in a way that cleanly terminates them on the remote
51354 + end, leaving the remote host in LAST_ACK state. Because of this
51355 + side-effect and to prevent intentional LAST_ACK DoSes, this
51356 + feature also adds automatic mitigation against such attacks.
51357 + The mitigation drastically reduces the amount of time a socket
51358 + can spend in LAST_ACK state. If you're using haproxy and not
51359 + all servers it connects to have this option enabled, consider
51360 + disabling this feature on the haproxy host.
51361 +
51362 + If the sysctl option is enabled, two sysctl options with names
51363 + "ip_blackhole" and "lastack_retries" will be created.
51364 + While "ip_blackhole" takes the standard zero/non-zero on/off
51365 + toggle, "lastack_retries" uses the same kinds of values as
51366 + "tcp_retries1" and "tcp_retries2". The default value of 4
51367 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51368 + state.
51369 +
51370 +config GRKERNSEC_SOCKET
51371 + bool "Socket restrictions"
51372 + depends on NET
51373 + help
51374 + If you say Y here, you will be able to choose from several options.
51375 + If you assign a GID on your system and add it to the supplementary
51376 + groups of users you want to restrict socket access to, this patch
51377 + will perform up to three things, based on the option(s) you choose.
51378 +
51379 +config GRKERNSEC_SOCKET_ALL
51380 + bool "Deny any sockets to group"
51381 + depends on GRKERNSEC_SOCKET
51382 + help
51383 + If you say Y here, you will be able to choose a GID of whose users will
51384 + be unable to connect to other hosts from your machine or run server
51385 + applications from your machine. If the sysctl option is enabled, a
51386 + sysctl option with name "socket_all" is created.
51387 +
51388 +config GRKERNSEC_SOCKET_ALL_GID
51389 + int "GID to deny all sockets for"
51390 + depends on GRKERNSEC_SOCKET_ALL
51391 + default 1004
51392 + help
51393 + Here you can choose the GID to disable socket access for. Remember to
51394 + add the users you want socket access disabled for to the GID
51395 + specified here. If the sysctl option is enabled, a sysctl option
51396 + with name "socket_all_gid" is created.
51397 +
51398 +config GRKERNSEC_SOCKET_CLIENT
51399 + bool "Deny client sockets to group"
51400 + depends on GRKERNSEC_SOCKET
51401 + help
51402 + If you say Y here, you will be able to choose a GID of whose users will
51403 + be unable to connect to other hosts from your machine, but will be
51404 + able to run servers. If this option is enabled, all users in the group
51405 + you specify will have to use passive mode when initiating ftp transfers
51406 + from the shell on your machine. If the sysctl option is enabled, a
51407 + sysctl option with name "socket_client" is created.
51408 +
51409 +config GRKERNSEC_SOCKET_CLIENT_GID
51410 + int "GID to deny client sockets for"
51411 + depends on GRKERNSEC_SOCKET_CLIENT
51412 + default 1003
51413 + help
51414 + Here you can choose the GID to disable client socket access for.
51415 + Remember to add the users you want client socket access disabled for to
51416 + the GID specified here. If the sysctl option is enabled, a sysctl
51417 + option with name "socket_client_gid" is created.
51418 +
51419 +config GRKERNSEC_SOCKET_SERVER
51420 + bool "Deny server sockets to group"
51421 + depends on GRKERNSEC_SOCKET
51422 + help
51423 + If you say Y here, you will be able to choose a GID of whose users will
51424 + be unable to run server applications from your machine. If the sysctl
51425 + option is enabled, a sysctl option with name "socket_server" is created.
51426 +
51427 +config GRKERNSEC_SOCKET_SERVER_GID
51428 + int "GID to deny server sockets for"
51429 + depends on GRKERNSEC_SOCKET_SERVER
51430 + default 1002
51431 + help
51432 + Here you can choose the GID to disable server socket access for.
51433 + Remember to add the users you want server socket access disabled for to
51434 + the GID specified here. If the sysctl option is enabled, a sysctl
51435 + option with name "socket_server_gid" is created.
51436 +
51437 +endmenu
51438 +menu "Sysctl Support"
51439 +depends on GRKERNSEC && SYSCTL
51440 +
51441 +config GRKERNSEC_SYSCTL
51442 + bool "Sysctl support"
51443 + default y if GRKERNSEC_CONFIG_AUTO
51444 + help
51445 + If you say Y here, you will be able to change the options that
51446 + grsecurity runs with at bootup, without having to recompile your
51447 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51448 + to enable (1) or disable (0) various features. All the sysctl entries
51449 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51450 + All features enabled in the kernel configuration are disabled at boot
51451 + if you do not say Y to the "Turn on features by default" option.
51452 + All options should be set at startup, and the grsec_lock entry should
51453 + be set to a non-zero value after all the options are set.
51454 + *THIS IS EXTREMELY IMPORTANT*
51455 +
51456 +config GRKERNSEC_SYSCTL_DISTRO
51457 + bool "Extra sysctl support for distro makers (READ HELP)"
51458 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51459 + help
51460 + If you say Y here, additional sysctl options will be created
51461 + for features that affect processes running as root. Therefore,
51462 + it is critical when using this option that the grsec_lock entry be
51463 + enabled after boot. Only distros with prebuilt kernel packages
51464 + with this option enabled that can ensure grsec_lock is enabled
51465 + after boot should use this option.
51466 + *Failure to set grsec_lock after boot makes all grsec features
51467 + this option covers useless*
51468 +
51469 + Currently this option creates the following sysctl entries:
51470 + "Disable Privileged I/O": "disable_priv_io"
51471 +
51472 +config GRKERNSEC_SYSCTL_ON
51473 + bool "Turn on features by default"
51474 + default y if GRKERNSEC_CONFIG_AUTO
51475 + depends on GRKERNSEC_SYSCTL
51476 + help
51477 + If you say Y here, instead of having all features enabled in the
51478 + kernel configuration disabled at boot time, the features will be
51479 + enabled at boot time. It is recommended you say Y here unless
51480 + there is some reason you would want all sysctl-tunable features to
51481 + be disabled by default. As mentioned elsewhere, it is important
51482 + to enable the grsec_lock entry once you have finished modifying
51483 + the sysctl entries.
51484 +
51485 +endmenu
51486 +menu "Logging Options"
51487 +depends on GRKERNSEC
51488 +
51489 +config GRKERNSEC_FLOODTIME
51490 + int "Seconds in between log messages (minimum)"
51491 + default 10
51492 + help
51493 + This option allows you to enforce the number of seconds between
51494 + grsecurity log messages. The default should be suitable for most
51495 + people, however, if you choose to change it, choose a value small enough
51496 + to allow informative logs to be produced, but large enough to
51497 + prevent flooding.
51498 +
51499 +config GRKERNSEC_FLOODBURST
51500 + int "Number of messages in a burst (maximum)"
51501 + default 6
51502 + help
51503 + This option allows you to choose the maximum number of messages allowed
51504 + within the flood time interval you chose in a separate option. The
51505 + default should be suitable for most people, however if you find that
51506 + many of your logs are being interpreted as flooding, you may want to
51507 + raise this value.
51508 +
51509 +endmenu
51510 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51511 new file mode 100644
51512 index 0000000..1b9afa9
51513 --- /dev/null
51514 +++ b/grsecurity/Makefile
51515 @@ -0,0 +1,38 @@
51516 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51517 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51518 +# into an RBAC system
51519 +#
51520 +# All code in this directory and various hooks inserted throughout the kernel
51521 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51522 +# under the GPL v2 or higher
51523 +
51524 +KBUILD_CFLAGS += -Werror
51525 +
51526 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51527 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51528 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51529 +
51530 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51531 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51532 + gracl_learn.o grsec_log.o
51533 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51534 +
51535 +ifdef CONFIG_NET
51536 +obj-y += grsec_sock.o
51537 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51538 +endif
51539 +
51540 +ifndef CONFIG_GRKERNSEC
51541 +obj-y += grsec_disabled.o
51542 +endif
51543 +
51544 +ifdef CONFIG_GRKERNSEC_HIDESYM
51545 +extra-y := grsec_hidesym.o
51546 +$(obj)/grsec_hidesym.o:
51547 + @-chmod -f 500 /boot
51548 + @-chmod -f 500 /lib/modules
51549 + @-chmod -f 500 /lib64/modules
51550 + @-chmod -f 500 /lib32/modules
51551 + @-chmod -f 700 .
51552 + @echo ' grsec: protected kernel image paths'
51553 +endif
51554 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51555 new file mode 100644
51556 index 0000000..3d58260
51557 --- /dev/null
51558 +++ b/grsecurity/gracl.c
51559 @@ -0,0 +1,4029 @@
51560 +#include <linux/kernel.h>
51561 +#include <linux/module.h>
51562 +#include <linux/sched.h>
51563 +#include <linux/mm.h>
51564 +#include <linux/file.h>
51565 +#include <linux/fs.h>
51566 +#include <linux/namei.h>
51567 +#include <linux/mount.h>
51568 +#include <linux/tty.h>
51569 +#include <linux/proc_fs.h>
51570 +#include <linux/lglock.h>
51571 +#include <linux/slab.h>
51572 +#include <linux/vmalloc.h>
51573 +#include <linux/types.h>
51574 +#include <linux/sysctl.h>
51575 +#include <linux/netdevice.h>
51576 +#include <linux/ptrace.h>
51577 +#include <linux/gracl.h>
51578 +#include <linux/gralloc.h>
51579 +#include <linux/security.h>
51580 +#include <linux/grinternal.h>
51581 +#include <linux/pid_namespace.h>
51582 +#include <linux/stop_machine.h>
51583 +#include <linux/fdtable.h>
51584 +#include <linux/percpu.h>
51585 +#include <linux/lglock.h>
51586 +#include "../fs/mount.h"
51587 +
51588 +#include <asm/uaccess.h>
51589 +#include <asm/errno.h>
51590 +#include <asm/mman.h>
51591 +
51592 +extern struct lglock vfsmount_lock;
51593 +
51594 +static struct acl_role_db acl_role_set;
51595 +static struct name_db name_set;
51596 +static struct inodev_db inodev_set;
51597 +
51598 +/* for keeping track of userspace pointers used for subjects, so we
51599 + can share references in the kernel as well
51600 +*/
51601 +
51602 +static struct path real_root;
51603 +
51604 +static struct acl_subj_map_db subj_map_set;
51605 +
51606 +static struct acl_role_label *default_role;
51607 +
51608 +static struct acl_role_label *role_list;
51609 +
51610 +static u16 acl_sp_role_value;
51611 +
51612 +extern char *gr_shared_page[4];
51613 +static DEFINE_MUTEX(gr_dev_mutex);
51614 +DEFINE_RWLOCK(gr_inode_lock);
51615 +
51616 +struct gr_arg *gr_usermode;
51617 +
51618 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51619 +
51620 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51621 +extern void gr_clear_learn_entries(void);
51622 +
51623 +#ifdef CONFIG_GRKERNSEC_RESLOG
51624 +extern void gr_log_resource(const struct task_struct *task,
51625 + const int res, const unsigned long wanted, const int gt);
51626 +#endif
51627 +
51628 +unsigned char *gr_system_salt;
51629 +unsigned char *gr_system_sum;
51630 +
51631 +static struct sprole_pw **acl_special_roles = NULL;
51632 +static __u16 num_sprole_pws = 0;
51633 +
51634 +static struct acl_role_label *kernel_role = NULL;
51635 +
51636 +static unsigned int gr_auth_attempts = 0;
51637 +static unsigned long gr_auth_expires = 0UL;
51638 +
51639 +#ifdef CONFIG_NET
51640 +extern struct vfsmount *sock_mnt;
51641 +#endif
51642 +
51643 +extern struct vfsmount *pipe_mnt;
51644 +extern struct vfsmount *shm_mnt;
51645 +#ifdef CONFIG_HUGETLBFS
51646 +extern struct vfsmount *hugetlbfs_vfsmount;
51647 +#endif
51648 +
51649 +static struct acl_object_label *fakefs_obj_rw;
51650 +static struct acl_object_label *fakefs_obj_rwx;
51651 +
51652 +extern int gr_init_uidset(void);
51653 +extern void gr_free_uidset(void);
51654 +extern void gr_remove_uid(uid_t uid);
51655 +extern int gr_find_uid(uid_t uid);
51656 +
51657 +__inline__ int
51658 +gr_acl_is_enabled(void)
51659 +{
51660 + return (gr_status & GR_READY);
51661 +}
51662 +
51663 +#ifdef CONFIG_BTRFS_FS
51664 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51665 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51666 +#endif
51667 +
51668 +static inline dev_t __get_dev(const struct dentry *dentry)
51669 +{
51670 +#ifdef CONFIG_BTRFS_FS
51671 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51672 + return get_btrfs_dev_from_inode(dentry->d_inode);
51673 + else
51674 +#endif
51675 + return dentry->d_inode->i_sb->s_dev;
51676 +}
51677 +
51678 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51679 +{
51680 + return __get_dev(dentry);
51681 +}
51682 +
51683 +static char gr_task_roletype_to_char(struct task_struct *task)
51684 +{
51685 + switch (task->role->roletype &
51686 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51687 + GR_ROLE_SPECIAL)) {
51688 + case GR_ROLE_DEFAULT:
51689 + return 'D';
51690 + case GR_ROLE_USER:
51691 + return 'U';
51692 + case GR_ROLE_GROUP:
51693 + return 'G';
51694 + case GR_ROLE_SPECIAL:
51695 + return 'S';
51696 + }
51697 +
51698 + return 'X';
51699 +}
51700 +
51701 +char gr_roletype_to_char(void)
51702 +{
51703 + return gr_task_roletype_to_char(current);
51704 +}
51705 +
51706 +__inline__ int
51707 +gr_acl_tpe_check(void)
51708 +{
51709 + if (unlikely(!(gr_status & GR_READY)))
51710 + return 0;
51711 + if (current->role->roletype & GR_ROLE_TPE)
51712 + return 1;
51713 + else
51714 + return 0;
51715 +}
51716 +
51717 +int
51718 +gr_handle_rawio(const struct inode *inode)
51719 +{
51720 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51721 + if (inode && S_ISBLK(inode->i_mode) &&
51722 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51723 + !capable(CAP_SYS_RAWIO))
51724 + return 1;
51725 +#endif
51726 + return 0;
51727 +}
51728 +
51729 +static int
51730 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51731 +{
51732 + if (likely(lena != lenb))
51733 + return 0;
51734 +
51735 + return !memcmp(a, b, lena);
51736 +}
51737 +
51738 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51739 +{
51740 + *buflen -= namelen;
51741 + if (*buflen < 0)
51742 + return -ENAMETOOLONG;
51743 + *buffer -= namelen;
51744 + memcpy(*buffer, str, namelen);
51745 + return 0;
51746 +}
51747 +
51748 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51749 +{
51750 + return prepend(buffer, buflen, name->name, name->len);
51751 +}
51752 +
51753 +static int prepend_path(const struct path *path, struct path *root,
51754 + char **buffer, int *buflen)
51755 +{
51756 + struct dentry *dentry = path->dentry;
51757 + struct vfsmount *vfsmnt = path->mnt;
51758 + struct mount *mnt = real_mount(vfsmnt);
51759 + bool slash = false;
51760 + int error = 0;
51761 +
51762 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51763 + struct dentry * parent;
51764 +
51765 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51766 + /* Global root? */
51767 + if (!mnt_has_parent(mnt)) {
51768 + goto out;
51769 + }
51770 + dentry = mnt->mnt_mountpoint;
51771 + mnt = mnt->mnt_parent;
51772 + vfsmnt = &mnt->mnt;
51773 + continue;
51774 + }
51775 + parent = dentry->d_parent;
51776 + prefetch(parent);
51777 + spin_lock(&dentry->d_lock);
51778 + error = prepend_name(buffer, buflen, &dentry->d_name);
51779 + spin_unlock(&dentry->d_lock);
51780 + if (!error)
51781 + error = prepend(buffer, buflen, "/", 1);
51782 + if (error)
51783 + break;
51784 +
51785 + slash = true;
51786 + dentry = parent;
51787 + }
51788 +
51789 +out:
51790 + if (!error && !slash)
51791 + error = prepend(buffer, buflen, "/", 1);
51792 +
51793 + return error;
51794 +}
51795 +
51796 +/* this must be called with vfsmount_lock and rename_lock held */
51797 +
51798 +static char *__our_d_path(const struct path *path, struct path *root,
51799 + char *buf, int buflen)
51800 +{
51801 + char *res = buf + buflen;
51802 + int error;
51803 +
51804 + prepend(&res, &buflen, "\0", 1);
51805 + error = prepend_path(path, root, &res, &buflen);
51806 + if (error)
51807 + return ERR_PTR(error);
51808 +
51809 + return res;
51810 +}
51811 +
51812 +static char *
51813 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51814 +{
51815 + char *retval;
51816 +
51817 + retval = __our_d_path(path, root, buf, buflen);
51818 + if (unlikely(IS_ERR(retval)))
51819 + retval = strcpy(buf, "<path too long>");
51820 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51821 + retval[1] = '\0';
51822 +
51823 + return retval;
51824 +}
51825 +
51826 +static char *
51827 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51828 + char *buf, int buflen)
51829 +{
51830 + struct path path;
51831 + char *res;
51832 +
51833 + path.dentry = (struct dentry *)dentry;
51834 + path.mnt = (struct vfsmount *)vfsmnt;
51835 +
51836 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51837 + by the RBAC system */
51838 + res = gen_full_path(&path, &real_root, buf, buflen);
51839 +
51840 + return res;
51841 +}
51842 +
51843 +static char *
51844 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51845 + char *buf, int buflen)
51846 +{
51847 + char *res;
51848 + struct path path;
51849 + struct path root;
51850 + struct task_struct *reaper = init_pid_ns.child_reaper;
51851 +
51852 + path.dentry = (struct dentry *)dentry;
51853 + path.mnt = (struct vfsmount *)vfsmnt;
51854 +
51855 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51856 + get_fs_root(reaper->fs, &root);
51857 +
51858 + write_seqlock(&rename_lock);
51859 + br_read_lock(&vfsmount_lock);
51860 + res = gen_full_path(&path, &root, buf, buflen);
51861 + br_read_unlock(&vfsmount_lock);
51862 + write_sequnlock(&rename_lock);
51863 +
51864 + path_put(&root);
51865 + return res;
51866 +}
51867 +
51868 +static char *
51869 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51870 +{
51871 + char *ret;
51872 + write_seqlock(&rename_lock);
51873 + br_read_lock(&vfsmount_lock);
51874 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51875 + PAGE_SIZE);
51876 + br_read_unlock(&vfsmount_lock);
51877 + write_sequnlock(&rename_lock);
51878 + return ret;
51879 +}
51880 +
51881 +static char *
51882 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51883 +{
51884 + char *ret;
51885 + char *buf;
51886 + int buflen;
51887 +
51888 + write_seqlock(&rename_lock);
51889 + br_read_lock(&vfsmount_lock);
51890 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51891 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51892 + buflen = (int)(ret - buf);
51893 + if (buflen >= 5)
51894 + prepend(&ret, &buflen, "/proc", 5);
51895 + else
51896 + ret = strcpy(buf, "<path too long>");
51897 + br_read_unlock(&vfsmount_lock);
51898 + write_sequnlock(&rename_lock);
51899 + return ret;
51900 +}
51901 +
51902 +char *
51903 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51904 +{
51905 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51906 + PAGE_SIZE);
51907 +}
51908 +
51909 +char *
51910 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51911 +{
51912 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51913 + PAGE_SIZE);
51914 +}
51915 +
51916 +char *
51917 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51918 +{
51919 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51920 + PAGE_SIZE);
51921 +}
51922 +
51923 +char *
51924 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51925 +{
51926 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51927 + PAGE_SIZE);
51928 +}
51929 +
51930 +char *
51931 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51932 +{
51933 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51934 + PAGE_SIZE);
51935 +}
51936 +
51937 +__inline__ __u32
51938 +to_gr_audit(const __u32 reqmode)
51939 +{
51940 + /* masks off auditable permission flags, then shifts them to create
51941 + auditing flags, and adds the special case of append auditing if
51942 + we're requesting write */
51943 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51944 +}
51945 +
51946 +struct acl_subject_label *
51947 +lookup_subject_map(const struct acl_subject_label *userp)
51948 +{
51949 + unsigned int index = shash(userp, subj_map_set.s_size);
51950 + struct subject_map *match;
51951 +
51952 + match = subj_map_set.s_hash[index];
51953 +
51954 + while (match && match->user != userp)
51955 + match = match->next;
51956 +
51957 + if (match != NULL)
51958 + return match->kernel;
51959 + else
51960 + return NULL;
51961 +}
51962 +
51963 +static void
51964 +insert_subj_map_entry(struct subject_map *subjmap)
51965 +{
51966 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51967 + struct subject_map **curr;
51968 +
51969 + subjmap->prev = NULL;
51970 +
51971 + curr = &subj_map_set.s_hash[index];
51972 + if (*curr != NULL)
51973 + (*curr)->prev = subjmap;
51974 +
51975 + subjmap->next = *curr;
51976 + *curr = subjmap;
51977 +
51978 + return;
51979 +}
51980 +
51981 +static struct acl_role_label *
51982 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51983 + const gid_t gid)
51984 +{
51985 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51986 + struct acl_role_label *match;
51987 + struct role_allowed_ip *ipp;
51988 + unsigned int x;
51989 + u32 curr_ip = task->signal->curr_ip;
51990 +
51991 + task->signal->saved_ip = curr_ip;
51992 +
51993 + match = acl_role_set.r_hash[index];
51994 +
51995 + while (match) {
51996 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51997 + for (x = 0; x < match->domain_child_num; x++) {
51998 + if (match->domain_children[x] == uid)
51999 + goto found;
52000 + }
52001 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52002 + break;
52003 + match = match->next;
52004 + }
52005 +found:
52006 + if (match == NULL) {
52007 + try_group:
52008 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52009 + match = acl_role_set.r_hash[index];
52010 +
52011 + while (match) {
52012 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52013 + for (x = 0; x < match->domain_child_num; x++) {
52014 + if (match->domain_children[x] == gid)
52015 + goto found2;
52016 + }
52017 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52018 + break;
52019 + match = match->next;
52020 + }
52021 +found2:
52022 + if (match == NULL)
52023 + match = default_role;
52024 + if (match->allowed_ips == NULL)
52025 + return match;
52026 + else {
52027 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52028 + if (likely
52029 + ((ntohl(curr_ip) & ipp->netmask) ==
52030 + (ntohl(ipp->addr) & ipp->netmask)))
52031 + return match;
52032 + }
52033 + match = default_role;
52034 + }
52035 + } else if (match->allowed_ips == NULL) {
52036 + return match;
52037 + } else {
52038 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52039 + if (likely
52040 + ((ntohl(curr_ip) & ipp->netmask) ==
52041 + (ntohl(ipp->addr) & ipp->netmask)))
52042 + return match;
52043 + }
52044 + goto try_group;
52045 + }
52046 +
52047 + return match;
52048 +}
52049 +
52050 +struct acl_subject_label *
52051 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52052 + const struct acl_role_label *role)
52053 +{
52054 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52055 + struct acl_subject_label *match;
52056 +
52057 + match = role->subj_hash[index];
52058 +
52059 + while (match && (match->inode != ino || match->device != dev ||
52060 + (match->mode & GR_DELETED))) {
52061 + match = match->next;
52062 + }
52063 +
52064 + if (match && !(match->mode & GR_DELETED))
52065 + return match;
52066 + else
52067 + return NULL;
52068 +}
52069 +
52070 +struct acl_subject_label *
52071 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52072 + const struct acl_role_label *role)
52073 +{
52074 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52075 + struct acl_subject_label *match;
52076 +
52077 + match = role->subj_hash[index];
52078 +
52079 + while (match && (match->inode != ino || match->device != dev ||
52080 + !(match->mode & GR_DELETED))) {
52081 + match = match->next;
52082 + }
52083 +
52084 + if (match && (match->mode & GR_DELETED))
52085 + return match;
52086 + else
52087 + return NULL;
52088 +}
52089 +
52090 +static struct acl_object_label *
52091 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52092 + const struct acl_subject_label *subj)
52093 +{
52094 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52095 + struct acl_object_label *match;
52096 +
52097 + match = subj->obj_hash[index];
52098 +
52099 + while (match && (match->inode != ino || match->device != dev ||
52100 + (match->mode & GR_DELETED))) {
52101 + match = match->next;
52102 + }
52103 +
52104 + if (match && !(match->mode & GR_DELETED))
52105 + return match;
52106 + else
52107 + return NULL;
52108 +}
52109 +
52110 +static struct acl_object_label *
52111 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52112 + const struct acl_subject_label *subj)
52113 +{
52114 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52115 + struct acl_object_label *match;
52116 +
52117 + match = subj->obj_hash[index];
52118 +
52119 + while (match && (match->inode != ino || match->device != dev ||
52120 + !(match->mode & GR_DELETED))) {
52121 + match = match->next;
52122 + }
52123 +
52124 + if (match && (match->mode & GR_DELETED))
52125 + return match;
52126 +
52127 + match = subj->obj_hash[index];
52128 +
52129 + while (match && (match->inode != ino || match->device != dev ||
52130 + (match->mode & GR_DELETED))) {
52131 + match = match->next;
52132 + }
52133 +
52134 + if (match && !(match->mode & GR_DELETED))
52135 + return match;
52136 + else
52137 + return NULL;
52138 +}
52139 +
52140 +static struct name_entry *
52141 +lookup_name_entry(const char *name)
52142 +{
52143 + unsigned int len = strlen(name);
52144 + unsigned int key = full_name_hash(name, len);
52145 + unsigned int index = key % name_set.n_size;
52146 + struct name_entry *match;
52147 +
52148 + match = name_set.n_hash[index];
52149 +
52150 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52151 + match = match->next;
52152 +
52153 + return match;
52154 +}
52155 +
52156 +static struct name_entry *
52157 +lookup_name_entry_create(const char *name)
52158 +{
52159 + unsigned int len = strlen(name);
52160 + unsigned int key = full_name_hash(name, len);
52161 + unsigned int index = key % name_set.n_size;
52162 + struct name_entry *match;
52163 +
52164 + match = name_set.n_hash[index];
52165 +
52166 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52167 + !match->deleted))
52168 + match = match->next;
52169 +
52170 + if (match && match->deleted)
52171 + return match;
52172 +
52173 + match = name_set.n_hash[index];
52174 +
52175 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52176 + match->deleted))
52177 + match = match->next;
52178 +
52179 + if (match && !match->deleted)
52180 + return match;
52181 + else
52182 + return NULL;
52183 +}
52184 +
52185 +static struct inodev_entry *
52186 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52187 +{
52188 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52189 + struct inodev_entry *match;
52190 +
52191 + match = inodev_set.i_hash[index];
52192 +
52193 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52194 + match = match->next;
52195 +
52196 + return match;
52197 +}
52198 +
52199 +static void
52200 +insert_inodev_entry(struct inodev_entry *entry)
52201 +{
52202 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52203 + inodev_set.i_size);
52204 + struct inodev_entry **curr;
52205 +
52206 + entry->prev = NULL;
52207 +
52208 + curr = &inodev_set.i_hash[index];
52209 + if (*curr != NULL)
52210 + (*curr)->prev = entry;
52211 +
52212 + entry->next = *curr;
52213 + *curr = entry;
52214 +
52215 + return;
52216 +}
52217 +
52218 +static void
52219 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52220 +{
52221 + unsigned int index =
52222 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52223 + struct acl_role_label **curr;
52224 + struct acl_role_label *tmp, *tmp2;
52225 +
52226 + curr = &acl_role_set.r_hash[index];
52227 +
52228 + /* simple case, slot is empty, just set it to our role */
52229 + if (*curr == NULL) {
52230 + *curr = role;
52231 + } else {
52232 + /* example:
52233 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52234 + 2 -> 3
52235 + */
52236 + /* first check to see if we can already be reached via this slot */
52237 + tmp = *curr;
52238 + while (tmp && tmp != role)
52239 + tmp = tmp->next;
52240 + if (tmp == role) {
52241 + /* we don't need to add ourselves to this slot's chain */
52242 + return;
52243 + }
52244 + /* we need to add ourselves to this chain, two cases */
52245 + if (role->next == NULL) {
52246 + /* simple case, append the current chain to our role */
52247 + role->next = *curr;
52248 + *curr = role;
52249 + } else {
52250 + /* 1 -> 2 -> 3 -> 4
52251 + 2 -> 3 -> 4
52252 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52253 + */
52254 + /* trickier case: walk our role's chain until we find
52255 + the role for the start of the current slot's chain */
52256 + tmp = role;
52257 + tmp2 = *curr;
52258 + while (tmp->next && tmp->next != tmp2)
52259 + tmp = tmp->next;
52260 + if (tmp->next == tmp2) {
52261 + /* from example above, we found 3, so just
52262 + replace this slot's chain with ours */
52263 + *curr = role;
52264 + } else {
52265 + /* we didn't find a subset of our role's chain
52266 + in the current slot's chain, so append their
52267 + chain to ours, and set us as the first role in
52268 + the slot's chain
52269 +
52270 + we could fold this case with the case above,
52271 + but making it explicit for clarity
52272 + */
52273 + tmp->next = tmp2;
52274 + *curr = role;
52275 + }
52276 + }
52277 + }
52278 +
52279 + return;
52280 +}
52281 +
52282 +static void
52283 +insert_acl_role_label(struct acl_role_label *role)
52284 +{
52285 + int i;
52286 +
52287 + if (role_list == NULL) {
52288 + role_list = role;
52289 + role->prev = NULL;
52290 + } else {
52291 + role->prev = role_list;
52292 + role_list = role;
52293 + }
52294 +
52295 + /* used for hash chains */
52296 + role->next = NULL;
52297 +
52298 + if (role->roletype & GR_ROLE_DOMAIN) {
52299 + for (i = 0; i < role->domain_child_num; i++)
52300 + __insert_acl_role_label(role, role->domain_children[i]);
52301 + } else
52302 + __insert_acl_role_label(role, role->uidgid);
52303 +}
52304 +
52305 +static int
52306 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52307 +{
52308 + struct name_entry **curr, *nentry;
52309 + struct inodev_entry *ientry;
52310 + unsigned int len = strlen(name);
52311 + unsigned int key = full_name_hash(name, len);
52312 + unsigned int index = key % name_set.n_size;
52313 +
52314 + curr = &name_set.n_hash[index];
52315 +
52316 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52317 + curr = &((*curr)->next);
52318 +
52319 + if (*curr != NULL)
52320 + return 1;
52321 +
52322 + nentry = acl_alloc(sizeof (struct name_entry));
52323 + if (nentry == NULL)
52324 + return 0;
52325 + ientry = acl_alloc(sizeof (struct inodev_entry));
52326 + if (ientry == NULL)
52327 + return 0;
52328 + ientry->nentry = nentry;
52329 +
52330 + nentry->key = key;
52331 + nentry->name = name;
52332 + nentry->inode = inode;
52333 + nentry->device = device;
52334 + nentry->len = len;
52335 + nentry->deleted = deleted;
52336 +
52337 + nentry->prev = NULL;
52338 + curr = &name_set.n_hash[index];
52339 + if (*curr != NULL)
52340 + (*curr)->prev = nentry;
52341 + nentry->next = *curr;
52342 + *curr = nentry;
52343 +
52344 + /* insert us into the table searchable by inode/dev */
52345 + insert_inodev_entry(ientry);
52346 +
52347 + return 1;
52348 +}
52349 +
52350 +static void
52351 +insert_acl_obj_label(struct acl_object_label *obj,
52352 + struct acl_subject_label *subj)
52353 +{
52354 + unsigned int index =
52355 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52356 + struct acl_object_label **curr;
52357 +
52358 +
52359 + obj->prev = NULL;
52360 +
52361 + curr = &subj->obj_hash[index];
52362 + if (*curr != NULL)
52363 + (*curr)->prev = obj;
52364 +
52365 + obj->next = *curr;
52366 + *curr = obj;
52367 +
52368 + return;
52369 +}
52370 +
52371 +static void
52372 +insert_acl_subj_label(struct acl_subject_label *obj,
52373 + struct acl_role_label *role)
52374 +{
52375 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52376 + struct acl_subject_label **curr;
52377 +
52378 + obj->prev = NULL;
52379 +
52380 + curr = &role->subj_hash[index];
52381 + if (*curr != NULL)
52382 + (*curr)->prev = obj;
52383 +
52384 + obj->next = *curr;
52385 + *curr = obj;
52386 +
52387 + return;
52388 +}
52389 +
52390 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52391 +
52392 +static void *
52393 +create_table(__u32 * len, int elementsize)
52394 +{
52395 + unsigned int table_sizes[] = {
52396 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52397 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52398 + 4194301, 8388593, 16777213, 33554393, 67108859
52399 + };
52400 + void *newtable = NULL;
52401 + unsigned int pwr = 0;
52402 +
52403 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52404 + table_sizes[pwr] <= *len)
52405 + pwr++;
52406 +
52407 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52408 + return newtable;
52409 +
52410 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52411 + newtable =
52412 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52413 + else
52414 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52415 +
52416 + *len = table_sizes[pwr];
52417 +
52418 + return newtable;
52419 +}
52420 +
52421 +static int
52422 +init_variables(const struct gr_arg *arg)
52423 +{
52424 + struct task_struct *reaper = init_pid_ns.child_reaper;
52425 + unsigned int stacksize;
52426 +
52427 + subj_map_set.s_size = arg->role_db.num_subjects;
52428 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52429 + name_set.n_size = arg->role_db.num_objects;
52430 + inodev_set.i_size = arg->role_db.num_objects;
52431 +
52432 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52433 + !name_set.n_size || !inodev_set.i_size)
52434 + return 1;
52435 +
52436 + if (!gr_init_uidset())
52437 + return 1;
52438 +
52439 + /* set up the stack that holds allocation info */
52440 +
52441 + stacksize = arg->role_db.num_pointers + 5;
52442 +
52443 + if (!acl_alloc_stack_init(stacksize))
52444 + return 1;
52445 +
52446 + /* grab reference for the real root dentry and vfsmount */
52447 + get_fs_root(reaper->fs, &real_root);
52448 +
52449 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52450 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52451 +#endif
52452 +
52453 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52454 + if (fakefs_obj_rw == NULL)
52455 + return 1;
52456 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52457 +
52458 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52459 + if (fakefs_obj_rwx == NULL)
52460 + return 1;
52461 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52462 +
52463 + subj_map_set.s_hash =
52464 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52465 + acl_role_set.r_hash =
52466 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52467 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52468 + inodev_set.i_hash =
52469 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52470 +
52471 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52472 + !name_set.n_hash || !inodev_set.i_hash)
52473 + return 1;
52474 +
52475 + memset(subj_map_set.s_hash, 0,
52476 + sizeof(struct subject_map *) * subj_map_set.s_size);
52477 + memset(acl_role_set.r_hash, 0,
52478 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52479 + memset(name_set.n_hash, 0,
52480 + sizeof (struct name_entry *) * name_set.n_size);
52481 + memset(inodev_set.i_hash, 0,
52482 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52483 +
52484 + return 0;
52485 +}
52486 +
52487 +/* free information not needed after startup
52488 + currently contains user->kernel pointer mappings for subjects
52489 +*/
52490 +
52491 +static void
52492 +free_init_variables(void)
52493 +{
52494 + __u32 i;
52495 +
52496 + if (subj_map_set.s_hash) {
52497 + for (i = 0; i < subj_map_set.s_size; i++) {
52498 + if (subj_map_set.s_hash[i]) {
52499 + kfree(subj_map_set.s_hash[i]);
52500 + subj_map_set.s_hash[i] = NULL;
52501 + }
52502 + }
52503 +
52504 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52505 + PAGE_SIZE)
52506 + kfree(subj_map_set.s_hash);
52507 + else
52508 + vfree(subj_map_set.s_hash);
52509 + }
52510 +
52511 + return;
52512 +}
52513 +
52514 +static void
52515 +free_variables(void)
52516 +{
52517 + struct acl_subject_label *s;
52518 + struct acl_role_label *r;
52519 + struct task_struct *task, *task2;
52520 + unsigned int x;
52521 +
52522 + gr_clear_learn_entries();
52523 +
52524 + read_lock(&tasklist_lock);
52525 + do_each_thread(task2, task) {
52526 + task->acl_sp_role = 0;
52527 + task->acl_role_id = 0;
52528 + task->acl = NULL;
52529 + task->role = NULL;
52530 + } while_each_thread(task2, task);
52531 + read_unlock(&tasklist_lock);
52532 +
52533 + /* release the reference to the real root dentry and vfsmount */
52534 + path_put(&real_root);
52535 + memset(&real_root, 0, sizeof(real_root));
52536 +
52537 + /* free all object hash tables */
52538 +
52539 + FOR_EACH_ROLE_START(r)
52540 + if (r->subj_hash == NULL)
52541 + goto next_role;
52542 + FOR_EACH_SUBJECT_START(r, s, x)
52543 + if (s->obj_hash == NULL)
52544 + break;
52545 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52546 + kfree(s->obj_hash);
52547 + else
52548 + vfree(s->obj_hash);
52549 + FOR_EACH_SUBJECT_END(s, x)
52550 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52551 + if (s->obj_hash == NULL)
52552 + break;
52553 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52554 + kfree(s->obj_hash);
52555 + else
52556 + vfree(s->obj_hash);
52557 + FOR_EACH_NESTED_SUBJECT_END(s)
52558 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52559 + kfree(r->subj_hash);
52560 + else
52561 + vfree(r->subj_hash);
52562 + r->subj_hash = NULL;
52563 +next_role:
52564 + FOR_EACH_ROLE_END(r)
52565 +
52566 + acl_free_all();
52567 +
52568 + if (acl_role_set.r_hash) {
52569 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52570 + PAGE_SIZE)
52571 + kfree(acl_role_set.r_hash);
52572 + else
52573 + vfree(acl_role_set.r_hash);
52574 + }
52575 + if (name_set.n_hash) {
52576 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52577 + PAGE_SIZE)
52578 + kfree(name_set.n_hash);
52579 + else
52580 + vfree(name_set.n_hash);
52581 + }
52582 +
52583 + if (inodev_set.i_hash) {
52584 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52585 + PAGE_SIZE)
52586 + kfree(inodev_set.i_hash);
52587 + else
52588 + vfree(inodev_set.i_hash);
52589 + }
52590 +
52591 + gr_free_uidset();
52592 +
52593 + memset(&name_set, 0, sizeof (struct name_db));
52594 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52595 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52596 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52597 +
52598 + default_role = NULL;
52599 + kernel_role = NULL;
52600 + role_list = NULL;
52601 +
52602 + return;
52603 +}
52604 +
52605 +static __u32
52606 +count_user_objs(struct acl_object_label *userp)
52607 +{
52608 + struct acl_object_label o_tmp;
52609 + __u32 num = 0;
52610 +
52611 + while (userp) {
52612 + if (copy_from_user(&o_tmp, userp,
52613 + sizeof (struct acl_object_label)))
52614 + break;
52615 +
52616 + userp = o_tmp.prev;
52617 + num++;
52618 + }
52619 +
52620 + return num;
52621 +}
52622 +
52623 +static struct acl_subject_label *
52624 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52625 +
52626 +static int
52627 +copy_user_glob(struct acl_object_label *obj)
52628 +{
52629 + struct acl_object_label *g_tmp, **guser;
52630 + unsigned int len;
52631 + char *tmp;
52632 +
52633 + if (obj->globbed == NULL)
52634 + return 0;
52635 +
52636 + guser = &obj->globbed;
52637 + while (*guser) {
52638 + g_tmp = (struct acl_object_label *)
52639 + acl_alloc(sizeof (struct acl_object_label));
52640 + if (g_tmp == NULL)
52641 + return -ENOMEM;
52642 +
52643 + if (copy_from_user(g_tmp, *guser,
52644 + sizeof (struct acl_object_label)))
52645 + return -EFAULT;
52646 +
52647 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52648 +
52649 + if (!len || len >= PATH_MAX)
52650 + return -EINVAL;
52651 +
52652 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52653 + return -ENOMEM;
52654 +
52655 + if (copy_from_user(tmp, g_tmp->filename, len))
52656 + return -EFAULT;
52657 + tmp[len-1] = '\0';
52658 + g_tmp->filename = tmp;
52659 +
52660 + *guser = g_tmp;
52661 + guser = &(g_tmp->next);
52662 + }
52663 +
52664 + return 0;
52665 +}
52666 +
52667 +static int
52668 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52669 + struct acl_role_label *role)
52670 +{
52671 + struct acl_object_label *o_tmp;
52672 + unsigned int len;
52673 + int ret;
52674 + char *tmp;
52675 +
52676 + while (userp) {
52677 + if ((o_tmp = (struct acl_object_label *)
52678 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52679 + return -ENOMEM;
52680 +
52681 + if (copy_from_user(o_tmp, userp,
52682 + sizeof (struct acl_object_label)))
52683 + return -EFAULT;
52684 +
52685 + userp = o_tmp->prev;
52686 +
52687 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52688 +
52689 + if (!len || len >= PATH_MAX)
52690 + return -EINVAL;
52691 +
52692 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52693 + return -ENOMEM;
52694 +
52695 + if (copy_from_user(tmp, o_tmp->filename, len))
52696 + return -EFAULT;
52697 + tmp[len-1] = '\0';
52698 + o_tmp->filename = tmp;
52699 +
52700 + insert_acl_obj_label(o_tmp, subj);
52701 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52702 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52703 + return -ENOMEM;
52704 +
52705 + ret = copy_user_glob(o_tmp);
52706 + if (ret)
52707 + return ret;
52708 +
52709 + if (o_tmp->nested) {
52710 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52711 + if (IS_ERR(o_tmp->nested))
52712 + return PTR_ERR(o_tmp->nested);
52713 +
52714 + /* insert into nested subject list */
52715 + o_tmp->nested->next = role->hash->first;
52716 + role->hash->first = o_tmp->nested;
52717 + }
52718 + }
52719 +
52720 + return 0;
52721 +}
52722 +
52723 +static __u32
52724 +count_user_subjs(struct acl_subject_label *userp)
52725 +{
52726 + struct acl_subject_label s_tmp;
52727 + __u32 num = 0;
52728 +
52729 + while (userp) {
52730 + if (copy_from_user(&s_tmp, userp,
52731 + sizeof (struct acl_subject_label)))
52732 + break;
52733 +
52734 + userp = s_tmp.prev;
52735 + /* do not count nested subjects against this count, since
52736 + they are not included in the hash table, but are
52737 + attached to objects. We have already counted
52738 + the subjects in userspace for the allocation
52739 + stack
52740 + */
52741 + if (!(s_tmp.mode & GR_NESTED))
52742 + num++;
52743 + }
52744 +
52745 + return num;
52746 +}
52747 +
52748 +static int
52749 +copy_user_allowedips(struct acl_role_label *rolep)
52750 +{
52751 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52752 +
52753 + ruserip = rolep->allowed_ips;
52754 +
52755 + while (ruserip) {
52756 + rlast = rtmp;
52757 +
52758 + if ((rtmp = (struct role_allowed_ip *)
52759 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52760 + return -ENOMEM;
52761 +
52762 + if (copy_from_user(rtmp, ruserip,
52763 + sizeof (struct role_allowed_ip)))
52764 + return -EFAULT;
52765 +
52766 + ruserip = rtmp->prev;
52767 +
52768 + if (!rlast) {
52769 + rtmp->prev = NULL;
52770 + rolep->allowed_ips = rtmp;
52771 + } else {
52772 + rlast->next = rtmp;
52773 + rtmp->prev = rlast;
52774 + }
52775 +
52776 + if (!ruserip)
52777 + rtmp->next = NULL;
52778 + }
52779 +
52780 + return 0;
52781 +}
52782 +
52783 +static int
52784 +copy_user_transitions(struct acl_role_label *rolep)
52785 +{
52786 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52787 +
52788 + unsigned int len;
52789 + char *tmp;
52790 +
52791 + rusertp = rolep->transitions;
52792 +
52793 + while (rusertp) {
52794 + rlast = rtmp;
52795 +
52796 + if ((rtmp = (struct role_transition *)
52797 + acl_alloc(sizeof (struct role_transition))) == NULL)
52798 + return -ENOMEM;
52799 +
52800 + if (copy_from_user(rtmp, rusertp,
52801 + sizeof (struct role_transition)))
52802 + return -EFAULT;
52803 +
52804 + rusertp = rtmp->prev;
52805 +
52806 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52807 +
52808 + if (!len || len >= GR_SPROLE_LEN)
52809 + return -EINVAL;
52810 +
52811 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52812 + return -ENOMEM;
52813 +
52814 + if (copy_from_user(tmp, rtmp->rolename, len))
52815 + return -EFAULT;
52816 + tmp[len-1] = '\0';
52817 + rtmp->rolename = tmp;
52818 +
52819 + if (!rlast) {
52820 + rtmp->prev = NULL;
52821 + rolep->transitions = rtmp;
52822 + } else {
52823 + rlast->next = rtmp;
52824 + rtmp->prev = rlast;
52825 + }
52826 +
52827 + if (!rusertp)
52828 + rtmp->next = NULL;
52829 + }
52830 +
52831 + return 0;
52832 +}
52833 +
52834 +static struct acl_subject_label *
52835 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52836 +{
52837 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52838 + unsigned int len;
52839 + char *tmp;
52840 + __u32 num_objs;
52841 + struct acl_ip_label **i_tmp, *i_utmp2;
52842 + struct gr_hash_struct ghash;
52843 + struct subject_map *subjmap;
52844 + unsigned int i_num;
52845 + int err;
52846 +
52847 + s_tmp = lookup_subject_map(userp);
52848 +
52849 + /* we've already copied this subject into the kernel, just return
52850 + the reference to it, and don't copy it over again
52851 + */
52852 + if (s_tmp)
52853 + return(s_tmp);
52854 +
52855 + if ((s_tmp = (struct acl_subject_label *)
52856 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52857 + return ERR_PTR(-ENOMEM);
52858 +
52859 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52860 + if (subjmap == NULL)
52861 + return ERR_PTR(-ENOMEM);
52862 +
52863 + subjmap->user = userp;
52864 + subjmap->kernel = s_tmp;
52865 + insert_subj_map_entry(subjmap);
52866 +
52867 + if (copy_from_user(s_tmp, userp,
52868 + sizeof (struct acl_subject_label)))
52869 + return ERR_PTR(-EFAULT);
52870 +
52871 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52872 +
52873 + if (!len || len >= PATH_MAX)
52874 + return ERR_PTR(-EINVAL);
52875 +
52876 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52877 + return ERR_PTR(-ENOMEM);
52878 +
52879 + if (copy_from_user(tmp, s_tmp->filename, len))
52880 + return ERR_PTR(-EFAULT);
52881 + tmp[len-1] = '\0';
52882 + s_tmp->filename = tmp;
52883 +
52884 + if (!strcmp(s_tmp->filename, "/"))
52885 + role->root_label = s_tmp;
52886 +
52887 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52888 + return ERR_PTR(-EFAULT);
52889 +
52890 + /* copy user and group transition tables */
52891 +
52892 + if (s_tmp->user_trans_num) {
52893 + uid_t *uidlist;
52894 +
52895 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52896 + if (uidlist == NULL)
52897 + return ERR_PTR(-ENOMEM);
52898 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52899 + return ERR_PTR(-EFAULT);
52900 +
52901 + s_tmp->user_transitions = uidlist;
52902 + }
52903 +
52904 + if (s_tmp->group_trans_num) {
52905 + gid_t *gidlist;
52906 +
52907 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52908 + if (gidlist == NULL)
52909 + return ERR_PTR(-ENOMEM);
52910 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52911 + return ERR_PTR(-EFAULT);
52912 +
52913 + s_tmp->group_transitions = gidlist;
52914 + }
52915 +
52916 + /* set up object hash table */
52917 + num_objs = count_user_objs(ghash.first);
52918 +
52919 + s_tmp->obj_hash_size = num_objs;
52920 + s_tmp->obj_hash =
52921 + (struct acl_object_label **)
52922 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52923 +
52924 + if (!s_tmp->obj_hash)
52925 + return ERR_PTR(-ENOMEM);
52926 +
52927 + memset(s_tmp->obj_hash, 0,
52928 + s_tmp->obj_hash_size *
52929 + sizeof (struct acl_object_label *));
52930 +
52931 + /* add in objects */
52932 + err = copy_user_objs(ghash.first, s_tmp, role);
52933 +
52934 + if (err)
52935 + return ERR_PTR(err);
52936 +
52937 + /* set pointer for parent subject */
52938 + if (s_tmp->parent_subject) {
52939 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52940 +
52941 + if (IS_ERR(s_tmp2))
52942 + return s_tmp2;
52943 +
52944 + s_tmp->parent_subject = s_tmp2;
52945 + }
52946 +
52947 + /* add in ip acls */
52948 +
52949 + if (!s_tmp->ip_num) {
52950 + s_tmp->ips = NULL;
52951 + goto insert;
52952 + }
52953 +
52954 + i_tmp =
52955 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52956 + sizeof (struct acl_ip_label *));
52957 +
52958 + if (!i_tmp)
52959 + return ERR_PTR(-ENOMEM);
52960 +
52961 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52962 + *(i_tmp + i_num) =
52963 + (struct acl_ip_label *)
52964 + acl_alloc(sizeof (struct acl_ip_label));
52965 + if (!*(i_tmp + i_num))
52966 + return ERR_PTR(-ENOMEM);
52967 +
52968 + if (copy_from_user
52969 + (&i_utmp2, s_tmp->ips + i_num,
52970 + sizeof (struct acl_ip_label *)))
52971 + return ERR_PTR(-EFAULT);
52972 +
52973 + if (copy_from_user
52974 + (*(i_tmp + i_num), i_utmp2,
52975 + sizeof (struct acl_ip_label)))
52976 + return ERR_PTR(-EFAULT);
52977 +
52978 + if ((*(i_tmp + i_num))->iface == NULL)
52979 + continue;
52980 +
52981 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52982 + if (!len || len >= IFNAMSIZ)
52983 + return ERR_PTR(-EINVAL);
52984 + tmp = acl_alloc(len);
52985 + if (tmp == NULL)
52986 + return ERR_PTR(-ENOMEM);
52987 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52988 + return ERR_PTR(-EFAULT);
52989 + (*(i_tmp + i_num))->iface = tmp;
52990 + }
52991 +
52992 + s_tmp->ips = i_tmp;
52993 +
52994 +insert:
52995 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52996 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52997 + return ERR_PTR(-ENOMEM);
52998 +
52999 + return s_tmp;
53000 +}
53001 +
53002 +static int
53003 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53004 +{
53005 + struct acl_subject_label s_pre;
53006 + struct acl_subject_label * ret;
53007 + int err;
53008 +
53009 + while (userp) {
53010 + if (copy_from_user(&s_pre, userp,
53011 + sizeof (struct acl_subject_label)))
53012 + return -EFAULT;
53013 +
53014 + /* do not add nested subjects here, add
53015 + while parsing objects
53016 + */
53017 +
53018 + if (s_pre.mode & GR_NESTED) {
53019 + userp = s_pre.prev;
53020 + continue;
53021 + }
53022 +
53023 + ret = do_copy_user_subj(userp, role);
53024 +
53025 + err = PTR_ERR(ret);
53026 + if (IS_ERR(ret))
53027 + return err;
53028 +
53029 + insert_acl_subj_label(ret, role);
53030 +
53031 + userp = s_pre.prev;
53032 + }
53033 +
53034 + return 0;
53035 +}
53036 +
53037 +static int
53038 +copy_user_acl(struct gr_arg *arg)
53039 +{
53040 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53041 + struct acl_subject_label *subj_list;
53042 + struct sprole_pw *sptmp;
53043 + struct gr_hash_struct *ghash;
53044 + uid_t *domainlist;
53045 + unsigned int r_num;
53046 + unsigned int len;
53047 + char *tmp;
53048 + int err = 0;
53049 + __u16 i;
53050 + __u32 num_subjs;
53051 +
53052 + /* we need a default and kernel role */
53053 + if (arg->role_db.num_roles < 2)
53054 + return -EINVAL;
53055 +
53056 + /* copy special role authentication info from userspace */
53057 +
53058 + num_sprole_pws = arg->num_sprole_pws;
53059 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53060 +
53061 + if (!acl_special_roles && num_sprole_pws)
53062 + return -ENOMEM;
53063 +
53064 + for (i = 0; i < num_sprole_pws; i++) {
53065 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53066 + if (!sptmp)
53067 + return -ENOMEM;
53068 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53069 + sizeof (struct sprole_pw)))
53070 + return -EFAULT;
53071 +
53072 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53073 +
53074 + if (!len || len >= GR_SPROLE_LEN)
53075 + return -EINVAL;
53076 +
53077 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53078 + return -ENOMEM;
53079 +
53080 + if (copy_from_user(tmp, sptmp->rolename, len))
53081 + return -EFAULT;
53082 +
53083 + tmp[len-1] = '\0';
53084 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53085 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53086 +#endif
53087 + sptmp->rolename = tmp;
53088 + acl_special_roles[i] = sptmp;
53089 + }
53090 +
53091 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53092 +
53093 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53094 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53095 +
53096 + if (!r_tmp)
53097 + return -ENOMEM;
53098 +
53099 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53100 + sizeof (struct acl_role_label *)))
53101 + return -EFAULT;
53102 +
53103 + if (copy_from_user(r_tmp, r_utmp2,
53104 + sizeof (struct acl_role_label)))
53105 + return -EFAULT;
53106 +
53107 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53108 +
53109 + if (!len || len >= PATH_MAX)
53110 + return -EINVAL;
53111 +
53112 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53113 + return -ENOMEM;
53114 +
53115 + if (copy_from_user(tmp, r_tmp->rolename, len))
53116 + return -EFAULT;
53117 +
53118 + tmp[len-1] = '\0';
53119 + r_tmp->rolename = tmp;
53120 +
53121 + if (!strcmp(r_tmp->rolename, "default")
53122 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53123 + default_role = r_tmp;
53124 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53125 + kernel_role = r_tmp;
53126 + }
53127 +
53128 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53129 + return -ENOMEM;
53130 +
53131 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53132 + return -EFAULT;
53133 +
53134 + r_tmp->hash = ghash;
53135 +
53136 + num_subjs = count_user_subjs(r_tmp->hash->first);
53137 +
53138 + r_tmp->subj_hash_size = num_subjs;
53139 + r_tmp->subj_hash =
53140 + (struct acl_subject_label **)
53141 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53142 +
53143 + if (!r_tmp->subj_hash)
53144 + return -ENOMEM;
53145 +
53146 + err = copy_user_allowedips(r_tmp);
53147 + if (err)
53148 + return err;
53149 +
53150 + /* copy domain info */
53151 + if (r_tmp->domain_children != NULL) {
53152 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53153 + if (domainlist == NULL)
53154 + return -ENOMEM;
53155 +
53156 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53157 + return -EFAULT;
53158 +
53159 + r_tmp->domain_children = domainlist;
53160 + }
53161 +
53162 + err = copy_user_transitions(r_tmp);
53163 + if (err)
53164 + return err;
53165 +
53166 + memset(r_tmp->subj_hash, 0,
53167 + r_tmp->subj_hash_size *
53168 + sizeof (struct acl_subject_label *));
53169 +
53170 + /* acquire the list of subjects, then NULL out
53171 + the list prior to parsing the subjects for this role,
53172 + as during this parsing the list is replaced with a list
53173 + of *nested* subjects for the role
53174 + */
53175 + subj_list = r_tmp->hash->first;
53176 +
53177 + /* set nested subject list to null */
53178 + r_tmp->hash->first = NULL;
53179 +
53180 + err = copy_user_subjs(subj_list, r_tmp);
53181 +
53182 + if (err)
53183 + return err;
53184 +
53185 + insert_acl_role_label(r_tmp);
53186 + }
53187 +
53188 + if (default_role == NULL || kernel_role == NULL)
53189 + return -EINVAL;
53190 +
53191 + return err;
53192 +}
53193 +
53194 +static int
53195 +gracl_init(struct gr_arg *args)
53196 +{
53197 + int error = 0;
53198 +
53199 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53200 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53201 +
53202 + if (init_variables(args)) {
53203 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53204 + error = -ENOMEM;
53205 + free_variables();
53206 + goto out;
53207 + }
53208 +
53209 + error = copy_user_acl(args);
53210 + free_init_variables();
53211 + if (error) {
53212 + free_variables();
53213 + goto out;
53214 + }
53215 +
53216 + if ((error = gr_set_acls(0))) {
53217 + free_variables();
53218 + goto out;
53219 + }
53220 +
53221 + pax_open_kernel();
53222 + gr_status |= GR_READY;
53223 + pax_close_kernel();
53224 +
53225 + out:
53226 + return error;
53227 +}
53228 +
53229 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53230 +
53231 +static int
53232 +glob_match(const char *p, const char *n)
53233 +{
53234 + char c;
53235 +
53236 + while ((c = *p++) != '\0') {
53237 + switch (c) {
53238 + case '?':
53239 + if (*n == '\0')
53240 + return 1;
53241 + else if (*n == '/')
53242 + return 1;
53243 + break;
53244 + case '\\':
53245 + if (*n != c)
53246 + return 1;
53247 + break;
53248 + case '*':
53249 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53250 + if (*n == '/')
53251 + return 1;
53252 + else if (c == '?') {
53253 + if (*n == '\0')
53254 + return 1;
53255 + else
53256 + ++n;
53257 + }
53258 + }
53259 + if (c == '\0') {
53260 + return 0;
53261 + } else {
53262 + const char *endp;
53263 +
53264 + if ((endp = strchr(n, '/')) == NULL)
53265 + endp = n + strlen(n);
53266 +
53267 + if (c == '[') {
53268 + for (--p; n < endp; ++n)
53269 + if (!glob_match(p, n))
53270 + return 0;
53271 + } else if (c == '/') {
53272 + while (*n != '\0' && *n != '/')
53273 + ++n;
53274 + if (*n == '/' && !glob_match(p, n + 1))
53275 + return 0;
53276 + } else {
53277 + for (--p; n < endp; ++n)
53278 + if (*n == c && !glob_match(p, n))
53279 + return 0;
53280 + }
53281 +
53282 + return 1;
53283 + }
53284 + case '[':
53285 + {
53286 + int not;
53287 + char cold;
53288 +
53289 + if (*n == '\0' || *n == '/')
53290 + return 1;
53291 +
53292 + not = (*p == '!' || *p == '^');
53293 + if (not)
53294 + ++p;
53295 +
53296 + c = *p++;
53297 + for (;;) {
53298 + unsigned char fn = (unsigned char)*n;
53299 +
53300 + if (c == '\0')
53301 + return 1;
53302 + else {
53303 + if (c == fn)
53304 + goto matched;
53305 + cold = c;
53306 + c = *p++;
53307 +
53308 + if (c == '-' && *p != ']') {
53309 + unsigned char cend = *p++;
53310 +
53311 + if (cend == '\0')
53312 + return 1;
53313 +
53314 + if (cold <= fn && fn <= cend)
53315 + goto matched;
53316 +
53317 + c = *p++;
53318 + }
53319 + }
53320 +
53321 + if (c == ']')
53322 + break;
53323 + }
53324 + if (!not)
53325 + return 1;
53326 + break;
53327 + matched:
53328 + while (c != ']') {
53329 + if (c == '\0')
53330 + return 1;
53331 +
53332 + c = *p++;
53333 + }
53334 + if (not)
53335 + return 1;
53336 + }
53337 + break;
53338 + default:
53339 + if (c != *n)
53340 + return 1;
53341 + }
53342 +
53343 + ++n;
53344 + }
53345 +
53346 + if (*n == '\0')
53347 + return 0;
53348 +
53349 + if (*n == '/')
53350 + return 0;
53351 +
53352 + return 1;
53353 +}
53354 +
53355 +static struct acl_object_label *
53356 +chk_glob_label(struct acl_object_label *globbed,
53357 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53358 +{
53359 + struct acl_object_label *tmp;
53360 +
53361 + if (*path == NULL)
53362 + *path = gr_to_filename_nolock(dentry, mnt);
53363 +
53364 + tmp = globbed;
53365 +
53366 + while (tmp) {
53367 + if (!glob_match(tmp->filename, *path))
53368 + return tmp;
53369 + tmp = tmp->next;
53370 + }
53371 +
53372 + return NULL;
53373 +}
53374 +
53375 +static struct acl_object_label *
53376 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53377 + const ino_t curr_ino, const dev_t curr_dev,
53378 + const struct acl_subject_label *subj, char **path, const int checkglob)
53379 +{
53380 + struct acl_subject_label *tmpsubj;
53381 + struct acl_object_label *retval;
53382 + struct acl_object_label *retval2;
53383 +
53384 + tmpsubj = (struct acl_subject_label *) subj;
53385 + read_lock(&gr_inode_lock);
53386 + do {
53387 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53388 + if (retval) {
53389 + if (checkglob && retval->globbed) {
53390 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53391 + if (retval2)
53392 + retval = retval2;
53393 + }
53394 + break;
53395 + }
53396 + } while ((tmpsubj = tmpsubj->parent_subject));
53397 + read_unlock(&gr_inode_lock);
53398 +
53399 + return retval;
53400 +}
53401 +
53402 +static __inline__ struct acl_object_label *
53403 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53404 + struct dentry *curr_dentry,
53405 + const struct acl_subject_label *subj, char **path, const int checkglob)
53406 +{
53407 + int newglob = checkglob;
53408 + ino_t inode;
53409 + dev_t device;
53410 +
53411 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53412 + as we don't want a / * rule to match instead of the / object
53413 + don't do this for create lookups that call this function though, since they're looking up
53414 + on the parent and thus need globbing checks on all paths
53415 + */
53416 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53417 + newglob = GR_NO_GLOB;
53418 +
53419 + spin_lock(&curr_dentry->d_lock);
53420 + inode = curr_dentry->d_inode->i_ino;
53421 + device = __get_dev(curr_dentry);
53422 + spin_unlock(&curr_dentry->d_lock);
53423 +
53424 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53425 +}
53426 +
53427 +static struct acl_object_label *
53428 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53429 + const struct acl_subject_label *subj, char *path, const int checkglob)
53430 +{
53431 + struct dentry *dentry = (struct dentry *) l_dentry;
53432 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53433 + struct mount *real_mnt = real_mount(mnt);
53434 + struct acl_object_label *retval;
53435 + struct dentry *parent;
53436 +
53437 + write_seqlock(&rename_lock);
53438 + br_read_lock(&vfsmount_lock);
53439 +
53440 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53441 +#ifdef CONFIG_NET
53442 + mnt == sock_mnt ||
53443 +#endif
53444 +#ifdef CONFIG_HUGETLBFS
53445 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53446 +#endif
53447 + /* ignore Eric Biederman */
53448 + IS_PRIVATE(l_dentry->d_inode))) {
53449 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53450 + goto out;
53451 + }
53452 +
53453 + for (;;) {
53454 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53455 + break;
53456 +
53457 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53458 + if (!mnt_has_parent(real_mnt))
53459 + break;
53460 +
53461 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53462 + if (retval != NULL)
53463 + goto out;
53464 +
53465 + dentry = real_mnt->mnt_mountpoint;
53466 + real_mnt = real_mnt->mnt_parent;
53467 + mnt = &real_mnt->mnt;
53468 + continue;
53469 + }
53470 +
53471 + parent = dentry->d_parent;
53472 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53473 + if (retval != NULL)
53474 + goto out;
53475 +
53476 + dentry = parent;
53477 + }
53478 +
53479 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53480 +
53481 + /* real_root is pinned so we don't have to hold a reference */
53482 + if (retval == NULL)
53483 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53484 +out:
53485 + br_read_unlock(&vfsmount_lock);
53486 + write_sequnlock(&rename_lock);
53487 +
53488 + BUG_ON(retval == NULL);
53489 +
53490 + return retval;
53491 +}
53492 +
53493 +static __inline__ struct acl_object_label *
53494 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53495 + const struct acl_subject_label *subj)
53496 +{
53497 + char *path = NULL;
53498 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53499 +}
53500 +
53501 +static __inline__ struct acl_object_label *
53502 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53503 + const struct acl_subject_label *subj)
53504 +{
53505 + char *path = NULL;
53506 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53507 +}
53508 +
53509 +static __inline__ struct acl_object_label *
53510 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53511 + const struct acl_subject_label *subj, char *path)
53512 +{
53513 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53514 +}
53515 +
53516 +static struct acl_subject_label *
53517 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53518 + const struct acl_role_label *role)
53519 +{
53520 + struct dentry *dentry = (struct dentry *) l_dentry;
53521 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53522 + struct mount *real_mnt = real_mount(mnt);
53523 + struct acl_subject_label *retval;
53524 + struct dentry *parent;
53525 +
53526 + write_seqlock(&rename_lock);
53527 + br_read_lock(&vfsmount_lock);
53528 +
53529 + for (;;) {
53530 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53531 + break;
53532 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53533 + if (!mnt_has_parent(real_mnt))
53534 + break;
53535 +
53536 + spin_lock(&dentry->d_lock);
53537 + read_lock(&gr_inode_lock);
53538 + retval =
53539 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53540 + __get_dev(dentry), role);
53541 + read_unlock(&gr_inode_lock);
53542 + spin_unlock(&dentry->d_lock);
53543 + if (retval != NULL)
53544 + goto out;
53545 +
53546 + dentry = real_mnt->mnt_mountpoint;
53547 + real_mnt = real_mnt->mnt_parent;
53548 + mnt = &real_mnt->mnt;
53549 + continue;
53550 + }
53551 +
53552 + spin_lock(&dentry->d_lock);
53553 + read_lock(&gr_inode_lock);
53554 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53555 + __get_dev(dentry), role);
53556 + read_unlock(&gr_inode_lock);
53557 + parent = dentry->d_parent;
53558 + spin_unlock(&dentry->d_lock);
53559 +
53560 + if (retval != NULL)
53561 + goto out;
53562 +
53563 + dentry = parent;
53564 + }
53565 +
53566 + spin_lock(&dentry->d_lock);
53567 + read_lock(&gr_inode_lock);
53568 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53569 + __get_dev(dentry), role);
53570 + read_unlock(&gr_inode_lock);
53571 + spin_unlock(&dentry->d_lock);
53572 +
53573 + if (unlikely(retval == NULL)) {
53574 + /* real_root is pinned, we don't need to hold a reference */
53575 + read_lock(&gr_inode_lock);
53576 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53577 + __get_dev(real_root.dentry), role);
53578 + read_unlock(&gr_inode_lock);
53579 + }
53580 +out:
53581 + br_read_unlock(&vfsmount_lock);
53582 + write_sequnlock(&rename_lock);
53583 +
53584 + BUG_ON(retval == NULL);
53585 +
53586 + return retval;
53587 +}
53588 +
53589 +static void
53590 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53591 +{
53592 + struct task_struct *task = current;
53593 + const struct cred *cred = current_cred();
53594 +
53595 + security_learn(GR_LEARN_AUDIT_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 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53599 +
53600 + return;
53601 +}
53602 +
53603 +static void
53604 +gr_log_learn_id_change(const char type, const unsigned int real,
53605 + const unsigned int effective, const unsigned int fs)
53606 +{
53607 + struct task_struct *task = current;
53608 + const struct cred *cred = current_cred();
53609 +
53610 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53611 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53612 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53613 + type, real, effective, fs, &task->signal->saved_ip);
53614 +
53615 + return;
53616 +}
53617 +
53618 +__u32
53619 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53620 + const struct vfsmount * mnt)
53621 +{
53622 + __u32 retval = mode;
53623 + struct acl_subject_label *curracl;
53624 + struct acl_object_label *currobj;
53625 +
53626 + if (unlikely(!(gr_status & GR_READY)))
53627 + return (mode & ~GR_AUDITS);
53628 +
53629 + curracl = current->acl;
53630 +
53631 + currobj = chk_obj_label(dentry, mnt, curracl);
53632 + retval = currobj->mode & mode;
53633 +
53634 + /* if we're opening a specified transfer file for writing
53635 + (e.g. /dev/initctl), then transfer our role to init
53636 + */
53637 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53638 + current->role->roletype & GR_ROLE_PERSIST)) {
53639 + struct task_struct *task = init_pid_ns.child_reaper;
53640 +
53641 + if (task->role != current->role) {
53642 + task->acl_sp_role = 0;
53643 + task->acl_role_id = current->acl_role_id;
53644 + task->role = current->role;
53645 + rcu_read_lock();
53646 + read_lock(&grsec_exec_file_lock);
53647 + gr_apply_subject_to_task(task);
53648 + read_unlock(&grsec_exec_file_lock);
53649 + rcu_read_unlock();
53650 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53651 + }
53652 + }
53653 +
53654 + if (unlikely
53655 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53656 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53657 + __u32 new_mode = mode;
53658 +
53659 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53660 +
53661 + retval = new_mode;
53662 +
53663 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53664 + new_mode |= GR_INHERIT;
53665 +
53666 + if (!(mode & GR_NOLEARN))
53667 + gr_log_learn(dentry, mnt, new_mode);
53668 + }
53669 +
53670 + return retval;
53671 +}
53672 +
53673 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53674 + const struct dentry *parent,
53675 + const struct vfsmount *mnt)
53676 +{
53677 + struct name_entry *match;
53678 + struct acl_object_label *matchpo;
53679 + struct acl_subject_label *curracl;
53680 + char *path;
53681 +
53682 + if (unlikely(!(gr_status & GR_READY)))
53683 + return NULL;
53684 +
53685 + preempt_disable();
53686 + path = gr_to_filename_rbac(new_dentry, mnt);
53687 + match = lookup_name_entry_create(path);
53688 +
53689 + curracl = current->acl;
53690 +
53691 + if (match) {
53692 + read_lock(&gr_inode_lock);
53693 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53694 + read_unlock(&gr_inode_lock);
53695 +
53696 + if (matchpo) {
53697 + preempt_enable();
53698 + return matchpo;
53699 + }
53700 + }
53701 +
53702 + // lookup parent
53703 +
53704 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53705 +
53706 + preempt_enable();
53707 + return matchpo;
53708 +}
53709 +
53710 +__u32
53711 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53712 + const struct vfsmount * mnt, const __u32 mode)
53713 +{
53714 + struct acl_object_label *matchpo;
53715 + __u32 retval;
53716 +
53717 + if (unlikely(!(gr_status & GR_READY)))
53718 + return (mode & ~GR_AUDITS);
53719 +
53720 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53721 +
53722 + retval = matchpo->mode & mode;
53723 +
53724 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53725 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53726 + __u32 new_mode = mode;
53727 +
53728 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53729 +
53730 + gr_log_learn(new_dentry, mnt, new_mode);
53731 + return new_mode;
53732 + }
53733 +
53734 + return retval;
53735 +}
53736 +
53737 +__u32
53738 +gr_check_link(const struct dentry * new_dentry,
53739 + const struct dentry * parent_dentry,
53740 + const struct vfsmount * parent_mnt,
53741 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53742 +{
53743 + struct acl_object_label *obj;
53744 + __u32 oldmode, newmode;
53745 + __u32 needmode;
53746 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53747 + GR_DELETE | GR_INHERIT;
53748 +
53749 + if (unlikely(!(gr_status & GR_READY)))
53750 + return (GR_CREATE | GR_LINK);
53751 +
53752 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53753 + oldmode = obj->mode;
53754 +
53755 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53756 + newmode = obj->mode;
53757 +
53758 + needmode = newmode & checkmodes;
53759 +
53760 + // old name for hardlink must have at least the permissions of the new name
53761 + if ((oldmode & needmode) != needmode)
53762 + goto bad;
53763 +
53764 + // if old name had restrictions/auditing, make sure the new name does as well
53765 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53766 +
53767 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53768 + if (is_privileged_binary(old_dentry))
53769 + needmode |= GR_SETID;
53770 +
53771 + if ((newmode & needmode) != needmode)
53772 + goto bad;
53773 +
53774 + // enforce minimum permissions
53775 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53776 + return newmode;
53777 +bad:
53778 + needmode = oldmode;
53779 + if (is_privileged_binary(old_dentry))
53780 + needmode |= GR_SETID;
53781 +
53782 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53783 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53784 + return (GR_CREATE | GR_LINK);
53785 + } else if (newmode & GR_SUPPRESS)
53786 + return GR_SUPPRESS;
53787 + else
53788 + return 0;
53789 +}
53790 +
53791 +int
53792 +gr_check_hidden_task(const struct task_struct *task)
53793 +{
53794 + if (unlikely(!(gr_status & GR_READY)))
53795 + return 0;
53796 +
53797 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53798 + return 1;
53799 +
53800 + return 0;
53801 +}
53802 +
53803 +int
53804 +gr_check_protected_task(const struct task_struct *task)
53805 +{
53806 + if (unlikely(!(gr_status & GR_READY) || !task))
53807 + return 0;
53808 +
53809 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53810 + task->acl != current->acl)
53811 + return 1;
53812 +
53813 + return 0;
53814 +}
53815 +
53816 +int
53817 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53818 +{
53819 + struct task_struct *p;
53820 + int ret = 0;
53821 +
53822 + if (unlikely(!(gr_status & GR_READY) || !pid))
53823 + return ret;
53824 +
53825 + read_lock(&tasklist_lock);
53826 + do_each_pid_task(pid, type, p) {
53827 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53828 + p->acl != current->acl) {
53829 + ret = 1;
53830 + goto out;
53831 + }
53832 + } while_each_pid_task(pid, type, p);
53833 +out:
53834 + read_unlock(&tasklist_lock);
53835 +
53836 + return ret;
53837 +}
53838 +
53839 +void
53840 +gr_copy_label(struct task_struct *tsk)
53841 +{
53842 + tsk->signal->used_accept = 0;
53843 + tsk->acl_sp_role = 0;
53844 + tsk->acl_role_id = current->acl_role_id;
53845 + tsk->acl = current->acl;
53846 + tsk->role = current->role;
53847 + tsk->signal->curr_ip = current->signal->curr_ip;
53848 + tsk->signal->saved_ip = current->signal->saved_ip;
53849 + if (current->exec_file)
53850 + get_file(current->exec_file);
53851 + tsk->exec_file = current->exec_file;
53852 + tsk->is_writable = current->is_writable;
53853 + if (unlikely(current->signal->used_accept)) {
53854 + current->signal->curr_ip = 0;
53855 + current->signal->saved_ip = 0;
53856 + }
53857 +
53858 + return;
53859 +}
53860 +
53861 +static void
53862 +gr_set_proc_res(struct task_struct *task)
53863 +{
53864 + struct acl_subject_label *proc;
53865 + unsigned short i;
53866 +
53867 + proc = task->acl;
53868 +
53869 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53870 + return;
53871 +
53872 + for (i = 0; i < RLIM_NLIMITS; i++) {
53873 + if (!(proc->resmask & (1 << i)))
53874 + continue;
53875 +
53876 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53877 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53878 + }
53879 +
53880 + return;
53881 +}
53882 +
53883 +extern int __gr_process_user_ban(struct user_struct *user);
53884 +
53885 +int
53886 +gr_check_user_change(int real, int effective, int fs)
53887 +{
53888 + unsigned int i;
53889 + __u16 num;
53890 + uid_t *uidlist;
53891 + int curuid;
53892 + int realok = 0;
53893 + int effectiveok = 0;
53894 + int fsok = 0;
53895 +
53896 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53897 + struct user_struct *user;
53898 +
53899 + if (real == -1)
53900 + goto skipit;
53901 +
53902 + user = find_user(real);
53903 + if (user == NULL)
53904 + goto skipit;
53905 +
53906 + if (__gr_process_user_ban(user)) {
53907 + /* for find_user */
53908 + free_uid(user);
53909 + return 1;
53910 + }
53911 +
53912 + /* for find_user */
53913 + free_uid(user);
53914 +
53915 +skipit:
53916 +#endif
53917 +
53918 + if (unlikely(!(gr_status & GR_READY)))
53919 + return 0;
53920 +
53921 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53922 + gr_log_learn_id_change('u', real, effective, fs);
53923 +
53924 + num = current->acl->user_trans_num;
53925 + uidlist = current->acl->user_transitions;
53926 +
53927 + if (uidlist == NULL)
53928 + return 0;
53929 +
53930 + if (real == -1)
53931 + realok = 1;
53932 + if (effective == -1)
53933 + effectiveok = 1;
53934 + if (fs == -1)
53935 + fsok = 1;
53936 +
53937 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53938 + for (i = 0; i < num; i++) {
53939 + curuid = (int)uidlist[i];
53940 + if (real == curuid)
53941 + realok = 1;
53942 + if (effective == curuid)
53943 + effectiveok = 1;
53944 + if (fs == curuid)
53945 + fsok = 1;
53946 + }
53947 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53948 + for (i = 0; i < num; i++) {
53949 + curuid = (int)uidlist[i];
53950 + if (real == curuid)
53951 + break;
53952 + if (effective == curuid)
53953 + break;
53954 + if (fs == curuid)
53955 + break;
53956 + }
53957 + /* not in deny list */
53958 + if (i == num) {
53959 + realok = 1;
53960 + effectiveok = 1;
53961 + fsok = 1;
53962 + }
53963 + }
53964 +
53965 + if (realok && effectiveok && fsok)
53966 + return 0;
53967 + else {
53968 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53969 + return 1;
53970 + }
53971 +}
53972 +
53973 +int
53974 +gr_check_group_change(int real, int effective, int fs)
53975 +{
53976 + unsigned int i;
53977 + __u16 num;
53978 + gid_t *gidlist;
53979 + int curgid;
53980 + int realok = 0;
53981 + int effectiveok = 0;
53982 + int fsok = 0;
53983 +
53984 + if (unlikely(!(gr_status & GR_READY)))
53985 + return 0;
53986 +
53987 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53988 + gr_log_learn_id_change('g', real, effective, fs);
53989 +
53990 + num = current->acl->group_trans_num;
53991 + gidlist = current->acl->group_transitions;
53992 +
53993 + if (gidlist == NULL)
53994 + return 0;
53995 +
53996 + if (real == -1)
53997 + realok = 1;
53998 + if (effective == -1)
53999 + effectiveok = 1;
54000 + if (fs == -1)
54001 + fsok = 1;
54002 +
54003 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54004 + for (i = 0; i < num; i++) {
54005 + curgid = (int)gidlist[i];
54006 + if (real == curgid)
54007 + realok = 1;
54008 + if (effective == curgid)
54009 + effectiveok = 1;
54010 + if (fs == curgid)
54011 + fsok = 1;
54012 + }
54013 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54014 + for (i = 0; i < num; i++) {
54015 + curgid = (int)gidlist[i];
54016 + if (real == curgid)
54017 + break;
54018 + if (effective == curgid)
54019 + break;
54020 + if (fs == curgid)
54021 + break;
54022 + }
54023 + /* not in deny list */
54024 + if (i == num) {
54025 + realok = 1;
54026 + effectiveok = 1;
54027 + fsok = 1;
54028 + }
54029 + }
54030 +
54031 + if (realok && effectiveok && fsok)
54032 + return 0;
54033 + else {
54034 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54035 + return 1;
54036 + }
54037 +}
54038 +
54039 +extern int gr_acl_is_capable(const int cap);
54040 +
54041 +void
54042 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54043 +{
54044 + struct acl_role_label *role = task->role;
54045 + struct acl_subject_label *subj = NULL;
54046 + struct acl_object_label *obj;
54047 + struct file *filp;
54048 +
54049 + if (unlikely(!(gr_status & GR_READY)))
54050 + return;
54051 +
54052 + filp = task->exec_file;
54053 +
54054 + /* kernel process, we'll give them the kernel role */
54055 + if (unlikely(!filp)) {
54056 + task->role = kernel_role;
54057 + task->acl = kernel_role->root_label;
54058 + return;
54059 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54060 + role = lookup_acl_role_label(task, uid, gid);
54061 +
54062 + /* don't change the role if we're not a privileged process */
54063 + if (role && task->role != role &&
54064 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54065 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54066 + return;
54067 +
54068 + /* perform subject lookup in possibly new role
54069 + we can use this result below in the case where role == task->role
54070 + */
54071 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54072 +
54073 + /* if we changed uid/gid, but result in the same role
54074 + and are using inheritance, don't lose the inherited subject
54075 + if current subject is other than what normal lookup
54076 + would result in, we arrived via inheritance, don't
54077 + lose subject
54078 + */
54079 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54080 + (subj == task->acl)))
54081 + task->acl = subj;
54082 +
54083 + task->role = role;
54084 +
54085 + task->is_writable = 0;
54086 +
54087 + /* ignore additional mmap checks for processes that are writable
54088 + by the default ACL */
54089 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54090 + if (unlikely(obj->mode & GR_WRITE))
54091 + task->is_writable = 1;
54092 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54093 + if (unlikely(obj->mode & GR_WRITE))
54094 + task->is_writable = 1;
54095 +
54096 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54097 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54098 +#endif
54099 +
54100 + gr_set_proc_res(task);
54101 +
54102 + return;
54103 +}
54104 +
54105 +int
54106 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54107 + const int unsafe_flags)
54108 +{
54109 + struct task_struct *task = current;
54110 + struct acl_subject_label *newacl;
54111 + struct acl_object_label *obj;
54112 + __u32 retmode;
54113 +
54114 + if (unlikely(!(gr_status & GR_READY)))
54115 + return 0;
54116 +
54117 + newacl = chk_subj_label(dentry, mnt, task->role);
54118 +
54119 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54120 + did an exec
54121 + */
54122 + rcu_read_lock();
54123 + read_lock(&tasklist_lock);
54124 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54125 + (task->parent->acl->mode & GR_POVERRIDE))) {
54126 + read_unlock(&tasklist_lock);
54127 + rcu_read_unlock();
54128 + goto skip_check;
54129 + }
54130 + read_unlock(&tasklist_lock);
54131 + rcu_read_unlock();
54132 +
54133 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54134 + !(task->role->roletype & GR_ROLE_GOD) &&
54135 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54136 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54137 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54138 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54139 + else
54140 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54141 + return -EACCES;
54142 + }
54143 +
54144 +skip_check:
54145 +
54146 + obj = chk_obj_label(dentry, mnt, task->acl);
54147 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54148 +
54149 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54150 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54151 + if (obj->nested)
54152 + task->acl = obj->nested;
54153 + else
54154 + task->acl = newacl;
54155 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54156 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54157 +
54158 + task->is_writable = 0;
54159 +
54160 + /* ignore additional mmap checks for processes that are writable
54161 + by the default ACL */
54162 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54163 + if (unlikely(obj->mode & GR_WRITE))
54164 + task->is_writable = 1;
54165 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54166 + if (unlikely(obj->mode & GR_WRITE))
54167 + task->is_writable = 1;
54168 +
54169 + gr_set_proc_res(task);
54170 +
54171 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54172 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54173 +#endif
54174 + return 0;
54175 +}
54176 +
54177 +/* always called with valid inodev ptr */
54178 +static void
54179 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54180 +{
54181 + struct acl_object_label *matchpo;
54182 + struct acl_subject_label *matchps;
54183 + struct acl_subject_label *subj;
54184 + struct acl_role_label *role;
54185 + unsigned int x;
54186 +
54187 + FOR_EACH_ROLE_START(role)
54188 + FOR_EACH_SUBJECT_START(role, subj, x)
54189 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54190 + matchpo->mode |= GR_DELETED;
54191 + FOR_EACH_SUBJECT_END(subj,x)
54192 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54193 + /* nested subjects aren't in the role's subj_hash table */
54194 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54195 + matchpo->mode |= GR_DELETED;
54196 + FOR_EACH_NESTED_SUBJECT_END(subj)
54197 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54198 + matchps->mode |= GR_DELETED;
54199 + FOR_EACH_ROLE_END(role)
54200 +
54201 + inodev->nentry->deleted = 1;
54202 +
54203 + return;
54204 +}
54205 +
54206 +void
54207 +gr_handle_delete(const ino_t ino, const dev_t dev)
54208 +{
54209 + struct inodev_entry *inodev;
54210 +
54211 + if (unlikely(!(gr_status & GR_READY)))
54212 + return;
54213 +
54214 + write_lock(&gr_inode_lock);
54215 + inodev = lookup_inodev_entry(ino, dev);
54216 + if (inodev != NULL)
54217 + do_handle_delete(inodev, ino, dev);
54218 + write_unlock(&gr_inode_lock);
54219 +
54220 + return;
54221 +}
54222 +
54223 +static void
54224 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54225 + const ino_t newinode, const dev_t newdevice,
54226 + struct acl_subject_label *subj)
54227 +{
54228 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54229 + struct acl_object_label *match;
54230 +
54231 + match = subj->obj_hash[index];
54232 +
54233 + while (match && (match->inode != oldinode ||
54234 + match->device != olddevice ||
54235 + !(match->mode & GR_DELETED)))
54236 + match = match->next;
54237 +
54238 + if (match && (match->inode == oldinode)
54239 + && (match->device == olddevice)
54240 + && (match->mode & GR_DELETED)) {
54241 + if (match->prev == NULL) {
54242 + subj->obj_hash[index] = match->next;
54243 + if (match->next != NULL)
54244 + match->next->prev = NULL;
54245 + } else {
54246 + match->prev->next = match->next;
54247 + if (match->next != NULL)
54248 + match->next->prev = match->prev;
54249 + }
54250 + match->prev = NULL;
54251 + match->next = NULL;
54252 + match->inode = newinode;
54253 + match->device = newdevice;
54254 + match->mode &= ~GR_DELETED;
54255 +
54256 + insert_acl_obj_label(match, subj);
54257 + }
54258 +
54259 + return;
54260 +}
54261 +
54262 +static void
54263 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54264 + const ino_t newinode, const dev_t newdevice,
54265 + struct acl_role_label *role)
54266 +{
54267 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54268 + struct acl_subject_label *match;
54269 +
54270 + match = role->subj_hash[index];
54271 +
54272 + while (match && (match->inode != oldinode ||
54273 + match->device != olddevice ||
54274 + !(match->mode & GR_DELETED)))
54275 + match = match->next;
54276 +
54277 + if (match && (match->inode == oldinode)
54278 + && (match->device == olddevice)
54279 + && (match->mode & GR_DELETED)) {
54280 + if (match->prev == NULL) {
54281 + role->subj_hash[index] = match->next;
54282 + if (match->next != NULL)
54283 + match->next->prev = NULL;
54284 + } else {
54285 + match->prev->next = match->next;
54286 + if (match->next != NULL)
54287 + match->next->prev = match->prev;
54288 + }
54289 + match->prev = NULL;
54290 + match->next = NULL;
54291 + match->inode = newinode;
54292 + match->device = newdevice;
54293 + match->mode &= ~GR_DELETED;
54294 +
54295 + insert_acl_subj_label(match, role);
54296 + }
54297 +
54298 + return;
54299 +}
54300 +
54301 +static void
54302 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54303 + const ino_t newinode, const dev_t newdevice)
54304 +{
54305 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54306 + struct inodev_entry *match;
54307 +
54308 + match = inodev_set.i_hash[index];
54309 +
54310 + while (match && (match->nentry->inode != oldinode ||
54311 + match->nentry->device != olddevice || !match->nentry->deleted))
54312 + match = match->next;
54313 +
54314 + if (match && (match->nentry->inode == oldinode)
54315 + && (match->nentry->device == olddevice) &&
54316 + match->nentry->deleted) {
54317 + if (match->prev == NULL) {
54318 + inodev_set.i_hash[index] = match->next;
54319 + if (match->next != NULL)
54320 + match->next->prev = NULL;
54321 + } else {
54322 + match->prev->next = match->next;
54323 + if (match->next != NULL)
54324 + match->next->prev = match->prev;
54325 + }
54326 + match->prev = NULL;
54327 + match->next = NULL;
54328 + match->nentry->inode = newinode;
54329 + match->nentry->device = newdevice;
54330 + match->nentry->deleted = 0;
54331 +
54332 + insert_inodev_entry(match);
54333 + }
54334 +
54335 + return;
54336 +}
54337 +
54338 +static void
54339 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54340 +{
54341 + struct acl_subject_label *subj;
54342 + struct acl_role_label *role;
54343 + unsigned int x;
54344 +
54345 + FOR_EACH_ROLE_START(role)
54346 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54347 +
54348 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54349 + if ((subj->inode == ino) && (subj->device == dev)) {
54350 + subj->inode = ino;
54351 + subj->device = dev;
54352 + }
54353 + /* nested subjects aren't in the role's subj_hash table */
54354 + update_acl_obj_label(matchn->inode, matchn->device,
54355 + ino, dev, subj);
54356 + FOR_EACH_NESTED_SUBJECT_END(subj)
54357 + FOR_EACH_SUBJECT_START(role, subj, x)
54358 + update_acl_obj_label(matchn->inode, matchn->device,
54359 + ino, dev, subj);
54360 + FOR_EACH_SUBJECT_END(subj,x)
54361 + FOR_EACH_ROLE_END(role)
54362 +
54363 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54364 +
54365 + return;
54366 +}
54367 +
54368 +static void
54369 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54370 + const struct vfsmount *mnt)
54371 +{
54372 + ino_t ino = dentry->d_inode->i_ino;
54373 + dev_t dev = __get_dev(dentry);
54374 +
54375 + __do_handle_create(matchn, ino, dev);
54376 +
54377 + return;
54378 +}
54379 +
54380 +void
54381 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54382 +{
54383 + struct name_entry *matchn;
54384 +
54385 + if (unlikely(!(gr_status & GR_READY)))
54386 + return;
54387 +
54388 + preempt_disable();
54389 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54390 +
54391 + if (unlikely((unsigned long)matchn)) {
54392 + write_lock(&gr_inode_lock);
54393 + do_handle_create(matchn, dentry, mnt);
54394 + write_unlock(&gr_inode_lock);
54395 + }
54396 + preempt_enable();
54397 +
54398 + return;
54399 +}
54400 +
54401 +void
54402 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54403 +{
54404 + struct name_entry *matchn;
54405 +
54406 + if (unlikely(!(gr_status & GR_READY)))
54407 + return;
54408 +
54409 + preempt_disable();
54410 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54411 +
54412 + if (unlikely((unsigned long)matchn)) {
54413 + write_lock(&gr_inode_lock);
54414 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54415 + write_unlock(&gr_inode_lock);
54416 + }
54417 + preempt_enable();
54418 +
54419 + return;
54420 +}
54421 +
54422 +void
54423 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54424 + struct dentry *old_dentry,
54425 + struct dentry *new_dentry,
54426 + struct vfsmount *mnt, const __u8 replace)
54427 +{
54428 + struct name_entry *matchn;
54429 + struct inodev_entry *inodev;
54430 + struct inode *inode = new_dentry->d_inode;
54431 + ino_t old_ino = old_dentry->d_inode->i_ino;
54432 + dev_t old_dev = __get_dev(old_dentry);
54433 +
54434 + /* vfs_rename swaps the name and parent link for old_dentry and
54435 + new_dentry
54436 + at this point, old_dentry has the new name, parent link, and inode
54437 + for the renamed file
54438 + if a file is being replaced by a rename, new_dentry has the inode
54439 + and name for the replaced file
54440 + */
54441 +
54442 + if (unlikely(!(gr_status & GR_READY)))
54443 + return;
54444 +
54445 + preempt_disable();
54446 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54447 +
54448 + /* we wouldn't have to check d_inode if it weren't for
54449 + NFS silly-renaming
54450 + */
54451 +
54452 + write_lock(&gr_inode_lock);
54453 + if (unlikely(replace && inode)) {
54454 + ino_t new_ino = inode->i_ino;
54455 + dev_t new_dev = __get_dev(new_dentry);
54456 +
54457 + inodev = lookup_inodev_entry(new_ino, new_dev);
54458 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54459 + do_handle_delete(inodev, new_ino, new_dev);
54460 + }
54461 +
54462 + inodev = lookup_inodev_entry(old_ino, old_dev);
54463 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54464 + do_handle_delete(inodev, old_ino, old_dev);
54465 +
54466 + if (unlikely((unsigned long)matchn))
54467 + do_handle_create(matchn, old_dentry, mnt);
54468 +
54469 + write_unlock(&gr_inode_lock);
54470 + preempt_enable();
54471 +
54472 + return;
54473 +}
54474 +
54475 +static int
54476 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54477 + unsigned char **sum)
54478 +{
54479 + struct acl_role_label *r;
54480 + struct role_allowed_ip *ipp;
54481 + struct role_transition *trans;
54482 + unsigned int i;
54483 + int found = 0;
54484 + u32 curr_ip = current->signal->curr_ip;
54485 +
54486 + current->signal->saved_ip = curr_ip;
54487 +
54488 + /* check transition table */
54489 +
54490 + for (trans = current->role->transitions; trans; trans = trans->next) {
54491 + if (!strcmp(rolename, trans->rolename)) {
54492 + found = 1;
54493 + break;
54494 + }
54495 + }
54496 +
54497 + if (!found)
54498 + return 0;
54499 +
54500 + /* handle special roles that do not require authentication
54501 + and check ip */
54502 +
54503 + FOR_EACH_ROLE_START(r)
54504 + if (!strcmp(rolename, r->rolename) &&
54505 + (r->roletype & GR_ROLE_SPECIAL)) {
54506 + found = 0;
54507 + if (r->allowed_ips != NULL) {
54508 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54509 + if ((ntohl(curr_ip) & ipp->netmask) ==
54510 + (ntohl(ipp->addr) & ipp->netmask))
54511 + found = 1;
54512 + }
54513 + } else
54514 + found = 2;
54515 + if (!found)
54516 + return 0;
54517 +
54518 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54519 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54520 + *salt = NULL;
54521 + *sum = NULL;
54522 + return 1;
54523 + }
54524 + }
54525 + FOR_EACH_ROLE_END(r)
54526 +
54527 + for (i = 0; i < num_sprole_pws; i++) {
54528 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54529 + *salt = acl_special_roles[i]->salt;
54530 + *sum = acl_special_roles[i]->sum;
54531 + return 1;
54532 + }
54533 + }
54534 +
54535 + return 0;
54536 +}
54537 +
54538 +static void
54539 +assign_special_role(char *rolename)
54540 +{
54541 + struct acl_object_label *obj;
54542 + struct acl_role_label *r;
54543 + struct acl_role_label *assigned = NULL;
54544 + struct task_struct *tsk;
54545 + struct file *filp;
54546 +
54547 + FOR_EACH_ROLE_START(r)
54548 + if (!strcmp(rolename, r->rolename) &&
54549 + (r->roletype & GR_ROLE_SPECIAL)) {
54550 + assigned = r;
54551 + break;
54552 + }
54553 + FOR_EACH_ROLE_END(r)
54554 +
54555 + if (!assigned)
54556 + return;
54557 +
54558 + read_lock(&tasklist_lock);
54559 + read_lock(&grsec_exec_file_lock);
54560 +
54561 + tsk = current->real_parent;
54562 + if (tsk == NULL)
54563 + goto out_unlock;
54564 +
54565 + filp = tsk->exec_file;
54566 + if (filp == NULL)
54567 + goto out_unlock;
54568 +
54569 + tsk->is_writable = 0;
54570 +
54571 + tsk->acl_sp_role = 1;
54572 + tsk->acl_role_id = ++acl_sp_role_value;
54573 + tsk->role = assigned;
54574 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54575 +
54576 + /* ignore additional mmap checks for processes that are writable
54577 + by the default ACL */
54578 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54579 + if (unlikely(obj->mode & GR_WRITE))
54580 + tsk->is_writable = 1;
54581 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54582 + if (unlikely(obj->mode & GR_WRITE))
54583 + tsk->is_writable = 1;
54584 +
54585 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54586 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54587 +#endif
54588 +
54589 +out_unlock:
54590 + read_unlock(&grsec_exec_file_lock);
54591 + read_unlock(&tasklist_lock);
54592 + return;
54593 +}
54594 +
54595 +int gr_check_secure_terminal(struct task_struct *task)
54596 +{
54597 + struct task_struct *p, *p2, *p3;
54598 + struct files_struct *files;
54599 + struct fdtable *fdt;
54600 + struct file *our_file = NULL, *file;
54601 + int i;
54602 +
54603 + if (task->signal->tty == NULL)
54604 + return 1;
54605 +
54606 + files = get_files_struct(task);
54607 + if (files != NULL) {
54608 + rcu_read_lock();
54609 + fdt = files_fdtable(files);
54610 + for (i=0; i < fdt->max_fds; i++) {
54611 + file = fcheck_files(files, i);
54612 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54613 + get_file(file);
54614 + our_file = file;
54615 + }
54616 + }
54617 + rcu_read_unlock();
54618 + put_files_struct(files);
54619 + }
54620 +
54621 + if (our_file == NULL)
54622 + return 1;
54623 +
54624 + read_lock(&tasklist_lock);
54625 + do_each_thread(p2, p) {
54626 + files = get_files_struct(p);
54627 + if (files == NULL ||
54628 + (p->signal && p->signal->tty == task->signal->tty)) {
54629 + if (files != NULL)
54630 + put_files_struct(files);
54631 + continue;
54632 + }
54633 + rcu_read_lock();
54634 + fdt = files_fdtable(files);
54635 + for (i=0; i < fdt->max_fds; i++) {
54636 + file = fcheck_files(files, i);
54637 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54638 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54639 + p3 = task;
54640 + while (p3->pid > 0) {
54641 + if (p3 == p)
54642 + break;
54643 + p3 = p3->real_parent;
54644 + }
54645 + if (p3 == p)
54646 + break;
54647 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54648 + gr_handle_alertkill(p);
54649 + rcu_read_unlock();
54650 + put_files_struct(files);
54651 + read_unlock(&tasklist_lock);
54652 + fput(our_file);
54653 + return 0;
54654 + }
54655 + }
54656 + rcu_read_unlock();
54657 + put_files_struct(files);
54658 + } while_each_thread(p2, p);
54659 + read_unlock(&tasklist_lock);
54660 +
54661 + fput(our_file);
54662 + return 1;
54663 +}
54664 +
54665 +static int gr_rbac_disable(void *unused)
54666 +{
54667 + pax_open_kernel();
54668 + gr_status &= ~GR_READY;
54669 + pax_close_kernel();
54670 +
54671 + return 0;
54672 +}
54673 +
54674 +ssize_t
54675 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54676 +{
54677 + struct gr_arg_wrapper uwrap;
54678 + unsigned char *sprole_salt = NULL;
54679 + unsigned char *sprole_sum = NULL;
54680 + int error = sizeof (struct gr_arg_wrapper);
54681 + int error2 = 0;
54682 +
54683 + mutex_lock(&gr_dev_mutex);
54684 +
54685 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54686 + error = -EPERM;
54687 + goto out;
54688 + }
54689 +
54690 + if (count != sizeof (struct gr_arg_wrapper)) {
54691 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54692 + error = -EINVAL;
54693 + goto out;
54694 + }
54695 +
54696 +
54697 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54698 + gr_auth_expires = 0;
54699 + gr_auth_attempts = 0;
54700 + }
54701 +
54702 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54703 + error = -EFAULT;
54704 + goto out;
54705 + }
54706 +
54707 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54708 + error = -EINVAL;
54709 + goto out;
54710 + }
54711 +
54712 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54713 + error = -EFAULT;
54714 + goto out;
54715 + }
54716 +
54717 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54718 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54719 + time_after(gr_auth_expires, get_seconds())) {
54720 + error = -EBUSY;
54721 + goto out;
54722 + }
54723 +
54724 + /* if non-root trying to do anything other than use a special role,
54725 + do not attempt authentication, do not count towards authentication
54726 + locking
54727 + */
54728 +
54729 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54730 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54731 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54732 + error = -EPERM;
54733 + goto out;
54734 + }
54735 +
54736 + /* ensure pw and special role name are null terminated */
54737 +
54738 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54739 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54740 +
54741 + /* Okay.
54742 + * We have our enough of the argument structure..(we have yet
54743 + * to copy_from_user the tables themselves) . Copy the tables
54744 + * only if we need them, i.e. for loading operations. */
54745 +
54746 + switch (gr_usermode->mode) {
54747 + case GR_STATUS:
54748 + if (gr_status & GR_READY) {
54749 + error = 1;
54750 + if (!gr_check_secure_terminal(current))
54751 + error = 3;
54752 + } else
54753 + error = 2;
54754 + goto out;
54755 + case GR_SHUTDOWN:
54756 + if ((gr_status & GR_READY)
54757 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54758 + stop_machine(gr_rbac_disable, NULL, NULL);
54759 + free_variables();
54760 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54761 + memset(gr_system_salt, 0, GR_SALT_LEN);
54762 + memset(gr_system_sum, 0, GR_SHA_LEN);
54763 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54764 + } else if (gr_status & GR_READY) {
54765 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54766 + error = -EPERM;
54767 + } else {
54768 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54769 + error = -EAGAIN;
54770 + }
54771 + break;
54772 + case GR_ENABLE:
54773 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54774 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54775 + else {
54776 + if (gr_status & GR_READY)
54777 + error = -EAGAIN;
54778 + else
54779 + error = error2;
54780 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54781 + }
54782 + break;
54783 + case GR_RELOAD:
54784 + if (!(gr_status & GR_READY)) {
54785 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54786 + error = -EAGAIN;
54787 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54788 + stop_machine(gr_rbac_disable, NULL, NULL);
54789 + free_variables();
54790 + error2 = gracl_init(gr_usermode);
54791 + if (!error2)
54792 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54793 + else {
54794 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54795 + error = error2;
54796 + }
54797 + } else {
54798 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54799 + error = -EPERM;
54800 + }
54801 + break;
54802 + case GR_SEGVMOD:
54803 + if (unlikely(!(gr_status & GR_READY))) {
54804 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54805 + error = -EAGAIN;
54806 + break;
54807 + }
54808 +
54809 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54810 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54811 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54812 + struct acl_subject_label *segvacl;
54813 + segvacl =
54814 + lookup_acl_subj_label(gr_usermode->segv_inode,
54815 + gr_usermode->segv_device,
54816 + current->role);
54817 + if (segvacl) {
54818 + segvacl->crashes = 0;
54819 + segvacl->expires = 0;
54820 + }
54821 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54822 + gr_remove_uid(gr_usermode->segv_uid);
54823 + }
54824 + } else {
54825 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54826 + error = -EPERM;
54827 + }
54828 + break;
54829 + case GR_SPROLE:
54830 + case GR_SPROLEPAM:
54831 + if (unlikely(!(gr_status & GR_READY))) {
54832 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54833 + error = -EAGAIN;
54834 + break;
54835 + }
54836 +
54837 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54838 + current->role->expires = 0;
54839 + current->role->auth_attempts = 0;
54840 + }
54841 +
54842 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54843 + time_after(current->role->expires, get_seconds())) {
54844 + error = -EBUSY;
54845 + goto out;
54846 + }
54847 +
54848 + if (lookup_special_role_auth
54849 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54850 + && ((!sprole_salt && !sprole_sum)
54851 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54852 + char *p = "";
54853 + assign_special_role(gr_usermode->sp_role);
54854 + read_lock(&tasklist_lock);
54855 + if (current->real_parent)
54856 + p = current->real_parent->role->rolename;
54857 + read_unlock(&tasklist_lock);
54858 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54859 + p, acl_sp_role_value);
54860 + } else {
54861 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54862 + error = -EPERM;
54863 + if(!(current->role->auth_attempts++))
54864 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54865 +
54866 + goto out;
54867 + }
54868 + break;
54869 + case GR_UNSPROLE:
54870 + if (unlikely(!(gr_status & GR_READY))) {
54871 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54872 + error = -EAGAIN;
54873 + break;
54874 + }
54875 +
54876 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54877 + char *p = "";
54878 + int i = 0;
54879 +
54880 + read_lock(&tasklist_lock);
54881 + if (current->real_parent) {
54882 + p = current->real_parent->role->rolename;
54883 + i = current->real_parent->acl_role_id;
54884 + }
54885 + read_unlock(&tasklist_lock);
54886 +
54887 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54888 + gr_set_acls(1);
54889 + } else {
54890 + error = -EPERM;
54891 + goto out;
54892 + }
54893 + break;
54894 + default:
54895 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54896 + error = -EINVAL;
54897 + break;
54898 + }
54899 +
54900 + if (error != -EPERM)
54901 + goto out;
54902 +
54903 + if(!(gr_auth_attempts++))
54904 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54905 +
54906 + out:
54907 + mutex_unlock(&gr_dev_mutex);
54908 + return error;
54909 +}
54910 +
54911 +/* must be called with
54912 + rcu_read_lock();
54913 + read_lock(&tasklist_lock);
54914 + read_lock(&grsec_exec_file_lock);
54915 +*/
54916 +int gr_apply_subject_to_task(struct task_struct *task)
54917 +{
54918 + struct acl_object_label *obj;
54919 + char *tmpname;
54920 + struct acl_subject_label *tmpsubj;
54921 + struct file *filp;
54922 + struct name_entry *nmatch;
54923 +
54924 + filp = task->exec_file;
54925 + if (filp == NULL)
54926 + return 0;
54927 +
54928 + /* the following is to apply the correct subject
54929 + on binaries running when the RBAC system
54930 + is enabled, when the binaries have been
54931 + replaced or deleted since their execution
54932 + -----
54933 + when the RBAC system starts, the inode/dev
54934 + from exec_file will be one the RBAC system
54935 + is unaware of. It only knows the inode/dev
54936 + of the present file on disk, or the absence
54937 + of it.
54938 + */
54939 + preempt_disable();
54940 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54941 +
54942 + nmatch = lookup_name_entry(tmpname);
54943 + preempt_enable();
54944 + tmpsubj = NULL;
54945 + if (nmatch) {
54946 + if (nmatch->deleted)
54947 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54948 + else
54949 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54950 + if (tmpsubj != NULL)
54951 + task->acl = tmpsubj;
54952 + }
54953 + if (tmpsubj == NULL)
54954 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54955 + task->role);
54956 + if (task->acl) {
54957 + task->is_writable = 0;
54958 + /* ignore additional mmap checks for processes that are writable
54959 + by the default ACL */
54960 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54961 + if (unlikely(obj->mode & GR_WRITE))
54962 + task->is_writable = 1;
54963 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54964 + if (unlikely(obj->mode & GR_WRITE))
54965 + task->is_writable = 1;
54966 +
54967 + gr_set_proc_res(task);
54968 +
54969 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54970 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54971 +#endif
54972 + } else {
54973 + return 1;
54974 + }
54975 +
54976 + return 0;
54977 +}
54978 +
54979 +int
54980 +gr_set_acls(const int type)
54981 +{
54982 + struct task_struct *task, *task2;
54983 + struct acl_role_label *role = current->role;
54984 + __u16 acl_role_id = current->acl_role_id;
54985 + const struct cred *cred;
54986 + int ret;
54987 +
54988 + rcu_read_lock();
54989 + read_lock(&tasklist_lock);
54990 + read_lock(&grsec_exec_file_lock);
54991 + do_each_thread(task2, task) {
54992 + /* check to see if we're called from the exit handler,
54993 + if so, only replace ACLs that have inherited the admin
54994 + ACL */
54995 +
54996 + if (type && (task->role != role ||
54997 + task->acl_role_id != acl_role_id))
54998 + continue;
54999 +
55000 + task->acl_role_id = 0;
55001 + task->acl_sp_role = 0;
55002 +
55003 + if (task->exec_file) {
55004 + cred = __task_cred(task);
55005 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55006 + ret = gr_apply_subject_to_task(task);
55007 + if (ret) {
55008 + read_unlock(&grsec_exec_file_lock);
55009 + read_unlock(&tasklist_lock);
55010 + rcu_read_unlock();
55011 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55012 + return ret;
55013 + }
55014 + } else {
55015 + // it's a kernel process
55016 + task->role = kernel_role;
55017 + task->acl = kernel_role->root_label;
55018 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55019 + task->acl->mode &= ~GR_PROCFIND;
55020 +#endif
55021 + }
55022 + } while_each_thread(task2, task);
55023 + read_unlock(&grsec_exec_file_lock);
55024 + read_unlock(&tasklist_lock);
55025 + rcu_read_unlock();
55026 +
55027 + return 0;
55028 +}
55029 +
55030 +void
55031 +gr_learn_resource(const struct task_struct *task,
55032 + const int res, const unsigned long wanted, const int gt)
55033 +{
55034 + struct acl_subject_label *acl;
55035 + const struct cred *cred;
55036 +
55037 + if (unlikely((gr_status & GR_READY) &&
55038 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55039 + goto skip_reslog;
55040 +
55041 +#ifdef CONFIG_GRKERNSEC_RESLOG
55042 + gr_log_resource(task, res, wanted, gt);
55043 +#endif
55044 + skip_reslog:
55045 +
55046 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55047 + return;
55048 +
55049 + acl = task->acl;
55050 +
55051 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55052 + !(acl->resmask & (1 << (unsigned short) res))))
55053 + return;
55054 +
55055 + if (wanted >= acl->res[res].rlim_cur) {
55056 + unsigned long res_add;
55057 +
55058 + res_add = wanted;
55059 + switch (res) {
55060 + case RLIMIT_CPU:
55061 + res_add += GR_RLIM_CPU_BUMP;
55062 + break;
55063 + case RLIMIT_FSIZE:
55064 + res_add += GR_RLIM_FSIZE_BUMP;
55065 + break;
55066 + case RLIMIT_DATA:
55067 + res_add += GR_RLIM_DATA_BUMP;
55068 + break;
55069 + case RLIMIT_STACK:
55070 + res_add += GR_RLIM_STACK_BUMP;
55071 + break;
55072 + case RLIMIT_CORE:
55073 + res_add += GR_RLIM_CORE_BUMP;
55074 + break;
55075 + case RLIMIT_RSS:
55076 + res_add += GR_RLIM_RSS_BUMP;
55077 + break;
55078 + case RLIMIT_NPROC:
55079 + res_add += GR_RLIM_NPROC_BUMP;
55080 + break;
55081 + case RLIMIT_NOFILE:
55082 + res_add += GR_RLIM_NOFILE_BUMP;
55083 + break;
55084 + case RLIMIT_MEMLOCK:
55085 + res_add += GR_RLIM_MEMLOCK_BUMP;
55086 + break;
55087 + case RLIMIT_AS:
55088 + res_add += GR_RLIM_AS_BUMP;
55089 + break;
55090 + case RLIMIT_LOCKS:
55091 + res_add += GR_RLIM_LOCKS_BUMP;
55092 + break;
55093 + case RLIMIT_SIGPENDING:
55094 + res_add += GR_RLIM_SIGPENDING_BUMP;
55095 + break;
55096 + case RLIMIT_MSGQUEUE:
55097 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55098 + break;
55099 + case RLIMIT_NICE:
55100 + res_add += GR_RLIM_NICE_BUMP;
55101 + break;
55102 + case RLIMIT_RTPRIO:
55103 + res_add += GR_RLIM_RTPRIO_BUMP;
55104 + break;
55105 + case RLIMIT_RTTIME:
55106 + res_add += GR_RLIM_RTTIME_BUMP;
55107 + break;
55108 + }
55109 +
55110 + acl->res[res].rlim_cur = res_add;
55111 +
55112 + if (wanted > acl->res[res].rlim_max)
55113 + acl->res[res].rlim_max = res_add;
55114 +
55115 + /* only log the subject filename, since resource logging is supported for
55116 + single-subject learning only */
55117 + rcu_read_lock();
55118 + cred = __task_cred(task);
55119 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55120 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55121 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55122 + "", (unsigned long) res, &task->signal->saved_ip);
55123 + rcu_read_unlock();
55124 + }
55125 +
55126 + return;
55127 +}
55128 +
55129 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55130 +void
55131 +pax_set_initial_flags(struct linux_binprm *bprm)
55132 +{
55133 + struct task_struct *task = current;
55134 + struct acl_subject_label *proc;
55135 + unsigned long flags;
55136 +
55137 + if (unlikely(!(gr_status & GR_READY)))
55138 + return;
55139 +
55140 + flags = pax_get_flags(task);
55141 +
55142 + proc = task->acl;
55143 +
55144 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55145 + flags &= ~MF_PAX_PAGEEXEC;
55146 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55147 + flags &= ~MF_PAX_SEGMEXEC;
55148 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55149 + flags &= ~MF_PAX_RANDMMAP;
55150 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55151 + flags &= ~MF_PAX_EMUTRAMP;
55152 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55153 + flags &= ~MF_PAX_MPROTECT;
55154 +
55155 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55156 + flags |= MF_PAX_PAGEEXEC;
55157 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55158 + flags |= MF_PAX_SEGMEXEC;
55159 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55160 + flags |= MF_PAX_RANDMMAP;
55161 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55162 + flags |= MF_PAX_EMUTRAMP;
55163 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55164 + flags |= MF_PAX_MPROTECT;
55165 +
55166 + pax_set_flags(task, flags);
55167 +
55168 + return;
55169 +}
55170 +#endif
55171 +
55172 +int
55173 +gr_handle_proc_ptrace(struct task_struct *task)
55174 +{
55175 + struct file *filp;
55176 + struct task_struct *tmp = task;
55177 + struct task_struct *curtemp = current;
55178 + __u32 retmode;
55179 +
55180 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55181 + if (unlikely(!(gr_status & GR_READY)))
55182 + return 0;
55183 +#endif
55184 +
55185 + read_lock(&tasklist_lock);
55186 + read_lock(&grsec_exec_file_lock);
55187 + filp = task->exec_file;
55188 +
55189 + while (tmp->pid > 0) {
55190 + if (tmp == curtemp)
55191 + break;
55192 + tmp = tmp->real_parent;
55193 + }
55194 +
55195 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55196 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55197 + read_unlock(&grsec_exec_file_lock);
55198 + read_unlock(&tasklist_lock);
55199 + return 1;
55200 + }
55201 +
55202 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55203 + if (!(gr_status & GR_READY)) {
55204 + read_unlock(&grsec_exec_file_lock);
55205 + read_unlock(&tasklist_lock);
55206 + return 0;
55207 + }
55208 +#endif
55209 +
55210 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55211 + read_unlock(&grsec_exec_file_lock);
55212 + read_unlock(&tasklist_lock);
55213 +
55214 + if (retmode & GR_NOPTRACE)
55215 + return 1;
55216 +
55217 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55218 + && (current->acl != task->acl || (current->acl != current->role->root_label
55219 + && current->pid != task->pid)))
55220 + return 1;
55221 +
55222 + return 0;
55223 +}
55224 +
55225 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55226 +{
55227 + if (unlikely(!(gr_status & GR_READY)))
55228 + return;
55229 +
55230 + if (!(current->role->roletype & GR_ROLE_GOD))
55231 + return;
55232 +
55233 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55234 + p->role->rolename, gr_task_roletype_to_char(p),
55235 + p->acl->filename);
55236 +}
55237 +
55238 +int
55239 +gr_handle_ptrace(struct task_struct *task, const long request)
55240 +{
55241 + struct task_struct *tmp = task;
55242 + struct task_struct *curtemp = current;
55243 + __u32 retmode;
55244 +
55245 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55246 + if (unlikely(!(gr_status & GR_READY)))
55247 + return 0;
55248 +#endif
55249 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55250 + read_lock(&tasklist_lock);
55251 + while (tmp->pid > 0) {
55252 + if (tmp == curtemp)
55253 + break;
55254 + tmp = tmp->real_parent;
55255 + }
55256 +
55257 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55258 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55259 + read_unlock(&tasklist_lock);
55260 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55261 + return 1;
55262 + }
55263 + read_unlock(&tasklist_lock);
55264 + }
55265 +
55266 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55267 + if (!(gr_status & GR_READY))
55268 + return 0;
55269 +#endif
55270 +
55271 + read_lock(&grsec_exec_file_lock);
55272 + if (unlikely(!task->exec_file)) {
55273 + read_unlock(&grsec_exec_file_lock);
55274 + return 0;
55275 + }
55276 +
55277 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55278 + read_unlock(&grsec_exec_file_lock);
55279 +
55280 + if (retmode & GR_NOPTRACE) {
55281 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55282 + return 1;
55283 + }
55284 +
55285 + if (retmode & GR_PTRACERD) {
55286 + switch (request) {
55287 + case PTRACE_SEIZE:
55288 + case PTRACE_POKETEXT:
55289 + case PTRACE_POKEDATA:
55290 + case PTRACE_POKEUSR:
55291 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55292 + case PTRACE_SETREGS:
55293 + case PTRACE_SETFPREGS:
55294 +#endif
55295 +#ifdef CONFIG_X86
55296 + case PTRACE_SETFPXREGS:
55297 +#endif
55298 +#ifdef CONFIG_ALTIVEC
55299 + case PTRACE_SETVRREGS:
55300 +#endif
55301 + return 1;
55302 + default:
55303 + return 0;
55304 + }
55305 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55306 + !(current->role->roletype & GR_ROLE_GOD) &&
55307 + (current->acl != task->acl)) {
55308 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55309 + return 1;
55310 + }
55311 +
55312 + return 0;
55313 +}
55314 +
55315 +static int is_writable_mmap(const struct file *filp)
55316 +{
55317 + struct task_struct *task = current;
55318 + struct acl_object_label *obj, *obj2;
55319 +
55320 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55321 + !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))) {
55322 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55323 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55324 + task->role->root_label);
55325 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55326 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55327 + return 1;
55328 + }
55329 + }
55330 + return 0;
55331 +}
55332 +
55333 +int
55334 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55335 +{
55336 + __u32 mode;
55337 +
55338 + if (unlikely(!file || !(prot & PROT_EXEC)))
55339 + return 1;
55340 +
55341 + if (is_writable_mmap(file))
55342 + return 0;
55343 +
55344 + mode =
55345 + gr_search_file(file->f_path.dentry,
55346 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55347 + file->f_path.mnt);
55348 +
55349 + if (!gr_tpe_allow(file))
55350 + return 0;
55351 +
55352 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55353 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55354 + return 0;
55355 + } else if (unlikely(!(mode & GR_EXEC))) {
55356 + return 0;
55357 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55358 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55359 + return 1;
55360 + }
55361 +
55362 + return 1;
55363 +}
55364 +
55365 +int
55366 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55367 +{
55368 + __u32 mode;
55369 +
55370 + if (unlikely(!file || !(prot & PROT_EXEC)))
55371 + return 1;
55372 +
55373 + if (is_writable_mmap(file))
55374 + return 0;
55375 +
55376 + mode =
55377 + gr_search_file(file->f_path.dentry,
55378 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55379 + file->f_path.mnt);
55380 +
55381 + if (!gr_tpe_allow(file))
55382 + return 0;
55383 +
55384 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55385 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55386 + return 0;
55387 + } else if (unlikely(!(mode & GR_EXEC))) {
55388 + return 0;
55389 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55390 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55391 + return 1;
55392 + }
55393 +
55394 + return 1;
55395 +}
55396 +
55397 +void
55398 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55399 +{
55400 + unsigned long runtime;
55401 + unsigned long cputime;
55402 + unsigned int wday, cday;
55403 + __u8 whr, chr;
55404 + __u8 wmin, cmin;
55405 + __u8 wsec, csec;
55406 + struct timespec timeval;
55407 +
55408 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55409 + !(task->acl->mode & GR_PROCACCT)))
55410 + return;
55411 +
55412 + do_posix_clock_monotonic_gettime(&timeval);
55413 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55414 + wday = runtime / (3600 * 24);
55415 + runtime -= wday * (3600 * 24);
55416 + whr = runtime / 3600;
55417 + runtime -= whr * 3600;
55418 + wmin = runtime / 60;
55419 + runtime -= wmin * 60;
55420 + wsec = runtime;
55421 +
55422 + cputime = (task->utime + task->stime) / HZ;
55423 + cday = cputime / (3600 * 24);
55424 + cputime -= cday * (3600 * 24);
55425 + chr = cputime / 3600;
55426 + cputime -= chr * 3600;
55427 + cmin = cputime / 60;
55428 + cputime -= cmin * 60;
55429 + csec = cputime;
55430 +
55431 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55432 +
55433 + return;
55434 +}
55435 +
55436 +void gr_set_kernel_label(struct task_struct *task)
55437 +{
55438 + if (gr_status & GR_READY) {
55439 + task->role = kernel_role;
55440 + task->acl = kernel_role->root_label;
55441 + }
55442 + return;
55443 +}
55444 +
55445 +#ifdef CONFIG_TASKSTATS
55446 +int gr_is_taskstats_denied(int pid)
55447 +{
55448 + struct task_struct *task;
55449 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55450 + const struct cred *cred;
55451 +#endif
55452 + int ret = 0;
55453 +
55454 + /* restrict taskstats viewing to un-chrooted root users
55455 + who have the 'view' subject flag if the RBAC system is enabled
55456 + */
55457 +
55458 + rcu_read_lock();
55459 + read_lock(&tasklist_lock);
55460 + task = find_task_by_vpid(pid);
55461 + if (task) {
55462 +#ifdef CONFIG_GRKERNSEC_CHROOT
55463 + if (proc_is_chrooted(task))
55464 + ret = -EACCES;
55465 +#endif
55466 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55467 + cred = __task_cred(task);
55468 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55469 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55470 + ret = -EACCES;
55471 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55472 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55473 + ret = -EACCES;
55474 +#endif
55475 +#endif
55476 + if (gr_status & GR_READY) {
55477 + if (!(task->acl->mode & GR_VIEW))
55478 + ret = -EACCES;
55479 + }
55480 + } else
55481 + ret = -ENOENT;
55482 +
55483 + read_unlock(&tasklist_lock);
55484 + rcu_read_unlock();
55485 +
55486 + return ret;
55487 +}
55488 +#endif
55489 +
55490 +/* AUXV entries are filled via a descendant of search_binary_handler
55491 + after we've already applied the subject for the target
55492 +*/
55493 +int gr_acl_enable_at_secure(void)
55494 +{
55495 + if (unlikely(!(gr_status & GR_READY)))
55496 + return 0;
55497 +
55498 + if (current->acl->mode & GR_ATSECURE)
55499 + return 1;
55500 +
55501 + return 0;
55502 +}
55503 +
55504 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55505 +{
55506 + struct task_struct *task = current;
55507 + struct dentry *dentry = file->f_path.dentry;
55508 + struct vfsmount *mnt = file->f_path.mnt;
55509 + struct acl_object_label *obj, *tmp;
55510 + struct acl_subject_label *subj;
55511 + unsigned int bufsize;
55512 + int is_not_root;
55513 + char *path;
55514 + dev_t dev = __get_dev(dentry);
55515 +
55516 + if (unlikely(!(gr_status & GR_READY)))
55517 + return 1;
55518 +
55519 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55520 + return 1;
55521 +
55522 + /* ignore Eric Biederman */
55523 + if (IS_PRIVATE(dentry->d_inode))
55524 + return 1;
55525 +
55526 + subj = task->acl;
55527 + read_lock(&gr_inode_lock);
55528 + do {
55529 + obj = lookup_acl_obj_label(ino, dev, subj);
55530 + if (obj != NULL) {
55531 + read_unlock(&gr_inode_lock);
55532 + return (obj->mode & GR_FIND) ? 1 : 0;
55533 + }
55534 + } while ((subj = subj->parent_subject));
55535 + read_unlock(&gr_inode_lock);
55536 +
55537 + /* this is purely an optimization since we're looking for an object
55538 + for the directory we're doing a readdir on
55539 + if it's possible for any globbed object to match the entry we're
55540 + filling into the directory, then the object we find here will be
55541 + an anchor point with attached globbed objects
55542 + */
55543 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55544 + if (obj->globbed == NULL)
55545 + return (obj->mode & GR_FIND) ? 1 : 0;
55546 +
55547 + is_not_root = ((obj->filename[0] == '/') &&
55548 + (obj->filename[1] == '\0')) ? 0 : 1;
55549 + bufsize = PAGE_SIZE - namelen - is_not_root;
55550 +
55551 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55552 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55553 + return 1;
55554 +
55555 + preempt_disable();
55556 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55557 + bufsize);
55558 +
55559 + bufsize = strlen(path);
55560 +
55561 + /* if base is "/", don't append an additional slash */
55562 + if (is_not_root)
55563 + *(path + bufsize) = '/';
55564 + memcpy(path + bufsize + is_not_root, name, namelen);
55565 + *(path + bufsize + namelen + is_not_root) = '\0';
55566 +
55567 + tmp = obj->globbed;
55568 + while (tmp) {
55569 + if (!glob_match(tmp->filename, path)) {
55570 + preempt_enable();
55571 + return (tmp->mode & GR_FIND) ? 1 : 0;
55572 + }
55573 + tmp = tmp->next;
55574 + }
55575 + preempt_enable();
55576 + return (obj->mode & GR_FIND) ? 1 : 0;
55577 +}
55578 +
55579 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55580 +EXPORT_SYMBOL(gr_acl_is_enabled);
55581 +#endif
55582 +EXPORT_SYMBOL(gr_learn_resource);
55583 +EXPORT_SYMBOL(gr_set_kernel_label);
55584 +#ifdef CONFIG_SECURITY
55585 +EXPORT_SYMBOL(gr_check_user_change);
55586 +EXPORT_SYMBOL(gr_check_group_change);
55587 +#endif
55588 +
55589 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55590 new file mode 100644
55591 index 0000000..34fefda
55592 --- /dev/null
55593 +++ b/grsecurity/gracl_alloc.c
55594 @@ -0,0 +1,105 @@
55595 +#include <linux/kernel.h>
55596 +#include <linux/mm.h>
55597 +#include <linux/slab.h>
55598 +#include <linux/vmalloc.h>
55599 +#include <linux/gracl.h>
55600 +#include <linux/grsecurity.h>
55601 +
55602 +static unsigned long alloc_stack_next = 1;
55603 +static unsigned long alloc_stack_size = 1;
55604 +static void **alloc_stack;
55605 +
55606 +static __inline__ int
55607 +alloc_pop(void)
55608 +{
55609 + if (alloc_stack_next == 1)
55610 + return 0;
55611 +
55612 + kfree(alloc_stack[alloc_stack_next - 2]);
55613 +
55614 + alloc_stack_next--;
55615 +
55616 + return 1;
55617 +}
55618 +
55619 +static __inline__ int
55620 +alloc_push(void *buf)
55621 +{
55622 + if (alloc_stack_next >= alloc_stack_size)
55623 + return 1;
55624 +
55625 + alloc_stack[alloc_stack_next - 1] = buf;
55626 +
55627 + alloc_stack_next++;
55628 +
55629 + return 0;
55630 +}
55631 +
55632 +void *
55633 +acl_alloc(unsigned long len)
55634 +{
55635 + void *ret = NULL;
55636 +
55637 + if (!len || len > PAGE_SIZE)
55638 + goto out;
55639 +
55640 + ret = kmalloc(len, GFP_KERNEL);
55641 +
55642 + if (ret) {
55643 + if (alloc_push(ret)) {
55644 + kfree(ret);
55645 + ret = NULL;
55646 + }
55647 + }
55648 +
55649 +out:
55650 + return ret;
55651 +}
55652 +
55653 +void *
55654 +acl_alloc_num(unsigned long num, unsigned long len)
55655 +{
55656 + if (!len || (num > (PAGE_SIZE / len)))
55657 + return NULL;
55658 +
55659 + return acl_alloc(num * len);
55660 +}
55661 +
55662 +void
55663 +acl_free_all(void)
55664 +{
55665 + if (gr_acl_is_enabled() || !alloc_stack)
55666 + return;
55667 +
55668 + while (alloc_pop()) ;
55669 +
55670 + if (alloc_stack) {
55671 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55672 + kfree(alloc_stack);
55673 + else
55674 + vfree(alloc_stack);
55675 + }
55676 +
55677 + alloc_stack = NULL;
55678 + alloc_stack_size = 1;
55679 + alloc_stack_next = 1;
55680 +
55681 + return;
55682 +}
55683 +
55684 +int
55685 +acl_alloc_stack_init(unsigned long size)
55686 +{
55687 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55688 + alloc_stack =
55689 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55690 + else
55691 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55692 +
55693 + alloc_stack_size = size;
55694 +
55695 + if (!alloc_stack)
55696 + return 0;
55697 + else
55698 + return 1;
55699 +}
55700 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55701 new file mode 100644
55702 index 0000000..6d21049
55703 --- /dev/null
55704 +++ b/grsecurity/gracl_cap.c
55705 @@ -0,0 +1,110 @@
55706 +#include <linux/kernel.h>
55707 +#include <linux/module.h>
55708 +#include <linux/sched.h>
55709 +#include <linux/gracl.h>
55710 +#include <linux/grsecurity.h>
55711 +#include <linux/grinternal.h>
55712 +
55713 +extern const char *captab_log[];
55714 +extern int captab_log_entries;
55715 +
55716 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55717 +{
55718 + struct acl_subject_label *curracl;
55719 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55720 + kernel_cap_t cap_audit = __cap_empty_set;
55721 +
55722 + if (!gr_acl_is_enabled())
55723 + return 1;
55724 +
55725 + curracl = task->acl;
55726 +
55727 + cap_drop = curracl->cap_lower;
55728 + cap_mask = curracl->cap_mask;
55729 + cap_audit = curracl->cap_invert_audit;
55730 +
55731 + while ((curracl = curracl->parent_subject)) {
55732 + /* if the cap isn't specified in the current computed mask but is specified in the
55733 + current level subject, and is lowered in the current level subject, then add
55734 + it to the set of dropped capabilities
55735 + otherwise, add the current level subject's mask to the current computed mask
55736 + */
55737 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55738 + cap_raise(cap_mask, cap);
55739 + if (cap_raised(curracl->cap_lower, cap))
55740 + cap_raise(cap_drop, cap);
55741 + if (cap_raised(curracl->cap_invert_audit, cap))
55742 + cap_raise(cap_audit, cap);
55743 + }
55744 + }
55745 +
55746 + if (!cap_raised(cap_drop, cap)) {
55747 + if (cap_raised(cap_audit, cap))
55748 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55749 + return 1;
55750 + }
55751 +
55752 + curracl = task->acl;
55753 +
55754 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55755 + && cap_raised(cred->cap_effective, cap)) {
55756 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55757 + task->role->roletype, cred->uid,
55758 + cred->gid, task->exec_file ?
55759 + gr_to_filename(task->exec_file->f_path.dentry,
55760 + task->exec_file->f_path.mnt) : curracl->filename,
55761 + curracl->filename, 0UL,
55762 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55763 + return 1;
55764 + }
55765 +
55766 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55767 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55768 +
55769 + return 0;
55770 +}
55771 +
55772 +int
55773 +gr_acl_is_capable(const int cap)
55774 +{
55775 + return gr_task_acl_is_capable(current, current_cred(), cap);
55776 +}
55777 +
55778 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55779 +{
55780 + struct acl_subject_label *curracl;
55781 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55782 +
55783 + if (!gr_acl_is_enabled())
55784 + return 1;
55785 +
55786 + curracl = task->acl;
55787 +
55788 + cap_drop = curracl->cap_lower;
55789 + cap_mask = curracl->cap_mask;
55790 +
55791 + while ((curracl = curracl->parent_subject)) {
55792 + /* if the cap isn't specified in the current computed mask but is specified in the
55793 + current level subject, and is lowered in the current level subject, then add
55794 + it to the set of dropped capabilities
55795 + otherwise, add the current level subject's mask to the current computed mask
55796 + */
55797 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55798 + cap_raise(cap_mask, cap);
55799 + if (cap_raised(curracl->cap_lower, cap))
55800 + cap_raise(cap_drop, cap);
55801 + }
55802 + }
55803 +
55804 + if (!cap_raised(cap_drop, cap))
55805 + return 1;
55806 +
55807 + return 0;
55808 +}
55809 +
55810 +int
55811 +gr_acl_is_capable_nolog(const int cap)
55812 +{
55813 + return gr_task_acl_is_capable_nolog(current, cap);
55814 +}
55815 +
55816 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55817 new file mode 100644
55818 index 0000000..d28e241
55819 --- /dev/null
55820 +++ b/grsecurity/gracl_fs.c
55821 @@ -0,0 +1,437 @@
55822 +#include <linux/kernel.h>
55823 +#include <linux/sched.h>
55824 +#include <linux/types.h>
55825 +#include <linux/fs.h>
55826 +#include <linux/file.h>
55827 +#include <linux/stat.h>
55828 +#include <linux/grsecurity.h>
55829 +#include <linux/grinternal.h>
55830 +#include <linux/gracl.h>
55831 +
55832 +umode_t
55833 +gr_acl_umask(void)
55834 +{
55835 + if (unlikely(!gr_acl_is_enabled()))
55836 + return 0;
55837 +
55838 + return current->role->umask;
55839 +}
55840 +
55841 +__u32
55842 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55843 + const struct vfsmount * mnt)
55844 +{
55845 + __u32 mode;
55846 +
55847 + if (unlikely(!dentry->d_inode))
55848 + return GR_FIND;
55849 +
55850 + mode =
55851 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55852 +
55853 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55854 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55855 + return mode;
55856 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55857 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55858 + return 0;
55859 + } else if (unlikely(!(mode & GR_FIND)))
55860 + return 0;
55861 +
55862 + return GR_FIND;
55863 +}
55864 +
55865 +__u32
55866 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55867 + int acc_mode)
55868 +{
55869 + __u32 reqmode = GR_FIND;
55870 + __u32 mode;
55871 +
55872 + if (unlikely(!dentry->d_inode))
55873 + return reqmode;
55874 +
55875 + if (acc_mode & MAY_APPEND)
55876 + reqmode |= GR_APPEND;
55877 + else if (acc_mode & MAY_WRITE)
55878 + reqmode |= GR_WRITE;
55879 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55880 + reqmode |= GR_READ;
55881 +
55882 + mode =
55883 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55884 + mnt);
55885 +
55886 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55887 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55888 + reqmode & GR_READ ? " reading" : "",
55889 + reqmode & GR_WRITE ? " writing" : reqmode &
55890 + GR_APPEND ? " appending" : "");
55891 + return reqmode;
55892 + } else
55893 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55894 + {
55895 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55896 + reqmode & GR_READ ? " reading" : "",
55897 + reqmode & GR_WRITE ? " writing" : reqmode &
55898 + GR_APPEND ? " appending" : "");
55899 + return 0;
55900 + } else if (unlikely((mode & reqmode) != reqmode))
55901 + return 0;
55902 +
55903 + return reqmode;
55904 +}
55905 +
55906 +__u32
55907 +gr_acl_handle_creat(const struct dentry * dentry,
55908 + const struct dentry * p_dentry,
55909 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55910 + const int imode)
55911 +{
55912 + __u32 reqmode = GR_WRITE | GR_CREATE;
55913 + __u32 mode;
55914 +
55915 + if (acc_mode & MAY_APPEND)
55916 + reqmode |= GR_APPEND;
55917 + // if a directory was required or the directory already exists, then
55918 + // don't count this open as a read
55919 + if ((acc_mode & MAY_READ) &&
55920 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55921 + reqmode |= GR_READ;
55922 + if ((open_flags & O_CREAT) &&
55923 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55924 + reqmode |= GR_SETID;
55925 +
55926 + mode =
55927 + gr_check_create(dentry, p_dentry, p_mnt,
55928 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55929 +
55930 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55931 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55932 + reqmode & GR_READ ? " reading" : "",
55933 + reqmode & GR_WRITE ? " writing" : reqmode &
55934 + GR_APPEND ? " appending" : "");
55935 + return reqmode;
55936 + } else
55937 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55938 + {
55939 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55940 + reqmode & GR_READ ? " reading" : "",
55941 + reqmode & GR_WRITE ? " writing" : reqmode &
55942 + GR_APPEND ? " appending" : "");
55943 + return 0;
55944 + } else if (unlikely((mode & reqmode) != reqmode))
55945 + return 0;
55946 +
55947 + return reqmode;
55948 +}
55949 +
55950 +__u32
55951 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55952 + const int fmode)
55953 +{
55954 + __u32 mode, reqmode = GR_FIND;
55955 +
55956 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55957 + reqmode |= GR_EXEC;
55958 + if (fmode & S_IWOTH)
55959 + reqmode |= GR_WRITE;
55960 + if (fmode & S_IROTH)
55961 + reqmode |= GR_READ;
55962 +
55963 + mode =
55964 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55965 + mnt);
55966 +
55967 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55968 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55969 + reqmode & GR_READ ? " reading" : "",
55970 + reqmode & GR_WRITE ? " writing" : "",
55971 + reqmode & GR_EXEC ? " executing" : "");
55972 + return reqmode;
55973 + } else
55974 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55975 + {
55976 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55977 + reqmode & GR_READ ? " reading" : "",
55978 + reqmode & GR_WRITE ? " writing" : "",
55979 + reqmode & GR_EXEC ? " executing" : "");
55980 + return 0;
55981 + } else if (unlikely((mode & reqmode) != reqmode))
55982 + return 0;
55983 +
55984 + return reqmode;
55985 +}
55986 +
55987 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55988 +{
55989 + __u32 mode;
55990 +
55991 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55992 +
55993 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55994 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55995 + return mode;
55996 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55997 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55998 + return 0;
55999 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56000 + return 0;
56001 +
56002 + return (reqmode);
56003 +}
56004 +
56005 +__u32
56006 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56007 +{
56008 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56009 +}
56010 +
56011 +__u32
56012 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56013 +{
56014 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56015 +}
56016 +
56017 +__u32
56018 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56019 +{
56020 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56021 +}
56022 +
56023 +__u32
56024 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56025 +{
56026 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56027 +}
56028 +
56029 +__u32
56030 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56031 + umode_t *modeptr)
56032 +{
56033 + umode_t mode;
56034 +
56035 + *modeptr &= ~gr_acl_umask();
56036 + mode = *modeptr;
56037 +
56038 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56039 + return 1;
56040 +
56041 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56042 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56043 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56044 + GR_CHMOD_ACL_MSG);
56045 + } else {
56046 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56047 + }
56048 +}
56049 +
56050 +__u32
56051 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56052 +{
56053 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56054 +}
56055 +
56056 +__u32
56057 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56058 +{
56059 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56060 +}
56061 +
56062 +__u32
56063 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56064 +{
56065 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56066 +}
56067 +
56068 +__u32
56069 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56070 +{
56071 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56072 + GR_UNIXCONNECT_ACL_MSG);
56073 +}
56074 +
56075 +/* hardlinks require at minimum create and link permission,
56076 + any additional privilege required is based on the
56077 + privilege of the file being linked to
56078 +*/
56079 +__u32
56080 +gr_acl_handle_link(const struct dentry * new_dentry,
56081 + const struct dentry * parent_dentry,
56082 + const struct vfsmount * parent_mnt,
56083 + const struct dentry * old_dentry,
56084 + const struct vfsmount * old_mnt, const char *to)
56085 +{
56086 + __u32 mode;
56087 + __u32 needmode = GR_CREATE | GR_LINK;
56088 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56089 +
56090 + mode =
56091 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56092 + old_mnt);
56093 +
56094 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56095 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56096 + return mode;
56097 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56098 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56099 + return 0;
56100 + } else if (unlikely((mode & needmode) != needmode))
56101 + return 0;
56102 +
56103 + return 1;
56104 +}
56105 +
56106 +__u32
56107 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56108 + const struct dentry * parent_dentry,
56109 + const struct vfsmount * parent_mnt, const char *from)
56110 +{
56111 + __u32 needmode = GR_WRITE | GR_CREATE;
56112 + __u32 mode;
56113 +
56114 + mode =
56115 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56116 + GR_CREATE | GR_AUDIT_CREATE |
56117 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56118 +
56119 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56120 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56121 + return mode;
56122 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56123 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56124 + return 0;
56125 + } else if (unlikely((mode & needmode) != needmode))
56126 + return 0;
56127 +
56128 + return (GR_WRITE | GR_CREATE);
56129 +}
56130 +
56131 +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)
56132 +{
56133 + __u32 mode;
56134 +
56135 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56136 +
56137 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56138 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56139 + return mode;
56140 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56141 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56142 + return 0;
56143 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56144 + return 0;
56145 +
56146 + return (reqmode);
56147 +}
56148 +
56149 +__u32
56150 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56151 + const struct dentry * parent_dentry,
56152 + const struct vfsmount * parent_mnt,
56153 + const int mode)
56154 +{
56155 + __u32 reqmode = GR_WRITE | GR_CREATE;
56156 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56157 + reqmode |= GR_SETID;
56158 +
56159 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56160 + reqmode, GR_MKNOD_ACL_MSG);
56161 +}
56162 +
56163 +__u32
56164 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56165 + const struct dentry *parent_dentry,
56166 + const struct vfsmount *parent_mnt)
56167 +{
56168 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56169 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56170 +}
56171 +
56172 +#define RENAME_CHECK_SUCCESS(old, new) \
56173 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56174 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56175 +
56176 +int
56177 +gr_acl_handle_rename(struct dentry *new_dentry,
56178 + struct dentry *parent_dentry,
56179 + const struct vfsmount *parent_mnt,
56180 + struct dentry *old_dentry,
56181 + struct inode *old_parent_inode,
56182 + struct vfsmount *old_mnt, const char *newname)
56183 +{
56184 + __u32 comp1, comp2;
56185 + int error = 0;
56186 +
56187 + if (unlikely(!gr_acl_is_enabled()))
56188 + return 0;
56189 +
56190 + if (!new_dentry->d_inode) {
56191 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56192 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56193 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56194 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56195 + GR_DELETE | GR_AUDIT_DELETE |
56196 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56197 + GR_SUPPRESS, old_mnt);
56198 + } else {
56199 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56200 + GR_CREATE | GR_DELETE |
56201 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56202 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56203 + GR_SUPPRESS, parent_mnt);
56204 + comp2 =
56205 + gr_search_file(old_dentry,
56206 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56207 + GR_DELETE | GR_AUDIT_DELETE |
56208 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56209 + }
56210 +
56211 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56212 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56213 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56214 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56215 + && !(comp2 & GR_SUPPRESS)) {
56216 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56217 + error = -EACCES;
56218 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56219 + error = -EACCES;
56220 +
56221 + return error;
56222 +}
56223 +
56224 +void
56225 +gr_acl_handle_exit(void)
56226 +{
56227 + u16 id;
56228 + char *rolename;
56229 + struct file *exec_file;
56230 +
56231 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56232 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56233 + id = current->acl_role_id;
56234 + rolename = current->role->rolename;
56235 + gr_set_acls(1);
56236 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56237 + }
56238 +
56239 + write_lock(&grsec_exec_file_lock);
56240 + exec_file = current->exec_file;
56241 + current->exec_file = NULL;
56242 + write_unlock(&grsec_exec_file_lock);
56243 +
56244 + if (exec_file)
56245 + fput(exec_file);
56246 +}
56247 +
56248 +int
56249 +gr_acl_handle_procpidmem(const struct task_struct *task)
56250 +{
56251 + if (unlikely(!gr_acl_is_enabled()))
56252 + return 0;
56253 +
56254 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56255 + return -EACCES;
56256 +
56257 + return 0;
56258 +}
56259 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56260 new file mode 100644
56261 index 0000000..58800a7
56262 --- /dev/null
56263 +++ b/grsecurity/gracl_ip.c
56264 @@ -0,0 +1,384 @@
56265 +#include <linux/kernel.h>
56266 +#include <asm/uaccess.h>
56267 +#include <asm/errno.h>
56268 +#include <net/sock.h>
56269 +#include <linux/file.h>
56270 +#include <linux/fs.h>
56271 +#include <linux/net.h>
56272 +#include <linux/in.h>
56273 +#include <linux/skbuff.h>
56274 +#include <linux/ip.h>
56275 +#include <linux/udp.h>
56276 +#include <linux/types.h>
56277 +#include <linux/sched.h>
56278 +#include <linux/netdevice.h>
56279 +#include <linux/inetdevice.h>
56280 +#include <linux/gracl.h>
56281 +#include <linux/grsecurity.h>
56282 +#include <linux/grinternal.h>
56283 +
56284 +#define GR_BIND 0x01
56285 +#define GR_CONNECT 0x02
56286 +#define GR_INVERT 0x04
56287 +#define GR_BINDOVERRIDE 0x08
56288 +#define GR_CONNECTOVERRIDE 0x10
56289 +#define GR_SOCK_FAMILY 0x20
56290 +
56291 +static const char * gr_protocols[IPPROTO_MAX] = {
56292 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56293 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56294 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56295 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56296 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56297 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56298 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56299 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56300 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56301 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56302 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56303 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56304 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56305 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56306 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56307 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56308 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56309 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56310 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56311 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56312 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56313 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56314 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56315 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56316 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56317 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56318 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56319 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56320 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56321 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56322 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56323 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56324 + };
56325 +
56326 +static const char * gr_socktypes[SOCK_MAX] = {
56327 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56328 + "unknown:7", "unknown:8", "unknown:9", "packet"
56329 + };
56330 +
56331 +static const char * gr_sockfamilies[AF_MAX+1] = {
56332 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56333 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56334 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56335 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56336 + };
56337 +
56338 +const char *
56339 +gr_proto_to_name(unsigned char proto)
56340 +{
56341 + return gr_protocols[proto];
56342 +}
56343 +
56344 +const char *
56345 +gr_socktype_to_name(unsigned char type)
56346 +{
56347 + return gr_socktypes[type];
56348 +}
56349 +
56350 +const char *
56351 +gr_sockfamily_to_name(unsigned char family)
56352 +{
56353 + return gr_sockfamilies[family];
56354 +}
56355 +
56356 +int
56357 +gr_search_socket(const int domain, const int type, const int protocol)
56358 +{
56359 + struct acl_subject_label *curr;
56360 + const struct cred *cred = current_cred();
56361 +
56362 + if (unlikely(!gr_acl_is_enabled()))
56363 + goto exit;
56364 +
56365 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56366 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56367 + goto exit; // let the kernel handle it
56368 +
56369 + curr = current->acl;
56370 +
56371 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56372 + /* the family is allowed, if this is PF_INET allow it only if
56373 + the extra sock type/protocol checks pass */
56374 + if (domain == PF_INET)
56375 + goto inet_check;
56376 + goto exit;
56377 + } else {
56378 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56379 + __u32 fakeip = 0;
56380 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56381 + current->role->roletype, cred->uid,
56382 + cred->gid, current->exec_file ?
56383 + gr_to_filename(current->exec_file->f_path.dentry,
56384 + current->exec_file->f_path.mnt) :
56385 + curr->filename, curr->filename,
56386 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56387 + &current->signal->saved_ip);
56388 + goto exit;
56389 + }
56390 + goto exit_fail;
56391 + }
56392 +
56393 +inet_check:
56394 + /* the rest of this checking is for IPv4 only */
56395 + if (!curr->ips)
56396 + goto exit;
56397 +
56398 + if ((curr->ip_type & (1 << type)) &&
56399 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56400 + goto exit;
56401 +
56402 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56403 + /* we don't place acls on raw sockets , and sometimes
56404 + dgram/ip sockets are opened for ioctl and not
56405 + bind/connect, so we'll fake a bind learn log */
56406 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56407 + __u32 fakeip = 0;
56408 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56409 + current->role->roletype, cred->uid,
56410 + cred->gid, current->exec_file ?
56411 + gr_to_filename(current->exec_file->f_path.dentry,
56412 + current->exec_file->f_path.mnt) :
56413 + curr->filename, curr->filename,
56414 + &fakeip, 0, type,
56415 + protocol, GR_CONNECT, &current->signal->saved_ip);
56416 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56417 + __u32 fakeip = 0;
56418 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56419 + current->role->roletype, cred->uid,
56420 + cred->gid, current->exec_file ?
56421 + gr_to_filename(current->exec_file->f_path.dentry,
56422 + current->exec_file->f_path.mnt) :
56423 + curr->filename, curr->filename,
56424 + &fakeip, 0, type,
56425 + protocol, GR_BIND, &current->signal->saved_ip);
56426 + }
56427 + /* we'll log when they use connect or bind */
56428 + goto exit;
56429 + }
56430 +
56431 +exit_fail:
56432 + if (domain == PF_INET)
56433 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56434 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56435 + else
56436 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56437 + gr_socktype_to_name(type), protocol);
56438 +
56439 + return 0;
56440 +exit:
56441 + return 1;
56442 +}
56443 +
56444 +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)
56445 +{
56446 + if ((ip->mode & mode) &&
56447 + (ip_port >= ip->low) &&
56448 + (ip_port <= ip->high) &&
56449 + ((ntohl(ip_addr) & our_netmask) ==
56450 + (ntohl(our_addr) & our_netmask))
56451 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56452 + && (ip->type & (1 << type))) {
56453 + if (ip->mode & GR_INVERT)
56454 + return 2; // specifically denied
56455 + else
56456 + return 1; // allowed
56457 + }
56458 +
56459 + return 0; // not specifically allowed, may continue parsing
56460 +}
56461 +
56462 +static int
56463 +gr_search_connectbind(const int full_mode, struct sock *sk,
56464 + struct sockaddr_in *addr, const int type)
56465 +{
56466 + char iface[IFNAMSIZ] = {0};
56467 + struct acl_subject_label *curr;
56468 + struct acl_ip_label *ip;
56469 + struct inet_sock *isk;
56470 + struct net_device *dev;
56471 + struct in_device *idev;
56472 + unsigned long i;
56473 + int ret;
56474 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56475 + __u32 ip_addr = 0;
56476 + __u32 our_addr;
56477 + __u32 our_netmask;
56478 + char *p;
56479 + __u16 ip_port = 0;
56480 + const struct cred *cred = current_cred();
56481 +
56482 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56483 + return 0;
56484 +
56485 + curr = current->acl;
56486 + isk = inet_sk(sk);
56487 +
56488 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56489 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56490 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56491 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56492 + struct sockaddr_in saddr;
56493 + int err;
56494 +
56495 + saddr.sin_family = AF_INET;
56496 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56497 + saddr.sin_port = isk->inet_sport;
56498 +
56499 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56500 + if (err)
56501 + return err;
56502 +
56503 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56504 + if (err)
56505 + return err;
56506 + }
56507 +
56508 + if (!curr->ips)
56509 + return 0;
56510 +
56511 + ip_addr = addr->sin_addr.s_addr;
56512 + ip_port = ntohs(addr->sin_port);
56513 +
56514 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56515 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56516 + current->role->roletype, cred->uid,
56517 + cred->gid, current->exec_file ?
56518 + gr_to_filename(current->exec_file->f_path.dentry,
56519 + current->exec_file->f_path.mnt) :
56520 + curr->filename, curr->filename,
56521 + &ip_addr, ip_port, type,
56522 + sk->sk_protocol, mode, &current->signal->saved_ip);
56523 + return 0;
56524 + }
56525 +
56526 + for (i = 0; i < curr->ip_num; i++) {
56527 + ip = *(curr->ips + i);
56528 + if (ip->iface != NULL) {
56529 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56530 + p = strchr(iface, ':');
56531 + if (p != NULL)
56532 + *p = '\0';
56533 + dev = dev_get_by_name(sock_net(sk), iface);
56534 + if (dev == NULL)
56535 + continue;
56536 + idev = in_dev_get(dev);
56537 + if (idev == NULL) {
56538 + dev_put(dev);
56539 + continue;
56540 + }
56541 + rcu_read_lock();
56542 + for_ifa(idev) {
56543 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56544 + our_addr = ifa->ifa_address;
56545 + our_netmask = 0xffffffff;
56546 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56547 + if (ret == 1) {
56548 + rcu_read_unlock();
56549 + in_dev_put(idev);
56550 + dev_put(dev);
56551 + return 0;
56552 + } else if (ret == 2) {
56553 + rcu_read_unlock();
56554 + in_dev_put(idev);
56555 + dev_put(dev);
56556 + goto denied;
56557 + }
56558 + }
56559 + } endfor_ifa(idev);
56560 + rcu_read_unlock();
56561 + in_dev_put(idev);
56562 + dev_put(dev);
56563 + } else {
56564 + our_addr = ip->addr;
56565 + our_netmask = ip->netmask;
56566 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56567 + if (ret == 1)
56568 + return 0;
56569 + else if (ret == 2)
56570 + goto denied;
56571 + }
56572 + }
56573 +
56574 +denied:
56575 + if (mode == GR_BIND)
56576 + 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));
56577 + else if (mode == GR_CONNECT)
56578 + 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));
56579 +
56580 + return -EACCES;
56581 +}
56582 +
56583 +int
56584 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56585 +{
56586 + /* always allow disconnection of dgram sockets with connect */
56587 + if (addr->sin_family == AF_UNSPEC)
56588 + return 0;
56589 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56590 +}
56591 +
56592 +int
56593 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56594 +{
56595 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56596 +}
56597 +
56598 +int gr_search_listen(struct socket *sock)
56599 +{
56600 + struct sock *sk = sock->sk;
56601 + struct sockaddr_in addr;
56602 +
56603 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56604 + addr.sin_port = inet_sk(sk)->inet_sport;
56605 +
56606 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56607 +}
56608 +
56609 +int gr_search_accept(struct socket *sock)
56610 +{
56611 + struct sock *sk = sock->sk;
56612 + struct sockaddr_in addr;
56613 +
56614 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56615 + addr.sin_port = inet_sk(sk)->inet_sport;
56616 +
56617 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56618 +}
56619 +
56620 +int
56621 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56622 +{
56623 + if (addr)
56624 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56625 + else {
56626 + struct sockaddr_in sin;
56627 + const struct inet_sock *inet = inet_sk(sk);
56628 +
56629 + sin.sin_addr.s_addr = inet->inet_daddr;
56630 + sin.sin_port = inet->inet_dport;
56631 +
56632 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56633 + }
56634 +}
56635 +
56636 +int
56637 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56638 +{
56639 + struct sockaddr_in sin;
56640 +
56641 + if (unlikely(skb->len < sizeof (struct udphdr)))
56642 + return 0; // skip this packet
56643 +
56644 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56645 + sin.sin_port = udp_hdr(skb)->source;
56646 +
56647 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56648 +}
56649 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56650 new file mode 100644
56651 index 0000000..25f54ef
56652 --- /dev/null
56653 +++ b/grsecurity/gracl_learn.c
56654 @@ -0,0 +1,207 @@
56655 +#include <linux/kernel.h>
56656 +#include <linux/mm.h>
56657 +#include <linux/sched.h>
56658 +#include <linux/poll.h>
56659 +#include <linux/string.h>
56660 +#include <linux/file.h>
56661 +#include <linux/types.h>
56662 +#include <linux/vmalloc.h>
56663 +#include <linux/grinternal.h>
56664 +
56665 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56666 + size_t count, loff_t *ppos);
56667 +extern int gr_acl_is_enabled(void);
56668 +
56669 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56670 +static int gr_learn_attached;
56671 +
56672 +/* use a 512k buffer */
56673 +#define LEARN_BUFFER_SIZE (512 * 1024)
56674 +
56675 +static DEFINE_SPINLOCK(gr_learn_lock);
56676 +static DEFINE_MUTEX(gr_learn_user_mutex);
56677 +
56678 +/* we need to maintain two buffers, so that the kernel context of grlearn
56679 + uses a semaphore around the userspace copying, and the other kernel contexts
56680 + use a spinlock when copying into the buffer, since they cannot sleep
56681 +*/
56682 +static char *learn_buffer;
56683 +static char *learn_buffer_user;
56684 +static int learn_buffer_len;
56685 +static int learn_buffer_user_len;
56686 +
56687 +static ssize_t
56688 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56689 +{
56690 + DECLARE_WAITQUEUE(wait, current);
56691 + ssize_t retval = 0;
56692 +
56693 + add_wait_queue(&learn_wait, &wait);
56694 + set_current_state(TASK_INTERRUPTIBLE);
56695 + do {
56696 + mutex_lock(&gr_learn_user_mutex);
56697 + spin_lock(&gr_learn_lock);
56698 + if (learn_buffer_len)
56699 + break;
56700 + spin_unlock(&gr_learn_lock);
56701 + mutex_unlock(&gr_learn_user_mutex);
56702 + if (file->f_flags & O_NONBLOCK) {
56703 + retval = -EAGAIN;
56704 + goto out;
56705 + }
56706 + if (signal_pending(current)) {
56707 + retval = -ERESTARTSYS;
56708 + goto out;
56709 + }
56710 +
56711 + schedule();
56712 + } while (1);
56713 +
56714 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56715 + learn_buffer_user_len = learn_buffer_len;
56716 + retval = learn_buffer_len;
56717 + learn_buffer_len = 0;
56718 +
56719 + spin_unlock(&gr_learn_lock);
56720 +
56721 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56722 + retval = -EFAULT;
56723 +
56724 + mutex_unlock(&gr_learn_user_mutex);
56725 +out:
56726 + set_current_state(TASK_RUNNING);
56727 + remove_wait_queue(&learn_wait, &wait);
56728 + return retval;
56729 +}
56730 +
56731 +static unsigned int
56732 +poll_learn(struct file * file, poll_table * wait)
56733 +{
56734 + poll_wait(file, &learn_wait, wait);
56735 +
56736 + if (learn_buffer_len)
56737 + return (POLLIN | POLLRDNORM);
56738 +
56739 + return 0;
56740 +}
56741 +
56742 +void
56743 +gr_clear_learn_entries(void)
56744 +{
56745 + char *tmp;
56746 +
56747 + mutex_lock(&gr_learn_user_mutex);
56748 + spin_lock(&gr_learn_lock);
56749 + tmp = learn_buffer;
56750 + learn_buffer = NULL;
56751 + spin_unlock(&gr_learn_lock);
56752 + if (tmp)
56753 + vfree(tmp);
56754 + if (learn_buffer_user != NULL) {
56755 + vfree(learn_buffer_user);
56756 + learn_buffer_user = NULL;
56757 + }
56758 + learn_buffer_len = 0;
56759 + mutex_unlock(&gr_learn_user_mutex);
56760 +
56761 + return;
56762 +}
56763 +
56764 +void
56765 +gr_add_learn_entry(const char *fmt, ...)
56766 +{
56767 + va_list args;
56768 + unsigned int len;
56769 +
56770 + if (!gr_learn_attached)
56771 + return;
56772 +
56773 + spin_lock(&gr_learn_lock);
56774 +
56775 + /* leave a gap at the end so we know when it's "full" but don't have to
56776 + compute the exact length of the string we're trying to append
56777 + */
56778 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56779 + spin_unlock(&gr_learn_lock);
56780 + wake_up_interruptible(&learn_wait);
56781 + return;
56782 + }
56783 + if (learn_buffer == NULL) {
56784 + spin_unlock(&gr_learn_lock);
56785 + return;
56786 + }
56787 +
56788 + va_start(args, fmt);
56789 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56790 + va_end(args);
56791 +
56792 + learn_buffer_len += len + 1;
56793 +
56794 + spin_unlock(&gr_learn_lock);
56795 + wake_up_interruptible(&learn_wait);
56796 +
56797 + return;
56798 +}
56799 +
56800 +static int
56801 +open_learn(struct inode *inode, struct file *file)
56802 +{
56803 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56804 + return -EBUSY;
56805 + if (file->f_mode & FMODE_READ) {
56806 + int retval = 0;
56807 + mutex_lock(&gr_learn_user_mutex);
56808 + if (learn_buffer == NULL)
56809 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56810 + if (learn_buffer_user == NULL)
56811 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56812 + if (learn_buffer == NULL) {
56813 + retval = -ENOMEM;
56814 + goto out_error;
56815 + }
56816 + if (learn_buffer_user == NULL) {
56817 + retval = -ENOMEM;
56818 + goto out_error;
56819 + }
56820 + learn_buffer_len = 0;
56821 + learn_buffer_user_len = 0;
56822 + gr_learn_attached = 1;
56823 +out_error:
56824 + mutex_unlock(&gr_learn_user_mutex);
56825 + return retval;
56826 + }
56827 + return 0;
56828 +}
56829 +
56830 +static int
56831 +close_learn(struct inode *inode, struct file *file)
56832 +{
56833 + if (file->f_mode & FMODE_READ) {
56834 + char *tmp = NULL;
56835 + mutex_lock(&gr_learn_user_mutex);
56836 + spin_lock(&gr_learn_lock);
56837 + tmp = learn_buffer;
56838 + learn_buffer = NULL;
56839 + spin_unlock(&gr_learn_lock);
56840 + if (tmp)
56841 + vfree(tmp);
56842 + if (learn_buffer_user != NULL) {
56843 + vfree(learn_buffer_user);
56844 + learn_buffer_user = NULL;
56845 + }
56846 + learn_buffer_len = 0;
56847 + learn_buffer_user_len = 0;
56848 + gr_learn_attached = 0;
56849 + mutex_unlock(&gr_learn_user_mutex);
56850 + }
56851 +
56852 + return 0;
56853 +}
56854 +
56855 +const struct file_operations grsec_fops = {
56856 + .read = read_learn,
56857 + .write = write_grsec_handler,
56858 + .open = open_learn,
56859 + .release = close_learn,
56860 + .poll = poll_learn,
56861 +};
56862 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56863 new file mode 100644
56864 index 0000000..39645c9
56865 --- /dev/null
56866 +++ b/grsecurity/gracl_res.c
56867 @@ -0,0 +1,68 @@
56868 +#include <linux/kernel.h>
56869 +#include <linux/sched.h>
56870 +#include <linux/gracl.h>
56871 +#include <linux/grinternal.h>
56872 +
56873 +static const char *restab_log[] = {
56874 + [RLIMIT_CPU] = "RLIMIT_CPU",
56875 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56876 + [RLIMIT_DATA] = "RLIMIT_DATA",
56877 + [RLIMIT_STACK] = "RLIMIT_STACK",
56878 + [RLIMIT_CORE] = "RLIMIT_CORE",
56879 + [RLIMIT_RSS] = "RLIMIT_RSS",
56880 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56881 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56882 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56883 + [RLIMIT_AS] = "RLIMIT_AS",
56884 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56885 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56886 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56887 + [RLIMIT_NICE] = "RLIMIT_NICE",
56888 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56889 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56890 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56891 +};
56892 +
56893 +void
56894 +gr_log_resource(const struct task_struct *task,
56895 + const int res, const unsigned long wanted, const int gt)
56896 +{
56897 + const struct cred *cred;
56898 + unsigned long rlim;
56899 +
56900 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56901 + return;
56902 +
56903 + // not yet supported resource
56904 + if (unlikely(!restab_log[res]))
56905 + return;
56906 +
56907 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56908 + rlim = task_rlimit_max(task, res);
56909 + else
56910 + rlim = task_rlimit(task, res);
56911 +
56912 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56913 + return;
56914 +
56915 + rcu_read_lock();
56916 + cred = __task_cred(task);
56917 +
56918 + if (res == RLIMIT_NPROC &&
56919 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56920 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56921 + goto out_rcu_unlock;
56922 + else if (res == RLIMIT_MEMLOCK &&
56923 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56924 + goto out_rcu_unlock;
56925 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56926 + goto out_rcu_unlock;
56927 + rcu_read_unlock();
56928 +
56929 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56930 +
56931 + return;
56932 +out_rcu_unlock:
56933 + rcu_read_unlock();
56934 + return;
56935 +}
56936 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56937 new file mode 100644
56938 index 0000000..25197e9
56939 --- /dev/null
56940 +++ b/grsecurity/gracl_segv.c
56941 @@ -0,0 +1,299 @@
56942 +#include <linux/kernel.h>
56943 +#include <linux/mm.h>
56944 +#include <asm/uaccess.h>
56945 +#include <asm/errno.h>
56946 +#include <asm/mman.h>
56947 +#include <net/sock.h>
56948 +#include <linux/file.h>
56949 +#include <linux/fs.h>
56950 +#include <linux/net.h>
56951 +#include <linux/in.h>
56952 +#include <linux/slab.h>
56953 +#include <linux/types.h>
56954 +#include <linux/sched.h>
56955 +#include <linux/timer.h>
56956 +#include <linux/gracl.h>
56957 +#include <linux/grsecurity.h>
56958 +#include <linux/grinternal.h>
56959 +
56960 +static struct crash_uid *uid_set;
56961 +static unsigned short uid_used;
56962 +static DEFINE_SPINLOCK(gr_uid_lock);
56963 +extern rwlock_t gr_inode_lock;
56964 +extern struct acl_subject_label *
56965 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56966 + struct acl_role_label *role);
56967 +
56968 +#ifdef CONFIG_BTRFS_FS
56969 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56970 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56971 +#endif
56972 +
56973 +static inline dev_t __get_dev(const struct dentry *dentry)
56974 +{
56975 +#ifdef CONFIG_BTRFS_FS
56976 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56977 + return get_btrfs_dev_from_inode(dentry->d_inode);
56978 + else
56979 +#endif
56980 + return dentry->d_inode->i_sb->s_dev;
56981 +}
56982 +
56983 +int
56984 +gr_init_uidset(void)
56985 +{
56986 + uid_set =
56987 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56988 + uid_used = 0;
56989 +
56990 + return uid_set ? 1 : 0;
56991 +}
56992 +
56993 +void
56994 +gr_free_uidset(void)
56995 +{
56996 + if (uid_set)
56997 + kfree(uid_set);
56998 +
56999 + return;
57000 +}
57001 +
57002 +int
57003 +gr_find_uid(const uid_t uid)
57004 +{
57005 + struct crash_uid *tmp = uid_set;
57006 + uid_t buid;
57007 + int low = 0, high = uid_used - 1, mid;
57008 +
57009 + while (high >= low) {
57010 + mid = (low + high) >> 1;
57011 + buid = tmp[mid].uid;
57012 + if (buid == uid)
57013 + return mid;
57014 + if (buid > uid)
57015 + high = mid - 1;
57016 + if (buid < uid)
57017 + low = mid + 1;
57018 + }
57019 +
57020 + return -1;
57021 +}
57022 +
57023 +static __inline__ void
57024 +gr_insertsort(void)
57025 +{
57026 + unsigned short i, j;
57027 + struct crash_uid index;
57028 +
57029 + for (i = 1; i < uid_used; i++) {
57030 + index = uid_set[i];
57031 + j = i;
57032 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57033 + uid_set[j] = uid_set[j - 1];
57034 + j--;
57035 + }
57036 + uid_set[j] = index;
57037 + }
57038 +
57039 + return;
57040 +}
57041 +
57042 +static __inline__ void
57043 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57044 +{
57045 + int loc;
57046 +
57047 + if (uid_used == GR_UIDTABLE_MAX)
57048 + return;
57049 +
57050 + loc = gr_find_uid(uid);
57051 +
57052 + if (loc >= 0) {
57053 + uid_set[loc].expires = expires;
57054 + return;
57055 + }
57056 +
57057 + uid_set[uid_used].uid = uid;
57058 + uid_set[uid_used].expires = expires;
57059 + uid_used++;
57060 +
57061 + gr_insertsort();
57062 +
57063 + return;
57064 +}
57065 +
57066 +void
57067 +gr_remove_uid(const unsigned short loc)
57068 +{
57069 + unsigned short i;
57070 +
57071 + for (i = loc + 1; i < uid_used; i++)
57072 + uid_set[i - 1] = uid_set[i];
57073 +
57074 + uid_used--;
57075 +
57076 + return;
57077 +}
57078 +
57079 +int
57080 +gr_check_crash_uid(const uid_t uid)
57081 +{
57082 + int loc;
57083 + int ret = 0;
57084 +
57085 + if (unlikely(!gr_acl_is_enabled()))
57086 + return 0;
57087 +
57088 + spin_lock(&gr_uid_lock);
57089 + loc = gr_find_uid(uid);
57090 +
57091 + if (loc < 0)
57092 + goto out_unlock;
57093 +
57094 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57095 + gr_remove_uid(loc);
57096 + else
57097 + ret = 1;
57098 +
57099 +out_unlock:
57100 + spin_unlock(&gr_uid_lock);
57101 + return ret;
57102 +}
57103 +
57104 +static __inline__ int
57105 +proc_is_setxid(const struct cred *cred)
57106 +{
57107 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57108 + !uid_eq(cred->uid, cred->fsuid))
57109 + return 1;
57110 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57111 + !uid_eq(cred->gid, cred->fsgid))
57112 + return 1;
57113 +
57114 + return 0;
57115 +}
57116 +
57117 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57118 +
57119 +void
57120 +gr_handle_crash(struct task_struct *task, const int sig)
57121 +{
57122 + struct acl_subject_label *curr;
57123 + struct task_struct *tsk, *tsk2;
57124 + const struct cred *cred;
57125 + const struct cred *cred2;
57126 +
57127 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57128 + return;
57129 +
57130 + if (unlikely(!gr_acl_is_enabled()))
57131 + return;
57132 +
57133 + curr = task->acl;
57134 +
57135 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57136 + return;
57137 +
57138 + if (time_before_eq(curr->expires, get_seconds())) {
57139 + curr->expires = 0;
57140 + curr->crashes = 0;
57141 + }
57142 +
57143 + curr->crashes++;
57144 +
57145 + if (!curr->expires)
57146 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57147 +
57148 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57149 + time_after(curr->expires, get_seconds())) {
57150 + rcu_read_lock();
57151 + cred = __task_cred(task);
57152 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57153 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57154 + spin_lock(&gr_uid_lock);
57155 + gr_insert_uid(cred->uid, curr->expires);
57156 + spin_unlock(&gr_uid_lock);
57157 + curr->expires = 0;
57158 + curr->crashes = 0;
57159 + read_lock(&tasklist_lock);
57160 + do_each_thread(tsk2, tsk) {
57161 + cred2 = __task_cred(tsk);
57162 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57163 + gr_fake_force_sig(SIGKILL, tsk);
57164 + } while_each_thread(tsk2, tsk);
57165 + read_unlock(&tasklist_lock);
57166 + } else {
57167 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57168 + read_lock(&tasklist_lock);
57169 + read_lock(&grsec_exec_file_lock);
57170 + do_each_thread(tsk2, tsk) {
57171 + if (likely(tsk != task)) {
57172 + // if this thread has the same subject as the one that triggered
57173 + // RES_CRASH and it's the same binary, kill it
57174 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57175 + gr_fake_force_sig(SIGKILL, tsk);
57176 + }
57177 + } while_each_thread(tsk2, tsk);
57178 + read_unlock(&grsec_exec_file_lock);
57179 + read_unlock(&tasklist_lock);
57180 + }
57181 + rcu_read_unlock();
57182 + }
57183 +
57184 + return;
57185 +}
57186 +
57187 +int
57188 +gr_check_crash_exec(const struct file *filp)
57189 +{
57190 + struct acl_subject_label *curr;
57191 +
57192 + if (unlikely(!gr_acl_is_enabled()))
57193 + return 0;
57194 +
57195 + read_lock(&gr_inode_lock);
57196 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57197 + __get_dev(filp->f_path.dentry),
57198 + current->role);
57199 + read_unlock(&gr_inode_lock);
57200 +
57201 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57202 + (!curr->crashes && !curr->expires))
57203 + return 0;
57204 +
57205 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57206 + time_after(curr->expires, get_seconds()))
57207 + return 1;
57208 + else if (time_before_eq(curr->expires, get_seconds())) {
57209 + curr->crashes = 0;
57210 + curr->expires = 0;
57211 + }
57212 +
57213 + return 0;
57214 +}
57215 +
57216 +void
57217 +gr_handle_alertkill(struct task_struct *task)
57218 +{
57219 + struct acl_subject_label *curracl;
57220 + __u32 curr_ip;
57221 + struct task_struct *p, *p2;
57222 +
57223 + if (unlikely(!gr_acl_is_enabled()))
57224 + return;
57225 +
57226 + curracl = task->acl;
57227 + curr_ip = task->signal->curr_ip;
57228 +
57229 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57230 + read_lock(&tasklist_lock);
57231 + do_each_thread(p2, p) {
57232 + if (p->signal->curr_ip == curr_ip)
57233 + gr_fake_force_sig(SIGKILL, p);
57234 + } while_each_thread(p2, p);
57235 + read_unlock(&tasklist_lock);
57236 + } else if (curracl->mode & GR_KILLPROC)
57237 + gr_fake_force_sig(SIGKILL, task);
57238 +
57239 + return;
57240 +}
57241 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57242 new file mode 100644
57243 index 0000000..9d83a69
57244 --- /dev/null
57245 +++ b/grsecurity/gracl_shm.c
57246 @@ -0,0 +1,40 @@
57247 +#include <linux/kernel.h>
57248 +#include <linux/mm.h>
57249 +#include <linux/sched.h>
57250 +#include <linux/file.h>
57251 +#include <linux/ipc.h>
57252 +#include <linux/gracl.h>
57253 +#include <linux/grsecurity.h>
57254 +#include <linux/grinternal.h>
57255 +
57256 +int
57257 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57258 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57259 +{
57260 + struct task_struct *task;
57261 +
57262 + if (!gr_acl_is_enabled())
57263 + return 1;
57264 +
57265 + rcu_read_lock();
57266 + read_lock(&tasklist_lock);
57267 +
57268 + task = find_task_by_vpid(shm_cprid);
57269 +
57270 + if (unlikely(!task))
57271 + task = find_task_by_vpid(shm_lapid);
57272 +
57273 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57274 + (task->pid == shm_lapid)) &&
57275 + (task->acl->mode & GR_PROTSHM) &&
57276 + (task->acl != current->acl))) {
57277 + read_unlock(&tasklist_lock);
57278 + rcu_read_unlock();
57279 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57280 + return 0;
57281 + }
57282 + read_unlock(&tasklist_lock);
57283 + rcu_read_unlock();
57284 +
57285 + return 1;
57286 +}
57287 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57288 new file mode 100644
57289 index 0000000..bc0be01
57290 --- /dev/null
57291 +++ b/grsecurity/grsec_chdir.c
57292 @@ -0,0 +1,19 @@
57293 +#include <linux/kernel.h>
57294 +#include <linux/sched.h>
57295 +#include <linux/fs.h>
57296 +#include <linux/file.h>
57297 +#include <linux/grsecurity.h>
57298 +#include <linux/grinternal.h>
57299 +
57300 +void
57301 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57302 +{
57303 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57304 + if ((grsec_enable_chdir && grsec_enable_group &&
57305 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57306 + !grsec_enable_group)) {
57307 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57308 + }
57309 +#endif
57310 + return;
57311 +}
57312 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57313 new file mode 100644
57314 index 0000000..9807ee2
57315 --- /dev/null
57316 +++ b/grsecurity/grsec_chroot.c
57317 @@ -0,0 +1,368 @@
57318 +#include <linux/kernel.h>
57319 +#include <linux/module.h>
57320 +#include <linux/sched.h>
57321 +#include <linux/file.h>
57322 +#include <linux/fs.h>
57323 +#include <linux/mount.h>
57324 +#include <linux/types.h>
57325 +#include "../fs/mount.h"
57326 +#include <linux/grsecurity.h>
57327 +#include <linux/grinternal.h>
57328 +
57329 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57330 +{
57331 +#ifdef CONFIG_GRKERNSEC
57332 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57333 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57334 + task->gr_is_chrooted = 1;
57335 + else
57336 + task->gr_is_chrooted = 0;
57337 +
57338 + task->gr_chroot_dentry = path->dentry;
57339 +#endif
57340 + return;
57341 +}
57342 +
57343 +void gr_clear_chroot_entries(struct task_struct *task)
57344 +{
57345 +#ifdef CONFIG_GRKERNSEC
57346 + task->gr_is_chrooted = 0;
57347 + task->gr_chroot_dentry = NULL;
57348 +#endif
57349 + return;
57350 +}
57351 +
57352 +int
57353 +gr_handle_chroot_unix(const pid_t pid)
57354 +{
57355 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57356 + struct task_struct *p;
57357 +
57358 + if (unlikely(!grsec_enable_chroot_unix))
57359 + return 1;
57360 +
57361 + if (likely(!proc_is_chrooted(current)))
57362 + return 1;
57363 +
57364 + rcu_read_lock();
57365 + read_lock(&tasklist_lock);
57366 + p = find_task_by_vpid_unrestricted(pid);
57367 + if (unlikely(p && !have_same_root(current, p))) {
57368 + read_unlock(&tasklist_lock);
57369 + rcu_read_unlock();
57370 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57371 + return 0;
57372 + }
57373 + read_unlock(&tasklist_lock);
57374 + rcu_read_unlock();
57375 +#endif
57376 + return 1;
57377 +}
57378 +
57379 +int
57380 +gr_handle_chroot_nice(void)
57381 +{
57382 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57383 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57384 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57385 + return -EPERM;
57386 + }
57387 +#endif
57388 + return 0;
57389 +}
57390 +
57391 +int
57392 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57393 +{
57394 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57395 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57396 + && proc_is_chrooted(current)) {
57397 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57398 + return -EACCES;
57399 + }
57400 +#endif
57401 + return 0;
57402 +}
57403 +
57404 +int
57405 +gr_handle_chroot_rawio(const struct inode *inode)
57406 +{
57407 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57408 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57409 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57410 + return 1;
57411 +#endif
57412 + return 0;
57413 +}
57414 +
57415 +int
57416 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57417 +{
57418 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57419 + struct task_struct *p;
57420 + int ret = 0;
57421 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57422 + return ret;
57423 +
57424 + read_lock(&tasklist_lock);
57425 + do_each_pid_task(pid, type, p) {
57426 + if (!have_same_root(current, p)) {
57427 + ret = 1;
57428 + goto out;
57429 + }
57430 + } while_each_pid_task(pid, type, p);
57431 +out:
57432 + read_unlock(&tasklist_lock);
57433 + return ret;
57434 +#endif
57435 + return 0;
57436 +}
57437 +
57438 +int
57439 +gr_pid_is_chrooted(struct task_struct *p)
57440 +{
57441 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57442 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57443 + return 0;
57444 +
57445 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57446 + !have_same_root(current, p)) {
57447 + return 1;
57448 + }
57449 +#endif
57450 + return 0;
57451 +}
57452 +
57453 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57454 +
57455 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57456 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57457 +{
57458 + struct path path, currentroot;
57459 + int ret = 0;
57460 +
57461 + path.dentry = (struct dentry *)u_dentry;
57462 + path.mnt = (struct vfsmount *)u_mnt;
57463 + get_fs_root(current->fs, &currentroot);
57464 + if (path_is_under(&path, &currentroot))
57465 + ret = 1;
57466 + path_put(&currentroot);
57467 +
57468 + return ret;
57469 +}
57470 +#endif
57471 +
57472 +int
57473 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57474 +{
57475 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57476 + if (!grsec_enable_chroot_fchdir)
57477 + return 1;
57478 +
57479 + if (!proc_is_chrooted(current))
57480 + return 1;
57481 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57482 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57483 + return 0;
57484 + }
57485 +#endif
57486 + return 1;
57487 +}
57488 +
57489 +int
57490 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57491 + const time_t shm_createtime)
57492 +{
57493 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57494 + struct task_struct *p;
57495 + time_t starttime;
57496 +
57497 + if (unlikely(!grsec_enable_chroot_shmat))
57498 + return 1;
57499 +
57500 + if (likely(!proc_is_chrooted(current)))
57501 + return 1;
57502 +
57503 + rcu_read_lock();
57504 + read_lock(&tasklist_lock);
57505 +
57506 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57507 + starttime = p->start_time.tv_sec;
57508 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57509 + if (have_same_root(current, p)) {
57510 + goto allow;
57511 + } else {
57512 + read_unlock(&tasklist_lock);
57513 + rcu_read_unlock();
57514 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57515 + return 0;
57516 + }
57517 + }
57518 + /* creator exited, pid reuse, fall through to next check */
57519 + }
57520 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57521 + if (unlikely(!have_same_root(current, p))) {
57522 + read_unlock(&tasklist_lock);
57523 + rcu_read_unlock();
57524 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57525 + return 0;
57526 + }
57527 + }
57528 +
57529 +allow:
57530 + read_unlock(&tasklist_lock);
57531 + rcu_read_unlock();
57532 +#endif
57533 + return 1;
57534 +}
57535 +
57536 +void
57537 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57538 +{
57539 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57540 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57541 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57542 +#endif
57543 + return;
57544 +}
57545 +
57546 +int
57547 +gr_handle_chroot_mknod(const struct dentry *dentry,
57548 + const struct vfsmount *mnt, const int mode)
57549 +{
57550 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57551 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57552 + proc_is_chrooted(current)) {
57553 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57554 + return -EPERM;
57555 + }
57556 +#endif
57557 + return 0;
57558 +}
57559 +
57560 +int
57561 +gr_handle_chroot_mount(const struct dentry *dentry,
57562 + const struct vfsmount *mnt, const char *dev_name)
57563 +{
57564 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57565 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57566 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57567 + return -EPERM;
57568 + }
57569 +#endif
57570 + return 0;
57571 +}
57572 +
57573 +int
57574 +gr_handle_chroot_pivot(void)
57575 +{
57576 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57577 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57578 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57579 + return -EPERM;
57580 + }
57581 +#endif
57582 + return 0;
57583 +}
57584 +
57585 +int
57586 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57587 +{
57588 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57589 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57590 + !gr_is_outside_chroot(dentry, mnt)) {
57591 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57592 + return -EPERM;
57593 + }
57594 +#endif
57595 + return 0;
57596 +}
57597 +
57598 +extern const char *captab_log[];
57599 +extern int captab_log_entries;
57600 +
57601 +int
57602 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57603 +{
57604 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57605 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57606 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57607 + if (cap_raised(chroot_caps, cap)) {
57608 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57609 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57610 + }
57611 + return 0;
57612 + }
57613 + }
57614 +#endif
57615 + return 1;
57616 +}
57617 +
57618 +int
57619 +gr_chroot_is_capable(const int cap)
57620 +{
57621 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57622 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57623 +#endif
57624 + return 1;
57625 +}
57626 +
57627 +int
57628 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57629 +{
57630 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57631 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57632 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57633 + if (cap_raised(chroot_caps, cap)) {
57634 + return 0;
57635 + }
57636 + }
57637 +#endif
57638 + return 1;
57639 +}
57640 +
57641 +int
57642 +gr_chroot_is_capable_nolog(const int cap)
57643 +{
57644 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57645 + return gr_task_chroot_is_capable_nolog(current, cap);
57646 +#endif
57647 + return 1;
57648 +}
57649 +
57650 +int
57651 +gr_handle_chroot_sysctl(const int op)
57652 +{
57653 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57654 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57655 + proc_is_chrooted(current))
57656 + return -EACCES;
57657 +#endif
57658 + return 0;
57659 +}
57660 +
57661 +void
57662 +gr_handle_chroot_chdir(struct path *path)
57663 +{
57664 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57665 + if (grsec_enable_chroot_chdir)
57666 + set_fs_pwd(current->fs, path);
57667 +#endif
57668 + return;
57669 +}
57670 +
57671 +int
57672 +gr_handle_chroot_chmod(const struct dentry *dentry,
57673 + const struct vfsmount *mnt, const int mode)
57674 +{
57675 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57676 + /* allow chmod +s on directories, but not files */
57677 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57678 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57679 + proc_is_chrooted(current)) {
57680 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57681 + return -EPERM;
57682 + }
57683 +#endif
57684 + return 0;
57685 +}
57686 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57687 new file mode 100644
57688 index 0000000..213ad8b
57689 --- /dev/null
57690 +++ b/grsecurity/grsec_disabled.c
57691 @@ -0,0 +1,437 @@
57692 +#include <linux/kernel.h>
57693 +#include <linux/module.h>
57694 +#include <linux/sched.h>
57695 +#include <linux/file.h>
57696 +#include <linux/fs.h>
57697 +#include <linux/kdev_t.h>
57698 +#include <linux/net.h>
57699 +#include <linux/in.h>
57700 +#include <linux/ip.h>
57701 +#include <linux/skbuff.h>
57702 +#include <linux/sysctl.h>
57703 +
57704 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57705 +void
57706 +pax_set_initial_flags(struct linux_binprm *bprm)
57707 +{
57708 + return;
57709 +}
57710 +#endif
57711 +
57712 +#ifdef CONFIG_SYSCTL
57713 +__u32
57714 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57715 +{
57716 + return 0;
57717 +}
57718 +#endif
57719 +
57720 +#ifdef CONFIG_TASKSTATS
57721 +int gr_is_taskstats_denied(int pid)
57722 +{
57723 + return 0;
57724 +}
57725 +#endif
57726 +
57727 +int
57728 +gr_acl_is_enabled(void)
57729 +{
57730 + return 0;
57731 +}
57732 +
57733 +void
57734 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57735 +{
57736 + return;
57737 +}
57738 +
57739 +int
57740 +gr_handle_rawio(const struct inode *inode)
57741 +{
57742 + return 0;
57743 +}
57744 +
57745 +void
57746 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57747 +{
57748 + return;
57749 +}
57750 +
57751 +int
57752 +gr_handle_ptrace(struct task_struct *task, const long request)
57753 +{
57754 + return 0;
57755 +}
57756 +
57757 +int
57758 +gr_handle_proc_ptrace(struct task_struct *task)
57759 +{
57760 + return 0;
57761 +}
57762 +
57763 +void
57764 +gr_learn_resource(const struct task_struct *task,
57765 + const int res, const unsigned long wanted, const int gt)
57766 +{
57767 + return;
57768 +}
57769 +
57770 +int
57771 +gr_set_acls(const int type)
57772 +{
57773 + return 0;
57774 +}
57775 +
57776 +int
57777 +gr_check_hidden_task(const struct task_struct *tsk)
57778 +{
57779 + return 0;
57780 +}
57781 +
57782 +int
57783 +gr_check_protected_task(const struct task_struct *task)
57784 +{
57785 + return 0;
57786 +}
57787 +
57788 +int
57789 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57790 +{
57791 + return 0;
57792 +}
57793 +
57794 +void
57795 +gr_copy_label(struct task_struct *tsk)
57796 +{
57797 + return;
57798 +}
57799 +
57800 +void
57801 +gr_set_pax_flags(struct task_struct *task)
57802 +{
57803 + return;
57804 +}
57805 +
57806 +int
57807 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57808 + const int unsafe_share)
57809 +{
57810 + return 0;
57811 +}
57812 +
57813 +void
57814 +gr_handle_delete(const ino_t ino, const dev_t dev)
57815 +{
57816 + return;
57817 +}
57818 +
57819 +void
57820 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57821 +{
57822 + return;
57823 +}
57824 +
57825 +void
57826 +gr_handle_crash(struct task_struct *task, const int sig)
57827 +{
57828 + return;
57829 +}
57830 +
57831 +int
57832 +gr_check_crash_exec(const struct file *filp)
57833 +{
57834 + return 0;
57835 +}
57836 +
57837 +int
57838 +gr_check_crash_uid(const uid_t uid)
57839 +{
57840 + return 0;
57841 +}
57842 +
57843 +void
57844 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57845 + struct dentry *old_dentry,
57846 + struct dentry *new_dentry,
57847 + struct vfsmount *mnt, const __u8 replace)
57848 +{
57849 + return;
57850 +}
57851 +
57852 +int
57853 +gr_search_socket(const int family, const int type, const int protocol)
57854 +{
57855 + return 1;
57856 +}
57857 +
57858 +int
57859 +gr_search_connectbind(const int mode, const struct socket *sock,
57860 + const struct sockaddr_in *addr)
57861 +{
57862 + return 0;
57863 +}
57864 +
57865 +void
57866 +gr_handle_alertkill(struct task_struct *task)
57867 +{
57868 + return;
57869 +}
57870 +
57871 +__u32
57872 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57873 +{
57874 + return 1;
57875 +}
57876 +
57877 +__u32
57878 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57879 + const struct vfsmount * mnt)
57880 +{
57881 + return 1;
57882 +}
57883 +
57884 +__u32
57885 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57886 + int acc_mode)
57887 +{
57888 + return 1;
57889 +}
57890 +
57891 +__u32
57892 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57893 +{
57894 + return 1;
57895 +}
57896 +
57897 +__u32
57898 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57899 +{
57900 + return 1;
57901 +}
57902 +
57903 +int
57904 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57905 + unsigned int *vm_flags)
57906 +{
57907 + return 1;
57908 +}
57909 +
57910 +__u32
57911 +gr_acl_handle_truncate(const struct dentry * dentry,
57912 + const struct vfsmount * mnt)
57913 +{
57914 + return 1;
57915 +}
57916 +
57917 +__u32
57918 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57919 +{
57920 + return 1;
57921 +}
57922 +
57923 +__u32
57924 +gr_acl_handle_access(const struct dentry * dentry,
57925 + const struct vfsmount * mnt, const int fmode)
57926 +{
57927 + return 1;
57928 +}
57929 +
57930 +__u32
57931 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57932 + umode_t *mode)
57933 +{
57934 + return 1;
57935 +}
57936 +
57937 +__u32
57938 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57939 +{
57940 + return 1;
57941 +}
57942 +
57943 +__u32
57944 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57945 +{
57946 + return 1;
57947 +}
57948 +
57949 +void
57950 +grsecurity_init(void)
57951 +{
57952 + return;
57953 +}
57954 +
57955 +umode_t gr_acl_umask(void)
57956 +{
57957 + return 0;
57958 +}
57959 +
57960 +__u32
57961 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57962 + const struct dentry * parent_dentry,
57963 + const struct vfsmount * parent_mnt,
57964 + const int mode)
57965 +{
57966 + return 1;
57967 +}
57968 +
57969 +__u32
57970 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57971 + const struct dentry * parent_dentry,
57972 + const struct vfsmount * parent_mnt)
57973 +{
57974 + return 1;
57975 +}
57976 +
57977 +__u32
57978 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57979 + const struct dentry * parent_dentry,
57980 + const struct vfsmount * parent_mnt, const char *from)
57981 +{
57982 + return 1;
57983 +}
57984 +
57985 +__u32
57986 +gr_acl_handle_link(const struct dentry * new_dentry,
57987 + const struct dentry * parent_dentry,
57988 + const struct vfsmount * parent_mnt,
57989 + const struct dentry * old_dentry,
57990 + const struct vfsmount * old_mnt, const char *to)
57991 +{
57992 + return 1;
57993 +}
57994 +
57995 +int
57996 +gr_acl_handle_rename(const struct dentry *new_dentry,
57997 + const struct dentry *parent_dentry,
57998 + const struct vfsmount *parent_mnt,
57999 + const struct dentry *old_dentry,
58000 + const struct inode *old_parent_inode,
58001 + const struct vfsmount *old_mnt, const char *newname)
58002 +{
58003 + return 0;
58004 +}
58005 +
58006 +int
58007 +gr_acl_handle_filldir(const struct file *file, const char *name,
58008 + const int namelen, const ino_t ino)
58009 +{
58010 + return 1;
58011 +}
58012 +
58013 +int
58014 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58015 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58016 +{
58017 + return 1;
58018 +}
58019 +
58020 +int
58021 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58022 +{
58023 + return 0;
58024 +}
58025 +
58026 +int
58027 +gr_search_accept(const struct socket *sock)
58028 +{
58029 + return 0;
58030 +}
58031 +
58032 +int
58033 +gr_search_listen(const struct socket *sock)
58034 +{
58035 + return 0;
58036 +}
58037 +
58038 +int
58039 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58040 +{
58041 + return 0;
58042 +}
58043 +
58044 +__u32
58045 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58046 +{
58047 + return 1;
58048 +}
58049 +
58050 +__u32
58051 +gr_acl_handle_creat(const struct dentry * dentry,
58052 + const struct dentry * p_dentry,
58053 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58054 + const int imode)
58055 +{
58056 + return 1;
58057 +}
58058 +
58059 +void
58060 +gr_acl_handle_exit(void)
58061 +{
58062 + return;
58063 +}
58064 +
58065 +int
58066 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58067 +{
58068 + return 1;
58069 +}
58070 +
58071 +void
58072 +gr_set_role_label(const uid_t uid, const gid_t gid)
58073 +{
58074 + return;
58075 +}
58076 +
58077 +int
58078 +gr_acl_handle_procpidmem(const struct task_struct *task)
58079 +{
58080 + return 0;
58081 +}
58082 +
58083 +int
58084 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58085 +{
58086 + return 0;
58087 +}
58088 +
58089 +int
58090 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58091 +{
58092 + return 0;
58093 +}
58094 +
58095 +void
58096 +gr_set_kernel_label(struct task_struct *task)
58097 +{
58098 + return;
58099 +}
58100 +
58101 +int
58102 +gr_check_user_change(int real, int effective, int fs)
58103 +{
58104 + return 0;
58105 +}
58106 +
58107 +int
58108 +gr_check_group_change(int real, int effective, int fs)
58109 +{
58110 + return 0;
58111 +}
58112 +
58113 +int gr_acl_enable_at_secure(void)
58114 +{
58115 + return 0;
58116 +}
58117 +
58118 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58119 +{
58120 + return dentry->d_inode->i_sb->s_dev;
58121 +}
58122 +
58123 +EXPORT_SYMBOL(gr_learn_resource);
58124 +EXPORT_SYMBOL(gr_set_kernel_label);
58125 +#ifdef CONFIG_SECURITY
58126 +EXPORT_SYMBOL(gr_check_user_change);
58127 +EXPORT_SYMBOL(gr_check_group_change);
58128 +#endif
58129 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58130 new file mode 100644
58131 index 0000000..abfa971
58132 --- /dev/null
58133 +++ b/grsecurity/grsec_exec.c
58134 @@ -0,0 +1,174 @@
58135 +#include <linux/kernel.h>
58136 +#include <linux/sched.h>
58137 +#include <linux/file.h>
58138 +#include <linux/binfmts.h>
58139 +#include <linux/fs.h>
58140 +#include <linux/types.h>
58141 +#include <linux/grdefs.h>
58142 +#include <linux/grsecurity.h>
58143 +#include <linux/grinternal.h>
58144 +#include <linux/capability.h>
58145 +#include <linux/module.h>
58146 +
58147 +#include <asm/uaccess.h>
58148 +
58149 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58150 +static char gr_exec_arg_buf[132];
58151 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58152 +#endif
58153 +
58154 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58155 +
58156 +void
58157 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58158 +{
58159 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58160 + char *grarg = gr_exec_arg_buf;
58161 + unsigned int i, x, execlen = 0;
58162 + char c;
58163 +
58164 + if (!((grsec_enable_execlog && grsec_enable_group &&
58165 + in_group_p(grsec_audit_gid))
58166 + || (grsec_enable_execlog && !grsec_enable_group)))
58167 + return;
58168 +
58169 + mutex_lock(&gr_exec_arg_mutex);
58170 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58171 +
58172 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58173 + const char __user *p;
58174 + unsigned int len;
58175 +
58176 + p = get_user_arg_ptr(argv, i);
58177 + if (IS_ERR(p))
58178 + goto log;
58179 +
58180 + len = strnlen_user(p, 128 - execlen);
58181 + if (len > 128 - execlen)
58182 + len = 128 - execlen;
58183 + else if (len > 0)
58184 + len--;
58185 + if (copy_from_user(grarg + execlen, p, len))
58186 + goto log;
58187 +
58188 + /* rewrite unprintable characters */
58189 + for (x = 0; x < len; x++) {
58190 + c = *(grarg + execlen + x);
58191 + if (c < 32 || c > 126)
58192 + *(grarg + execlen + x) = ' ';
58193 + }
58194 +
58195 + execlen += len;
58196 + *(grarg + execlen) = ' ';
58197 + *(grarg + execlen + 1) = '\0';
58198 + execlen++;
58199 + }
58200 +
58201 + log:
58202 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58203 + bprm->file->f_path.mnt, grarg);
58204 + mutex_unlock(&gr_exec_arg_mutex);
58205 +#endif
58206 + return;
58207 +}
58208 +
58209 +#ifdef CONFIG_GRKERNSEC
58210 +extern int gr_acl_is_capable(const int cap);
58211 +extern int gr_acl_is_capable_nolog(const int cap);
58212 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58213 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58214 +extern int gr_chroot_is_capable(const int cap);
58215 +extern int gr_chroot_is_capable_nolog(const int cap);
58216 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58217 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58218 +#endif
58219 +
58220 +const char *captab_log[] = {
58221 + "CAP_CHOWN",
58222 + "CAP_DAC_OVERRIDE",
58223 + "CAP_DAC_READ_SEARCH",
58224 + "CAP_FOWNER",
58225 + "CAP_FSETID",
58226 + "CAP_KILL",
58227 + "CAP_SETGID",
58228 + "CAP_SETUID",
58229 + "CAP_SETPCAP",
58230 + "CAP_LINUX_IMMUTABLE",
58231 + "CAP_NET_BIND_SERVICE",
58232 + "CAP_NET_BROADCAST",
58233 + "CAP_NET_ADMIN",
58234 + "CAP_NET_RAW",
58235 + "CAP_IPC_LOCK",
58236 + "CAP_IPC_OWNER",
58237 + "CAP_SYS_MODULE",
58238 + "CAP_SYS_RAWIO",
58239 + "CAP_SYS_CHROOT",
58240 + "CAP_SYS_PTRACE",
58241 + "CAP_SYS_PACCT",
58242 + "CAP_SYS_ADMIN",
58243 + "CAP_SYS_BOOT",
58244 + "CAP_SYS_NICE",
58245 + "CAP_SYS_RESOURCE",
58246 + "CAP_SYS_TIME",
58247 + "CAP_SYS_TTY_CONFIG",
58248 + "CAP_MKNOD",
58249 + "CAP_LEASE",
58250 + "CAP_AUDIT_WRITE",
58251 + "CAP_AUDIT_CONTROL",
58252 + "CAP_SETFCAP",
58253 + "CAP_MAC_OVERRIDE",
58254 + "CAP_MAC_ADMIN",
58255 + "CAP_SYSLOG",
58256 + "CAP_WAKE_ALARM"
58257 +};
58258 +
58259 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58260 +
58261 +int gr_is_capable(const int cap)
58262 +{
58263 +#ifdef CONFIG_GRKERNSEC
58264 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58265 + return 1;
58266 + return 0;
58267 +#else
58268 + return 1;
58269 +#endif
58270 +}
58271 +
58272 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58273 +{
58274 +#ifdef CONFIG_GRKERNSEC
58275 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58276 + return 1;
58277 + return 0;
58278 +#else
58279 + return 1;
58280 +#endif
58281 +}
58282 +
58283 +int gr_is_capable_nolog(const int cap)
58284 +{
58285 +#ifdef CONFIG_GRKERNSEC
58286 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58287 + return 1;
58288 + return 0;
58289 +#else
58290 + return 1;
58291 +#endif
58292 +}
58293 +
58294 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58295 +{
58296 +#ifdef CONFIG_GRKERNSEC
58297 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58298 + return 1;
58299 + return 0;
58300 +#else
58301 + return 1;
58302 +#endif
58303 +}
58304 +
58305 +EXPORT_SYMBOL(gr_is_capable);
58306 +EXPORT_SYMBOL(gr_is_capable_nolog);
58307 +EXPORT_SYMBOL(gr_task_is_capable);
58308 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58309 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58310 new file mode 100644
58311 index 0000000..d3ee748
58312 --- /dev/null
58313 +++ b/grsecurity/grsec_fifo.c
58314 @@ -0,0 +1,24 @@
58315 +#include <linux/kernel.h>
58316 +#include <linux/sched.h>
58317 +#include <linux/fs.h>
58318 +#include <linux/file.h>
58319 +#include <linux/grinternal.h>
58320 +
58321 +int
58322 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58323 + const struct dentry *dir, const int flag, const int acc_mode)
58324 +{
58325 +#ifdef CONFIG_GRKERNSEC_FIFO
58326 + const struct cred *cred = current_cred();
58327 +
58328 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58329 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58330 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58331 + (cred->fsuid != dentry->d_inode->i_uid)) {
58332 + if (!inode_permission(dentry->d_inode, acc_mode))
58333 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58334 + return -EACCES;
58335 + }
58336 +#endif
58337 + return 0;
58338 +}
58339 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58340 new file mode 100644
58341 index 0000000..8ca18bf
58342 --- /dev/null
58343 +++ b/grsecurity/grsec_fork.c
58344 @@ -0,0 +1,23 @@
58345 +#include <linux/kernel.h>
58346 +#include <linux/sched.h>
58347 +#include <linux/grsecurity.h>
58348 +#include <linux/grinternal.h>
58349 +#include <linux/errno.h>
58350 +
58351 +void
58352 +gr_log_forkfail(const int retval)
58353 +{
58354 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58355 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58356 + switch (retval) {
58357 + case -EAGAIN:
58358 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58359 + break;
58360 + case -ENOMEM:
58361 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58362 + break;
58363 + }
58364 + }
58365 +#endif
58366 + return;
58367 +}
58368 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58369 new file mode 100644
58370 index 0000000..05a6015
58371 --- /dev/null
58372 +++ b/grsecurity/grsec_init.c
58373 @@ -0,0 +1,283 @@
58374 +#include <linux/kernel.h>
58375 +#include <linux/sched.h>
58376 +#include <linux/mm.h>
58377 +#include <linux/gracl.h>
58378 +#include <linux/slab.h>
58379 +#include <linux/vmalloc.h>
58380 +#include <linux/percpu.h>
58381 +#include <linux/module.h>
58382 +
58383 +int grsec_enable_ptrace_readexec;
58384 +int grsec_enable_setxid;
58385 +int grsec_enable_symlinkown;
58386 +int grsec_symlinkown_gid;
58387 +int grsec_enable_brute;
58388 +int grsec_enable_link;
58389 +int grsec_enable_dmesg;
58390 +int grsec_enable_harden_ptrace;
58391 +int grsec_enable_fifo;
58392 +int grsec_enable_execlog;
58393 +int grsec_enable_signal;
58394 +int grsec_enable_forkfail;
58395 +int grsec_enable_audit_ptrace;
58396 +int grsec_enable_time;
58397 +int grsec_enable_audit_textrel;
58398 +int grsec_enable_group;
58399 +int grsec_audit_gid;
58400 +int grsec_enable_chdir;
58401 +int grsec_enable_mount;
58402 +int grsec_enable_rofs;
58403 +int grsec_enable_chroot_findtask;
58404 +int grsec_enable_chroot_mount;
58405 +int grsec_enable_chroot_shmat;
58406 +int grsec_enable_chroot_fchdir;
58407 +int grsec_enable_chroot_double;
58408 +int grsec_enable_chroot_pivot;
58409 +int grsec_enable_chroot_chdir;
58410 +int grsec_enable_chroot_chmod;
58411 +int grsec_enable_chroot_mknod;
58412 +int grsec_enable_chroot_nice;
58413 +int grsec_enable_chroot_execlog;
58414 +int grsec_enable_chroot_caps;
58415 +int grsec_enable_chroot_sysctl;
58416 +int grsec_enable_chroot_unix;
58417 +int grsec_enable_tpe;
58418 +int grsec_tpe_gid;
58419 +int grsec_enable_blackhole;
58420 +#ifdef CONFIG_IPV6_MODULE
58421 +EXPORT_SYMBOL(grsec_enable_blackhole);
58422 +#endif
58423 +int grsec_lastack_retries;
58424 +int grsec_enable_tpe_all;
58425 +int grsec_enable_tpe_invert;
58426 +int grsec_enable_socket_all;
58427 +int grsec_socket_all_gid;
58428 +int grsec_enable_socket_client;
58429 +int grsec_socket_client_gid;
58430 +int grsec_enable_socket_server;
58431 +int grsec_socket_server_gid;
58432 +int grsec_resource_logging;
58433 +int grsec_disable_privio;
58434 +int grsec_enable_log_rwxmaps;
58435 +int grsec_lock;
58436 +
58437 +DEFINE_SPINLOCK(grsec_alert_lock);
58438 +unsigned long grsec_alert_wtime = 0;
58439 +unsigned long grsec_alert_fyet = 0;
58440 +
58441 +DEFINE_SPINLOCK(grsec_audit_lock);
58442 +
58443 +DEFINE_RWLOCK(grsec_exec_file_lock);
58444 +
58445 +char *gr_shared_page[4];
58446 +
58447 +char *gr_alert_log_fmt;
58448 +char *gr_audit_log_fmt;
58449 +char *gr_alert_log_buf;
58450 +char *gr_audit_log_buf;
58451 +
58452 +extern struct gr_arg *gr_usermode;
58453 +extern unsigned char *gr_system_salt;
58454 +extern unsigned char *gr_system_sum;
58455 +
58456 +void __init
58457 +grsecurity_init(void)
58458 +{
58459 + int j;
58460 + /* create the per-cpu shared pages */
58461 +
58462 +#ifdef CONFIG_X86
58463 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58464 +#endif
58465 +
58466 + for (j = 0; j < 4; j++) {
58467 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58468 + if (gr_shared_page[j] == NULL) {
58469 + panic("Unable to allocate grsecurity shared page");
58470 + return;
58471 + }
58472 + }
58473 +
58474 + /* allocate log buffers */
58475 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58476 + if (!gr_alert_log_fmt) {
58477 + panic("Unable to allocate grsecurity alert log format buffer");
58478 + return;
58479 + }
58480 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58481 + if (!gr_audit_log_fmt) {
58482 + panic("Unable to allocate grsecurity audit log format buffer");
58483 + return;
58484 + }
58485 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58486 + if (!gr_alert_log_buf) {
58487 + panic("Unable to allocate grsecurity alert log buffer");
58488 + return;
58489 + }
58490 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58491 + if (!gr_audit_log_buf) {
58492 + panic("Unable to allocate grsecurity audit log buffer");
58493 + return;
58494 + }
58495 +
58496 + /* allocate memory for authentication structure */
58497 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58498 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58499 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58500 +
58501 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58502 + panic("Unable to allocate grsecurity authentication structure");
58503 + return;
58504 + }
58505 +
58506 +
58507 +#ifdef CONFIG_GRKERNSEC_IO
58508 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58509 + grsec_disable_privio = 1;
58510 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58511 + grsec_disable_privio = 1;
58512 +#else
58513 + grsec_disable_privio = 0;
58514 +#endif
58515 +#endif
58516 +
58517 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58518 + /* for backward compatibility, tpe_invert always defaults to on if
58519 + enabled in the kernel
58520 + */
58521 + grsec_enable_tpe_invert = 1;
58522 +#endif
58523 +
58524 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58525 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58526 + grsec_lock = 1;
58527 +#endif
58528 +
58529 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58530 + grsec_enable_audit_textrel = 1;
58531 +#endif
58532 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58533 + grsec_enable_log_rwxmaps = 1;
58534 +#endif
58535 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58536 + grsec_enable_group = 1;
58537 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58538 +#endif
58539 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58540 + grsec_enable_ptrace_readexec = 1;
58541 +#endif
58542 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58543 + grsec_enable_chdir = 1;
58544 +#endif
58545 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58546 + grsec_enable_harden_ptrace = 1;
58547 +#endif
58548 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58549 + grsec_enable_mount = 1;
58550 +#endif
58551 +#ifdef CONFIG_GRKERNSEC_LINK
58552 + grsec_enable_link = 1;
58553 +#endif
58554 +#ifdef CONFIG_GRKERNSEC_BRUTE
58555 + grsec_enable_brute = 1;
58556 +#endif
58557 +#ifdef CONFIG_GRKERNSEC_DMESG
58558 + grsec_enable_dmesg = 1;
58559 +#endif
58560 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58561 + grsec_enable_blackhole = 1;
58562 + grsec_lastack_retries = 4;
58563 +#endif
58564 +#ifdef CONFIG_GRKERNSEC_FIFO
58565 + grsec_enable_fifo = 1;
58566 +#endif
58567 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58568 + grsec_enable_execlog = 1;
58569 +#endif
58570 +#ifdef CONFIG_GRKERNSEC_SETXID
58571 + grsec_enable_setxid = 1;
58572 +#endif
58573 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58574 + grsec_enable_signal = 1;
58575 +#endif
58576 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58577 + grsec_enable_forkfail = 1;
58578 +#endif
58579 +#ifdef CONFIG_GRKERNSEC_TIME
58580 + grsec_enable_time = 1;
58581 +#endif
58582 +#ifdef CONFIG_GRKERNSEC_RESLOG
58583 + grsec_resource_logging = 1;
58584 +#endif
58585 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58586 + grsec_enable_chroot_findtask = 1;
58587 +#endif
58588 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58589 + grsec_enable_chroot_unix = 1;
58590 +#endif
58591 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58592 + grsec_enable_chroot_mount = 1;
58593 +#endif
58594 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58595 + grsec_enable_chroot_fchdir = 1;
58596 +#endif
58597 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58598 + grsec_enable_chroot_shmat = 1;
58599 +#endif
58600 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58601 + grsec_enable_audit_ptrace = 1;
58602 +#endif
58603 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58604 + grsec_enable_chroot_double = 1;
58605 +#endif
58606 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58607 + grsec_enable_chroot_pivot = 1;
58608 +#endif
58609 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58610 + grsec_enable_chroot_chdir = 1;
58611 +#endif
58612 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58613 + grsec_enable_chroot_chmod = 1;
58614 +#endif
58615 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58616 + grsec_enable_chroot_mknod = 1;
58617 +#endif
58618 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58619 + grsec_enable_chroot_nice = 1;
58620 +#endif
58621 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58622 + grsec_enable_chroot_execlog = 1;
58623 +#endif
58624 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58625 + grsec_enable_chroot_caps = 1;
58626 +#endif
58627 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58628 + grsec_enable_chroot_sysctl = 1;
58629 +#endif
58630 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58631 + grsec_enable_symlinkown = 1;
58632 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58633 +#endif
58634 +#ifdef CONFIG_GRKERNSEC_TPE
58635 + grsec_enable_tpe = 1;
58636 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58637 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58638 + grsec_enable_tpe_all = 1;
58639 +#endif
58640 +#endif
58641 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58642 + grsec_enable_socket_all = 1;
58643 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58644 +#endif
58645 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58646 + grsec_enable_socket_client = 1;
58647 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58648 +#endif
58649 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58650 + grsec_enable_socket_server = 1;
58651 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58652 +#endif
58653 +#endif
58654 +
58655 + return;
58656 +}
58657 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58658 new file mode 100644
58659 index 0000000..589481f
58660 --- /dev/null
58661 +++ b/grsecurity/grsec_link.c
58662 @@ -0,0 +1,58 @@
58663 +#include <linux/kernel.h>
58664 +#include <linux/sched.h>
58665 +#include <linux/fs.h>
58666 +#include <linux/file.h>
58667 +#include <linux/grinternal.h>
58668 +
58669 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58670 +{
58671 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58672 + const struct inode *link_inode = link->dentry->d_inode;
58673 +
58674 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58675 + /* ignore root-owned links, e.g. /proc/self */
58676 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58677 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58678 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58679 + return 1;
58680 + }
58681 +#endif
58682 + return 0;
58683 +}
58684 +
58685 +int
58686 +gr_handle_follow_link(const struct inode *parent,
58687 + const struct inode *inode,
58688 + const struct dentry *dentry, const struct vfsmount *mnt)
58689 +{
58690 +#ifdef CONFIG_GRKERNSEC_LINK
58691 + const struct cred *cred = current_cred();
58692 +
58693 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58694 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58695 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58696 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58697 + return -EACCES;
58698 + }
58699 +#endif
58700 + return 0;
58701 +}
58702 +
58703 +int
58704 +gr_handle_hardlink(const struct dentry *dentry,
58705 + const struct vfsmount *mnt,
58706 + struct inode *inode, const int mode, const char *to)
58707 +{
58708 +#ifdef CONFIG_GRKERNSEC_LINK
58709 + const struct cred *cred = current_cred();
58710 +
58711 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58712 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58713 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58714 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58715 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58716 + return -EPERM;
58717 + }
58718 +#endif
58719 + return 0;
58720 +}
58721 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58722 new file mode 100644
58723 index 0000000..a45d2e9
58724 --- /dev/null
58725 +++ b/grsecurity/grsec_log.c
58726 @@ -0,0 +1,322 @@
58727 +#include <linux/kernel.h>
58728 +#include <linux/sched.h>
58729 +#include <linux/file.h>
58730 +#include <linux/tty.h>
58731 +#include <linux/fs.h>
58732 +#include <linux/grinternal.h>
58733 +
58734 +#ifdef CONFIG_TREE_PREEMPT_RCU
58735 +#define DISABLE_PREEMPT() preempt_disable()
58736 +#define ENABLE_PREEMPT() preempt_enable()
58737 +#else
58738 +#define DISABLE_PREEMPT()
58739 +#define ENABLE_PREEMPT()
58740 +#endif
58741 +
58742 +#define BEGIN_LOCKS(x) \
58743 + DISABLE_PREEMPT(); \
58744 + rcu_read_lock(); \
58745 + read_lock(&tasklist_lock); \
58746 + read_lock(&grsec_exec_file_lock); \
58747 + if (x != GR_DO_AUDIT) \
58748 + spin_lock(&grsec_alert_lock); \
58749 + else \
58750 + spin_lock(&grsec_audit_lock)
58751 +
58752 +#define END_LOCKS(x) \
58753 + if (x != GR_DO_AUDIT) \
58754 + spin_unlock(&grsec_alert_lock); \
58755 + else \
58756 + spin_unlock(&grsec_audit_lock); \
58757 + read_unlock(&grsec_exec_file_lock); \
58758 + read_unlock(&tasklist_lock); \
58759 + rcu_read_unlock(); \
58760 + ENABLE_PREEMPT(); \
58761 + if (x == GR_DONT_AUDIT) \
58762 + gr_handle_alertkill(current)
58763 +
58764 +enum {
58765 + FLOODING,
58766 + NO_FLOODING
58767 +};
58768 +
58769 +extern char *gr_alert_log_fmt;
58770 +extern char *gr_audit_log_fmt;
58771 +extern char *gr_alert_log_buf;
58772 +extern char *gr_audit_log_buf;
58773 +
58774 +static int gr_log_start(int audit)
58775 +{
58776 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58777 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58778 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58779 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58780 + unsigned long curr_secs = get_seconds();
58781 +
58782 + if (audit == GR_DO_AUDIT)
58783 + goto set_fmt;
58784 +
58785 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58786 + grsec_alert_wtime = curr_secs;
58787 + grsec_alert_fyet = 0;
58788 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58789 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58790 + grsec_alert_fyet++;
58791 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58792 + grsec_alert_wtime = curr_secs;
58793 + grsec_alert_fyet++;
58794 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58795 + return FLOODING;
58796 + }
58797 + else return FLOODING;
58798 +
58799 +set_fmt:
58800 +#endif
58801 + memset(buf, 0, PAGE_SIZE);
58802 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58803 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58804 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58805 + } else if (current->signal->curr_ip) {
58806 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58807 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58808 + } else if (gr_acl_is_enabled()) {
58809 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58810 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58811 + } else {
58812 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58813 + strcpy(buf, fmt);
58814 + }
58815 +
58816 + return NO_FLOODING;
58817 +}
58818 +
58819 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58820 + __attribute__ ((format (printf, 2, 0)));
58821 +
58822 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58823 +{
58824 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58825 + unsigned int len = strlen(buf);
58826 +
58827 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58828 +
58829 + return;
58830 +}
58831 +
58832 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58833 + __attribute__ ((format (printf, 2, 3)));
58834 +
58835 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58836 +{
58837 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58838 + unsigned int len = strlen(buf);
58839 + va_list ap;
58840 +
58841 + va_start(ap, msg);
58842 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58843 + va_end(ap);
58844 +
58845 + return;
58846 +}
58847 +
58848 +static void gr_log_end(int audit, int append_default)
58849 +{
58850 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58851 +
58852 + if (append_default) {
58853 + unsigned int len = strlen(buf);
58854 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58855 + }
58856 +
58857 + printk("%s\n", buf);
58858 +
58859 + return;
58860 +}
58861 +
58862 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58863 +{
58864 + int logtype;
58865 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58866 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58867 + void *voidptr = NULL;
58868 + int num1 = 0, num2 = 0;
58869 + unsigned long ulong1 = 0, ulong2 = 0;
58870 + struct dentry *dentry = NULL;
58871 + struct vfsmount *mnt = NULL;
58872 + struct file *file = NULL;
58873 + struct task_struct *task = NULL;
58874 + const struct cred *cred, *pcred;
58875 + va_list ap;
58876 +
58877 + BEGIN_LOCKS(audit);
58878 + logtype = gr_log_start(audit);
58879 + if (logtype == FLOODING) {
58880 + END_LOCKS(audit);
58881 + return;
58882 + }
58883 + va_start(ap, argtypes);
58884 + switch (argtypes) {
58885 + case GR_TTYSNIFF:
58886 + task = va_arg(ap, struct task_struct *);
58887 + 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);
58888 + break;
58889 + case GR_SYSCTL_HIDDEN:
58890 + str1 = va_arg(ap, char *);
58891 + gr_log_middle_varargs(audit, msg, result, str1);
58892 + break;
58893 + case GR_RBAC:
58894 + dentry = va_arg(ap, struct dentry *);
58895 + mnt = va_arg(ap, struct vfsmount *);
58896 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58897 + break;
58898 + case GR_RBAC_STR:
58899 + dentry = va_arg(ap, struct dentry *);
58900 + mnt = va_arg(ap, struct vfsmount *);
58901 + str1 = va_arg(ap, char *);
58902 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58903 + break;
58904 + case GR_STR_RBAC:
58905 + str1 = va_arg(ap, char *);
58906 + dentry = va_arg(ap, struct dentry *);
58907 + mnt = va_arg(ap, struct vfsmount *);
58908 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58909 + break;
58910 + case GR_RBAC_MODE2:
58911 + dentry = va_arg(ap, struct dentry *);
58912 + mnt = va_arg(ap, struct vfsmount *);
58913 + str1 = va_arg(ap, char *);
58914 + str2 = va_arg(ap, char *);
58915 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58916 + break;
58917 + case GR_RBAC_MODE3:
58918 + dentry = va_arg(ap, struct dentry *);
58919 + mnt = va_arg(ap, struct vfsmount *);
58920 + str1 = va_arg(ap, char *);
58921 + str2 = va_arg(ap, char *);
58922 + str3 = va_arg(ap, char *);
58923 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58924 + break;
58925 + case GR_FILENAME:
58926 + dentry = va_arg(ap, struct dentry *);
58927 + mnt = va_arg(ap, struct vfsmount *);
58928 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58929 + break;
58930 + case GR_STR_FILENAME:
58931 + str1 = va_arg(ap, char *);
58932 + dentry = va_arg(ap, struct dentry *);
58933 + mnt = va_arg(ap, struct vfsmount *);
58934 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58935 + break;
58936 + case GR_FILENAME_STR:
58937 + dentry = va_arg(ap, struct dentry *);
58938 + mnt = va_arg(ap, struct vfsmount *);
58939 + str1 = va_arg(ap, char *);
58940 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58941 + break;
58942 + case GR_FILENAME_TWO_INT:
58943 + dentry = va_arg(ap, struct dentry *);
58944 + mnt = va_arg(ap, struct vfsmount *);
58945 + num1 = va_arg(ap, int);
58946 + num2 = va_arg(ap, int);
58947 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58948 + break;
58949 + case GR_FILENAME_TWO_INT_STR:
58950 + dentry = va_arg(ap, struct dentry *);
58951 + mnt = va_arg(ap, struct vfsmount *);
58952 + num1 = va_arg(ap, int);
58953 + num2 = va_arg(ap, int);
58954 + str1 = va_arg(ap, char *);
58955 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58956 + break;
58957 + case GR_TEXTREL:
58958 + file = va_arg(ap, struct file *);
58959 + ulong1 = va_arg(ap, unsigned long);
58960 + ulong2 = va_arg(ap, unsigned long);
58961 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58962 + break;
58963 + case GR_PTRACE:
58964 + task = va_arg(ap, struct task_struct *);
58965 + 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);
58966 + break;
58967 + case GR_RESOURCE:
58968 + task = va_arg(ap, struct task_struct *);
58969 + cred = __task_cred(task);
58970 + pcred = __task_cred(task->real_parent);
58971 + ulong1 = va_arg(ap, unsigned long);
58972 + str1 = va_arg(ap, char *);
58973 + ulong2 = va_arg(ap, unsigned long);
58974 + 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);
58975 + break;
58976 + case GR_CAP:
58977 + task = va_arg(ap, struct task_struct *);
58978 + cred = __task_cred(task);
58979 + pcred = __task_cred(task->real_parent);
58980 + str1 = va_arg(ap, char *);
58981 + 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);
58982 + break;
58983 + case GR_SIG:
58984 + str1 = va_arg(ap, char *);
58985 + voidptr = va_arg(ap, void *);
58986 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58987 + break;
58988 + case GR_SIG2:
58989 + task = va_arg(ap, struct task_struct *);
58990 + cred = __task_cred(task);
58991 + pcred = __task_cred(task->real_parent);
58992 + num1 = va_arg(ap, int);
58993 + 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);
58994 + break;
58995 + case GR_CRASH1:
58996 + task = va_arg(ap, struct task_struct *);
58997 + cred = __task_cred(task);
58998 + pcred = __task_cred(task->real_parent);
58999 + ulong1 = va_arg(ap, unsigned long);
59000 + 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);
59001 + break;
59002 + case GR_CRASH2:
59003 + task = va_arg(ap, struct task_struct *);
59004 + cred = __task_cred(task);
59005 + pcred = __task_cred(task->real_parent);
59006 + ulong1 = va_arg(ap, unsigned long);
59007 + 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);
59008 + break;
59009 + case GR_RWXMAP:
59010 + file = va_arg(ap, struct file *);
59011 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59012 + break;
59013 + case GR_PSACCT:
59014 + {
59015 + unsigned int wday, cday;
59016 + __u8 whr, chr;
59017 + __u8 wmin, cmin;
59018 + __u8 wsec, csec;
59019 + char cur_tty[64] = { 0 };
59020 + char parent_tty[64] = { 0 };
59021 +
59022 + task = va_arg(ap, struct task_struct *);
59023 + wday = va_arg(ap, unsigned int);
59024 + cday = va_arg(ap, unsigned int);
59025 + whr = va_arg(ap, int);
59026 + chr = va_arg(ap, int);
59027 + wmin = va_arg(ap, int);
59028 + cmin = va_arg(ap, int);
59029 + wsec = va_arg(ap, int);
59030 + csec = va_arg(ap, int);
59031 + ulong1 = va_arg(ap, unsigned long);
59032 + cred = __task_cred(task);
59033 + pcred = __task_cred(task->real_parent);
59034 +
59035 + 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);
59036 + }
59037 + break;
59038 + default:
59039 + gr_log_middle(audit, msg, ap);
59040 + }
59041 + va_end(ap);
59042 + // these don't need DEFAULTSECARGS printed on the end
59043 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59044 + gr_log_end(audit, 0);
59045 + else
59046 + gr_log_end(audit, 1);
59047 + END_LOCKS(audit);
59048 +}
59049 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59050 new file mode 100644
59051 index 0000000..f536303
59052 --- /dev/null
59053 +++ b/grsecurity/grsec_mem.c
59054 @@ -0,0 +1,40 @@
59055 +#include <linux/kernel.h>
59056 +#include <linux/sched.h>
59057 +#include <linux/mm.h>
59058 +#include <linux/mman.h>
59059 +#include <linux/grinternal.h>
59060 +
59061 +void
59062 +gr_handle_ioperm(void)
59063 +{
59064 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59065 + return;
59066 +}
59067 +
59068 +void
59069 +gr_handle_iopl(void)
59070 +{
59071 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59072 + return;
59073 +}
59074 +
59075 +void
59076 +gr_handle_mem_readwrite(u64 from, u64 to)
59077 +{
59078 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59079 + return;
59080 +}
59081 +
59082 +void
59083 +gr_handle_vm86(void)
59084 +{
59085 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59086 + return;
59087 +}
59088 +
59089 +void
59090 +gr_log_badprocpid(const char *entry)
59091 +{
59092 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59093 + return;
59094 +}
59095 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59096 new file mode 100644
59097 index 0000000..2131422
59098 --- /dev/null
59099 +++ b/grsecurity/grsec_mount.c
59100 @@ -0,0 +1,62 @@
59101 +#include <linux/kernel.h>
59102 +#include <linux/sched.h>
59103 +#include <linux/mount.h>
59104 +#include <linux/grsecurity.h>
59105 +#include <linux/grinternal.h>
59106 +
59107 +void
59108 +gr_log_remount(const char *devname, const int retval)
59109 +{
59110 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59111 + if (grsec_enable_mount && (retval >= 0))
59112 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59113 +#endif
59114 + return;
59115 +}
59116 +
59117 +void
59118 +gr_log_unmount(const char *devname, const int retval)
59119 +{
59120 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59121 + if (grsec_enable_mount && (retval >= 0))
59122 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59123 +#endif
59124 + return;
59125 +}
59126 +
59127 +void
59128 +gr_log_mount(const char *from, const char *to, const int retval)
59129 +{
59130 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59131 + if (grsec_enable_mount && (retval >= 0))
59132 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59133 +#endif
59134 + return;
59135 +}
59136 +
59137 +int
59138 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59139 +{
59140 +#ifdef CONFIG_GRKERNSEC_ROFS
59141 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59142 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59143 + return -EPERM;
59144 + } else
59145 + return 0;
59146 +#endif
59147 + return 0;
59148 +}
59149 +
59150 +int
59151 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59152 +{
59153 +#ifdef CONFIG_GRKERNSEC_ROFS
59154 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59155 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59156 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59157 + return -EPERM;
59158 + } else
59159 + return 0;
59160 +#endif
59161 + return 0;
59162 +}
59163 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59164 new file mode 100644
59165 index 0000000..a3b12a0
59166 --- /dev/null
59167 +++ b/grsecurity/grsec_pax.c
59168 @@ -0,0 +1,36 @@
59169 +#include <linux/kernel.h>
59170 +#include <linux/sched.h>
59171 +#include <linux/mm.h>
59172 +#include <linux/file.h>
59173 +#include <linux/grinternal.h>
59174 +#include <linux/grsecurity.h>
59175 +
59176 +void
59177 +gr_log_textrel(struct vm_area_struct * vma)
59178 +{
59179 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59180 + if (grsec_enable_audit_textrel)
59181 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59182 +#endif
59183 + return;
59184 +}
59185 +
59186 +void
59187 +gr_log_rwxmmap(struct file *file)
59188 +{
59189 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59190 + if (grsec_enable_log_rwxmaps)
59191 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59192 +#endif
59193 + return;
59194 +}
59195 +
59196 +void
59197 +gr_log_rwxmprotect(struct file *file)
59198 +{
59199 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59200 + if (grsec_enable_log_rwxmaps)
59201 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59202 +#endif
59203 + return;
59204 +}
59205 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59206 new file mode 100644
59207 index 0000000..f7f29aa
59208 --- /dev/null
59209 +++ b/grsecurity/grsec_ptrace.c
59210 @@ -0,0 +1,30 @@
59211 +#include <linux/kernel.h>
59212 +#include <linux/sched.h>
59213 +#include <linux/grinternal.h>
59214 +#include <linux/security.h>
59215 +
59216 +void
59217 +gr_audit_ptrace(struct task_struct *task)
59218 +{
59219 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59220 + if (grsec_enable_audit_ptrace)
59221 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59222 +#endif
59223 + return;
59224 +}
59225 +
59226 +int
59227 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59228 +{
59229 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59230 + const struct dentry *dentry = file->f_path.dentry;
59231 + const struct vfsmount *mnt = file->f_path.mnt;
59232 +
59233 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59234 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59235 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59236 + return -EACCES;
59237 + }
59238 +#endif
59239 + return 0;
59240 +}
59241 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59242 new file mode 100644
59243 index 0000000..b4ac94c
59244 --- /dev/null
59245 +++ b/grsecurity/grsec_sig.c
59246 @@ -0,0 +1,209 @@
59247 +#include <linux/kernel.h>
59248 +#include <linux/sched.h>
59249 +#include <linux/delay.h>
59250 +#include <linux/grsecurity.h>
59251 +#include <linux/grinternal.h>
59252 +#include <linux/hardirq.h>
59253 +
59254 +char *signames[] = {
59255 + [SIGSEGV] = "Segmentation fault",
59256 + [SIGILL] = "Illegal instruction",
59257 + [SIGABRT] = "Abort",
59258 + [SIGBUS] = "Invalid alignment/Bus error"
59259 +};
59260 +
59261 +void
59262 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59263 +{
59264 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59265 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59266 + (sig == SIGABRT) || (sig == SIGBUS))) {
59267 + if (t->pid == current->pid) {
59268 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59269 + } else {
59270 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59271 + }
59272 + }
59273 +#endif
59274 + return;
59275 +}
59276 +
59277 +int
59278 +gr_handle_signal(const struct task_struct *p, const int sig)
59279 +{
59280 +#ifdef CONFIG_GRKERNSEC
59281 + /* ignore the 0 signal for protected task checks */
59282 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59283 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59284 + return -EPERM;
59285 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59286 + return -EPERM;
59287 + }
59288 +#endif
59289 + return 0;
59290 +}
59291 +
59292 +#ifdef CONFIG_GRKERNSEC
59293 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59294 +
59295 +int gr_fake_force_sig(int sig, struct task_struct *t)
59296 +{
59297 + unsigned long int flags;
59298 + int ret, blocked, ignored;
59299 + struct k_sigaction *action;
59300 +
59301 + spin_lock_irqsave(&t->sighand->siglock, flags);
59302 + action = &t->sighand->action[sig-1];
59303 + ignored = action->sa.sa_handler == SIG_IGN;
59304 + blocked = sigismember(&t->blocked, sig);
59305 + if (blocked || ignored) {
59306 + action->sa.sa_handler = SIG_DFL;
59307 + if (blocked) {
59308 + sigdelset(&t->blocked, sig);
59309 + recalc_sigpending_and_wake(t);
59310 + }
59311 + }
59312 + if (action->sa.sa_handler == SIG_DFL)
59313 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59314 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59315 +
59316 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59317 +
59318 + return ret;
59319 +}
59320 +#endif
59321 +
59322 +#ifdef CONFIG_GRKERNSEC_BRUTE
59323 +#define GR_USER_BAN_TIME (15 * 60)
59324 +
59325 +static int __get_dumpable(unsigned long mm_flags)
59326 +{
59327 + int ret;
59328 +
59329 + ret = mm_flags & MMF_DUMPABLE_MASK;
59330 + return (ret >= 2) ? 2 : ret;
59331 +}
59332 +#endif
59333 +
59334 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59335 +{
59336 +#ifdef CONFIG_GRKERNSEC_BRUTE
59337 + kuid_t uid = GLOBAL_ROOT_UID;
59338 +
59339 + if (!grsec_enable_brute)
59340 + return;
59341 +
59342 + rcu_read_lock();
59343 + read_lock(&tasklist_lock);
59344 + read_lock(&grsec_exec_file_lock);
59345 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59346 + p->real_parent->brute = 1;
59347 + else {
59348 + const struct cred *cred = __task_cred(p), *cred2;
59349 + struct task_struct *tsk, *tsk2;
59350 +
59351 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59352 + struct user_struct *user;
59353 +
59354 + uid = cred->uid;
59355 +
59356 + /* this is put upon execution past expiration */
59357 + user = find_user(uid);
59358 + if (user == NULL)
59359 + goto unlock;
59360 + user->banned = 1;
59361 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59362 + if (user->ban_expires == ~0UL)
59363 + user->ban_expires--;
59364 +
59365 + do_each_thread(tsk2, tsk) {
59366 + cred2 = __task_cred(tsk);
59367 + if (tsk != p && uid_eq(cred2->uid, uid))
59368 + gr_fake_force_sig(SIGKILL, tsk);
59369 + } while_each_thread(tsk2, tsk);
59370 + }
59371 + }
59372 +unlock:
59373 + read_unlock(&grsec_exec_file_lock);
59374 + read_unlock(&tasklist_lock);
59375 + rcu_read_unlock();
59376 +
59377 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59378 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59379 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59380 +
59381 +#endif
59382 + return;
59383 +}
59384 +
59385 +void gr_handle_brute_check(void)
59386 +{
59387 +#ifdef CONFIG_GRKERNSEC_BRUTE
59388 + if (current->brute)
59389 + msleep(30 * 1000);
59390 +#endif
59391 + return;
59392 +}
59393 +
59394 +void gr_handle_kernel_exploit(void)
59395 +{
59396 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59397 + const struct cred *cred;
59398 + struct task_struct *tsk, *tsk2;
59399 + struct user_struct *user;
59400 + kuid_t uid;
59401 +
59402 + if (in_irq() || in_serving_softirq() || in_nmi())
59403 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59404 +
59405 + uid = current_uid();
59406 +
59407 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59408 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59409 + else {
59410 + /* kill all the processes of this user, hold a reference
59411 + to their creds struct, and prevent them from creating
59412 + another process until system reset
59413 + */
59414 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59415 + from_kuid_munged(&init_user_ns, uid));
59416 + /* we intentionally leak this ref */
59417 + user = get_uid(current->cred->user);
59418 + if (user) {
59419 + user->banned = 1;
59420 + user->ban_expires = ~0UL;
59421 + }
59422 +
59423 + read_lock(&tasklist_lock);
59424 + do_each_thread(tsk2, tsk) {
59425 + cred = __task_cred(tsk);
59426 + if (uid_eq(cred->uid, uid))
59427 + gr_fake_force_sig(SIGKILL, tsk);
59428 + } while_each_thread(tsk2, tsk);
59429 + read_unlock(&tasklist_lock);
59430 + }
59431 +#endif
59432 +}
59433 +
59434 +int __gr_process_user_ban(struct user_struct *user)
59435 +{
59436 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59437 + if (unlikely(user->banned)) {
59438 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59439 + user->banned = 0;
59440 + user->ban_expires = 0;
59441 + free_uid(user);
59442 + } else
59443 + return -EPERM;
59444 + }
59445 +#endif
59446 + return 0;
59447 +}
59448 +
59449 +int gr_process_user_ban(void)
59450 +{
59451 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59452 + return __gr_process_user_ban(current->cred->user);
59453 +#endif
59454 + return 0;
59455 +}
59456 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59457 new file mode 100644
59458 index 0000000..4030d57
59459 --- /dev/null
59460 +++ b/grsecurity/grsec_sock.c
59461 @@ -0,0 +1,244 @@
59462 +#include <linux/kernel.h>
59463 +#include <linux/module.h>
59464 +#include <linux/sched.h>
59465 +#include <linux/file.h>
59466 +#include <linux/net.h>
59467 +#include <linux/in.h>
59468 +#include <linux/ip.h>
59469 +#include <net/sock.h>
59470 +#include <net/inet_sock.h>
59471 +#include <linux/grsecurity.h>
59472 +#include <linux/grinternal.h>
59473 +#include <linux/gracl.h>
59474 +
59475 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59476 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59477 +
59478 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59479 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59480 +
59481 +#ifdef CONFIG_UNIX_MODULE
59482 +EXPORT_SYMBOL(gr_acl_handle_unix);
59483 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59484 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59485 +EXPORT_SYMBOL(gr_handle_create);
59486 +#endif
59487 +
59488 +#ifdef CONFIG_GRKERNSEC
59489 +#define gr_conn_table_size 32749
59490 +struct conn_table_entry {
59491 + struct conn_table_entry *next;
59492 + struct signal_struct *sig;
59493 +};
59494 +
59495 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59496 +DEFINE_SPINLOCK(gr_conn_table_lock);
59497 +
59498 +extern const char * gr_socktype_to_name(unsigned char type);
59499 +extern const char * gr_proto_to_name(unsigned char proto);
59500 +extern const char * gr_sockfamily_to_name(unsigned char family);
59501 +
59502 +static __inline__ int
59503 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59504 +{
59505 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59506 +}
59507 +
59508 +static __inline__ int
59509 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59510 + __u16 sport, __u16 dport)
59511 +{
59512 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59513 + sig->gr_sport == sport && sig->gr_dport == dport))
59514 + return 1;
59515 + else
59516 + return 0;
59517 +}
59518 +
59519 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59520 +{
59521 + struct conn_table_entry **match;
59522 + unsigned int index;
59523 +
59524 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59525 + sig->gr_sport, sig->gr_dport,
59526 + gr_conn_table_size);
59527 +
59528 + newent->sig = sig;
59529 +
59530 + match = &gr_conn_table[index];
59531 + newent->next = *match;
59532 + *match = newent;
59533 +
59534 + return;
59535 +}
59536 +
59537 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59538 +{
59539 + struct conn_table_entry *match, *last = NULL;
59540 + unsigned int index;
59541 +
59542 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59543 + sig->gr_sport, sig->gr_dport,
59544 + gr_conn_table_size);
59545 +
59546 + match = gr_conn_table[index];
59547 + while (match && !conn_match(match->sig,
59548 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59549 + sig->gr_dport)) {
59550 + last = match;
59551 + match = match->next;
59552 + }
59553 +
59554 + if (match) {
59555 + if (last)
59556 + last->next = match->next;
59557 + else
59558 + gr_conn_table[index] = NULL;
59559 + kfree(match);
59560 + }
59561 +
59562 + return;
59563 +}
59564 +
59565 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59566 + __u16 sport, __u16 dport)
59567 +{
59568 + struct conn_table_entry *match;
59569 + unsigned int index;
59570 +
59571 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59572 +
59573 + match = gr_conn_table[index];
59574 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59575 + match = match->next;
59576 +
59577 + if (match)
59578 + return match->sig;
59579 + else
59580 + return NULL;
59581 +}
59582 +
59583 +#endif
59584 +
59585 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59586 +{
59587 +#ifdef CONFIG_GRKERNSEC
59588 + struct signal_struct *sig = task->signal;
59589 + struct conn_table_entry *newent;
59590 +
59591 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59592 + if (newent == NULL)
59593 + return;
59594 + /* no bh lock needed since we are called with bh disabled */
59595 + spin_lock(&gr_conn_table_lock);
59596 + gr_del_task_from_ip_table_nolock(sig);
59597 + sig->gr_saddr = inet->inet_rcv_saddr;
59598 + sig->gr_daddr = inet->inet_daddr;
59599 + sig->gr_sport = inet->inet_sport;
59600 + sig->gr_dport = inet->inet_dport;
59601 + gr_add_to_task_ip_table_nolock(sig, newent);
59602 + spin_unlock(&gr_conn_table_lock);
59603 +#endif
59604 + return;
59605 +}
59606 +
59607 +void gr_del_task_from_ip_table(struct task_struct *task)
59608 +{
59609 +#ifdef CONFIG_GRKERNSEC
59610 + spin_lock_bh(&gr_conn_table_lock);
59611 + gr_del_task_from_ip_table_nolock(task->signal);
59612 + spin_unlock_bh(&gr_conn_table_lock);
59613 +#endif
59614 + return;
59615 +}
59616 +
59617 +void
59618 +gr_attach_curr_ip(const struct sock *sk)
59619 +{
59620 +#ifdef CONFIG_GRKERNSEC
59621 + struct signal_struct *p, *set;
59622 + const struct inet_sock *inet = inet_sk(sk);
59623 +
59624 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59625 + return;
59626 +
59627 + set = current->signal;
59628 +
59629 + spin_lock_bh(&gr_conn_table_lock);
59630 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59631 + inet->inet_dport, inet->inet_sport);
59632 + if (unlikely(p != NULL)) {
59633 + set->curr_ip = p->curr_ip;
59634 + set->used_accept = 1;
59635 + gr_del_task_from_ip_table_nolock(p);
59636 + spin_unlock_bh(&gr_conn_table_lock);
59637 + return;
59638 + }
59639 + spin_unlock_bh(&gr_conn_table_lock);
59640 +
59641 + set->curr_ip = inet->inet_daddr;
59642 + set->used_accept = 1;
59643 +#endif
59644 + return;
59645 +}
59646 +
59647 +int
59648 +gr_handle_sock_all(const int family, const int type, const int protocol)
59649 +{
59650 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59651 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59652 + (family != AF_UNIX)) {
59653 + if (family == AF_INET)
59654 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59655 + else
59656 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59657 + return -EACCES;
59658 + }
59659 +#endif
59660 + return 0;
59661 +}
59662 +
59663 +int
59664 +gr_handle_sock_server(const struct sockaddr *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->sa_family != AF_UNIX) &&
59670 + (sck->sa_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_server_other(const struct sock *sck)
59680 +{
59681 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59682 + if (grsec_enable_socket_server &&
59683 + in_group_p(grsec_socket_server_gid) &&
59684 + sck && (sck->sk_family != AF_UNIX) &&
59685 + (sck->sk_family != AF_LOCAL)) {
59686 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59687 + return -EACCES;
59688 + }
59689 +#endif
59690 + return 0;
59691 +}
59692 +
59693 +int
59694 +gr_handle_sock_client(const struct sockaddr *sck)
59695 +{
59696 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59697 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59698 + sck && (sck->sa_family != AF_UNIX) &&
59699 + (sck->sa_family != AF_LOCAL)) {
59700 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59701 + return -EACCES;
59702 + }
59703 +#endif
59704 + return 0;
59705 +}
59706 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59707 new file mode 100644
59708 index 0000000..f55ef0f
59709 --- /dev/null
59710 +++ b/grsecurity/grsec_sysctl.c
59711 @@ -0,0 +1,469 @@
59712 +#include <linux/kernel.h>
59713 +#include <linux/sched.h>
59714 +#include <linux/sysctl.h>
59715 +#include <linux/grsecurity.h>
59716 +#include <linux/grinternal.h>
59717 +
59718 +int
59719 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59720 +{
59721 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59722 + if (dirname == NULL || name == NULL)
59723 + return 0;
59724 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59725 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59726 + return -EACCES;
59727 + }
59728 +#endif
59729 + return 0;
59730 +}
59731 +
59732 +#ifdef CONFIG_GRKERNSEC_ROFS
59733 +static int __maybe_unused one = 1;
59734 +#endif
59735 +
59736 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59737 +struct ctl_table grsecurity_table[] = {
59738 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59739 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59740 +#ifdef CONFIG_GRKERNSEC_IO
59741 + {
59742 + .procname = "disable_priv_io",
59743 + .data = &grsec_disable_privio,
59744 + .maxlen = sizeof(int),
59745 + .mode = 0600,
59746 + .proc_handler = &proc_dointvec,
59747 + },
59748 +#endif
59749 +#endif
59750 +#ifdef CONFIG_GRKERNSEC_LINK
59751 + {
59752 + .procname = "linking_restrictions",
59753 + .data = &grsec_enable_link,
59754 + .maxlen = sizeof(int),
59755 + .mode = 0600,
59756 + .proc_handler = &proc_dointvec,
59757 + },
59758 +#endif
59759 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59760 + {
59761 + .procname = "enforce_symlinksifowner",
59762 + .data = &grsec_enable_symlinkown,
59763 + .maxlen = sizeof(int),
59764 + .mode = 0600,
59765 + .proc_handler = &proc_dointvec,
59766 + },
59767 + {
59768 + .procname = "symlinkown_gid",
59769 + .data = &grsec_symlinkown_gid,
59770 + .maxlen = sizeof(int),
59771 + .mode = 0600,
59772 + .proc_handler = &proc_dointvec,
59773 + },
59774 +#endif
59775 +#ifdef CONFIG_GRKERNSEC_BRUTE
59776 + {
59777 + .procname = "deter_bruteforce",
59778 + .data = &grsec_enable_brute,
59779 + .maxlen = sizeof(int),
59780 + .mode = 0600,
59781 + .proc_handler = &proc_dointvec,
59782 + },
59783 +#endif
59784 +#ifdef CONFIG_GRKERNSEC_FIFO
59785 + {
59786 + .procname = "fifo_restrictions",
59787 + .data = &grsec_enable_fifo,
59788 + .maxlen = sizeof(int),
59789 + .mode = 0600,
59790 + .proc_handler = &proc_dointvec,
59791 + },
59792 +#endif
59793 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59794 + {
59795 + .procname = "ptrace_readexec",
59796 + .data = &grsec_enable_ptrace_readexec,
59797 + .maxlen = sizeof(int),
59798 + .mode = 0600,
59799 + .proc_handler = &proc_dointvec,
59800 + },
59801 +#endif
59802 +#ifdef CONFIG_GRKERNSEC_SETXID
59803 + {
59804 + .procname = "consistent_setxid",
59805 + .data = &grsec_enable_setxid,
59806 + .maxlen = sizeof(int),
59807 + .mode = 0600,
59808 + .proc_handler = &proc_dointvec,
59809 + },
59810 +#endif
59811 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59812 + {
59813 + .procname = "ip_blackhole",
59814 + .data = &grsec_enable_blackhole,
59815 + .maxlen = sizeof(int),
59816 + .mode = 0600,
59817 + .proc_handler = &proc_dointvec,
59818 + },
59819 + {
59820 + .procname = "lastack_retries",
59821 + .data = &grsec_lastack_retries,
59822 + .maxlen = sizeof(int),
59823 + .mode = 0600,
59824 + .proc_handler = &proc_dointvec,
59825 + },
59826 +#endif
59827 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59828 + {
59829 + .procname = "exec_logging",
59830 + .data = &grsec_enable_execlog,
59831 + .maxlen = sizeof(int),
59832 + .mode = 0600,
59833 + .proc_handler = &proc_dointvec,
59834 + },
59835 +#endif
59836 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59837 + {
59838 + .procname = "rwxmap_logging",
59839 + .data = &grsec_enable_log_rwxmaps,
59840 + .maxlen = sizeof(int),
59841 + .mode = 0600,
59842 + .proc_handler = &proc_dointvec,
59843 + },
59844 +#endif
59845 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59846 + {
59847 + .procname = "signal_logging",
59848 + .data = &grsec_enable_signal,
59849 + .maxlen = sizeof(int),
59850 + .mode = 0600,
59851 + .proc_handler = &proc_dointvec,
59852 + },
59853 +#endif
59854 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59855 + {
59856 + .procname = "forkfail_logging",
59857 + .data = &grsec_enable_forkfail,
59858 + .maxlen = sizeof(int),
59859 + .mode = 0600,
59860 + .proc_handler = &proc_dointvec,
59861 + },
59862 +#endif
59863 +#ifdef CONFIG_GRKERNSEC_TIME
59864 + {
59865 + .procname = "timechange_logging",
59866 + .data = &grsec_enable_time,
59867 + .maxlen = sizeof(int),
59868 + .mode = 0600,
59869 + .proc_handler = &proc_dointvec,
59870 + },
59871 +#endif
59872 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59873 + {
59874 + .procname = "chroot_deny_shmat",
59875 + .data = &grsec_enable_chroot_shmat,
59876 + .maxlen = sizeof(int),
59877 + .mode = 0600,
59878 + .proc_handler = &proc_dointvec,
59879 + },
59880 +#endif
59881 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59882 + {
59883 + .procname = "chroot_deny_unix",
59884 + .data = &grsec_enable_chroot_unix,
59885 + .maxlen = sizeof(int),
59886 + .mode = 0600,
59887 + .proc_handler = &proc_dointvec,
59888 + },
59889 +#endif
59890 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59891 + {
59892 + .procname = "chroot_deny_mount",
59893 + .data = &grsec_enable_chroot_mount,
59894 + .maxlen = sizeof(int),
59895 + .mode = 0600,
59896 + .proc_handler = &proc_dointvec,
59897 + },
59898 +#endif
59899 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59900 + {
59901 + .procname = "chroot_deny_fchdir",
59902 + .data = &grsec_enable_chroot_fchdir,
59903 + .maxlen = sizeof(int),
59904 + .mode = 0600,
59905 + .proc_handler = &proc_dointvec,
59906 + },
59907 +#endif
59908 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59909 + {
59910 + .procname = "chroot_deny_chroot",
59911 + .data = &grsec_enable_chroot_double,
59912 + .maxlen = sizeof(int),
59913 + .mode = 0600,
59914 + .proc_handler = &proc_dointvec,
59915 + },
59916 +#endif
59917 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59918 + {
59919 + .procname = "chroot_deny_pivot",
59920 + .data = &grsec_enable_chroot_pivot,
59921 + .maxlen = sizeof(int),
59922 + .mode = 0600,
59923 + .proc_handler = &proc_dointvec,
59924 + },
59925 +#endif
59926 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59927 + {
59928 + .procname = "chroot_enforce_chdir",
59929 + .data = &grsec_enable_chroot_chdir,
59930 + .maxlen = sizeof(int),
59931 + .mode = 0600,
59932 + .proc_handler = &proc_dointvec,
59933 + },
59934 +#endif
59935 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59936 + {
59937 + .procname = "chroot_deny_chmod",
59938 + .data = &grsec_enable_chroot_chmod,
59939 + .maxlen = sizeof(int),
59940 + .mode = 0600,
59941 + .proc_handler = &proc_dointvec,
59942 + },
59943 +#endif
59944 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59945 + {
59946 + .procname = "chroot_deny_mknod",
59947 + .data = &grsec_enable_chroot_mknod,
59948 + .maxlen = sizeof(int),
59949 + .mode = 0600,
59950 + .proc_handler = &proc_dointvec,
59951 + },
59952 +#endif
59953 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59954 + {
59955 + .procname = "chroot_restrict_nice",
59956 + .data = &grsec_enable_chroot_nice,
59957 + .maxlen = sizeof(int),
59958 + .mode = 0600,
59959 + .proc_handler = &proc_dointvec,
59960 + },
59961 +#endif
59962 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59963 + {
59964 + .procname = "chroot_execlog",
59965 + .data = &grsec_enable_chroot_execlog,
59966 + .maxlen = sizeof(int),
59967 + .mode = 0600,
59968 + .proc_handler = &proc_dointvec,
59969 + },
59970 +#endif
59971 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59972 + {
59973 + .procname = "chroot_caps",
59974 + .data = &grsec_enable_chroot_caps,
59975 + .maxlen = sizeof(int),
59976 + .mode = 0600,
59977 + .proc_handler = &proc_dointvec,
59978 + },
59979 +#endif
59980 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59981 + {
59982 + .procname = "chroot_deny_sysctl",
59983 + .data = &grsec_enable_chroot_sysctl,
59984 + .maxlen = sizeof(int),
59985 + .mode = 0600,
59986 + .proc_handler = &proc_dointvec,
59987 + },
59988 +#endif
59989 +#ifdef CONFIG_GRKERNSEC_TPE
59990 + {
59991 + .procname = "tpe",
59992 + .data = &grsec_enable_tpe,
59993 + .maxlen = sizeof(int),
59994 + .mode = 0600,
59995 + .proc_handler = &proc_dointvec,
59996 + },
59997 + {
59998 + .procname = "tpe_gid",
59999 + .data = &grsec_tpe_gid,
60000 + .maxlen = sizeof(int),
60001 + .mode = 0600,
60002 + .proc_handler = &proc_dointvec,
60003 + },
60004 +#endif
60005 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60006 + {
60007 + .procname = "tpe_invert",
60008 + .data = &grsec_enable_tpe_invert,
60009 + .maxlen = sizeof(int),
60010 + .mode = 0600,
60011 + .proc_handler = &proc_dointvec,
60012 + },
60013 +#endif
60014 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60015 + {
60016 + .procname = "tpe_restrict_all",
60017 + .data = &grsec_enable_tpe_all,
60018 + .maxlen = sizeof(int),
60019 + .mode = 0600,
60020 + .proc_handler = &proc_dointvec,
60021 + },
60022 +#endif
60023 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60024 + {
60025 + .procname = "socket_all",
60026 + .data = &grsec_enable_socket_all,
60027 + .maxlen = sizeof(int),
60028 + .mode = 0600,
60029 + .proc_handler = &proc_dointvec,
60030 + },
60031 + {
60032 + .procname = "socket_all_gid",
60033 + .data = &grsec_socket_all_gid,
60034 + .maxlen = sizeof(int),
60035 + .mode = 0600,
60036 + .proc_handler = &proc_dointvec,
60037 + },
60038 +#endif
60039 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60040 + {
60041 + .procname = "socket_client",
60042 + .data = &grsec_enable_socket_client,
60043 + .maxlen = sizeof(int),
60044 + .mode = 0600,
60045 + .proc_handler = &proc_dointvec,
60046 + },
60047 + {
60048 + .procname = "socket_client_gid",
60049 + .data = &grsec_socket_client_gid,
60050 + .maxlen = sizeof(int),
60051 + .mode = 0600,
60052 + .proc_handler = &proc_dointvec,
60053 + },
60054 +#endif
60055 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60056 + {
60057 + .procname = "socket_server",
60058 + .data = &grsec_enable_socket_server,
60059 + .maxlen = sizeof(int),
60060 + .mode = 0600,
60061 + .proc_handler = &proc_dointvec,
60062 + },
60063 + {
60064 + .procname = "socket_server_gid",
60065 + .data = &grsec_socket_server_gid,
60066 + .maxlen = sizeof(int),
60067 + .mode = 0600,
60068 + .proc_handler = &proc_dointvec,
60069 + },
60070 +#endif
60071 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60072 + {
60073 + .procname = "audit_group",
60074 + .data = &grsec_enable_group,
60075 + .maxlen = sizeof(int),
60076 + .mode = 0600,
60077 + .proc_handler = &proc_dointvec,
60078 + },
60079 + {
60080 + .procname = "audit_gid",
60081 + .data = &grsec_audit_gid,
60082 + .maxlen = sizeof(int),
60083 + .mode = 0600,
60084 + .proc_handler = &proc_dointvec,
60085 + },
60086 +#endif
60087 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60088 + {
60089 + .procname = "audit_chdir",
60090 + .data = &grsec_enable_chdir,
60091 + .maxlen = sizeof(int),
60092 + .mode = 0600,
60093 + .proc_handler = &proc_dointvec,
60094 + },
60095 +#endif
60096 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60097 + {
60098 + .procname = "audit_mount",
60099 + .data = &grsec_enable_mount,
60100 + .maxlen = sizeof(int),
60101 + .mode = 0600,
60102 + .proc_handler = &proc_dointvec,
60103 + },
60104 +#endif
60105 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60106 + {
60107 + .procname = "audit_textrel",
60108 + .data = &grsec_enable_audit_textrel,
60109 + .maxlen = sizeof(int),
60110 + .mode = 0600,
60111 + .proc_handler = &proc_dointvec,
60112 + },
60113 +#endif
60114 +#ifdef CONFIG_GRKERNSEC_DMESG
60115 + {
60116 + .procname = "dmesg",
60117 + .data = &grsec_enable_dmesg,
60118 + .maxlen = sizeof(int),
60119 + .mode = 0600,
60120 + .proc_handler = &proc_dointvec,
60121 + },
60122 +#endif
60123 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60124 + {
60125 + .procname = "chroot_findtask",
60126 + .data = &grsec_enable_chroot_findtask,
60127 + .maxlen = sizeof(int),
60128 + .mode = 0600,
60129 + .proc_handler = &proc_dointvec,
60130 + },
60131 +#endif
60132 +#ifdef CONFIG_GRKERNSEC_RESLOG
60133 + {
60134 + .procname = "resource_logging",
60135 + .data = &grsec_resource_logging,
60136 + .maxlen = sizeof(int),
60137 + .mode = 0600,
60138 + .proc_handler = &proc_dointvec,
60139 + },
60140 +#endif
60141 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60142 + {
60143 + .procname = "audit_ptrace",
60144 + .data = &grsec_enable_audit_ptrace,
60145 + .maxlen = sizeof(int),
60146 + .mode = 0600,
60147 + .proc_handler = &proc_dointvec,
60148 + },
60149 +#endif
60150 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60151 + {
60152 + .procname = "harden_ptrace",
60153 + .data = &grsec_enable_harden_ptrace,
60154 + .maxlen = sizeof(int),
60155 + .mode = 0600,
60156 + .proc_handler = &proc_dointvec,
60157 + },
60158 +#endif
60159 + {
60160 + .procname = "grsec_lock",
60161 + .data = &grsec_lock,
60162 + .maxlen = sizeof(int),
60163 + .mode = 0600,
60164 + .proc_handler = &proc_dointvec,
60165 + },
60166 +#endif
60167 +#ifdef CONFIG_GRKERNSEC_ROFS
60168 + {
60169 + .procname = "romount_protect",
60170 + .data = &grsec_enable_rofs,
60171 + .maxlen = sizeof(int),
60172 + .mode = 0600,
60173 + .proc_handler = &proc_dointvec_minmax,
60174 + .extra1 = &one,
60175 + .extra2 = &one,
60176 + },
60177 +#endif
60178 + { }
60179 +};
60180 +#endif
60181 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60182 new file mode 100644
60183 index 0000000..0dc13c3
60184 --- /dev/null
60185 +++ b/grsecurity/grsec_time.c
60186 @@ -0,0 +1,16 @@
60187 +#include <linux/kernel.h>
60188 +#include <linux/sched.h>
60189 +#include <linux/grinternal.h>
60190 +#include <linux/module.h>
60191 +
60192 +void
60193 +gr_log_timechange(void)
60194 +{
60195 +#ifdef CONFIG_GRKERNSEC_TIME
60196 + if (grsec_enable_time)
60197 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60198 +#endif
60199 + return;
60200 +}
60201 +
60202 +EXPORT_SYMBOL(gr_log_timechange);
60203 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60204 new file mode 100644
60205 index 0000000..07e0dc0
60206 --- /dev/null
60207 +++ b/grsecurity/grsec_tpe.c
60208 @@ -0,0 +1,73 @@
60209 +#include <linux/kernel.h>
60210 +#include <linux/sched.h>
60211 +#include <linux/file.h>
60212 +#include <linux/fs.h>
60213 +#include <linux/grinternal.h>
60214 +
60215 +extern int gr_acl_tpe_check(void);
60216 +
60217 +int
60218 +gr_tpe_allow(const struct file *file)
60219 +{
60220 +#ifdef CONFIG_GRKERNSEC
60221 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60222 + const struct cred *cred = current_cred();
60223 + char *msg = NULL;
60224 + char *msg2 = NULL;
60225 +
60226 + // never restrict root
60227 + if (!cred->uid)
60228 + return 1;
60229 +
60230 + if (grsec_enable_tpe) {
60231 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60232 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60233 + msg = "not being in trusted group";
60234 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60235 + msg = "being in untrusted group";
60236 +#else
60237 + if (in_group_p(grsec_tpe_gid))
60238 + msg = "being in untrusted group";
60239 +#endif
60240 + }
60241 + if (!msg && gr_acl_tpe_check())
60242 + msg = "being in untrusted role";
60243 +
60244 + // not in any affected group/role
60245 + if (!msg)
60246 + goto next_check;
60247 +
60248 + if (inode->i_uid)
60249 + msg2 = "file in non-root-owned directory";
60250 + else if (inode->i_mode & S_IWOTH)
60251 + msg2 = "file in world-writable directory";
60252 + else if (inode->i_mode & S_IWGRP)
60253 + msg2 = "file in group-writable directory";
60254 +
60255 + if (msg && msg2) {
60256 + char fullmsg[70] = {0};
60257 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60258 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60259 + return 0;
60260 + }
60261 + msg = NULL;
60262 +next_check:
60263 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60264 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60265 + return 1;
60266 +
60267 + if (inode->i_uid && (inode->i_uid != cred->uid))
60268 + msg = "directory not owned by user";
60269 + else if (inode->i_mode & S_IWOTH)
60270 + msg = "file in world-writable directory";
60271 + else if (inode->i_mode & S_IWGRP)
60272 + msg = "file in group-writable directory";
60273 +
60274 + if (msg) {
60275 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60276 + return 0;
60277 + }
60278 +#endif
60279 +#endif
60280 + return 1;
60281 +}
60282 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60283 new file mode 100644
60284 index 0000000..9f7b1ac
60285 --- /dev/null
60286 +++ b/grsecurity/grsum.c
60287 @@ -0,0 +1,61 @@
60288 +#include <linux/err.h>
60289 +#include <linux/kernel.h>
60290 +#include <linux/sched.h>
60291 +#include <linux/mm.h>
60292 +#include <linux/scatterlist.h>
60293 +#include <linux/crypto.h>
60294 +#include <linux/gracl.h>
60295 +
60296 +
60297 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60298 +#error "crypto and sha256 must be built into the kernel"
60299 +#endif
60300 +
60301 +int
60302 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60303 +{
60304 + char *p;
60305 + struct crypto_hash *tfm;
60306 + struct hash_desc desc;
60307 + struct scatterlist sg;
60308 + unsigned char temp_sum[GR_SHA_LEN];
60309 + volatile int retval = 0;
60310 + volatile int dummy = 0;
60311 + unsigned int i;
60312 +
60313 + sg_init_table(&sg, 1);
60314 +
60315 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60316 + if (IS_ERR(tfm)) {
60317 + /* should never happen, since sha256 should be built in */
60318 + return 1;
60319 + }
60320 +
60321 + desc.tfm = tfm;
60322 + desc.flags = 0;
60323 +
60324 + crypto_hash_init(&desc);
60325 +
60326 + p = salt;
60327 + sg_set_buf(&sg, p, GR_SALT_LEN);
60328 + crypto_hash_update(&desc, &sg, sg.length);
60329 +
60330 + p = entry->pw;
60331 + sg_set_buf(&sg, p, strlen(p));
60332 +
60333 + crypto_hash_update(&desc, &sg, sg.length);
60334 +
60335 + crypto_hash_final(&desc, temp_sum);
60336 +
60337 + memset(entry->pw, 0, GR_PW_LEN);
60338 +
60339 + for (i = 0; i < GR_SHA_LEN; i++)
60340 + if (sum[i] != temp_sum[i])
60341 + retval = 1;
60342 + else
60343 + dummy = 1; // waste a cycle
60344 +
60345 + crypto_free_hash(tfm);
60346 +
60347 + return retval;
60348 +}
60349 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60350 index bde976e..a1cc32a 100644
60351 --- a/include/acpi/acpi_bus.h
60352 +++ b/include/acpi/acpi_bus.h
60353 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60354 acpi_op_bind bind;
60355 acpi_op_unbind unbind;
60356 acpi_op_notify notify;
60357 -};
60358 +} __no_const;
60359
60360 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60361
60362 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60363 index 77ff547..181834f 100644
60364 --- a/include/asm-generic/4level-fixup.h
60365 +++ b/include/asm-generic/4level-fixup.h
60366 @@ -13,8 +13,10 @@
60367 #define pmd_alloc(mm, pud, address) \
60368 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60369 NULL: pmd_offset(pud, address))
60370 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60371
60372 #define pud_alloc(mm, pgd, address) (pgd)
60373 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60374 #define pud_offset(pgd, start) (pgd)
60375 #define pud_none(pud) 0
60376 #define pud_bad(pud) 0
60377 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60378 index b7babf0..3ba8aee 100644
60379 --- a/include/asm-generic/atomic-long.h
60380 +++ b/include/asm-generic/atomic-long.h
60381 @@ -22,6 +22,12 @@
60382
60383 typedef atomic64_t atomic_long_t;
60384
60385 +#ifdef CONFIG_PAX_REFCOUNT
60386 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60387 +#else
60388 +typedef atomic64_t atomic_long_unchecked_t;
60389 +#endif
60390 +
60391 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60392
60393 static inline long atomic_long_read(atomic_long_t *l)
60394 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60395 return (long)atomic64_read(v);
60396 }
60397
60398 +#ifdef CONFIG_PAX_REFCOUNT
60399 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60400 +{
60401 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60402 +
60403 + return (long)atomic64_read_unchecked(v);
60404 +}
60405 +#endif
60406 +
60407 static inline void atomic_long_set(atomic_long_t *l, long i)
60408 {
60409 atomic64_t *v = (atomic64_t *)l;
60410 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60411 atomic64_set(v, i);
60412 }
60413
60414 +#ifdef CONFIG_PAX_REFCOUNT
60415 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60416 +{
60417 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60418 +
60419 + atomic64_set_unchecked(v, i);
60420 +}
60421 +#endif
60422 +
60423 static inline void atomic_long_inc(atomic_long_t *l)
60424 {
60425 atomic64_t *v = (atomic64_t *)l;
60426 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60427 atomic64_inc(v);
60428 }
60429
60430 +#ifdef CONFIG_PAX_REFCOUNT
60431 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60432 +{
60433 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60434 +
60435 + atomic64_inc_unchecked(v);
60436 +}
60437 +#endif
60438 +
60439 static inline void atomic_long_dec(atomic_long_t *l)
60440 {
60441 atomic64_t *v = (atomic64_t *)l;
60442 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60443 atomic64_dec(v);
60444 }
60445
60446 +#ifdef CONFIG_PAX_REFCOUNT
60447 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60448 +{
60449 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60450 +
60451 + atomic64_dec_unchecked(v);
60452 +}
60453 +#endif
60454 +
60455 static inline void atomic_long_add(long i, atomic_long_t *l)
60456 {
60457 atomic64_t *v = (atomic64_t *)l;
60458 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60459 atomic64_add(i, v);
60460 }
60461
60462 +#ifdef CONFIG_PAX_REFCOUNT
60463 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60464 +{
60465 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60466 +
60467 + atomic64_add_unchecked(i, v);
60468 +}
60469 +#endif
60470 +
60471 static inline void atomic_long_sub(long i, atomic_long_t *l)
60472 {
60473 atomic64_t *v = (atomic64_t *)l;
60474 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60475 atomic64_sub(i, v);
60476 }
60477
60478 +#ifdef CONFIG_PAX_REFCOUNT
60479 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60480 +{
60481 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60482 +
60483 + atomic64_sub_unchecked(i, v);
60484 +}
60485 +#endif
60486 +
60487 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60488 {
60489 atomic64_t *v = (atomic64_t *)l;
60490 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60491 return (long)atomic64_inc_return(v);
60492 }
60493
60494 +#ifdef CONFIG_PAX_REFCOUNT
60495 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60496 +{
60497 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60498 +
60499 + return (long)atomic64_inc_return_unchecked(v);
60500 +}
60501 +#endif
60502 +
60503 static inline long atomic_long_dec_return(atomic_long_t *l)
60504 {
60505 atomic64_t *v = (atomic64_t *)l;
60506 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60507
60508 typedef atomic_t atomic_long_t;
60509
60510 +#ifdef CONFIG_PAX_REFCOUNT
60511 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60512 +#else
60513 +typedef atomic_t atomic_long_unchecked_t;
60514 +#endif
60515 +
60516 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60517 static inline long atomic_long_read(atomic_long_t *l)
60518 {
60519 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60520 return (long)atomic_read(v);
60521 }
60522
60523 +#ifdef CONFIG_PAX_REFCOUNT
60524 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60525 +{
60526 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60527 +
60528 + return (long)atomic_read_unchecked(v);
60529 +}
60530 +#endif
60531 +
60532 static inline void atomic_long_set(atomic_long_t *l, long i)
60533 {
60534 atomic_t *v = (atomic_t *)l;
60535 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60536 atomic_set(v, i);
60537 }
60538
60539 +#ifdef CONFIG_PAX_REFCOUNT
60540 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60541 +{
60542 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60543 +
60544 + atomic_set_unchecked(v, i);
60545 +}
60546 +#endif
60547 +
60548 static inline void atomic_long_inc(atomic_long_t *l)
60549 {
60550 atomic_t *v = (atomic_t *)l;
60551 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60552 atomic_inc(v);
60553 }
60554
60555 +#ifdef CONFIG_PAX_REFCOUNT
60556 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60557 +{
60558 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60559 +
60560 + atomic_inc_unchecked(v);
60561 +}
60562 +#endif
60563 +
60564 static inline void atomic_long_dec(atomic_long_t *l)
60565 {
60566 atomic_t *v = (atomic_t *)l;
60567 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60568 atomic_dec(v);
60569 }
60570
60571 +#ifdef CONFIG_PAX_REFCOUNT
60572 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60573 +{
60574 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60575 +
60576 + atomic_dec_unchecked(v);
60577 +}
60578 +#endif
60579 +
60580 static inline void atomic_long_add(long i, atomic_long_t *l)
60581 {
60582 atomic_t *v = (atomic_t *)l;
60583 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60584 atomic_add(i, v);
60585 }
60586
60587 +#ifdef CONFIG_PAX_REFCOUNT
60588 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60589 +{
60590 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60591 +
60592 + atomic_add_unchecked(i, v);
60593 +}
60594 +#endif
60595 +
60596 static inline void atomic_long_sub(long i, atomic_long_t *l)
60597 {
60598 atomic_t *v = (atomic_t *)l;
60599 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60600 atomic_sub(i, v);
60601 }
60602
60603 +#ifdef CONFIG_PAX_REFCOUNT
60604 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60605 +{
60606 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60607 +
60608 + atomic_sub_unchecked(i, v);
60609 +}
60610 +#endif
60611 +
60612 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60613 {
60614 atomic_t *v = (atomic_t *)l;
60615 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60616 return (long)atomic_inc_return(v);
60617 }
60618
60619 +#ifdef CONFIG_PAX_REFCOUNT
60620 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60621 +{
60622 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60623 +
60624 + return (long)atomic_inc_return_unchecked(v);
60625 +}
60626 +#endif
60627 +
60628 static inline long atomic_long_dec_return(atomic_long_t *l)
60629 {
60630 atomic_t *v = (atomic_t *)l;
60631 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60632
60633 #endif /* BITS_PER_LONG == 64 */
60634
60635 +#ifdef CONFIG_PAX_REFCOUNT
60636 +static inline void pax_refcount_needs_these_functions(void)
60637 +{
60638 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60639 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60640 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60641 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60642 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60643 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60644 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60645 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60646 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60647 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60648 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60649 +#ifdef CONFIG_X86
60650 + atomic_clear_mask_unchecked(0, NULL);
60651 + atomic_set_mask_unchecked(0, NULL);
60652 +#endif
60653 +
60654 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60655 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60656 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60657 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60658 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60659 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60660 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60661 +}
60662 +#else
60663 +#define atomic_read_unchecked(v) atomic_read(v)
60664 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60665 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60666 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60667 +#define atomic_inc_unchecked(v) atomic_inc(v)
60668 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60669 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60670 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60671 +#define atomic_dec_unchecked(v) atomic_dec(v)
60672 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60673 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60674 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60675 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60676 +
60677 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60678 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60679 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60680 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60681 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60682 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60683 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60684 +#endif
60685 +
60686 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60687 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60688 index 1ced641..c896ee8 100644
60689 --- a/include/asm-generic/atomic.h
60690 +++ b/include/asm-generic/atomic.h
60691 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60692 * Atomically clears the bits set in @mask from @v
60693 */
60694 #ifndef atomic_clear_mask
60695 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60696 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60697 {
60698 unsigned long flags;
60699
60700 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60701 index b18ce4f..2ee2843 100644
60702 --- a/include/asm-generic/atomic64.h
60703 +++ b/include/asm-generic/atomic64.h
60704 @@ -16,6 +16,8 @@ typedef struct {
60705 long long counter;
60706 } atomic64_t;
60707
60708 +typedef atomic64_t atomic64_unchecked_t;
60709 +
60710 #define ATOMIC64_INIT(i) { (i) }
60711
60712 extern long long atomic64_read(const atomic64_t *v);
60713 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60714 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60715 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60716
60717 +#define atomic64_read_unchecked(v) atomic64_read(v)
60718 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60719 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60720 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60721 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60722 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60723 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60724 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60725 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60726 +
60727 #endif /* _ASM_GENERIC_ATOMIC64_H */
60728 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60729 index 1bfcfe5..e04c5c9 100644
60730 --- a/include/asm-generic/cache.h
60731 +++ b/include/asm-generic/cache.h
60732 @@ -6,7 +6,7 @@
60733 * cache lines need to provide their own cache.h.
60734 */
60735
60736 -#define L1_CACHE_SHIFT 5
60737 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60738 +#define L1_CACHE_SHIFT 5UL
60739 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60740
60741 #endif /* __ASM_GENERIC_CACHE_H */
60742 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60743 index 0d68a1e..b74a761 100644
60744 --- a/include/asm-generic/emergency-restart.h
60745 +++ b/include/asm-generic/emergency-restart.h
60746 @@ -1,7 +1,7 @@
60747 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60748 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60749
60750 -static inline void machine_emergency_restart(void)
60751 +static inline __noreturn void machine_emergency_restart(void)
60752 {
60753 machine_restart(NULL);
60754 }
60755 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60756 index 90f99c7..00ce236 100644
60757 --- a/include/asm-generic/kmap_types.h
60758 +++ b/include/asm-generic/kmap_types.h
60759 @@ -2,9 +2,9 @@
60760 #define _ASM_GENERIC_KMAP_TYPES_H
60761
60762 #ifdef __WITH_KM_FENCE
60763 -# define KM_TYPE_NR 41
60764 +# define KM_TYPE_NR 42
60765 #else
60766 -# define KM_TYPE_NR 20
60767 +# define KM_TYPE_NR 21
60768 #endif
60769
60770 #endif
60771 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60772 index 9ceb03b..2efbcbd 100644
60773 --- a/include/asm-generic/local.h
60774 +++ b/include/asm-generic/local.h
60775 @@ -39,6 +39,7 @@ typedef struct
60776 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60777 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60778 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60779 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60780
60781 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60782 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60783 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60784 index 725612b..9cc513a 100644
60785 --- a/include/asm-generic/pgtable-nopmd.h
60786 +++ b/include/asm-generic/pgtable-nopmd.h
60787 @@ -1,14 +1,19 @@
60788 #ifndef _PGTABLE_NOPMD_H
60789 #define _PGTABLE_NOPMD_H
60790
60791 -#ifndef __ASSEMBLY__
60792 -
60793 #include <asm-generic/pgtable-nopud.h>
60794
60795 -struct mm_struct;
60796 -
60797 #define __PAGETABLE_PMD_FOLDED
60798
60799 +#define PMD_SHIFT PUD_SHIFT
60800 +#define PTRS_PER_PMD 1
60801 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60802 +#define PMD_MASK (~(PMD_SIZE-1))
60803 +
60804 +#ifndef __ASSEMBLY__
60805 +
60806 +struct mm_struct;
60807 +
60808 /*
60809 * Having the pmd type consist of a pud gets the size right, and allows
60810 * us to conceptually access the pud entry that this pmd is folded into
60811 @@ -16,11 +21,6 @@ struct mm_struct;
60812 */
60813 typedef struct { pud_t pud; } pmd_t;
60814
60815 -#define PMD_SHIFT PUD_SHIFT
60816 -#define PTRS_PER_PMD 1
60817 -#define PMD_SIZE (1UL << PMD_SHIFT)
60818 -#define PMD_MASK (~(PMD_SIZE-1))
60819 -
60820 /*
60821 * The "pud_xxx()" functions here are trivial for a folded two-level
60822 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60823 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60824 index 810431d..0ec4804f 100644
60825 --- a/include/asm-generic/pgtable-nopud.h
60826 +++ b/include/asm-generic/pgtable-nopud.h
60827 @@ -1,10 +1,15 @@
60828 #ifndef _PGTABLE_NOPUD_H
60829 #define _PGTABLE_NOPUD_H
60830
60831 -#ifndef __ASSEMBLY__
60832 -
60833 #define __PAGETABLE_PUD_FOLDED
60834
60835 +#define PUD_SHIFT PGDIR_SHIFT
60836 +#define PTRS_PER_PUD 1
60837 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60838 +#define PUD_MASK (~(PUD_SIZE-1))
60839 +
60840 +#ifndef __ASSEMBLY__
60841 +
60842 /*
60843 * Having the pud type consist of a pgd gets the size right, and allows
60844 * us to conceptually access the pgd entry that this pud is folded into
60845 @@ -12,11 +17,6 @@
60846 */
60847 typedef struct { pgd_t pgd; } pud_t;
60848
60849 -#define PUD_SHIFT PGDIR_SHIFT
60850 -#define PTRS_PER_PUD 1
60851 -#define PUD_SIZE (1UL << PUD_SHIFT)
60852 -#define PUD_MASK (~(PUD_SIZE-1))
60853 -
60854 /*
60855 * The "pgd_xxx()" functions here are trivial for a folded two-level
60856 * setup: the pud is never bad, and a pud always exists (as it's folded
60857 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60858 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60859
60860 #define pgd_populate(mm, pgd, pud) do { } while (0)
60861 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60862 /*
60863 * (puds are folded into pgds so this doesn't get actually called,
60864 * but the define is needed for a generic inline function.)
60865 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60866 index ff4947b..f48183f 100644
60867 --- a/include/asm-generic/pgtable.h
60868 +++ b/include/asm-generic/pgtable.h
60869 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60870 #endif
60871 }
60872
60873 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60874 +static inline unsigned long pax_open_kernel(void) { return 0; }
60875 +#endif
60876 +
60877 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60878 +static inline unsigned long pax_close_kernel(void) { return 0; }
60879 +#endif
60880 +
60881 #endif /* CONFIG_MMU */
60882
60883 #endif /* !__ASSEMBLY__ */
60884 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60885 index 4e2e1cc..12c266b 100644
60886 --- a/include/asm-generic/vmlinux.lds.h
60887 +++ b/include/asm-generic/vmlinux.lds.h
60888 @@ -218,6 +218,7 @@
60889 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60890 VMLINUX_SYMBOL(__start_rodata) = .; \
60891 *(.rodata) *(.rodata.*) \
60892 + *(.data..read_only) \
60893 *(__vermagic) /* Kernel version magic */ \
60894 . = ALIGN(8); \
60895 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60896 @@ -716,17 +717,18 @@
60897 * section in the linker script will go there too. @phdr should have
60898 * a leading colon.
60899 *
60900 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60901 + * Note that this macros defines per_cpu_load as an absolute symbol.
60902 * If there is no need to put the percpu section at a predetermined
60903 * address, use PERCPU_SECTION.
60904 */
60905 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60906 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60907 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60908 + per_cpu_load = .; \
60909 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60910 - LOAD_OFFSET) { \
60911 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60912 PERCPU_INPUT(cacheline) \
60913 } phdr \
60914 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60915 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60916
60917 /**
60918 * PERCPU_SECTION - define output section for percpu area, simple version
60919 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60920 index d6b67bb..a272c29 100644
60921 --- a/include/drm/drmP.h
60922 +++ b/include/drm/drmP.h
60923 @@ -72,6 +72,7 @@
60924 #include <linux/workqueue.h>
60925 #include <linux/poll.h>
60926 #include <asm/pgalloc.h>
60927 +#include <asm/local.h>
60928 #include "drm.h"
60929
60930 #include <linux/idr.h>
60931 @@ -1067,7 +1068,7 @@ struct drm_device {
60932
60933 /** \name Usage Counters */
60934 /*@{ */
60935 - int open_count; /**< Outstanding files open */
60936 + local_t open_count; /**< Outstanding files open */
60937 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60938 atomic_t vma_count; /**< Outstanding vma areas open */
60939 int buf_use; /**< Buffers in use -- cannot alloc */
60940 @@ -1078,7 +1079,7 @@ struct drm_device {
60941 /*@{ */
60942 unsigned long counters;
60943 enum drm_stat_type types[15];
60944 - atomic_t counts[15];
60945 + atomic_unchecked_t counts[15];
60946 /*@} */
60947
60948 struct list_head filelist;
60949 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60950 index e01cc80..319855d 100644
60951 --- a/include/drm/drm_crtc_helper.h
60952 +++ b/include/drm/drm_crtc_helper.h
60953 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60954
60955 /* disable crtc when not in use - more explicit than dpms off */
60956 void (*disable)(struct drm_crtc *crtc);
60957 -};
60958 +} __no_const;
60959
60960 /**
60961 * drm_encoder_helper_funcs - helper operations for encoders
60962 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60963 struct drm_connector *connector);
60964 /* disable encoder when not in use - more explicit than dpms off */
60965 void (*disable)(struct drm_encoder *encoder);
60966 -};
60967 +} __no_const;
60968
60969 /**
60970 * drm_connector_helper_funcs - helper operations for connectors
60971 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60972 index d6d1da4..fdd1ac5 100644
60973 --- a/include/drm/ttm/ttm_memory.h
60974 +++ b/include/drm/ttm/ttm_memory.h
60975 @@ -48,7 +48,7 @@
60976
60977 struct ttm_mem_shrink {
60978 int (*do_shrink) (struct ttm_mem_shrink *);
60979 -};
60980 +} __no_const;
60981
60982 /**
60983 * struct ttm_mem_global - Global memory accounting structure.
60984 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60985 index e86dfca..40cc55f 100644
60986 --- a/include/linux/a.out.h
60987 +++ b/include/linux/a.out.h
60988 @@ -39,6 +39,14 @@ enum machine_type {
60989 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60990 };
60991
60992 +/* Constants for the N_FLAGS field */
60993 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60994 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60995 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60996 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60997 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60998 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60999 +
61000 #if !defined (N_MAGIC)
61001 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61002 #endif
61003 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61004 index 06fd4bb..1caec0d 100644
61005 --- a/include/linux/atmdev.h
61006 +++ b/include/linux/atmdev.h
61007 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61008 #endif
61009
61010 struct k_atm_aal_stats {
61011 -#define __HANDLE_ITEM(i) atomic_t i
61012 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61013 __AAL_STAT_ITEMS
61014 #undef __HANDLE_ITEM
61015 };
61016 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61017 index 366422b..1fa7f84 100644
61018 --- a/include/linux/binfmts.h
61019 +++ b/include/linux/binfmts.h
61020 @@ -89,6 +89,7 @@ struct linux_binfmt {
61021 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61022 int (*load_shlib)(struct file *);
61023 int (*core_dump)(struct coredump_params *cprm);
61024 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61025 unsigned long min_coredump; /* minimal dump size */
61026 };
61027
61028 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61029 index 4a2ab7c..a2de7a8 100644
61030 --- a/include/linux/blkdev.h
61031 +++ b/include/linux/blkdev.h
61032 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61033 /* this callback is with swap_lock and sometimes page table lock held */
61034 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61035 struct module *owner;
61036 -};
61037 +} __do_const;
61038
61039 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61040 unsigned long);
61041 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61042 index 4d1a074..88f929a 100644
61043 --- a/include/linux/blktrace_api.h
61044 +++ b/include/linux/blktrace_api.h
61045 @@ -162,7 +162,7 @@ struct blk_trace {
61046 struct dentry *dir;
61047 struct dentry *dropped_file;
61048 struct dentry *msg_file;
61049 - atomic_t dropped;
61050 + atomic_unchecked_t dropped;
61051 };
61052
61053 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61054 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61055 index 83195fb..0b0f77d 100644
61056 --- a/include/linux/byteorder/little_endian.h
61057 +++ b/include/linux/byteorder/little_endian.h
61058 @@ -42,51 +42,51 @@
61059
61060 static inline __le64 __cpu_to_le64p(const __u64 *p)
61061 {
61062 - return (__force __le64)*p;
61063 + return (__force const __le64)*p;
61064 }
61065 static inline __u64 __le64_to_cpup(const __le64 *p)
61066 {
61067 - return (__force __u64)*p;
61068 + return (__force const __u64)*p;
61069 }
61070 static inline __le32 __cpu_to_le32p(const __u32 *p)
61071 {
61072 - return (__force __le32)*p;
61073 + return (__force const __le32)*p;
61074 }
61075 static inline __u32 __le32_to_cpup(const __le32 *p)
61076 {
61077 - return (__force __u32)*p;
61078 + return (__force const __u32)*p;
61079 }
61080 static inline __le16 __cpu_to_le16p(const __u16 *p)
61081 {
61082 - return (__force __le16)*p;
61083 + return (__force const __le16)*p;
61084 }
61085 static inline __u16 __le16_to_cpup(const __le16 *p)
61086 {
61087 - return (__force __u16)*p;
61088 + return (__force const __u16)*p;
61089 }
61090 static inline __be64 __cpu_to_be64p(const __u64 *p)
61091 {
61092 - return (__force __be64)__swab64p(p);
61093 + return (__force const __be64)__swab64p(p);
61094 }
61095 static inline __u64 __be64_to_cpup(const __be64 *p)
61096 {
61097 - return __swab64p((__u64 *)p);
61098 + return __swab64p((const __u64 *)p);
61099 }
61100 static inline __be32 __cpu_to_be32p(const __u32 *p)
61101 {
61102 - return (__force __be32)__swab32p(p);
61103 + return (__force const __be32)__swab32p(p);
61104 }
61105 static inline __u32 __be32_to_cpup(const __be32 *p)
61106 {
61107 - return __swab32p((__u32 *)p);
61108 + return __swab32p((const __u32 *)p);
61109 }
61110 static inline __be16 __cpu_to_be16p(const __u16 *p)
61111 {
61112 - return (__force __be16)__swab16p(p);
61113 + return (__force const __be16)__swab16p(p);
61114 }
61115 static inline __u16 __be16_to_cpup(const __be16 *p)
61116 {
61117 - return __swab16p((__u16 *)p);
61118 + return __swab16p((const __u16 *)p);
61119 }
61120 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61121 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61122 diff --git a/include/linux/cache.h b/include/linux/cache.h
61123 index 4c57065..4307975 100644
61124 --- a/include/linux/cache.h
61125 +++ b/include/linux/cache.h
61126 @@ -16,6 +16,10 @@
61127 #define __read_mostly
61128 #endif
61129
61130 +#ifndef __read_only
61131 +#define __read_only __read_mostly
61132 +#endif
61133 +
61134 #ifndef ____cacheline_aligned
61135 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61136 #endif
61137 diff --git a/include/linux/capability.h b/include/linux/capability.h
61138 index d10b7ed..0288b79 100644
61139 --- a/include/linux/capability.h
61140 +++ b/include/linux/capability.h
61141 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61142 extern bool ns_capable(struct user_namespace *ns, int cap);
61143 extern bool nsown_capable(int cap);
61144 extern bool inode_capable(const struct inode *inode, int cap);
61145 +extern bool capable_nolog(int cap);
61146 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61147 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61148
61149 /* audit system wants to get cap info from files as well */
61150 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61151
61152 +extern int is_privileged_binary(const struct dentry *dentry);
61153 +
61154 #endif /* __KERNEL__ */
61155
61156 #endif /* !_LINUX_CAPABILITY_H */
61157 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61158 index 42e55de..1cd0e66 100644
61159 --- a/include/linux/cleancache.h
61160 +++ b/include/linux/cleancache.h
61161 @@ -31,7 +31,7 @@ struct cleancache_ops {
61162 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61163 void (*invalidate_inode)(int, struct cleancache_filekey);
61164 void (*invalidate_fs)(int);
61165 -};
61166 +} __no_const;
61167
61168 extern struct cleancache_ops
61169 cleancache_register_ops(struct cleancache_ops *ops);
61170 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61171 index 77335fa..6cbe7dd 100644
61172 --- a/include/linux/clk-provider.h
61173 +++ b/include/linux/clk-provider.h
61174 @@ -111,6 +111,7 @@ struct clk_ops {
61175 unsigned long);
61176 void (*init)(struct clk_hw *hw);
61177 };
61178 +typedef struct clk_ops __no_const clk_ops_no_const;
61179
61180 /**
61181 * struct clk_init_data - holds init data that's common to all clocks and is
61182 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61183 index 934bc34..1b47129 100644
61184 --- a/include/linux/compiler-gcc4.h
61185 +++ b/include/linux/compiler-gcc4.h
61186 @@ -32,6 +32,21 @@
61187 #define __linktime_error(message) __attribute__((__error__(message)))
61188
61189 #if __GNUC_MINOR__ >= 5
61190 +
61191 +#ifdef CONSTIFY_PLUGIN
61192 +#define __no_const __attribute__((no_const))
61193 +#define __do_const __attribute__((do_const))
61194 +#endif
61195 +
61196 +#ifdef SIZE_OVERFLOW_PLUGIN
61197 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61198 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61199 +#endif
61200 +
61201 +#ifdef LATENT_ENTROPY_PLUGIN
61202 +#define __latent_entropy __attribute__((latent_entropy))
61203 +#endif
61204 +
61205 /*
61206 * Mark a position in code as unreachable. This can be used to
61207 * suppress control flow warnings after asm blocks that transfer
61208 @@ -47,6 +62,11 @@
61209 #define __noclone __attribute__((__noclone__))
61210
61211 #endif
61212 +
61213 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61214 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61215 +#define __bos0(ptr) __bos((ptr), 0)
61216 +#define __bos1(ptr) __bos((ptr), 1)
61217 #endif
61218
61219 #if __GNUC_MINOR__ >= 6
61220 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61221 index f430e41..38be90f 100644
61222 --- a/include/linux/compiler.h
61223 +++ b/include/linux/compiler.h
61224 @@ -5,31 +5,62 @@
61225
61226 #ifdef __CHECKER__
61227 # define __user __attribute__((noderef, address_space(1)))
61228 +# define __force_user __force __user
61229 # define __kernel __attribute__((address_space(0)))
61230 +# define __force_kernel __force __kernel
61231 # define __safe __attribute__((safe))
61232 # define __force __attribute__((force))
61233 # define __nocast __attribute__((nocast))
61234 # define __iomem __attribute__((noderef, address_space(2)))
61235 +# define __force_iomem __force __iomem
61236 # define __acquires(x) __attribute__((context(x,0,1)))
61237 # define __releases(x) __attribute__((context(x,1,0)))
61238 # define __acquire(x) __context__(x,1)
61239 # define __release(x) __context__(x,-1)
61240 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61241 # define __percpu __attribute__((noderef, address_space(3)))
61242 +# define __force_percpu __force __percpu
61243 #ifdef CONFIG_SPARSE_RCU_POINTER
61244 # define __rcu __attribute__((noderef, address_space(4)))
61245 +# define __force_rcu __force __rcu
61246 #else
61247 # define __rcu
61248 +# define __force_rcu
61249 #endif
61250 extern void __chk_user_ptr(const volatile void __user *);
61251 extern void __chk_io_ptr(const volatile void __iomem *);
61252 +#elif defined(CHECKER_PLUGIN)
61253 +//# define __user
61254 +//# define __force_user
61255 +//# define __kernel
61256 +//# define __force_kernel
61257 +# define __safe
61258 +# define __force
61259 +# define __nocast
61260 +# define __iomem
61261 +# define __force_iomem
61262 +# define __chk_user_ptr(x) (void)0
61263 +# define __chk_io_ptr(x) (void)0
61264 +# define __builtin_warning(x, y...) (1)
61265 +# define __acquires(x)
61266 +# define __releases(x)
61267 +# define __acquire(x) (void)0
61268 +# define __release(x) (void)0
61269 +# define __cond_lock(x,c) (c)
61270 +# define __percpu
61271 +# define __force_percpu
61272 +# define __rcu
61273 +# define __force_rcu
61274 #else
61275 # define __user
61276 +# define __force_user
61277 # define __kernel
61278 +# define __force_kernel
61279 # define __safe
61280 # define __force
61281 # define __nocast
61282 # define __iomem
61283 +# define __force_iomem
61284 # define __chk_user_ptr(x) (void)0
61285 # define __chk_io_ptr(x) (void)0
61286 # define __builtin_warning(x, y...) (1)
61287 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61288 # define __release(x) (void)0
61289 # define __cond_lock(x,c) (c)
61290 # define __percpu
61291 +# define __force_percpu
61292 # define __rcu
61293 +# define __force_rcu
61294 #endif
61295
61296 #ifdef __KERNEL__
61297 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61298 # define __attribute_const__ /* unimplemented */
61299 #endif
61300
61301 +#ifndef __no_const
61302 +# define __no_const
61303 +#endif
61304 +
61305 +#ifndef __do_const
61306 +# define __do_const
61307 +#endif
61308 +
61309 +#ifndef __size_overflow
61310 +# define __size_overflow(...)
61311 +#endif
61312 +
61313 +#ifndef __intentional_overflow
61314 +# define __intentional_overflow(...)
61315 +#endif
61316 +
61317 +#ifndef __latent_entropy
61318 +# define __latent_entropy
61319 +#endif
61320 +
61321 /*
61322 * Tell gcc if a function is cold. The compiler will assume any path
61323 * directly leading to the call is unlikely.
61324 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61325 #define __cold
61326 #endif
61327
61328 +#ifndef __alloc_size
61329 +#define __alloc_size(...)
61330 +#endif
61331 +
61332 +#ifndef __bos
61333 +#define __bos(ptr, arg)
61334 +#endif
61335 +
61336 +#ifndef __bos0
61337 +#define __bos0(ptr)
61338 +#endif
61339 +
61340 +#ifndef __bos1
61341 +#define __bos1(ptr)
61342 +#endif
61343 +
61344 /* Simple shorthand for a section definition */
61345 #ifndef __section
61346 # define __section(S) __attribute__ ((__section__(#S)))
61347 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61348 * use is to mediate communication between process-level code and irq/NMI
61349 * handlers, all running on the same CPU.
61350 */
61351 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61352 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61353 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61354
61355 #endif /* __LINUX_COMPILER_H */
61356 diff --git a/include/linux/cred.h b/include/linux/cred.h
61357 index ebbed2c..908cc2c 100644
61358 --- a/include/linux/cred.h
61359 +++ b/include/linux/cred.h
61360 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61361 static inline void validate_process_creds(void)
61362 {
61363 }
61364 +static inline void validate_task_creds(struct task_struct *task)
61365 +{
61366 +}
61367 #endif
61368
61369 /**
61370 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61371 index b92eadf..b4ecdc1 100644
61372 --- a/include/linux/crypto.h
61373 +++ b/include/linux/crypto.h
61374 @@ -373,7 +373,7 @@ struct cipher_tfm {
61375 const u8 *key, unsigned int keylen);
61376 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61377 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61378 -};
61379 +} __no_const;
61380
61381 struct hash_tfm {
61382 int (*init)(struct hash_desc *desc);
61383 @@ -394,13 +394,13 @@ struct compress_tfm {
61384 int (*cot_decompress)(struct crypto_tfm *tfm,
61385 const u8 *src, unsigned int slen,
61386 u8 *dst, unsigned int *dlen);
61387 -};
61388 +} __no_const;
61389
61390 struct rng_tfm {
61391 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61392 unsigned int dlen);
61393 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61394 -};
61395 +} __no_const;
61396
61397 #define crt_ablkcipher crt_u.ablkcipher
61398 #define crt_aead crt_u.aead
61399 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61400 index 7925bf0..d5143d2 100644
61401 --- a/include/linux/decompress/mm.h
61402 +++ b/include/linux/decompress/mm.h
61403 @@ -77,7 +77,7 @@ static void free(void *where)
61404 * warnings when not needed (indeed large_malloc / large_free are not
61405 * needed by inflate */
61406
61407 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61408 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61409 #define free(a) kfree(a)
61410
61411 #define large_malloc(a) vmalloc(a)
61412 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61413 index 94af418..b1ca7a2 100644
61414 --- a/include/linux/dma-mapping.h
61415 +++ b/include/linux/dma-mapping.h
61416 @@ -54,7 +54,7 @@ struct dma_map_ops {
61417 u64 (*get_required_mask)(struct device *dev);
61418 #endif
61419 int is_phys;
61420 -};
61421 +} __do_const;
61422
61423 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61424
61425 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61426 index 9c02a45..89fdd73 100644
61427 --- a/include/linux/dmaengine.h
61428 +++ b/include/linux/dmaengine.h
61429 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61430 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61431 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61432
61433 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61434 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61435 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61436 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61437 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61438 struct dma_pinned_list *pinned_list, struct page *page,
61439 unsigned int offset, size_t len);
61440
61441 diff --git a/include/linux/efi.h b/include/linux/efi.h
61442 index ec45ccd..9923c32 100644
61443 --- a/include/linux/efi.h
61444 +++ b/include/linux/efi.h
61445 @@ -635,7 +635,7 @@ struct efivar_operations {
61446 efi_get_variable_t *get_variable;
61447 efi_get_next_variable_t *get_next_variable;
61448 efi_set_variable_t *set_variable;
61449 -};
61450 +} __no_const;
61451
61452 struct efivars {
61453 /*
61454 diff --git a/include/linux/elf.h b/include/linux/elf.h
61455 index 999b4f5..57753b4 100644
61456 --- a/include/linux/elf.h
61457 +++ b/include/linux/elf.h
61458 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61459 #define PT_GNU_EH_FRAME 0x6474e550
61460
61461 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61462 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61463 +
61464 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61465 +
61466 +/* Constants for the e_flags field */
61467 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61468 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61469 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61470 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61471 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61472 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61473
61474 /*
61475 * Extended Numbering
61476 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61477 #define DT_DEBUG 21
61478 #define DT_TEXTREL 22
61479 #define DT_JMPREL 23
61480 +#define DT_FLAGS 30
61481 + #define DF_TEXTREL 0x00000004
61482 #define DT_ENCODING 32
61483 #define OLD_DT_LOOS 0x60000000
61484 #define DT_LOOS 0x6000000d
61485 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61486 #define PF_W 0x2
61487 #define PF_X 0x1
61488
61489 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61490 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61491 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61492 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61493 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61494 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61495 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61496 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61497 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61498 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61499 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61500 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61501 +
61502 typedef struct elf32_phdr{
61503 Elf32_Word p_type;
61504 Elf32_Off p_offset;
61505 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61506 #define EI_OSABI 7
61507 #define EI_PAD 8
61508
61509 +#define EI_PAX 14
61510 +
61511 #define ELFMAG0 0x7f /* EI_MAG */
61512 #define ELFMAG1 'E'
61513 #define ELFMAG2 'L'
61514 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61515 #define elf_note elf32_note
61516 #define elf_addr_t Elf32_Off
61517 #define Elf_Half Elf32_Half
61518 +#define elf_dyn Elf32_Dyn
61519
61520 #else
61521
61522 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61523 #define elf_note elf64_note
61524 #define elf_addr_t Elf64_Off
61525 #define Elf_Half Elf64_Half
61526 +#define elf_dyn Elf64_Dyn
61527
61528 #endif
61529
61530 diff --git a/include/linux/filter.h b/include/linux/filter.h
61531 index 82b0135..917914d 100644
61532 --- a/include/linux/filter.h
61533 +++ b/include/linux/filter.h
61534 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61535
61536 struct sk_buff;
61537 struct sock;
61538 +struct bpf_jit_work;
61539
61540 struct sk_filter
61541 {
61542 @@ -153,6 +154,9 @@ struct sk_filter
61543 unsigned int len; /* Number of filter blocks */
61544 unsigned int (*bpf_func)(const struct sk_buff *skb,
61545 const struct sock_filter *filter);
61546 +#ifdef CONFIG_BPF_JIT
61547 + struct bpf_jit_work *work;
61548 +#endif
61549 struct rcu_head rcu;
61550 struct sock_filter insns[0];
61551 };
61552 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61553 index db04ec5..f6ed627 100644
61554 --- a/include/linux/firewire.h
61555 +++ b/include/linux/firewire.h
61556 @@ -430,7 +430,7 @@ struct fw_iso_context {
61557 union {
61558 fw_iso_callback_t sc;
61559 fw_iso_mc_callback_t mc;
61560 - } callback;
61561 + } __no_const callback;
61562 void *callback_data;
61563 };
61564
61565 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61566 index 0e4e2ee..4ff4312 100644
61567 --- a/include/linux/frontswap.h
61568 +++ b/include/linux/frontswap.h
61569 @@ -11,7 +11,7 @@ struct frontswap_ops {
61570 int (*load)(unsigned, pgoff_t, struct page *);
61571 void (*invalidate_page)(unsigned, pgoff_t);
61572 void (*invalidate_area)(unsigned);
61573 -};
61574 +} __no_const;
61575
61576 extern bool frontswap_enabled;
61577 extern struct frontswap_ops
61578 diff --git a/include/linux/fs.h b/include/linux/fs.h
61579 index aa11047..7d046d0 100644
61580 --- a/include/linux/fs.h
61581 +++ b/include/linux/fs.h
61582 @@ -1802,7 +1802,8 @@ struct file_operations {
61583 int (*setlease)(struct file *, long, struct file_lock **);
61584 long (*fallocate)(struct file *file, int mode, loff_t offset,
61585 loff_t len);
61586 -};
61587 +} __do_const;
61588 +typedef struct file_operations __no_const file_operations_no_const;
61589
61590 struct inode_operations {
61591 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61592 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61593 index 003dc0f..3c4ea97 100644
61594 --- a/include/linux/fs_struct.h
61595 +++ b/include/linux/fs_struct.h
61596 @@ -6,7 +6,7 @@
61597 #include <linux/seqlock.h>
61598
61599 struct fs_struct {
61600 - int users;
61601 + atomic_t users;
61602 spinlock_t lock;
61603 seqcount_t seq;
61604 int umask;
61605 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61606 index ce31408..b1ad003 100644
61607 --- a/include/linux/fscache-cache.h
61608 +++ b/include/linux/fscache-cache.h
61609 @@ -102,7 +102,7 @@ struct fscache_operation {
61610 fscache_operation_release_t release;
61611 };
61612
61613 -extern atomic_t fscache_op_debug_id;
61614 +extern atomic_unchecked_t fscache_op_debug_id;
61615 extern void fscache_op_work_func(struct work_struct *work);
61616
61617 extern void fscache_enqueue_operation(struct fscache_operation *);
61618 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61619 {
61620 INIT_WORK(&op->work, fscache_op_work_func);
61621 atomic_set(&op->usage, 1);
61622 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61623 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61624 op->processor = processor;
61625 op->release = release;
61626 INIT_LIST_HEAD(&op->pend_link);
61627 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61628 index a6dfe69..569586df 100644
61629 --- a/include/linux/fsnotify.h
61630 +++ b/include/linux/fsnotify.h
61631 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61632 */
61633 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61634 {
61635 - return kstrdup(name, GFP_KERNEL);
61636 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61637 }
61638
61639 /*
61640 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61641 index 63d966d..cdcb717 100644
61642 --- a/include/linux/fsnotify_backend.h
61643 +++ b/include/linux/fsnotify_backend.h
61644 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61645 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61646 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61647 };
61648 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61649
61650 /*
61651 * A group is a "thing" that wants to receive notification about filesystem
61652 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61653 index 642928c..e6c83a7 100644
61654 --- a/include/linux/ftrace_event.h
61655 +++ b/include/linux/ftrace_event.h
61656 @@ -97,7 +97,7 @@ struct trace_event_functions {
61657 trace_print_func raw;
61658 trace_print_func hex;
61659 trace_print_func binary;
61660 -};
61661 +} __no_const;
61662
61663 struct trace_event {
61664 struct hlist_node node;
61665 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61666 extern int trace_add_event_call(struct ftrace_event_call *call);
61667 extern void trace_remove_event_call(struct ftrace_event_call *call);
61668
61669 -#define is_signed_type(type) (((type)(-1)) < 0)
61670 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61671
61672 int trace_set_clr_event(const char *system, const char *event, int set);
61673
61674 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61675 index 4f440b3..342233a 100644
61676 --- a/include/linux/genhd.h
61677 +++ b/include/linux/genhd.h
61678 @@ -190,7 +190,7 @@ struct gendisk {
61679 struct kobject *slave_dir;
61680
61681 struct timer_rand_state *random;
61682 - atomic_t sync_io; /* RAID */
61683 + atomic_unchecked_t sync_io; /* RAID */
61684 struct disk_events *ev;
61685 #ifdef CONFIG_BLK_DEV_INTEGRITY
61686 struct blk_integrity *integrity;
61687 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61688 index 4883f39..26688a8 100644
61689 --- a/include/linux/gfp.h
61690 +++ b/include/linux/gfp.h
61691 @@ -39,6 +39,12 @@ struct vm_area_struct;
61692 #define ___GFP_OTHER_NODE 0x800000u
61693 #define ___GFP_WRITE 0x1000000u
61694
61695 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61696 +#define ___GFP_USERCOPY 0x2000000u
61697 +#else
61698 +#define ___GFP_USERCOPY 0
61699 +#endif
61700 +
61701 /*
61702 * GFP bitmasks..
61703 *
61704 @@ -93,6 +99,7 @@ struct vm_area_struct;
61705 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61706 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61707 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61708 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61709
61710 /*
61711 * This may seem redundant, but it's a way of annotating false positives vs.
61712 @@ -100,7 +107,7 @@ struct vm_area_struct;
61713 */
61714 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61715
61716 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61717 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61718 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61719
61720 /* This equals 0, but use constants in case they ever change */
61721 @@ -154,6 +161,8 @@ struct vm_area_struct;
61722 /* 4GB DMA on some platforms */
61723 #define GFP_DMA32 __GFP_DMA32
61724
61725 +#define GFP_USERCOPY __GFP_USERCOPY
61726 +
61727 /* Convert GFP flags to their corresponding migrate type */
61728 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61729 {
61730 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61731 new file mode 100644
61732 index 0000000..c938b1f
61733 --- /dev/null
61734 +++ b/include/linux/gracl.h
61735 @@ -0,0 +1,319 @@
61736 +#ifndef GR_ACL_H
61737 +#define GR_ACL_H
61738 +
61739 +#include <linux/grdefs.h>
61740 +#include <linux/resource.h>
61741 +#include <linux/capability.h>
61742 +#include <linux/dcache.h>
61743 +#include <asm/resource.h>
61744 +
61745 +/* Major status information */
61746 +
61747 +#define GR_VERSION "grsecurity 2.9.1"
61748 +#define GRSECURITY_VERSION 0x2901
61749 +
61750 +enum {
61751 + GR_SHUTDOWN = 0,
61752 + GR_ENABLE = 1,
61753 + GR_SPROLE = 2,
61754 + GR_RELOAD = 3,
61755 + GR_SEGVMOD = 4,
61756 + GR_STATUS = 5,
61757 + GR_UNSPROLE = 6,
61758 + GR_PASSSET = 7,
61759 + GR_SPROLEPAM = 8,
61760 +};
61761 +
61762 +/* Password setup definitions
61763 + * kernel/grhash.c */
61764 +enum {
61765 + GR_PW_LEN = 128,
61766 + GR_SALT_LEN = 16,
61767 + GR_SHA_LEN = 32,
61768 +};
61769 +
61770 +enum {
61771 + GR_SPROLE_LEN = 64,
61772 +};
61773 +
61774 +enum {
61775 + GR_NO_GLOB = 0,
61776 + GR_REG_GLOB,
61777 + GR_CREATE_GLOB
61778 +};
61779 +
61780 +#define GR_NLIMITS 32
61781 +
61782 +/* Begin Data Structures */
61783 +
61784 +struct sprole_pw {
61785 + unsigned char *rolename;
61786 + unsigned char salt[GR_SALT_LEN];
61787 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61788 +};
61789 +
61790 +struct name_entry {
61791 + __u32 key;
61792 + ino_t inode;
61793 + dev_t device;
61794 + char *name;
61795 + __u16 len;
61796 + __u8 deleted;
61797 + struct name_entry *prev;
61798 + struct name_entry *next;
61799 +};
61800 +
61801 +struct inodev_entry {
61802 + struct name_entry *nentry;
61803 + struct inodev_entry *prev;
61804 + struct inodev_entry *next;
61805 +};
61806 +
61807 +struct acl_role_db {
61808 + struct acl_role_label **r_hash;
61809 + __u32 r_size;
61810 +};
61811 +
61812 +struct inodev_db {
61813 + struct inodev_entry **i_hash;
61814 + __u32 i_size;
61815 +};
61816 +
61817 +struct name_db {
61818 + struct name_entry **n_hash;
61819 + __u32 n_size;
61820 +};
61821 +
61822 +struct crash_uid {
61823 + uid_t uid;
61824 + unsigned long expires;
61825 +};
61826 +
61827 +struct gr_hash_struct {
61828 + void **table;
61829 + void **nametable;
61830 + void *first;
61831 + __u32 table_size;
61832 + __u32 used_size;
61833 + int type;
61834 +};
61835 +
61836 +/* Userspace Grsecurity ACL data structures */
61837 +
61838 +struct acl_subject_label {
61839 + char *filename;
61840 + ino_t inode;
61841 + dev_t device;
61842 + __u32 mode;
61843 + kernel_cap_t cap_mask;
61844 + kernel_cap_t cap_lower;
61845 + kernel_cap_t cap_invert_audit;
61846 +
61847 + struct rlimit res[GR_NLIMITS];
61848 + __u32 resmask;
61849 +
61850 + __u8 user_trans_type;
61851 + __u8 group_trans_type;
61852 + uid_t *user_transitions;
61853 + gid_t *group_transitions;
61854 + __u16 user_trans_num;
61855 + __u16 group_trans_num;
61856 +
61857 + __u32 sock_families[2];
61858 + __u32 ip_proto[8];
61859 + __u32 ip_type;
61860 + struct acl_ip_label **ips;
61861 + __u32 ip_num;
61862 + __u32 inaddr_any_override;
61863 +
61864 + __u32 crashes;
61865 + unsigned long expires;
61866 +
61867 + struct acl_subject_label *parent_subject;
61868 + struct gr_hash_struct *hash;
61869 + struct acl_subject_label *prev;
61870 + struct acl_subject_label *next;
61871 +
61872 + struct acl_object_label **obj_hash;
61873 + __u32 obj_hash_size;
61874 + __u16 pax_flags;
61875 +};
61876 +
61877 +struct role_allowed_ip {
61878 + __u32 addr;
61879 + __u32 netmask;
61880 +
61881 + struct role_allowed_ip *prev;
61882 + struct role_allowed_ip *next;
61883 +};
61884 +
61885 +struct role_transition {
61886 + char *rolename;
61887 +
61888 + struct role_transition *prev;
61889 + struct role_transition *next;
61890 +};
61891 +
61892 +struct acl_role_label {
61893 + char *rolename;
61894 + uid_t uidgid;
61895 + __u16 roletype;
61896 +
61897 + __u16 auth_attempts;
61898 + unsigned long expires;
61899 +
61900 + struct acl_subject_label *root_label;
61901 + struct gr_hash_struct *hash;
61902 +
61903 + struct acl_role_label *prev;
61904 + struct acl_role_label *next;
61905 +
61906 + struct role_transition *transitions;
61907 + struct role_allowed_ip *allowed_ips;
61908 + uid_t *domain_children;
61909 + __u16 domain_child_num;
61910 +
61911 + umode_t umask;
61912 +
61913 + struct acl_subject_label **subj_hash;
61914 + __u32 subj_hash_size;
61915 +};
61916 +
61917 +struct user_acl_role_db {
61918 + struct acl_role_label **r_table;
61919 + __u32 num_pointers; /* Number of allocations to track */
61920 + __u32 num_roles; /* Number of roles */
61921 + __u32 num_domain_children; /* Number of domain children */
61922 + __u32 num_subjects; /* Number of subjects */
61923 + __u32 num_objects; /* Number of objects */
61924 +};
61925 +
61926 +struct acl_object_label {
61927 + char *filename;
61928 + ino_t inode;
61929 + dev_t device;
61930 + __u32 mode;
61931 +
61932 + struct acl_subject_label *nested;
61933 + struct acl_object_label *globbed;
61934 +
61935 + /* next two structures not used */
61936 +
61937 + struct acl_object_label *prev;
61938 + struct acl_object_label *next;
61939 +};
61940 +
61941 +struct acl_ip_label {
61942 + char *iface;
61943 + __u32 addr;
61944 + __u32 netmask;
61945 + __u16 low, high;
61946 + __u8 mode;
61947 + __u32 type;
61948 + __u32 proto[8];
61949 +
61950 + /* next two structures not used */
61951 +
61952 + struct acl_ip_label *prev;
61953 + struct acl_ip_label *next;
61954 +};
61955 +
61956 +struct gr_arg {
61957 + struct user_acl_role_db role_db;
61958 + unsigned char pw[GR_PW_LEN];
61959 + unsigned char salt[GR_SALT_LEN];
61960 + unsigned char sum[GR_SHA_LEN];
61961 + unsigned char sp_role[GR_SPROLE_LEN];
61962 + struct sprole_pw *sprole_pws;
61963 + dev_t segv_device;
61964 + ino_t segv_inode;
61965 + uid_t segv_uid;
61966 + __u16 num_sprole_pws;
61967 + __u16 mode;
61968 +};
61969 +
61970 +struct gr_arg_wrapper {
61971 + struct gr_arg *arg;
61972 + __u32 version;
61973 + __u32 size;
61974 +};
61975 +
61976 +struct subject_map {
61977 + struct acl_subject_label *user;
61978 + struct acl_subject_label *kernel;
61979 + struct subject_map *prev;
61980 + struct subject_map *next;
61981 +};
61982 +
61983 +struct acl_subj_map_db {
61984 + struct subject_map **s_hash;
61985 + __u32 s_size;
61986 +};
61987 +
61988 +/* End Data Structures Section */
61989 +
61990 +/* Hash functions generated by empirical testing by Brad Spengler
61991 + Makes good use of the low bits of the inode. Generally 0-1 times
61992 + in loop for successful match. 0-3 for unsuccessful match.
61993 + Shift/add algorithm with modulus of table size and an XOR*/
61994 +
61995 +static __inline__ unsigned int
61996 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61997 +{
61998 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61999 +}
62000 +
62001 + static __inline__ unsigned int
62002 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62003 +{
62004 + return ((const unsigned long)userp % sz);
62005 +}
62006 +
62007 +static __inline__ unsigned int
62008 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62009 +{
62010 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62011 +}
62012 +
62013 +static __inline__ unsigned int
62014 +nhash(const char *name, const __u16 len, const unsigned int sz)
62015 +{
62016 + return full_name_hash((const unsigned char *)name, len) % sz;
62017 +}
62018 +
62019 +#define FOR_EACH_ROLE_START(role) \
62020 + role = role_list; \
62021 + while (role) {
62022 +
62023 +#define FOR_EACH_ROLE_END(role) \
62024 + role = role->prev; \
62025 + }
62026 +
62027 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62028 + subj = NULL; \
62029 + iter = 0; \
62030 + while (iter < role->subj_hash_size) { \
62031 + if (subj == NULL) \
62032 + subj = role->subj_hash[iter]; \
62033 + if (subj == NULL) { \
62034 + iter++; \
62035 + continue; \
62036 + }
62037 +
62038 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62039 + subj = subj->next; \
62040 + if (subj == NULL) \
62041 + iter++; \
62042 + }
62043 +
62044 +
62045 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62046 + subj = role->hash->first; \
62047 + while (subj != NULL) {
62048 +
62049 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62050 + subj = subj->next; \
62051 + }
62052 +
62053 +#endif
62054 +
62055 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62056 new file mode 100644
62057 index 0000000..323ecf2
62058 --- /dev/null
62059 +++ b/include/linux/gralloc.h
62060 @@ -0,0 +1,9 @@
62061 +#ifndef __GRALLOC_H
62062 +#define __GRALLOC_H
62063 +
62064 +void acl_free_all(void);
62065 +int acl_alloc_stack_init(unsigned long size);
62066 +void *acl_alloc(unsigned long len);
62067 +void *acl_alloc_num(unsigned long num, unsigned long len);
62068 +
62069 +#endif
62070 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62071 new file mode 100644
62072 index 0000000..b30e9bc
62073 --- /dev/null
62074 +++ b/include/linux/grdefs.h
62075 @@ -0,0 +1,140 @@
62076 +#ifndef GRDEFS_H
62077 +#define GRDEFS_H
62078 +
62079 +/* Begin grsecurity status declarations */
62080 +
62081 +enum {
62082 + GR_READY = 0x01,
62083 + GR_STATUS_INIT = 0x00 // disabled state
62084 +};
62085 +
62086 +/* Begin ACL declarations */
62087 +
62088 +/* Role flags */
62089 +
62090 +enum {
62091 + GR_ROLE_USER = 0x0001,
62092 + GR_ROLE_GROUP = 0x0002,
62093 + GR_ROLE_DEFAULT = 0x0004,
62094 + GR_ROLE_SPECIAL = 0x0008,
62095 + GR_ROLE_AUTH = 0x0010,
62096 + GR_ROLE_NOPW = 0x0020,
62097 + GR_ROLE_GOD = 0x0040,
62098 + GR_ROLE_LEARN = 0x0080,
62099 + GR_ROLE_TPE = 0x0100,
62100 + GR_ROLE_DOMAIN = 0x0200,
62101 + GR_ROLE_PAM = 0x0400,
62102 + GR_ROLE_PERSIST = 0x0800
62103 +};
62104 +
62105 +/* ACL Subject and Object mode flags */
62106 +enum {
62107 + GR_DELETED = 0x80000000
62108 +};
62109 +
62110 +/* ACL Object-only mode flags */
62111 +enum {
62112 + GR_READ = 0x00000001,
62113 + GR_APPEND = 0x00000002,
62114 + GR_WRITE = 0x00000004,
62115 + GR_EXEC = 0x00000008,
62116 + GR_FIND = 0x00000010,
62117 + GR_INHERIT = 0x00000020,
62118 + GR_SETID = 0x00000040,
62119 + GR_CREATE = 0x00000080,
62120 + GR_DELETE = 0x00000100,
62121 + GR_LINK = 0x00000200,
62122 + GR_AUDIT_READ = 0x00000400,
62123 + GR_AUDIT_APPEND = 0x00000800,
62124 + GR_AUDIT_WRITE = 0x00001000,
62125 + GR_AUDIT_EXEC = 0x00002000,
62126 + GR_AUDIT_FIND = 0x00004000,
62127 + GR_AUDIT_INHERIT= 0x00008000,
62128 + GR_AUDIT_SETID = 0x00010000,
62129 + GR_AUDIT_CREATE = 0x00020000,
62130 + GR_AUDIT_DELETE = 0x00040000,
62131 + GR_AUDIT_LINK = 0x00080000,
62132 + GR_PTRACERD = 0x00100000,
62133 + GR_NOPTRACE = 0x00200000,
62134 + GR_SUPPRESS = 0x00400000,
62135 + GR_NOLEARN = 0x00800000,
62136 + GR_INIT_TRANSFER= 0x01000000
62137 +};
62138 +
62139 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62140 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62141 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62142 +
62143 +/* ACL subject-only mode flags */
62144 +enum {
62145 + GR_KILL = 0x00000001,
62146 + GR_VIEW = 0x00000002,
62147 + GR_PROTECTED = 0x00000004,
62148 + GR_LEARN = 0x00000008,
62149 + GR_OVERRIDE = 0x00000010,
62150 + /* just a placeholder, this mode is only used in userspace */
62151 + GR_DUMMY = 0x00000020,
62152 + GR_PROTSHM = 0x00000040,
62153 + GR_KILLPROC = 0x00000080,
62154 + GR_KILLIPPROC = 0x00000100,
62155 + /* just a placeholder, this mode is only used in userspace */
62156 + GR_NOTROJAN = 0x00000200,
62157 + GR_PROTPROCFD = 0x00000400,
62158 + GR_PROCACCT = 0x00000800,
62159 + GR_RELAXPTRACE = 0x00001000,
62160 + GR_NESTED = 0x00002000,
62161 + GR_INHERITLEARN = 0x00004000,
62162 + GR_PROCFIND = 0x00008000,
62163 + GR_POVERRIDE = 0x00010000,
62164 + GR_KERNELAUTH = 0x00020000,
62165 + GR_ATSECURE = 0x00040000,
62166 + GR_SHMEXEC = 0x00080000
62167 +};
62168 +
62169 +enum {
62170 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62171 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62172 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62173 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62174 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62175 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62176 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62177 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62178 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62179 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62180 +};
62181 +
62182 +enum {
62183 + GR_ID_USER = 0x01,
62184 + GR_ID_GROUP = 0x02,
62185 +};
62186 +
62187 +enum {
62188 + GR_ID_ALLOW = 0x01,
62189 + GR_ID_DENY = 0x02,
62190 +};
62191 +
62192 +#define GR_CRASH_RES 31
62193 +#define GR_UIDTABLE_MAX 500
62194 +
62195 +/* begin resource learning section */
62196 +enum {
62197 + GR_RLIM_CPU_BUMP = 60,
62198 + GR_RLIM_FSIZE_BUMP = 50000,
62199 + GR_RLIM_DATA_BUMP = 10000,
62200 + GR_RLIM_STACK_BUMP = 1000,
62201 + GR_RLIM_CORE_BUMP = 10000,
62202 + GR_RLIM_RSS_BUMP = 500000,
62203 + GR_RLIM_NPROC_BUMP = 1,
62204 + GR_RLIM_NOFILE_BUMP = 5,
62205 + GR_RLIM_MEMLOCK_BUMP = 50000,
62206 + GR_RLIM_AS_BUMP = 500000,
62207 + GR_RLIM_LOCKS_BUMP = 2,
62208 + GR_RLIM_SIGPENDING_BUMP = 5,
62209 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62210 + GR_RLIM_NICE_BUMP = 1,
62211 + GR_RLIM_RTPRIO_BUMP = 1,
62212 + GR_RLIM_RTTIME_BUMP = 1000000
62213 +};
62214 +
62215 +#endif
62216 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62217 new file mode 100644
62218 index 0000000..c9292f7
62219 --- /dev/null
62220 +++ b/include/linux/grinternal.h
62221 @@ -0,0 +1,223 @@
62222 +#ifndef __GRINTERNAL_H
62223 +#define __GRINTERNAL_H
62224 +
62225 +#ifdef CONFIG_GRKERNSEC
62226 +
62227 +#include <linux/fs.h>
62228 +#include <linux/mnt_namespace.h>
62229 +#include <linux/nsproxy.h>
62230 +#include <linux/gracl.h>
62231 +#include <linux/grdefs.h>
62232 +#include <linux/grmsg.h>
62233 +
62234 +void gr_add_learn_entry(const char *fmt, ...)
62235 + __attribute__ ((format (printf, 1, 2)));
62236 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62237 + const struct vfsmount *mnt);
62238 +__u32 gr_check_create(const struct dentry *new_dentry,
62239 + const struct dentry *parent,
62240 + const struct vfsmount *mnt, const __u32 mode);
62241 +int gr_check_protected_task(const struct task_struct *task);
62242 +__u32 to_gr_audit(const __u32 reqmode);
62243 +int gr_set_acls(const int type);
62244 +int gr_apply_subject_to_task(struct task_struct *task);
62245 +int gr_acl_is_enabled(void);
62246 +char gr_roletype_to_char(void);
62247 +
62248 +void gr_handle_alertkill(struct task_struct *task);
62249 +char *gr_to_filename(const struct dentry *dentry,
62250 + const struct vfsmount *mnt);
62251 +char *gr_to_filename1(const struct dentry *dentry,
62252 + const struct vfsmount *mnt);
62253 +char *gr_to_filename2(const struct dentry *dentry,
62254 + const struct vfsmount *mnt);
62255 +char *gr_to_filename3(const struct dentry *dentry,
62256 + const struct vfsmount *mnt);
62257 +
62258 +extern int grsec_enable_ptrace_readexec;
62259 +extern int grsec_enable_harden_ptrace;
62260 +extern int grsec_enable_link;
62261 +extern int grsec_enable_fifo;
62262 +extern int grsec_enable_execve;
62263 +extern int grsec_enable_shm;
62264 +extern int grsec_enable_execlog;
62265 +extern int grsec_enable_signal;
62266 +extern int grsec_enable_audit_ptrace;
62267 +extern int grsec_enable_forkfail;
62268 +extern int grsec_enable_time;
62269 +extern int grsec_enable_rofs;
62270 +extern int grsec_enable_chroot_shmat;
62271 +extern int grsec_enable_chroot_mount;
62272 +extern int grsec_enable_chroot_double;
62273 +extern int grsec_enable_chroot_pivot;
62274 +extern int grsec_enable_chroot_chdir;
62275 +extern int grsec_enable_chroot_chmod;
62276 +extern int grsec_enable_chroot_mknod;
62277 +extern int grsec_enable_chroot_fchdir;
62278 +extern int grsec_enable_chroot_nice;
62279 +extern int grsec_enable_chroot_execlog;
62280 +extern int grsec_enable_chroot_caps;
62281 +extern int grsec_enable_chroot_sysctl;
62282 +extern int grsec_enable_chroot_unix;
62283 +extern int grsec_enable_symlinkown;
62284 +extern int grsec_symlinkown_gid;
62285 +extern int grsec_enable_tpe;
62286 +extern int grsec_tpe_gid;
62287 +extern int grsec_enable_tpe_all;
62288 +extern int grsec_enable_tpe_invert;
62289 +extern int grsec_enable_socket_all;
62290 +extern int grsec_socket_all_gid;
62291 +extern int grsec_enable_socket_client;
62292 +extern int grsec_socket_client_gid;
62293 +extern int grsec_enable_socket_server;
62294 +extern int grsec_socket_server_gid;
62295 +extern int grsec_audit_gid;
62296 +extern int grsec_enable_group;
62297 +extern int grsec_enable_audit_textrel;
62298 +extern int grsec_enable_log_rwxmaps;
62299 +extern int grsec_enable_mount;
62300 +extern int grsec_enable_chdir;
62301 +extern int grsec_resource_logging;
62302 +extern int grsec_enable_blackhole;
62303 +extern int grsec_lastack_retries;
62304 +extern int grsec_enable_brute;
62305 +extern int grsec_lock;
62306 +
62307 +extern spinlock_t grsec_alert_lock;
62308 +extern unsigned long grsec_alert_wtime;
62309 +extern unsigned long grsec_alert_fyet;
62310 +
62311 +extern spinlock_t grsec_audit_lock;
62312 +
62313 +extern rwlock_t grsec_exec_file_lock;
62314 +
62315 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62316 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62317 + (tsk)->exec_file->f_vfsmnt) : "/")
62318 +
62319 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62320 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62321 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62322 +
62323 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62324 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62325 + (tsk)->exec_file->f_vfsmnt) : "/")
62326 +
62327 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62328 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62329 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62330 +
62331 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62332 +
62333 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62334 +
62335 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62336 + (task)->pid, (cred)->uid, \
62337 + (cred)->euid, (cred)->gid, (cred)->egid, \
62338 + gr_parent_task_fullpath(task), \
62339 + (task)->real_parent->comm, (task)->real_parent->pid, \
62340 + (pcred)->uid, (pcred)->euid, \
62341 + (pcred)->gid, (pcred)->egid
62342 +
62343 +#define GR_CHROOT_CAPS {{ \
62344 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62345 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62346 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62347 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62348 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62349 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62350 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62351 +
62352 +#define security_learn(normal_msg,args...) \
62353 +({ \
62354 + read_lock(&grsec_exec_file_lock); \
62355 + gr_add_learn_entry(normal_msg "\n", ## args); \
62356 + read_unlock(&grsec_exec_file_lock); \
62357 +})
62358 +
62359 +enum {
62360 + GR_DO_AUDIT,
62361 + GR_DONT_AUDIT,
62362 + /* used for non-audit messages that we shouldn't kill the task on */
62363 + GR_DONT_AUDIT_GOOD
62364 +};
62365 +
62366 +enum {
62367 + GR_TTYSNIFF,
62368 + GR_RBAC,
62369 + GR_RBAC_STR,
62370 + GR_STR_RBAC,
62371 + GR_RBAC_MODE2,
62372 + GR_RBAC_MODE3,
62373 + GR_FILENAME,
62374 + GR_SYSCTL_HIDDEN,
62375 + GR_NOARGS,
62376 + GR_ONE_INT,
62377 + GR_ONE_INT_TWO_STR,
62378 + GR_ONE_STR,
62379 + GR_STR_INT,
62380 + GR_TWO_STR_INT,
62381 + GR_TWO_INT,
62382 + GR_TWO_U64,
62383 + GR_THREE_INT,
62384 + GR_FIVE_INT_TWO_STR,
62385 + GR_TWO_STR,
62386 + GR_THREE_STR,
62387 + GR_FOUR_STR,
62388 + GR_STR_FILENAME,
62389 + GR_FILENAME_STR,
62390 + GR_FILENAME_TWO_INT,
62391 + GR_FILENAME_TWO_INT_STR,
62392 + GR_TEXTREL,
62393 + GR_PTRACE,
62394 + GR_RESOURCE,
62395 + GR_CAP,
62396 + GR_SIG,
62397 + GR_SIG2,
62398 + GR_CRASH1,
62399 + GR_CRASH2,
62400 + GR_PSACCT,
62401 + GR_RWXMAP
62402 +};
62403 +
62404 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62405 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62406 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62407 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62408 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62409 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62410 +#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)
62411 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62412 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62413 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62414 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62415 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62416 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62417 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62418 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62419 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62420 +#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)
62421 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62422 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62423 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62424 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62425 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62426 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62427 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62428 +#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)
62429 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62430 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62431 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62432 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62433 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62434 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62435 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62436 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62437 +#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)
62438 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62439 +
62440 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62441 +
62442 +#endif
62443 +
62444 +#endif
62445 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62446 new file mode 100644
62447 index 0000000..54f4e85
62448 --- /dev/null
62449 +++ b/include/linux/grmsg.h
62450 @@ -0,0 +1,110 @@
62451 +#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"
62452 +#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"
62453 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62454 +#define GR_STOPMOD_MSG "denied modification of module state by "
62455 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62456 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62457 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62458 +#define GR_IOPL_MSG "denied use of iopl() by "
62459 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62460 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62461 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62462 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62463 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62464 +#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"
62465 +#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"
62466 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62467 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62468 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62469 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62470 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62471 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62472 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62473 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62474 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62475 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62476 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62477 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62478 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62479 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62480 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62481 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62482 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62483 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62484 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62485 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62486 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62487 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62488 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62489 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62490 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62491 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62492 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62493 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62494 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62495 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62496 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62497 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62498 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62499 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62500 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62501 +#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"
62502 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62503 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62504 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62505 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62506 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62507 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62508 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62509 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62510 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62511 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62512 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62513 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62514 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62515 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62516 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62517 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62518 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62519 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62520 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62521 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62522 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62523 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62524 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62525 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62526 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62527 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62528 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62529 +#define GR_TIME_MSG "time set by "
62530 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62531 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62532 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62533 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62534 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62535 +#define GR_BIND_MSG "denied bind() by "
62536 +#define GR_CONNECT_MSG "denied connect() by "
62537 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62538 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62539 +#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"
62540 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62541 +#define GR_CAP_ACL_MSG "use of %s denied for "
62542 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62543 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62544 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62545 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62546 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62547 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62548 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62549 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62550 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62551 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62552 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62553 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62554 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62555 +#define GR_VM86_MSG "denied use of vm86 by "
62556 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62557 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62558 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62559 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62560 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62561 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62562 new file mode 100644
62563 index 0000000..f9b9a21
62564 --- /dev/null
62565 +++ b/include/linux/grsecurity.h
62566 @@ -0,0 +1,238 @@
62567 +#ifndef GR_SECURITY_H
62568 +#define GR_SECURITY_H
62569 +#include <linux/fs.h>
62570 +#include <linux/fs_struct.h>
62571 +#include <linux/binfmts.h>
62572 +#include <linux/gracl.h>
62573 +
62574 +/* notify of brain-dead configs */
62575 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62576 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62577 +#endif
62578 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62579 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62580 +#endif
62581 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62582 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62583 +#endif
62584 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62585 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62586 +#endif
62587 +
62588 +#include <linux/compat.h>
62589 +
62590 +struct user_arg_ptr {
62591 +#ifdef CONFIG_COMPAT
62592 + bool is_compat;
62593 +#endif
62594 + union {
62595 + const char __user *const __user *native;
62596 +#ifdef CONFIG_COMPAT
62597 + compat_uptr_t __user *compat;
62598 +#endif
62599 + } ptr;
62600 +};
62601 +
62602 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62603 +void gr_handle_brute_check(void);
62604 +void gr_handle_kernel_exploit(void);
62605 +int gr_process_user_ban(void);
62606 +
62607 +char gr_roletype_to_char(void);
62608 +
62609 +int gr_acl_enable_at_secure(void);
62610 +
62611 +int gr_check_user_change(int real, int effective, int fs);
62612 +int gr_check_group_change(int real, int effective, int fs);
62613 +
62614 +void gr_del_task_from_ip_table(struct task_struct *p);
62615 +
62616 +int gr_pid_is_chrooted(struct task_struct *p);
62617 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62618 +int gr_handle_chroot_nice(void);
62619 +int gr_handle_chroot_sysctl(const int op);
62620 +int gr_handle_chroot_setpriority(struct task_struct *p,
62621 + const int niceval);
62622 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62623 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62624 + const struct vfsmount *mnt);
62625 +void gr_handle_chroot_chdir(struct path *path);
62626 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62627 + const struct vfsmount *mnt, const int mode);
62628 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62629 + const struct vfsmount *mnt, const int mode);
62630 +int gr_handle_chroot_mount(const struct dentry *dentry,
62631 + const struct vfsmount *mnt,
62632 + const char *dev_name);
62633 +int gr_handle_chroot_pivot(void);
62634 +int gr_handle_chroot_unix(const pid_t pid);
62635 +
62636 +int gr_handle_rawio(const struct inode *inode);
62637 +
62638 +void gr_handle_ioperm(void);
62639 +void gr_handle_iopl(void);
62640 +
62641 +umode_t gr_acl_umask(void);
62642 +
62643 +int gr_tpe_allow(const struct file *file);
62644 +
62645 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62646 +void gr_clear_chroot_entries(struct task_struct *task);
62647 +
62648 +void gr_log_forkfail(const int retval);
62649 +void gr_log_timechange(void);
62650 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62651 +void gr_log_chdir(const struct dentry *dentry,
62652 + const struct vfsmount *mnt);
62653 +void gr_log_chroot_exec(const struct dentry *dentry,
62654 + const struct vfsmount *mnt);
62655 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62656 +void gr_log_remount(const char *devname, const int retval);
62657 +void gr_log_unmount(const char *devname, const int retval);
62658 +void gr_log_mount(const char *from, const char *to, const int retval);
62659 +void gr_log_textrel(struct vm_area_struct *vma);
62660 +void gr_log_rwxmmap(struct file *file);
62661 +void gr_log_rwxmprotect(struct file *file);
62662 +
62663 +int gr_handle_follow_link(const struct inode *parent,
62664 + const struct inode *inode,
62665 + const struct dentry *dentry,
62666 + const struct vfsmount *mnt);
62667 +int gr_handle_fifo(const struct dentry *dentry,
62668 + const struct vfsmount *mnt,
62669 + const struct dentry *dir, const int flag,
62670 + const int acc_mode);
62671 +int gr_handle_hardlink(const struct dentry *dentry,
62672 + const struct vfsmount *mnt,
62673 + struct inode *inode,
62674 + const int mode, const char *to);
62675 +
62676 +int gr_is_capable(const int cap);
62677 +int gr_is_capable_nolog(const int cap);
62678 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62679 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62680 +
62681 +void gr_learn_resource(const struct task_struct *task, const int limit,
62682 + const unsigned long wanted, const int gt);
62683 +void gr_copy_label(struct task_struct *tsk);
62684 +void gr_handle_crash(struct task_struct *task, const int sig);
62685 +int gr_handle_signal(const struct task_struct *p, const int sig);
62686 +int gr_check_crash_uid(const uid_t uid);
62687 +int gr_check_protected_task(const struct task_struct *task);
62688 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62689 +int gr_acl_handle_mmap(const struct file *file,
62690 + const unsigned long prot);
62691 +int gr_acl_handle_mprotect(const struct file *file,
62692 + const unsigned long prot);
62693 +int gr_check_hidden_task(const struct task_struct *tsk);
62694 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62695 + const struct vfsmount *mnt);
62696 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62697 + const struct vfsmount *mnt);
62698 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62699 + const struct vfsmount *mnt, const int fmode);
62700 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62701 + const struct vfsmount *mnt, umode_t *mode);
62702 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62703 + const struct vfsmount *mnt);
62704 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62705 + const struct vfsmount *mnt);
62706 +int gr_handle_ptrace(struct task_struct *task, const long request);
62707 +int gr_handle_proc_ptrace(struct task_struct *task);
62708 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62709 + const struct vfsmount *mnt);
62710 +int gr_check_crash_exec(const struct file *filp);
62711 +int gr_acl_is_enabled(void);
62712 +void gr_set_kernel_label(struct task_struct *task);
62713 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62714 + const gid_t gid);
62715 +int gr_set_proc_label(const struct dentry *dentry,
62716 + const struct vfsmount *mnt,
62717 + const int unsafe_flags);
62718 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62719 + const struct vfsmount *mnt);
62720 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62721 + const struct vfsmount *mnt, int acc_mode);
62722 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62723 + const struct dentry *p_dentry,
62724 + const struct vfsmount *p_mnt,
62725 + int open_flags, int acc_mode, const int imode);
62726 +void gr_handle_create(const struct dentry *dentry,
62727 + const struct vfsmount *mnt);
62728 +void gr_handle_proc_create(const struct dentry *dentry,
62729 + const struct inode *inode);
62730 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62731 + const struct dentry *parent_dentry,
62732 + const struct vfsmount *parent_mnt,
62733 + const int mode);
62734 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62735 + const struct dentry *parent_dentry,
62736 + const struct vfsmount *parent_mnt);
62737 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62738 + const struct vfsmount *mnt);
62739 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62740 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62741 + const struct vfsmount *mnt);
62742 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62743 + const struct dentry *parent_dentry,
62744 + const struct vfsmount *parent_mnt,
62745 + const char *from);
62746 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62747 + const struct dentry *parent_dentry,
62748 + const struct vfsmount *parent_mnt,
62749 + const struct dentry *old_dentry,
62750 + const struct vfsmount *old_mnt, const char *to);
62751 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62752 +int gr_acl_handle_rename(struct dentry *new_dentry,
62753 + struct dentry *parent_dentry,
62754 + const struct vfsmount *parent_mnt,
62755 + struct dentry *old_dentry,
62756 + struct inode *old_parent_inode,
62757 + struct vfsmount *old_mnt, const char *newname);
62758 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62759 + struct dentry *old_dentry,
62760 + struct dentry *new_dentry,
62761 + struct vfsmount *mnt, const __u8 replace);
62762 +__u32 gr_check_link(const struct dentry *new_dentry,
62763 + const struct dentry *parent_dentry,
62764 + const struct vfsmount *parent_mnt,
62765 + const struct dentry *old_dentry,
62766 + const struct vfsmount *old_mnt);
62767 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62768 + const unsigned int namelen, const ino_t ino);
62769 +
62770 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62771 + const struct vfsmount *mnt);
62772 +void gr_acl_handle_exit(void);
62773 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62774 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62775 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62776 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62777 +void gr_audit_ptrace(struct task_struct *task);
62778 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62779 +
62780 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62781 +
62782 +#ifdef CONFIG_GRKERNSEC
62783 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62784 +void gr_handle_vm86(void);
62785 +void gr_handle_mem_readwrite(u64 from, u64 to);
62786 +
62787 +void gr_log_badprocpid(const char *entry);
62788 +
62789 +extern int grsec_enable_dmesg;
62790 +extern int grsec_disable_privio;
62791 +
62792 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62793 +extern int grsec_proc_gid;
62794 +#endif
62795 +
62796 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62797 +extern int grsec_enable_chroot_findtask;
62798 +#endif
62799 +#ifdef CONFIG_GRKERNSEC_SETXID
62800 +extern int grsec_enable_setxid;
62801 +#endif
62802 +#endif
62803 +
62804 +#endif
62805 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62806 new file mode 100644
62807 index 0000000..e7ffaaf
62808 --- /dev/null
62809 +++ b/include/linux/grsock.h
62810 @@ -0,0 +1,19 @@
62811 +#ifndef __GRSOCK_H
62812 +#define __GRSOCK_H
62813 +
62814 +extern void gr_attach_curr_ip(const struct sock *sk);
62815 +extern int gr_handle_sock_all(const int family, const int type,
62816 + const int protocol);
62817 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62818 +extern int gr_handle_sock_server_other(const struct sock *sck);
62819 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62820 +extern int gr_search_connect(struct socket * sock,
62821 + struct sockaddr_in * addr);
62822 +extern int gr_search_bind(struct socket * sock,
62823 + struct sockaddr_in * addr);
62824 +extern int gr_search_listen(struct socket * sock);
62825 +extern int gr_search_accept(struct socket * sock);
62826 +extern int gr_search_socket(const int domain, const int type,
62827 + const int protocol);
62828 +
62829 +#endif
62830 diff --git a/include/linux/hid.h b/include/linux/hid.h
62831 index 42970de..5db3c92 100644
62832 --- a/include/linux/hid.h
62833 +++ b/include/linux/hid.h
62834 @@ -705,7 +705,7 @@ struct hid_ll_driver {
62835 unsigned int code, int value);
62836
62837 int (*parse)(struct hid_device *hdev);
62838 -};
62839 +} __no_const;
62840
62841 #define PM_HINT_FULLON 1<<5
62842 #define PM_HINT_NORMAL 1<<1
62843 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62844 index ef788b5..ac41b7b 100644
62845 --- a/include/linux/highmem.h
62846 +++ b/include/linux/highmem.h
62847 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62848 kunmap_atomic(kaddr);
62849 }
62850
62851 +static inline void sanitize_highpage(struct page *page)
62852 +{
62853 + void *kaddr;
62854 + unsigned long flags;
62855 +
62856 + local_irq_save(flags);
62857 + kaddr = kmap_atomic(page);
62858 + clear_page(kaddr);
62859 + kunmap_atomic(kaddr);
62860 + local_irq_restore(flags);
62861 +}
62862 +
62863 static inline void zero_user_segments(struct page *page,
62864 unsigned start1, unsigned end1,
62865 unsigned start2, unsigned end2)
62866 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62867 index 5970266..1c48c3b 100644
62868 --- a/include/linux/i2c.h
62869 +++ b/include/linux/i2c.h
62870 @@ -369,6 +369,7 @@ struct i2c_algorithm {
62871 /* To determine what the adapter supports */
62872 u32 (*functionality) (struct i2c_adapter *);
62873 };
62874 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62875
62876 /*
62877 * i2c_adapter is the structure used to identify a physical i2c bus along
62878 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62879 index d23c3c2..eb63c81 100644
62880 --- a/include/linux/i2o.h
62881 +++ b/include/linux/i2o.h
62882 @@ -565,7 +565,7 @@ struct i2o_controller {
62883 struct i2o_device *exec; /* Executive */
62884 #if BITS_PER_LONG == 64
62885 spinlock_t context_list_lock; /* lock for context_list */
62886 - atomic_t context_list_counter; /* needed for unique contexts */
62887 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62888 struct list_head context_list; /* list of context id's
62889 and pointers */
62890 #endif
62891 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62892 index aa2e167..84024ce 100644
62893 --- a/include/linux/if_team.h
62894 +++ b/include/linux/if_team.h
62895 @@ -109,6 +109,7 @@ struct team_mode_ops {
62896 void (*port_enabled)(struct team *team, struct team_port *port);
62897 void (*port_disabled)(struct team *team, struct team_port *port);
62898 };
62899 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62900
62901 enum team_option_type {
62902 TEAM_OPTION_TYPE_U32,
62903 @@ -181,7 +182,7 @@ struct team {
62904 struct list_head option_inst_list; /* list of option instances */
62905
62906 const struct team_mode *mode;
62907 - struct team_mode_ops ops;
62908 + team_mode_ops_no_const ops;
62909 long mode_priv[TEAM_MODE_PRIV_LONGS];
62910 };
62911
62912 diff --git a/include/linux/init.h b/include/linux/init.h
62913 index 5e664f6..0a1225c 100644
62914 --- a/include/linux/init.h
62915 +++ b/include/linux/init.h
62916 @@ -39,9 +39,15 @@
62917 * Also note, that this data cannot be "const".
62918 */
62919
62920 +#ifdef MODULE
62921 +#define add_latent_entropy
62922 +#else
62923 +#define add_latent_entropy __latent_entropy
62924 +#endif
62925 +
62926 /* These are for everybody (although not all archs will actually
62927 discard it in modules) */
62928 -#define __init __section(.init.text) __cold notrace
62929 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62930 #define __initdata __section(.init.data)
62931 #define __initconst __section(.init.rodata)
62932 #define __exitdata __section(.exit.data)
62933 @@ -83,7 +89,7 @@
62934 #define __exit __section(.exit.text) __exitused __cold notrace
62935
62936 /* Used for HOTPLUG */
62937 -#define __devinit __section(.devinit.text) __cold notrace
62938 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62939 #define __devinitdata __section(.devinit.data)
62940 #define __devinitconst __section(.devinit.rodata)
62941 #define __devexit __section(.devexit.text) __exitused __cold notrace
62942 @@ -91,7 +97,7 @@
62943 #define __devexitconst __section(.devexit.rodata)
62944
62945 /* Used for HOTPLUG_CPU */
62946 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62947 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62948 #define __cpuinitdata __section(.cpuinit.data)
62949 #define __cpuinitconst __section(.cpuinit.rodata)
62950 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62951 @@ -99,7 +105,7 @@
62952 #define __cpuexitconst __section(.cpuexit.rodata)
62953
62954 /* Used for MEMORY_HOTPLUG */
62955 -#define __meminit __section(.meminit.text) __cold notrace
62956 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62957 #define __meminitdata __section(.meminit.data)
62958 #define __meminitconst __section(.meminit.rodata)
62959 #define __memexit __section(.memexit.text) __exitused __cold notrace
62960 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62961 index 89f1cb1..7986c0f 100644
62962 --- a/include/linux/init_task.h
62963 +++ b/include/linux/init_task.h
62964 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
62965
62966 #define INIT_TASK_COMM "swapper"
62967
62968 +#ifdef CONFIG_X86
62969 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62970 +#else
62971 +#define INIT_TASK_THREAD_INFO
62972 +#endif
62973 +
62974 /*
62975 * INIT_TASK is used to set up the first task table, touch at
62976 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62977 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
62978 RCU_POINTER_INITIALIZER(cred, &init_cred), \
62979 .comm = INIT_TASK_COMM, \
62980 .thread = INIT_THREAD, \
62981 + INIT_TASK_THREAD_INFO \
62982 .fs = &init_fs, \
62983 .files = &init_files, \
62984 .signal = &init_signals, \
62985 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62986 index 78e2ada..745564d 100644
62987 --- a/include/linux/intel-iommu.h
62988 +++ b/include/linux/intel-iommu.h
62989 @@ -296,7 +296,7 @@ struct iommu_flush {
62990 u8 fm, u64 type);
62991 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62992 unsigned int size_order, u64 type);
62993 -};
62994 +} __no_const;
62995
62996 enum {
62997 SR_DMAR_FECTL_REG,
62998 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62999 index c5f856a..d29c117 100644
63000 --- a/include/linux/interrupt.h
63001 +++ b/include/linux/interrupt.h
63002 @@ -433,7 +433,7 @@ enum
63003 /* map softirq index to softirq name. update 'softirq_to_name' in
63004 * kernel/softirq.c when adding a new softirq.
63005 */
63006 -extern char *softirq_to_name[NR_SOFTIRQS];
63007 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63008
63009 /* softirq mask and active fields moved to irq_cpustat_t in
63010 * asm/hardirq.h to get better cache usage. KAO
63011 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63012
63013 struct softirq_action
63014 {
63015 - void (*action)(struct softirq_action *);
63016 + void (*action)(void);
63017 };
63018
63019 asmlinkage void do_softirq(void);
63020 asmlinkage void __do_softirq(void);
63021 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63022 +extern void open_softirq(int nr, void (*action)(void));
63023 extern void softirq_init(void);
63024 extern void __raise_softirq_irqoff(unsigned int nr);
63025
63026 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63027 index 6883e19..06992b1 100644
63028 --- a/include/linux/kallsyms.h
63029 +++ b/include/linux/kallsyms.h
63030 @@ -15,7 +15,8 @@
63031
63032 struct module;
63033
63034 -#ifdef CONFIG_KALLSYMS
63035 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63036 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63037 /* Lookup the address for a symbol. Returns 0 if not found. */
63038 unsigned long kallsyms_lookup_name(const char *name);
63039
63040 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63041 /* Stupid that this does nothing, but I didn't create this mess. */
63042 #define __print_symbol(fmt, addr)
63043 #endif /*CONFIG_KALLSYMS*/
63044 +#else /* when included by kallsyms.c, vsnprintf.c, or
63045 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63046 +extern void __print_symbol(const char *fmt, unsigned long address);
63047 +extern int sprint_backtrace(char *buffer, unsigned long address);
63048 +extern int sprint_symbol(char *buffer, unsigned long address);
63049 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63050 +const char *kallsyms_lookup(unsigned long addr,
63051 + unsigned long *symbolsize,
63052 + unsigned long *offset,
63053 + char **modname, char *namebuf);
63054 +#endif
63055
63056 /* This macro allows us to keep printk typechecking */
63057 static __printf(1, 2)
63058 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63059 index c4d2fc1..5df9c19 100644
63060 --- a/include/linux/kgdb.h
63061 +++ b/include/linux/kgdb.h
63062 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63063 extern int kgdb_io_module_registered;
63064
63065 extern atomic_t kgdb_setting_breakpoint;
63066 -extern atomic_t kgdb_cpu_doing_single_step;
63067 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63068
63069 extern struct task_struct *kgdb_usethread;
63070 extern struct task_struct *kgdb_contthread;
63071 @@ -252,7 +252,7 @@ struct kgdb_arch {
63072 void (*disable_hw_break)(struct pt_regs *regs);
63073 void (*remove_all_hw_break)(void);
63074 void (*correct_hw_break)(void);
63075 -};
63076 +} __do_const;
63077
63078 /**
63079 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63080 @@ -277,7 +277,7 @@ struct kgdb_io {
63081 void (*pre_exception) (void);
63082 void (*post_exception) (void);
63083 int is_console;
63084 -};
63085 +} __do_const;
63086
63087 extern struct kgdb_arch arch_kgdb_ops;
63088
63089 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63090 index 5398d58..5883a34 100644
63091 --- a/include/linux/kmod.h
63092 +++ b/include/linux/kmod.h
63093 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63094 * usually useless though. */
63095 extern __printf(2, 3)
63096 int __request_module(bool wait, const char *name, ...);
63097 +extern __printf(3, 4)
63098 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63099 #define request_module(mod...) __request_module(true, mod)
63100 #define request_module_nowait(mod...) __request_module(false, mod)
63101 #define try_then_request_module(x, mod...) \
63102 diff --git a/include/linux/kref.h b/include/linux/kref.h
63103 index 65af688..0592677 100644
63104 --- a/include/linux/kref.h
63105 +++ b/include/linux/kref.h
63106 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63107 static inline int kref_sub(struct kref *kref, unsigned int count,
63108 void (*release)(struct kref *kref))
63109 {
63110 - WARN_ON(release == NULL);
63111 + BUG_ON(release == NULL);
63112
63113 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63114 release(kref);
63115 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63116 index b70b48b..0d7153b 100644
63117 --- a/include/linux/kvm_host.h
63118 +++ b/include/linux/kvm_host.h
63119 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63120 void vcpu_load(struct kvm_vcpu *vcpu);
63121 void vcpu_put(struct kvm_vcpu *vcpu);
63122
63123 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63124 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63125 struct module *module);
63126 void kvm_exit(void);
63127
63128 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63129 struct kvm_guest_debug *dbg);
63130 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63131
63132 -int kvm_arch_init(void *opaque);
63133 +int kvm_arch_init(const void *opaque);
63134 void kvm_arch_exit(void);
63135
63136 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63137 diff --git a/include/linux/libata.h b/include/linux/libata.h
63138 index 64f90e1..32b945b 100644
63139 --- a/include/linux/libata.h
63140 +++ b/include/linux/libata.h
63141 @@ -909,7 +909,7 @@ struct ata_port_operations {
63142 * fields must be pointers.
63143 */
63144 const struct ata_port_operations *inherits;
63145 -};
63146 +} __do_const;
63147
63148 struct ata_port_info {
63149 unsigned long flags;
63150 diff --git a/include/linux/memory.h b/include/linux/memory.h
63151 index ff9a9f8..c715deb 100644
63152 --- a/include/linux/memory.h
63153 +++ b/include/linux/memory.h
63154 @@ -143,7 +143,7 @@ struct memory_accessor {
63155 size_t count);
63156 ssize_t (*write)(struct memory_accessor *, const char *buf,
63157 off_t offset, size_t count);
63158 -};
63159 +} __no_const;
63160
63161 /*
63162 * Kernel text modification mutex, used for code patching. Users of this lock
63163 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63164 index 1318ca6..7521340 100644
63165 --- a/include/linux/mfd/abx500.h
63166 +++ b/include/linux/mfd/abx500.h
63167 @@ -452,6 +452,7 @@ struct abx500_ops {
63168 int (*event_registers_startup_state_get) (struct device *, u8 *);
63169 int (*startup_irq_enabled) (struct device *, unsigned int);
63170 };
63171 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63172
63173 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63174 void abx500_remove_ops(struct device *dev);
63175 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63176 index 9b07725..3d55001 100644
63177 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63178 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63179 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63180 int (*enable) (struct ux500_charger *, int, int, int);
63181 int (*kick_wd) (struct ux500_charger *);
63182 int (*update_curr) (struct ux500_charger *, int);
63183 -};
63184 +} __no_const;
63185
63186 /**
63187 * struct ux500_charger - power supply ux500 charger sub class
63188 diff --git a/include/linux/mm.h b/include/linux/mm.h
63189 index 311be90..5f1638c 100644
63190 --- a/include/linux/mm.h
63191 +++ b/include/linux/mm.h
63192 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63193
63194 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63195 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63196 +
63197 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63198 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63199 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63200 +#else
63201 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63202 +#endif
63203 +
63204 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63205 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63206
63207 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63208 int set_page_dirty_lock(struct page *page);
63209 int clear_page_dirty_for_io(struct page *page);
63210
63211 -/* Is the vma a continuation of the stack vma above it? */
63212 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63213 -{
63214 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63215 -}
63216 -
63217 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63218 - unsigned long addr)
63219 -{
63220 - return (vma->vm_flags & VM_GROWSDOWN) &&
63221 - (vma->vm_start == addr) &&
63222 - !vma_growsdown(vma->vm_prev, addr);
63223 -}
63224 -
63225 -/* Is the vma a continuation of the stack vma below it? */
63226 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63227 -{
63228 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63229 -}
63230 -
63231 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63232 - unsigned long addr)
63233 -{
63234 - return (vma->vm_flags & VM_GROWSUP) &&
63235 - (vma->vm_end == addr) &&
63236 - !vma_growsup(vma->vm_next, addr);
63237 -}
63238 -
63239 extern pid_t
63240 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63241
63242 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63243 }
63244 #endif
63245
63246 +#ifdef CONFIG_MMU
63247 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63248 +#else
63249 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63250 +{
63251 + return __pgprot(0);
63252 +}
63253 +#endif
63254 +
63255 int vma_wants_writenotify(struct vm_area_struct *vma);
63256
63257 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63258 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63259 {
63260 return 0;
63261 }
63262 +
63263 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63264 + unsigned long address)
63265 +{
63266 + return 0;
63267 +}
63268 #else
63269 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63270 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63271 #endif
63272
63273 #ifdef __PAGETABLE_PMD_FOLDED
63274 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63275 {
63276 return 0;
63277 }
63278 +
63279 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63280 + unsigned long address)
63281 +{
63282 + return 0;
63283 +}
63284 #else
63285 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63286 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63287 #endif
63288
63289 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63290 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63291 NULL: pud_offset(pgd, address);
63292 }
63293
63294 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63295 +{
63296 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63297 + NULL: pud_offset(pgd, address);
63298 +}
63299 +
63300 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63301 {
63302 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63303 NULL: pmd_offset(pud, address);
63304 }
63305 +
63306 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63307 +{
63308 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63309 + NULL: pmd_offset(pud, address);
63310 +}
63311 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63312
63313 #if USE_SPLIT_PTLOCKS
63314 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63315 unsigned long, unsigned long,
63316 unsigned long, unsigned long);
63317 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63318 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63319
63320 /* These take the mm semaphore themselves */
63321 extern unsigned long vm_brk(unsigned long, unsigned long);
63322 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63323 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63324 struct vm_area_struct **pprev);
63325
63326 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63327 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63328 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63329 +
63330 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63331 NULL if none. Assume start_addr < end_addr. */
63332 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63333 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63334 return vma;
63335 }
63336
63337 -#ifdef CONFIG_MMU
63338 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63339 -#else
63340 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63341 -{
63342 - return __pgprot(0);
63343 -}
63344 -#endif
63345 -
63346 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63347 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63348 unsigned long pfn, unsigned long size, pgprot_t);
63349 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63350 extern int sysctl_memory_failure_early_kill;
63351 extern int sysctl_memory_failure_recovery;
63352 extern void shake_page(struct page *p, int access);
63353 -extern atomic_long_t mce_bad_pages;
63354 +extern atomic_long_unchecked_t mce_bad_pages;
63355 extern int soft_offline_page(struct page *page, int flags);
63356
63357 extern void dump_page(struct page *page);
63358 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63359 static inline bool page_is_guard(struct page *page) { return false; }
63360 #endif /* CONFIG_DEBUG_PAGEALLOC */
63361
63362 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63363 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63364 +#else
63365 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63366 +#endif
63367 +
63368 #endif /* __KERNEL__ */
63369 #endif /* _LINUX_MM_H */
63370 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63371 index bf78672..debc693 100644
63372 --- a/include/linux/mm_types.h
63373 +++ b/include/linux/mm_types.h
63374 @@ -279,6 +279,8 @@ struct vm_area_struct {
63375 #ifdef CONFIG_NUMA
63376 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63377 #endif
63378 +
63379 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63380 };
63381
63382 struct core_thread {
63383 @@ -353,7 +355,7 @@ struct mm_struct {
63384 unsigned long def_flags;
63385 unsigned long nr_ptes; /* Page table pages */
63386 unsigned long start_code, end_code, start_data, end_data;
63387 - unsigned long start_brk, brk, start_stack;
63388 + unsigned long brk_gap, start_brk, brk, start_stack;
63389 unsigned long arg_start, arg_end, env_start, env_end;
63390
63391 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63392 @@ -405,6 +407,24 @@ struct mm_struct {
63393 struct cpumask cpumask_allocation;
63394 #endif
63395 struct uprobes_state uprobes_state;
63396 +
63397 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63398 + unsigned long pax_flags;
63399 +#endif
63400 +
63401 +#ifdef CONFIG_PAX_DLRESOLVE
63402 + unsigned long call_dl_resolve;
63403 +#endif
63404 +
63405 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63406 + unsigned long call_syscall;
63407 +#endif
63408 +
63409 +#ifdef CONFIG_PAX_ASLR
63410 + unsigned long delta_mmap; /* randomized offset */
63411 + unsigned long delta_stack; /* randomized offset */
63412 +#endif
63413 +
63414 };
63415
63416 static inline void mm_init_cpumask(struct mm_struct *mm)
63417 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63418 index 1d1b1e1..2a13c78 100644
63419 --- a/include/linux/mmu_notifier.h
63420 +++ b/include/linux/mmu_notifier.h
63421 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63422 */
63423 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63424 ({ \
63425 - pte_t __pte; \
63426 + pte_t ___pte; \
63427 struct vm_area_struct *___vma = __vma; \
63428 unsigned long ___address = __address; \
63429 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63430 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63431 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63432 - __pte; \
63433 + ___pte; \
63434 })
63435
63436 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63437 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63438 index 2daa54f..bfdf2f5 100644
63439 --- a/include/linux/mmzone.h
63440 +++ b/include/linux/mmzone.h
63441 @@ -414,7 +414,7 @@ struct zone {
63442 unsigned long flags; /* zone flags, see below */
63443
63444 /* Zone statistics */
63445 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63446 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63447
63448 /*
63449 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63450 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63451 index 6955045..ebdb7cd 100644
63452 --- a/include/linux/mod_devicetable.h
63453 +++ b/include/linux/mod_devicetable.h
63454 @@ -12,7 +12,7 @@
63455 typedef unsigned long kernel_ulong_t;
63456 #endif
63457
63458 -#define PCI_ANY_ID (~0)
63459 +#define PCI_ANY_ID ((__u16)~0)
63460
63461 struct pci_device_id {
63462 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63463 @@ -139,7 +139,7 @@ struct usb_device_id {
63464 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63465 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63466
63467 -#define HID_ANY_ID (~0)
63468 +#define HID_ANY_ID (~0U)
63469 #define HID_BUS_ANY 0xffff
63470 #define HID_GROUP_ANY 0x0000
63471
63472 diff --git a/include/linux/module.h b/include/linux/module.h
63473 index fbcafe2..e5d9587 100644
63474 --- a/include/linux/module.h
63475 +++ b/include/linux/module.h
63476 @@ -17,6 +17,7 @@
63477 #include <linux/moduleparam.h>
63478 #include <linux/tracepoint.h>
63479 #include <linux/export.h>
63480 +#include <linux/fs.h>
63481
63482 #include <linux/percpu.h>
63483 #include <asm/module.h>
63484 @@ -273,19 +274,16 @@ struct module
63485 int (*init)(void);
63486
63487 /* If this is non-NULL, vfree after init() returns */
63488 - void *module_init;
63489 + void *module_init_rx, *module_init_rw;
63490
63491 /* Here is the actual code + data, vfree'd on unload. */
63492 - void *module_core;
63493 + void *module_core_rx, *module_core_rw;
63494
63495 /* Here are the sizes of the init and core sections */
63496 - unsigned int init_size, core_size;
63497 + unsigned int init_size_rw, core_size_rw;
63498
63499 /* The size of the executable code in each section. */
63500 - unsigned int init_text_size, core_text_size;
63501 -
63502 - /* Size of RO sections of the module (text+rodata) */
63503 - unsigned int init_ro_size, core_ro_size;
63504 + unsigned int init_size_rx, core_size_rx;
63505
63506 /* Arch-specific module values */
63507 struct mod_arch_specific arch;
63508 @@ -341,6 +339,10 @@ struct module
63509 #ifdef CONFIG_EVENT_TRACING
63510 struct ftrace_event_call **trace_events;
63511 unsigned int num_trace_events;
63512 + struct file_operations trace_id;
63513 + struct file_operations trace_enable;
63514 + struct file_operations trace_format;
63515 + struct file_operations trace_filter;
63516 #endif
63517 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63518 unsigned int num_ftrace_callsites;
63519 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63520 bool is_module_percpu_address(unsigned long addr);
63521 bool is_module_text_address(unsigned long addr);
63522
63523 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63524 +{
63525 +
63526 +#ifdef CONFIG_PAX_KERNEXEC
63527 + if (ktla_ktva(addr) >= (unsigned long)start &&
63528 + ktla_ktva(addr) < (unsigned long)start + size)
63529 + return 1;
63530 +#endif
63531 +
63532 + return ((void *)addr >= start && (void *)addr < start + size);
63533 +}
63534 +
63535 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63536 +{
63537 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63538 +}
63539 +
63540 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63541 +{
63542 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63543 +}
63544 +
63545 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63546 +{
63547 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63548 +}
63549 +
63550 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63551 +{
63552 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63553 +}
63554 +
63555 static inline int within_module_core(unsigned long addr, struct module *mod)
63556 {
63557 - return (unsigned long)mod->module_core <= addr &&
63558 - addr < (unsigned long)mod->module_core + mod->core_size;
63559 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63560 }
63561
63562 static inline int within_module_init(unsigned long addr, struct module *mod)
63563 {
63564 - return (unsigned long)mod->module_init <= addr &&
63565 - addr < (unsigned long)mod->module_init + mod->init_size;
63566 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63567 }
63568
63569 /* Search for module by name: must hold module_mutex. */
63570 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63571 index b2be02e..72d2f78 100644
63572 --- a/include/linux/moduleloader.h
63573 +++ b/include/linux/moduleloader.h
63574 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63575
63576 /* Allocator used for allocating struct module, core sections and init
63577 sections. Returns NULL on failure. */
63578 -void *module_alloc(unsigned long size);
63579 +void *module_alloc(unsigned long size) __size_overflow(1);
63580 +
63581 +#ifdef CONFIG_PAX_KERNEXEC
63582 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63583 +#else
63584 +#define module_alloc_exec(x) module_alloc(x)
63585 +#endif
63586
63587 /* Free memory returned from module_alloc. */
63588 void module_free(struct module *mod, void *module_region);
63589
63590 +#ifdef CONFIG_PAX_KERNEXEC
63591 +void module_free_exec(struct module *mod, void *module_region);
63592 +#else
63593 +#define module_free_exec(x, y) module_free((x), (y))
63594 +#endif
63595 +
63596 /* Apply the given relocation to the (simplified) ELF. Return -error
63597 or 0. */
63598 int apply_relocate(Elf_Shdr *sechdrs,
63599 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63600 index d6a5806..7c13347 100644
63601 --- a/include/linux/moduleparam.h
63602 +++ b/include/linux/moduleparam.h
63603 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63604 * @len is usually just sizeof(string).
63605 */
63606 #define module_param_string(name, string, len, perm) \
63607 - static const struct kparam_string __param_string_##name \
63608 + static const struct kparam_string __param_string_##name __used \
63609 = { len, string }; \
63610 __module_param_call(MODULE_PARAM_PREFIX, name, \
63611 &param_ops_string, \
63612 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63613 */
63614 #define module_param_array_named(name, array, type, nump, perm) \
63615 param_check_##type(name, &(array)[0]); \
63616 - static const struct kparam_array __param_arr_##name \
63617 + static const struct kparam_array __param_arr_##name __used \
63618 = { .max = ARRAY_SIZE(array), .num = nump, \
63619 .ops = &param_ops_##type, \
63620 .elemsize = sizeof(array[0]), .elem = array }; \
63621 diff --git a/include/linux/namei.h b/include/linux/namei.h
63622 index 4bf19d8..5268cea 100644
63623 --- a/include/linux/namei.h
63624 +++ b/include/linux/namei.h
63625 @@ -18,7 +18,7 @@ struct nameidata {
63626 unsigned seq;
63627 int last_type;
63628 unsigned depth;
63629 - char *saved_names[MAX_NESTED_LINKS + 1];
63630 + const char *saved_names[MAX_NESTED_LINKS + 1];
63631 };
63632
63633 /*
63634 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63635
63636 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63637
63638 -static inline void nd_set_link(struct nameidata *nd, char *path)
63639 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63640 {
63641 nd->saved_names[nd->depth] = path;
63642 }
63643
63644 -static inline char *nd_get_link(struct nameidata *nd)
63645 +static inline const char *nd_get_link(const struct nameidata *nd)
63646 {
63647 return nd->saved_names[nd->depth];
63648 }
63649 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63650 index 59dc05f3..c905a34 100644
63651 --- a/include/linux/netdevice.h
63652 +++ b/include/linux/netdevice.h
63653 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63654 struct net_device *dev,
63655 int idx);
63656 };
63657 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63658
63659 /*
63660 * The DEVICE structure.
63661 @@ -1087,7 +1088,7 @@ struct net_device {
63662 int iflink;
63663
63664 struct net_device_stats stats;
63665 - atomic_long_t rx_dropped; /* dropped packets by core network
63666 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63667 * Do not use this in drivers.
63668 */
63669
63670 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63671 new file mode 100644
63672 index 0000000..33f4af8
63673 --- /dev/null
63674 +++ b/include/linux/netfilter/xt_gradm.h
63675 @@ -0,0 +1,9 @@
63676 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63677 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63678 +
63679 +struct xt_gradm_mtinfo {
63680 + __u16 flags;
63681 + __u16 invflags;
63682 +};
63683 +
63684 +#endif
63685 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63686 index c65a18a..0c05f3a 100644
63687 --- a/include/linux/of_pdt.h
63688 +++ b/include/linux/of_pdt.h
63689 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63690
63691 /* return 0 on success; fill in 'len' with number of bytes in path */
63692 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63693 -};
63694 +} __no_const;
63695
63696 extern void *prom_early_alloc(unsigned long size);
63697
63698 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63699 index a4c5624..79d6d88 100644
63700 --- a/include/linux/oprofile.h
63701 +++ b/include/linux/oprofile.h
63702 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63703 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63704 char const * name, ulong * val);
63705
63706 -/** Create a file for read-only access to an atomic_t. */
63707 +/** Create a file for read-only access to an atomic_unchecked_t. */
63708 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63709 - char const * name, atomic_t * val);
63710 + char const * name, atomic_unchecked_t * val);
63711
63712 /** create a directory */
63713 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63714 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63715 index bdb4161..f373d41 100644
63716 --- a/include/linux/perf_event.h
63717 +++ b/include/linux/perf_event.h
63718 @@ -882,8 +882,8 @@ struct perf_event {
63719
63720 enum perf_event_active_state state;
63721 unsigned int attach_state;
63722 - local64_t count;
63723 - atomic64_t child_count;
63724 + local64_t count; /* PaX: fix it one day */
63725 + atomic64_unchecked_t child_count;
63726
63727 /*
63728 * These are the total time in nanoseconds that the event
63729 @@ -934,8 +934,8 @@ struct perf_event {
63730 * These accumulate total time (in nanoseconds) that children
63731 * events have been enabled and running, respectively.
63732 */
63733 - atomic64_t child_total_time_enabled;
63734 - atomic64_t child_total_time_running;
63735 + atomic64_unchecked_t child_total_time_enabled;
63736 + atomic64_unchecked_t child_total_time_running;
63737
63738 /*
63739 * Protect attach/detach and child_list:
63740 diff --git a/include/linux/personality.h b/include/linux/personality.h
63741 index 8fc7dd1a..c19d89e 100644
63742 --- a/include/linux/personality.h
63743 +++ b/include/linux/personality.h
63744 @@ -44,6 +44,7 @@ enum {
63745 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63746 ADDR_NO_RANDOMIZE | \
63747 ADDR_COMPAT_LAYOUT | \
63748 + ADDR_LIMIT_3GB | \
63749 MMAP_PAGE_ZERO)
63750
63751 /*
63752 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63753 index ad1a427..6419649 100644
63754 --- a/include/linux/pipe_fs_i.h
63755 +++ b/include/linux/pipe_fs_i.h
63756 @@ -45,9 +45,9 @@ struct pipe_buffer {
63757 struct pipe_inode_info {
63758 wait_queue_head_t wait;
63759 unsigned int nrbufs, curbuf, buffers;
63760 - unsigned int readers;
63761 - unsigned int writers;
63762 - unsigned int waiting_writers;
63763 + atomic_t readers;
63764 + atomic_t writers;
63765 + atomic_t waiting_writers;
63766 unsigned int r_counter;
63767 unsigned int w_counter;
63768 struct page *tmp_page;
63769 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63770 index f271860..6b3bec5 100644
63771 --- a/include/linux/pm_runtime.h
63772 +++ b/include/linux/pm_runtime.h
63773 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63774
63775 static inline void pm_runtime_mark_last_busy(struct device *dev)
63776 {
63777 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63778 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63779 }
63780
63781 #else /* !CONFIG_PM_RUNTIME */
63782 diff --git a/include/linux/poison.h b/include/linux/poison.h
63783 index 2110a81..13a11bb 100644
63784 --- a/include/linux/poison.h
63785 +++ b/include/linux/poison.h
63786 @@ -19,8 +19,8 @@
63787 * under normal circumstances, used to verify that nobody uses
63788 * non-initialized list entries.
63789 */
63790 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63791 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63792 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63793 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63794
63795 /********** include/linux/timer.h **********/
63796 /*
63797 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63798 index 5a710b9..0b0dab9 100644
63799 --- a/include/linux/preempt.h
63800 +++ b/include/linux/preempt.h
63801 @@ -126,7 +126,7 @@ struct preempt_ops {
63802 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63803 void (*sched_out)(struct preempt_notifier *notifier,
63804 struct task_struct *next);
63805 -};
63806 +} __no_const;
63807
63808 /**
63809 * preempt_notifier - key for installing preemption notifiers
63810 diff --git a/include/linux/printk.h b/include/linux/printk.h
63811 index 9afc01e..92c32e8 100644
63812 --- a/include/linux/printk.h
63813 +++ b/include/linux/printk.h
63814 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63815 extern int printk_needs_cpu(int cpu);
63816 extern void printk_tick(void);
63817
63818 +extern int kptr_restrict;
63819 +
63820 #ifdef CONFIG_PRINTK
63821 asmlinkage __printf(5, 0)
63822 int vprintk_emit(int facility, int level,
63823 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63824
63825 extern int printk_delay_msec;
63826 extern int dmesg_restrict;
63827 -extern int kptr_restrict;
63828
63829 void log_buf_kexec_setup(void);
63830 void __init setup_log_buf(int early);
63831 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63832 index 3fd2e87..d93a721 100644
63833 --- a/include/linux/proc_fs.h
63834 +++ b/include/linux/proc_fs.h
63835 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63836 return proc_create_data(name, mode, parent, proc_fops, NULL);
63837 }
63838
63839 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63840 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63841 +{
63842 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63843 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63844 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63845 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63846 +#else
63847 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63848 +#endif
63849 +}
63850 +
63851 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63852 umode_t mode, struct proc_dir_entry *base,
63853 read_proc_t *read_proc, void * data)
63854 @@ -258,7 +270,7 @@ union proc_op {
63855 int (*proc_show)(struct seq_file *m,
63856 struct pid_namespace *ns, struct pid *pid,
63857 struct task_struct *task);
63858 -};
63859 +} __no_const;
63860
63861 struct ctl_table_header;
63862 struct ctl_table;
63863 diff --git a/include/linux/random.h b/include/linux/random.h
63864 index ac621ce..c1215f3 100644
63865 --- a/include/linux/random.h
63866 +++ b/include/linux/random.h
63867 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63868 unsigned int value);
63869 extern void add_interrupt_randomness(int irq, int irq_flags);
63870
63871 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63872 +extern void transfer_latent_entropy(void);
63873 +#endif
63874 +
63875 extern void get_random_bytes(void *buf, int nbytes);
63876 extern void get_random_bytes_arch(void *buf, int nbytes);
63877 void generate_random_uuid(unsigned char uuid_out[16]);
63878 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63879
63880 u32 prandom32(struct rnd_state *);
63881
63882 +static inline unsigned long pax_get_random_long(void)
63883 +{
63884 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63885 +}
63886 +
63887 /*
63888 * Handle minimum values for seeds
63889 */
63890 static inline u32 __seed(u32 x, u32 m)
63891 {
63892 - return (x < m) ? x + m : x;
63893 + return (x <= m) ? x + m + 1 : x;
63894 }
63895
63896 /**
63897 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63898 index e0879a7..a12f962 100644
63899 --- a/include/linux/reboot.h
63900 +++ b/include/linux/reboot.h
63901 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63902 * Architecture-specific implementations of sys_reboot commands.
63903 */
63904
63905 -extern void machine_restart(char *cmd);
63906 -extern void machine_halt(void);
63907 -extern void machine_power_off(void);
63908 +extern void machine_restart(char *cmd) __noreturn;
63909 +extern void machine_halt(void) __noreturn;
63910 +extern void machine_power_off(void) __noreturn;
63911
63912 extern void machine_shutdown(void);
63913 struct pt_regs;
63914 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63915 */
63916
63917 extern void kernel_restart_prepare(char *cmd);
63918 -extern void kernel_restart(char *cmd);
63919 -extern void kernel_halt(void);
63920 -extern void kernel_power_off(void);
63921 +extern void kernel_restart(char *cmd) __noreturn;
63922 +extern void kernel_halt(void) __noreturn;
63923 +extern void kernel_power_off(void) __noreturn;
63924
63925 extern int C_A_D; /* for sysctl */
63926 void ctrl_alt_del(void);
63927 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63928 * Emergency restart, callable from an interrupt handler.
63929 */
63930
63931 -extern void emergency_restart(void);
63932 +extern void emergency_restart(void) __noreturn;
63933 #include <asm/emergency-restart.h>
63934
63935 #endif
63936 diff --git a/include/linux/relay.h b/include/linux/relay.h
63937 index 91cacc3..b55ff74 100644
63938 --- a/include/linux/relay.h
63939 +++ b/include/linux/relay.h
63940 @@ -160,7 +160,7 @@ struct rchan_callbacks
63941 * The callback should return 0 if successful, negative if not.
63942 */
63943 int (*remove_buf_file)(struct dentry *dentry);
63944 -};
63945 +} __no_const;
63946
63947 /*
63948 * CONFIG_RELAY kernel API, kernel/relay.c
63949 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63950 index 6fdf027..ff72610 100644
63951 --- a/include/linux/rfkill.h
63952 +++ b/include/linux/rfkill.h
63953 @@ -147,6 +147,7 @@ struct rfkill_ops {
63954 void (*query)(struct rfkill *rfkill, void *data);
63955 int (*set_block)(void *data, bool blocked);
63956 };
63957 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63958
63959 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63960 /**
63961 diff --git a/include/linux/rio.h b/include/linux/rio.h
63962 index a90ebad..fd87b5d 100644
63963 --- a/include/linux/rio.h
63964 +++ b/include/linux/rio.h
63965 @@ -321,7 +321,7 @@ struct rio_ops {
63966 int mbox, void *buffer, size_t len);
63967 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63968 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63969 -};
63970 +} __no_const;
63971
63972 #define RIO_RESOURCE_MEM 0x00000100
63973 #define RIO_RESOURCE_DOORBELL 0x00000200
63974 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63975 index 3fce545..b4fed6e 100644
63976 --- a/include/linux/rmap.h
63977 +++ b/include/linux/rmap.h
63978 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63979 void anon_vma_init(void); /* create anon_vma_cachep */
63980 int anon_vma_prepare(struct vm_area_struct *);
63981 void unlink_anon_vmas(struct vm_area_struct *);
63982 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63983 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63984 void anon_vma_moveto_tail(struct vm_area_struct *);
63985 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63986 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63987
63988 static inline void anon_vma_merge(struct vm_area_struct *vma,
63989 struct vm_area_struct *next)
63990 diff --git a/include/linux/sched.h b/include/linux/sched.h
63991 index 23bddac..5976055 100644
63992 --- a/include/linux/sched.h
63993 +++ b/include/linux/sched.h
63994 @@ -101,6 +101,7 @@ struct bio_list;
63995 struct fs_struct;
63996 struct perf_event_context;
63997 struct blk_plug;
63998 +struct linux_binprm;
63999
64000 /*
64001 * List of flags we want to share for kernel threads,
64002 @@ -384,10 +385,13 @@ struct user_namespace;
64003 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64004
64005 extern int sysctl_max_map_count;
64006 +extern unsigned long sysctl_heap_stack_gap;
64007
64008 #include <linux/aio.h>
64009
64010 #ifdef CONFIG_MMU
64011 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64012 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64013 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64014 extern unsigned long
64015 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64016 @@ -651,6 +655,17 @@ struct signal_struct {
64017 #ifdef CONFIG_TASKSTATS
64018 struct taskstats *stats;
64019 #endif
64020 +
64021 +#ifdef CONFIG_GRKERNSEC
64022 + u32 curr_ip;
64023 + u32 saved_ip;
64024 + u32 gr_saddr;
64025 + u32 gr_daddr;
64026 + u16 gr_sport;
64027 + u16 gr_dport;
64028 + u8 used_accept:1;
64029 +#endif
64030 +
64031 #ifdef CONFIG_AUDIT
64032 unsigned audit_tty;
64033 struct tty_audit_buf *tty_audit_buf;
64034 @@ -734,6 +749,11 @@ struct user_struct {
64035 struct key *session_keyring; /* UID's default session keyring */
64036 #endif
64037
64038 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64039 + unsigned int banned;
64040 + unsigned long ban_expires;
64041 +#endif
64042 +
64043 /* Hash table maintenance information */
64044 struct hlist_node uidhash_node;
64045 kuid_t uid;
64046 @@ -1356,8 +1376,8 @@ struct task_struct {
64047 struct list_head thread_group;
64048
64049 struct completion *vfork_done; /* for vfork() */
64050 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64051 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64052 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64053 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64054
64055 cputime_t utime, stime, utimescaled, stimescaled;
64056 cputime_t gtime;
64057 @@ -1373,11 +1393,6 @@ struct task_struct {
64058 struct task_cputime cputime_expires;
64059 struct list_head cpu_timers[3];
64060
64061 -/* process credentials */
64062 - const struct cred __rcu *real_cred; /* objective and real subjective task
64063 - * credentials (COW) */
64064 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64065 - * credentials (COW) */
64066 char comm[TASK_COMM_LEN]; /* executable name excluding path
64067 - access with [gs]et_task_comm (which lock
64068 it with task_lock())
64069 @@ -1394,6 +1409,10 @@ struct task_struct {
64070 #endif
64071 /* CPU-specific state of this task */
64072 struct thread_struct thread;
64073 +/* thread_info moved to task_struct */
64074 +#ifdef CONFIG_X86
64075 + struct thread_info tinfo;
64076 +#endif
64077 /* filesystem information */
64078 struct fs_struct *fs;
64079 /* open file information */
64080 @@ -1467,6 +1486,10 @@ struct task_struct {
64081 gfp_t lockdep_reclaim_gfp;
64082 #endif
64083
64084 +/* process credentials */
64085 + const struct cred __rcu *real_cred; /* objective and real subjective task
64086 + * credentials (COW) */
64087 +
64088 /* journalling filesystem info */
64089 void *journal_info;
64090
64091 @@ -1505,6 +1528,10 @@ struct task_struct {
64092 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64093 struct list_head cg_list;
64094 #endif
64095 +
64096 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64097 + * credentials (COW) */
64098 +
64099 #ifdef CONFIG_FUTEX
64100 struct robust_list_head __user *robust_list;
64101 #ifdef CONFIG_COMPAT
64102 @@ -1589,8 +1616,74 @@ struct task_struct {
64103 #ifdef CONFIG_UPROBES
64104 struct uprobe_task *utask;
64105 #endif
64106 +
64107 +#ifdef CONFIG_GRKERNSEC
64108 + /* grsecurity */
64109 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64110 + u64 exec_id;
64111 +#endif
64112 +#ifdef CONFIG_GRKERNSEC_SETXID
64113 + const struct cred *delayed_cred;
64114 +#endif
64115 + struct dentry *gr_chroot_dentry;
64116 + struct acl_subject_label *acl;
64117 + struct acl_role_label *role;
64118 + struct file *exec_file;
64119 + u16 acl_role_id;
64120 + /* is this the task that authenticated to the special role */
64121 + u8 acl_sp_role;
64122 + u8 is_writable;
64123 + u8 brute;
64124 + u8 gr_is_chrooted;
64125 +#endif
64126 +
64127 };
64128
64129 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64130 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64131 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64132 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64133 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64134 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64135 +
64136 +#ifdef CONFIG_PAX_SOFTMODE
64137 +extern int pax_softmode;
64138 +#endif
64139 +
64140 +extern int pax_check_flags(unsigned long *);
64141 +
64142 +/* if tsk != current then task_lock must be held on it */
64143 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64144 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64145 +{
64146 + if (likely(tsk->mm))
64147 + return tsk->mm->pax_flags;
64148 + else
64149 + return 0UL;
64150 +}
64151 +
64152 +/* if tsk != current then task_lock must be held on it */
64153 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64154 +{
64155 + if (likely(tsk->mm)) {
64156 + tsk->mm->pax_flags = flags;
64157 + return 0;
64158 + }
64159 + return -EINVAL;
64160 +}
64161 +#endif
64162 +
64163 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64164 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64165 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64166 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64167 +#endif
64168 +
64169 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64170 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64171 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64172 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64173 +
64174 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64175 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64176
64177 @@ -2125,7 +2218,9 @@ void yield(void);
64178 extern struct exec_domain default_exec_domain;
64179
64180 union thread_union {
64181 +#ifndef CONFIG_X86
64182 struct thread_info thread_info;
64183 +#endif
64184 unsigned long stack[THREAD_SIZE/sizeof(long)];
64185 };
64186
64187 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64188 */
64189
64190 extern struct task_struct *find_task_by_vpid(pid_t nr);
64191 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64192 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64193 struct pid_namespace *ns);
64194
64195 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64196 extern void exit_itimers(struct signal_struct *);
64197 extern void flush_itimer_signals(void);
64198
64199 -extern void do_group_exit(int);
64200 +extern __noreturn void do_group_exit(int);
64201
64202 extern void daemonize(const char *, ...);
64203 extern int allow_signal(int);
64204 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64205
64206 #endif
64207
64208 -static inline int object_is_on_stack(void *obj)
64209 +static inline int object_starts_on_stack(void *obj)
64210 {
64211 - void *stack = task_stack_page(current);
64212 + const void *stack = task_stack_page(current);
64213
64214 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64215 }
64216 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64217 index 899fbb4..1cb4138 100644
64218 --- a/include/linux/screen_info.h
64219 +++ b/include/linux/screen_info.h
64220 @@ -43,7 +43,8 @@ struct screen_info {
64221 __u16 pages; /* 0x32 */
64222 __u16 vesa_attributes; /* 0x34 */
64223 __u32 capabilities; /* 0x36 */
64224 - __u8 _reserved[6]; /* 0x3a */
64225 + __u16 vesapm_size; /* 0x3a */
64226 + __u8 _reserved[4]; /* 0x3c */
64227 } __attribute__((packed));
64228
64229 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64230 diff --git a/include/linux/security.h b/include/linux/security.h
64231 index d143b8e..9f27b95 100644
64232 --- a/include/linux/security.h
64233 +++ b/include/linux/security.h
64234 @@ -26,6 +26,7 @@
64235 #include <linux/capability.h>
64236 #include <linux/slab.h>
64237 #include <linux/err.h>
64238 +#include <linux/grsecurity.h>
64239
64240 struct linux_binprm;
64241 struct cred;
64242 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64243 index 83c44ee..e8a9eba 100644
64244 --- a/include/linux/seq_file.h
64245 +++ b/include/linux/seq_file.h
64246 @@ -25,6 +25,9 @@ struct seq_file {
64247 struct mutex lock;
64248 const struct seq_operations *op;
64249 int poll_event;
64250 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64251 + u64 exec_id;
64252 +#endif
64253 void *private;
64254 };
64255
64256 @@ -34,6 +37,7 @@ struct seq_operations {
64257 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64258 int (*show) (struct seq_file *m, void *v);
64259 };
64260 +typedef struct seq_operations __no_const seq_operations_no_const;
64261
64262 #define SEQ_SKIP 1
64263
64264 diff --git a/include/linux/shm.h b/include/linux/shm.h
64265 index edd0868..f98feee 100644
64266 --- a/include/linux/shm.h
64267 +++ b/include/linux/shm.h
64268 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64269
64270 /* The task created the shm object. NULL if the task is dead. */
64271 struct task_struct *shm_creator;
64272 +#ifdef CONFIG_GRKERNSEC
64273 + time_t shm_createtime;
64274 + pid_t shm_lapid;
64275 +#endif
64276 };
64277
64278 /* shm_mode upper byte flags */
64279 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64280 index f3165d2..2cb3cb7 100644
64281 --- a/include/linux/skbuff.h
64282 +++ b/include/linux/skbuff.h
64283 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64284 extern struct sk_buff *__alloc_skb(unsigned int size,
64285 gfp_t priority, int flags, int node);
64286 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64287 -static inline struct sk_buff *alloc_skb(unsigned int size,
64288 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64289 gfp_t priority)
64290 {
64291 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64292 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64293 */
64294 static inline int skb_queue_empty(const struct sk_buff_head *list)
64295 {
64296 - return list->next == (struct sk_buff *)list;
64297 + return list->next == (const struct sk_buff *)list;
64298 }
64299
64300 /**
64301 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64302 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64303 const struct sk_buff *skb)
64304 {
64305 - return skb->next == (struct sk_buff *)list;
64306 + return skb->next == (const struct sk_buff *)list;
64307 }
64308
64309 /**
64310 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64311 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64312 const struct sk_buff *skb)
64313 {
64314 - return skb->prev == (struct sk_buff *)list;
64315 + return skb->prev == (const struct sk_buff *)list;
64316 }
64317
64318 /**
64319 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64320 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64321 */
64322 #ifndef NET_SKB_PAD
64323 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64324 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64325 #endif
64326
64327 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64328 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64329 int noblock, int *err);
64330 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64331 struct poll_table_struct *wait);
64332 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64333 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64334 int offset, struct iovec *to,
64335 int size);
64336 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64337 diff --git a/include/linux/slab.h b/include/linux/slab.h
64338 index 0dd2dfa..2b8677c 100644
64339 --- a/include/linux/slab.h
64340 +++ b/include/linux/slab.h
64341 @@ -11,12 +11,20 @@
64342
64343 #include <linux/gfp.h>
64344 #include <linux/types.h>
64345 +#include <linux/err.h>
64346
64347 /*
64348 * Flags to pass to kmem_cache_create().
64349 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64350 */
64351 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64352 +
64353 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64354 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64355 +#else
64356 +#define SLAB_USERCOPY 0x00000000UL
64357 +#endif
64358 +
64359 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64360 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64361 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64362 @@ -87,10 +95,13 @@
64363 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64364 * Both make kfree a no-op.
64365 */
64366 -#define ZERO_SIZE_PTR ((void *)16)
64367 +#define ZERO_SIZE_PTR \
64368 +({ \
64369 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64370 + (void *)(-MAX_ERRNO-1L); \
64371 +})
64372
64373 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64374 - (unsigned long)ZERO_SIZE_PTR)
64375 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64376
64377 /*
64378 * Common fields provided in kmem_cache by all slab allocators
64379 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64380 void kfree(const void *);
64381 void kzfree(const void *);
64382 size_t ksize(const void *);
64383 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64384 +bool is_usercopy_object(const void *ptr);
64385
64386 /*
64387 * Allocator specific definitions. These are mainly used to establish optimized
64388 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64389 */
64390 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64391 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64392 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64393 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64394 #define kmalloc_track_caller(size, flags) \
64395 __kmalloc_track_caller(size, flags, _RET_IP_)
64396 #else
64397 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64398 */
64399 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64400 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64401 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64402 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64403 #define kmalloc_node_track_caller(size, flags, node) \
64404 __kmalloc_node_track_caller(size, flags, node, \
64405 _RET_IP_)
64406 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64407 index 0c634fa..8616300 100644
64408 --- a/include/linux/slab_def.h
64409 +++ b/include/linux/slab_def.h
64410 @@ -69,10 +69,10 @@ struct kmem_cache {
64411 unsigned long node_allocs;
64412 unsigned long node_frees;
64413 unsigned long node_overflow;
64414 - atomic_t allochit;
64415 - atomic_t allocmiss;
64416 - atomic_t freehit;
64417 - atomic_t freemiss;
64418 + atomic_unchecked_t allochit;
64419 + atomic_unchecked_t allocmiss;
64420 + atomic_unchecked_t freehit;
64421 + atomic_unchecked_t freemiss;
64422
64423 /*
64424 * If debugging is enabled, then the allocator can add additional
64425 @@ -105,11 +105,16 @@ struct cache_sizes {
64426 #ifdef CONFIG_ZONE_DMA
64427 struct kmem_cache *cs_dmacachep;
64428 #endif
64429 +
64430 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64431 + struct kmem_cache *cs_usercopycachep;
64432 +#endif
64433 +
64434 };
64435 extern struct cache_sizes malloc_sizes[];
64436
64437 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64438 -void *__kmalloc(size_t size, gfp_t flags);
64439 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64440
64441 #ifdef CONFIG_TRACING
64442 extern void *kmem_cache_alloc_trace(size_t size,
64443 @@ -152,6 +157,13 @@ found:
64444 cachep = malloc_sizes[i].cs_dmacachep;
64445 else
64446 #endif
64447 +
64448 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64449 + if (flags & GFP_USERCOPY)
64450 + cachep = malloc_sizes[i].cs_usercopycachep;
64451 + else
64452 +#endif
64453 +
64454 cachep = malloc_sizes[i].cs_cachep;
64455
64456 ret = kmem_cache_alloc_trace(size, cachep, flags);
64457 @@ -162,7 +174,7 @@ found:
64458 }
64459
64460 #ifdef CONFIG_NUMA
64461 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64462 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64463 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64464
64465 #ifdef CONFIG_TRACING
64466 @@ -205,6 +217,13 @@ found:
64467 cachep = malloc_sizes[i].cs_dmacachep;
64468 else
64469 #endif
64470 +
64471 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64472 + if (flags & GFP_USERCOPY)
64473 + cachep = malloc_sizes[i].cs_usercopycachep;
64474 + else
64475 +#endif
64476 +
64477 cachep = malloc_sizes[i].cs_cachep;
64478
64479 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64480 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64481 index 0ec00b3..22b4715 100644
64482 --- a/include/linux/slob_def.h
64483 +++ b/include/linux/slob_def.h
64484 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64485 return kmem_cache_alloc_node(cachep, flags, -1);
64486 }
64487
64488 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64489 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64490
64491 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64492 {
64493 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64494 return __kmalloc_node(size, flags, -1);
64495 }
64496
64497 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64498 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64499 {
64500 return kmalloc(size, flags);
64501 }
64502 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64503 index df448ad..b99e7f6 100644
64504 --- a/include/linux/slub_def.h
64505 +++ b/include/linux/slub_def.h
64506 @@ -91,7 +91,7 @@ struct kmem_cache {
64507 struct kmem_cache_order_objects max;
64508 struct kmem_cache_order_objects min;
64509 gfp_t allocflags; /* gfp flags to use on each alloc */
64510 - int refcount; /* Refcount for slab cache destroy */
64511 + atomic_t refcount; /* Refcount for slab cache destroy */
64512 void (*ctor)(void *);
64513 int inuse; /* Offset to metadata */
64514 int align; /* Alignment */
64515 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64516 * Sorry that the following has to be that ugly but some versions of GCC
64517 * have trouble with constant propagation and loops.
64518 */
64519 -static __always_inline int kmalloc_index(size_t size)
64520 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64521 {
64522 if (!size)
64523 return 0;
64524 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64525 }
64526
64527 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64528 -void *__kmalloc(size_t size, gfp_t flags);
64529 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64530
64531 static __always_inline void *
64532 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64533 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64534 }
64535 #endif
64536
64537 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64538 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64539 {
64540 unsigned int order = get_order(size);
64541 return kmalloc_order_trace(size, flags, order);
64542 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64543 }
64544
64545 #ifdef CONFIG_NUMA
64546 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64547 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64548 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64549
64550 #ifdef CONFIG_TRACING
64551 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64552 index de8832d..0147b46 100644
64553 --- a/include/linux/sonet.h
64554 +++ b/include/linux/sonet.h
64555 @@ -61,7 +61,7 @@ struct sonet_stats {
64556 #include <linux/atomic.h>
64557
64558 struct k_sonet_stats {
64559 -#define __HANDLE_ITEM(i) atomic_t i
64560 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64561 __SONET_ITEMS
64562 #undef __HANDLE_ITEM
64563 };
64564 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64565 index 523547e..2cb7140 100644
64566 --- a/include/linux/sunrpc/clnt.h
64567 +++ b/include/linux/sunrpc/clnt.h
64568 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64569 {
64570 switch (sap->sa_family) {
64571 case AF_INET:
64572 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64573 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64574 case AF_INET6:
64575 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64576 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64577 }
64578 return 0;
64579 }
64580 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64581 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64582 const struct sockaddr *src)
64583 {
64584 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64585 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64586 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64587
64588 dsin->sin_family = ssin->sin_family;
64589 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64590 if (sa->sa_family != AF_INET6)
64591 return 0;
64592
64593 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64594 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64595 }
64596
64597 #endif /* __KERNEL__ */
64598 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64599 index dc0c3cc..8503fb6 100644
64600 --- a/include/linux/sunrpc/sched.h
64601 +++ b/include/linux/sunrpc/sched.h
64602 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64603 void (*rpc_count_stats)(struct rpc_task *, void *);
64604 void (*rpc_release)(void *);
64605 };
64606 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64607
64608 struct rpc_task_setup {
64609 struct rpc_task *task;
64610 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64611 index 0b8e3e6..33e0a01 100644
64612 --- a/include/linux/sunrpc/svc_rdma.h
64613 +++ b/include/linux/sunrpc/svc_rdma.h
64614 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64615 extern unsigned int svcrdma_max_requests;
64616 extern unsigned int svcrdma_max_req_size;
64617
64618 -extern atomic_t rdma_stat_recv;
64619 -extern atomic_t rdma_stat_read;
64620 -extern atomic_t rdma_stat_write;
64621 -extern atomic_t rdma_stat_sq_starve;
64622 -extern atomic_t rdma_stat_rq_starve;
64623 -extern atomic_t rdma_stat_rq_poll;
64624 -extern atomic_t rdma_stat_rq_prod;
64625 -extern atomic_t rdma_stat_sq_poll;
64626 -extern atomic_t rdma_stat_sq_prod;
64627 +extern atomic_unchecked_t rdma_stat_recv;
64628 +extern atomic_unchecked_t rdma_stat_read;
64629 +extern atomic_unchecked_t rdma_stat_write;
64630 +extern atomic_unchecked_t rdma_stat_sq_starve;
64631 +extern atomic_unchecked_t rdma_stat_rq_starve;
64632 +extern atomic_unchecked_t rdma_stat_rq_poll;
64633 +extern atomic_unchecked_t rdma_stat_rq_prod;
64634 +extern atomic_unchecked_t rdma_stat_sq_poll;
64635 +extern atomic_unchecked_t rdma_stat_sq_prod;
64636
64637 #define RPCRDMA_VERSION 1
64638
64639 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64640 index c34b4c8..a65b67d 100644
64641 --- a/include/linux/sysctl.h
64642 +++ b/include/linux/sysctl.h
64643 @@ -155,7 +155,11 @@ enum
64644 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64645 };
64646
64647 -
64648 +#ifdef CONFIG_PAX_SOFTMODE
64649 +enum {
64650 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64651 +};
64652 +#endif
64653
64654 /* CTL_VM names: */
64655 enum
64656 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64657
64658 extern int proc_dostring(struct ctl_table *, int,
64659 void __user *, size_t *, loff_t *);
64660 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64661 + void __user *, size_t *, loff_t *);
64662 extern int proc_dointvec(struct ctl_table *, int,
64663 void __user *, size_t *, loff_t *);
64664 extern int proc_dointvec_minmax(struct ctl_table *, int,
64665 diff --git a/include/linux/tty.h b/include/linux/tty.h
64666 index 9f47ab5..73da944 100644
64667 --- a/include/linux/tty.h
64668 +++ b/include/linux/tty.h
64669 @@ -225,7 +225,7 @@ struct tty_port {
64670 const struct tty_port_operations *ops; /* Port operations */
64671 spinlock_t lock; /* Lock protecting tty field */
64672 int blocked_open; /* Waiting to open */
64673 - int count; /* Usage count */
64674 + atomic_t count; /* Usage count */
64675 wait_queue_head_t open_wait; /* Open waiters */
64676 wait_queue_head_t close_wait; /* Close waiters */
64677 wait_queue_head_t delta_msr_wait; /* Modem status change */
64678 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64679 struct tty_struct *tty, struct file *filp);
64680 static inline int tty_port_users(struct tty_port *port)
64681 {
64682 - return port->count + port->blocked_open;
64683 + return atomic_read(&port->count) + port->blocked_open;
64684 }
64685
64686 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64687 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64688 index fb79dd8d..07d4773 100644
64689 --- a/include/linux/tty_ldisc.h
64690 +++ b/include/linux/tty_ldisc.h
64691 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64692
64693 struct module *owner;
64694
64695 - int refcount;
64696 + atomic_t refcount;
64697 };
64698
64699 struct tty_ldisc {
64700 diff --git a/include/linux/types.h b/include/linux/types.h
64701 index bf0dd75..a1f23aaa 100644
64702 --- a/include/linux/types.h
64703 +++ b/include/linux/types.h
64704 @@ -220,10 +220,26 @@ typedef struct {
64705 int counter;
64706 } atomic_t;
64707
64708 +#ifdef CONFIG_PAX_REFCOUNT
64709 +typedef struct {
64710 + int counter;
64711 +} atomic_unchecked_t;
64712 +#else
64713 +typedef atomic_t atomic_unchecked_t;
64714 +#endif
64715 +
64716 #ifdef CONFIG_64BIT
64717 typedef struct {
64718 long counter;
64719 } atomic64_t;
64720 +
64721 +#ifdef CONFIG_PAX_REFCOUNT
64722 +typedef struct {
64723 + long counter;
64724 +} atomic64_unchecked_t;
64725 +#else
64726 +typedef atomic64_t atomic64_unchecked_t;
64727 +#endif
64728 #endif
64729
64730 struct list_head {
64731 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64732 index 5ca0951..ab496a5 100644
64733 --- a/include/linux/uaccess.h
64734 +++ b/include/linux/uaccess.h
64735 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64736 long ret; \
64737 mm_segment_t old_fs = get_fs(); \
64738 \
64739 - set_fs(KERNEL_DS); \
64740 pagefault_disable(); \
64741 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64742 - pagefault_enable(); \
64743 + set_fs(KERNEL_DS); \
64744 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64745 set_fs(old_fs); \
64746 + pagefault_enable(); \
64747 ret; \
64748 })
64749
64750 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64751 index 99c1b4d..bb94261 100644
64752 --- a/include/linux/unaligned/access_ok.h
64753 +++ b/include/linux/unaligned/access_ok.h
64754 @@ -6,32 +6,32 @@
64755
64756 static inline u16 get_unaligned_le16(const void *p)
64757 {
64758 - return le16_to_cpup((__le16 *)p);
64759 + return le16_to_cpup((const __le16 *)p);
64760 }
64761
64762 static inline u32 get_unaligned_le32(const void *p)
64763 {
64764 - return le32_to_cpup((__le32 *)p);
64765 + return le32_to_cpup((const __le32 *)p);
64766 }
64767
64768 static inline u64 get_unaligned_le64(const void *p)
64769 {
64770 - return le64_to_cpup((__le64 *)p);
64771 + return le64_to_cpup((const __le64 *)p);
64772 }
64773
64774 static inline u16 get_unaligned_be16(const void *p)
64775 {
64776 - return be16_to_cpup((__be16 *)p);
64777 + return be16_to_cpup((const __be16 *)p);
64778 }
64779
64780 static inline u32 get_unaligned_be32(const void *p)
64781 {
64782 - return be32_to_cpup((__be32 *)p);
64783 + return be32_to_cpup((const __be32 *)p);
64784 }
64785
64786 static inline u64 get_unaligned_be64(const void *p)
64787 {
64788 - return be64_to_cpup((__be64 *)p);
64789 + return be64_to_cpup((const __be64 *)p);
64790 }
64791
64792 static inline void put_unaligned_le16(u16 val, void *p)
64793 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64794 index c5d36c6..8478c90 100644
64795 --- a/include/linux/usb/renesas_usbhs.h
64796 +++ b/include/linux/usb/renesas_usbhs.h
64797 @@ -39,7 +39,7 @@ enum {
64798 */
64799 struct renesas_usbhs_driver_callback {
64800 int (*notify_hotplug)(struct platform_device *pdev);
64801 -};
64802 +} __no_const;
64803
64804 /*
64805 * callback functions for platform
64806 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64807 * VBUS control is needed for Host
64808 */
64809 int (*set_vbus)(struct platform_device *pdev, int enable);
64810 -};
64811 +} __no_const;
64812
64813 /*
64814 * parameters for renesas usbhs
64815 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64816 index 6f8fbcf..8259001 100644
64817 --- a/include/linux/vermagic.h
64818 +++ b/include/linux/vermagic.h
64819 @@ -25,9 +25,35 @@
64820 #define MODULE_ARCH_VERMAGIC ""
64821 #endif
64822
64823 +#ifdef CONFIG_PAX_REFCOUNT
64824 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64825 +#else
64826 +#define MODULE_PAX_REFCOUNT ""
64827 +#endif
64828 +
64829 +#ifdef CONSTIFY_PLUGIN
64830 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64831 +#else
64832 +#define MODULE_CONSTIFY_PLUGIN ""
64833 +#endif
64834 +
64835 +#ifdef STACKLEAK_PLUGIN
64836 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64837 +#else
64838 +#define MODULE_STACKLEAK_PLUGIN ""
64839 +#endif
64840 +
64841 +#ifdef CONFIG_GRKERNSEC
64842 +#define MODULE_GRSEC "GRSEC "
64843 +#else
64844 +#define MODULE_GRSEC ""
64845 +#endif
64846 +
64847 #define VERMAGIC_STRING \
64848 UTS_RELEASE " " \
64849 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64850 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64851 - MODULE_ARCH_VERMAGIC
64852 + MODULE_ARCH_VERMAGIC \
64853 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64854 + MODULE_GRSEC
64855
64856 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64857 index 6071e91..ca6a489 100644
64858 --- a/include/linux/vmalloc.h
64859 +++ b/include/linux/vmalloc.h
64860 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64861 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64862 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64863 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64864 +
64865 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64866 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64867 +#endif
64868 +
64869 /* bits [20..32] reserved for arch specific ioremap internals */
64870
64871 /*
64872 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64873 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64874 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64875 unsigned long start, unsigned long end, gfp_t gfp_mask,
64876 - pgprot_t prot, int node, const void *caller);
64877 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
64878 extern void vfree(const void *addr);
64879
64880 extern void *vmap(struct page **pages, unsigned int count,
64881 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64882 extern void free_vm_area(struct vm_struct *area);
64883
64884 /* for /dev/kmem */
64885 -extern long vread(char *buf, char *addr, unsigned long count);
64886 -extern long vwrite(char *buf, char *addr, unsigned long count);
64887 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64888 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64889
64890 /*
64891 * Internals. Dont't use..
64892 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64893 index ad2cfd5..74c94ad 100644
64894 --- a/include/linux/vmstat.h
64895 +++ b/include/linux/vmstat.h
64896 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64897 /*
64898 * Zone based page accounting with per cpu differentials.
64899 */
64900 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64901 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64902
64903 static inline void zone_page_state_add(long x, struct zone *zone,
64904 enum zone_stat_item item)
64905 {
64906 - atomic_long_add(x, &zone->vm_stat[item]);
64907 - atomic_long_add(x, &vm_stat[item]);
64908 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64909 + atomic_long_add_unchecked(x, &vm_stat[item]);
64910 }
64911
64912 static inline unsigned long global_page_state(enum zone_stat_item item)
64913 {
64914 - long x = atomic_long_read(&vm_stat[item]);
64915 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64916 #ifdef CONFIG_SMP
64917 if (x < 0)
64918 x = 0;
64919 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64920 static inline unsigned long zone_page_state(struct zone *zone,
64921 enum zone_stat_item item)
64922 {
64923 - long x = atomic_long_read(&zone->vm_stat[item]);
64924 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64925 #ifdef CONFIG_SMP
64926 if (x < 0)
64927 x = 0;
64928 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64929 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64930 enum zone_stat_item item)
64931 {
64932 - long x = atomic_long_read(&zone->vm_stat[item]);
64933 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64934
64935 #ifdef CONFIG_SMP
64936 int cpu;
64937 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64938
64939 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64940 {
64941 - atomic_long_inc(&zone->vm_stat[item]);
64942 - atomic_long_inc(&vm_stat[item]);
64943 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64944 + atomic_long_inc_unchecked(&vm_stat[item]);
64945 }
64946
64947 static inline void __inc_zone_page_state(struct page *page,
64948 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
64949
64950 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64951 {
64952 - atomic_long_dec(&zone->vm_stat[item]);
64953 - atomic_long_dec(&vm_stat[item]);
64954 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64955 + atomic_long_dec_unchecked(&vm_stat[item]);
64956 }
64957
64958 static inline void __dec_zone_page_state(struct page *page,
64959 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64960 index e5d1220..ef6e406 100644
64961 --- a/include/linux/xattr.h
64962 +++ b/include/linux/xattr.h
64963 @@ -57,6 +57,11 @@
64964 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64965 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64966
64967 +/* User namespace */
64968 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64969 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64970 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64971 +
64972 #ifdef __KERNEL__
64973
64974 #include <linux/types.h>
64975 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64976 index 944ecdf..a3994fc 100644
64977 --- a/include/media/saa7146_vv.h
64978 +++ b/include/media/saa7146_vv.h
64979 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64980 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64981
64982 /* the extension can override this */
64983 - struct v4l2_ioctl_ops vid_ops;
64984 - struct v4l2_ioctl_ops vbi_ops;
64985 + v4l2_ioctl_ops_no_const vid_ops;
64986 + v4l2_ioctl_ops_no_const vbi_ops;
64987 /* pointer to the saa7146 core ops */
64988 const struct v4l2_ioctl_ops *core_ops;
64989
64990 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64991 index 5c416cd..20021aa 100644
64992 --- a/include/media/v4l2-dev.h
64993 +++ b/include/media/v4l2-dev.h
64994 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64995 int (*mmap) (struct file *, struct vm_area_struct *);
64996 int (*open) (struct file *);
64997 int (*release) (struct file *);
64998 -};
64999 +} __do_const;
65000 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65001
65002 /*
65003 * Newer version of video_device, handled by videodev2.c
65004 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65005 index e614c9c..20602b7 100644
65006 --- a/include/media/v4l2-ioctl.h
65007 +++ b/include/media/v4l2-ioctl.h
65008 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65009 long (*vidioc_default) (struct file *file, void *fh,
65010 bool valid_prio, int cmd, void *arg);
65011 };
65012 -
65013 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65014
65015 /* v4l debugging and diagnostics */
65016
65017 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65018 index bcb9cc3..f4ec722e 100644
65019 --- a/include/net/caif/caif_hsi.h
65020 +++ b/include/net/caif/caif_hsi.h
65021 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65022 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65023 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65024 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65025 -};
65026 +} __no_const;
65027
65028 /* Structure implemented by HSI device. */
65029 struct cfhsi_ops {
65030 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65031 index 9e5425b..8136ffc 100644
65032 --- a/include/net/caif/cfctrl.h
65033 +++ b/include/net/caif/cfctrl.h
65034 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65035 void (*radioset_rsp)(void);
65036 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65037 struct cflayer *client_layer);
65038 -};
65039 +} __no_const;
65040
65041 /* Link Setup Parameters for CAIF-Links. */
65042 struct cfctrl_link_param {
65043 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65044 struct cfctrl {
65045 struct cfsrvl serv;
65046 struct cfctrl_rsp res;
65047 - atomic_t req_seq_no;
65048 - atomic_t rsp_seq_no;
65049 + atomic_unchecked_t req_seq_no;
65050 + atomic_unchecked_t rsp_seq_no;
65051 struct list_head list;
65052 /* Protects from simultaneous access to first_req list */
65053 spinlock_t info_list_lock;
65054 diff --git a/include/net/flow.h b/include/net/flow.h
65055 index 628e11b..4c475df 100644
65056 --- a/include/net/flow.h
65057 +++ b/include/net/flow.h
65058 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65059
65060 extern void flow_cache_flush(void);
65061 extern void flow_cache_flush_deferred(void);
65062 -extern atomic_t flow_cache_genid;
65063 +extern atomic_unchecked_t flow_cache_genid;
65064
65065 #endif
65066 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65067 index 53f464d..ba76aaa 100644
65068 --- a/include/net/inetpeer.h
65069 +++ b/include/net/inetpeer.h
65070 @@ -47,8 +47,8 @@ struct inet_peer {
65071 */
65072 union {
65073 struct {
65074 - atomic_t rid; /* Frag reception counter */
65075 - atomic_t ip_id_count; /* IP ID for the next packet */
65076 + atomic_unchecked_t rid; /* Frag reception counter */
65077 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65078 };
65079 struct rcu_head rcu;
65080 struct inet_peer *gc_next;
65081 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65082 more++;
65083 inet_peer_refcheck(p);
65084 do {
65085 - old = atomic_read(&p->ip_id_count);
65086 + old = atomic_read_unchecked(&p->ip_id_count);
65087 new = old + more;
65088 if (!new)
65089 new = 1;
65090 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65091 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65092 return new;
65093 }
65094
65095 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65096 index 9497be1..5a4fafe 100644
65097 --- a/include/net/ip_fib.h
65098 +++ b/include/net/ip_fib.h
65099 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65100
65101 #define FIB_RES_SADDR(net, res) \
65102 ((FIB_RES_NH(res).nh_saddr_genid == \
65103 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65104 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65105 FIB_RES_NH(res).nh_saddr : \
65106 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65107 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65108 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65109 index 95374d1..2300e36 100644
65110 --- a/include/net/ip_vs.h
65111 +++ b/include/net/ip_vs.h
65112 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65113 struct ip_vs_conn *control; /* Master control connection */
65114 atomic_t n_control; /* Number of controlled ones */
65115 struct ip_vs_dest *dest; /* real server */
65116 - atomic_t in_pkts; /* incoming packet counter */
65117 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65118
65119 /* packet transmitter for different forwarding methods. If it
65120 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65121 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65122 __be16 port; /* port number of the server */
65123 union nf_inet_addr addr; /* IP address of the server */
65124 volatile unsigned int flags; /* dest status flags */
65125 - atomic_t conn_flags; /* flags to copy to conn */
65126 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65127 atomic_t weight; /* server weight */
65128
65129 atomic_t refcnt; /* reference counter */
65130 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65131 index 69b610a..fe3962c 100644
65132 --- a/include/net/irda/ircomm_core.h
65133 +++ b/include/net/irda/ircomm_core.h
65134 @@ -51,7 +51,7 @@ typedef struct {
65135 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65136 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65137 struct ircomm_info *);
65138 -} call_t;
65139 +} __no_const call_t;
65140
65141 struct ircomm_cb {
65142 irda_queue_t queue;
65143 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65144 index 59ba38bc..d515662 100644
65145 --- a/include/net/irda/ircomm_tty.h
65146 +++ b/include/net/irda/ircomm_tty.h
65147 @@ -35,6 +35,7 @@
65148 #include <linux/termios.h>
65149 #include <linux/timer.h>
65150 #include <linux/tty.h> /* struct tty_struct */
65151 +#include <asm/local.h>
65152
65153 #include <net/irda/irias_object.h>
65154 #include <net/irda/ircomm_core.h>
65155 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65156 unsigned short close_delay;
65157 unsigned short closing_wait; /* time to wait before closing */
65158
65159 - int open_count;
65160 - int blocked_open; /* # of blocked opens */
65161 + local_t open_count;
65162 + local_t blocked_open; /* # of blocked opens */
65163
65164 /* Protect concurent access to :
65165 * o self->open_count
65166 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65167 index cc7c197..9f2da2a 100644
65168 --- a/include/net/iucv/af_iucv.h
65169 +++ b/include/net/iucv/af_iucv.h
65170 @@ -141,7 +141,7 @@ struct iucv_sock {
65171 struct iucv_sock_list {
65172 struct hlist_head head;
65173 rwlock_t lock;
65174 - atomic_t autobind_name;
65175 + atomic_unchecked_t autobind_name;
65176 };
65177
65178 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65179 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65180 index 344d898..2ae1302 100644
65181 --- a/include/net/neighbour.h
65182 +++ b/include/net/neighbour.h
65183 @@ -123,7 +123,7 @@ struct neigh_ops {
65184 void (*error_report)(struct neighbour *, struct sk_buff *);
65185 int (*output)(struct neighbour *, struct sk_buff *);
65186 int (*connected_output)(struct neighbour *, struct sk_buff *);
65187 -};
65188 +} __do_const;
65189
65190 struct pneigh_entry {
65191 struct pneigh_entry *next;
65192 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65193 index fd87963..312a11f 100644
65194 --- a/include/net/net_namespace.h
65195 +++ b/include/net/net_namespace.h
65196 @@ -102,7 +102,7 @@ struct net {
65197 #endif
65198 struct netns_ipvs *ipvs;
65199 struct sock *diag_nlsk;
65200 - atomic_t rt_genid;
65201 + atomic_unchecked_t rt_genid;
65202 };
65203
65204
65205 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65206
65207 static inline int rt_genid(struct net *net)
65208 {
65209 - return atomic_read(&net->rt_genid);
65210 + return atomic_read_unchecked(&net->rt_genid);
65211 }
65212
65213 static inline void rt_genid_bump(struct net *net)
65214 {
65215 - atomic_inc(&net->rt_genid);
65216 + atomic_inc_unchecked(&net->rt_genid);
65217 }
65218
65219 #endif /* __NET_NET_NAMESPACE_H */
65220 diff --git a/include/net/netdma.h b/include/net/netdma.h
65221 index 8ba8ce2..99b7fff 100644
65222 --- a/include/net/netdma.h
65223 +++ b/include/net/netdma.h
65224 @@ -24,7 +24,7 @@
65225 #include <linux/dmaengine.h>
65226 #include <linux/skbuff.h>
65227
65228 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65229 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65230 struct sk_buff *skb, int offset, struct iovec *to,
65231 size_t len, struct dma_pinned_list *pinned_list);
65232
65233 diff --git a/include/net/netlink.h b/include/net/netlink.h
65234 index 785f37a..c81dc0c 100644
65235 --- a/include/net/netlink.h
65236 +++ b/include/net/netlink.h
65237 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65238 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65239 {
65240 if (mark)
65241 - skb_trim(skb, (unsigned char *) mark - skb->data);
65242 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65243 }
65244
65245 /**
65246 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65247 index eb24dbc..567d6ed 100644
65248 --- a/include/net/netns/ipv4.h
65249 +++ b/include/net/netns/ipv4.h
65250 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65251 unsigned int sysctl_ping_group_range[2];
65252 long sysctl_tcp_mem[3];
65253
65254 - atomic_t dev_addr_genid;
65255 + atomic_unchecked_t dev_addr_genid;
65256
65257 #ifdef CONFIG_IP_MROUTE
65258 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65259 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65260 index ff49964..1411fee 100644
65261 --- a/include/net/sctp/sctp.h
65262 +++ b/include/net/sctp/sctp.h
65263 @@ -320,9 +320,9 @@ do { \
65264
65265 #else /* SCTP_DEBUG */
65266
65267 -#define SCTP_DEBUG_PRINTK(whatever...)
65268 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65269 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65270 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65271 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65272 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65273 #define SCTP_ENABLE_DEBUG
65274 #define SCTP_DISABLE_DEBUG
65275 #define SCTP_ASSERT(expr, str, func)
65276 diff --git a/include/net/sock.h b/include/net/sock.h
65277 index adb7da2..1100002 100644
65278 --- a/include/net/sock.h
65279 +++ b/include/net/sock.h
65280 @@ -305,7 +305,7 @@ struct sock {
65281 #ifdef CONFIG_RPS
65282 __u32 sk_rxhash;
65283 #endif
65284 - atomic_t sk_drops;
65285 + atomic_unchecked_t sk_drops;
65286 int sk_rcvbuf;
65287
65288 struct sk_filter __rcu *sk_filter;
65289 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65290 }
65291
65292 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65293 - char __user *from, char *to,
65294 + char __user *from, unsigned char *to,
65295 int copy, int offset)
65296 {
65297 if (skb->ip_summed == CHECKSUM_NONE) {
65298 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65299 }
65300 }
65301
65302 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65303 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65304
65305 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65306 {
65307 diff --git a/include/net/tcp.h b/include/net/tcp.h
65308 index 1f000ff..e5a8dfb 100644
65309 --- a/include/net/tcp.h
65310 +++ b/include/net/tcp.h
65311 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65312 extern void tcp_xmit_retransmit_queue(struct sock *);
65313 extern void tcp_simple_retransmit(struct sock *);
65314 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65315 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65316 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65317
65318 extern void tcp_send_probe0(struct sock *);
65319 extern void tcp_send_partial(struct sock *);
65320 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65321 struct inet6_skb_parm h6;
65322 #endif
65323 } header; /* For incoming frames */
65324 - __u32 seq; /* Starting sequence number */
65325 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65326 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65327 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65328 __u32 when; /* used to compute rtt's */
65329 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65330
65331 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65332
65333 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65334 /* 1 byte hole */
65335 - __u32 ack_seq; /* Sequence number ACK'd */
65336 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65337 };
65338
65339 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65340 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65341 char *name;
65342 sa_family_t family;
65343 const struct file_operations *seq_fops;
65344 - struct seq_operations seq_ops;
65345 + seq_operations_no_const seq_ops;
65346 };
65347
65348 struct tcp_iter_state {
65349 diff --git a/include/net/udp.h b/include/net/udp.h
65350 index 065f379..b661b40 100644
65351 --- a/include/net/udp.h
65352 +++ b/include/net/udp.h
65353 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65354 sa_family_t family;
65355 struct udp_table *udp_table;
65356 const struct file_operations *seq_fops;
65357 - struct seq_operations seq_ops;
65358 + seq_operations_no_const seq_ops;
65359 };
65360
65361 struct udp_iter_state {
65362 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65363 index 639dd13..15b206c 100644
65364 --- a/include/net/xfrm.h
65365 +++ b/include/net/xfrm.h
65366 @@ -514,7 +514,7 @@ struct xfrm_policy {
65367 struct timer_list timer;
65368
65369 struct flow_cache_object flo;
65370 - atomic_t genid;
65371 + atomic_unchecked_t genid;
65372 u32 priority;
65373 u32 index;
65374 struct xfrm_mark mark;
65375 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65376 index 1a046b1..ee0bef0 100644
65377 --- a/include/rdma/iw_cm.h
65378 +++ b/include/rdma/iw_cm.h
65379 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65380 int backlog);
65381
65382 int (*destroy_listen)(struct iw_cm_id *cm_id);
65383 -};
65384 +} __no_const;
65385
65386 /**
65387 * iw_create_cm_id - Create an IW CM identifier.
65388 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65389 index 399162b..b337f1a 100644
65390 --- a/include/scsi/libfc.h
65391 +++ b/include/scsi/libfc.h
65392 @@ -762,6 +762,7 @@ struct libfc_function_template {
65393 */
65394 void (*disc_stop_final) (struct fc_lport *);
65395 };
65396 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65397
65398 /**
65399 * struct fc_disc - Discovery context
65400 @@ -866,7 +867,7 @@ struct fc_lport {
65401 struct fc_vport *vport;
65402
65403 /* Operational Information */
65404 - struct libfc_function_template tt;
65405 + libfc_function_template_no_const tt;
65406 u8 link_up;
65407 u8 qfull;
65408 enum fc_lport_state state;
65409 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65410 index 9895f69..f1418f0 100644
65411 --- a/include/scsi/scsi_device.h
65412 +++ b/include/scsi/scsi_device.h
65413 @@ -166,9 +166,9 @@ struct scsi_device {
65414 unsigned int max_device_blocked; /* what device_blocked counts down from */
65415 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65416
65417 - atomic_t iorequest_cnt;
65418 - atomic_t iodone_cnt;
65419 - atomic_t ioerr_cnt;
65420 + atomic_unchecked_t iorequest_cnt;
65421 + atomic_unchecked_t iodone_cnt;
65422 + atomic_unchecked_t ioerr_cnt;
65423
65424 struct device sdev_gendev,
65425 sdev_dev;
65426 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65427 index b797e8f..8e2c3aa 100644
65428 --- a/include/scsi/scsi_transport_fc.h
65429 +++ b/include/scsi/scsi_transport_fc.h
65430 @@ -751,7 +751,8 @@ struct fc_function_template {
65431 unsigned long show_host_system_hostname:1;
65432
65433 unsigned long disable_target_scan:1;
65434 -};
65435 +} __do_const;
65436 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65437
65438
65439 /**
65440 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65441 index 030b87c..98a6954 100644
65442 --- a/include/sound/ak4xxx-adda.h
65443 +++ b/include/sound/ak4xxx-adda.h
65444 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65445 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65446 unsigned char val);
65447 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65448 -};
65449 +} __no_const;
65450
65451 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65452
65453 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65454 index 8c05e47..2b5df97 100644
65455 --- a/include/sound/hwdep.h
65456 +++ b/include/sound/hwdep.h
65457 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65458 struct snd_hwdep_dsp_status *status);
65459 int (*dsp_load)(struct snd_hwdep *hw,
65460 struct snd_hwdep_dsp_image *image);
65461 -};
65462 +} __no_const;
65463
65464 struct snd_hwdep {
65465 struct snd_card *card;
65466 diff --git a/include/sound/info.h b/include/sound/info.h
65467 index 9ca1a49..aba1728 100644
65468 --- a/include/sound/info.h
65469 +++ b/include/sound/info.h
65470 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65471 struct snd_info_buffer *buffer);
65472 void (*write)(struct snd_info_entry *entry,
65473 struct snd_info_buffer *buffer);
65474 -};
65475 +} __no_const;
65476
65477 struct snd_info_entry_ops {
65478 int (*open)(struct snd_info_entry *entry,
65479 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65480 index cdca2ab..10bbe05 100644
65481 --- a/include/sound/pcm.h
65482 +++ b/include/sound/pcm.h
65483 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65484 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65485 int (*ack)(struct snd_pcm_substream *substream);
65486 };
65487 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65488
65489 /*
65490 *
65491 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65492 index af1b49e..a5d55a5 100644
65493 --- a/include/sound/sb16_csp.h
65494 +++ b/include/sound/sb16_csp.h
65495 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65496 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65497 int (*csp_stop) (struct snd_sb_csp * p);
65498 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65499 -};
65500 +} __no_const;
65501
65502 /*
65503 * CSP private data
65504 diff --git a/include/sound/soc.h b/include/sound/soc.h
65505 index e063380..e8077d5 100644
65506 --- a/include/sound/soc.h
65507 +++ b/include/sound/soc.h
65508 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65509 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65510 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65511 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65512 -};
65513 +} __do_const;
65514
65515 struct snd_soc_platform {
65516 const char *name;
65517 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65518 struct snd_soc_dai_link *dai_link;
65519 struct mutex pcm_mutex;
65520 enum snd_soc_pcm_subclass pcm_subclass;
65521 - struct snd_pcm_ops ops;
65522 + snd_pcm_ops_no_const ops;
65523
65524 unsigned int dev_registered:1;
65525
65526 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65527 index fe8590c..aaed363 100644
65528 --- a/include/sound/tea575x-tuner.h
65529 +++ b/include/sound/tea575x-tuner.h
65530 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65531
65532 struct snd_tea575x {
65533 struct v4l2_device *v4l2_dev;
65534 - struct v4l2_file_operations fops;
65535 + v4l2_file_operations_no_const fops;
65536 struct video_device vd; /* video device */
65537 int radio_nr; /* radio_nr */
65538 bool tea5759; /* 5759 chip is present */
65539 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65540 index 5be8937..a8e46e9 100644
65541 --- a/include/target/target_core_base.h
65542 +++ b/include/target/target_core_base.h
65543 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65544 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65545 int (*t10_pr_register)(struct se_cmd *);
65546 int (*t10_pr_clear)(struct se_cmd *);
65547 -};
65548 +} __no_const;
65549
65550 struct t10_reservation {
65551 /* Reservation effects all target ports */
65552 @@ -758,7 +758,7 @@ struct se_device {
65553 spinlock_t stats_lock;
65554 /* Active commands on this virtual SE device */
65555 atomic_t simple_cmds;
65556 - atomic_t dev_ordered_id;
65557 + atomic_unchecked_t dev_ordered_id;
65558 atomic_t dev_ordered_sync;
65559 atomic_t dev_qf_count;
65560 struct se_obj dev_obj;
65561 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65562 new file mode 100644
65563 index 0000000..2efe49d
65564 --- /dev/null
65565 +++ b/include/trace/events/fs.h
65566 @@ -0,0 +1,53 @@
65567 +#undef TRACE_SYSTEM
65568 +#define TRACE_SYSTEM fs
65569 +
65570 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65571 +#define _TRACE_FS_H
65572 +
65573 +#include <linux/fs.h>
65574 +#include <linux/tracepoint.h>
65575 +
65576 +TRACE_EVENT(do_sys_open,
65577 +
65578 + TP_PROTO(char *filename, int flags, int mode),
65579 +
65580 + TP_ARGS(filename, flags, mode),
65581 +
65582 + TP_STRUCT__entry(
65583 + __string( filename, filename )
65584 + __field( int, flags )
65585 + __field( int, mode )
65586 + ),
65587 +
65588 + TP_fast_assign(
65589 + __assign_str(filename, filename);
65590 + __entry->flags = flags;
65591 + __entry->mode = mode;
65592 + ),
65593 +
65594 + TP_printk("\"%s\" %x %o",
65595 + __get_str(filename), __entry->flags, __entry->mode)
65596 +);
65597 +
65598 +TRACE_EVENT(open_exec,
65599 +
65600 + TP_PROTO(const char *filename),
65601 +
65602 + TP_ARGS(filename),
65603 +
65604 + TP_STRUCT__entry(
65605 + __string( filename, filename )
65606 + ),
65607 +
65608 + TP_fast_assign(
65609 + __assign_str(filename, filename);
65610 + ),
65611 +
65612 + TP_printk("\"%s\"",
65613 + __get_str(filename))
65614 +);
65615 +
65616 +#endif /* _TRACE_FS_H */
65617 +
65618 +/* This part must be outside protection */
65619 +#include <trace/define_trace.h>
65620 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65621 index 1c09820..7f5ec79 100644
65622 --- a/include/trace/events/irq.h
65623 +++ b/include/trace/events/irq.h
65624 @@ -36,7 +36,7 @@ struct softirq_action;
65625 */
65626 TRACE_EVENT(irq_handler_entry,
65627
65628 - TP_PROTO(int irq, struct irqaction *action),
65629 + TP_PROTO(int irq, const struct irqaction *action),
65630
65631 TP_ARGS(irq, action),
65632
65633 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65634 */
65635 TRACE_EVENT(irq_handler_exit,
65636
65637 - TP_PROTO(int irq, struct irqaction *action, int ret),
65638 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65639
65640 TP_ARGS(irq, action, ret),
65641
65642 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65643 index f9466fa..f4e2b81 100644
65644 --- a/include/video/udlfb.h
65645 +++ b/include/video/udlfb.h
65646 @@ -53,10 +53,10 @@ struct dlfb_data {
65647 u32 pseudo_palette[256];
65648 int blank_mode; /*one of FB_BLANK_ */
65649 /* blit-only rendering path metrics, exposed through sysfs */
65650 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65651 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65652 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65653 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65654 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65655 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65656 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65657 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65658 };
65659
65660 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65661 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65662 index 0993a22..32ba2fe 100644
65663 --- a/include/video/uvesafb.h
65664 +++ b/include/video/uvesafb.h
65665 @@ -177,6 +177,7 @@ struct uvesafb_par {
65666 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65667 u8 pmi_setpal; /* PMI for palette changes */
65668 u16 *pmi_base; /* protected mode interface location */
65669 + u8 *pmi_code; /* protected mode code location */
65670 void *pmi_start;
65671 void *pmi_pal;
65672 u8 *vbe_state_orig; /*
65673 diff --git a/init/Kconfig b/init/Kconfig
65674 index af6c7f8..5c188f8 100644
65675 --- a/init/Kconfig
65676 +++ b/init/Kconfig
65677 @@ -850,6 +850,7 @@ endif # CGROUPS
65678
65679 config CHECKPOINT_RESTORE
65680 bool "Checkpoint/restore support" if EXPERT
65681 + depends on !GRKERNSEC
65682 default n
65683 help
65684 Enables additional kernel features in a sake of checkpoint/restore.
65685 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65686 # Security modules
65687 depends on SECURITY_TOMOYO = n
65688 depends on SECURITY_APPARMOR = n
65689 + depends on GRKERNSEC = n
65690
65691 config UIDGID_STRICT_TYPE_CHECKS
65692 bool "Require conversions between uid/gids and their internal representation"
65693 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65694
65695 config COMPAT_BRK
65696 bool "Disable heap randomization"
65697 - default y
65698 + default n
65699 help
65700 Randomizing heap placement makes heap exploits harder, but it
65701 also breaks ancient binaries (including anything libc5 based).
65702 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65703 config STOP_MACHINE
65704 bool
65705 default y
65706 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65707 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65708 help
65709 Need stop_machine() primitive.
65710
65711 diff --git a/init/Makefile b/init/Makefile
65712 index 7bc47ee..6da2dc7 100644
65713 --- a/init/Makefile
65714 +++ b/init/Makefile
65715 @@ -2,6 +2,9 @@
65716 # Makefile for the linux kernel.
65717 #
65718
65719 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65720 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65721 +
65722 obj-y := main.o version.o mounts.o
65723 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65724 obj-y += noinitramfs.o
65725 diff --git a/init/do_mounts.c b/init/do_mounts.c
65726 index d3f0aee..c9322f5 100644
65727 --- a/init/do_mounts.c
65728 +++ b/init/do_mounts.c
65729 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65730 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65731 {
65732 struct super_block *s;
65733 - int err = sys_mount(name, "/root", fs, flags, data);
65734 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65735 if (err)
65736 return err;
65737
65738 - sys_chdir("/root");
65739 + sys_chdir((const char __force_user *)"/root");
65740 s = current->fs->pwd.dentry->d_sb;
65741 ROOT_DEV = s->s_dev;
65742 printk(KERN_INFO
65743 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65744 va_start(args, fmt);
65745 vsprintf(buf, fmt, args);
65746 va_end(args);
65747 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65748 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65749 if (fd >= 0) {
65750 sys_ioctl(fd, FDEJECT, 0);
65751 sys_close(fd);
65752 }
65753 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65754 - fd = sys_open("/dev/console", O_RDWR, 0);
65755 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65756 if (fd >= 0) {
65757 sys_ioctl(fd, TCGETS, (long)&termios);
65758 termios.c_lflag &= ~ICANON;
65759 sys_ioctl(fd, TCSETSF, (long)&termios);
65760 - sys_read(fd, &c, 1);
65761 + sys_read(fd, (char __user *)&c, 1);
65762 termios.c_lflag |= ICANON;
65763 sys_ioctl(fd, TCSETSF, (long)&termios);
65764 sys_close(fd);
65765 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65766 mount_root();
65767 out:
65768 devtmpfs_mount("dev");
65769 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65770 - sys_chroot(".");
65771 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65772 + sys_chroot((const char __force_user *)".");
65773 }
65774 diff --git a/init/do_mounts.h b/init/do_mounts.h
65775 index f5b978a..69dbfe8 100644
65776 --- a/init/do_mounts.h
65777 +++ b/init/do_mounts.h
65778 @@ -15,15 +15,15 @@ extern int root_mountflags;
65779
65780 static inline int create_dev(char *name, dev_t dev)
65781 {
65782 - sys_unlink(name);
65783 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65784 + sys_unlink((char __force_user *)name);
65785 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65786 }
65787
65788 #if BITS_PER_LONG == 32
65789 static inline u32 bstat(char *name)
65790 {
65791 struct stat64 stat;
65792 - if (sys_stat64(name, &stat) != 0)
65793 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65794 return 0;
65795 if (!S_ISBLK(stat.st_mode))
65796 return 0;
65797 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65798 static inline u32 bstat(char *name)
65799 {
65800 struct stat stat;
65801 - if (sys_newstat(name, &stat) != 0)
65802 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65803 return 0;
65804 if (!S_ISBLK(stat.st_mode))
65805 return 0;
65806 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65807 index 135959a2..28a3f43 100644
65808 --- a/init/do_mounts_initrd.c
65809 +++ b/init/do_mounts_initrd.c
65810 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65811 create_dev("/dev/root.old", Root_RAM0);
65812 /* mount initrd on rootfs' /root */
65813 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65814 - sys_mkdir("/old", 0700);
65815 - root_fd = sys_open("/", 0, 0);
65816 - old_fd = sys_open("/old", 0, 0);
65817 + sys_mkdir((const char __force_user *)"/old", 0700);
65818 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65819 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65820 /* move initrd over / and chdir/chroot in initrd root */
65821 - sys_chdir("/root");
65822 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65823 - sys_chroot(".");
65824 + sys_chdir((const char __force_user *)"/root");
65825 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65826 + sys_chroot((const char __force_user *)".");
65827
65828 /*
65829 * In case that a resume from disk is carried out by linuxrc or one of
65830 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65831
65832 /* move initrd to rootfs' /old */
65833 sys_fchdir(old_fd);
65834 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65835 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65836 /* switch root and cwd back to / of rootfs */
65837 sys_fchdir(root_fd);
65838 - sys_chroot(".");
65839 + sys_chroot((const char __force_user *)".");
65840 sys_close(old_fd);
65841 sys_close(root_fd);
65842
65843 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65844 - sys_chdir("/old");
65845 + sys_chdir((const char __force_user *)"/old");
65846 return;
65847 }
65848
65849 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65850 mount_root();
65851
65852 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65853 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65854 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65855 if (!error)
65856 printk("okay\n");
65857 else {
65858 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65859 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65860 if (error == -ENOENT)
65861 printk("/initrd does not exist. Ignored.\n");
65862 else
65863 printk("failed\n");
65864 printk(KERN_NOTICE "Unmounting old root\n");
65865 - sys_umount("/old", MNT_DETACH);
65866 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65867 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65868 if (fd < 0) {
65869 error = fd;
65870 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65871 * mounted in the normal path.
65872 */
65873 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65874 - sys_unlink("/initrd.image");
65875 + sys_unlink((const char __force_user *)"/initrd.image");
65876 handle_initrd();
65877 return 1;
65878 }
65879 }
65880 - sys_unlink("/initrd.image");
65881 + sys_unlink((const char __force_user *)"/initrd.image");
65882 return 0;
65883 }
65884 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65885 index 8cb6db5..d729f50 100644
65886 --- a/init/do_mounts_md.c
65887 +++ b/init/do_mounts_md.c
65888 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65889 partitioned ? "_d" : "", minor,
65890 md_setup_args[ent].device_names);
65891
65892 - fd = sys_open(name, 0, 0);
65893 + fd = sys_open((char __force_user *)name, 0, 0);
65894 if (fd < 0) {
65895 printk(KERN_ERR "md: open failed - cannot start "
65896 "array %s\n", name);
65897 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65898 * array without it
65899 */
65900 sys_close(fd);
65901 - fd = sys_open(name, 0, 0);
65902 + fd = sys_open((char __force_user *)name, 0, 0);
65903 sys_ioctl(fd, BLKRRPART, 0);
65904 }
65905 sys_close(fd);
65906 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65907
65908 wait_for_device_probe();
65909
65910 - fd = sys_open("/dev/md0", 0, 0);
65911 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65912 if (fd >= 0) {
65913 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65914 sys_close(fd);
65915 diff --git a/init/init_task.c b/init/init_task.c
65916 index 8b2f399..f0797c9 100644
65917 --- a/init/init_task.c
65918 +++ b/init/init_task.c
65919 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65920 * Initial thread structure. Alignment of this is handled by a special
65921 * linker map entry.
65922 */
65923 +#ifdef CONFIG_X86
65924 +union thread_union init_thread_union __init_task_data;
65925 +#else
65926 union thread_union init_thread_union __init_task_data =
65927 { INIT_THREAD_INFO(init_task) };
65928 +#endif
65929 diff --git a/init/initramfs.c b/init/initramfs.c
65930 index 84c6bf1..8899338 100644
65931 --- a/init/initramfs.c
65932 +++ b/init/initramfs.c
65933 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65934 }
65935 }
65936
65937 -static long __init do_utime(char *filename, time_t mtime)
65938 +static long __init do_utime(char __force_user *filename, time_t mtime)
65939 {
65940 struct timespec t[2];
65941
65942 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65943 struct dir_entry *de, *tmp;
65944 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65945 list_del(&de->list);
65946 - do_utime(de->name, de->mtime);
65947 + do_utime((char __force_user *)de->name, de->mtime);
65948 kfree(de->name);
65949 kfree(de);
65950 }
65951 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65952 if (nlink >= 2) {
65953 char *old = find_link(major, minor, ino, mode, collected);
65954 if (old)
65955 - return (sys_link(old, collected) < 0) ? -1 : 1;
65956 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65957 }
65958 return 0;
65959 }
65960 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65961 {
65962 struct stat st;
65963
65964 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65965 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65966 if (S_ISDIR(st.st_mode))
65967 - sys_rmdir(path);
65968 + sys_rmdir((char __force_user *)path);
65969 else
65970 - sys_unlink(path);
65971 + sys_unlink((char __force_user *)path);
65972 }
65973 }
65974
65975 @@ -315,7 +315,7 @@ static int __init do_name(void)
65976 int openflags = O_WRONLY|O_CREAT;
65977 if (ml != 1)
65978 openflags |= O_TRUNC;
65979 - wfd = sys_open(collected, openflags, mode);
65980 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65981
65982 if (wfd >= 0) {
65983 sys_fchown(wfd, uid, gid);
65984 @@ -327,17 +327,17 @@ static int __init do_name(void)
65985 }
65986 }
65987 } else if (S_ISDIR(mode)) {
65988 - sys_mkdir(collected, mode);
65989 - sys_chown(collected, uid, gid);
65990 - sys_chmod(collected, mode);
65991 + sys_mkdir((char __force_user *)collected, mode);
65992 + sys_chown((char __force_user *)collected, uid, gid);
65993 + sys_chmod((char __force_user *)collected, mode);
65994 dir_add(collected, mtime);
65995 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65996 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65997 if (maybe_link() == 0) {
65998 - sys_mknod(collected, mode, rdev);
65999 - sys_chown(collected, uid, gid);
66000 - sys_chmod(collected, mode);
66001 - do_utime(collected, mtime);
66002 + sys_mknod((char __force_user *)collected, mode, rdev);
66003 + sys_chown((char __force_user *)collected, uid, gid);
66004 + sys_chmod((char __force_user *)collected, mode);
66005 + do_utime((char __force_user *)collected, mtime);
66006 }
66007 }
66008 return 0;
66009 @@ -346,15 +346,15 @@ static int __init do_name(void)
66010 static int __init do_copy(void)
66011 {
66012 if (count >= body_len) {
66013 - sys_write(wfd, victim, body_len);
66014 + sys_write(wfd, (char __force_user *)victim, body_len);
66015 sys_close(wfd);
66016 - do_utime(vcollected, mtime);
66017 + do_utime((char __force_user *)vcollected, mtime);
66018 kfree(vcollected);
66019 eat(body_len);
66020 state = SkipIt;
66021 return 0;
66022 } else {
66023 - sys_write(wfd, victim, count);
66024 + sys_write(wfd, (char __force_user *)victim, count);
66025 body_len -= count;
66026 eat(count);
66027 return 1;
66028 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66029 {
66030 collected[N_ALIGN(name_len) + body_len] = '\0';
66031 clean_path(collected, 0);
66032 - sys_symlink(collected + N_ALIGN(name_len), collected);
66033 - sys_lchown(collected, uid, gid);
66034 - do_utime(collected, mtime);
66035 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66036 + sys_lchown((char __force_user *)collected, uid, gid);
66037 + do_utime((char __force_user *)collected, mtime);
66038 state = SkipIt;
66039 next_state = Reset;
66040 return 0;
66041 diff --git a/init/main.c b/init/main.c
66042 index b286730..9ff6135 100644
66043 --- a/init/main.c
66044 +++ b/init/main.c
66045 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66046 extern void tc_init(void);
66047 #endif
66048
66049 +extern void grsecurity_init(void);
66050 +
66051 /*
66052 * Debug helper: via this flag we know that we are in 'early bootup code'
66053 * where only the boot processor is running with IRQ disabled. This means
66054 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66055
66056 __setup("reset_devices", set_reset_devices);
66057
66058 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66059 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66060 +static int __init setup_grsec_proc_gid(char *str)
66061 +{
66062 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66063 + return 1;
66064 +}
66065 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66066 +#endif
66067 +
66068 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66069 +extern char pax_enter_kernel_user[];
66070 +extern char pax_exit_kernel_user[];
66071 +extern pgdval_t clone_pgd_mask;
66072 +#endif
66073 +
66074 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66075 +static int __init setup_pax_nouderef(char *str)
66076 +{
66077 +#ifdef CONFIG_X86_32
66078 + unsigned int cpu;
66079 + struct desc_struct *gdt;
66080 +
66081 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66082 + gdt = get_cpu_gdt_table(cpu);
66083 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66084 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66085 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66086 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66087 + }
66088 + loadsegment(ds, __KERNEL_DS);
66089 + loadsegment(es, __KERNEL_DS);
66090 + loadsegment(ss, __KERNEL_DS);
66091 +#else
66092 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66093 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66094 + clone_pgd_mask = ~(pgdval_t)0UL;
66095 +#endif
66096 +
66097 + return 0;
66098 +}
66099 +early_param("pax_nouderef", setup_pax_nouderef);
66100 +#endif
66101 +
66102 +#ifdef CONFIG_PAX_SOFTMODE
66103 +int pax_softmode;
66104 +
66105 +static int __init setup_pax_softmode(char *str)
66106 +{
66107 + get_option(&str, &pax_softmode);
66108 + return 1;
66109 +}
66110 +__setup("pax_softmode=", setup_pax_softmode);
66111 +#endif
66112 +
66113 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66114 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66115 static const char *panic_later, *panic_param;
66116 @@ -675,6 +732,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66117 {
66118 int count = preempt_count();
66119 int ret;
66120 + const char *msg1 = "", *msg2 = "";
66121
66122 if (initcall_debug)
66123 ret = do_one_initcall_debug(fn);
66124 @@ -687,15 +745,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66125 sprintf(msgbuf, "error code %d ", ret);
66126
66127 if (preempt_count() != count) {
66128 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66129 + msg1 = " preemption imbalance";
66130 preempt_count() = count;
66131 }
66132 if (irqs_disabled()) {
66133 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66134 + msg2 = " disabled interrupts";
66135 local_irq_enable();
66136 }
66137 - if (msgbuf[0]) {
66138 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66139 + if (msgbuf[0] || *msg1 || *msg2) {
66140 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66141 }
66142
66143 return ret;
66144 @@ -749,8 +807,14 @@ static void __init do_initcall_level(int level)
66145 level, level,
66146 &repair_env_string);
66147
66148 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66149 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66150 do_one_initcall(*fn);
66151 +
66152 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66153 + transfer_latent_entropy();
66154 +#endif
66155 +
66156 + }
66157 }
66158
66159 static void __init do_initcalls(void)
66160 @@ -784,8 +848,14 @@ static void __init do_pre_smp_initcalls(void)
66161 {
66162 initcall_t *fn;
66163
66164 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66165 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66166 do_one_initcall(*fn);
66167 +
66168 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66169 + transfer_latent_entropy();
66170 +#endif
66171 +
66172 + }
66173 }
66174
66175 static void run_init_process(const char *init_filename)
66176 @@ -867,7 +937,7 @@ static int __init kernel_init(void * unused)
66177 do_basic_setup();
66178
66179 /* Open the /dev/console on the rootfs, this should never fail */
66180 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66181 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66182 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66183
66184 (void) sys_dup(0);
66185 @@ -880,11 +950,13 @@ static int __init kernel_init(void * unused)
66186 if (!ramdisk_execute_command)
66187 ramdisk_execute_command = "/init";
66188
66189 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66190 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66191 ramdisk_execute_command = NULL;
66192 prepare_namespace();
66193 }
66194
66195 + grsecurity_init();
66196 +
66197 /*
66198 * Ok, we have completed the initial bootup, and
66199 * we're essentially up and running. Get rid of the
66200 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66201 index 9a08acc..e65ebe7 100644
66202 --- a/ipc/mqueue.c
66203 +++ b/ipc/mqueue.c
66204 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66205 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66206 info->attr.mq_msgsize);
66207
66208 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66209 spin_lock(&mq_lock);
66210 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66211 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66212 diff --git a/ipc/msg.c b/ipc/msg.c
66213 index 7385de2..a8180e08 100644
66214 --- a/ipc/msg.c
66215 +++ b/ipc/msg.c
66216 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66217 return security_msg_queue_associate(msq, msgflg);
66218 }
66219
66220 +static struct ipc_ops msg_ops = {
66221 + .getnew = newque,
66222 + .associate = msg_security,
66223 + .more_checks = NULL
66224 +};
66225 +
66226 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66227 {
66228 struct ipc_namespace *ns;
66229 - struct ipc_ops msg_ops;
66230 struct ipc_params msg_params;
66231
66232 ns = current->nsproxy->ipc_ns;
66233
66234 - msg_ops.getnew = newque;
66235 - msg_ops.associate = msg_security;
66236 - msg_ops.more_checks = NULL;
66237 -
66238 msg_params.key = key;
66239 msg_params.flg = msgflg;
66240
66241 diff --git a/ipc/sem.c b/ipc/sem.c
66242 index 5215a81..cfc0cac 100644
66243 --- a/ipc/sem.c
66244 +++ b/ipc/sem.c
66245 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66246 return 0;
66247 }
66248
66249 +static struct ipc_ops sem_ops = {
66250 + .getnew = newary,
66251 + .associate = sem_security,
66252 + .more_checks = sem_more_checks
66253 +};
66254 +
66255 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66256 {
66257 struct ipc_namespace *ns;
66258 - struct ipc_ops sem_ops;
66259 struct ipc_params sem_params;
66260
66261 ns = current->nsproxy->ipc_ns;
66262 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66263 if (nsems < 0 || nsems > ns->sc_semmsl)
66264 return -EINVAL;
66265
66266 - sem_ops.getnew = newary;
66267 - sem_ops.associate = sem_security;
66268 - sem_ops.more_checks = sem_more_checks;
66269 -
66270 sem_params.key = key;
66271 sem_params.flg = semflg;
66272 sem_params.u.nsems = nsems;
66273 diff --git a/ipc/shm.c b/ipc/shm.c
66274 index 00faa05..7040960 100644
66275 --- a/ipc/shm.c
66276 +++ b/ipc/shm.c
66277 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66278 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66279 #endif
66280
66281 +#ifdef CONFIG_GRKERNSEC
66282 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66283 + const time_t shm_createtime, const uid_t cuid,
66284 + const int shmid);
66285 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66286 + const time_t shm_createtime);
66287 +#endif
66288 +
66289 void shm_init_ns(struct ipc_namespace *ns)
66290 {
66291 ns->shm_ctlmax = SHMMAX;
66292 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66293 shp->shm_lprid = 0;
66294 shp->shm_atim = shp->shm_dtim = 0;
66295 shp->shm_ctim = get_seconds();
66296 +#ifdef CONFIG_GRKERNSEC
66297 + {
66298 + struct timespec timeval;
66299 + do_posix_clock_monotonic_gettime(&timeval);
66300 +
66301 + shp->shm_createtime = timeval.tv_sec;
66302 + }
66303 +#endif
66304 shp->shm_segsz = size;
66305 shp->shm_nattch = 0;
66306 shp->shm_file = file;
66307 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66308 return 0;
66309 }
66310
66311 +static struct ipc_ops shm_ops = {
66312 + .getnew = newseg,
66313 + .associate = shm_security,
66314 + .more_checks = shm_more_checks
66315 +};
66316 +
66317 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66318 {
66319 struct ipc_namespace *ns;
66320 - struct ipc_ops shm_ops;
66321 struct ipc_params shm_params;
66322
66323 ns = current->nsproxy->ipc_ns;
66324
66325 - shm_ops.getnew = newseg;
66326 - shm_ops.associate = shm_security;
66327 - shm_ops.more_checks = shm_more_checks;
66328 -
66329 shm_params.key = key;
66330 shm_params.flg = shmflg;
66331 shm_params.u.size = size;
66332 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66333 f_mode = FMODE_READ | FMODE_WRITE;
66334 }
66335 if (shmflg & SHM_EXEC) {
66336 +
66337 +#ifdef CONFIG_PAX_MPROTECT
66338 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66339 + goto out;
66340 +#endif
66341 +
66342 prot |= PROT_EXEC;
66343 acc_mode |= S_IXUGO;
66344 }
66345 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66346 if (err)
66347 goto out_unlock;
66348
66349 +#ifdef CONFIG_GRKERNSEC
66350 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66351 + shp->shm_perm.cuid, shmid) ||
66352 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66353 + err = -EACCES;
66354 + goto out_unlock;
66355 + }
66356 +#endif
66357 +
66358 path = shp->shm_file->f_path;
66359 path_get(&path);
66360 shp->shm_nattch++;
66361 +#ifdef CONFIG_GRKERNSEC
66362 + shp->shm_lapid = current->pid;
66363 +#endif
66364 size = i_size_read(path.dentry->d_inode);
66365 shm_unlock(shp);
66366
66367 diff --git a/kernel/acct.c b/kernel/acct.c
66368 index 02e6167..54824f7 100644
66369 --- a/kernel/acct.c
66370 +++ b/kernel/acct.c
66371 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66372 */
66373 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66374 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66375 - file->f_op->write(file, (char *)&ac,
66376 + file->f_op->write(file, (char __force_user *)&ac,
66377 sizeof(acct_t), &file->f_pos);
66378 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66379 set_fs(fs);
66380 diff --git a/kernel/audit.c b/kernel/audit.c
66381 index a8c84be..8bd034c 100644
66382 --- a/kernel/audit.c
66383 +++ b/kernel/audit.c
66384 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66385 3) suppressed due to audit_rate_limit
66386 4) suppressed due to audit_backlog_limit
66387 */
66388 -static atomic_t audit_lost = ATOMIC_INIT(0);
66389 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66390
66391 /* The netlink socket. */
66392 static struct sock *audit_sock;
66393 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66394 unsigned long now;
66395 int print;
66396
66397 - atomic_inc(&audit_lost);
66398 + atomic_inc_unchecked(&audit_lost);
66399
66400 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66401
66402 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66403 printk(KERN_WARNING
66404 "audit: audit_lost=%d audit_rate_limit=%d "
66405 "audit_backlog_limit=%d\n",
66406 - atomic_read(&audit_lost),
66407 + atomic_read_unchecked(&audit_lost),
66408 audit_rate_limit,
66409 audit_backlog_limit);
66410 audit_panic(message);
66411 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66412 status_set.pid = audit_pid;
66413 status_set.rate_limit = audit_rate_limit;
66414 status_set.backlog_limit = audit_backlog_limit;
66415 - status_set.lost = atomic_read(&audit_lost);
66416 + status_set.lost = atomic_read_unchecked(&audit_lost);
66417 status_set.backlog = skb_queue_len(&audit_skb_queue);
66418 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66419 &status_set, sizeof(status_set));
66420 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66421 index 4b96415..d8c16ee 100644
66422 --- a/kernel/auditsc.c
66423 +++ b/kernel/auditsc.c
66424 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66425 }
66426
66427 /* global counter which is incremented every time something logs in */
66428 -static atomic_t session_id = ATOMIC_INIT(0);
66429 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66430
66431 /**
66432 * audit_set_loginuid - set current task's audit_context loginuid
66433 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66434 return -EPERM;
66435 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66436
66437 - sessionid = atomic_inc_return(&session_id);
66438 + sessionid = atomic_inc_return_unchecked(&session_id);
66439 if (context && context->in_syscall) {
66440 struct audit_buffer *ab;
66441
66442 diff --git a/kernel/capability.c b/kernel/capability.c
66443 index 493d972..ea17248 100644
66444 --- a/kernel/capability.c
66445 +++ b/kernel/capability.c
66446 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66447 * before modification is attempted and the application
66448 * fails.
66449 */
66450 + if (tocopy > ARRAY_SIZE(kdata))
66451 + return -EFAULT;
66452 +
66453 if (copy_to_user(dataptr, kdata, tocopy
66454 * sizeof(struct __user_cap_data_struct))) {
66455 return -EFAULT;
66456 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66457 int ret;
66458
66459 rcu_read_lock();
66460 - ret = security_capable(__task_cred(t), ns, cap);
66461 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66462 + gr_task_is_capable(t, __task_cred(t), cap);
66463 rcu_read_unlock();
66464
66465 - return (ret == 0);
66466 + return ret;
66467 }
66468
66469 /**
66470 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66471 int ret;
66472
66473 rcu_read_lock();
66474 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66475 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66476 rcu_read_unlock();
66477
66478 - return (ret == 0);
66479 + return ret;
66480 }
66481
66482 /**
66483 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66484 BUG();
66485 }
66486
66487 - if (security_capable(current_cred(), ns, cap) == 0) {
66488 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66489 current->flags |= PF_SUPERPRIV;
66490 return true;
66491 }
66492 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66493 }
66494 EXPORT_SYMBOL(ns_capable);
66495
66496 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66497 +{
66498 + if (unlikely(!cap_valid(cap))) {
66499 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66500 + BUG();
66501 + }
66502 +
66503 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66504 + current->flags |= PF_SUPERPRIV;
66505 + return true;
66506 + }
66507 + return false;
66508 +}
66509 +EXPORT_SYMBOL(ns_capable_nolog);
66510 +
66511 /**
66512 * capable - Determine if the current task has a superior capability in effect
66513 * @cap: The capability to be tested for
66514 @@ -408,6 +427,12 @@ bool capable(int cap)
66515 }
66516 EXPORT_SYMBOL(capable);
66517
66518 +bool capable_nolog(int cap)
66519 +{
66520 + return ns_capable_nolog(&init_user_ns, cap);
66521 +}
66522 +EXPORT_SYMBOL(capable_nolog);
66523 +
66524 /**
66525 * nsown_capable - Check superior capability to one's own user_ns
66526 * @cap: The capability in question
66527 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66528
66529 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66530 }
66531 +
66532 +bool inode_capable_nolog(const struct inode *inode, int cap)
66533 +{
66534 + struct user_namespace *ns = current_user_ns();
66535 +
66536 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66537 +}
66538 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66539 index ff2bce5..a41e8f9 100644
66540 --- a/kernel/cgroup.c
66541 +++ b/kernel/cgroup.c
66542 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66543 struct css_set *cg = link->cg;
66544 struct task_struct *task;
66545 int count = 0;
66546 - seq_printf(seq, "css_set %p\n", cg);
66547 + seq_printf(seq, "css_set %pK\n", cg);
66548 list_for_each_entry(task, &cg->tasks, cg_list) {
66549 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66550 seq_puts(seq, " ...\n");
66551 diff --git a/kernel/compat.c b/kernel/compat.c
66552 index c28a306..b4d0cf3 100644
66553 --- a/kernel/compat.c
66554 +++ b/kernel/compat.c
66555 @@ -13,6 +13,7 @@
66556
66557 #include <linux/linkage.h>
66558 #include <linux/compat.h>
66559 +#include <linux/module.h>
66560 #include <linux/errno.h>
66561 #include <linux/time.h>
66562 #include <linux/signal.h>
66563 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66564 mm_segment_t oldfs;
66565 long ret;
66566
66567 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66568 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66569 oldfs = get_fs();
66570 set_fs(KERNEL_DS);
66571 ret = hrtimer_nanosleep_restart(restart);
66572 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66573 oldfs = get_fs();
66574 set_fs(KERNEL_DS);
66575 ret = hrtimer_nanosleep(&tu,
66576 - rmtp ? (struct timespec __user *)&rmt : NULL,
66577 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66578 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66579 set_fs(oldfs);
66580
66581 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66582 mm_segment_t old_fs = get_fs();
66583
66584 set_fs(KERNEL_DS);
66585 - ret = sys_sigpending((old_sigset_t __user *) &s);
66586 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66587 set_fs(old_fs);
66588 if (ret == 0)
66589 ret = put_user(s, set);
66590 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66591 mm_segment_t old_fs = get_fs();
66592
66593 set_fs(KERNEL_DS);
66594 - ret = sys_old_getrlimit(resource, &r);
66595 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66596 set_fs(old_fs);
66597
66598 if (!ret) {
66599 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66600 mm_segment_t old_fs = get_fs();
66601
66602 set_fs(KERNEL_DS);
66603 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66604 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66605 set_fs(old_fs);
66606
66607 if (ret)
66608 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66609 set_fs (KERNEL_DS);
66610 ret = sys_wait4(pid,
66611 (stat_addr ?
66612 - (unsigned int __user *) &status : NULL),
66613 - options, (struct rusage __user *) &r);
66614 + (unsigned int __force_user *) &status : NULL),
66615 + options, (struct rusage __force_user *) &r);
66616 set_fs (old_fs);
66617
66618 if (ret > 0) {
66619 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66620 memset(&info, 0, sizeof(info));
66621
66622 set_fs(KERNEL_DS);
66623 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66624 - uru ? (struct rusage __user *)&ru : NULL);
66625 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66626 + uru ? (struct rusage __force_user *)&ru : NULL);
66627 set_fs(old_fs);
66628
66629 if ((ret < 0) || (info.si_signo == 0))
66630 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66631 oldfs = get_fs();
66632 set_fs(KERNEL_DS);
66633 err = sys_timer_settime(timer_id, flags,
66634 - (struct itimerspec __user *) &newts,
66635 - (struct itimerspec __user *) &oldts);
66636 + (struct itimerspec __force_user *) &newts,
66637 + (struct itimerspec __force_user *) &oldts);
66638 set_fs(oldfs);
66639 if (!err && old && put_compat_itimerspec(old, &oldts))
66640 return -EFAULT;
66641 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66642 oldfs = get_fs();
66643 set_fs(KERNEL_DS);
66644 err = sys_timer_gettime(timer_id,
66645 - (struct itimerspec __user *) &ts);
66646 + (struct itimerspec __force_user *) &ts);
66647 set_fs(oldfs);
66648 if (!err && put_compat_itimerspec(setting, &ts))
66649 return -EFAULT;
66650 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66651 oldfs = get_fs();
66652 set_fs(KERNEL_DS);
66653 err = sys_clock_settime(which_clock,
66654 - (struct timespec __user *) &ts);
66655 + (struct timespec __force_user *) &ts);
66656 set_fs(oldfs);
66657 return err;
66658 }
66659 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66660 oldfs = get_fs();
66661 set_fs(KERNEL_DS);
66662 err = sys_clock_gettime(which_clock,
66663 - (struct timespec __user *) &ts);
66664 + (struct timespec __force_user *) &ts);
66665 set_fs(oldfs);
66666 if (!err && put_compat_timespec(&ts, tp))
66667 return -EFAULT;
66668 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66669
66670 oldfs = get_fs();
66671 set_fs(KERNEL_DS);
66672 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66673 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66674 set_fs(oldfs);
66675
66676 err = compat_put_timex(utp, &txc);
66677 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66678 oldfs = get_fs();
66679 set_fs(KERNEL_DS);
66680 err = sys_clock_getres(which_clock,
66681 - (struct timespec __user *) &ts);
66682 + (struct timespec __force_user *) &ts);
66683 set_fs(oldfs);
66684 if (!err && tp && put_compat_timespec(&ts, tp))
66685 return -EFAULT;
66686 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66687 long err;
66688 mm_segment_t oldfs;
66689 struct timespec tu;
66690 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66691 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66692
66693 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66694 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66695 oldfs = get_fs();
66696 set_fs(KERNEL_DS);
66697 err = clock_nanosleep_restart(restart);
66698 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66699 oldfs = get_fs();
66700 set_fs(KERNEL_DS);
66701 err = sys_clock_nanosleep(which_clock, flags,
66702 - (struct timespec __user *) &in,
66703 - (struct timespec __user *) &out);
66704 + (struct timespec __force_user *) &in,
66705 + (struct timespec __force_user *) &out);
66706 set_fs(oldfs);
66707
66708 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66709 diff --git a/kernel/configs.c b/kernel/configs.c
66710 index 42e8fa0..9e7406b 100644
66711 --- a/kernel/configs.c
66712 +++ b/kernel/configs.c
66713 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66714 struct proc_dir_entry *entry;
66715
66716 /* create the current config file */
66717 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66718 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66719 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66720 + &ikconfig_file_ops);
66721 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66722 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66723 + &ikconfig_file_ops);
66724 +#endif
66725 +#else
66726 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66727 &ikconfig_file_ops);
66728 +#endif
66729 +
66730 if (!entry)
66731 return -ENOMEM;
66732
66733 diff --git a/kernel/cred.c b/kernel/cred.c
66734 index de728ac..e3c267c 100644
66735 --- a/kernel/cred.c
66736 +++ b/kernel/cred.c
66737 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66738 validate_creds(cred);
66739 alter_cred_subscribers(cred, -1);
66740 put_cred(cred);
66741 +
66742 +#ifdef CONFIG_GRKERNSEC_SETXID
66743 + cred = (struct cred *) tsk->delayed_cred;
66744 + if (cred != NULL) {
66745 + tsk->delayed_cred = NULL;
66746 + validate_creds(cred);
66747 + alter_cred_subscribers(cred, -1);
66748 + put_cred(cred);
66749 + }
66750 +#endif
66751 }
66752
66753 /**
66754 @@ -469,7 +479,7 @@ error_put:
66755 * Always returns 0 thus allowing this function to be tail-called at the end
66756 * of, say, sys_setgid().
66757 */
66758 -int commit_creds(struct cred *new)
66759 +static int __commit_creds(struct cred *new)
66760 {
66761 struct task_struct *task = current;
66762 const struct cred *old = task->real_cred;
66763 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66764
66765 get_cred(new); /* we will require a ref for the subj creds too */
66766
66767 + gr_set_role_label(task, new->uid, new->gid);
66768 +
66769 /* dumpability changes */
66770 if (!uid_eq(old->euid, new->euid) ||
66771 !gid_eq(old->egid, new->egid) ||
66772 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66773 put_cred(old);
66774 return 0;
66775 }
66776 +#ifdef CONFIG_GRKERNSEC_SETXID
66777 +extern int set_user(struct cred *new);
66778 +
66779 +void gr_delayed_cred_worker(void)
66780 +{
66781 + const struct cred *new = current->delayed_cred;
66782 + struct cred *ncred;
66783 +
66784 + current->delayed_cred = NULL;
66785 +
66786 + if (current_uid() && new != NULL) {
66787 + // from doing get_cred on it when queueing this
66788 + put_cred(new);
66789 + return;
66790 + } else if (new == NULL)
66791 + return;
66792 +
66793 + ncred = prepare_creds();
66794 + if (!ncred)
66795 + goto die;
66796 + // uids
66797 + ncred->uid = new->uid;
66798 + ncred->euid = new->euid;
66799 + ncred->suid = new->suid;
66800 + ncred->fsuid = new->fsuid;
66801 + // gids
66802 + ncred->gid = new->gid;
66803 + ncred->egid = new->egid;
66804 + ncred->sgid = new->sgid;
66805 + ncred->fsgid = new->fsgid;
66806 + // groups
66807 + if (set_groups(ncred, new->group_info) < 0) {
66808 + abort_creds(ncred);
66809 + goto die;
66810 + }
66811 + // caps
66812 + ncred->securebits = new->securebits;
66813 + ncred->cap_inheritable = new->cap_inheritable;
66814 + ncred->cap_permitted = new->cap_permitted;
66815 + ncred->cap_effective = new->cap_effective;
66816 + ncred->cap_bset = new->cap_bset;
66817 +
66818 + if (set_user(ncred)) {
66819 + abort_creds(ncred);
66820 + goto die;
66821 + }
66822 +
66823 + // from doing get_cred on it when queueing this
66824 + put_cred(new);
66825 +
66826 + __commit_creds(ncred);
66827 + return;
66828 +die:
66829 + // from doing get_cred on it when queueing this
66830 + put_cred(new);
66831 + do_group_exit(SIGKILL);
66832 +}
66833 +#endif
66834 +
66835 +int commit_creds(struct cred *new)
66836 +{
66837 +#ifdef CONFIG_GRKERNSEC_SETXID
66838 + int ret;
66839 + int schedule_it = 0;
66840 + struct task_struct *t;
66841 +
66842 + /* we won't get called with tasklist_lock held for writing
66843 + and interrupts disabled as the cred struct in that case is
66844 + init_cred
66845 + */
66846 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66847 + !current_uid() && new->uid) {
66848 + schedule_it = 1;
66849 + }
66850 + ret = __commit_creds(new);
66851 + if (schedule_it) {
66852 + rcu_read_lock();
66853 + read_lock(&tasklist_lock);
66854 + for (t = next_thread(current); t != current;
66855 + t = next_thread(t)) {
66856 + if (t->delayed_cred == NULL) {
66857 + t->delayed_cred = get_cred(new);
66858 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66859 + set_tsk_need_resched(t);
66860 + }
66861 + }
66862 + read_unlock(&tasklist_lock);
66863 + rcu_read_unlock();
66864 + }
66865 + return ret;
66866 +#else
66867 + return __commit_creds(new);
66868 +#endif
66869 +}
66870 +
66871 EXPORT_SYMBOL(commit_creds);
66872
66873 /**
66874 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66875 index 0557f24..1a00d9a 100644
66876 --- a/kernel/debug/debug_core.c
66877 +++ b/kernel/debug/debug_core.c
66878 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66879 */
66880 static atomic_t masters_in_kgdb;
66881 static atomic_t slaves_in_kgdb;
66882 -static atomic_t kgdb_break_tasklet_var;
66883 +static atomic_unchecked_t kgdb_break_tasklet_var;
66884 atomic_t kgdb_setting_breakpoint;
66885
66886 struct task_struct *kgdb_usethread;
66887 @@ -132,7 +132,7 @@ int kgdb_single_step;
66888 static pid_t kgdb_sstep_pid;
66889
66890 /* to keep track of the CPU which is doing the single stepping*/
66891 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66892 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66893
66894 /*
66895 * If you are debugging a problem where roundup (the collection of
66896 @@ -540,7 +540,7 @@ return_normal:
66897 * kernel will only try for the value of sstep_tries before
66898 * giving up and continuing on.
66899 */
66900 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66901 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66902 (kgdb_info[cpu].task &&
66903 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66904 atomic_set(&kgdb_active, -1);
66905 @@ -634,8 +634,8 @@ cpu_master_loop:
66906 }
66907
66908 kgdb_restore:
66909 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66910 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66911 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66912 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66913 if (kgdb_info[sstep_cpu].task)
66914 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66915 else
66916 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66917 static void kgdb_tasklet_bpt(unsigned long ing)
66918 {
66919 kgdb_breakpoint();
66920 - atomic_set(&kgdb_break_tasklet_var, 0);
66921 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66922 }
66923
66924 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66925
66926 void kgdb_schedule_breakpoint(void)
66927 {
66928 - if (atomic_read(&kgdb_break_tasklet_var) ||
66929 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66930 atomic_read(&kgdb_active) != -1 ||
66931 atomic_read(&kgdb_setting_breakpoint))
66932 return;
66933 - atomic_inc(&kgdb_break_tasklet_var);
66934 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66935 tasklet_schedule(&kgdb_tasklet_breakpoint);
66936 }
66937 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66938 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66939 index 31df170..bc98840 100644
66940 --- a/kernel/debug/kdb/kdb_main.c
66941 +++ b/kernel/debug/kdb/kdb_main.c
66942 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
66943 list_for_each_entry(mod, kdb_modules, list) {
66944
66945 kdb_printf("%-20s%8u 0x%p ", mod->name,
66946 - mod->core_size, (void *)mod);
66947 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66948 #ifdef CONFIG_MODULE_UNLOAD
66949 kdb_printf("%4ld ", module_refcount(mod));
66950 #endif
66951 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
66952 kdb_printf(" (Loading)");
66953 else
66954 kdb_printf(" (Live)");
66955 - kdb_printf(" 0x%p", mod->module_core);
66956 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66957
66958 #ifdef CONFIG_MODULE_UNLOAD
66959 {
66960 diff --git a/kernel/events/core.c b/kernel/events/core.c
66961 index 7fee567..8affa2c 100644
66962 --- a/kernel/events/core.c
66963 +++ b/kernel/events/core.c
66964 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66965 return 0;
66966 }
66967
66968 -static atomic64_t perf_event_id;
66969 +static atomic64_unchecked_t perf_event_id;
66970
66971 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66972 enum event_type_t event_type);
66973 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
66974
66975 static inline u64 perf_event_count(struct perf_event *event)
66976 {
66977 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66978 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66979 }
66980
66981 static u64 perf_event_read(struct perf_event *event)
66982 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66983 mutex_lock(&event->child_mutex);
66984 total += perf_event_read(event);
66985 *enabled += event->total_time_enabled +
66986 - atomic64_read(&event->child_total_time_enabled);
66987 + atomic64_read_unchecked(&event->child_total_time_enabled);
66988 *running += event->total_time_running +
66989 - atomic64_read(&event->child_total_time_running);
66990 + atomic64_read_unchecked(&event->child_total_time_running);
66991
66992 list_for_each_entry(child, &event->child_list, child_list) {
66993 total += perf_event_read(child);
66994 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
66995 userpg->offset -= local64_read(&event->hw.prev_count);
66996
66997 userpg->time_enabled = enabled +
66998 - atomic64_read(&event->child_total_time_enabled);
66999 + atomic64_read_unchecked(&event->child_total_time_enabled);
67000
67001 userpg->time_running = running +
67002 - atomic64_read(&event->child_total_time_running);
67003 + atomic64_read_unchecked(&event->child_total_time_running);
67004
67005 arch_perf_update_userpage(userpg, now);
67006
67007 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67008 values[n++] = perf_event_count(event);
67009 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67010 values[n++] = enabled +
67011 - atomic64_read(&event->child_total_time_enabled);
67012 + atomic64_read_unchecked(&event->child_total_time_enabled);
67013 }
67014 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67015 values[n++] = running +
67016 - atomic64_read(&event->child_total_time_running);
67017 + atomic64_read_unchecked(&event->child_total_time_running);
67018 }
67019 if (read_format & PERF_FORMAT_ID)
67020 values[n++] = primary_event_id(event);
67021 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67022 * need to add enough zero bytes after the string to handle
67023 * the 64bit alignment we do later.
67024 */
67025 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67026 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67027 if (!buf) {
67028 name = strncpy(tmp, "//enomem", sizeof(tmp));
67029 goto got_name;
67030 }
67031 - name = d_path(&file->f_path, buf, PATH_MAX);
67032 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67033 if (IS_ERR(name)) {
67034 name = strncpy(tmp, "//toolong", sizeof(tmp));
67035 goto got_name;
67036 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67037 event->parent = parent_event;
67038
67039 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67040 - event->id = atomic64_inc_return(&perf_event_id);
67041 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67042
67043 event->state = PERF_EVENT_STATE_INACTIVE;
67044
67045 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67046 /*
67047 * Add back the child's count to the parent's count:
67048 */
67049 - atomic64_add(child_val, &parent_event->child_count);
67050 - atomic64_add(child_event->total_time_enabled,
67051 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67052 + atomic64_add_unchecked(child_event->total_time_enabled,
67053 &parent_event->child_total_time_enabled);
67054 - atomic64_add(child_event->total_time_running,
67055 + atomic64_add_unchecked(child_event->total_time_running,
67056 &parent_event->child_total_time_running);
67057
67058 /*
67059 diff --git a/kernel/exit.c b/kernel/exit.c
67060 index f65345f9..9c28dab 100644
67061 --- a/kernel/exit.c
67062 +++ b/kernel/exit.c
67063 @@ -59,6 +59,10 @@
67064 #include <asm/pgtable.h>
67065 #include <asm/mmu_context.h>
67066
67067 +#ifdef CONFIG_GRKERNSEC
67068 +extern rwlock_t grsec_exec_file_lock;
67069 +#endif
67070 +
67071 static void exit_mm(struct task_struct * tsk);
67072
67073 static void __unhash_process(struct task_struct *p, bool group_dead)
67074 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67075 struct task_struct *leader;
67076 int zap_leader;
67077 repeat:
67078 +#ifdef CONFIG_NET
67079 + gr_del_task_from_ip_table(p);
67080 +#endif
67081 +
67082 /* don't need to get the RCU readlock here - the process is dead and
67083 * can't be modifying its own credentials. But shut RCU-lockdep up */
67084 rcu_read_lock();
67085 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67086 * know it'll be handled, so that they don't get converted to
67087 * SIGKILL or just silently dropped.
67088 */
67089 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67090 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67091 recalc_sigpending();
67092 spin_unlock_irq(&current->sighand->siglock);
67093 return 0;
67094 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67095 vsnprintf(current->comm, sizeof(current->comm), name, args);
67096 va_end(args);
67097
67098 +#ifdef CONFIG_GRKERNSEC
67099 + write_lock(&grsec_exec_file_lock);
67100 + if (current->exec_file) {
67101 + fput(current->exec_file);
67102 + current->exec_file = NULL;
67103 + }
67104 + write_unlock(&grsec_exec_file_lock);
67105 +#endif
67106 +
67107 + gr_set_kernel_label(current);
67108 +
67109 /*
67110 * If we were started as result of loading a module, close all of the
67111 * user space pages. We don't need them, and if we didn't close them
67112 @@ -907,6 +926,8 @@ void do_exit(long code)
67113 struct task_struct *tsk = current;
67114 int group_dead;
67115
67116 + set_fs(USER_DS);
67117 +
67118 profile_task_exit(tsk);
67119
67120 WARN_ON(blk_needs_flush_plug(tsk));
67121 @@ -923,7 +944,6 @@ void do_exit(long code)
67122 * mm_release()->clear_child_tid() from writing to a user-controlled
67123 * kernel address.
67124 */
67125 - set_fs(USER_DS);
67126
67127 ptrace_event(PTRACE_EVENT_EXIT, code);
67128
67129 @@ -982,6 +1002,9 @@ void do_exit(long code)
67130 tsk->exit_code = code;
67131 taskstats_exit(tsk, group_dead);
67132
67133 + gr_acl_handle_psacct(tsk, code);
67134 + gr_acl_handle_exit();
67135 +
67136 exit_mm(tsk);
67137
67138 if (group_dead)
67139 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67140 * Take down every thread in the group. This is called by fatal signals
67141 * as well as by sys_exit_group (below).
67142 */
67143 -void
67144 +__noreturn void
67145 do_group_exit(int exit_code)
67146 {
67147 struct signal_struct *sig = current->signal;
67148 diff --git a/kernel/fork.c b/kernel/fork.c
67149 index 2c8857e..288c9c7 100644
67150 --- a/kernel/fork.c
67151 +++ b/kernel/fork.c
67152 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67153 *stackend = STACK_END_MAGIC; /* for overflow detection */
67154
67155 #ifdef CONFIG_CC_STACKPROTECTOR
67156 - tsk->stack_canary = get_random_int();
67157 + tsk->stack_canary = pax_get_random_long();
67158 #endif
67159
67160 /*
67161 @@ -343,13 +343,78 @@ free_tsk:
67162 }
67163
67164 #ifdef CONFIG_MMU
67165 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67166 +{
67167 + struct vm_area_struct *tmp;
67168 + unsigned long charge;
67169 + struct mempolicy *pol;
67170 + struct file *file;
67171 +
67172 + charge = 0;
67173 + if (mpnt->vm_flags & VM_ACCOUNT) {
67174 + unsigned long len = vma_pages(mpnt);
67175 +
67176 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67177 + goto fail_nomem;
67178 + charge = len;
67179 + }
67180 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67181 + if (!tmp)
67182 + goto fail_nomem;
67183 + *tmp = *mpnt;
67184 + tmp->vm_mm = mm;
67185 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67186 + pol = mpol_dup(vma_policy(mpnt));
67187 + if (IS_ERR(pol))
67188 + goto fail_nomem_policy;
67189 + vma_set_policy(tmp, pol);
67190 + if (anon_vma_fork(tmp, mpnt))
67191 + goto fail_nomem_anon_vma_fork;
67192 + tmp->vm_flags &= ~VM_LOCKED;
67193 + tmp->vm_next = tmp->vm_prev = NULL;
67194 + tmp->vm_mirror = NULL;
67195 + file = tmp->vm_file;
67196 + if (file) {
67197 + struct inode *inode = file->f_path.dentry->d_inode;
67198 + struct address_space *mapping = file->f_mapping;
67199 +
67200 + get_file(file);
67201 + if (tmp->vm_flags & VM_DENYWRITE)
67202 + atomic_dec(&inode->i_writecount);
67203 + mutex_lock(&mapping->i_mmap_mutex);
67204 + if (tmp->vm_flags & VM_SHARED)
67205 + mapping->i_mmap_writable++;
67206 + flush_dcache_mmap_lock(mapping);
67207 + /* insert tmp into the share list, just after mpnt */
67208 + vma_prio_tree_add(tmp, mpnt);
67209 + flush_dcache_mmap_unlock(mapping);
67210 + mutex_unlock(&mapping->i_mmap_mutex);
67211 + }
67212 +
67213 + /*
67214 + * Clear hugetlb-related page reserves for children. This only
67215 + * affects MAP_PRIVATE mappings. Faults generated by the child
67216 + * are not guaranteed to succeed, even if read-only
67217 + */
67218 + if (is_vm_hugetlb_page(tmp))
67219 + reset_vma_resv_huge_pages(tmp);
67220 +
67221 + return tmp;
67222 +
67223 +fail_nomem_anon_vma_fork:
67224 + mpol_put(pol);
67225 +fail_nomem_policy:
67226 + kmem_cache_free(vm_area_cachep, tmp);
67227 +fail_nomem:
67228 + vm_unacct_memory(charge);
67229 + return NULL;
67230 +}
67231 +
67232 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67233 {
67234 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67235 struct rb_node **rb_link, *rb_parent;
67236 int retval;
67237 - unsigned long charge;
67238 - struct mempolicy *pol;
67239
67240 down_write(&oldmm->mmap_sem);
67241 flush_cache_dup_mm(oldmm);
67242 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67243 mm->locked_vm = 0;
67244 mm->mmap = NULL;
67245 mm->mmap_cache = NULL;
67246 - mm->free_area_cache = oldmm->mmap_base;
67247 - mm->cached_hole_size = ~0UL;
67248 + mm->free_area_cache = oldmm->free_area_cache;
67249 + mm->cached_hole_size = oldmm->cached_hole_size;
67250 mm->map_count = 0;
67251 cpumask_clear(mm_cpumask(mm));
67252 mm->mm_rb = RB_ROOT;
67253 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67254
67255 prev = NULL;
67256 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67257 - struct file *file;
67258 -
67259 if (mpnt->vm_flags & VM_DONTCOPY) {
67260 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67261 -vma_pages(mpnt));
67262 continue;
67263 }
67264 - charge = 0;
67265 - if (mpnt->vm_flags & VM_ACCOUNT) {
67266 - unsigned long len = vma_pages(mpnt);
67267 -
67268 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67269 - goto fail_nomem;
67270 - charge = len;
67271 - }
67272 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67273 - if (!tmp)
67274 - goto fail_nomem;
67275 - *tmp = *mpnt;
67276 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67277 - pol = mpol_dup(vma_policy(mpnt));
67278 - retval = PTR_ERR(pol);
67279 - if (IS_ERR(pol))
67280 - goto fail_nomem_policy;
67281 - vma_set_policy(tmp, pol);
67282 - tmp->vm_mm = mm;
67283 - if (anon_vma_fork(tmp, mpnt))
67284 - goto fail_nomem_anon_vma_fork;
67285 - tmp->vm_flags &= ~VM_LOCKED;
67286 - tmp->vm_next = tmp->vm_prev = NULL;
67287 - file = tmp->vm_file;
67288 - if (file) {
67289 - struct inode *inode = file->f_path.dentry->d_inode;
67290 - struct address_space *mapping = file->f_mapping;
67291 -
67292 - get_file(file);
67293 - if (tmp->vm_flags & VM_DENYWRITE)
67294 - atomic_dec(&inode->i_writecount);
67295 - mutex_lock(&mapping->i_mmap_mutex);
67296 - if (tmp->vm_flags & VM_SHARED)
67297 - mapping->i_mmap_writable++;
67298 - flush_dcache_mmap_lock(mapping);
67299 - /* insert tmp into the share list, just after mpnt */
67300 - vma_prio_tree_add(tmp, mpnt);
67301 - flush_dcache_mmap_unlock(mapping);
67302 - mutex_unlock(&mapping->i_mmap_mutex);
67303 + tmp = dup_vma(mm, oldmm, mpnt);
67304 + if (!tmp) {
67305 + retval = -ENOMEM;
67306 + goto out;
67307 }
67308
67309 /*
67310 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67311 if (retval)
67312 goto out;
67313
67314 - if (file)
67315 + if (tmp->vm_file)
67316 uprobe_mmap(tmp);
67317 }
67318 +
67319 +#ifdef CONFIG_PAX_SEGMEXEC
67320 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67321 + struct vm_area_struct *mpnt_m;
67322 +
67323 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67324 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67325 +
67326 + if (!mpnt->vm_mirror)
67327 + continue;
67328 +
67329 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67330 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67331 + mpnt->vm_mirror = mpnt_m;
67332 + } else {
67333 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67334 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67335 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67336 + mpnt->vm_mirror->vm_mirror = mpnt;
67337 + }
67338 + }
67339 + BUG_ON(mpnt_m);
67340 + }
67341 +#endif
67342 +
67343 /* a new mm has just been created */
67344 arch_dup_mmap(oldmm, mm);
67345 retval = 0;
67346 @@ -466,14 +519,6 @@ out:
67347 flush_tlb_mm(oldmm);
67348 up_write(&oldmm->mmap_sem);
67349 return retval;
67350 -fail_nomem_anon_vma_fork:
67351 - mpol_put(pol);
67352 -fail_nomem_policy:
67353 - kmem_cache_free(vm_area_cachep, tmp);
67354 -fail_nomem:
67355 - retval = -ENOMEM;
67356 - vm_unacct_memory(charge);
67357 - goto out;
67358 }
67359
67360 static inline int mm_alloc_pgd(struct mm_struct *mm)
67361 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67362 return ERR_PTR(err);
67363
67364 mm = get_task_mm(task);
67365 - if (mm && mm != current->mm &&
67366 - !ptrace_may_access(task, mode)) {
67367 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67368 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67369 mmput(mm);
67370 mm = ERR_PTR(-EACCES);
67371 }
67372 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67373 spin_unlock(&fs->lock);
67374 return -EAGAIN;
67375 }
67376 - fs->users++;
67377 + atomic_inc(&fs->users);
67378 spin_unlock(&fs->lock);
67379 return 0;
67380 }
67381 tsk->fs = copy_fs_struct(fs);
67382 if (!tsk->fs)
67383 return -ENOMEM;
67384 + /* Carry through gr_chroot_dentry and is_chrooted instead
67385 + of recomputing it here. Already copied when the task struct
67386 + is duplicated. This allows pivot_root to not be treated as
67387 + a chroot
67388 + */
67389 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67390 +
67391 return 0;
67392 }
67393
67394 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67395 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67396 #endif
67397 retval = -EAGAIN;
67398 +
67399 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67400 +
67401 if (atomic_read(&p->real_cred->user->processes) >=
67402 task_rlimit(p, RLIMIT_NPROC)) {
67403 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67404 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67405 /* Need tasklist lock for parent etc handling! */
67406 write_lock_irq(&tasklist_lock);
67407
67408 + /* synchronizes with gr_set_acls() */
67409 + gr_copy_label(p);
67410 +
67411 /* CLONE_PARENT re-uses the old parent */
67412 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67413 p->real_parent = current->real_parent;
67414 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67415 bad_fork_free:
67416 free_task(p);
67417 fork_out:
67418 + gr_log_forkfail(retval);
67419 +
67420 return ERR_PTR(retval);
67421 }
67422
67423 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67424 if (clone_flags & CLONE_PARENT_SETTID)
67425 put_user(nr, parent_tidptr);
67426
67427 + gr_handle_brute_check();
67428 +
67429 if (clone_flags & CLONE_VFORK) {
67430 p->vfork_done = &vfork;
67431 init_completion(&vfork);
67432 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67433 return 0;
67434
67435 /* don't need lock here; in the worst case we'll do useless copy */
67436 - if (fs->users == 1)
67437 + if (atomic_read(&fs->users) == 1)
67438 return 0;
67439
67440 *new_fsp = copy_fs_struct(fs);
67441 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67442 fs = current->fs;
67443 spin_lock(&fs->lock);
67444 current->fs = new_fs;
67445 - if (--fs->users)
67446 + gr_set_chroot_entries(current, &current->fs->root);
67447 + if (atomic_dec_return(&fs->users))
67448 new_fs = NULL;
67449 else
67450 new_fs = fs;
67451 diff --git a/kernel/futex.c b/kernel/futex.c
67452 index 3717e7b..473c750 100644
67453 --- a/kernel/futex.c
67454 +++ b/kernel/futex.c
67455 @@ -54,6 +54,7 @@
67456 #include <linux/mount.h>
67457 #include <linux/pagemap.h>
67458 #include <linux/syscalls.h>
67459 +#include <linux/ptrace.h>
67460 #include <linux/signal.h>
67461 #include <linux/export.h>
67462 #include <linux/magic.h>
67463 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67464 struct page *page, *page_head;
67465 int err, ro = 0;
67466
67467 +#ifdef CONFIG_PAX_SEGMEXEC
67468 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67469 + return -EFAULT;
67470 +#endif
67471 +
67472 /*
67473 * The futex address must be "naturally" aligned.
67474 */
67475 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67476 {
67477 u32 curval;
67478 int i;
67479 + mm_segment_t oldfs;
67480
67481 /*
67482 * This will fail and we want it. Some arch implementations do
67483 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67484 * implementation, the non-functional ones will return
67485 * -ENOSYS.
67486 */
67487 + oldfs = get_fs();
67488 + set_fs(USER_DS);
67489 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67490 futex_cmpxchg_enabled = 1;
67491 + set_fs(oldfs);
67492
67493 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67494 plist_head_init(&futex_queues[i].chain);
67495 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67496 index 9b22d03..6295b62 100644
67497 --- a/kernel/gcov/base.c
67498 +++ b/kernel/gcov/base.c
67499 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67500 }
67501
67502 #ifdef CONFIG_MODULES
67503 -static inline int within(void *addr, void *start, unsigned long size)
67504 -{
67505 - return ((addr >= start) && (addr < start + size));
67506 -}
67507 -
67508 /* Update list and generate events when modules are unloaded. */
67509 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67510 void *data)
67511 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67512 prev = NULL;
67513 /* Remove entries located in module from linked list. */
67514 for (info = gcov_info_head; info; info = info->next) {
67515 - if (within(info, mod->module_core, mod->core_size)) {
67516 + if (within_module_core_rw((unsigned long)info, mod)) {
67517 if (prev)
67518 prev->next = info->next;
67519 else
67520 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67521 index 6db7a5e..25b6648 100644
67522 --- a/kernel/hrtimer.c
67523 +++ b/kernel/hrtimer.c
67524 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67525 local_irq_restore(flags);
67526 }
67527
67528 -static void run_hrtimer_softirq(struct softirq_action *h)
67529 +static void run_hrtimer_softirq(void)
67530 {
67531 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67532
67533 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67534 index 4304919..408c4c0 100644
67535 --- a/kernel/jump_label.c
67536 +++ b/kernel/jump_label.c
67537 @@ -13,6 +13,7 @@
67538 #include <linux/sort.h>
67539 #include <linux/err.h>
67540 #include <linux/static_key.h>
67541 +#include <linux/mm.h>
67542
67543 #ifdef HAVE_JUMP_LABEL
67544
67545 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67546
67547 size = (((unsigned long)stop - (unsigned long)start)
67548 / sizeof(struct jump_entry));
67549 + pax_open_kernel();
67550 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67551 + pax_close_kernel();
67552 }
67553
67554 static void jump_label_update(struct static_key *key, int enable);
67555 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67556 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67557 struct jump_entry *iter;
67558
67559 + pax_open_kernel();
67560 for (iter = iter_start; iter < iter_stop; iter++) {
67561 if (within_module_init(iter->code, mod))
67562 iter->code = 0;
67563 }
67564 + pax_close_kernel();
67565 }
67566
67567 static int
67568 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67569 index 2169fee..45c017a 100644
67570 --- a/kernel/kallsyms.c
67571 +++ b/kernel/kallsyms.c
67572 @@ -11,6 +11,9 @@
67573 * Changed the compression method from stem compression to "table lookup"
67574 * compression (see scripts/kallsyms.c for a more complete description)
67575 */
67576 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67577 +#define __INCLUDED_BY_HIDESYM 1
67578 +#endif
67579 #include <linux/kallsyms.h>
67580 #include <linux/module.h>
67581 #include <linux/init.h>
67582 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67583
67584 static inline int is_kernel_inittext(unsigned long addr)
67585 {
67586 + if (system_state != SYSTEM_BOOTING)
67587 + return 0;
67588 +
67589 if (addr >= (unsigned long)_sinittext
67590 && addr <= (unsigned long)_einittext)
67591 return 1;
67592 return 0;
67593 }
67594
67595 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67596 +#ifdef CONFIG_MODULES
67597 +static inline int is_module_text(unsigned long addr)
67598 +{
67599 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67600 + return 1;
67601 +
67602 + addr = ktla_ktva(addr);
67603 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67604 +}
67605 +#else
67606 +static inline int is_module_text(unsigned long addr)
67607 +{
67608 + return 0;
67609 +}
67610 +#endif
67611 +#endif
67612 +
67613 static inline int is_kernel_text(unsigned long addr)
67614 {
67615 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67616 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67617
67618 static inline int is_kernel(unsigned long addr)
67619 {
67620 +
67621 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67622 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67623 + return 1;
67624 +
67625 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67626 +#else
67627 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67628 +#endif
67629 +
67630 return 1;
67631 return in_gate_area_no_mm(addr);
67632 }
67633
67634 static int is_ksym_addr(unsigned long addr)
67635 {
67636 +
67637 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67638 + if (is_module_text(addr))
67639 + return 0;
67640 +#endif
67641 +
67642 if (all_var)
67643 return is_kernel(addr);
67644
67645 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67646
67647 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67648 {
67649 - iter->name[0] = '\0';
67650 iter->nameoff = get_symbol_offset(new_pos);
67651 iter->pos = new_pos;
67652 }
67653 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67654 {
67655 struct kallsym_iter *iter = m->private;
67656
67657 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67658 + if (current_uid())
67659 + return 0;
67660 +#endif
67661 +
67662 /* Some debugging symbols have no name. Ignore them. */
67663 if (!iter->name[0])
67664 return 0;
67665 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67666 */
67667 type = iter->exported ? toupper(iter->type) :
67668 tolower(iter->type);
67669 +
67670 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67671 type, iter->name, iter->module_name);
67672 } else
67673 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67674 struct kallsym_iter *iter;
67675 int ret;
67676
67677 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67678 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67679 if (!iter)
67680 return -ENOMEM;
67681 reset_iter(iter, 0);
67682 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67683 index 30b7b22..c726387 100644
67684 --- a/kernel/kcmp.c
67685 +++ b/kernel/kcmp.c
67686 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67687 struct task_struct *task1, *task2;
67688 int ret;
67689
67690 +#ifdef CONFIG_GRKERNSEC
67691 + return -ENOSYS;
67692 +#endif
67693 +
67694 rcu_read_lock();
67695
67696 /*
67697 diff --git a/kernel/kexec.c b/kernel/kexec.c
67698 index 0668d58..591b6fc 100644
67699 --- a/kernel/kexec.c
67700 +++ b/kernel/kexec.c
67701 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67702 unsigned long flags)
67703 {
67704 struct compat_kexec_segment in;
67705 - struct kexec_segment out, __user *ksegments;
67706 + struct kexec_segment out;
67707 + struct kexec_segment __user *ksegments;
67708 unsigned long i, result;
67709
67710 /* Don't allow clients that don't understand the native
67711 diff --git a/kernel/kmod.c b/kernel/kmod.c
67712 index 6f99aea..eb6e3a0 100644
67713 --- a/kernel/kmod.c
67714 +++ b/kernel/kmod.c
67715 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67716 kfree(info->argv);
67717 }
67718
67719 -static int call_modprobe(char *module_name, int wait)
67720 +static int call_modprobe(char *module_name, char *module_param, int wait)
67721 {
67722 static char *envp[] = {
67723 "HOME=/",
67724 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67725 NULL
67726 };
67727
67728 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67729 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67730 if (!argv)
67731 goto out;
67732
67733 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67734 argv[1] = "-q";
67735 argv[2] = "--";
67736 argv[3] = module_name; /* check free_modprobe_argv() */
67737 - argv[4] = NULL;
67738 + argv[4] = module_param;
67739 + argv[5] = NULL;
67740
67741 return call_usermodehelper_fns(modprobe_path, argv, envp,
67742 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67743 @@ -119,9 +120,8 @@ out:
67744 * If module auto-loading support is disabled then this function
67745 * becomes a no-operation.
67746 */
67747 -int __request_module(bool wait, const char *fmt, ...)
67748 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67749 {
67750 - va_list args;
67751 char module_name[MODULE_NAME_LEN];
67752 unsigned int max_modprobes;
67753 int ret;
67754 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67755 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67756 static int kmod_loop_msg;
67757
67758 - va_start(args, fmt);
67759 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67760 - va_end(args);
67761 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67762 if (ret >= MODULE_NAME_LEN)
67763 return -ENAMETOOLONG;
67764
67765 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67766 if (ret)
67767 return ret;
67768
67769 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67770 + if (!current_uid()) {
67771 + /* hack to workaround consolekit/udisks stupidity */
67772 + read_lock(&tasklist_lock);
67773 + if (!strcmp(current->comm, "mount") &&
67774 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67775 + read_unlock(&tasklist_lock);
67776 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67777 + return -EPERM;
67778 + }
67779 + read_unlock(&tasklist_lock);
67780 + }
67781 +#endif
67782 +
67783 /* If modprobe needs a service that is in a module, we get a recursive
67784 * loop. Limit the number of running kmod threads to max_threads/2 or
67785 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67786 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67787
67788 trace_module_request(module_name, wait, _RET_IP_);
67789
67790 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67791 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67792
67793 atomic_dec(&kmod_concurrent);
67794 return ret;
67795 }
67796 +
67797 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67798 +{
67799 + va_list args;
67800 + int ret;
67801 +
67802 + va_start(args, fmt);
67803 + ret = ____request_module(wait, module_param, fmt, args);
67804 + va_end(args);
67805 +
67806 + return ret;
67807 +}
67808 +
67809 +int __request_module(bool wait, const char *fmt, ...)
67810 +{
67811 + va_list args;
67812 + int ret;
67813 +
67814 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67815 + if (current_uid()) {
67816 + char module_param[MODULE_NAME_LEN];
67817 +
67818 + memset(module_param, 0, sizeof(module_param));
67819 +
67820 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67821 +
67822 + va_start(args, fmt);
67823 + ret = ____request_module(wait, module_param, fmt, args);
67824 + va_end(args);
67825 +
67826 + return ret;
67827 + }
67828 +#endif
67829 +
67830 + va_start(args, fmt);
67831 + ret = ____request_module(wait, NULL, fmt, args);
67832 + va_end(args);
67833 +
67834 + return ret;
67835 +}
67836 +
67837 EXPORT_SYMBOL(__request_module);
67838 #endif /* CONFIG_MODULES */
67839
67840 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
67841 *
67842 * Thus the __user pointer cast is valid here.
67843 */
67844 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67845 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67846
67847 /*
67848 * If ret is 0, either ____call_usermodehelper failed and the
67849 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67850 index c62b854..6fc810d 100644
67851 --- a/kernel/kprobes.c
67852 +++ b/kernel/kprobes.c
67853 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67854 * kernel image and loaded module images reside. This is required
67855 * so x86_64 can correctly handle the %rip-relative fixups.
67856 */
67857 - kip->insns = module_alloc(PAGE_SIZE);
67858 + kip->insns = module_alloc_exec(PAGE_SIZE);
67859 if (!kip->insns) {
67860 kfree(kip);
67861 return NULL;
67862 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67863 */
67864 if (!list_is_singular(&kip->list)) {
67865 list_del(&kip->list);
67866 - module_free(NULL, kip->insns);
67867 + module_free_exec(NULL, kip->insns);
67868 kfree(kip);
67869 }
67870 return 1;
67871 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67872 {
67873 int i, err = 0;
67874 unsigned long offset = 0, size = 0;
67875 - char *modname, namebuf[128];
67876 + char *modname, namebuf[KSYM_NAME_LEN];
67877 const char *symbol_name;
67878 void *addr;
67879 struct kprobe_blackpoint *kb;
67880 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
67881 kprobe_type = "k";
67882
67883 if (sym)
67884 - seq_printf(pi, "%p %s %s+0x%x %s ",
67885 + seq_printf(pi, "%pK %s %s+0x%x %s ",
67886 p->addr, kprobe_type, sym, offset,
67887 (modname ? modname : " "));
67888 else
67889 - seq_printf(pi, "%p %s %p ",
67890 + seq_printf(pi, "%pK %s %pK ",
67891 p->addr, kprobe_type, p->addr);
67892
67893 if (!pp)
67894 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67895 const char *sym = NULL;
67896 unsigned int i = *(loff_t *) v;
67897 unsigned long offset = 0;
67898 - char *modname, namebuf[128];
67899 + char *modname, namebuf[KSYM_NAME_LEN];
67900
67901 head = &kprobe_table[i];
67902 preempt_disable();
67903 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67904 index 4e316e1..5501eef 100644
67905 --- a/kernel/ksysfs.c
67906 +++ b/kernel/ksysfs.c
67907 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67908 {
67909 if (count+1 > UEVENT_HELPER_PATH_LEN)
67910 return -ENOENT;
67911 + if (!capable(CAP_SYS_ADMIN))
67912 + return -EPERM;
67913 memcpy(uevent_helper, buf, count);
67914 uevent_helper[count] = '\0';
67915 if (count && uevent_helper[count-1] == '\n')
67916 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67917 index ea9ee45..67ebc8f 100644
67918 --- a/kernel/lockdep.c
67919 +++ b/kernel/lockdep.c
67920 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67921 end = (unsigned long) &_end,
67922 addr = (unsigned long) obj;
67923
67924 +#ifdef CONFIG_PAX_KERNEXEC
67925 + start = ktla_ktva(start);
67926 +#endif
67927 +
67928 /*
67929 * static variable?
67930 */
67931 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67932 if (!static_obj(lock->key)) {
67933 debug_locks_off();
67934 printk("INFO: trying to register non-static key.\n");
67935 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67936 printk("the code is fine but needs lockdep annotation.\n");
67937 printk("turning off the locking correctness validator.\n");
67938 dump_stack();
67939 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67940 if (!class)
67941 return 0;
67942 }
67943 - atomic_inc((atomic_t *)&class->ops);
67944 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67945 if (very_verbose(class)) {
67946 printk("\nacquire class [%p] %s", class->key, class->name);
67947 if (class->name_version > 1)
67948 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67949 index 91c32a0..7b88d63 100644
67950 --- a/kernel/lockdep_proc.c
67951 +++ b/kernel/lockdep_proc.c
67952 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67953
67954 static void print_name(struct seq_file *m, struct lock_class *class)
67955 {
67956 - char str[128];
67957 + char str[KSYM_NAME_LEN];
67958 const char *name = class->name;
67959
67960 if (!name) {
67961 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
67962 return 0;
67963 }
67964
67965 - seq_printf(m, "%p", class->key);
67966 + seq_printf(m, "%pK", class->key);
67967 #ifdef CONFIG_DEBUG_LOCKDEP
67968 seq_printf(m, " OPS:%8ld", class->ops);
67969 #endif
67970 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
67971
67972 list_for_each_entry(entry, &class->locks_after, entry) {
67973 if (entry->distance == 1) {
67974 - seq_printf(m, " -> [%p] ", entry->class->key);
67975 + seq_printf(m, " -> [%pK] ", entry->class->key);
67976 print_name(m, entry->class);
67977 seq_puts(m, "\n");
67978 }
67979 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
67980 if (!class->key)
67981 continue;
67982
67983 - seq_printf(m, "[%p] ", class->key);
67984 + seq_printf(m, "[%pK] ", class->key);
67985 print_name(m, class);
67986 seq_puts(m, "\n");
67987 }
67988 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67989 if (!i)
67990 seq_line(m, '-', 40-namelen, namelen);
67991
67992 - snprintf(ip, sizeof(ip), "[<%p>]",
67993 + snprintf(ip, sizeof(ip), "[<%pK>]",
67994 (void *)class->contention_point[i]);
67995 seq_printf(m, "%40s %14lu %29s %pS\n",
67996 name, stats->contention_point[i],
67997 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67998 if (!i)
67999 seq_line(m, '-', 40-namelen, namelen);
68000
68001 - snprintf(ip, sizeof(ip), "[<%p>]",
68002 + snprintf(ip, sizeof(ip), "[<%pK>]",
68003 (void *)class->contending_point[i]);
68004 seq_printf(m, "%40s %14lu %29s %pS\n",
68005 name, stats->contending_point[i],
68006 diff --git a/kernel/module.c b/kernel/module.c
68007 index 9ad9ee9..de7a157 100644
68008 --- a/kernel/module.c
68009 +++ b/kernel/module.c
68010 @@ -58,6 +58,7 @@
68011 #include <linux/jump_label.h>
68012 #include <linux/pfn.h>
68013 #include <linux/bsearch.h>
68014 +#include <linux/grsecurity.h>
68015
68016 #define CREATE_TRACE_POINTS
68017 #include <trace/events/module.h>
68018 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68019
68020 /* Bounds of module allocation, for speeding __module_address.
68021 * Protected by module_mutex. */
68022 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68023 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68024 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68025
68026 int register_module_notifier(struct notifier_block * nb)
68027 {
68028 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68029 return true;
68030
68031 list_for_each_entry_rcu(mod, &modules, list) {
68032 - struct symsearch arr[] = {
68033 + struct symsearch modarr[] = {
68034 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68035 NOT_GPL_ONLY, false },
68036 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68037 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68038 #endif
68039 };
68040
68041 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68042 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68043 return true;
68044 }
68045 return false;
68046 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68047 static int percpu_modalloc(struct module *mod,
68048 unsigned long size, unsigned long align)
68049 {
68050 - if (align > PAGE_SIZE) {
68051 + if (align-1 >= PAGE_SIZE) {
68052 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68053 mod->name, align, PAGE_SIZE);
68054 align = PAGE_SIZE;
68055 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68056 static ssize_t show_coresize(struct module_attribute *mattr,
68057 struct module_kobject *mk, char *buffer)
68058 {
68059 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68060 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68061 }
68062
68063 static struct module_attribute modinfo_coresize =
68064 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68065 static ssize_t show_initsize(struct module_attribute *mattr,
68066 struct module_kobject *mk, char *buffer)
68067 {
68068 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68069 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68070 }
68071
68072 static struct module_attribute modinfo_initsize =
68073 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68074 */
68075 #ifdef CONFIG_SYSFS
68076
68077 -#ifdef CONFIG_KALLSYMS
68078 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68079 static inline bool sect_empty(const Elf_Shdr *sect)
68080 {
68081 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68082 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68083
68084 static void unset_module_core_ro_nx(struct module *mod)
68085 {
68086 - set_page_attributes(mod->module_core + mod->core_text_size,
68087 - mod->module_core + mod->core_size,
68088 + set_page_attributes(mod->module_core_rw,
68089 + mod->module_core_rw + mod->core_size_rw,
68090 set_memory_x);
68091 - set_page_attributes(mod->module_core,
68092 - mod->module_core + mod->core_ro_size,
68093 + set_page_attributes(mod->module_core_rx,
68094 + mod->module_core_rx + mod->core_size_rx,
68095 set_memory_rw);
68096 }
68097
68098 static void unset_module_init_ro_nx(struct module *mod)
68099 {
68100 - set_page_attributes(mod->module_init + mod->init_text_size,
68101 - mod->module_init + mod->init_size,
68102 + set_page_attributes(mod->module_init_rw,
68103 + mod->module_init_rw + mod->init_size_rw,
68104 set_memory_x);
68105 - set_page_attributes(mod->module_init,
68106 - mod->module_init + mod->init_ro_size,
68107 + set_page_attributes(mod->module_init_rx,
68108 + mod->module_init_rx + mod->init_size_rx,
68109 set_memory_rw);
68110 }
68111
68112 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68113
68114 mutex_lock(&module_mutex);
68115 list_for_each_entry_rcu(mod, &modules, list) {
68116 - if ((mod->module_core) && (mod->core_text_size)) {
68117 - set_page_attributes(mod->module_core,
68118 - mod->module_core + mod->core_text_size,
68119 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68120 + set_page_attributes(mod->module_core_rx,
68121 + mod->module_core_rx + mod->core_size_rx,
68122 set_memory_rw);
68123 }
68124 - if ((mod->module_init) && (mod->init_text_size)) {
68125 - set_page_attributes(mod->module_init,
68126 - mod->module_init + mod->init_text_size,
68127 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68128 + set_page_attributes(mod->module_init_rx,
68129 + mod->module_init_rx + mod->init_size_rx,
68130 set_memory_rw);
68131 }
68132 }
68133 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68134
68135 mutex_lock(&module_mutex);
68136 list_for_each_entry_rcu(mod, &modules, list) {
68137 - if ((mod->module_core) && (mod->core_text_size)) {
68138 - set_page_attributes(mod->module_core,
68139 - mod->module_core + mod->core_text_size,
68140 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68141 + set_page_attributes(mod->module_core_rx,
68142 + mod->module_core_rx + mod->core_size_rx,
68143 set_memory_ro);
68144 }
68145 - if ((mod->module_init) && (mod->init_text_size)) {
68146 - set_page_attributes(mod->module_init,
68147 - mod->module_init + mod->init_text_size,
68148 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68149 + set_page_attributes(mod->module_init_rx,
68150 + mod->module_init_rx + mod->init_size_rx,
68151 set_memory_ro);
68152 }
68153 }
68154 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68155
68156 /* This may be NULL, but that's OK */
68157 unset_module_init_ro_nx(mod);
68158 - module_free(mod, mod->module_init);
68159 + module_free(mod, mod->module_init_rw);
68160 + module_free_exec(mod, mod->module_init_rx);
68161 kfree(mod->args);
68162 percpu_modfree(mod);
68163
68164 /* Free lock-classes: */
68165 - lockdep_free_key_range(mod->module_core, mod->core_size);
68166 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68167 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68168
68169 /* Finally, free the core (containing the module structure) */
68170 unset_module_core_ro_nx(mod);
68171 - module_free(mod, mod->module_core);
68172 + module_free_exec(mod, mod->module_core_rx);
68173 + module_free(mod, mod->module_core_rw);
68174
68175 #ifdef CONFIG_MPU
68176 update_protections(current->mm);
68177 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68178 int ret = 0;
68179 const struct kernel_symbol *ksym;
68180
68181 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68182 + int is_fs_load = 0;
68183 + int register_filesystem_found = 0;
68184 + char *p;
68185 +
68186 + p = strstr(mod->args, "grsec_modharden_fs");
68187 + if (p) {
68188 + char *endptr = p + strlen("grsec_modharden_fs");
68189 + /* copy \0 as well */
68190 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68191 + is_fs_load = 1;
68192 + }
68193 +#endif
68194 +
68195 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68196 const char *name = info->strtab + sym[i].st_name;
68197
68198 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68199 + /* it's a real shame this will never get ripped and copied
68200 + upstream! ;(
68201 + */
68202 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68203 + register_filesystem_found = 1;
68204 +#endif
68205 +
68206 switch (sym[i].st_shndx) {
68207 case SHN_COMMON:
68208 /* We compiled with -fno-common. These are not
68209 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68210 ksym = resolve_symbol_wait(mod, info, name);
68211 /* Ok if resolved. */
68212 if (ksym && !IS_ERR(ksym)) {
68213 + pax_open_kernel();
68214 sym[i].st_value = ksym->value;
68215 + pax_close_kernel();
68216 break;
68217 }
68218
68219 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68220 secbase = (unsigned long)mod_percpu(mod);
68221 else
68222 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68223 + pax_open_kernel();
68224 sym[i].st_value += secbase;
68225 + pax_close_kernel();
68226 break;
68227 }
68228 }
68229
68230 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68231 + if (is_fs_load && !register_filesystem_found) {
68232 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68233 + ret = -EPERM;
68234 + }
68235 +#endif
68236 +
68237 return ret;
68238 }
68239
68240 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68241 || s->sh_entsize != ~0UL
68242 || strstarts(sname, ".init"))
68243 continue;
68244 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68245 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68246 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68247 + else
68248 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68249 pr_debug("\t%s\n", sname);
68250 }
68251 - switch (m) {
68252 - case 0: /* executable */
68253 - mod->core_size = debug_align(mod->core_size);
68254 - mod->core_text_size = mod->core_size;
68255 - break;
68256 - case 1: /* RO: text and ro-data */
68257 - mod->core_size = debug_align(mod->core_size);
68258 - mod->core_ro_size = mod->core_size;
68259 - break;
68260 - case 3: /* whole core */
68261 - mod->core_size = debug_align(mod->core_size);
68262 - break;
68263 - }
68264 }
68265
68266 pr_debug("Init section allocation order:\n");
68267 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68268 || s->sh_entsize != ~0UL
68269 || !strstarts(sname, ".init"))
68270 continue;
68271 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68272 - | INIT_OFFSET_MASK);
68273 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68274 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68275 + else
68276 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68277 + s->sh_entsize |= INIT_OFFSET_MASK;
68278 pr_debug("\t%s\n", sname);
68279 }
68280 - switch (m) {
68281 - case 0: /* executable */
68282 - mod->init_size = debug_align(mod->init_size);
68283 - mod->init_text_size = mod->init_size;
68284 - break;
68285 - case 1: /* RO: text and ro-data */
68286 - mod->init_size = debug_align(mod->init_size);
68287 - mod->init_ro_size = mod->init_size;
68288 - break;
68289 - case 3: /* whole init */
68290 - mod->init_size = debug_align(mod->init_size);
68291 - break;
68292 - }
68293 }
68294 }
68295
68296 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68297
68298 /* Put symbol section at end of init part of module. */
68299 symsect->sh_flags |= SHF_ALLOC;
68300 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68301 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68302 info->index.sym) | INIT_OFFSET_MASK;
68303 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68304
68305 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68306 }
68307
68308 /* Append room for core symbols at end of core part. */
68309 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68310 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68311 - mod->core_size += strtab_size;
68312 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68313 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68314 + mod->core_size_rx += strtab_size;
68315
68316 /* Put string table section at end of init part of module. */
68317 strsect->sh_flags |= SHF_ALLOC;
68318 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68319 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68320 info->index.str) | INIT_OFFSET_MASK;
68321 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68322 }
68323 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68324 /* Make sure we get permanent strtab: don't use info->strtab. */
68325 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68326
68327 + pax_open_kernel();
68328 +
68329 /* Set types up while we still have access to sections. */
68330 for (i = 0; i < mod->num_symtab; i++)
68331 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68332
68333 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68334 - mod->core_strtab = s = mod->module_core + info->stroffs;
68335 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68336 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68337 src = mod->symtab;
68338 *dst = *src;
68339 *s++ = 0;
68340 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68341 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68342 }
68343 mod->core_num_syms = ndst;
68344 +
68345 + pax_close_kernel();
68346 }
68347 #else
68348 static inline void layout_symtab(struct module *mod, struct load_info *info)
68349 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68350 return size == 0 ? NULL : vmalloc_exec(size);
68351 }
68352
68353 -static void *module_alloc_update_bounds(unsigned long size)
68354 +static void *module_alloc_update_bounds_rw(unsigned long size)
68355 {
68356 void *ret = module_alloc(size);
68357
68358 if (ret) {
68359 mutex_lock(&module_mutex);
68360 /* Update module bounds. */
68361 - if ((unsigned long)ret < module_addr_min)
68362 - module_addr_min = (unsigned long)ret;
68363 - if ((unsigned long)ret + size > module_addr_max)
68364 - module_addr_max = (unsigned long)ret + size;
68365 + if ((unsigned long)ret < module_addr_min_rw)
68366 + module_addr_min_rw = (unsigned long)ret;
68367 + if ((unsigned long)ret + size > module_addr_max_rw)
68368 + module_addr_max_rw = (unsigned long)ret + size;
68369 + mutex_unlock(&module_mutex);
68370 + }
68371 + return ret;
68372 +}
68373 +
68374 +static void *module_alloc_update_bounds_rx(unsigned long size)
68375 +{
68376 + void *ret = module_alloc_exec(size);
68377 +
68378 + if (ret) {
68379 + mutex_lock(&module_mutex);
68380 + /* Update module bounds. */
68381 + if ((unsigned long)ret < module_addr_min_rx)
68382 + module_addr_min_rx = (unsigned long)ret;
68383 + if ((unsigned long)ret + size > module_addr_max_rx)
68384 + module_addr_max_rx = (unsigned long)ret + size;
68385 mutex_unlock(&module_mutex);
68386 }
68387 return ret;
68388 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68389 static int check_modinfo(struct module *mod, struct load_info *info)
68390 {
68391 const char *modmagic = get_modinfo(info, "vermagic");
68392 + const char *license = get_modinfo(info, "license");
68393 int err;
68394
68395 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68396 + if (!license || !license_is_gpl_compatible(license))
68397 + return -ENOEXEC;
68398 +#endif
68399 +
68400 /* This is allowed: modprobe --force will invalidate it. */
68401 if (!modmagic) {
68402 err = try_to_force_load(mod, "bad vermagic");
68403 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68404 }
68405
68406 /* Set up license info based on the info section */
68407 - set_license(mod, get_modinfo(info, "license"));
68408 + set_license(mod, license);
68409
68410 return 0;
68411 }
68412 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68413 void *ptr;
68414
68415 /* Do the allocs. */
68416 - ptr = module_alloc_update_bounds(mod->core_size);
68417 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68418 /*
68419 * The pointer to this block is stored in the module structure
68420 * which is inside the block. Just mark it as not being a
68421 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68422 if (!ptr)
68423 return -ENOMEM;
68424
68425 - memset(ptr, 0, mod->core_size);
68426 - mod->module_core = ptr;
68427 + memset(ptr, 0, mod->core_size_rw);
68428 + mod->module_core_rw = ptr;
68429
68430 - ptr = module_alloc_update_bounds(mod->init_size);
68431 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68432 /*
68433 * The pointer to this block is stored in the module structure
68434 * which is inside the block. This block doesn't need to be
68435 * scanned as it contains data and code that will be freed
68436 * after the module is initialized.
68437 */
68438 - kmemleak_ignore(ptr);
68439 - if (!ptr && mod->init_size) {
68440 - module_free(mod, mod->module_core);
68441 + kmemleak_not_leak(ptr);
68442 + if (!ptr && mod->init_size_rw) {
68443 + module_free(mod, mod->module_core_rw);
68444 return -ENOMEM;
68445 }
68446 - memset(ptr, 0, mod->init_size);
68447 - mod->module_init = ptr;
68448 + memset(ptr, 0, mod->init_size_rw);
68449 + mod->module_init_rw = ptr;
68450 +
68451 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68452 + kmemleak_not_leak(ptr);
68453 + if (!ptr) {
68454 + module_free(mod, mod->module_init_rw);
68455 + module_free(mod, mod->module_core_rw);
68456 + return -ENOMEM;
68457 + }
68458 +
68459 + pax_open_kernel();
68460 + memset(ptr, 0, mod->core_size_rx);
68461 + pax_close_kernel();
68462 + mod->module_core_rx = ptr;
68463 +
68464 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68465 + kmemleak_not_leak(ptr);
68466 + if (!ptr && mod->init_size_rx) {
68467 + module_free_exec(mod, mod->module_core_rx);
68468 + module_free(mod, mod->module_init_rw);
68469 + module_free(mod, mod->module_core_rw);
68470 + return -ENOMEM;
68471 + }
68472 +
68473 + pax_open_kernel();
68474 + memset(ptr, 0, mod->init_size_rx);
68475 + pax_close_kernel();
68476 + mod->module_init_rx = ptr;
68477
68478 /* Transfer each section which specifies SHF_ALLOC */
68479 pr_debug("final section addresses:\n");
68480 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68481 if (!(shdr->sh_flags & SHF_ALLOC))
68482 continue;
68483
68484 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68485 - dest = mod->module_init
68486 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68487 - else
68488 - dest = mod->module_core + shdr->sh_entsize;
68489 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68490 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68491 + dest = mod->module_init_rw
68492 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68493 + else
68494 + dest = mod->module_init_rx
68495 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68496 + } else {
68497 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68498 + dest = mod->module_core_rw + shdr->sh_entsize;
68499 + else
68500 + dest = mod->module_core_rx + shdr->sh_entsize;
68501 + }
68502 +
68503 + if (shdr->sh_type != SHT_NOBITS) {
68504 +
68505 +#ifdef CONFIG_PAX_KERNEXEC
68506 +#ifdef CONFIG_X86_64
68507 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68508 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68509 +#endif
68510 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68511 + pax_open_kernel();
68512 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68513 + pax_close_kernel();
68514 + } else
68515 +#endif
68516
68517 - if (shdr->sh_type != SHT_NOBITS)
68518 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68519 + }
68520 /* Update sh_addr to point to copy in image. */
68521 - shdr->sh_addr = (unsigned long)dest;
68522 +
68523 +#ifdef CONFIG_PAX_KERNEXEC
68524 + if (shdr->sh_flags & SHF_EXECINSTR)
68525 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68526 + else
68527 +#endif
68528 +
68529 + shdr->sh_addr = (unsigned long)dest;
68530 pr_debug("\t0x%lx %s\n",
68531 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68532 }
68533 @@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68534 * Do it before processing of module parameters, so the module
68535 * can provide parameter accessor functions of its own.
68536 */
68537 - if (mod->module_init)
68538 - flush_icache_range((unsigned long)mod->module_init,
68539 - (unsigned long)mod->module_init
68540 - + mod->init_size);
68541 - flush_icache_range((unsigned long)mod->module_core,
68542 - (unsigned long)mod->module_core + mod->core_size);
68543 + if (mod->module_init_rx)
68544 + flush_icache_range((unsigned long)mod->module_init_rx,
68545 + (unsigned long)mod->module_init_rx
68546 + + mod->init_size_rx);
68547 + flush_icache_range((unsigned long)mod->module_core_rx,
68548 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68549
68550 set_fs(old_fs);
68551 }
68552 @@ -2838,8 +2938,10 @@ out:
68553 static void module_deallocate(struct module *mod, struct load_info *info)
68554 {
68555 percpu_modfree(mod);
68556 - module_free(mod, mod->module_init);
68557 - module_free(mod, mod->module_core);
68558 + module_free_exec(mod, mod->module_init_rx);
68559 + module_free_exec(mod, mod->module_core_rx);
68560 + module_free(mod, mod->module_init_rw);
68561 + module_free(mod, mod->module_core_rw);
68562 }
68563
68564 int __weak module_finalize(const Elf_Ehdr *hdr,
68565 @@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68566 static int post_relocation(struct module *mod, const struct load_info *info)
68567 {
68568 /* Sort exception table now relocations are done. */
68569 + pax_open_kernel();
68570 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68571 + pax_close_kernel();
68572
68573 /* Copy relocated percpu area over. */
68574 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68575 @@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68576 if (err)
68577 goto free_unload;
68578
68579 + /* Now copy in args */
68580 + mod->args = strndup_user(uargs, ~0UL >> 1);
68581 + if (IS_ERR(mod->args)) {
68582 + err = PTR_ERR(mod->args);
68583 + goto free_unload;
68584 + }
68585 +
68586 /* Set up MODINFO_ATTR fields */
68587 setup_modinfo(mod, &info);
68588
68589 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68590 + {
68591 + char *p, *p2;
68592 +
68593 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68594 + 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);
68595 + err = -EPERM;
68596 + goto free_modinfo;
68597 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68598 + p += strlen("grsec_modharden_normal");
68599 + p2 = strstr(p, "_");
68600 + if (p2) {
68601 + *p2 = '\0';
68602 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68603 + *p2 = '_';
68604 + }
68605 + err = -EPERM;
68606 + goto free_modinfo;
68607 + }
68608 + }
68609 +#endif
68610 +
68611 /* Fix up syms, so that st_value is a pointer to location. */
68612 err = simplify_symbols(mod, &info);
68613 if (err < 0)
68614 @@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68615
68616 flush_module_icache(mod);
68617
68618 - /* Now copy in args */
68619 - mod->args = strndup_user(uargs, ~0UL >> 1);
68620 - if (IS_ERR(mod->args)) {
68621 - err = PTR_ERR(mod->args);
68622 - goto free_arch_cleanup;
68623 - }
68624 -
68625 /* Mark state as coming so strong_try_module_get() ignores us. */
68626 mod->state = MODULE_STATE_COMING;
68627
68628 @@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68629 unlock:
68630 mutex_unlock(&module_mutex);
68631 synchronize_sched();
68632 - kfree(mod->args);
68633 - free_arch_cleanup:
68634 module_arch_cleanup(mod);
68635 free_modinfo:
68636 free_modinfo(mod);
68637 + kfree(mod->args);
68638 free_unload:
68639 module_unload_free(mod);
68640 free_module:
68641 @@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68642 MODULE_STATE_COMING, mod);
68643
68644 /* Set RO and NX regions for core */
68645 - set_section_ro_nx(mod->module_core,
68646 - mod->core_text_size,
68647 - mod->core_ro_size,
68648 - mod->core_size);
68649 + set_section_ro_nx(mod->module_core_rx,
68650 + mod->core_size_rx,
68651 + mod->core_size_rx,
68652 + mod->core_size_rx);
68653
68654 /* Set RO and NX regions for init */
68655 - set_section_ro_nx(mod->module_init,
68656 - mod->init_text_size,
68657 - mod->init_ro_size,
68658 - mod->init_size);
68659 + set_section_ro_nx(mod->module_init_rx,
68660 + mod->init_size_rx,
68661 + mod->init_size_rx,
68662 + mod->init_size_rx);
68663
68664 do_mod_ctors(mod);
68665 /* Start the module */
68666 @@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68667 mod->strtab = mod->core_strtab;
68668 #endif
68669 unset_module_init_ro_nx(mod);
68670 - module_free(mod, mod->module_init);
68671 - mod->module_init = NULL;
68672 - mod->init_size = 0;
68673 - mod->init_ro_size = 0;
68674 - mod->init_text_size = 0;
68675 + module_free(mod, mod->module_init_rw);
68676 + module_free_exec(mod, mod->module_init_rx);
68677 + mod->module_init_rw = NULL;
68678 + mod->module_init_rx = NULL;
68679 + mod->init_size_rw = 0;
68680 + mod->init_size_rx = 0;
68681 mutex_unlock(&module_mutex);
68682
68683 return 0;
68684 @@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68685 unsigned long nextval;
68686
68687 /* At worse, next value is at end of module */
68688 - if (within_module_init(addr, mod))
68689 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68690 + if (within_module_init_rx(addr, mod))
68691 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68692 + else if (within_module_init_rw(addr, mod))
68693 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68694 + else if (within_module_core_rx(addr, mod))
68695 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68696 + else if (within_module_core_rw(addr, mod))
68697 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68698 else
68699 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68700 + return NULL;
68701
68702 /* Scan for closest preceding symbol, and next symbol. (ELF
68703 starts real symbols at 1). */
68704 @@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68705 char buf[8];
68706
68707 seq_printf(m, "%s %u",
68708 - mod->name, mod->init_size + mod->core_size);
68709 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68710 print_unload_info(m, mod);
68711
68712 /* Informative for users. */
68713 @@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68714 mod->state == MODULE_STATE_COMING ? "Loading":
68715 "Live");
68716 /* Used by oprofile and other similar tools. */
68717 - seq_printf(m, " 0x%pK", mod->module_core);
68718 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68719
68720 /* Taints info */
68721 if (mod->taints)
68722 @@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68723
68724 static int __init proc_modules_init(void)
68725 {
68726 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68727 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68728 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68729 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68730 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68731 +#else
68732 proc_create("modules", 0, NULL, &proc_modules_operations);
68733 +#endif
68734 +#else
68735 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68736 +#endif
68737 return 0;
68738 }
68739 module_init(proc_modules_init);
68740 @@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68741 {
68742 struct module *mod;
68743
68744 - if (addr < module_addr_min || addr > module_addr_max)
68745 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68746 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68747 return NULL;
68748
68749 list_for_each_entry_rcu(mod, &modules, list)
68750 - if (within_module_core(addr, mod)
68751 - || within_module_init(addr, mod))
68752 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68753 return mod;
68754 return NULL;
68755 }
68756 @@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68757 */
68758 struct module *__module_text_address(unsigned long addr)
68759 {
68760 - struct module *mod = __module_address(addr);
68761 + struct module *mod;
68762 +
68763 +#ifdef CONFIG_X86_32
68764 + addr = ktla_ktva(addr);
68765 +#endif
68766 +
68767 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68768 + return NULL;
68769 +
68770 + mod = __module_address(addr);
68771 +
68772 if (mod) {
68773 /* Make sure it's within the text section. */
68774 - if (!within(addr, mod->module_init, mod->init_text_size)
68775 - && !within(addr, mod->module_core, mod->core_text_size))
68776 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68777 mod = NULL;
68778 }
68779 return mod;
68780 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68781 index 7e3443f..b2a1e6b 100644
68782 --- a/kernel/mutex-debug.c
68783 +++ b/kernel/mutex-debug.c
68784 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68785 }
68786
68787 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68788 - struct thread_info *ti)
68789 + struct task_struct *task)
68790 {
68791 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68792
68793 /* Mark the current thread as blocked on the lock: */
68794 - ti->task->blocked_on = waiter;
68795 + task->blocked_on = waiter;
68796 }
68797
68798 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68799 - struct thread_info *ti)
68800 + struct task_struct *task)
68801 {
68802 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68803 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68804 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68805 - ti->task->blocked_on = NULL;
68806 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68807 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68808 + task->blocked_on = NULL;
68809
68810 list_del_init(&waiter->list);
68811 waiter->task = NULL;
68812 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68813 index 0799fd3..d06ae3b 100644
68814 --- a/kernel/mutex-debug.h
68815 +++ b/kernel/mutex-debug.h
68816 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68817 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68818 extern void debug_mutex_add_waiter(struct mutex *lock,
68819 struct mutex_waiter *waiter,
68820 - struct thread_info *ti);
68821 + struct task_struct *task);
68822 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68823 - struct thread_info *ti);
68824 + struct task_struct *task);
68825 extern void debug_mutex_unlock(struct mutex *lock);
68826 extern void debug_mutex_init(struct mutex *lock, const char *name,
68827 struct lock_class_key *key);
68828 diff --git a/kernel/mutex.c b/kernel/mutex.c
68829 index a307cc9..27fd2e9 100644
68830 --- a/kernel/mutex.c
68831 +++ b/kernel/mutex.c
68832 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68833 spin_lock_mutex(&lock->wait_lock, flags);
68834
68835 debug_mutex_lock_common(lock, &waiter);
68836 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68837 + debug_mutex_add_waiter(lock, &waiter, task);
68838
68839 /* add waiting tasks to the end of the waitqueue (FIFO): */
68840 list_add_tail(&waiter.list, &lock->wait_list);
68841 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68842 * TASK_UNINTERRUPTIBLE case.)
68843 */
68844 if (unlikely(signal_pending_state(state, task))) {
68845 - mutex_remove_waiter(lock, &waiter,
68846 - task_thread_info(task));
68847 + mutex_remove_waiter(lock, &waiter, task);
68848 mutex_release(&lock->dep_map, 1, ip);
68849 spin_unlock_mutex(&lock->wait_lock, flags);
68850
68851 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68852 done:
68853 lock_acquired(&lock->dep_map, ip);
68854 /* got the lock - rejoice! */
68855 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68856 + mutex_remove_waiter(lock, &waiter, task);
68857 mutex_set_owner(lock);
68858
68859 /* set it to 0 if there are no waiters left: */
68860 diff --git a/kernel/panic.c b/kernel/panic.c
68861 index e1b2822..5edc1d9 100644
68862 --- a/kernel/panic.c
68863 +++ b/kernel/panic.c
68864 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68865 const char *board;
68866
68867 printk(KERN_WARNING "------------[ cut here ]------------\n");
68868 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68869 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68870 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68871 if (board)
68872 printk(KERN_WARNING "Hardware name: %s\n", board);
68873 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68874 */
68875 void __stack_chk_fail(void)
68876 {
68877 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68878 + dump_stack();
68879 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68880 __builtin_return_address(0));
68881 }
68882 EXPORT_SYMBOL(__stack_chk_fail);
68883 diff --git a/kernel/pid.c b/kernel/pid.c
68884 index e86b291a..e8b0fb5 100644
68885 --- a/kernel/pid.c
68886 +++ b/kernel/pid.c
68887 @@ -33,6 +33,7 @@
68888 #include <linux/rculist.h>
68889 #include <linux/bootmem.h>
68890 #include <linux/hash.h>
68891 +#include <linux/security.h>
68892 #include <linux/pid_namespace.h>
68893 #include <linux/init_task.h>
68894 #include <linux/syscalls.h>
68895 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68896
68897 int pid_max = PID_MAX_DEFAULT;
68898
68899 -#define RESERVED_PIDS 300
68900 +#define RESERVED_PIDS 500
68901
68902 int pid_max_min = RESERVED_PIDS + 1;
68903 int pid_max_max = PID_MAX_LIMIT;
68904 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68905 */
68906 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68907 {
68908 + struct task_struct *task;
68909 +
68910 rcu_lockdep_assert(rcu_read_lock_held(),
68911 "find_task_by_pid_ns() needs rcu_read_lock()"
68912 " protection");
68913 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68914 +
68915 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68916 +
68917 + if (gr_pid_is_chrooted(task))
68918 + return NULL;
68919 +
68920 + return task;
68921 }
68922
68923 struct task_struct *find_task_by_vpid(pid_t vnr)
68924 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68925 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68926 }
68927
68928 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68929 +{
68930 + rcu_lockdep_assert(rcu_read_lock_held(),
68931 + "find_task_by_pid_ns() needs rcu_read_lock()"
68932 + " protection");
68933 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68934 +}
68935 +
68936 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68937 {
68938 struct pid *pid;
68939 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68940 index 125cb67..a4d1c30 100644
68941 --- a/kernel/posix-cpu-timers.c
68942 +++ b/kernel/posix-cpu-timers.c
68943 @@ -6,6 +6,7 @@
68944 #include <linux/posix-timers.h>
68945 #include <linux/errno.h>
68946 #include <linux/math64.h>
68947 +#include <linux/security.h>
68948 #include <asm/uaccess.h>
68949 #include <linux/kernel_stat.h>
68950 #include <trace/events/timer.h>
68951 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68952
68953 static __init int init_posix_cpu_timers(void)
68954 {
68955 - struct k_clock process = {
68956 + static struct k_clock process = {
68957 .clock_getres = process_cpu_clock_getres,
68958 .clock_get = process_cpu_clock_get,
68959 .timer_create = process_cpu_timer_create,
68960 .nsleep = process_cpu_nsleep,
68961 .nsleep_restart = process_cpu_nsleep_restart,
68962 };
68963 - struct k_clock thread = {
68964 + static struct k_clock thread = {
68965 .clock_getres = thread_cpu_clock_getres,
68966 .clock_get = thread_cpu_clock_get,
68967 .timer_create = thread_cpu_timer_create,
68968 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68969 index 69185ae..cc2847a 100644
68970 --- a/kernel/posix-timers.c
68971 +++ b/kernel/posix-timers.c
68972 @@ -43,6 +43,7 @@
68973 #include <linux/idr.h>
68974 #include <linux/posix-clock.h>
68975 #include <linux/posix-timers.h>
68976 +#include <linux/grsecurity.h>
68977 #include <linux/syscalls.h>
68978 #include <linux/wait.h>
68979 #include <linux/workqueue.h>
68980 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68981 * which we beg off on and pass to do_sys_settimeofday().
68982 */
68983
68984 -static struct k_clock posix_clocks[MAX_CLOCKS];
68985 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68986
68987 /*
68988 * These ones are defined below.
68989 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68990 */
68991 static __init int init_posix_timers(void)
68992 {
68993 - struct k_clock clock_realtime = {
68994 + static struct k_clock clock_realtime = {
68995 .clock_getres = hrtimer_get_res,
68996 .clock_get = posix_clock_realtime_get,
68997 .clock_set = posix_clock_realtime_set,
68998 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68999 .timer_get = common_timer_get,
69000 .timer_del = common_timer_del,
69001 };
69002 - struct k_clock clock_monotonic = {
69003 + static struct k_clock clock_monotonic = {
69004 .clock_getres = hrtimer_get_res,
69005 .clock_get = posix_ktime_get_ts,
69006 .nsleep = common_nsleep,
69007 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69008 .timer_get = common_timer_get,
69009 .timer_del = common_timer_del,
69010 };
69011 - struct k_clock clock_monotonic_raw = {
69012 + static struct k_clock clock_monotonic_raw = {
69013 .clock_getres = hrtimer_get_res,
69014 .clock_get = posix_get_monotonic_raw,
69015 };
69016 - struct k_clock clock_realtime_coarse = {
69017 + static struct k_clock clock_realtime_coarse = {
69018 .clock_getres = posix_get_coarse_res,
69019 .clock_get = posix_get_realtime_coarse,
69020 };
69021 - struct k_clock clock_monotonic_coarse = {
69022 + static struct k_clock clock_monotonic_coarse = {
69023 .clock_getres = posix_get_coarse_res,
69024 .clock_get = posix_get_monotonic_coarse,
69025 };
69026 - struct k_clock clock_boottime = {
69027 + static struct k_clock clock_boottime = {
69028 .clock_getres = hrtimer_get_res,
69029 .clock_get = posix_get_boottime,
69030 .nsleep = common_nsleep,
69031 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69032 return;
69033 }
69034
69035 - posix_clocks[clock_id] = *new_clock;
69036 + posix_clocks[clock_id] = new_clock;
69037 }
69038 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69039
69040 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69041 return (id & CLOCKFD_MASK) == CLOCKFD ?
69042 &clock_posix_dynamic : &clock_posix_cpu;
69043
69044 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69045 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69046 return NULL;
69047 - return &posix_clocks[id];
69048 + return posix_clocks[id];
69049 }
69050
69051 static int common_timer_create(struct k_itimer *new_timer)
69052 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69053 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69054 return -EFAULT;
69055
69056 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69057 + have their clock_set fptr set to a nosettime dummy function
69058 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69059 + call common_clock_set, which calls do_sys_settimeofday, which
69060 + we hook
69061 + */
69062 +
69063 return kc->clock_set(which_clock, &new_tp);
69064 }
69065
69066 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69067 index d523593..68197a4 100644
69068 --- a/kernel/power/poweroff.c
69069 +++ b/kernel/power/poweroff.c
69070 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69071 .enable_mask = SYSRQ_ENABLE_BOOT,
69072 };
69073
69074 -static int pm_sysrq_init(void)
69075 +static int __init pm_sysrq_init(void)
69076 {
69077 register_sysrq_key('o', &sysrq_poweroff_op);
69078 return 0;
69079 diff --git a/kernel/power/process.c b/kernel/power/process.c
69080 index 19db29f..33b52b6 100644
69081 --- a/kernel/power/process.c
69082 +++ b/kernel/power/process.c
69083 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69084 u64 elapsed_csecs64;
69085 unsigned int elapsed_csecs;
69086 bool wakeup = false;
69087 + bool timedout = false;
69088
69089 do_gettimeofday(&start);
69090
69091 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69092
69093 while (true) {
69094 todo = 0;
69095 + if (time_after(jiffies, end_time))
69096 + timedout = true;
69097 read_lock(&tasklist_lock);
69098 do_each_thread(g, p) {
69099 if (p == current || !freeze_task(p))
69100 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69101 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69102 * transition can't race with task state testing here.
69103 */
69104 - if (!task_is_stopped_or_traced(p) &&
69105 - !freezer_should_skip(p))
69106 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69107 todo++;
69108 + if (timedout) {
69109 + printk(KERN_ERR "Task refusing to freeze:\n");
69110 + sched_show_task(p);
69111 + }
69112 + }
69113 } while_each_thread(g, p);
69114 read_unlock(&tasklist_lock);
69115
69116 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69117 todo += wq_busy;
69118 }
69119
69120 - if (!todo || time_after(jiffies, end_time))
69121 + if (!todo || timedout)
69122 break;
69123
69124 if (pm_wakeup_pending()) {
69125 diff --git a/kernel/printk.c b/kernel/printk.c
69126 index 66a2ea3..10f3a01 100644
69127 --- a/kernel/printk.c
69128 +++ b/kernel/printk.c
69129 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69130 if (from_file && type != SYSLOG_ACTION_OPEN)
69131 return 0;
69132
69133 +#ifdef CONFIG_GRKERNSEC_DMESG
69134 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69135 + return -EPERM;
69136 +#endif
69137 +
69138 if (syslog_action_restricted(type)) {
69139 if (capable(CAP_SYSLOG))
69140 return 0;
69141 diff --git a/kernel/profile.c b/kernel/profile.c
69142 index 76b8e77..a2930e8 100644
69143 --- a/kernel/profile.c
69144 +++ b/kernel/profile.c
69145 @@ -39,7 +39,7 @@ struct profile_hit {
69146 /* Oprofile timer tick hook */
69147 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69148
69149 -static atomic_t *prof_buffer;
69150 +static atomic_unchecked_t *prof_buffer;
69151 static unsigned long prof_len, prof_shift;
69152
69153 int prof_on __read_mostly;
69154 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69155 hits[i].pc = 0;
69156 continue;
69157 }
69158 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69159 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69160 hits[i].hits = hits[i].pc = 0;
69161 }
69162 }
69163 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69164 * Add the current hit(s) and flush the write-queue out
69165 * to the global buffer:
69166 */
69167 - atomic_add(nr_hits, &prof_buffer[pc]);
69168 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69169 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69170 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69171 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69172 hits[i].pc = hits[i].hits = 0;
69173 }
69174 out:
69175 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69176 {
69177 unsigned long pc;
69178 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69179 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69180 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69181 }
69182 #endif /* !CONFIG_SMP */
69183
69184 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69185 return -EFAULT;
69186 buf++; p++; count--; read++;
69187 }
69188 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69189 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69190 if (copy_to_user(buf, (void *)pnt, count))
69191 return -EFAULT;
69192 read += count;
69193 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69194 }
69195 #endif
69196 profile_discard_flip_buffers();
69197 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69198 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69199 return count;
69200 }
69201
69202 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69203 index a232bb5..2a65ef9 100644
69204 --- a/kernel/ptrace.c
69205 +++ b/kernel/ptrace.c
69206 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69207
69208 if (seize)
69209 flags |= PT_SEIZED;
69210 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69211 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69212 flags |= PT_PTRACE_CAP;
69213 task->ptrace = flags;
69214
69215 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69216 break;
69217 return -EIO;
69218 }
69219 - if (copy_to_user(dst, buf, retval))
69220 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69221 return -EFAULT;
69222 copied += retval;
69223 src += retval;
69224 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69225 bool seized = child->ptrace & PT_SEIZED;
69226 int ret = -EIO;
69227 siginfo_t siginfo, *si;
69228 - void __user *datavp = (void __user *) data;
69229 + void __user *datavp = (__force void __user *) data;
69230 unsigned long __user *datalp = datavp;
69231 unsigned long flags;
69232
69233 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69234 goto out;
69235 }
69236
69237 + if (gr_handle_ptrace(child, request)) {
69238 + ret = -EPERM;
69239 + goto out_put_task_struct;
69240 + }
69241 +
69242 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69243 ret = ptrace_attach(child, request, addr, data);
69244 /*
69245 * Some architectures need to do book-keeping after
69246 * a ptrace attach.
69247 */
69248 - if (!ret)
69249 + if (!ret) {
69250 arch_ptrace_attach(child);
69251 + gr_audit_ptrace(child);
69252 + }
69253 goto out_put_task_struct;
69254 }
69255
69256 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69257 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69258 if (copied != sizeof(tmp))
69259 return -EIO;
69260 - return put_user(tmp, (unsigned long __user *)data);
69261 + return put_user(tmp, (__force unsigned long __user *)data);
69262 }
69263
69264 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69265 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69266 goto out;
69267 }
69268
69269 + if (gr_handle_ptrace(child, request)) {
69270 + ret = -EPERM;
69271 + goto out_put_task_struct;
69272 + }
69273 +
69274 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69275 ret = ptrace_attach(child, request, addr, data);
69276 /*
69277 * Some architectures need to do book-keeping after
69278 * a ptrace attach.
69279 */
69280 - if (!ret)
69281 + if (!ret) {
69282 arch_ptrace_attach(child);
69283 + gr_audit_ptrace(child);
69284 + }
69285 goto out_put_task_struct;
69286 }
69287
69288 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69289 index 547b1fe..65e874e 100644
69290 --- a/kernel/rcutiny.c
69291 +++ b/kernel/rcutiny.c
69292 @@ -46,7 +46,7 @@
69293 struct rcu_ctrlblk;
69294 static void invoke_rcu_callbacks(void);
69295 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69296 -static void rcu_process_callbacks(struct softirq_action *unused);
69297 +static void rcu_process_callbacks(void);
69298 static void __call_rcu(struct rcu_head *head,
69299 void (*func)(struct rcu_head *rcu),
69300 struct rcu_ctrlblk *rcp);
69301 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69302 rcu_is_callbacks_kthread()));
69303 }
69304
69305 -static void rcu_process_callbacks(struct softirq_action *unused)
69306 +static void rcu_process_callbacks(void)
69307 {
69308 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69309 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69310 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69311 index 918fd1e..85089bb 100644
69312 --- a/kernel/rcutiny_plugin.h
69313 +++ b/kernel/rcutiny_plugin.h
69314 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69315 have_rcu_kthread_work = morework;
69316 local_irq_restore(flags);
69317 if (work)
69318 - rcu_process_callbacks(NULL);
69319 + rcu_process_callbacks();
69320 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69321 }
69322
69323 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69324 index 25b1503..1988a74 100644
69325 --- a/kernel/rcutorture.c
69326 +++ b/kernel/rcutorture.c
69327 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69328 { 0 };
69329 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69330 { 0 };
69331 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69332 -static atomic_t n_rcu_torture_alloc;
69333 -static atomic_t n_rcu_torture_alloc_fail;
69334 -static atomic_t n_rcu_torture_free;
69335 -static atomic_t n_rcu_torture_mberror;
69336 -static atomic_t n_rcu_torture_error;
69337 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69338 +static atomic_unchecked_t n_rcu_torture_alloc;
69339 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69340 +static atomic_unchecked_t n_rcu_torture_free;
69341 +static atomic_unchecked_t n_rcu_torture_mberror;
69342 +static atomic_unchecked_t n_rcu_torture_error;
69343 static long n_rcu_torture_barrier_error;
69344 static long n_rcu_torture_boost_ktrerror;
69345 static long n_rcu_torture_boost_rterror;
69346 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69347
69348 spin_lock_bh(&rcu_torture_lock);
69349 if (list_empty(&rcu_torture_freelist)) {
69350 - atomic_inc(&n_rcu_torture_alloc_fail);
69351 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69352 spin_unlock_bh(&rcu_torture_lock);
69353 return NULL;
69354 }
69355 - atomic_inc(&n_rcu_torture_alloc);
69356 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69357 p = rcu_torture_freelist.next;
69358 list_del_init(p);
69359 spin_unlock_bh(&rcu_torture_lock);
69360 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69361 static void
69362 rcu_torture_free(struct rcu_torture *p)
69363 {
69364 - atomic_inc(&n_rcu_torture_free);
69365 + atomic_inc_unchecked(&n_rcu_torture_free);
69366 spin_lock_bh(&rcu_torture_lock);
69367 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69368 spin_unlock_bh(&rcu_torture_lock);
69369 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69370 i = rp->rtort_pipe_count;
69371 if (i > RCU_TORTURE_PIPE_LEN)
69372 i = RCU_TORTURE_PIPE_LEN;
69373 - atomic_inc(&rcu_torture_wcount[i]);
69374 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69375 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69376 rp->rtort_mbtest = 0;
69377 rcu_torture_free(rp);
69378 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69379 i = rp->rtort_pipe_count;
69380 if (i > RCU_TORTURE_PIPE_LEN)
69381 i = RCU_TORTURE_PIPE_LEN;
69382 - atomic_inc(&rcu_torture_wcount[i]);
69383 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69384 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69385 rp->rtort_mbtest = 0;
69386 list_del(&rp->rtort_free);
69387 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69388 i = old_rp->rtort_pipe_count;
69389 if (i > RCU_TORTURE_PIPE_LEN)
69390 i = RCU_TORTURE_PIPE_LEN;
69391 - atomic_inc(&rcu_torture_wcount[i]);
69392 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69393 old_rp->rtort_pipe_count++;
69394 cur_ops->deferred_free(old_rp);
69395 }
69396 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69397 }
69398 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69399 if (p->rtort_mbtest == 0)
69400 - atomic_inc(&n_rcu_torture_mberror);
69401 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69402 spin_lock(&rand_lock);
69403 cur_ops->read_delay(&rand);
69404 n_rcu_torture_timers++;
69405 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69406 }
69407 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69408 if (p->rtort_mbtest == 0)
69409 - atomic_inc(&n_rcu_torture_mberror);
69410 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69411 cur_ops->read_delay(&rand);
69412 preempt_disable();
69413 pipe_count = p->rtort_pipe_count;
69414 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69415 rcu_torture_current,
69416 rcu_torture_current_version,
69417 list_empty(&rcu_torture_freelist),
69418 - atomic_read(&n_rcu_torture_alloc),
69419 - atomic_read(&n_rcu_torture_alloc_fail),
69420 - atomic_read(&n_rcu_torture_free));
69421 + atomic_read_unchecked(&n_rcu_torture_alloc),
69422 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69423 + atomic_read_unchecked(&n_rcu_torture_free));
69424 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69425 - atomic_read(&n_rcu_torture_mberror),
69426 + atomic_read_unchecked(&n_rcu_torture_mberror),
69427 n_rcu_torture_boost_ktrerror,
69428 n_rcu_torture_boost_rterror);
69429 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69430 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69431 n_barrier_attempts,
69432 n_rcu_torture_barrier_error);
69433 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69434 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69435 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69436 n_rcu_torture_barrier_error != 0 ||
69437 n_rcu_torture_boost_ktrerror != 0 ||
69438 n_rcu_torture_boost_rterror != 0 ||
69439 n_rcu_torture_boost_failure != 0 ||
69440 i > 1) {
69441 cnt += sprintf(&page[cnt], "!!! ");
69442 - atomic_inc(&n_rcu_torture_error);
69443 + atomic_inc_unchecked(&n_rcu_torture_error);
69444 WARN_ON_ONCE(1);
69445 }
69446 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69447 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69448 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69449 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69450 cnt += sprintf(&page[cnt], " %d",
69451 - atomic_read(&rcu_torture_wcount[i]));
69452 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69453 }
69454 cnt += sprintf(&page[cnt], "\n");
69455 if (cur_ops->stats)
69456 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69457
69458 if (cur_ops->cleanup)
69459 cur_ops->cleanup();
69460 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69461 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69462 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69463 else if (n_online_successes != n_online_attempts ||
69464 n_offline_successes != n_offline_attempts)
69465 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69466
69467 rcu_torture_current = NULL;
69468 rcu_torture_current_version = 0;
69469 - atomic_set(&n_rcu_torture_alloc, 0);
69470 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69471 - atomic_set(&n_rcu_torture_free, 0);
69472 - atomic_set(&n_rcu_torture_mberror, 0);
69473 - atomic_set(&n_rcu_torture_error, 0);
69474 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69475 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69476 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69477 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69478 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69479 n_rcu_torture_barrier_error = 0;
69480 n_rcu_torture_boost_ktrerror = 0;
69481 n_rcu_torture_boost_rterror = 0;
69482 n_rcu_torture_boost_failure = 0;
69483 n_rcu_torture_boosts = 0;
69484 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69485 - atomic_set(&rcu_torture_wcount[i], 0);
69486 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69487 for_each_possible_cpu(cpu) {
69488 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69489 per_cpu(rcu_torture_count, cpu)[i] = 0;
69490 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69491 index f7bcd9e..8973e14 100644
69492 --- a/kernel/rcutree.c
69493 +++ b/kernel/rcutree.c
69494 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69495 rcu_prepare_for_idle(smp_processor_id());
69496 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69497 smp_mb__before_atomic_inc(); /* See above. */
69498 - atomic_inc(&rdtp->dynticks);
69499 + atomic_inc_unchecked(&rdtp->dynticks);
69500 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69501 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69502 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69503
69504 /*
69505 * The idle task is not permitted to enter the idle loop while
69506 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69507 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69508 {
69509 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69510 - atomic_inc(&rdtp->dynticks);
69511 + atomic_inc_unchecked(&rdtp->dynticks);
69512 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69513 smp_mb__after_atomic_inc(); /* See above. */
69514 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69515 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69516 rcu_cleanup_after_idle(smp_processor_id());
69517 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69518 if (!is_idle_task(current)) {
69519 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69520 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69521
69522 if (rdtp->dynticks_nmi_nesting == 0 &&
69523 - (atomic_read(&rdtp->dynticks) & 0x1))
69524 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69525 return;
69526 rdtp->dynticks_nmi_nesting++;
69527 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69528 - atomic_inc(&rdtp->dynticks);
69529 + atomic_inc_unchecked(&rdtp->dynticks);
69530 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69531 smp_mb__after_atomic_inc(); /* See above. */
69532 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69533 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69534 }
69535
69536 /**
69537 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69538 return;
69539 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69540 smp_mb__before_atomic_inc(); /* See above. */
69541 - atomic_inc(&rdtp->dynticks);
69542 + atomic_inc_unchecked(&rdtp->dynticks);
69543 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69544 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69545 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69546 }
69547
69548 /**
69549 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69550 int ret;
69551
69552 preempt_disable();
69553 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69554 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69555 preempt_enable();
69556 return ret;
69557 }
69558 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69559 */
69560 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69561 {
69562 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69563 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69564 return (rdp->dynticks_snap & 0x1) == 0;
69565 }
69566
69567 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69568 unsigned int curr;
69569 unsigned int snap;
69570
69571 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69572 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69573 snap = (unsigned int)rdp->dynticks_snap;
69574
69575 /*
69576 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69577 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69578 */
69579 if (till_stall_check < 3) {
69580 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69581 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69582 till_stall_check = 3;
69583 } else if (till_stall_check > 300) {
69584 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69585 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69586 till_stall_check = 300;
69587 }
69588 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69589 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69590 rsp->qlen += rdp->qlen;
69591 rdp->n_cbs_orphaned += rdp->qlen;
69592 rdp->qlen_lazy = 0;
69593 - ACCESS_ONCE(rdp->qlen) = 0;
69594 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69595 }
69596
69597 /*
69598 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69599 }
69600 smp_mb(); /* List handling before counting for rcu_barrier(). */
69601 rdp->qlen_lazy -= count_lazy;
69602 - ACCESS_ONCE(rdp->qlen) -= count;
69603 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69604 rdp->n_cbs_invoked += count;
69605
69606 /* Reinstate batch limit if we have worked down the excess. */
69607 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69608 /*
69609 * Do RCU core processing for the current CPU.
69610 */
69611 -static void rcu_process_callbacks(struct softirq_action *unused)
69612 +static void rcu_process_callbacks(void)
69613 {
69614 struct rcu_state *rsp;
69615
69616 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69617 rdp = this_cpu_ptr(rsp->rda);
69618
69619 /* Add the callback to our list. */
69620 - ACCESS_ONCE(rdp->qlen)++;
69621 + ACCESS_ONCE_RW(rdp->qlen)++;
69622 if (lazy)
69623 rdp->qlen_lazy++;
69624 else
69625 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69626 }
69627 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69628
69629 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69630 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69631 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69632 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69633
69634 static int synchronize_sched_expedited_cpu_stop(void *data)
69635 {
69636 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69637 int firstsnap, s, snap, trycount = 0;
69638
69639 /* Note that atomic_inc_return() implies full memory barrier. */
69640 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69641 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69642 get_online_cpus();
69643 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69644
69645 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69646 }
69647
69648 /* Check to see if someone else did our work for us. */
69649 - s = atomic_read(&sync_sched_expedited_done);
69650 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69651 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69652 smp_mb(); /* ensure test happens before caller kfree */
69653 return;
69654 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69655 * grace period works for us.
69656 */
69657 get_online_cpus();
69658 - snap = atomic_read(&sync_sched_expedited_started);
69659 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69660 smp_mb(); /* ensure read is before try_stop_cpus(). */
69661 }
69662
69663 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69664 * than we did beat us to the punch.
69665 */
69666 do {
69667 - s = atomic_read(&sync_sched_expedited_done);
69668 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69669 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69670 smp_mb(); /* ensure test happens before caller kfree */
69671 break;
69672 }
69673 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69674 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69675
69676 put_online_cpus();
69677 }
69678 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69679 * ACCESS_ONCE() to prevent the compiler from speculating
69680 * the increment to precede the early-exit check.
69681 */
69682 - ACCESS_ONCE(rsp->n_barrier_done)++;
69683 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69684 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69685 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69686 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69687 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69688
69689 /* Increment ->n_barrier_done to prevent duplicate work. */
69690 smp_mb(); /* Keep increment after above mechanism. */
69691 - ACCESS_ONCE(rsp->n_barrier_done)++;
69692 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69693 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69694 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69695 smp_mb(); /* Keep increment before caller's subsequent code. */
69696 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69697 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69698 init_callback_list(rdp);
69699 rdp->qlen_lazy = 0;
69700 - ACCESS_ONCE(rdp->qlen) = 0;
69701 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69702 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69703 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69704 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69705 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69706 rdp->cpu = cpu;
69707 rdp->rsp = rsp;
69708 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69709 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69710 rdp->n_force_qs_snap = rsp->n_force_qs;
69711 rdp->blimit = blimit;
69712 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69713 - atomic_set(&rdp->dynticks->dynticks,
69714 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69715 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69716 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69717 rcu_prepare_for_idle_init(cpu);
69718 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69719
69720 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69721 index 4d29169..d104a3c 100644
69722 --- a/kernel/rcutree.h
69723 +++ b/kernel/rcutree.h
69724 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69725 long long dynticks_nesting; /* Track irq/process nesting level. */
69726 /* Process level is worth LLONG_MAX/2. */
69727 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69728 - atomic_t dynticks; /* Even value for idle, else odd. */
69729 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69730 #ifdef CONFIG_RCU_FAST_NO_HZ
69731 int dyntick_drain; /* Prepare-for-idle state variable. */
69732 unsigned long dyntick_holdoff;
69733 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69734 index 7f3244c..417d606 100644
69735 --- a/kernel/rcutree_plugin.h
69736 +++ b/kernel/rcutree_plugin.h
69737 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69738
69739 /* Clean up and exit. */
69740 smp_mb(); /* ensure expedited GP seen before counter increment. */
69741 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69742 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69743 unlock_mb_ret:
69744 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69745 mb_ret:
69746 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69747 index abffb48..cbfa6d3 100644
69748 --- a/kernel/rcutree_trace.c
69749 +++ b/kernel/rcutree_trace.c
69750 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69751 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69752 rdp->qs_pending);
69753 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69754 - atomic_read(&rdp->dynticks->dynticks),
69755 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69756 rdp->dynticks->dynticks_nesting,
69757 rdp->dynticks->dynticks_nmi_nesting,
69758 rdp->dynticks_fqs);
69759 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69760 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69761 rdp->qs_pending);
69762 seq_printf(m, ",%d,%llx,%d,%lu",
69763 - atomic_read(&rdp->dynticks->dynticks),
69764 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69765 rdp->dynticks->dynticks_nesting,
69766 rdp->dynticks->dynticks_nmi_nesting,
69767 rdp->dynticks_fqs);
69768 diff --git a/kernel/resource.c b/kernel/resource.c
69769 index 34d4588..10baa6a 100644
69770 --- a/kernel/resource.c
69771 +++ b/kernel/resource.c
69772 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69773
69774 static int __init ioresources_init(void)
69775 {
69776 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69777 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69778 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69779 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69780 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69781 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69782 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69783 +#endif
69784 +#else
69785 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69786 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69787 +#endif
69788 return 0;
69789 }
69790 __initcall(ioresources_init);
69791 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69792 index 98ec494..4241d6d 100644
69793 --- a/kernel/rtmutex-tester.c
69794 +++ b/kernel/rtmutex-tester.c
69795 @@ -20,7 +20,7 @@
69796 #define MAX_RT_TEST_MUTEXES 8
69797
69798 static spinlock_t rttest_lock;
69799 -static atomic_t rttest_event;
69800 +static atomic_unchecked_t rttest_event;
69801
69802 struct test_thread_data {
69803 int opcode;
69804 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69805
69806 case RTTEST_LOCKCONT:
69807 td->mutexes[td->opdata] = 1;
69808 - td->event = atomic_add_return(1, &rttest_event);
69809 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69810 return 0;
69811
69812 case RTTEST_RESET:
69813 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69814 return 0;
69815
69816 case RTTEST_RESETEVENT:
69817 - atomic_set(&rttest_event, 0);
69818 + atomic_set_unchecked(&rttest_event, 0);
69819 return 0;
69820
69821 default:
69822 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69823 return ret;
69824
69825 td->mutexes[id] = 1;
69826 - td->event = atomic_add_return(1, &rttest_event);
69827 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69828 rt_mutex_lock(&mutexes[id]);
69829 - td->event = atomic_add_return(1, &rttest_event);
69830 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69831 td->mutexes[id] = 4;
69832 return 0;
69833
69834 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69835 return ret;
69836
69837 td->mutexes[id] = 1;
69838 - td->event = atomic_add_return(1, &rttest_event);
69839 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69840 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69841 - td->event = atomic_add_return(1, &rttest_event);
69842 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69843 td->mutexes[id] = ret ? 0 : 4;
69844 return ret ? -EINTR : 0;
69845
69846 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69847 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69848 return ret;
69849
69850 - td->event = atomic_add_return(1, &rttest_event);
69851 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69852 rt_mutex_unlock(&mutexes[id]);
69853 - td->event = atomic_add_return(1, &rttest_event);
69854 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69855 td->mutexes[id] = 0;
69856 return 0;
69857
69858 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69859 break;
69860
69861 td->mutexes[dat] = 2;
69862 - td->event = atomic_add_return(1, &rttest_event);
69863 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69864 break;
69865
69866 default:
69867 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69868 return;
69869
69870 td->mutexes[dat] = 3;
69871 - td->event = atomic_add_return(1, &rttest_event);
69872 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69873 break;
69874
69875 case RTTEST_LOCKNOWAIT:
69876 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69877 return;
69878
69879 td->mutexes[dat] = 1;
69880 - td->event = atomic_add_return(1, &rttest_event);
69881 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69882 return;
69883
69884 default:
69885 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69886 index 0984a21..939f183 100644
69887 --- a/kernel/sched/auto_group.c
69888 +++ b/kernel/sched/auto_group.c
69889 @@ -11,7 +11,7 @@
69890
69891 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69892 static struct autogroup autogroup_default;
69893 -static atomic_t autogroup_seq_nr;
69894 +static atomic_unchecked_t autogroup_seq_nr;
69895
69896 void __init autogroup_init(struct task_struct *init_task)
69897 {
69898 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69899
69900 kref_init(&ag->kref);
69901 init_rwsem(&ag->lock);
69902 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69903 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69904 ag->tg = tg;
69905 #ifdef CONFIG_RT_GROUP_SCHED
69906 /*
69907 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69908 index 1a48cdb..d3949ff 100644
69909 --- a/kernel/sched/core.c
69910 +++ b/kernel/sched/core.c
69911 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69912 /* convert nice value [19,-20] to rlimit style value [1,40] */
69913 int nice_rlim = 20 - nice;
69914
69915 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69916 +
69917 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69918 capable(CAP_SYS_NICE));
69919 }
69920 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69921 if (nice > 19)
69922 nice = 19;
69923
69924 - if (increment < 0 && !can_nice(current, nice))
69925 + if (increment < 0 && (!can_nice(current, nice) ||
69926 + gr_handle_chroot_nice()))
69927 return -EPERM;
69928
69929 retval = security_task_setnice(current, nice);
69930 @@ -4290,6 +4293,7 @@ recheck:
69931 unsigned long rlim_rtprio =
69932 task_rlimit(p, RLIMIT_RTPRIO);
69933
69934 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69935 /* can't set/change the rt policy */
69936 if (policy != p->policy && !rlim_rtprio)
69937 return -EPERM;
69938 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69939 index 96e2b18..bb31eec 100644
69940 --- a/kernel/sched/fair.c
69941 +++ b/kernel/sched/fair.c
69942 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69943 * run_rebalance_domains is triggered when needed from the scheduler tick.
69944 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69945 */
69946 -static void run_rebalance_domains(struct softirq_action *h)
69947 +static void run_rebalance_domains(void)
69948 {
69949 int this_cpu = smp_processor_id();
69950 struct rq *this_rq = cpu_rq(this_cpu);
69951 diff --git a/kernel/signal.c b/kernel/signal.c
69952 index be4f856..453401c 100644
69953 --- a/kernel/signal.c
69954 +++ b/kernel/signal.c
69955 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69956
69957 int print_fatal_signals __read_mostly;
69958
69959 -static void __user *sig_handler(struct task_struct *t, int sig)
69960 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69961 {
69962 return t->sighand->action[sig - 1].sa.sa_handler;
69963 }
69964
69965 -static int sig_handler_ignored(void __user *handler, int sig)
69966 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69967 {
69968 /* Is it explicitly or implicitly ignored? */
69969 return handler == SIG_IGN ||
69970 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69971
69972 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69973 {
69974 - void __user *handler;
69975 + __sighandler_t handler;
69976
69977 handler = sig_handler(t, sig);
69978
69979 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69980 atomic_inc(&user->sigpending);
69981 rcu_read_unlock();
69982
69983 + if (!override_rlimit)
69984 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69985 +
69986 if (override_rlimit ||
69987 atomic_read(&user->sigpending) <=
69988 task_rlimit(t, RLIMIT_SIGPENDING)) {
69989 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69990
69991 int unhandled_signal(struct task_struct *tsk, int sig)
69992 {
69993 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69994 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69995 if (is_global_init(tsk))
69996 return 1;
69997 if (handler != SIG_IGN && handler != SIG_DFL)
69998 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69999 }
70000 }
70001
70002 + /* allow glibc communication via tgkill to other threads in our
70003 + thread group */
70004 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70005 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70006 + && gr_handle_signal(t, sig))
70007 + return -EPERM;
70008 +
70009 return security_task_kill(t, info, sig, 0);
70010 }
70011
70012 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70013 return send_signal(sig, info, p, 1);
70014 }
70015
70016 -static int
70017 +int
70018 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70019 {
70020 return send_signal(sig, info, t, 0);
70021 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70022 unsigned long int flags;
70023 int ret, blocked, ignored;
70024 struct k_sigaction *action;
70025 + int is_unhandled = 0;
70026
70027 spin_lock_irqsave(&t->sighand->siglock, flags);
70028 action = &t->sighand->action[sig-1];
70029 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70030 }
70031 if (action->sa.sa_handler == SIG_DFL)
70032 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70033 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70034 + is_unhandled = 1;
70035 ret = specific_send_sig_info(sig, info, t);
70036 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70037
70038 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70039 + normal operation */
70040 + if (is_unhandled) {
70041 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70042 + gr_handle_crash(t, sig);
70043 + }
70044 +
70045 return ret;
70046 }
70047
70048 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70049 ret = check_kill_permission(sig, info, p);
70050 rcu_read_unlock();
70051
70052 - if (!ret && sig)
70053 + if (!ret && sig) {
70054 ret = do_send_sig_info(sig, info, p, true);
70055 + if (!ret)
70056 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70057 + }
70058
70059 return ret;
70060 }
70061 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70062 int error = -ESRCH;
70063
70064 rcu_read_lock();
70065 - p = find_task_by_vpid(pid);
70066 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70067 + /* allow glibc communication via tgkill to other threads in our
70068 + thread group */
70069 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70070 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70071 + p = find_task_by_vpid_unrestricted(pid);
70072 + else
70073 +#endif
70074 + p = find_task_by_vpid(pid);
70075 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70076 error = check_kill_permission(sig, info, p);
70077 /*
70078 diff --git a/kernel/softirq.c b/kernel/softirq.c
70079 index b73e681..645ab62 100644
70080 --- a/kernel/softirq.c
70081 +++ b/kernel/softirq.c
70082 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70083
70084 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70085
70086 -char *softirq_to_name[NR_SOFTIRQS] = {
70087 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70088 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70089 "TASKLET", "SCHED", "HRTIMER", "RCU"
70090 };
70091 @@ -243,7 +243,7 @@ restart:
70092 kstat_incr_softirqs_this_cpu(vec_nr);
70093
70094 trace_softirq_entry(vec_nr);
70095 - h->action(h);
70096 + h->action();
70097 trace_softirq_exit(vec_nr);
70098 if (unlikely(prev_count != preempt_count())) {
70099 printk(KERN_ERR "huh, entered softirq %u %s %p"
70100 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70101 or_softirq_pending(1UL << nr);
70102 }
70103
70104 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70105 +void open_softirq(int nr, void (*action)(void))
70106 {
70107 - softirq_vec[nr].action = action;
70108 + pax_open_kernel();
70109 + *(void **)&softirq_vec[nr].action = action;
70110 + pax_close_kernel();
70111 }
70112
70113 /*
70114 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70115
70116 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70117
70118 -static void tasklet_action(struct softirq_action *a)
70119 +static void tasklet_action(void)
70120 {
70121 struct tasklet_struct *list;
70122
70123 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70124 }
70125 }
70126
70127 -static void tasklet_hi_action(struct softirq_action *a)
70128 +static void tasklet_hi_action(void)
70129 {
70130 struct tasklet_struct *list;
70131
70132 diff --git a/kernel/srcu.c b/kernel/srcu.c
70133 index 2095be3..9a5b89d 100644
70134 --- a/kernel/srcu.c
70135 +++ b/kernel/srcu.c
70136 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70137 preempt_disable();
70138 idx = rcu_dereference_index_check(sp->completed,
70139 rcu_read_lock_sched_held()) & 0x1;
70140 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70141 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70142 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70143 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70144 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70145 preempt_enable();
70146 return idx;
70147 }
70148 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70149 {
70150 preempt_disable();
70151 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70152 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70153 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70154 preempt_enable();
70155 }
70156 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70157 diff --git a/kernel/sys.c b/kernel/sys.c
70158 index 909148a..cd51acf 100644
70159 --- a/kernel/sys.c
70160 +++ b/kernel/sys.c
70161 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70162 error = -EACCES;
70163 goto out;
70164 }
70165 +
70166 + if (gr_handle_chroot_setpriority(p, niceval)) {
70167 + error = -EACCES;
70168 + goto out;
70169 + }
70170 +
70171 no_nice = security_task_setnice(p, niceval);
70172 if (no_nice) {
70173 error = no_nice;
70174 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70175 goto error;
70176 }
70177
70178 + if (gr_check_group_change(new->gid, new->egid, -1))
70179 + goto error;
70180 +
70181 if (rgid != (gid_t) -1 ||
70182 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70183 new->sgid = new->egid;
70184 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70185 old = current_cred();
70186
70187 retval = -EPERM;
70188 +
70189 + if (gr_check_group_change(kgid, kgid, kgid))
70190 + goto error;
70191 +
70192 if (nsown_capable(CAP_SETGID))
70193 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70194 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70195 @@ -647,7 +660,7 @@ error:
70196 /*
70197 * change the user struct in a credentials set to match the new UID
70198 */
70199 -static int set_user(struct cred *new)
70200 +int set_user(struct cred *new)
70201 {
70202 struct user_struct *new_user;
70203
70204 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70205 goto error;
70206 }
70207
70208 + if (gr_check_user_change(new->uid, new->euid, -1))
70209 + goto error;
70210 +
70211 if (!uid_eq(new->uid, old->uid)) {
70212 retval = set_user(new);
70213 if (retval < 0)
70214 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70215 old = current_cred();
70216
70217 retval = -EPERM;
70218 +
70219 + if (gr_check_crash_uid(kuid))
70220 + goto error;
70221 + if (gr_check_user_change(kuid, kuid, kuid))
70222 + goto error;
70223 +
70224 if (nsown_capable(CAP_SETUID)) {
70225 new->suid = new->uid = kuid;
70226 if (!uid_eq(kuid, old->uid)) {
70227 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70228 goto error;
70229 }
70230
70231 + if (gr_check_user_change(kruid, keuid, -1))
70232 + goto error;
70233 +
70234 if (ruid != (uid_t) -1) {
70235 new->uid = kruid;
70236 if (!uid_eq(kruid, old->uid)) {
70237 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70238 goto error;
70239 }
70240
70241 + if (gr_check_group_change(krgid, kegid, -1))
70242 + goto error;
70243 +
70244 if (rgid != (gid_t) -1)
70245 new->gid = krgid;
70246 if (egid != (gid_t) -1)
70247 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70248 if (!uid_valid(kuid))
70249 return old_fsuid;
70250
70251 + if (gr_check_user_change(-1, -1, kuid))
70252 + goto error;
70253 +
70254 new = prepare_creds();
70255 if (!new)
70256 return old_fsuid;
70257 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70258 }
70259 }
70260
70261 +error:
70262 abort_creds(new);
70263 return old_fsuid;
70264
70265 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70266 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70267 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70268 nsown_capable(CAP_SETGID)) {
70269 + if (gr_check_group_change(-1, -1, kgid))
70270 + goto error;
70271 +
70272 if (!gid_eq(kgid, old->fsgid)) {
70273 new->fsgid = kgid;
70274 goto change_okay;
70275 }
70276 }
70277
70278 +error:
70279 abort_creds(new);
70280 return old_fsgid;
70281
70282 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70283 return -EFAULT;
70284
70285 down_read(&uts_sem);
70286 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70287 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70288 __OLD_UTS_LEN);
70289 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70290 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70291 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70292 __OLD_UTS_LEN);
70293 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70294 - error |= __copy_to_user(&name->release, &utsname()->release,
70295 + error |= __copy_to_user(name->release, &utsname()->release,
70296 __OLD_UTS_LEN);
70297 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70298 - error |= __copy_to_user(&name->version, &utsname()->version,
70299 + error |= __copy_to_user(name->version, &utsname()->version,
70300 __OLD_UTS_LEN);
70301 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70302 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70303 + error |= __copy_to_user(name->machine, &utsname()->machine,
70304 __OLD_UTS_LEN);
70305 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70306 up_read(&uts_sem);
70307 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70308 error = get_dumpable(me->mm);
70309 break;
70310 case PR_SET_DUMPABLE:
70311 - if (arg2 < 0 || arg2 > 1) {
70312 + if (arg2 > 1) {
70313 error = -EINVAL;
70314 break;
70315 }
70316 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70317 index 87174ef..68cbb82 100644
70318 --- a/kernel/sysctl.c
70319 +++ b/kernel/sysctl.c
70320 @@ -92,7 +92,6 @@
70321
70322
70323 #if defined(CONFIG_SYSCTL)
70324 -
70325 /* External variables not in a header file. */
70326 extern int sysctl_overcommit_memory;
70327 extern int sysctl_overcommit_ratio;
70328 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70329 void __user *buffer, size_t *lenp, loff_t *ppos);
70330 #endif
70331
70332 -#ifdef CONFIG_PRINTK
70333 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70334 void __user *buffer, size_t *lenp, loff_t *ppos);
70335 -#endif
70336
70337 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70338 void __user *buffer, size_t *lenp, loff_t *ppos);
70339 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70340
70341 #endif
70342
70343 +extern struct ctl_table grsecurity_table[];
70344 +
70345 static struct ctl_table kern_table[];
70346 static struct ctl_table vm_table[];
70347 static struct ctl_table fs_table[];
70348 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70349 int sysctl_legacy_va_layout;
70350 #endif
70351
70352 +#ifdef CONFIG_PAX_SOFTMODE
70353 +static ctl_table pax_table[] = {
70354 + {
70355 + .procname = "softmode",
70356 + .data = &pax_softmode,
70357 + .maxlen = sizeof(unsigned int),
70358 + .mode = 0600,
70359 + .proc_handler = &proc_dointvec,
70360 + },
70361 +
70362 + { }
70363 +};
70364 +#endif
70365 +
70366 /* The default sysctl tables: */
70367
70368 static struct ctl_table sysctl_base_table[] = {
70369 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70370 #endif
70371
70372 static struct ctl_table kern_table[] = {
70373 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70374 + {
70375 + .procname = "grsecurity",
70376 + .mode = 0500,
70377 + .child = grsecurity_table,
70378 + },
70379 +#endif
70380 +
70381 +#ifdef CONFIG_PAX_SOFTMODE
70382 + {
70383 + .procname = "pax",
70384 + .mode = 0500,
70385 + .child = pax_table,
70386 + },
70387 +#endif
70388 +
70389 {
70390 .procname = "sched_child_runs_first",
70391 .data = &sysctl_sched_child_runs_first,
70392 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70393 .data = &modprobe_path,
70394 .maxlen = KMOD_PATH_LEN,
70395 .mode = 0644,
70396 - .proc_handler = proc_dostring,
70397 + .proc_handler = proc_dostring_modpriv,
70398 },
70399 {
70400 .procname = "modules_disabled",
70401 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70402 .extra1 = &zero,
70403 .extra2 = &one,
70404 },
70405 +#endif
70406 {
70407 .procname = "kptr_restrict",
70408 .data = &kptr_restrict,
70409 .maxlen = sizeof(int),
70410 .mode = 0644,
70411 .proc_handler = proc_dointvec_minmax_sysadmin,
70412 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70413 + .extra1 = &two,
70414 +#else
70415 .extra1 = &zero,
70416 +#endif
70417 .extra2 = &two,
70418 },
70419 -#endif
70420 {
70421 .procname = "ngroups_max",
70422 .data = &ngroups_max,
70423 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70424 .proc_handler = proc_dointvec_minmax,
70425 .extra1 = &zero,
70426 },
70427 + {
70428 + .procname = "heap_stack_gap",
70429 + .data = &sysctl_heap_stack_gap,
70430 + .maxlen = sizeof(sysctl_heap_stack_gap),
70431 + .mode = 0644,
70432 + .proc_handler = proc_doulongvec_minmax,
70433 + },
70434 #else
70435 {
70436 .procname = "nr_trim_pages",
70437 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70438 buffer, lenp, ppos);
70439 }
70440
70441 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70442 + void __user *buffer, size_t *lenp, loff_t *ppos)
70443 +{
70444 + if (write && !capable(CAP_SYS_MODULE))
70445 + return -EPERM;
70446 +
70447 + return _proc_do_string(table->data, table->maxlen, write,
70448 + buffer, lenp, ppos);
70449 +}
70450 +
70451 static size_t proc_skip_spaces(char **buf)
70452 {
70453 size_t ret;
70454 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70455 len = strlen(tmp);
70456 if (len > *size)
70457 len = *size;
70458 + if (len > sizeof(tmp))
70459 + len = sizeof(tmp);
70460 if (copy_to_user(*buf, tmp, len))
70461 return -EFAULT;
70462 *size -= len;
70463 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70464 return err;
70465 }
70466
70467 -#ifdef CONFIG_PRINTK
70468 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70469 void __user *buffer, size_t *lenp, loff_t *ppos)
70470 {
70471 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70472
70473 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70474 }
70475 -#endif
70476
70477 struct do_proc_dointvec_minmax_conv_param {
70478 int *min;
70479 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70480 *i = val;
70481 } else {
70482 val = convdiv * (*i) / convmul;
70483 - if (!first)
70484 + if (!first) {
70485 err = proc_put_char(&buffer, &left, '\t');
70486 + if (err)
70487 + break;
70488 + }
70489 err = proc_put_long(&buffer, &left, val, false);
70490 if (err)
70491 break;
70492 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70493 return -ENOSYS;
70494 }
70495
70496 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70497 + void __user *buffer, size_t *lenp, loff_t *ppos)
70498 +{
70499 + return -ENOSYS;
70500 +}
70501 +
70502 int proc_dointvec(struct ctl_table *table, int write,
70503 void __user *buffer, size_t *lenp, loff_t *ppos)
70504 {
70505 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70506 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70507 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70508 EXPORT_SYMBOL(proc_dostring);
70509 +EXPORT_SYMBOL(proc_dostring_modpriv);
70510 EXPORT_SYMBOL(proc_doulongvec_minmax);
70511 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70512 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70513 index 65bdcf1..21eb831 100644
70514 --- a/kernel/sysctl_binary.c
70515 +++ b/kernel/sysctl_binary.c
70516 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70517 int i;
70518
70519 set_fs(KERNEL_DS);
70520 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70521 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70522 set_fs(old_fs);
70523 if (result < 0)
70524 goto out_kfree;
70525 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70526 }
70527
70528 set_fs(KERNEL_DS);
70529 - result = vfs_write(file, buffer, str - buffer, &pos);
70530 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70531 set_fs(old_fs);
70532 if (result < 0)
70533 goto out_kfree;
70534 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70535 int i;
70536
70537 set_fs(KERNEL_DS);
70538 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70539 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70540 set_fs(old_fs);
70541 if (result < 0)
70542 goto out_kfree;
70543 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70544 }
70545
70546 set_fs(KERNEL_DS);
70547 - result = vfs_write(file, buffer, str - buffer, &pos);
70548 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70549 set_fs(old_fs);
70550 if (result < 0)
70551 goto out_kfree;
70552 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70553 int i;
70554
70555 set_fs(KERNEL_DS);
70556 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70557 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70558 set_fs(old_fs);
70559 if (result < 0)
70560 goto out;
70561 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70562 __le16 dnaddr;
70563
70564 set_fs(KERNEL_DS);
70565 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70566 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70567 set_fs(old_fs);
70568 if (result < 0)
70569 goto out;
70570 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70571 le16_to_cpu(dnaddr) & 0x3ff);
70572
70573 set_fs(KERNEL_DS);
70574 - result = vfs_write(file, buf, len, &pos);
70575 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70576 set_fs(old_fs);
70577 if (result < 0)
70578 goto out;
70579 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70580 index d0a3279..db0ad99 100644
70581 --- a/kernel/taskstats.c
70582 +++ b/kernel/taskstats.c
70583 @@ -27,9 +27,12 @@
70584 #include <linux/cgroup.h>
70585 #include <linux/fs.h>
70586 #include <linux/file.h>
70587 +#include <linux/grsecurity.h>
70588 #include <net/genetlink.h>
70589 #include <linux/atomic.h>
70590
70591 +extern int gr_is_taskstats_denied(int pid);
70592 +
70593 /*
70594 * Maximum length of a cpumask that can be specified in
70595 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70596 @@ -561,6 +564,9 @@ err:
70597
70598 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70599 {
70600 + if (gr_is_taskstats_denied(current->pid))
70601 + return -EACCES;
70602 +
70603 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70604 return cmd_attr_register_cpumask(info);
70605 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70606 diff --git a/kernel/time.c b/kernel/time.c
70607 index ba744cf..267b7c5 100644
70608 --- a/kernel/time.c
70609 +++ b/kernel/time.c
70610 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70611 return error;
70612
70613 if (tz) {
70614 + /* we log in do_settimeofday called below, so don't log twice
70615 + */
70616 + if (!tv)
70617 + gr_log_timechange();
70618 +
70619 sys_tz = *tz;
70620 update_vsyscall_tz();
70621 if (firsttime) {
70622 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70623 index aa27d39..34d221c 100644
70624 --- a/kernel/time/alarmtimer.c
70625 +++ b/kernel/time/alarmtimer.c
70626 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70627 struct platform_device *pdev;
70628 int error = 0;
70629 int i;
70630 - struct k_clock alarm_clock = {
70631 + static struct k_clock alarm_clock = {
70632 .clock_getres = alarm_clock_getres,
70633 .clock_get = alarm_clock_get,
70634 .timer_create = alarm_timer_create,
70635 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70636 index f113755..ec24223 100644
70637 --- a/kernel/time/tick-broadcast.c
70638 +++ b/kernel/time/tick-broadcast.c
70639 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70640 * then clear the broadcast bit.
70641 */
70642 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70643 - int cpu = smp_processor_id();
70644 + cpu = smp_processor_id();
70645
70646 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70647 tick_broadcast_clear_oneshot(cpu);
70648 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70649 index f791637..00051de 100644
70650 --- a/kernel/time/timekeeping.c
70651 +++ b/kernel/time/timekeeping.c
70652 @@ -14,6 +14,7 @@
70653 #include <linux/init.h>
70654 #include <linux/mm.h>
70655 #include <linux/sched.h>
70656 +#include <linux/grsecurity.h>
70657 #include <linux/syscore_ops.h>
70658 #include <linux/clocksource.h>
70659 #include <linux/jiffies.h>
70660 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70661 if (!timespec_valid_strict(tv))
70662 return -EINVAL;
70663
70664 + gr_log_timechange();
70665 +
70666 write_seqlock_irqsave(&tk->lock, flags);
70667
70668 timekeeping_forward_now(tk);
70669 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70670 index af5a7e9..715611a 100644
70671 --- a/kernel/time/timer_list.c
70672 +++ b/kernel/time/timer_list.c
70673 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70674
70675 static void print_name_offset(struct seq_file *m, void *sym)
70676 {
70677 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70678 + SEQ_printf(m, "<%p>", NULL);
70679 +#else
70680 char symname[KSYM_NAME_LEN];
70681
70682 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70683 SEQ_printf(m, "<%pK>", sym);
70684 else
70685 SEQ_printf(m, "%s", symname);
70686 +#endif
70687 }
70688
70689 static void
70690 @@ -112,7 +116,11 @@ next_one:
70691 static void
70692 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70693 {
70694 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70695 + SEQ_printf(m, " .base: %p\n", NULL);
70696 +#else
70697 SEQ_printf(m, " .base: %pK\n", base);
70698 +#endif
70699 SEQ_printf(m, " .index: %d\n",
70700 base->index);
70701 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70702 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70703 {
70704 struct proc_dir_entry *pe;
70705
70706 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70707 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70708 +#else
70709 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70710 +#endif
70711 if (!pe)
70712 return -ENOMEM;
70713 return 0;
70714 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70715 index 0b537f2..40d6c20 100644
70716 --- a/kernel/time/timer_stats.c
70717 +++ b/kernel/time/timer_stats.c
70718 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70719 static unsigned long nr_entries;
70720 static struct entry entries[MAX_ENTRIES];
70721
70722 -static atomic_t overflow_count;
70723 +static atomic_unchecked_t overflow_count;
70724
70725 /*
70726 * The entries are in a hash-table, for fast lookup:
70727 @@ -140,7 +140,7 @@ static void reset_entries(void)
70728 nr_entries = 0;
70729 memset(entries, 0, sizeof(entries));
70730 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70731 - atomic_set(&overflow_count, 0);
70732 + atomic_set_unchecked(&overflow_count, 0);
70733 }
70734
70735 static struct entry *alloc_entry(void)
70736 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70737 if (likely(entry))
70738 entry->count++;
70739 else
70740 - atomic_inc(&overflow_count);
70741 + atomic_inc_unchecked(&overflow_count);
70742
70743 out_unlock:
70744 raw_spin_unlock_irqrestore(lock, flags);
70745 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70746
70747 static void print_name_offset(struct seq_file *m, unsigned long addr)
70748 {
70749 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70750 + seq_printf(m, "<%p>", NULL);
70751 +#else
70752 char symname[KSYM_NAME_LEN];
70753
70754 if (lookup_symbol_name(addr, symname) < 0)
70755 - seq_printf(m, "<%p>", (void *)addr);
70756 + seq_printf(m, "<%pK>", (void *)addr);
70757 else
70758 seq_printf(m, "%s", symname);
70759 +#endif
70760 }
70761
70762 static int tstats_show(struct seq_file *m, void *v)
70763 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70764
70765 seq_puts(m, "Timer Stats Version: v0.2\n");
70766 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70767 - if (atomic_read(&overflow_count))
70768 + if (atomic_read_unchecked(&overflow_count))
70769 seq_printf(m, "Overflow: %d entries\n",
70770 - atomic_read(&overflow_count));
70771 + atomic_read_unchecked(&overflow_count));
70772
70773 for (i = 0; i < nr_entries; i++) {
70774 entry = entries + i;
70775 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70776 {
70777 struct proc_dir_entry *pe;
70778
70779 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70780 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70781 +#else
70782 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70783 +#endif
70784 if (!pe)
70785 return -ENOMEM;
70786 return 0;
70787 diff --git a/kernel/timer.c b/kernel/timer.c
70788 index 46ef2b1..ad081f144 100644
70789 --- a/kernel/timer.c
70790 +++ b/kernel/timer.c
70791 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
70792 /*
70793 * This function runs timers and the timer-tq in bottom half context.
70794 */
70795 -static void run_timer_softirq(struct softirq_action *h)
70796 +static void run_timer_softirq(void)
70797 {
70798 struct tvec_base *base = __this_cpu_read(tvec_bases);
70799
70800 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70801 index c0bd030..62a1927 100644
70802 --- a/kernel/trace/blktrace.c
70803 +++ b/kernel/trace/blktrace.c
70804 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70805 struct blk_trace *bt = filp->private_data;
70806 char buf[16];
70807
70808 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70809 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70810
70811 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70812 }
70813 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70814 return 1;
70815
70816 bt = buf->chan->private_data;
70817 - atomic_inc(&bt->dropped);
70818 + atomic_inc_unchecked(&bt->dropped);
70819 return 0;
70820 }
70821
70822 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70823
70824 bt->dir = dir;
70825 bt->dev = dev;
70826 - atomic_set(&bt->dropped, 0);
70827 + atomic_set_unchecked(&bt->dropped, 0);
70828
70829 ret = -EIO;
70830 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70831 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70832 index b4f20fb..483c5fa 100644
70833 --- a/kernel/trace/ftrace.c
70834 +++ b/kernel/trace/ftrace.c
70835 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70836 if (unlikely(ftrace_disabled))
70837 return 0;
70838
70839 + ret = ftrace_arch_code_modify_prepare();
70840 + FTRACE_WARN_ON(ret);
70841 + if (ret)
70842 + return 0;
70843 +
70844 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70845 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70846 if (ret) {
70847 ftrace_bug(ret, ip);
70848 - return 0;
70849 }
70850 - return 1;
70851 + return ret ? 0 : 1;
70852 }
70853
70854 /*
70855 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70856
70857 int
70858 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70859 - void *data)
70860 + void *data)
70861 {
70862 struct ftrace_func_probe *entry;
70863 struct ftrace_page *pg;
70864 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70865 if (!count)
70866 return 0;
70867
70868 + pax_open_kernel();
70869 sort(start, count, sizeof(*start),
70870 ftrace_cmp_ips, ftrace_swap_ips);
70871 + pax_close_kernel();
70872
70873 start_pg = ftrace_allocate_pages(count);
70874 if (!start_pg)
70875 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70876 index 5c38c81..88012af 100644
70877 --- a/kernel/trace/trace.c
70878 +++ b/kernel/trace/trace.c
70879 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70880 };
70881 #endif
70882
70883 -static struct dentry *d_tracer;
70884 -
70885 struct dentry *tracing_init_dentry(void)
70886 {
70887 + static struct dentry *d_tracer;
70888 static int once;
70889
70890 if (d_tracer)
70891 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
70892 return d_tracer;
70893 }
70894
70895 -static struct dentry *d_percpu;
70896 -
70897 struct dentry *tracing_dentry_percpu(void)
70898 {
70899 + static struct dentry *d_percpu;
70900 static int once;
70901 struct dentry *d_tracer;
70902
70903 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70904 index 29111da..d190fe2 100644
70905 --- a/kernel/trace/trace_events.c
70906 +++ b/kernel/trace/trace_events.c
70907 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70908 struct ftrace_module_file_ops {
70909 struct list_head list;
70910 struct module *mod;
70911 - struct file_operations id;
70912 - struct file_operations enable;
70913 - struct file_operations format;
70914 - struct file_operations filter;
70915 };
70916
70917 static struct ftrace_module_file_ops *
70918 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70919
70920 file_ops->mod = mod;
70921
70922 - file_ops->id = ftrace_event_id_fops;
70923 - file_ops->id.owner = mod;
70924 -
70925 - file_ops->enable = ftrace_enable_fops;
70926 - file_ops->enable.owner = mod;
70927 -
70928 - file_ops->filter = ftrace_event_filter_fops;
70929 - file_ops->filter.owner = mod;
70930 -
70931 - file_ops->format = ftrace_event_format_fops;
70932 - file_ops->format.owner = mod;
70933 + pax_open_kernel();
70934 + *(void **)&mod->trace_id.owner = mod;
70935 + *(void **)&mod->trace_enable.owner = mod;
70936 + *(void **)&mod->trace_filter.owner = mod;
70937 + *(void **)&mod->trace_format.owner = mod;
70938 + pax_close_kernel();
70939
70940 list_add(&file_ops->list, &ftrace_module_file_list);
70941
70942 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70943
70944 for_each_event(call, start, end) {
70945 __trace_add_event_call(*call, mod,
70946 - &file_ops->id, &file_ops->enable,
70947 - &file_ops->filter, &file_ops->format);
70948 + &mod->trace_id, &mod->trace_enable,
70949 + &mod->trace_filter, &mod->trace_format);
70950 }
70951 }
70952
70953 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70954 index fd3c8aa..5f324a6 100644
70955 --- a/kernel/trace/trace_mmiotrace.c
70956 +++ b/kernel/trace/trace_mmiotrace.c
70957 @@ -24,7 +24,7 @@ struct header_iter {
70958 static struct trace_array *mmio_trace_array;
70959 static bool overrun_detected;
70960 static unsigned long prev_overruns;
70961 -static atomic_t dropped_count;
70962 +static atomic_unchecked_t dropped_count;
70963
70964 static void mmio_reset_data(struct trace_array *tr)
70965 {
70966 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70967
70968 static unsigned long count_overruns(struct trace_iterator *iter)
70969 {
70970 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70971 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70972 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70973
70974 if (over > prev_overruns)
70975 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70976 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70977 sizeof(*entry), 0, pc);
70978 if (!event) {
70979 - atomic_inc(&dropped_count);
70980 + atomic_inc_unchecked(&dropped_count);
70981 return;
70982 }
70983 entry = ring_buffer_event_data(event);
70984 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70985 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70986 sizeof(*entry), 0, pc);
70987 if (!event) {
70988 - atomic_inc(&dropped_count);
70989 + atomic_inc_unchecked(&dropped_count);
70990 return;
70991 }
70992 entry = ring_buffer_event_data(event);
70993 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70994 index 123b189..97b81f5 100644
70995 --- a/kernel/trace/trace_output.c
70996 +++ b/kernel/trace/trace_output.c
70997 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70998
70999 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71000 if (!IS_ERR(p)) {
71001 - p = mangle_path(s->buffer + s->len, p, "\n");
71002 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71003 if (p) {
71004 s->len = p - s->buffer;
71005 return 1;
71006 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71007 index d4545f4..a9010a1 100644
71008 --- a/kernel/trace/trace_stack.c
71009 +++ b/kernel/trace/trace_stack.c
71010 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71011 return;
71012
71013 /* we do not handle interrupt stacks yet */
71014 - if (!object_is_on_stack(&this_size))
71015 + if (!object_starts_on_stack(&this_size))
71016 return;
71017
71018 local_irq_save(flags);
71019 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71020 index 872bd6d..31601a2 100644
71021 --- a/kernel/workqueue.c
71022 +++ b/kernel/workqueue.c
71023 @@ -1422,7 +1422,7 @@ retry:
71024 /* morph UNBOUND to REBIND atomically */
71025 worker_flags &= ~WORKER_UNBOUND;
71026 worker_flags |= WORKER_REBIND;
71027 - ACCESS_ONCE(worker->flags) = worker_flags;
71028 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71029
71030 idle_rebind.cnt++;
71031 worker->idle_rebind = &idle_rebind;
71032 @@ -1448,7 +1448,7 @@ retry:
71033 /* morph UNBOUND to REBIND atomically */
71034 worker_flags &= ~WORKER_UNBOUND;
71035 worker_flags |= WORKER_REBIND;
71036 - ACCESS_ONCE(worker->flags) = worker_flags;
71037 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71038
71039 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71040 work_data_bits(rebind_work)))
71041 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71042 index 2403a63..5c4be4c 100644
71043 --- a/lib/Kconfig.debug
71044 +++ b/lib/Kconfig.debug
71045 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71046 depends on DEBUG_KERNEL
71047 depends on STACKTRACE_SUPPORT
71048 depends on PROC_FS
71049 + depends on !GRKERNSEC_HIDESYM
71050 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71051 select KALLSYMS
71052 select KALLSYMS_ALL
71053 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71054
71055 config PROVIDE_OHCI1394_DMA_INIT
71056 bool "Remote debugging over FireWire early on boot"
71057 - depends on PCI && X86
71058 + depends on PCI && X86 && !GRKERNSEC
71059 help
71060 If you want to debug problems which hang or crash the kernel early
71061 on boot and the crashing machine has a FireWire port, you can use
71062 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71063
71064 config FIREWIRE_OHCI_REMOTE_DMA
71065 bool "Remote debugging over FireWire with firewire-ohci"
71066 - depends on FIREWIRE_OHCI
71067 + depends on FIREWIRE_OHCI && !GRKERNSEC
71068 help
71069 This option lets you use the FireWire bus for remote debugging
71070 with help of the firewire-ohci driver. It enables unfiltered
71071 diff --git a/lib/bitmap.c b/lib/bitmap.c
71072 index 06fdfa1..97c5c7d 100644
71073 --- a/lib/bitmap.c
71074 +++ b/lib/bitmap.c
71075 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71076 {
71077 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71078 u32 chunk;
71079 - const char __user __force *ubuf = (const char __user __force *)buf;
71080 + const char __user *ubuf = (const char __force_user *)buf;
71081
71082 bitmap_zero(maskp, nmaskbits);
71083
71084 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71085 {
71086 if (!access_ok(VERIFY_READ, ubuf, ulen))
71087 return -EFAULT;
71088 - return __bitmap_parse((const char __force *)ubuf,
71089 + return __bitmap_parse((const char __force_kernel *)ubuf,
71090 ulen, 1, maskp, nmaskbits);
71091
71092 }
71093 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71094 {
71095 unsigned a, b;
71096 int c, old_c, totaldigits;
71097 - const char __user __force *ubuf = (const char __user __force *)buf;
71098 + const char __user *ubuf = (const char __force_user *)buf;
71099 int exp_digit, in_range;
71100
71101 totaldigits = c = 0;
71102 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71103 {
71104 if (!access_ok(VERIFY_READ, ubuf, ulen))
71105 return -EFAULT;
71106 - return __bitmap_parselist((const char __force *)ubuf,
71107 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71108 ulen, 1, maskp, nmaskbits);
71109 }
71110 EXPORT_SYMBOL(bitmap_parselist_user);
71111 diff --git a/lib/bug.c b/lib/bug.c
71112 index a28c141..2bd3d95 100644
71113 --- a/lib/bug.c
71114 +++ b/lib/bug.c
71115 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71116 return BUG_TRAP_TYPE_NONE;
71117
71118 bug = find_bug(bugaddr);
71119 + if (!bug)
71120 + return BUG_TRAP_TYPE_NONE;
71121
71122 file = NULL;
71123 line = 0;
71124 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71125 index d11808c..dc2d6f8 100644
71126 --- a/lib/debugobjects.c
71127 +++ b/lib/debugobjects.c
71128 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71129 if (limit > 4)
71130 return;
71131
71132 - is_on_stack = object_is_on_stack(addr);
71133 + is_on_stack = object_starts_on_stack(addr);
71134 if (is_on_stack == onstack)
71135 return;
71136
71137 diff --git a/lib/devres.c b/lib/devres.c
71138 index 80b9c76..9e32279 100644
71139 --- a/lib/devres.c
71140 +++ b/lib/devres.c
71141 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71142 void devm_iounmap(struct device *dev, void __iomem *addr)
71143 {
71144 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71145 - (void *)addr));
71146 + (void __force *)addr));
71147 iounmap(addr);
71148 }
71149 EXPORT_SYMBOL(devm_iounmap);
71150 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71151 {
71152 ioport_unmap(addr);
71153 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71154 - devm_ioport_map_match, (void *)addr));
71155 + devm_ioport_map_match, (void __force *)addr));
71156 }
71157 EXPORT_SYMBOL(devm_ioport_unmap);
71158
71159 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71160 index 66ce414..6f0a0dd 100644
71161 --- a/lib/dma-debug.c
71162 +++ b/lib/dma-debug.c
71163 @@ -924,7 +924,7 @@ out:
71164
71165 static void check_for_stack(struct device *dev, void *addr)
71166 {
71167 - if (object_is_on_stack(addr))
71168 + if (object_starts_on_stack(addr))
71169 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71170 "stack [addr=%p]\n", addr);
71171 }
71172 diff --git a/lib/inflate.c b/lib/inflate.c
71173 index 013a761..c28f3fc 100644
71174 --- a/lib/inflate.c
71175 +++ b/lib/inflate.c
71176 @@ -269,7 +269,7 @@ static void free(void *where)
71177 malloc_ptr = free_mem_ptr;
71178 }
71179 #else
71180 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71181 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71182 #define free(a) kfree(a)
71183 #endif
71184
71185 diff --git a/lib/ioremap.c b/lib/ioremap.c
71186 index 0c9216c..863bd89 100644
71187 --- a/lib/ioremap.c
71188 +++ b/lib/ioremap.c
71189 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71190 unsigned long next;
71191
71192 phys_addr -= addr;
71193 - pmd = pmd_alloc(&init_mm, pud, addr);
71194 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71195 if (!pmd)
71196 return -ENOMEM;
71197 do {
71198 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71199 unsigned long next;
71200
71201 phys_addr -= addr;
71202 - pud = pud_alloc(&init_mm, pgd, addr);
71203 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71204 if (!pud)
71205 return -ENOMEM;
71206 do {
71207 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71208 index bd2bea9..6b3c95e 100644
71209 --- a/lib/is_single_threaded.c
71210 +++ b/lib/is_single_threaded.c
71211 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71212 struct task_struct *p, *t;
71213 bool ret;
71214
71215 + if (!mm)
71216 + return true;
71217 +
71218 if (atomic_read(&task->signal->live) != 1)
71219 return false;
71220
71221 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71222 index e796429..6e38f9f 100644
71223 --- a/lib/radix-tree.c
71224 +++ b/lib/radix-tree.c
71225 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71226 int nr;
71227 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71228 };
71229 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71230 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71231
71232 static inline void *ptr_to_indirect(void *ptr)
71233 {
71234 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71235 index 0e33754..50a0e63 100644
71236 --- a/lib/vsprintf.c
71237 +++ b/lib/vsprintf.c
71238 @@ -16,6 +16,9 @@
71239 * - scnprintf and vscnprintf
71240 */
71241
71242 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71243 +#define __INCLUDED_BY_HIDESYM 1
71244 +#endif
71245 #include <stdarg.h>
71246 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71247 #include <linux/types.h>
71248 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71249 char sym[KSYM_SYMBOL_LEN];
71250 if (ext == 'B')
71251 sprint_backtrace(sym, value);
71252 - else if (ext != 'f' && ext != 's')
71253 + else if (ext != 'f' && ext != 's' && ext != 'a')
71254 sprint_symbol(sym, value);
71255 else
71256 sprint_symbol_no_offset(sym, value);
71257 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71258 return number(buf, end, *(const netdev_features_t *)addr, spec);
71259 }
71260
71261 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71262 +int kptr_restrict __read_mostly = 2;
71263 +#else
71264 int kptr_restrict __read_mostly;
71265 +#endif
71266
71267 /*
71268 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71269 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71270 * - 'S' For symbolic direct pointers with offset
71271 * - 's' For symbolic direct pointers without offset
71272 * - 'B' For backtraced symbolic direct pointers with offset
71273 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71274 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71275 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71276 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71277 * - 'M' For a 6-byte MAC address, it prints the address in the
71278 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71279
71280 if (!ptr && *fmt != 'K') {
71281 /*
71282 - * Print (null) with the same width as a pointer so it makes
71283 + * Print (nil) with the same width as a pointer so it makes
71284 * tabular output look nice.
71285 */
71286 if (spec.field_width == -1)
71287 spec.field_width = default_width;
71288 - return string(buf, end, "(null)", spec);
71289 + return string(buf, end, "(nil)", spec);
71290 }
71291
71292 switch (*fmt) {
71293 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71294 /* Fallthrough */
71295 case 'S':
71296 case 's':
71297 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71298 + break;
71299 +#else
71300 + return symbol_string(buf, end, ptr, spec, *fmt);
71301 +#endif
71302 + case 'A':
71303 + case 'a':
71304 case 'B':
71305 return symbol_string(buf, end, ptr, spec, *fmt);
71306 case 'R':
71307 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71308 va_end(va);
71309 return buf;
71310 }
71311 + case 'P':
71312 + break;
71313 case 'K':
71314 /*
71315 * %pK cannot be used in IRQ context because its test
71316 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71317 }
71318 break;
71319 }
71320 +
71321 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71322 + /* 'P' = approved pointers to copy to userland,
71323 + as in the /proc/kallsyms case, as we make it display nothing
71324 + for non-root users, and the real contents for root users
71325 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71326 + above
71327 + */
71328 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71329 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71330 + dump_stack();
71331 + ptr = NULL;
71332 + }
71333 +#endif
71334 +
71335 spec.flags |= SMALL;
71336 if (spec.field_width == -1) {
71337 spec.field_width = default_width;
71338 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71339 typeof(type) value; \
71340 if (sizeof(type) == 8) { \
71341 args = PTR_ALIGN(args, sizeof(u32)); \
71342 - *(u32 *)&value = *(u32 *)args; \
71343 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71344 + *(u32 *)&value = *(const u32 *)args; \
71345 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71346 } else { \
71347 args = PTR_ALIGN(args, sizeof(type)); \
71348 - value = *(typeof(type) *)args; \
71349 + value = *(const typeof(type) *)args; \
71350 } \
71351 args += sizeof(type); \
71352 value; \
71353 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71354 case FORMAT_TYPE_STR: {
71355 const char *str_arg = args;
71356 args += strlen(str_arg) + 1;
71357 - str = string(str, end, (char *)str_arg, spec);
71358 + str = string(str, end, str_arg, spec);
71359 break;
71360 }
71361
71362 diff --git a/localversion-grsec b/localversion-grsec
71363 new file mode 100644
71364 index 0000000..7cd6065
71365 --- /dev/null
71366 +++ b/localversion-grsec
71367 @@ -0,0 +1 @@
71368 +-grsec
71369 diff --git a/mm/Kconfig b/mm/Kconfig
71370 index d5c8019..f513038 100644
71371 --- a/mm/Kconfig
71372 +++ b/mm/Kconfig
71373 @@ -251,10 +251,10 @@ config KSM
71374 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71375
71376 config DEFAULT_MMAP_MIN_ADDR
71377 - int "Low address space to protect from user allocation"
71378 + int "Low address space to protect from user allocation"
71379 depends on MMU
71380 - default 4096
71381 - help
71382 + default 65536
71383 + help
71384 This is the portion of low virtual memory which should be protected
71385 from userspace allocation. Keeping a user from writing to low pages
71386 can help reduce the impact of kernel NULL pointer bugs.
71387 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71388
71389 config HWPOISON_INJECT
71390 tristate "HWPoison pages injector"
71391 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71392 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71393 select PROC_PAGE_MONITOR
71394
71395 config NOMMU_INITIAL_TRIM_EXCESS
71396 diff --git a/mm/filemap.c b/mm/filemap.c
71397 index 3843445..4fe6833 100644
71398 --- a/mm/filemap.c
71399 +++ b/mm/filemap.c
71400 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71401 struct address_space *mapping = file->f_mapping;
71402
71403 if (!mapping->a_ops->readpage)
71404 - return -ENOEXEC;
71405 + return -ENODEV;
71406 file_accessed(file);
71407 vma->vm_ops = &generic_file_vm_ops;
71408 vma->vm_flags |= VM_CAN_NONLINEAR;
71409 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71410 *pos = i_size_read(inode);
71411
71412 if (limit != RLIM_INFINITY) {
71413 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71414 if (*pos >= limit) {
71415 send_sig(SIGXFSZ, current, 0);
71416 return -EFBIG;
71417 diff --git a/mm/fremap.c b/mm/fremap.c
71418 index 9ed4fd4..c42648d 100644
71419 --- a/mm/fremap.c
71420 +++ b/mm/fremap.c
71421 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71422 retry:
71423 vma = find_vma(mm, start);
71424
71425 +#ifdef CONFIG_PAX_SEGMEXEC
71426 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71427 + goto out;
71428 +#endif
71429 +
71430 /*
71431 * Make sure the vma is shared, that it supports prefaulting,
71432 * and that the remapped range is valid and fully within
71433 diff --git a/mm/highmem.c b/mm/highmem.c
71434 index d517cd1..006a1c5 100644
71435 --- a/mm/highmem.c
71436 +++ b/mm/highmem.c
71437 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71438 * So no dangers, even with speculative execution.
71439 */
71440 page = pte_page(pkmap_page_table[i]);
71441 + pax_open_kernel();
71442 pte_clear(&init_mm, (unsigned long)page_address(page),
71443 &pkmap_page_table[i]);
71444 -
71445 + pax_close_kernel();
71446 set_page_address(page, NULL);
71447 need_flush = 1;
71448 }
71449 @@ -198,9 +199,11 @@ start:
71450 }
71451 }
71452 vaddr = PKMAP_ADDR(last_pkmap_nr);
71453 +
71454 + pax_open_kernel();
71455 set_pte_at(&init_mm, vaddr,
71456 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71457 -
71458 + pax_close_kernel();
71459 pkmap_count[last_pkmap_nr] = 1;
71460 set_page_address(page, (void *)vaddr);
71461
71462 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71463 index 141dbb6..ebff057 100644
71464 --- a/mm/huge_memory.c
71465 +++ b/mm/huge_memory.c
71466 @@ -735,7 +735,7 @@ out:
71467 * run pte_offset_map on the pmd, if an huge pmd could
71468 * materialize from under us from a different thread.
71469 */
71470 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71471 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71472 return VM_FAULT_OOM;
71473 /* if an huge pmd materialized from under us just retry later */
71474 if (unlikely(pmd_trans_huge(*pmd)))
71475 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71476 index 3adceaf..dccfea3 100644
71477 --- a/mm/hugetlb.c
71478 +++ b/mm/hugetlb.c
71479 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71480 return 1;
71481 }
71482
71483 +#ifdef CONFIG_PAX_SEGMEXEC
71484 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71485 +{
71486 + struct mm_struct *mm = vma->vm_mm;
71487 + struct vm_area_struct *vma_m;
71488 + unsigned long address_m;
71489 + pte_t *ptep_m;
71490 +
71491 + vma_m = pax_find_mirror_vma(vma);
71492 + if (!vma_m)
71493 + return;
71494 +
71495 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71496 + address_m = address + SEGMEXEC_TASK_SIZE;
71497 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71498 + get_page(page_m);
71499 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71500 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71501 +}
71502 +#endif
71503 +
71504 /*
71505 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71506 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71507 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71508 make_huge_pte(vma, new_page, 1));
71509 page_remove_rmap(old_page);
71510 hugepage_add_new_anon_rmap(new_page, vma, address);
71511 +
71512 +#ifdef CONFIG_PAX_SEGMEXEC
71513 + pax_mirror_huge_pte(vma, address, new_page);
71514 +#endif
71515 +
71516 /* Make the old page be freed below */
71517 new_page = old_page;
71518 mmu_notifier_invalidate_range_end(mm,
71519 @@ -2786,6 +2812,10 @@ retry:
71520 && (vma->vm_flags & VM_SHARED)));
71521 set_huge_pte_at(mm, address, ptep, new_pte);
71522
71523 +#ifdef CONFIG_PAX_SEGMEXEC
71524 + pax_mirror_huge_pte(vma, address, page);
71525 +#endif
71526 +
71527 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71528 /* Optimization, do the COW without a second fault */
71529 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71530 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71531 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71532 struct hstate *h = hstate_vma(vma);
71533
71534 +#ifdef CONFIG_PAX_SEGMEXEC
71535 + struct vm_area_struct *vma_m;
71536 +#endif
71537 +
71538 address &= huge_page_mask(h);
71539
71540 ptep = huge_pte_offset(mm, address);
71541 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71542 VM_FAULT_SET_HINDEX(hstate_index(h));
71543 }
71544
71545 +#ifdef CONFIG_PAX_SEGMEXEC
71546 + vma_m = pax_find_mirror_vma(vma);
71547 + if (vma_m) {
71548 + unsigned long address_m;
71549 +
71550 + if (vma->vm_start > vma_m->vm_start) {
71551 + address_m = address;
71552 + address -= SEGMEXEC_TASK_SIZE;
71553 + vma = vma_m;
71554 + h = hstate_vma(vma);
71555 + } else
71556 + address_m = address + SEGMEXEC_TASK_SIZE;
71557 +
71558 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71559 + return VM_FAULT_OOM;
71560 + address_m &= HPAGE_MASK;
71561 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71562 + }
71563 +#endif
71564 +
71565 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71566 if (!ptep)
71567 return VM_FAULT_OOM;
71568 diff --git a/mm/internal.h b/mm/internal.h
71569 index b8c91b3..93e95a3 100644
71570 --- a/mm/internal.h
71571 +++ b/mm/internal.h
71572 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71573 * in mm/page_alloc.c
71574 */
71575 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71576 +extern void free_compound_page(struct page *page);
71577 extern void prep_compound_page(struct page *page, unsigned long order);
71578 #ifdef CONFIG_MEMORY_FAILURE
71579 extern bool is_free_buddy_page(struct page *page);
71580 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71581 index 45eb621..6ccd8ea 100644
71582 --- a/mm/kmemleak.c
71583 +++ b/mm/kmemleak.c
71584 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71585
71586 for (i = 0; i < object->trace_len; i++) {
71587 void *ptr = (void *)object->trace[i];
71588 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71589 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71590 }
71591 }
71592
71593 diff --git a/mm/maccess.c b/mm/maccess.c
71594 index d53adf9..03a24bf 100644
71595 --- a/mm/maccess.c
71596 +++ b/mm/maccess.c
71597 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71598 set_fs(KERNEL_DS);
71599 pagefault_disable();
71600 ret = __copy_from_user_inatomic(dst,
71601 - (__force const void __user *)src, size);
71602 + (const void __force_user *)src, size);
71603 pagefault_enable();
71604 set_fs(old_fs);
71605
71606 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71607
71608 set_fs(KERNEL_DS);
71609 pagefault_disable();
71610 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71611 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71612 pagefault_enable();
71613 set_fs(old_fs);
71614
71615 diff --git a/mm/madvise.c b/mm/madvise.c
71616 index 14d260f..b2a80fd 100644
71617 --- a/mm/madvise.c
71618 +++ b/mm/madvise.c
71619 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71620 pgoff_t pgoff;
71621 unsigned long new_flags = vma->vm_flags;
71622
71623 +#ifdef CONFIG_PAX_SEGMEXEC
71624 + struct vm_area_struct *vma_m;
71625 +#endif
71626 +
71627 switch (behavior) {
71628 case MADV_NORMAL:
71629 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71630 @@ -119,6 +123,13 @@ success:
71631 /*
71632 * vm_flags is protected by the mmap_sem held in write mode.
71633 */
71634 +
71635 +#ifdef CONFIG_PAX_SEGMEXEC
71636 + vma_m = pax_find_mirror_vma(vma);
71637 + if (vma_m)
71638 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71639 +#endif
71640 +
71641 vma->vm_flags = new_flags;
71642
71643 out:
71644 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71645 struct vm_area_struct ** prev,
71646 unsigned long start, unsigned long end)
71647 {
71648 +
71649 +#ifdef CONFIG_PAX_SEGMEXEC
71650 + struct vm_area_struct *vma_m;
71651 +#endif
71652 +
71653 *prev = vma;
71654 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71655 return -EINVAL;
71656 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71657 zap_page_range(vma, start, end - start, &details);
71658 } else
71659 zap_page_range(vma, start, end - start, NULL);
71660 +
71661 +#ifdef CONFIG_PAX_SEGMEXEC
71662 + vma_m = pax_find_mirror_vma(vma);
71663 + if (vma_m) {
71664 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71665 + struct zap_details details = {
71666 + .nonlinear_vma = vma_m,
71667 + .last_index = ULONG_MAX,
71668 + };
71669 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71670 + } else
71671 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71672 + }
71673 +#endif
71674 +
71675 return 0;
71676 }
71677
71678 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71679 if (end < start)
71680 goto out;
71681
71682 +#ifdef CONFIG_PAX_SEGMEXEC
71683 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71684 + if (end > SEGMEXEC_TASK_SIZE)
71685 + goto out;
71686 + } else
71687 +#endif
71688 +
71689 + if (end > TASK_SIZE)
71690 + goto out;
71691 +
71692 error = 0;
71693 if (end == start)
71694 goto out;
71695 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71696 index a6e2141..eaf5aad 100644
71697 --- a/mm/memory-failure.c
71698 +++ b/mm/memory-failure.c
71699 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71700
71701 int sysctl_memory_failure_recovery __read_mostly = 1;
71702
71703 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71704 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71705
71706 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71707
71708 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71709 pfn, t->comm, t->pid);
71710 si.si_signo = SIGBUS;
71711 si.si_errno = 0;
71712 - si.si_addr = (void *)addr;
71713 + si.si_addr = (void __user *)addr;
71714 #ifdef __ARCH_SI_TRAPNO
71715 si.si_trapno = trapno;
71716 #endif
71717 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71718 }
71719
71720 nr_pages = 1 << compound_trans_order(hpage);
71721 - atomic_long_add(nr_pages, &mce_bad_pages);
71722 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71723
71724 /*
71725 * We need/can do nothing about count=0 pages.
71726 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71727 if (!PageHWPoison(hpage)
71728 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71729 || (p != hpage && TestSetPageHWPoison(hpage))) {
71730 - atomic_long_sub(nr_pages, &mce_bad_pages);
71731 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71732 return 0;
71733 }
71734 set_page_hwpoison_huge_page(hpage);
71735 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71736 }
71737 if (hwpoison_filter(p)) {
71738 if (TestClearPageHWPoison(p))
71739 - atomic_long_sub(nr_pages, &mce_bad_pages);
71740 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71741 unlock_page(hpage);
71742 put_page(hpage);
71743 return 0;
71744 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71745 return 0;
71746 }
71747 if (TestClearPageHWPoison(p))
71748 - atomic_long_sub(nr_pages, &mce_bad_pages);
71749 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71750 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71751 return 0;
71752 }
71753 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71754 */
71755 if (TestClearPageHWPoison(page)) {
71756 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71757 - atomic_long_sub(nr_pages, &mce_bad_pages);
71758 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71759 freeit = 1;
71760 if (PageHuge(page))
71761 clear_page_hwpoison_huge_page(page);
71762 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71763 }
71764 done:
71765 if (!PageHWPoison(hpage))
71766 - atomic_long_add(1 << compound_trans_order(hpage),
71767 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71768 &mce_bad_pages);
71769 set_page_hwpoison_huge_page(hpage);
71770 dequeue_hwpoisoned_huge_page(hpage);
71771 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71772 return ret;
71773
71774 done:
71775 - atomic_long_add(1, &mce_bad_pages);
71776 + atomic_long_add_unchecked(1, &mce_bad_pages);
71777 SetPageHWPoison(page);
71778 /* keep elevated page count for bad page */
71779 return ret;
71780 diff --git a/mm/memory.c b/mm/memory.c
71781 index 5736170..8e04800 100644
71782 --- a/mm/memory.c
71783 +++ b/mm/memory.c
71784 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71785 free_pte_range(tlb, pmd, addr);
71786 } while (pmd++, addr = next, addr != end);
71787
71788 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71789 start &= PUD_MASK;
71790 if (start < floor)
71791 return;
71792 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71793 pmd = pmd_offset(pud, start);
71794 pud_clear(pud);
71795 pmd_free_tlb(tlb, pmd, start);
71796 +#endif
71797 +
71798 }
71799
71800 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71801 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71802 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71803 } while (pud++, addr = next, addr != end);
71804
71805 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71806 start &= PGDIR_MASK;
71807 if (start < floor)
71808 return;
71809 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71810 pud = pud_offset(pgd, start);
71811 pgd_clear(pgd);
71812 pud_free_tlb(tlb, pud, start);
71813 +#endif
71814 +
71815 }
71816
71817 /*
71818 @@ -1614,12 +1620,6 @@ no_page_table:
71819 return page;
71820 }
71821
71822 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71823 -{
71824 - return stack_guard_page_start(vma, addr) ||
71825 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71826 -}
71827 -
71828 /**
71829 * __get_user_pages() - pin user pages in memory
71830 * @tsk: task_struct of target task
71831 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71832 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71833 i = 0;
71834
71835 - do {
71836 + while (nr_pages) {
71837 struct vm_area_struct *vma;
71838
71839 - vma = find_extend_vma(mm, start);
71840 + vma = find_vma(mm, start);
71841 if (!vma && in_gate_area(mm, start)) {
71842 unsigned long pg = start & PAGE_MASK;
71843 pgd_t *pgd;
71844 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71845 goto next_page;
71846 }
71847
71848 - if (!vma ||
71849 + if (!vma || start < vma->vm_start ||
71850 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71851 !(vm_flags & vma->vm_flags))
71852 return i ? : -EFAULT;
71853 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71854 int ret;
71855 unsigned int fault_flags = 0;
71856
71857 - /* For mlock, just skip the stack guard page. */
71858 - if (foll_flags & FOLL_MLOCK) {
71859 - if (stack_guard_page(vma, start))
71860 - goto next_page;
71861 - }
71862 if (foll_flags & FOLL_WRITE)
71863 fault_flags |= FAULT_FLAG_WRITE;
71864 if (nonblocking)
71865 @@ -1848,7 +1843,7 @@ next_page:
71866 start += PAGE_SIZE;
71867 nr_pages--;
71868 } while (nr_pages && start < vma->vm_end);
71869 - } while (nr_pages);
71870 + }
71871 return i;
71872 }
71873 EXPORT_SYMBOL(__get_user_pages);
71874 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71875 page_add_file_rmap(page);
71876 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71877
71878 +#ifdef CONFIG_PAX_SEGMEXEC
71879 + pax_mirror_file_pte(vma, addr, page, ptl);
71880 +#endif
71881 +
71882 retval = 0;
71883 pte_unmap_unlock(pte, ptl);
71884 return retval;
71885 @@ -2089,10 +2088,22 @@ out:
71886 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71887 struct page *page)
71888 {
71889 +
71890 +#ifdef CONFIG_PAX_SEGMEXEC
71891 + struct vm_area_struct *vma_m;
71892 +#endif
71893 +
71894 if (addr < vma->vm_start || addr >= vma->vm_end)
71895 return -EFAULT;
71896 if (!page_count(page))
71897 return -EINVAL;
71898 +
71899 +#ifdef CONFIG_PAX_SEGMEXEC
71900 + vma_m = pax_find_mirror_vma(vma);
71901 + if (vma_m)
71902 + vma_m->vm_flags |= VM_INSERTPAGE;
71903 +#endif
71904 +
71905 vma->vm_flags |= VM_INSERTPAGE;
71906 return insert_page(vma, addr, page, vma->vm_page_prot);
71907 }
71908 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71909 unsigned long pfn)
71910 {
71911 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71912 + BUG_ON(vma->vm_mirror);
71913
71914 if (addr < vma->vm_start || addr >= vma->vm_end)
71915 return -EFAULT;
71916 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71917
71918 BUG_ON(pud_huge(*pud));
71919
71920 - pmd = pmd_alloc(mm, pud, addr);
71921 + pmd = (mm == &init_mm) ?
71922 + pmd_alloc_kernel(mm, pud, addr) :
71923 + pmd_alloc(mm, pud, addr);
71924 if (!pmd)
71925 return -ENOMEM;
71926 do {
71927 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71928 unsigned long next;
71929 int err;
71930
71931 - pud = pud_alloc(mm, pgd, addr);
71932 + pud = (mm == &init_mm) ?
71933 + pud_alloc_kernel(mm, pgd, addr) :
71934 + pud_alloc(mm, pgd, addr);
71935 if (!pud)
71936 return -ENOMEM;
71937 do {
71938 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71939 copy_user_highpage(dst, src, va, vma);
71940 }
71941
71942 +#ifdef CONFIG_PAX_SEGMEXEC
71943 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71944 +{
71945 + struct mm_struct *mm = vma->vm_mm;
71946 + spinlock_t *ptl;
71947 + pte_t *pte, entry;
71948 +
71949 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71950 + entry = *pte;
71951 + if (!pte_present(entry)) {
71952 + if (!pte_none(entry)) {
71953 + BUG_ON(pte_file(entry));
71954 + free_swap_and_cache(pte_to_swp_entry(entry));
71955 + pte_clear_not_present_full(mm, address, pte, 0);
71956 + }
71957 + } else {
71958 + struct page *page;
71959 +
71960 + flush_cache_page(vma, address, pte_pfn(entry));
71961 + entry = ptep_clear_flush(vma, address, pte);
71962 + BUG_ON(pte_dirty(entry));
71963 + page = vm_normal_page(vma, address, entry);
71964 + if (page) {
71965 + update_hiwater_rss(mm);
71966 + if (PageAnon(page))
71967 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71968 + else
71969 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71970 + page_remove_rmap(page);
71971 + page_cache_release(page);
71972 + }
71973 + }
71974 + pte_unmap_unlock(pte, ptl);
71975 +}
71976 +
71977 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71978 + *
71979 + * the ptl of the lower mapped page is held on entry and is not released on exit
71980 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71981 + */
71982 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71983 +{
71984 + struct mm_struct *mm = vma->vm_mm;
71985 + unsigned long address_m;
71986 + spinlock_t *ptl_m;
71987 + struct vm_area_struct *vma_m;
71988 + pmd_t *pmd_m;
71989 + pte_t *pte_m, entry_m;
71990 +
71991 + BUG_ON(!page_m || !PageAnon(page_m));
71992 +
71993 + vma_m = pax_find_mirror_vma(vma);
71994 + if (!vma_m)
71995 + return;
71996 +
71997 + BUG_ON(!PageLocked(page_m));
71998 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71999 + address_m = address + SEGMEXEC_TASK_SIZE;
72000 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72001 + pte_m = pte_offset_map(pmd_m, address_m);
72002 + ptl_m = pte_lockptr(mm, pmd_m);
72003 + if (ptl != ptl_m) {
72004 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72005 + if (!pte_none(*pte_m))
72006 + goto out;
72007 + }
72008 +
72009 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72010 + page_cache_get(page_m);
72011 + page_add_anon_rmap(page_m, vma_m, address_m);
72012 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72013 + set_pte_at(mm, address_m, pte_m, entry_m);
72014 + update_mmu_cache(vma_m, address_m, entry_m);
72015 +out:
72016 + if (ptl != ptl_m)
72017 + spin_unlock(ptl_m);
72018 + pte_unmap(pte_m);
72019 + unlock_page(page_m);
72020 +}
72021 +
72022 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72023 +{
72024 + struct mm_struct *mm = vma->vm_mm;
72025 + unsigned long address_m;
72026 + spinlock_t *ptl_m;
72027 + struct vm_area_struct *vma_m;
72028 + pmd_t *pmd_m;
72029 + pte_t *pte_m, entry_m;
72030 +
72031 + BUG_ON(!page_m || PageAnon(page_m));
72032 +
72033 + vma_m = pax_find_mirror_vma(vma);
72034 + if (!vma_m)
72035 + return;
72036 +
72037 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72038 + address_m = address + SEGMEXEC_TASK_SIZE;
72039 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72040 + pte_m = pte_offset_map(pmd_m, address_m);
72041 + ptl_m = pte_lockptr(mm, pmd_m);
72042 + if (ptl != ptl_m) {
72043 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72044 + if (!pte_none(*pte_m))
72045 + goto out;
72046 + }
72047 +
72048 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72049 + page_cache_get(page_m);
72050 + page_add_file_rmap(page_m);
72051 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72052 + set_pte_at(mm, address_m, pte_m, entry_m);
72053 + update_mmu_cache(vma_m, address_m, entry_m);
72054 +out:
72055 + if (ptl != ptl_m)
72056 + spin_unlock(ptl_m);
72057 + pte_unmap(pte_m);
72058 +}
72059 +
72060 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72061 +{
72062 + struct mm_struct *mm = vma->vm_mm;
72063 + unsigned long address_m;
72064 + spinlock_t *ptl_m;
72065 + struct vm_area_struct *vma_m;
72066 + pmd_t *pmd_m;
72067 + pte_t *pte_m, entry_m;
72068 +
72069 + vma_m = pax_find_mirror_vma(vma);
72070 + if (!vma_m)
72071 + return;
72072 +
72073 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72074 + address_m = address + SEGMEXEC_TASK_SIZE;
72075 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72076 + pte_m = pte_offset_map(pmd_m, address_m);
72077 + ptl_m = pte_lockptr(mm, pmd_m);
72078 + if (ptl != ptl_m) {
72079 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72080 + if (!pte_none(*pte_m))
72081 + goto out;
72082 + }
72083 +
72084 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72085 + set_pte_at(mm, address_m, pte_m, entry_m);
72086 +out:
72087 + if (ptl != ptl_m)
72088 + spin_unlock(ptl_m);
72089 + pte_unmap(pte_m);
72090 +}
72091 +
72092 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72093 +{
72094 + struct page *page_m;
72095 + pte_t entry;
72096 +
72097 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72098 + goto out;
72099 +
72100 + entry = *pte;
72101 + page_m = vm_normal_page(vma, address, entry);
72102 + if (!page_m)
72103 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72104 + else if (PageAnon(page_m)) {
72105 + if (pax_find_mirror_vma(vma)) {
72106 + pte_unmap_unlock(pte, ptl);
72107 + lock_page(page_m);
72108 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72109 + if (pte_same(entry, *pte))
72110 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72111 + else
72112 + unlock_page(page_m);
72113 + }
72114 + } else
72115 + pax_mirror_file_pte(vma, address, page_m, ptl);
72116 +
72117 +out:
72118 + pte_unmap_unlock(pte, ptl);
72119 +}
72120 +#endif
72121 +
72122 /*
72123 * This routine handles present pages, when users try to write
72124 * to a shared page. It is done by copying the page to a new address
72125 @@ -2703,6 +2899,12 @@ gotten:
72126 */
72127 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72128 if (likely(pte_same(*page_table, orig_pte))) {
72129 +
72130 +#ifdef CONFIG_PAX_SEGMEXEC
72131 + if (pax_find_mirror_vma(vma))
72132 + BUG_ON(!trylock_page(new_page));
72133 +#endif
72134 +
72135 if (old_page) {
72136 if (!PageAnon(old_page)) {
72137 dec_mm_counter_fast(mm, MM_FILEPAGES);
72138 @@ -2754,6 +2956,10 @@ gotten:
72139 page_remove_rmap(old_page);
72140 }
72141
72142 +#ifdef CONFIG_PAX_SEGMEXEC
72143 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72144 +#endif
72145 +
72146 /* Free the old page.. */
72147 new_page = old_page;
72148 ret |= VM_FAULT_WRITE;
72149 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72150 swap_free(entry);
72151 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72152 try_to_free_swap(page);
72153 +
72154 +#ifdef CONFIG_PAX_SEGMEXEC
72155 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72156 +#endif
72157 +
72158 unlock_page(page);
72159 if (swapcache) {
72160 /*
72161 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72162
72163 /* No need to invalidate - it was non-present before */
72164 update_mmu_cache(vma, address, page_table);
72165 +
72166 +#ifdef CONFIG_PAX_SEGMEXEC
72167 + pax_mirror_anon_pte(vma, address, page, ptl);
72168 +#endif
72169 +
72170 unlock:
72171 pte_unmap_unlock(page_table, ptl);
72172 out:
72173 @@ -3075,40 +3291,6 @@ out_release:
72174 }
72175
72176 /*
72177 - * This is like a special single-page "expand_{down|up}wards()",
72178 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72179 - * doesn't hit another vma.
72180 - */
72181 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72182 -{
72183 - address &= PAGE_MASK;
72184 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72185 - struct vm_area_struct *prev = vma->vm_prev;
72186 -
72187 - /*
72188 - * Is there a mapping abutting this one below?
72189 - *
72190 - * That's only ok if it's the same stack mapping
72191 - * that has gotten split..
72192 - */
72193 - if (prev && prev->vm_end == address)
72194 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72195 -
72196 - expand_downwards(vma, address - PAGE_SIZE);
72197 - }
72198 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72199 - struct vm_area_struct *next = vma->vm_next;
72200 -
72201 - /* As VM_GROWSDOWN but s/below/above/ */
72202 - if (next && next->vm_start == address + PAGE_SIZE)
72203 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72204 -
72205 - expand_upwards(vma, address + PAGE_SIZE);
72206 - }
72207 - return 0;
72208 -}
72209 -
72210 -/*
72211 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72212 * but allow concurrent faults), and pte mapped but not yet locked.
72213 * We return with mmap_sem still held, but pte unmapped and unlocked.
72214 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72215 unsigned long address, pte_t *page_table, pmd_t *pmd,
72216 unsigned int flags)
72217 {
72218 - struct page *page;
72219 + struct page *page = NULL;
72220 spinlock_t *ptl;
72221 pte_t entry;
72222
72223 - pte_unmap(page_table);
72224 -
72225 - /* Check if we need to add a guard page to the stack */
72226 - if (check_stack_guard_page(vma, address) < 0)
72227 - return VM_FAULT_SIGBUS;
72228 -
72229 - /* Use the zero-page for reads */
72230 if (!(flags & FAULT_FLAG_WRITE)) {
72231 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72232 vma->vm_page_prot));
72233 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72234 + ptl = pte_lockptr(mm, pmd);
72235 + spin_lock(ptl);
72236 if (!pte_none(*page_table))
72237 goto unlock;
72238 goto setpte;
72239 }
72240
72241 /* Allocate our own private page. */
72242 + pte_unmap(page_table);
72243 +
72244 if (unlikely(anon_vma_prepare(vma)))
72245 goto oom;
72246 page = alloc_zeroed_user_highpage_movable(vma, address);
72247 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72248 if (!pte_none(*page_table))
72249 goto release;
72250
72251 +#ifdef CONFIG_PAX_SEGMEXEC
72252 + if (pax_find_mirror_vma(vma))
72253 + BUG_ON(!trylock_page(page));
72254 +#endif
72255 +
72256 inc_mm_counter_fast(mm, MM_ANONPAGES);
72257 page_add_new_anon_rmap(page, vma, address);
72258 setpte:
72259 @@ -3163,6 +3346,12 @@ setpte:
72260
72261 /* No need to invalidate - it was non-present before */
72262 update_mmu_cache(vma, address, page_table);
72263 +
72264 +#ifdef CONFIG_PAX_SEGMEXEC
72265 + if (page)
72266 + pax_mirror_anon_pte(vma, address, page, ptl);
72267 +#endif
72268 +
72269 unlock:
72270 pte_unmap_unlock(page_table, ptl);
72271 return 0;
72272 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72273 */
72274 /* Only go through if we didn't race with anybody else... */
72275 if (likely(pte_same(*page_table, orig_pte))) {
72276 +
72277 +#ifdef CONFIG_PAX_SEGMEXEC
72278 + if (anon && pax_find_mirror_vma(vma))
72279 + BUG_ON(!trylock_page(page));
72280 +#endif
72281 +
72282 flush_icache_page(vma, page);
72283 entry = mk_pte(page, vma->vm_page_prot);
72284 if (flags & FAULT_FLAG_WRITE)
72285 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72286
72287 /* no need to invalidate: a not-present page won't be cached */
72288 update_mmu_cache(vma, address, page_table);
72289 +
72290 +#ifdef CONFIG_PAX_SEGMEXEC
72291 + if (anon)
72292 + pax_mirror_anon_pte(vma, address, page, ptl);
72293 + else
72294 + pax_mirror_file_pte(vma, address, page, ptl);
72295 +#endif
72296 +
72297 } else {
72298 if (cow_page)
72299 mem_cgroup_uncharge_page(cow_page);
72300 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72301 if (flags & FAULT_FLAG_WRITE)
72302 flush_tlb_fix_spurious_fault(vma, address);
72303 }
72304 +
72305 +#ifdef CONFIG_PAX_SEGMEXEC
72306 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72307 + return 0;
72308 +#endif
72309 +
72310 unlock:
72311 pte_unmap_unlock(pte, ptl);
72312 return 0;
72313 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72314 pmd_t *pmd;
72315 pte_t *pte;
72316
72317 +#ifdef CONFIG_PAX_SEGMEXEC
72318 + struct vm_area_struct *vma_m;
72319 +#endif
72320 +
72321 __set_current_state(TASK_RUNNING);
72322
72323 count_vm_event(PGFAULT);
72324 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72325 if (unlikely(is_vm_hugetlb_page(vma)))
72326 return hugetlb_fault(mm, vma, address, flags);
72327
72328 +#ifdef CONFIG_PAX_SEGMEXEC
72329 + vma_m = pax_find_mirror_vma(vma);
72330 + if (vma_m) {
72331 + unsigned long address_m;
72332 + pgd_t *pgd_m;
72333 + pud_t *pud_m;
72334 + pmd_t *pmd_m;
72335 +
72336 + if (vma->vm_start > vma_m->vm_start) {
72337 + address_m = address;
72338 + address -= SEGMEXEC_TASK_SIZE;
72339 + vma = vma_m;
72340 + } else
72341 + address_m = address + SEGMEXEC_TASK_SIZE;
72342 +
72343 + pgd_m = pgd_offset(mm, address_m);
72344 + pud_m = pud_alloc(mm, pgd_m, address_m);
72345 + if (!pud_m)
72346 + return VM_FAULT_OOM;
72347 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72348 + if (!pmd_m)
72349 + return VM_FAULT_OOM;
72350 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72351 + return VM_FAULT_OOM;
72352 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72353 + }
72354 +#endif
72355 +
72356 retry:
72357 pgd = pgd_offset(mm, address);
72358 pud = pud_alloc(mm, pgd, address);
72359 @@ -3547,7 +3788,7 @@ retry:
72360 * run pte_offset_map on the pmd, if an huge pmd could
72361 * materialize from under us from a different thread.
72362 */
72363 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72364 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72365 return VM_FAULT_OOM;
72366 /* if an huge pmd materialized from under us just retry later */
72367 if (unlikely(pmd_trans_huge(*pmd)))
72368 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72369 spin_unlock(&mm->page_table_lock);
72370 return 0;
72371 }
72372 +
72373 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72374 +{
72375 + pud_t *new = pud_alloc_one(mm, address);
72376 + if (!new)
72377 + return -ENOMEM;
72378 +
72379 + smp_wmb(); /* See comment in __pte_alloc */
72380 +
72381 + spin_lock(&mm->page_table_lock);
72382 + if (pgd_present(*pgd)) /* Another has populated it */
72383 + pud_free(mm, new);
72384 + else
72385 + pgd_populate_kernel(mm, pgd, new);
72386 + spin_unlock(&mm->page_table_lock);
72387 + return 0;
72388 +}
72389 #endif /* __PAGETABLE_PUD_FOLDED */
72390
72391 #ifndef __PAGETABLE_PMD_FOLDED
72392 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72393 spin_unlock(&mm->page_table_lock);
72394 return 0;
72395 }
72396 +
72397 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72398 +{
72399 + pmd_t *new = pmd_alloc_one(mm, address);
72400 + if (!new)
72401 + return -ENOMEM;
72402 +
72403 + smp_wmb(); /* See comment in __pte_alloc */
72404 +
72405 + spin_lock(&mm->page_table_lock);
72406 +#ifndef __ARCH_HAS_4LEVEL_HACK
72407 + if (pud_present(*pud)) /* Another has populated it */
72408 + pmd_free(mm, new);
72409 + else
72410 + pud_populate_kernel(mm, pud, new);
72411 +#else
72412 + if (pgd_present(*pud)) /* Another has populated it */
72413 + pmd_free(mm, new);
72414 + else
72415 + pgd_populate_kernel(mm, pud, new);
72416 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72417 + spin_unlock(&mm->page_table_lock);
72418 + return 0;
72419 +}
72420 #endif /* __PAGETABLE_PMD_FOLDED */
72421
72422 int make_pages_present(unsigned long addr, unsigned long end)
72423 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72424 gate_vma.vm_start = FIXADDR_USER_START;
72425 gate_vma.vm_end = FIXADDR_USER_END;
72426 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72427 - gate_vma.vm_page_prot = __P101;
72428 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72429
72430 return 0;
72431 }
72432 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72433 index 3d64b36..dbab433 100644
72434 --- a/mm/mempolicy.c
72435 +++ b/mm/mempolicy.c
72436 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72437 unsigned long vmstart;
72438 unsigned long vmend;
72439
72440 +#ifdef CONFIG_PAX_SEGMEXEC
72441 + struct vm_area_struct *vma_m;
72442 +#endif
72443 +
72444 vma = find_vma(mm, start);
72445 if (!vma || vma->vm_start > start)
72446 return -EFAULT;
72447 @@ -691,9 +695,18 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72448 if (err)
72449 goto out;
72450 }
72451 +
72452 err = vma_replace_policy(vma, new_pol);
72453 if (err)
72454 goto out;
72455 +
72456 +#ifdef CONFIG_PAX_SEGMEXEC
72457 + vma_m = pax_find_mirror_vma(vma);
72458 + err = vma_replace_policy(vma_m, new_pol);
72459 + if (err)
72460 + goto out;
72461 +#endif
72462 +
72463 }
72464
72465 out:
72466 @@ -1147,6 +1160,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72467
72468 if (end < start)
72469 return -EINVAL;
72470 +
72471 +#ifdef CONFIG_PAX_SEGMEXEC
72472 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72473 + if (end > SEGMEXEC_TASK_SIZE)
72474 + return -EINVAL;
72475 + } else
72476 +#endif
72477 +
72478 + if (end > TASK_SIZE)
72479 + return -EINVAL;
72480 +
72481 if (end == start)
72482 return 0;
72483
72484 @@ -1370,8 +1394,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72485 */
72486 tcred = __task_cred(task);
72487 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72488 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72489 - !capable(CAP_SYS_NICE)) {
72490 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72491 rcu_read_unlock();
72492 err = -EPERM;
72493 goto out_put;
72494 @@ -1402,6 +1425,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72495 goto out;
72496 }
72497
72498 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72499 + if (mm != current->mm &&
72500 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72501 + mmput(mm);
72502 + err = -EPERM;
72503 + goto out;
72504 + }
72505 +#endif
72506 +
72507 err = do_migrate_pages(mm, old, new,
72508 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72509
72510 diff --git a/mm/migrate.c b/mm/migrate.c
72511 index 77ed2d7..317d528 100644
72512 --- a/mm/migrate.c
72513 +++ b/mm/migrate.c
72514 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72515 */
72516 tcred = __task_cred(task);
72517 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72518 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72519 - !capable(CAP_SYS_NICE)) {
72520 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72521 rcu_read_unlock();
72522 err = -EPERM;
72523 goto out;
72524 diff --git a/mm/mlock.c b/mm/mlock.c
72525 index ef726e8..cd7f1ec 100644
72526 --- a/mm/mlock.c
72527 +++ b/mm/mlock.c
72528 @@ -13,6 +13,7 @@
72529 #include <linux/pagemap.h>
72530 #include <linux/mempolicy.h>
72531 #include <linux/syscalls.h>
72532 +#include <linux/security.h>
72533 #include <linux/sched.h>
72534 #include <linux/export.h>
72535 #include <linux/rmap.h>
72536 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72537 {
72538 unsigned long nstart, end, tmp;
72539 struct vm_area_struct * vma, * prev;
72540 - int error;
72541 + int error = 0;
72542
72543 VM_BUG_ON(start & ~PAGE_MASK);
72544 VM_BUG_ON(len != PAGE_ALIGN(len));
72545 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72546 return -EINVAL;
72547 if (end == start)
72548 return 0;
72549 + if (end > TASK_SIZE)
72550 + return -EINVAL;
72551 +
72552 vma = find_vma(current->mm, start);
72553 if (!vma || vma->vm_start > start)
72554 return -ENOMEM;
72555 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72556 for (nstart = start ; ; ) {
72557 vm_flags_t newflags;
72558
72559 +#ifdef CONFIG_PAX_SEGMEXEC
72560 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72561 + break;
72562 +#endif
72563 +
72564 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72565
72566 newflags = vma->vm_flags | VM_LOCKED;
72567 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72568 lock_limit >>= PAGE_SHIFT;
72569
72570 /* check against resource limits */
72571 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72572 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72573 error = do_mlock(start, len, 1);
72574 up_write(&current->mm->mmap_sem);
72575 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72576 static int do_mlockall(int flags)
72577 {
72578 struct vm_area_struct * vma, * prev = NULL;
72579 - unsigned int def_flags = 0;
72580
72581 if (flags & MCL_FUTURE)
72582 - def_flags = VM_LOCKED;
72583 - current->mm->def_flags = def_flags;
72584 + current->mm->def_flags |= VM_LOCKED;
72585 + else
72586 + current->mm->def_flags &= ~VM_LOCKED;
72587 if (flags == MCL_FUTURE)
72588 goto out;
72589
72590 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72591 vm_flags_t newflags;
72592
72593 +#ifdef CONFIG_PAX_SEGMEXEC
72594 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72595 + break;
72596 +#endif
72597 +
72598 + BUG_ON(vma->vm_end > TASK_SIZE);
72599 newflags = vma->vm_flags | VM_LOCKED;
72600 if (!(flags & MCL_CURRENT))
72601 newflags &= ~VM_LOCKED;
72602 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72603 lock_limit >>= PAGE_SHIFT;
72604
72605 ret = -ENOMEM;
72606 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72607 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72608 capable(CAP_IPC_LOCK))
72609 ret = do_mlockall(flags);
72610 diff --git a/mm/mmap.c b/mm/mmap.c
72611 index ae18a48..86cf99e 100644
72612 --- a/mm/mmap.c
72613 +++ b/mm/mmap.c
72614 @@ -47,6 +47,16 @@
72615 #define arch_rebalance_pgtables(addr, len) (addr)
72616 #endif
72617
72618 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72619 +{
72620 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72621 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72622 + up_read(&mm->mmap_sem);
72623 + BUG();
72624 + }
72625 +#endif
72626 +}
72627 +
72628 static void unmap_region(struct mm_struct *mm,
72629 struct vm_area_struct *vma, struct vm_area_struct *prev,
72630 unsigned long start, unsigned long end);
72631 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72632 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72633 *
72634 */
72635 -pgprot_t protection_map[16] = {
72636 +pgprot_t protection_map[16] __read_only = {
72637 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72638 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72639 };
72640
72641 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72642 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72643 {
72644 - return __pgprot(pgprot_val(protection_map[vm_flags &
72645 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72646 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72647 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72648 +
72649 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72650 + if (!(__supported_pte_mask & _PAGE_NX) &&
72651 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72652 + (vm_flags & (VM_READ | VM_WRITE)))
72653 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72654 +#endif
72655 +
72656 + return prot;
72657 }
72658 EXPORT_SYMBOL(vm_get_page_prot);
72659
72660 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72661 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72662 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72663 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72664 /*
72665 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72666 * other variables. It can be updated by several CPUs frequently.
72667 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72668 struct vm_area_struct *next = vma->vm_next;
72669
72670 might_sleep();
72671 + BUG_ON(vma->vm_mirror);
72672 if (vma->vm_ops && vma->vm_ops->close)
72673 vma->vm_ops->close(vma);
72674 if (vma->vm_file) {
72675 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72676 * not page aligned -Ram Gupta
72677 */
72678 rlim = rlimit(RLIMIT_DATA);
72679 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72680 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72681 (mm->end_data - mm->start_data) > rlim)
72682 goto out;
72683 @@ -708,6 +730,12 @@ static int
72684 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72685 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72686 {
72687 +
72688 +#ifdef CONFIG_PAX_SEGMEXEC
72689 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72690 + return 0;
72691 +#endif
72692 +
72693 if (is_mergeable_vma(vma, file, vm_flags) &&
72694 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72695 if (vma->vm_pgoff == vm_pgoff)
72696 @@ -727,6 +755,12 @@ static int
72697 can_vma_merge_after(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_end == 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 pgoff_t vm_pglen;
72709 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72710 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72711 struct vm_area_struct *prev, unsigned long addr,
72712 unsigned long end, unsigned long vm_flags,
72713 - struct anon_vma *anon_vma, struct file *file,
72714 + struct anon_vma *anon_vma, struct file *file,
72715 pgoff_t pgoff, struct mempolicy *policy)
72716 {
72717 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72718 struct vm_area_struct *area, *next;
72719 int err;
72720
72721 +#ifdef CONFIG_PAX_SEGMEXEC
72722 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72723 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72724 +
72725 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72726 +#endif
72727 +
72728 /*
72729 * We later require that vma->vm_flags == vm_flags,
72730 * so this tests vma->vm_flags & VM_SPECIAL, too.
72731 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72732 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72733 next = next->vm_next;
72734
72735 +#ifdef CONFIG_PAX_SEGMEXEC
72736 + if (prev)
72737 + prev_m = pax_find_mirror_vma(prev);
72738 + if (area)
72739 + area_m = pax_find_mirror_vma(area);
72740 + if (next)
72741 + next_m = pax_find_mirror_vma(next);
72742 +#endif
72743 +
72744 /*
72745 * Can it merge with the predecessor?
72746 */
72747 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72748 /* cases 1, 6 */
72749 err = vma_adjust(prev, prev->vm_start,
72750 next->vm_end, prev->vm_pgoff, NULL);
72751 - } else /* cases 2, 5, 7 */
72752 +
72753 +#ifdef CONFIG_PAX_SEGMEXEC
72754 + if (!err && prev_m)
72755 + err = vma_adjust(prev_m, prev_m->vm_start,
72756 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72757 +#endif
72758 +
72759 + } else { /* cases 2, 5, 7 */
72760 err = vma_adjust(prev, prev->vm_start,
72761 end, prev->vm_pgoff, NULL);
72762 +
72763 +#ifdef CONFIG_PAX_SEGMEXEC
72764 + if (!err && prev_m)
72765 + err = vma_adjust(prev_m, prev_m->vm_start,
72766 + end_m, prev_m->vm_pgoff, NULL);
72767 +#endif
72768 +
72769 + }
72770 if (err)
72771 return NULL;
72772 khugepaged_enter_vma_merge(prev);
72773 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72774 mpol_equal(policy, vma_policy(next)) &&
72775 can_vma_merge_before(next, vm_flags,
72776 anon_vma, file, pgoff+pglen)) {
72777 - if (prev && addr < prev->vm_end) /* case 4 */
72778 + if (prev && addr < prev->vm_end) { /* case 4 */
72779 err = vma_adjust(prev, prev->vm_start,
72780 addr, prev->vm_pgoff, NULL);
72781 - else /* cases 3, 8 */
72782 +
72783 +#ifdef CONFIG_PAX_SEGMEXEC
72784 + if (!err && prev_m)
72785 + err = vma_adjust(prev_m, prev_m->vm_start,
72786 + addr_m, prev_m->vm_pgoff, NULL);
72787 +#endif
72788 +
72789 + } else { /* cases 3, 8 */
72790 err = vma_adjust(area, addr, next->vm_end,
72791 next->vm_pgoff - pglen, NULL);
72792 +
72793 +#ifdef CONFIG_PAX_SEGMEXEC
72794 + if (!err && area_m)
72795 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72796 + next_m->vm_pgoff - pglen, NULL);
72797 +#endif
72798 +
72799 + }
72800 if (err)
72801 return NULL;
72802 khugepaged_enter_vma_merge(area);
72803 @@ -940,16 +1020,13 @@ none:
72804 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72805 struct file *file, long pages)
72806 {
72807 - const unsigned long stack_flags
72808 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72809 -
72810 mm->total_vm += pages;
72811
72812 if (file) {
72813 mm->shared_vm += pages;
72814 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72815 mm->exec_vm += pages;
72816 - } else if (flags & stack_flags)
72817 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72818 mm->stack_vm += pages;
72819 if (flags & (VM_RESERVED|VM_IO))
72820 mm->reserved_vm += pages;
72821 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72822 * (the exception is when the underlying filesystem is noexec
72823 * mounted, in which case we dont add PROT_EXEC.)
72824 */
72825 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72826 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72827 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72828 prot |= PROT_EXEC;
72829
72830 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72831 /* Obtain the address to map to. we verify (or select) it and ensure
72832 * that it represents a valid section of the address space.
72833 */
72834 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72835 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72836 if (addr & ~PAGE_MASK)
72837 return addr;
72838
72839 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72840 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72841 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72842
72843 +#ifdef CONFIG_PAX_MPROTECT
72844 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72845 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72846 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72847 + gr_log_rwxmmap(file);
72848 +
72849 +#ifdef CONFIG_PAX_EMUPLT
72850 + vm_flags &= ~VM_EXEC;
72851 +#else
72852 + return -EPERM;
72853 +#endif
72854 +
72855 + }
72856 +
72857 + if (!(vm_flags & VM_EXEC))
72858 + vm_flags &= ~VM_MAYEXEC;
72859 +#else
72860 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72861 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72862 +#endif
72863 + else
72864 + vm_flags &= ~VM_MAYWRITE;
72865 + }
72866 +#endif
72867 +
72868 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72869 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72870 + vm_flags &= ~VM_PAGEEXEC;
72871 +#endif
72872 +
72873 if (flags & MAP_LOCKED)
72874 if (!can_do_mlock())
72875 return -EPERM;
72876 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72877 locked += mm->locked_vm;
72878 lock_limit = rlimit(RLIMIT_MEMLOCK);
72879 lock_limit >>= PAGE_SHIFT;
72880 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72881 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72882 return -EAGAIN;
72883 }
72884 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72885 }
72886 }
72887
72888 + if (!gr_acl_handle_mmap(file, prot))
72889 + return -EACCES;
72890 +
72891 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72892 }
72893
72894 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72895 vm_flags_t vm_flags = vma->vm_flags;
72896
72897 /* If it was private or non-writable, the write bit is already clear */
72898 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72899 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72900 return 0;
72901
72902 /* The backer wishes to know when pages are first written to? */
72903 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72904 unsigned long charged = 0;
72905 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72906
72907 +#ifdef CONFIG_PAX_SEGMEXEC
72908 + struct vm_area_struct *vma_m = NULL;
72909 +#endif
72910 +
72911 + /*
72912 + * mm->mmap_sem is required to protect against another thread
72913 + * changing the mappings in case we sleep.
72914 + */
72915 + verify_mm_writelocked(mm);
72916 +
72917 /* Clear old maps */
72918 error = -ENOMEM;
72919 -munmap_back:
72920 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72921 if (vma && vma->vm_start < addr + len) {
72922 if (do_munmap(mm, addr, len))
72923 return -ENOMEM;
72924 - goto munmap_back;
72925 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72926 + BUG_ON(vma && vma->vm_start < addr + len);
72927 }
72928
72929 /* Check against address space limit. */
72930 @@ -1282,6 +1403,16 @@ munmap_back:
72931 goto unacct_error;
72932 }
72933
72934 +#ifdef CONFIG_PAX_SEGMEXEC
72935 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72936 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72937 + if (!vma_m) {
72938 + error = -ENOMEM;
72939 + goto free_vma;
72940 + }
72941 + }
72942 +#endif
72943 +
72944 vma->vm_mm = mm;
72945 vma->vm_start = addr;
72946 vma->vm_end = addr + len;
72947 @@ -1306,6 +1437,19 @@ munmap_back:
72948 error = file->f_op->mmap(file, vma);
72949 if (error)
72950 goto unmap_and_free_vma;
72951 +
72952 +#ifdef CONFIG_PAX_SEGMEXEC
72953 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72954 + added_exe_file_vma(mm);
72955 +#endif
72956 +
72957 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72958 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72959 + vma->vm_flags |= VM_PAGEEXEC;
72960 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72961 + }
72962 +#endif
72963 +
72964 if (vm_flags & VM_EXECUTABLE)
72965 added_exe_file_vma(mm);
72966
72967 @@ -1343,6 +1487,11 @@ munmap_back:
72968 vma_link(mm, vma, prev, rb_link, rb_parent);
72969 file = vma->vm_file;
72970
72971 +#ifdef CONFIG_PAX_SEGMEXEC
72972 + if (vma_m)
72973 + BUG_ON(pax_mirror_vma(vma_m, vma));
72974 +#endif
72975 +
72976 /* Once vma denies write, undo our temporary denial count */
72977 if (correct_wcount)
72978 atomic_inc(&inode->i_writecount);
72979 @@ -1350,6 +1499,7 @@ out:
72980 perf_event_mmap(vma);
72981
72982 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72983 + track_exec_limit(mm, addr, addr + len, vm_flags);
72984 if (vm_flags & VM_LOCKED) {
72985 if (!mlock_vma_pages_range(vma, addr, addr + len))
72986 mm->locked_vm += (len >> PAGE_SHIFT);
72987 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72988 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72989 charged = 0;
72990 free_vma:
72991 +
72992 +#ifdef CONFIG_PAX_SEGMEXEC
72993 + if (vma_m)
72994 + kmem_cache_free(vm_area_cachep, vma_m);
72995 +#endif
72996 +
72997 kmem_cache_free(vm_area_cachep, vma);
72998 unacct_error:
72999 if (charged)
73000 @@ -1378,6 +1534,44 @@ unacct_error:
73001 return error;
73002 }
73003
73004 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73005 +{
73006 + if (!vma) {
73007 +#ifdef CONFIG_STACK_GROWSUP
73008 + if (addr > sysctl_heap_stack_gap)
73009 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73010 + else
73011 + vma = find_vma(current->mm, 0);
73012 + if (vma && (vma->vm_flags & VM_GROWSUP))
73013 + return false;
73014 +#endif
73015 + return true;
73016 + }
73017 +
73018 + if (addr + len > vma->vm_start)
73019 + return false;
73020 +
73021 + if (vma->vm_flags & VM_GROWSDOWN)
73022 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73023 +#ifdef CONFIG_STACK_GROWSUP
73024 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73025 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73026 +#endif
73027 +
73028 + return true;
73029 +}
73030 +
73031 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73032 +{
73033 + if (vma->vm_start < len)
73034 + return -ENOMEM;
73035 + if (!(vma->vm_flags & VM_GROWSDOWN))
73036 + return vma->vm_start - len;
73037 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73038 + return vma->vm_start - len - sysctl_heap_stack_gap;
73039 + return -ENOMEM;
73040 +}
73041 +
73042 /* Get an address range which is currently unmapped.
73043 * For shmat() with addr=0.
73044 *
73045 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73046 if (flags & MAP_FIXED)
73047 return addr;
73048
73049 +#ifdef CONFIG_PAX_RANDMMAP
73050 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73051 +#endif
73052 +
73053 if (addr) {
73054 addr = PAGE_ALIGN(addr);
73055 - vma = find_vma(mm, addr);
73056 - if (TASK_SIZE - len >= addr &&
73057 - (!vma || addr + len <= vma->vm_start))
73058 - return addr;
73059 + if (TASK_SIZE - len >= addr) {
73060 + vma = find_vma(mm, addr);
73061 + if (check_heap_stack_gap(vma, addr, len))
73062 + return addr;
73063 + }
73064 }
73065 if (len > mm->cached_hole_size) {
73066 - start_addr = addr = mm->free_area_cache;
73067 + start_addr = addr = mm->free_area_cache;
73068 } else {
73069 - start_addr = addr = TASK_UNMAPPED_BASE;
73070 - mm->cached_hole_size = 0;
73071 + start_addr = addr = mm->mmap_base;
73072 + mm->cached_hole_size = 0;
73073 }
73074
73075 full_search:
73076 @@ -1426,34 +1625,40 @@ full_search:
73077 * Start a new search - just in case we missed
73078 * some holes.
73079 */
73080 - if (start_addr != TASK_UNMAPPED_BASE) {
73081 - addr = TASK_UNMAPPED_BASE;
73082 - start_addr = addr;
73083 + if (start_addr != mm->mmap_base) {
73084 + start_addr = addr = mm->mmap_base;
73085 mm->cached_hole_size = 0;
73086 goto full_search;
73087 }
73088 return -ENOMEM;
73089 }
73090 - if (!vma || addr + len <= vma->vm_start) {
73091 - /*
73092 - * Remember the place where we stopped the search:
73093 - */
73094 - mm->free_area_cache = addr + len;
73095 - return addr;
73096 - }
73097 + if (check_heap_stack_gap(vma, addr, len))
73098 + break;
73099 if (addr + mm->cached_hole_size < vma->vm_start)
73100 mm->cached_hole_size = vma->vm_start - addr;
73101 addr = vma->vm_end;
73102 }
73103 +
73104 + /*
73105 + * Remember the place where we stopped the search:
73106 + */
73107 + mm->free_area_cache = addr + len;
73108 + return addr;
73109 }
73110 #endif
73111
73112 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73113 {
73114 +
73115 +#ifdef CONFIG_PAX_SEGMEXEC
73116 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73117 + return;
73118 +#endif
73119 +
73120 /*
73121 * Is this a new hole at the lowest possible address?
73122 */
73123 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73124 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73125 mm->free_area_cache = addr;
73126 }
73127
73128 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73129 {
73130 struct vm_area_struct *vma;
73131 struct mm_struct *mm = current->mm;
73132 - unsigned long addr = addr0, start_addr;
73133 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73134
73135 /* requested length too big for entire address space */
73136 if (len > TASK_SIZE)
73137 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73138 if (flags & MAP_FIXED)
73139 return addr;
73140
73141 +#ifdef CONFIG_PAX_RANDMMAP
73142 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73143 +#endif
73144 +
73145 /* requesting a specific address */
73146 if (addr) {
73147 addr = PAGE_ALIGN(addr);
73148 - vma = find_vma(mm, addr);
73149 - if (TASK_SIZE - len >= addr &&
73150 - (!vma || addr + len <= vma->vm_start))
73151 - return addr;
73152 + if (TASK_SIZE - len >= addr) {
73153 + vma = find_vma(mm, addr);
73154 + if (check_heap_stack_gap(vma, addr, len))
73155 + return addr;
73156 + }
73157 }
73158
73159 /* check if free_area_cache is useful for us */
73160 @@ -1508,7 +1718,7 @@ try_again:
73161 * return with success:
73162 */
73163 vma = find_vma(mm, addr);
73164 - if (!vma || addr+len <= vma->vm_start)
73165 + if (check_heap_stack_gap(vma, addr, len))
73166 /* remember the address as a hint for next time */
73167 return (mm->free_area_cache = addr);
73168
73169 @@ -1517,8 +1727,8 @@ try_again:
73170 mm->cached_hole_size = vma->vm_start - addr;
73171
73172 /* try just below the current vma->vm_start */
73173 - addr = vma->vm_start-len;
73174 - } while (len < vma->vm_start);
73175 + addr = skip_heap_stack_gap(vma, len);
73176 + } while (!IS_ERR_VALUE(addr));
73177
73178 fail:
73179 /*
73180 @@ -1541,13 +1751,21 @@ fail:
73181 * can happen with large stack limits and large mmap()
73182 * allocations.
73183 */
73184 + mm->mmap_base = TASK_UNMAPPED_BASE;
73185 +
73186 +#ifdef CONFIG_PAX_RANDMMAP
73187 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73188 + mm->mmap_base += mm->delta_mmap;
73189 +#endif
73190 +
73191 + mm->free_area_cache = mm->mmap_base;
73192 mm->cached_hole_size = ~0UL;
73193 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73194 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73195 /*
73196 * Restore the topdown base:
73197 */
73198 - mm->free_area_cache = mm->mmap_base;
73199 + mm->mmap_base = base;
73200 + mm->free_area_cache = base;
73201 mm->cached_hole_size = ~0UL;
73202
73203 return addr;
73204 @@ -1556,6 +1774,12 @@ fail:
73205
73206 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73207 {
73208 +
73209 +#ifdef CONFIG_PAX_SEGMEXEC
73210 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73211 + return;
73212 +#endif
73213 +
73214 /*
73215 * Is this a new hole at the highest possible address?
73216 */
73217 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73218 mm->free_area_cache = addr;
73219
73220 /* dont allow allocations above current base */
73221 - if (mm->free_area_cache > mm->mmap_base)
73222 + if (mm->free_area_cache > mm->mmap_base) {
73223 mm->free_area_cache = mm->mmap_base;
73224 + mm->cached_hole_size = ~0UL;
73225 + }
73226 }
73227
73228 unsigned long
73229 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73230 return vma;
73231 }
73232
73233 +#ifdef CONFIG_PAX_SEGMEXEC
73234 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73235 +{
73236 + struct vm_area_struct *vma_m;
73237 +
73238 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73239 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73240 + BUG_ON(vma->vm_mirror);
73241 + return NULL;
73242 + }
73243 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73244 + vma_m = vma->vm_mirror;
73245 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73246 + BUG_ON(vma->vm_file != vma_m->vm_file);
73247 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73248 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73249 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73250 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73251 + return vma_m;
73252 +}
73253 +#endif
73254 +
73255 /*
73256 * Verify that the stack growth is acceptable and
73257 * update accounting. This is shared with both the
73258 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73259 return -ENOMEM;
73260
73261 /* Stack limit test */
73262 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73263 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73264 return -ENOMEM;
73265
73266 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73267 locked = mm->locked_vm + grow;
73268 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73269 limit >>= PAGE_SHIFT;
73270 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73271 if (locked > limit && !capable(CAP_IPC_LOCK))
73272 return -ENOMEM;
73273 }
73274 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73275 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73276 * vma is the last one with address > vma->vm_end. Have to extend vma.
73277 */
73278 +#ifndef CONFIG_IA64
73279 +static
73280 +#endif
73281 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73282 {
73283 int error;
73284 + bool locknext;
73285
73286 if (!(vma->vm_flags & VM_GROWSUP))
73287 return -EFAULT;
73288
73289 + /* Also guard against wrapping around to address 0. */
73290 + if (address < PAGE_ALIGN(address+1))
73291 + address = PAGE_ALIGN(address+1);
73292 + else
73293 + return -ENOMEM;
73294 +
73295 /*
73296 * We must make sure the anon_vma is allocated
73297 * so that the anon_vma locking is not a noop.
73298 */
73299 if (unlikely(anon_vma_prepare(vma)))
73300 return -ENOMEM;
73301 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73302 + if (locknext && anon_vma_prepare(vma->vm_next))
73303 + return -ENOMEM;
73304 vma_lock_anon_vma(vma);
73305 + if (locknext)
73306 + vma_lock_anon_vma(vma->vm_next);
73307
73308 /*
73309 * vma->vm_start/vm_end cannot change under us because the caller
73310 * is required to hold the mmap_sem in read mode. We need the
73311 - * anon_vma lock to serialize against concurrent expand_stacks.
73312 - * Also guard against wrapping around to address 0.
73313 + * anon_vma locks to serialize against concurrent expand_stacks
73314 + * and expand_upwards.
73315 */
73316 - if (address < PAGE_ALIGN(address+4))
73317 - address = PAGE_ALIGN(address+4);
73318 - else {
73319 - vma_unlock_anon_vma(vma);
73320 - return -ENOMEM;
73321 - }
73322 error = 0;
73323
73324 /* Somebody else might have raced and expanded it already */
73325 - if (address > vma->vm_end) {
73326 + 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)
73327 + error = -ENOMEM;
73328 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73329 unsigned long size, grow;
73330
73331 size = address - vma->vm_start;
73332 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73333 }
73334 }
73335 }
73336 + if (locknext)
73337 + vma_unlock_anon_vma(vma->vm_next);
73338 vma_unlock_anon_vma(vma);
73339 khugepaged_enter_vma_merge(vma);
73340 return error;
73341 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73342 unsigned long address)
73343 {
73344 int error;
73345 + bool lockprev = false;
73346 + struct vm_area_struct *prev;
73347
73348 /*
73349 * We must make sure the anon_vma is allocated
73350 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73351 if (error)
73352 return error;
73353
73354 + prev = vma->vm_prev;
73355 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73356 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73357 +#endif
73358 + if (lockprev && anon_vma_prepare(prev))
73359 + return -ENOMEM;
73360 + if (lockprev)
73361 + vma_lock_anon_vma(prev);
73362 +
73363 vma_lock_anon_vma(vma);
73364
73365 /*
73366 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73367 */
73368
73369 /* Somebody else might have raced and expanded it already */
73370 - if (address < vma->vm_start) {
73371 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73372 + error = -ENOMEM;
73373 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73374 unsigned long size, grow;
73375
73376 +#ifdef CONFIG_PAX_SEGMEXEC
73377 + struct vm_area_struct *vma_m;
73378 +
73379 + vma_m = pax_find_mirror_vma(vma);
73380 +#endif
73381 +
73382 size = vma->vm_end - address;
73383 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73384
73385 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73386 if (!error) {
73387 vma->vm_start = address;
73388 vma->vm_pgoff -= grow;
73389 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73390 +
73391 +#ifdef CONFIG_PAX_SEGMEXEC
73392 + if (vma_m) {
73393 + vma_m->vm_start -= grow << PAGE_SHIFT;
73394 + vma_m->vm_pgoff -= grow;
73395 + }
73396 +#endif
73397 +
73398 perf_event_mmap(vma);
73399 }
73400 }
73401 }
73402 vma_unlock_anon_vma(vma);
73403 + if (lockprev)
73404 + vma_unlock_anon_vma(prev);
73405 khugepaged_enter_vma_merge(vma);
73406 return error;
73407 }
73408 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73409 do {
73410 long nrpages = vma_pages(vma);
73411
73412 +#ifdef CONFIG_PAX_SEGMEXEC
73413 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73414 + vma = remove_vma(vma);
73415 + continue;
73416 + }
73417 +#endif
73418 +
73419 if (vma->vm_flags & VM_ACCOUNT)
73420 nr_accounted += nrpages;
73421 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73422 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73423 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73424 vma->vm_prev = NULL;
73425 do {
73426 +
73427 +#ifdef CONFIG_PAX_SEGMEXEC
73428 + if (vma->vm_mirror) {
73429 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73430 + vma->vm_mirror->vm_mirror = NULL;
73431 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73432 + vma->vm_mirror = NULL;
73433 + }
73434 +#endif
73435 +
73436 rb_erase(&vma->vm_rb, &mm->mm_rb);
73437 mm->map_count--;
73438 tail_vma = vma;
73439 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73440 struct vm_area_struct *new;
73441 int err = -ENOMEM;
73442
73443 +#ifdef CONFIG_PAX_SEGMEXEC
73444 + struct vm_area_struct *vma_m, *new_m = NULL;
73445 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73446 +#endif
73447 +
73448 if (is_vm_hugetlb_page(vma) && (addr &
73449 ~(huge_page_mask(hstate_vma(vma)))))
73450 return -EINVAL;
73451
73452 +#ifdef CONFIG_PAX_SEGMEXEC
73453 + vma_m = pax_find_mirror_vma(vma);
73454 +#endif
73455 +
73456 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73457 if (!new)
73458 goto out_err;
73459
73460 +#ifdef CONFIG_PAX_SEGMEXEC
73461 + if (vma_m) {
73462 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73463 + if (!new_m) {
73464 + kmem_cache_free(vm_area_cachep, new);
73465 + goto out_err;
73466 + }
73467 + }
73468 +#endif
73469 +
73470 /* most fields are the same, copy all, and then fixup */
73471 *new = *vma;
73472
73473 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73474 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73475 }
73476
73477 +#ifdef CONFIG_PAX_SEGMEXEC
73478 + if (vma_m) {
73479 + *new_m = *vma_m;
73480 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73481 + new_m->vm_mirror = new;
73482 + new->vm_mirror = new_m;
73483 +
73484 + if (new_below)
73485 + new_m->vm_end = addr_m;
73486 + else {
73487 + new_m->vm_start = addr_m;
73488 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73489 + }
73490 + }
73491 +#endif
73492 +
73493 pol = mpol_dup(vma_policy(vma));
73494 if (IS_ERR(pol)) {
73495 err = PTR_ERR(pol);
73496 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73497 else
73498 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73499
73500 +#ifdef CONFIG_PAX_SEGMEXEC
73501 + if (!err && vma_m) {
73502 + if (anon_vma_clone(new_m, vma_m))
73503 + goto out_free_mpol;
73504 +
73505 + mpol_get(pol);
73506 + vma_set_policy(new_m, pol);
73507 +
73508 + if (new_m->vm_file) {
73509 + get_file(new_m->vm_file);
73510 + if (vma_m->vm_flags & VM_EXECUTABLE)
73511 + added_exe_file_vma(mm);
73512 + }
73513 +
73514 + if (new_m->vm_ops && new_m->vm_ops->open)
73515 + new_m->vm_ops->open(new_m);
73516 +
73517 + if (new_below)
73518 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73519 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73520 + else
73521 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73522 +
73523 + if (err) {
73524 + if (new_m->vm_ops && new_m->vm_ops->close)
73525 + new_m->vm_ops->close(new_m);
73526 + if (new_m->vm_file) {
73527 + if (vma_m->vm_flags & VM_EXECUTABLE)
73528 + removed_exe_file_vma(mm);
73529 + fput(new_m->vm_file);
73530 + }
73531 + mpol_put(pol);
73532 + }
73533 + }
73534 +#endif
73535 +
73536 /* Success. */
73537 if (!err)
73538 return 0;
73539 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73540 removed_exe_file_vma(mm);
73541 fput(new->vm_file);
73542 }
73543 - unlink_anon_vmas(new);
73544 out_free_mpol:
73545 mpol_put(pol);
73546 out_free_vma:
73547 +
73548 +#ifdef CONFIG_PAX_SEGMEXEC
73549 + if (new_m) {
73550 + unlink_anon_vmas(new_m);
73551 + kmem_cache_free(vm_area_cachep, new_m);
73552 + }
73553 +#endif
73554 +
73555 + unlink_anon_vmas(new);
73556 kmem_cache_free(vm_area_cachep, new);
73557 out_err:
73558 return err;
73559 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73560 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73561 unsigned long addr, int new_below)
73562 {
73563 +
73564 +#ifdef CONFIG_PAX_SEGMEXEC
73565 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73566 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73567 + if (mm->map_count >= sysctl_max_map_count-1)
73568 + return -ENOMEM;
73569 + } else
73570 +#endif
73571 +
73572 if (mm->map_count >= sysctl_max_map_count)
73573 return -ENOMEM;
73574
73575 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73576 * work. This now handles partial unmappings.
73577 * Jeremy Fitzhardinge <jeremy@goop.org>
73578 */
73579 +#ifdef CONFIG_PAX_SEGMEXEC
73580 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73581 {
73582 + int ret = __do_munmap(mm, start, len);
73583 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73584 + return ret;
73585 +
73586 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73587 +}
73588 +
73589 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73590 +#else
73591 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73592 +#endif
73593 +{
73594 unsigned long end;
73595 struct vm_area_struct *vma, *prev, *last;
73596
73597 + /*
73598 + * mm->mmap_sem is required to protect against another thread
73599 + * changing the mappings in case we sleep.
73600 + */
73601 + verify_mm_writelocked(mm);
73602 +
73603 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73604 return -EINVAL;
73605
73606 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73607 /* Fix up all other VM information */
73608 remove_vma_list(mm, vma);
73609
73610 + track_exec_limit(mm, start, end, 0UL);
73611 +
73612 return 0;
73613 }
73614
73615 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73616 int ret;
73617 struct mm_struct *mm = current->mm;
73618
73619 +
73620 +#ifdef CONFIG_PAX_SEGMEXEC
73621 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73622 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73623 + return -EINVAL;
73624 +#endif
73625 +
73626 down_write(&mm->mmap_sem);
73627 ret = do_munmap(mm, start, len);
73628 up_write(&mm->mmap_sem);
73629 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73630 return vm_munmap(addr, len);
73631 }
73632
73633 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73634 -{
73635 -#ifdef CONFIG_DEBUG_VM
73636 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73637 - WARN_ON(1);
73638 - up_read(&mm->mmap_sem);
73639 - }
73640 -#endif
73641 -}
73642 -
73643 /*
73644 * this is really a simplified "do_mmap". it only handles
73645 * anonymous maps. eventually we may be able to do some
73646 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73647 struct rb_node ** rb_link, * rb_parent;
73648 pgoff_t pgoff = addr >> PAGE_SHIFT;
73649 int error;
73650 + unsigned long charged;
73651
73652 len = PAGE_ALIGN(len);
73653 if (!len)
73654 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73655
73656 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73657
73658 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73659 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73660 + flags &= ~VM_EXEC;
73661 +
73662 +#ifdef CONFIG_PAX_MPROTECT
73663 + if (mm->pax_flags & MF_PAX_MPROTECT)
73664 + flags &= ~VM_MAYEXEC;
73665 +#endif
73666 +
73667 + }
73668 +#endif
73669 +
73670 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73671 if (error & ~PAGE_MASK)
73672 return error;
73673
73674 + charged = len >> PAGE_SHIFT;
73675 +
73676 /*
73677 * mlock MCL_FUTURE?
73678 */
73679 if (mm->def_flags & VM_LOCKED) {
73680 unsigned long locked, lock_limit;
73681 - locked = len >> PAGE_SHIFT;
73682 + locked = charged;
73683 locked += mm->locked_vm;
73684 lock_limit = rlimit(RLIMIT_MEMLOCK);
73685 lock_limit >>= PAGE_SHIFT;
73686 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73687 /*
73688 * Clear old maps. this also does some error checking for us
73689 */
73690 - munmap_back:
73691 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73692 if (vma && vma->vm_start < addr + len) {
73693 if (do_munmap(mm, addr, len))
73694 return -ENOMEM;
73695 - goto munmap_back;
73696 - }
73697 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73698 + BUG_ON(vma && vma->vm_start < addr + len);
73699 + }
73700
73701 /* Check against address space limits *after* clearing old maps... */
73702 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73703 + if (!may_expand_vm(mm, charged))
73704 return -ENOMEM;
73705
73706 if (mm->map_count > sysctl_max_map_count)
73707 return -ENOMEM;
73708
73709 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73710 + if (security_vm_enough_memory_mm(mm, charged))
73711 return -ENOMEM;
73712
73713 /* Can we just expand an old private anonymous mapping? */
73714 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73715 */
73716 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73717 if (!vma) {
73718 - vm_unacct_memory(len >> PAGE_SHIFT);
73719 + vm_unacct_memory(charged);
73720 return -ENOMEM;
73721 }
73722
73723 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73724 vma_link(mm, vma, prev, rb_link, rb_parent);
73725 out:
73726 perf_event_mmap(vma);
73727 - mm->total_vm += len >> PAGE_SHIFT;
73728 + mm->total_vm += charged;
73729 if (flags & VM_LOCKED) {
73730 if (!mlock_vma_pages_range(vma, addr, addr + len))
73731 - mm->locked_vm += (len >> PAGE_SHIFT);
73732 + mm->locked_vm += charged;
73733 }
73734 + track_exec_limit(mm, addr, addr + len, flags);
73735 return addr;
73736 }
73737
73738 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73739 while (vma) {
73740 if (vma->vm_flags & VM_ACCOUNT)
73741 nr_accounted += vma_pages(vma);
73742 + vma->vm_mirror = NULL;
73743 vma = remove_vma(vma);
73744 }
73745 vm_unacct_memory(nr_accounted);
73746 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73747 struct vm_area_struct * __vma, * prev;
73748 struct rb_node ** rb_link, * rb_parent;
73749
73750 +#ifdef CONFIG_PAX_SEGMEXEC
73751 + struct vm_area_struct *vma_m = NULL;
73752 +#endif
73753 +
73754 + if (security_mmap_addr(vma->vm_start))
73755 + return -EPERM;
73756 +
73757 /*
73758 * The vm_pgoff of a purely anonymous vma should be irrelevant
73759 * until its first write fault, when page's anon_vma and index
73760 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73761 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73762 return -ENOMEM;
73763
73764 +#ifdef CONFIG_PAX_SEGMEXEC
73765 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73766 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73767 + if (!vma_m)
73768 + return -ENOMEM;
73769 + }
73770 +#endif
73771 +
73772 vma_link(mm, vma, prev, rb_link, rb_parent);
73773 +
73774 +#ifdef CONFIG_PAX_SEGMEXEC
73775 + if (vma_m)
73776 + BUG_ON(pax_mirror_vma(vma_m, vma));
73777 +#endif
73778 +
73779 return 0;
73780 }
73781
73782 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73783 struct mempolicy *pol;
73784 bool faulted_in_anon_vma = true;
73785
73786 + BUG_ON(vma->vm_mirror);
73787 +
73788 /*
73789 * If anonymous vma has not yet been faulted, update new pgoff
73790 * to match new location, to increase its chance of merging.
73791 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73792 return NULL;
73793 }
73794
73795 +#ifdef CONFIG_PAX_SEGMEXEC
73796 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73797 +{
73798 + struct vm_area_struct *prev_m;
73799 + struct rb_node **rb_link_m, *rb_parent_m;
73800 + struct mempolicy *pol_m;
73801 +
73802 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73803 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73804 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73805 + *vma_m = *vma;
73806 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73807 + if (anon_vma_clone(vma_m, vma))
73808 + return -ENOMEM;
73809 + pol_m = vma_policy(vma_m);
73810 + mpol_get(pol_m);
73811 + vma_set_policy(vma_m, pol_m);
73812 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73813 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73814 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73815 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73816 + if (vma_m->vm_file)
73817 + get_file(vma_m->vm_file);
73818 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73819 + vma_m->vm_ops->open(vma_m);
73820 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73821 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73822 + vma_m->vm_mirror = vma;
73823 + vma->vm_mirror = vma_m;
73824 + return 0;
73825 +}
73826 +#endif
73827 +
73828 /*
73829 * Return true if the calling process may expand its vm space by the passed
73830 * number of pages
73831 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73832
73833 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73834
73835 +#ifdef CONFIG_PAX_RANDMMAP
73836 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73837 + cur -= mm->brk_gap;
73838 +#endif
73839 +
73840 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73841 if (cur + npages > lim)
73842 return 0;
73843 return 1;
73844 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
73845 vma->vm_start = addr;
73846 vma->vm_end = addr + len;
73847
73848 +#ifdef CONFIG_PAX_MPROTECT
73849 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73850 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73851 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73852 + return -EPERM;
73853 + if (!(vm_flags & VM_EXEC))
73854 + vm_flags &= ~VM_MAYEXEC;
73855 +#else
73856 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73857 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73858 +#endif
73859 + else
73860 + vm_flags &= ~VM_MAYWRITE;
73861 + }
73862 +#endif
73863 +
73864 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73865 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73866
73867 diff --git a/mm/mprotect.c b/mm/mprotect.c
73868 index a409926..8b32e6d 100644
73869 --- a/mm/mprotect.c
73870 +++ b/mm/mprotect.c
73871 @@ -23,10 +23,17 @@
73872 #include <linux/mmu_notifier.h>
73873 #include <linux/migrate.h>
73874 #include <linux/perf_event.h>
73875 +
73876 +#ifdef CONFIG_PAX_MPROTECT
73877 +#include <linux/elf.h>
73878 +#include <linux/binfmts.h>
73879 +#endif
73880 +
73881 #include <asm/uaccess.h>
73882 #include <asm/pgtable.h>
73883 #include <asm/cacheflush.h>
73884 #include <asm/tlbflush.h>
73885 +#include <asm/mmu_context.h>
73886
73887 #ifndef pgprot_modify
73888 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73889 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73890 flush_tlb_range(vma, start, end);
73891 }
73892
73893 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73894 +/* called while holding the mmap semaphor for writing except stack expansion */
73895 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73896 +{
73897 + unsigned long oldlimit, newlimit = 0UL;
73898 +
73899 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73900 + return;
73901 +
73902 + spin_lock(&mm->page_table_lock);
73903 + oldlimit = mm->context.user_cs_limit;
73904 + if ((prot & VM_EXEC) && oldlimit < end)
73905 + /* USER_CS limit moved up */
73906 + newlimit = end;
73907 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73908 + /* USER_CS limit moved down */
73909 + newlimit = start;
73910 +
73911 + if (newlimit) {
73912 + mm->context.user_cs_limit = newlimit;
73913 +
73914 +#ifdef CONFIG_SMP
73915 + wmb();
73916 + cpus_clear(mm->context.cpu_user_cs_mask);
73917 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73918 +#endif
73919 +
73920 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73921 + }
73922 + spin_unlock(&mm->page_table_lock);
73923 + if (newlimit == end) {
73924 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73925 +
73926 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73927 + if (is_vm_hugetlb_page(vma))
73928 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73929 + else
73930 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73931 + }
73932 +}
73933 +#endif
73934 +
73935 int
73936 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73937 unsigned long start, unsigned long end, unsigned long newflags)
73938 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73939 int error;
73940 int dirty_accountable = 0;
73941
73942 +#ifdef CONFIG_PAX_SEGMEXEC
73943 + struct vm_area_struct *vma_m = NULL;
73944 + unsigned long start_m, end_m;
73945 +
73946 + start_m = start + SEGMEXEC_TASK_SIZE;
73947 + end_m = end + SEGMEXEC_TASK_SIZE;
73948 +#endif
73949 +
73950 if (newflags == oldflags) {
73951 *pprev = vma;
73952 return 0;
73953 }
73954
73955 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73956 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73957 +
73958 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73959 + return -ENOMEM;
73960 +
73961 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73962 + return -ENOMEM;
73963 + }
73964 +
73965 /*
73966 * If we make a private mapping writable we increase our commit;
73967 * but (without finer accounting) cannot reduce our commit if we
73968 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73969 }
73970 }
73971
73972 +#ifdef CONFIG_PAX_SEGMEXEC
73973 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73974 + if (start != vma->vm_start) {
73975 + error = split_vma(mm, vma, start, 1);
73976 + if (error)
73977 + goto fail;
73978 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73979 + *pprev = (*pprev)->vm_next;
73980 + }
73981 +
73982 + if (end != vma->vm_end) {
73983 + error = split_vma(mm, vma, end, 0);
73984 + if (error)
73985 + goto fail;
73986 + }
73987 +
73988 + if (pax_find_mirror_vma(vma)) {
73989 + error = __do_munmap(mm, start_m, end_m - start_m);
73990 + if (error)
73991 + goto fail;
73992 + } else {
73993 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73994 + if (!vma_m) {
73995 + error = -ENOMEM;
73996 + goto fail;
73997 + }
73998 + vma->vm_flags = newflags;
73999 + error = pax_mirror_vma(vma_m, vma);
74000 + if (error) {
74001 + vma->vm_flags = oldflags;
74002 + goto fail;
74003 + }
74004 + }
74005 + }
74006 +#endif
74007 +
74008 /*
74009 * First try to merge with previous and/or next vma.
74010 */
74011 @@ -204,9 +307,21 @@ success:
74012 * vm_flags and vm_page_prot are protected by the mmap_sem
74013 * held in write mode.
74014 */
74015 +
74016 +#ifdef CONFIG_PAX_SEGMEXEC
74017 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74018 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74019 +#endif
74020 +
74021 vma->vm_flags = newflags;
74022 +
74023 +#ifdef CONFIG_PAX_MPROTECT
74024 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74025 + mm->binfmt->handle_mprotect(vma, newflags);
74026 +#endif
74027 +
74028 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74029 - vm_get_page_prot(newflags));
74030 + vm_get_page_prot(vma->vm_flags));
74031
74032 if (vma_wants_writenotify(vma)) {
74033 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74034 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74035 end = start + len;
74036 if (end <= start)
74037 return -ENOMEM;
74038 +
74039 +#ifdef CONFIG_PAX_SEGMEXEC
74040 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74041 + if (end > SEGMEXEC_TASK_SIZE)
74042 + return -EINVAL;
74043 + } else
74044 +#endif
74045 +
74046 + if (end > TASK_SIZE)
74047 + return -EINVAL;
74048 +
74049 if (!arch_validate_prot(prot))
74050 return -EINVAL;
74051
74052 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74053 /*
74054 * Does the application expect PROT_READ to imply PROT_EXEC:
74055 */
74056 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74057 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74058 prot |= PROT_EXEC;
74059
74060 vm_flags = calc_vm_prot_bits(prot);
74061 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74062 if (start > vma->vm_start)
74063 prev = vma;
74064
74065 +#ifdef CONFIG_PAX_MPROTECT
74066 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74067 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74068 +#endif
74069 +
74070 for (nstart = start ; ; ) {
74071 unsigned long newflags;
74072
74073 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74074
74075 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74076 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74077 + if (prot & (PROT_WRITE | PROT_EXEC))
74078 + gr_log_rwxmprotect(vma->vm_file);
74079 +
74080 + error = -EACCES;
74081 + goto out;
74082 + }
74083 +
74084 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74085 error = -EACCES;
74086 goto out;
74087 }
74088 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74089 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74090 if (error)
74091 goto out;
74092 +
74093 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74094 +
74095 nstart = tmp;
74096
74097 if (nstart < prev->vm_end)
74098 diff --git a/mm/mremap.c b/mm/mremap.c
74099 index cc06d0e..40b5d18 100644
74100 --- a/mm/mremap.c
74101 +++ b/mm/mremap.c
74102 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74103 continue;
74104 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74105 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74106 +
74107 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74108 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74109 + pte = pte_exprotect(pte);
74110 +#endif
74111 +
74112 set_pte_at(mm, new_addr, new_pte, pte);
74113 }
74114
74115 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74116 if (is_vm_hugetlb_page(vma))
74117 goto Einval;
74118
74119 +#ifdef CONFIG_PAX_SEGMEXEC
74120 + if (pax_find_mirror_vma(vma))
74121 + goto Einval;
74122 +#endif
74123 +
74124 /* We can't remap across vm area boundaries */
74125 if (old_len > vma->vm_end - addr)
74126 goto Efault;
74127 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74128 unsigned long ret = -EINVAL;
74129 unsigned long charged = 0;
74130 unsigned long map_flags;
74131 + unsigned long pax_task_size = TASK_SIZE;
74132
74133 if (new_addr & ~PAGE_MASK)
74134 goto out;
74135
74136 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74137 +#ifdef CONFIG_PAX_SEGMEXEC
74138 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74139 + pax_task_size = SEGMEXEC_TASK_SIZE;
74140 +#endif
74141 +
74142 + pax_task_size -= PAGE_SIZE;
74143 +
74144 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74145 goto out;
74146
74147 /* Check if the location we're moving into overlaps the
74148 * old location at all, and fail if it does.
74149 */
74150 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74151 - goto out;
74152 -
74153 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74154 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74155 goto out;
74156
74157 ret = do_munmap(mm, new_addr, new_len);
74158 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74159 struct vm_area_struct *vma;
74160 unsigned long ret = -EINVAL;
74161 unsigned long charged = 0;
74162 + unsigned long pax_task_size = TASK_SIZE;
74163
74164 down_write(&current->mm->mmap_sem);
74165
74166 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74167 if (!new_len)
74168 goto out;
74169
74170 +#ifdef CONFIG_PAX_SEGMEXEC
74171 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74172 + pax_task_size = SEGMEXEC_TASK_SIZE;
74173 +#endif
74174 +
74175 + pax_task_size -= PAGE_SIZE;
74176 +
74177 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74178 + old_len > pax_task_size || addr > pax_task_size-old_len)
74179 + goto out;
74180 +
74181 if (flags & MREMAP_FIXED) {
74182 if (flags & MREMAP_MAYMOVE)
74183 ret = mremap_to(addr, old_len, new_addr, new_len);
74184 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74185 addr + new_len);
74186 }
74187 ret = addr;
74188 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74189 goto out;
74190 }
74191 }
74192 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74193 goto out;
74194 }
74195
74196 + map_flags = vma->vm_flags;
74197 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74198 + if (!(ret & ~PAGE_MASK)) {
74199 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74200 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74201 + }
74202 }
74203 out:
74204 if (ret & ~PAGE_MASK)
74205 diff --git a/mm/nommu.c b/mm/nommu.c
74206 index d4b0c10..ed421b5 100644
74207 --- a/mm/nommu.c
74208 +++ b/mm/nommu.c
74209 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74210 int sysctl_overcommit_ratio = 50; /* default is 50% */
74211 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74212 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74213 -int heap_stack_gap = 0;
74214
74215 atomic_long_t mmap_pages_allocated;
74216
74217 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74218 EXPORT_SYMBOL(find_vma);
74219
74220 /*
74221 - * find a VMA
74222 - * - we don't extend stack VMAs under NOMMU conditions
74223 - */
74224 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74225 -{
74226 - return find_vma(mm, addr);
74227 -}
74228 -
74229 -/*
74230 * expand a stack to a given address
74231 * - not supported under NOMMU conditions
74232 */
74233 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74234
74235 /* most fields are the same, copy all, and then fixup */
74236 *new = *vma;
74237 + INIT_LIST_HEAD(&new->anon_vma_chain);
74238 *region = *vma->vm_region;
74239 new->vm_region = region;
74240
74241 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74242 index c13ea75..081ab2c 100644
74243 --- a/mm/page_alloc.c
74244 +++ b/mm/page_alloc.c
74245 @@ -340,7 +340,7 @@ out:
74246 * This usage means that zero-order pages may not be compound.
74247 */
74248
74249 -static void free_compound_page(struct page *page)
74250 +void free_compound_page(struct page *page)
74251 {
74252 __free_pages_ok(page, compound_order(page));
74253 }
74254 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74255 int i;
74256 int bad = 0;
74257
74258 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74259 + unsigned long index = 1UL << order;
74260 +#endif
74261 +
74262 trace_mm_page_free(page, order);
74263 kmemcheck_free_shadow(page, order);
74264
74265 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74266 debug_check_no_obj_freed(page_address(page),
74267 PAGE_SIZE << order);
74268 }
74269 +
74270 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74271 + for (; index; --index)
74272 + sanitize_highpage(page + index - 1);
74273 +#endif
74274 +
74275 arch_free_page(page, order);
74276 kernel_map_pages(page, 1 << order, 0);
74277
74278 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74279 arch_alloc_page(page, order);
74280 kernel_map_pages(page, 1 << order, 1);
74281
74282 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74283 if (gfp_flags & __GFP_ZERO)
74284 prep_zero_page(page, order, gfp_flags);
74285 +#endif
74286
74287 if (order && (gfp_flags & __GFP_COMP))
74288 prep_compound_page(page, order);
74289 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74290 unsigned long pfn;
74291
74292 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74293 +#ifdef CONFIG_X86_32
74294 + /* boot failures in VMware 8 on 32bit vanilla since
74295 + this change */
74296 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74297 +#else
74298 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74299 +#endif
74300 return 1;
74301 }
74302 return 0;
74303 diff --git a/mm/percpu.c b/mm/percpu.c
74304 index bb4be74..a43ea85 100644
74305 --- a/mm/percpu.c
74306 +++ b/mm/percpu.c
74307 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74308 static unsigned int pcpu_high_unit_cpu __read_mostly;
74309
74310 /* the address of the first chunk which starts with the kernel static area */
74311 -void *pcpu_base_addr __read_mostly;
74312 +void *pcpu_base_addr __read_only;
74313 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74314
74315 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74316 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74317 index 926b466..b23df53 100644
74318 --- a/mm/process_vm_access.c
74319 +++ b/mm/process_vm_access.c
74320 @@ -13,6 +13,7 @@
74321 #include <linux/uio.h>
74322 #include <linux/sched.h>
74323 #include <linux/highmem.h>
74324 +#include <linux/security.h>
74325 #include <linux/ptrace.h>
74326 #include <linux/slab.h>
74327 #include <linux/syscalls.h>
74328 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74329 size_t iov_l_curr_offset = 0;
74330 ssize_t iov_len;
74331
74332 + return -ENOSYS; // PaX: until properly audited
74333 +
74334 /*
74335 * Work out how many pages of struct pages we're going to need
74336 * when eventually calling get_user_pages
74337 */
74338 for (i = 0; i < riovcnt; i++) {
74339 iov_len = rvec[i].iov_len;
74340 - if (iov_len > 0) {
74341 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74342 - + iov_len)
74343 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74344 - / PAGE_SIZE + 1;
74345 - nr_pages = max(nr_pages, nr_pages_iov);
74346 - }
74347 + if (iov_len <= 0)
74348 + continue;
74349 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74350 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74351 + nr_pages = max(nr_pages, nr_pages_iov);
74352 }
74353
74354 if (nr_pages == 0)
74355 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74356 goto free_proc_pages;
74357 }
74358
74359 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74360 + rc = -EPERM;
74361 + goto put_task_struct;
74362 + }
74363 +
74364 mm = mm_access(task, PTRACE_MODE_ATTACH);
74365 if (!mm || IS_ERR(mm)) {
74366 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74367 diff --git a/mm/rmap.c b/mm/rmap.c
74368 index 0f3b7cd..c5652b6 100644
74369 --- a/mm/rmap.c
74370 +++ b/mm/rmap.c
74371 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74372 struct anon_vma *anon_vma = vma->anon_vma;
74373 struct anon_vma_chain *avc;
74374
74375 +#ifdef CONFIG_PAX_SEGMEXEC
74376 + struct anon_vma_chain *avc_m = NULL;
74377 +#endif
74378 +
74379 might_sleep();
74380 if (unlikely(!anon_vma)) {
74381 struct mm_struct *mm = vma->vm_mm;
74382 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74383 if (!avc)
74384 goto out_enomem;
74385
74386 +#ifdef CONFIG_PAX_SEGMEXEC
74387 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74388 + if (!avc_m)
74389 + goto out_enomem_free_avc;
74390 +#endif
74391 +
74392 anon_vma = find_mergeable_anon_vma(vma);
74393 allocated = NULL;
74394 if (!anon_vma) {
74395 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74396 /* page_table_lock to protect against threads */
74397 spin_lock(&mm->page_table_lock);
74398 if (likely(!vma->anon_vma)) {
74399 +
74400 +#ifdef CONFIG_PAX_SEGMEXEC
74401 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74402 +
74403 + if (vma_m) {
74404 + BUG_ON(vma_m->anon_vma);
74405 + vma_m->anon_vma = anon_vma;
74406 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74407 + avc_m = NULL;
74408 + }
74409 +#endif
74410 +
74411 vma->anon_vma = anon_vma;
74412 anon_vma_chain_link(vma, avc, anon_vma);
74413 allocated = NULL;
74414 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74415
74416 if (unlikely(allocated))
74417 put_anon_vma(allocated);
74418 +
74419 +#ifdef CONFIG_PAX_SEGMEXEC
74420 + if (unlikely(avc_m))
74421 + anon_vma_chain_free(avc_m);
74422 +#endif
74423 +
74424 if (unlikely(avc))
74425 anon_vma_chain_free(avc);
74426 }
74427 return 0;
74428
74429 out_enomem_free_avc:
74430 +
74431 +#ifdef CONFIG_PAX_SEGMEXEC
74432 + if (avc_m)
74433 + anon_vma_chain_free(avc_m);
74434 +#endif
74435 +
74436 anon_vma_chain_free(avc);
74437 out_enomem:
74438 return -ENOMEM;
74439 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74440 * Attach the anon_vmas from src to dst.
74441 * Returns 0 on success, -ENOMEM on failure.
74442 */
74443 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74444 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74445 {
74446 struct anon_vma_chain *avc, *pavc;
74447 struct anon_vma *root = NULL;
74448 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74449 * the corresponding VMA in the parent process is attached to.
74450 * Returns 0 on success, non-zero on failure.
74451 */
74452 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74453 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74454 {
74455 struct anon_vma_chain *avc;
74456 struct anon_vma *anon_vma;
74457 diff --git a/mm/shmem.c b/mm/shmem.c
74458 index d2eeca1..3f160be 100644
74459 --- a/mm/shmem.c
74460 +++ b/mm/shmem.c
74461 @@ -31,7 +31,7 @@
74462 #include <linux/export.h>
74463 #include <linux/swap.h>
74464
74465 -static struct vfsmount *shm_mnt;
74466 +struct vfsmount *shm_mnt;
74467
74468 #ifdef CONFIG_SHMEM
74469 /*
74470 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74471 #define BOGO_DIRENT_SIZE 20
74472
74473 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74474 -#define SHORT_SYMLINK_LEN 128
74475 +#define SHORT_SYMLINK_LEN 64
74476
74477 struct shmem_xattr {
74478 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74479 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74480 int err = -ENOMEM;
74481
74482 /* Round up to L1_CACHE_BYTES to resist false sharing */
74483 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74484 - L1_CACHE_BYTES), GFP_KERNEL);
74485 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74486 if (!sbinfo)
74487 return -ENOMEM;
74488
74489 diff --git a/mm/slab.c b/mm/slab.c
74490 index d066037..5bb78d9 100644
74491 --- a/mm/slab.c
74492 +++ b/mm/slab.c
74493 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74494
74495 /* Legal flag mask for kmem_cache_create(). */
74496 #if DEBUG
74497 -# define CREATE_MASK (SLAB_RED_ZONE | \
74498 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74499 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74500 SLAB_CACHE_DMA | \
74501 SLAB_STORE_USER | \
74502 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74503 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74504 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74505 #else
74506 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74507 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74508 SLAB_CACHE_DMA | \
74509 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74510 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74511 @@ -322,7 +322,7 @@ struct kmem_list3 {
74512 * Need this for bootstrapping a per node allocator.
74513 */
74514 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74515 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74516 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74517 #define CACHE_CACHE 0
74518 #define SIZE_AC MAX_NUMNODES
74519 #define SIZE_L3 (2 * MAX_NUMNODES)
74520 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74521 if ((x)->max_freeable < i) \
74522 (x)->max_freeable = i; \
74523 } while (0)
74524 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74525 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74526 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74527 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74528 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74529 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74530 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74531 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74532 #else
74533 #define STATS_INC_ACTIVE(x) do { } while (0)
74534 #define STATS_DEC_ACTIVE(x) do { } while (0)
74535 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74536 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74537 */
74538 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74539 - const struct slab *slab, void *obj)
74540 + const struct slab *slab, const void *obj)
74541 {
74542 u32 offset = (obj - slab->s_mem);
74543 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74544 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74545 struct cache_names {
74546 char *name;
74547 char *name_dma;
74548 + char *name_usercopy;
74549 };
74550
74551 static struct cache_names __initdata cache_names[] = {
74552 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74553 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74554 #include <linux/kmalloc_sizes.h>
74555 - {NULL,}
74556 + {NULL}
74557 #undef CACHE
74558 };
74559
74560 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74561 if (unlikely(gfpflags & GFP_DMA))
74562 return csizep->cs_dmacachep;
74563 #endif
74564 +
74565 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74566 + if (unlikely(gfpflags & GFP_USERCOPY))
74567 + return csizep->cs_usercopycachep;
74568 +#endif
74569 +
74570 return csizep->cs_cachep;
74571 }
74572
74573 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74574 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74575 sizes[INDEX_AC].cs_size,
74576 ARCH_KMALLOC_MINALIGN,
74577 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74578 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74579 NULL);
74580
74581 if (INDEX_AC != INDEX_L3) {
74582 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74583 __kmem_cache_create(names[INDEX_L3].name,
74584 sizes[INDEX_L3].cs_size,
74585 ARCH_KMALLOC_MINALIGN,
74586 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74587 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74588 NULL);
74589 }
74590
74591 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74592 sizes->cs_cachep = __kmem_cache_create(names->name,
74593 sizes->cs_size,
74594 ARCH_KMALLOC_MINALIGN,
74595 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74596 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74597 NULL);
74598 }
74599 #ifdef CONFIG_ZONE_DMA
74600 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74601 SLAB_PANIC,
74602 NULL);
74603 #endif
74604 +
74605 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74606 + sizes->cs_usercopycachep = kmem_cache_create(
74607 + names->name_usercopy,
74608 + sizes->cs_size,
74609 + ARCH_KMALLOC_MINALIGN,
74610 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74611 + NULL);
74612 +#endif
74613 +
74614 sizes++;
74615 names++;
74616 }
74617 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74618 }
74619 /* cpu stats */
74620 {
74621 - unsigned long allochit = atomic_read(&cachep->allochit);
74622 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74623 - unsigned long freehit = atomic_read(&cachep->freehit);
74624 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74625 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74626 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74627 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74628 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74629
74630 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74631 allochit, allocmiss, freehit, freemiss);
74632 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74633 {
74634 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74635 #ifdef CONFIG_DEBUG_SLAB_LEAK
74636 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74637 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74638 #endif
74639 return 0;
74640 }
74641 module_init(slab_proc_init);
74642 #endif
74643
74644 +bool is_usercopy_object(const void *ptr)
74645 +{
74646 + struct page *page;
74647 + struct kmem_cache *cachep;
74648 +
74649 + if (ZERO_OR_NULL_PTR(ptr))
74650 + return false;
74651 +
74652 + if (!slab_is_available())
74653 + return false;
74654 +
74655 + if (!virt_addr_valid(ptr))
74656 + return false;
74657 +
74658 + page = virt_to_head_page(ptr);
74659 +
74660 + if (!PageSlab(page))
74661 + return false;
74662 +
74663 + cachep = page_get_cache(page);
74664 + return cachep->flags & SLAB_USERCOPY;
74665 +}
74666 +
74667 +#ifdef CONFIG_PAX_USERCOPY
74668 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74669 +{
74670 + struct page *page;
74671 + struct kmem_cache *cachep;
74672 + struct slab *slabp;
74673 + unsigned int objnr;
74674 + unsigned long offset;
74675 +
74676 + if (ZERO_OR_NULL_PTR(ptr))
74677 + return "<null>";
74678 +
74679 + if (!virt_addr_valid(ptr))
74680 + return NULL;
74681 +
74682 + page = virt_to_head_page(ptr);
74683 +
74684 + if (!PageSlab(page))
74685 + return NULL;
74686 +
74687 + cachep = page_get_cache(page);
74688 + if (!(cachep->flags & SLAB_USERCOPY))
74689 + return cachep->name;
74690 +
74691 + slabp = page->slab_page;
74692 + objnr = obj_to_index(cachep, slabp, ptr);
74693 + BUG_ON(objnr >= cachep->num);
74694 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74695 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74696 + return NULL;
74697 +
74698 + return cachep->name;
74699 +}
74700 +#endif
74701 +
74702 /**
74703 * ksize - get the actual amount of memory allocated for a given object
74704 * @objp: Pointer to the object
74705 diff --git a/mm/slob.c b/mm/slob.c
74706 index 45d4ca7..88943c1 100644
74707 --- a/mm/slob.c
74708 +++ b/mm/slob.c
74709 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74710 /*
74711 * Return the size of a slob block.
74712 */
74713 -static slobidx_t slob_units(slob_t *s)
74714 +static slobidx_t slob_units(const slob_t *s)
74715 {
74716 if (s->units > 0)
74717 return s->units;
74718 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74719 /*
74720 * Return the next free slob block pointer after this one.
74721 */
74722 -static slob_t *slob_next(slob_t *s)
74723 +static slob_t *slob_next(const slob_t *s)
74724 {
74725 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74726 slobidx_t next;
74727 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74728 /*
74729 * Returns true if s is the last free block in its page.
74730 */
74731 -static int slob_last(slob_t *s)
74732 +static int slob_last(const slob_t *s)
74733 {
74734 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74735 }
74736
74737 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74738 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74739 {
74740 - void *page;
74741 + struct page *page;
74742
74743 #ifdef CONFIG_NUMA
74744 if (node != -1)
74745 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74746 if (!page)
74747 return NULL;
74748
74749 - return page_address(page);
74750 + __SetPageSlab(page);
74751 + return page;
74752 }
74753
74754 -static void slob_free_pages(void *b, int order)
74755 +static void slob_free_pages(struct page *sp, int order)
74756 {
74757 if (current->reclaim_state)
74758 current->reclaim_state->reclaimed_slab += 1 << order;
74759 - free_pages((unsigned long)b, order);
74760 + __ClearPageSlab(sp);
74761 + reset_page_mapcount(sp);
74762 + sp->private = 0;
74763 + __free_pages(sp, order);
74764 }
74765
74766 /*
74767 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74768
74769 /* Not enough space: must allocate a new page */
74770 if (!b) {
74771 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74772 - if (!b)
74773 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74774 + if (!sp)
74775 return NULL;
74776 - sp = virt_to_page(b);
74777 - __SetPageSlab(sp);
74778 + b = page_address(sp);
74779
74780 spin_lock_irqsave(&slob_lock, flags);
74781 sp->units = SLOB_UNITS(PAGE_SIZE);
74782 sp->freelist = b;
74783 + sp->private = 0;
74784 INIT_LIST_HEAD(&sp->list);
74785 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74786 set_slob_page_free(sp, slob_list);
74787 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74788 if (slob_page_free(sp))
74789 clear_slob_page_free(sp);
74790 spin_unlock_irqrestore(&slob_lock, flags);
74791 - __ClearPageSlab(sp);
74792 - reset_page_mapcount(sp);
74793 - slob_free_pages(b, 0);
74794 + slob_free_pages(sp, 0);
74795 return;
74796 }
74797
74798 @@ -425,11 +427,10 @@ out:
74799 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74800 */
74801
74802 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74803 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74804 {
74805 - unsigned int *m;
74806 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74807 - void *ret;
74808 + slob_t *m;
74809 + void *ret = NULL;
74810
74811 gfp &= gfp_allowed_mask;
74812
74813 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74814
74815 if (!m)
74816 return NULL;
74817 - *m = size;
74818 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74819 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74820 + m[0].units = size;
74821 + m[1].units = align;
74822 ret = (void *)m + align;
74823
74824 trace_kmalloc_node(_RET_IP_, ret,
74825 size, size + align, gfp, node);
74826 } else {
74827 unsigned int order = get_order(size);
74828 + struct page *page;
74829
74830 if (likely(order))
74831 gfp |= __GFP_COMP;
74832 - ret = slob_new_pages(gfp, order, node);
74833 - if (ret) {
74834 - struct page *page;
74835 - page = virt_to_page(ret);
74836 + page = slob_new_pages(gfp, order, node);
74837 + if (page) {
74838 + ret = page_address(page);
74839 page->private = size;
74840 }
74841
74842 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74843 size, PAGE_SIZE << order, gfp, node);
74844 }
74845
74846 - kmemleak_alloc(ret, size, 1, gfp);
74847 + return ret;
74848 +}
74849 +
74850 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74851 +{
74852 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74853 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74854 +
74855 + if (!ZERO_OR_NULL_PTR(ret))
74856 + kmemleak_alloc(ret, size, 1, gfp);
74857 return ret;
74858 }
74859 EXPORT_SYMBOL(__kmalloc_node);
74860 @@ -480,15 +493,91 @@ void kfree(const void *block)
74861 kmemleak_free(block);
74862
74863 sp = virt_to_page(block);
74864 - if (PageSlab(sp)) {
74865 + VM_BUG_ON(!PageSlab(sp));
74866 + if (!sp->private) {
74867 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74868 - unsigned int *m = (unsigned int *)(block - align);
74869 - slob_free(m, *m + align);
74870 - } else
74871 + slob_t *m = (slob_t *)(block - align);
74872 + slob_free(m, m[0].units + align);
74873 + } else {
74874 + __ClearPageSlab(sp);
74875 + reset_page_mapcount(sp);
74876 + sp->private = 0;
74877 put_page(sp);
74878 + }
74879 }
74880 EXPORT_SYMBOL(kfree);
74881
74882 +bool is_usercopy_object(const void *ptr)
74883 +{
74884 + if (!slab_is_available())
74885 + return false;
74886 +
74887 + // PAX: TODO
74888 +
74889 + return false;
74890 +}
74891 +
74892 +#ifdef CONFIG_PAX_USERCOPY
74893 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74894 +{
74895 + struct page *page;
74896 + const slob_t *free;
74897 + const void *base;
74898 + unsigned long flags;
74899 +
74900 + if (ZERO_OR_NULL_PTR(ptr))
74901 + return "<null>";
74902 +
74903 + if (!virt_addr_valid(ptr))
74904 + return NULL;
74905 +
74906 + page = virt_to_head_page(ptr);
74907 + if (!PageSlab(page))
74908 + return NULL;
74909 +
74910 + if (page->private) {
74911 + base = page;
74912 + if (base <= ptr && n <= page->private - (ptr - base))
74913 + return NULL;
74914 + return "<slob>";
74915 + }
74916 +
74917 + /* some tricky double walking to find the chunk */
74918 + spin_lock_irqsave(&slob_lock, flags);
74919 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74920 + free = page->freelist;
74921 +
74922 + while (!slob_last(free) && (void *)free <= ptr) {
74923 + base = free + slob_units(free);
74924 + free = slob_next(free);
74925 + }
74926 +
74927 + while (base < (void *)free) {
74928 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74929 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74930 + int offset;
74931 +
74932 + if (ptr < base + align)
74933 + break;
74934 +
74935 + offset = ptr - base - align;
74936 + if (offset >= m) {
74937 + base += size;
74938 + continue;
74939 + }
74940 +
74941 + if (n > m - offset)
74942 + break;
74943 +
74944 + spin_unlock_irqrestore(&slob_lock, flags);
74945 + return NULL;
74946 + }
74947 +
74948 + spin_unlock_irqrestore(&slob_lock, flags);
74949 + return "<slob>";
74950 +}
74951 +#endif
74952 +
74953 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74954 size_t ksize(const void *block)
74955 {
74956 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
74957 return 0;
74958
74959 sp = virt_to_page(block);
74960 - if (PageSlab(sp)) {
74961 + VM_BUG_ON(!PageSlab(sp));
74962 + if (!sp->private) {
74963 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74964 - unsigned int *m = (unsigned int *)(block - align);
74965 - return SLOB_UNITS(*m) * SLOB_UNIT;
74966 + slob_t *m = (slob_t *)(block - align);
74967 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74968 } else
74969 return sp->private;
74970 }
74971 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
74972 {
74973 struct kmem_cache *c;
74974
74975 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74976 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74977 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74978 +#else
74979 c = slob_alloc(sizeof(struct kmem_cache),
74980 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74981 +#endif
74982
74983 if (c) {
74984 c->name = name;
74985 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
74986
74987 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74988 {
74989 - void *b;
74990 + void *b = NULL;
74991
74992 flags &= gfp_allowed_mask;
74993
74994 lockdep_trace_alloc(flags);
74995
74996 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74997 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74998 +#else
74999 if (c->size < PAGE_SIZE) {
75000 b = slob_alloc(c->size, flags, c->align, node);
75001 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75002 SLOB_UNITS(c->size) * SLOB_UNIT,
75003 flags, node);
75004 } else {
75005 - b = slob_new_pages(flags, get_order(c->size), node);
75006 + struct page *sp;
75007 +
75008 + sp = slob_new_pages(flags, get_order(c->size), node);
75009 + if (sp) {
75010 + b = page_address(sp);
75011 + sp->private = c->size;
75012 + }
75013 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75014 PAGE_SIZE << get_order(c->size),
75015 flags, node);
75016 }
75017 +#endif
75018
75019 if (c->ctor)
75020 c->ctor(b);
75021 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75022
75023 static void __kmem_cache_free(void *b, int size)
75024 {
75025 - if (size < PAGE_SIZE)
75026 + struct page *sp;
75027 +
75028 + sp = virt_to_page(b);
75029 + BUG_ON(!PageSlab(sp));
75030 + if (!sp->private)
75031 slob_free(b, size);
75032 else
75033 - slob_free_pages(b, get_order(size));
75034 + slob_free_pages(sp, get_order(size));
75035 }
75036
75037 static void kmem_rcu_free(struct rcu_head *head)
75038 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75039
75040 void kmem_cache_free(struct kmem_cache *c, void *b)
75041 {
75042 + int size = c->size;
75043 +
75044 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75045 + if (size + c->align < PAGE_SIZE) {
75046 + size += c->align;
75047 + b -= c->align;
75048 + }
75049 +#endif
75050 +
75051 kmemleak_free_recursive(b, c->flags);
75052 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75053 struct slob_rcu *slob_rcu;
75054 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75055 - slob_rcu->size = c->size;
75056 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75057 + slob_rcu->size = size;
75058 call_rcu(&slob_rcu->head, kmem_rcu_free);
75059 } else {
75060 - __kmem_cache_free(b, c->size);
75061 + __kmem_cache_free(b, size);
75062 }
75063
75064 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75065 + trace_kfree(_RET_IP_, b);
75066 +#else
75067 trace_kmem_cache_free(_RET_IP_, b);
75068 +#endif
75069 +
75070 }
75071 EXPORT_SYMBOL(kmem_cache_free);
75072
75073 diff --git a/mm/slub.c b/mm/slub.c
75074 index 2fdd96f..1e2f893 100644
75075 --- a/mm/slub.c
75076 +++ b/mm/slub.c
75077 @@ -201,7 +201,7 @@ struct track {
75078
75079 enum track_item { TRACK_ALLOC, TRACK_FREE };
75080
75081 -#ifdef CONFIG_SYSFS
75082 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75083 static int sysfs_slab_add(struct kmem_cache *);
75084 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75085 static void sysfs_slab_remove(struct kmem_cache *);
75086 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75087 if (!t->addr)
75088 return;
75089
75090 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75091 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75092 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75093 #ifdef CONFIG_STACKTRACE
75094 {
75095 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75096
75097 page = virt_to_head_page(x);
75098
75099 + BUG_ON(!PageSlab(page));
75100 +
75101 slab_free(s, page, x, _RET_IP_);
75102
75103 trace_kmem_cache_free(_RET_IP_, x);
75104 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75105 * Merge control. If this is set then no merging of slab caches will occur.
75106 * (Could be removed. This was introduced to pacify the merge skeptics.)
75107 */
75108 -static int slub_nomerge;
75109 +static int slub_nomerge = 1;
75110
75111 /*
75112 * Calculate the order of allocation given an slab object size.
75113 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75114 else
75115 s->cpu_partial = 30;
75116
75117 - s->refcount = 1;
75118 + atomic_set(&s->refcount, 1);
75119 #ifdef CONFIG_NUMA
75120 s->remote_node_defrag_ratio = 1000;
75121 #endif
75122 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75123 void kmem_cache_destroy(struct kmem_cache *s)
75124 {
75125 mutex_lock(&slab_mutex);
75126 - s->refcount--;
75127 - if (!s->refcount) {
75128 + if (atomic_dec_and_test(&s->refcount)) {
75129 list_del(&s->list);
75130 mutex_unlock(&slab_mutex);
75131 if (kmem_cache_close(s)) {
75132 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75133 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75134 #endif
75135
75136 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75137 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75138 +#endif
75139 +
75140 static int __init setup_slub_min_order(char *str)
75141 {
75142 get_option(&str, &slub_min_order);
75143 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75144 return kmalloc_dma_caches[index];
75145
75146 #endif
75147 +
75148 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75149 + if (flags & SLAB_USERCOPY)
75150 + return kmalloc_usercopy_caches[index];
75151 +
75152 +#endif
75153 +
75154 return kmalloc_caches[index];
75155 }
75156
75157 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75158 EXPORT_SYMBOL(__kmalloc_node);
75159 #endif
75160
75161 +bool is_usercopy_object(const void *ptr)
75162 +{
75163 + struct page *page;
75164 + struct kmem_cache *s;
75165 +
75166 + if (ZERO_OR_NULL_PTR(ptr))
75167 + return false;
75168 +
75169 + if (!slab_is_available())
75170 + return false;
75171 +
75172 + if (!virt_addr_valid(ptr))
75173 + return false;
75174 +
75175 + page = virt_to_head_page(ptr);
75176 +
75177 + if (!PageSlab(page))
75178 + return false;
75179 +
75180 + s = page->slab;
75181 + return s->flags & SLAB_USERCOPY;
75182 +}
75183 +
75184 +#ifdef CONFIG_PAX_USERCOPY
75185 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75186 +{
75187 + struct page *page;
75188 + struct kmem_cache *s;
75189 + unsigned long offset;
75190 +
75191 + if (ZERO_OR_NULL_PTR(ptr))
75192 + return "<null>";
75193 +
75194 + if (!virt_addr_valid(ptr))
75195 + return NULL;
75196 +
75197 + page = virt_to_head_page(ptr);
75198 +
75199 + if (!PageSlab(page))
75200 + return NULL;
75201 +
75202 + s = page->slab;
75203 + if (!(s->flags & SLAB_USERCOPY))
75204 + return s->name;
75205 +
75206 + offset = (ptr - page_address(page)) % s->size;
75207 + if (offset <= s->object_size && n <= s->object_size - offset)
75208 + return NULL;
75209 +
75210 + return s->name;
75211 +}
75212 +#endif
75213 +
75214 size_t ksize(const void *object)
75215 {
75216 struct page *page;
75217 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75218 int node;
75219
75220 list_add(&s->list, &slab_caches);
75221 - s->refcount = -1;
75222 + atomic_set(&s->refcount, -1);
75223
75224 for_each_node_state(node, N_NORMAL_MEMORY) {
75225 struct kmem_cache_node *n = get_node(s, node);
75226 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75227
75228 /* Caches that are not of the two-to-the-power-of size */
75229 if (KMALLOC_MIN_SIZE <= 32) {
75230 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75231 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75232 caches++;
75233 }
75234
75235 if (KMALLOC_MIN_SIZE <= 64) {
75236 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75237 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75238 caches++;
75239 }
75240
75241 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75242 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75243 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75244 caches++;
75245 }
75246
75247 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75248 }
75249 }
75250 #endif
75251 +
75252 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75253 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75254 + struct kmem_cache *s = kmalloc_caches[i];
75255 +
75256 + if (s && s->size) {
75257 + char *name = kasprintf(GFP_NOWAIT,
75258 + "usercopy-kmalloc-%d", s->object_size);
75259 +
75260 + BUG_ON(!name);
75261 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75262 + s->object_size, SLAB_USERCOPY);
75263 + }
75264 + }
75265 +#endif
75266 +
75267 printk(KERN_INFO
75268 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75269 " CPUs=%d, Nodes=%d\n",
75270 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75271 /*
75272 * We may have set a slab to be unmergeable during bootstrap.
75273 */
75274 - if (s->refcount < 0)
75275 + if (atomic_read(&s->refcount) < 0)
75276 return 1;
75277
75278 return 0;
75279 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75280
75281 s = find_mergeable(size, align, flags, name, ctor);
75282 if (s) {
75283 - s->refcount++;
75284 + atomic_inc(&s->refcount);
75285 /*
75286 * Adjust the object sizes so that we clear
75287 * the complete object on kzalloc.
75288 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75289 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75290
75291 if (sysfs_slab_alias(s, name)) {
75292 - s->refcount--;
75293 + atomic_dec(&s->refcount);
75294 return NULL;
75295 }
75296 return s;
75297 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75298 }
75299 #endif
75300
75301 -#ifdef CONFIG_SYSFS
75302 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75303 static int count_inuse(struct page *page)
75304 {
75305 return page->inuse;
75306 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75307 validate_slab_cache(kmalloc_caches[9]);
75308 }
75309 #else
75310 -#ifdef CONFIG_SYSFS
75311 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75312 static void resiliency_test(void) {};
75313 #endif
75314 #endif
75315
75316 -#ifdef CONFIG_SYSFS
75317 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75318 enum slab_stat_type {
75319 SL_ALL, /* All slabs */
75320 SL_PARTIAL, /* Only partially allocated slabs */
75321 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75322
75323 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75324 {
75325 - return sprintf(buf, "%d\n", s->refcount - 1);
75326 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75327 }
75328 SLAB_ATTR_RO(aliases);
75329
75330 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75331 return name;
75332 }
75333
75334 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75335 static int sysfs_slab_add(struct kmem_cache *s)
75336 {
75337 int err;
75338 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75339 kobject_del(&s->kobj);
75340 kobject_put(&s->kobj);
75341 }
75342 +#endif
75343
75344 /*
75345 * Need to buffer aliases during bootup until sysfs becomes
75346 @@ -5354,6 +5437,7 @@ struct saved_alias {
75347
75348 static struct saved_alias *alias_list;
75349
75350 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75351 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75352 {
75353 struct saved_alias *al;
75354 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75355 alias_list = al;
75356 return 0;
75357 }
75358 +#endif
75359
75360 static int __init slab_sysfs_init(void)
75361 {
75362 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75363 index 1b7e22a..3fcd4f3 100644
75364 --- a/mm/sparse-vmemmap.c
75365 +++ b/mm/sparse-vmemmap.c
75366 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75367 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75368 if (!p)
75369 return NULL;
75370 - pud_populate(&init_mm, pud, p);
75371 + pud_populate_kernel(&init_mm, pud, p);
75372 }
75373 return pud;
75374 }
75375 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75376 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75377 if (!p)
75378 return NULL;
75379 - pgd_populate(&init_mm, pgd, p);
75380 + pgd_populate_kernel(&init_mm, pgd, p);
75381 }
75382 return pgd;
75383 }
75384 diff --git a/mm/swap.c b/mm/swap.c
75385 index 7782588..228c784 100644
75386 --- a/mm/swap.c
75387 +++ b/mm/swap.c
75388 @@ -30,6 +30,7 @@
75389 #include <linux/backing-dev.h>
75390 #include <linux/memcontrol.h>
75391 #include <linux/gfp.h>
75392 +#include <linux/hugetlb.h>
75393
75394 #include "internal.h"
75395
75396 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75397
75398 __page_cache_release(page);
75399 dtor = get_compound_page_dtor(page);
75400 + if (!PageHuge(page))
75401 + BUG_ON(dtor != free_compound_page);
75402 (*dtor)(page);
75403 }
75404
75405 diff --git a/mm/swapfile.c b/mm/swapfile.c
75406 index 14e254c..a6af32c 100644
75407 --- a/mm/swapfile.c
75408 +++ b/mm/swapfile.c
75409 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75410
75411 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75412 /* Activity counter to indicate that a swapon or swapoff has occurred */
75413 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75414 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75415
75416 static inline unsigned char swap_count(unsigned char ent)
75417 {
75418 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75419 }
75420 filp_close(swap_file, NULL);
75421 err = 0;
75422 - atomic_inc(&proc_poll_event);
75423 + atomic_inc_unchecked(&proc_poll_event);
75424 wake_up_interruptible(&proc_poll_wait);
75425
75426 out_dput:
75427 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75428
75429 poll_wait(file, &proc_poll_wait, wait);
75430
75431 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75432 - seq->poll_event = atomic_read(&proc_poll_event);
75433 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75434 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75435 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75436 }
75437
75438 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75439 return ret;
75440
75441 seq = file->private_data;
75442 - seq->poll_event = atomic_read(&proc_poll_event);
75443 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75444 return 0;
75445 }
75446
75447 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75448 (frontswap_map) ? "FS" : "");
75449
75450 mutex_unlock(&swapon_mutex);
75451 - atomic_inc(&proc_poll_event);
75452 + atomic_inc_unchecked(&proc_poll_event);
75453 wake_up_interruptible(&proc_poll_wait);
75454
75455 if (S_ISREG(inode->i_mode))
75456 diff --git a/mm/util.c b/mm/util.c
75457 index 8c7265a..c96d884 100644
75458 --- a/mm/util.c
75459 +++ b/mm/util.c
75460 @@ -285,6 +285,12 @@ done:
75461 void arch_pick_mmap_layout(struct mm_struct *mm)
75462 {
75463 mm->mmap_base = TASK_UNMAPPED_BASE;
75464 +
75465 +#ifdef CONFIG_PAX_RANDMMAP
75466 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75467 + mm->mmap_base += mm->delta_mmap;
75468 +#endif
75469 +
75470 mm->get_unmapped_area = arch_get_unmapped_area;
75471 mm->unmap_area = arch_unmap_area;
75472 }
75473 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75474 index 2bb90b1..ed47e53 100644
75475 --- a/mm/vmalloc.c
75476 +++ b/mm/vmalloc.c
75477 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75478
75479 pte = pte_offset_kernel(pmd, addr);
75480 do {
75481 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75482 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75483 +
75484 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75485 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75486 + BUG_ON(!pte_exec(*pte));
75487 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75488 + continue;
75489 + }
75490 +#endif
75491 +
75492 + {
75493 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75494 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75495 + }
75496 } while (pte++, addr += PAGE_SIZE, addr != end);
75497 }
75498
75499 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75500 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75501 {
75502 pte_t *pte;
75503 + int ret = -ENOMEM;
75504
75505 /*
75506 * nr is a running index into the array which helps higher level
75507 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75508 pte = pte_alloc_kernel(pmd, addr);
75509 if (!pte)
75510 return -ENOMEM;
75511 +
75512 + pax_open_kernel();
75513 do {
75514 struct page *page = pages[*nr];
75515
75516 - if (WARN_ON(!pte_none(*pte)))
75517 - return -EBUSY;
75518 - if (WARN_ON(!page))
75519 - return -ENOMEM;
75520 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75521 + if (pgprot_val(prot) & _PAGE_NX)
75522 +#endif
75523 +
75524 + if (WARN_ON(!pte_none(*pte))) {
75525 + ret = -EBUSY;
75526 + goto out;
75527 + }
75528 + if (WARN_ON(!page)) {
75529 + ret = -ENOMEM;
75530 + goto out;
75531 + }
75532 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75533 (*nr)++;
75534 } while (pte++, addr += PAGE_SIZE, addr != end);
75535 - return 0;
75536 + ret = 0;
75537 +out:
75538 + pax_close_kernel();
75539 + return ret;
75540 }
75541
75542 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75543 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75544 pmd_t *pmd;
75545 unsigned long next;
75546
75547 - pmd = pmd_alloc(&init_mm, pud, addr);
75548 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75549 if (!pmd)
75550 return -ENOMEM;
75551 do {
75552 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75553 pud_t *pud;
75554 unsigned long next;
75555
75556 - pud = pud_alloc(&init_mm, pgd, addr);
75557 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75558 if (!pud)
75559 return -ENOMEM;
75560 do {
75561 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75562 * and fall back on vmalloc() if that fails. Others
75563 * just put it in the vmalloc space.
75564 */
75565 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75566 +#ifdef CONFIG_MODULES
75567 +#ifdef MODULES_VADDR
75568 unsigned long addr = (unsigned long)x;
75569 if (addr >= MODULES_VADDR && addr < MODULES_END)
75570 return 1;
75571 #endif
75572 +
75573 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75574 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75575 + return 1;
75576 +#endif
75577 +
75578 +#endif
75579 +
75580 return is_vmalloc_addr(x);
75581 }
75582
75583 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75584
75585 if (!pgd_none(*pgd)) {
75586 pud_t *pud = pud_offset(pgd, addr);
75587 +#ifdef CONFIG_X86
75588 + if (!pud_large(*pud))
75589 +#endif
75590 if (!pud_none(*pud)) {
75591 pmd_t *pmd = pmd_offset(pud, addr);
75592 +#ifdef CONFIG_X86
75593 + if (!pmd_large(*pmd))
75594 +#endif
75595 if (!pmd_none(*pmd)) {
75596 pte_t *ptep, pte;
75597
75598 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75599 * Allocate a region of KVA of the specified size and alignment, within the
75600 * vstart and vend.
75601 */
75602 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75603 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75604 unsigned long align,
75605 unsigned long vstart, unsigned long vend,
75606 int node, gfp_t gfp_mask)
75607 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75608 struct vm_struct *area;
75609
75610 BUG_ON(in_interrupt());
75611 +
75612 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75613 + if (flags & VM_KERNEXEC) {
75614 + if (start != VMALLOC_START || end != VMALLOC_END)
75615 + return NULL;
75616 + start = (unsigned long)MODULES_EXEC_VADDR;
75617 + end = (unsigned long)MODULES_EXEC_END;
75618 + }
75619 +#endif
75620 +
75621 if (flags & VM_IOREMAP) {
75622 int bit = fls(size);
75623
75624 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75625 if (count > totalram_pages)
75626 return NULL;
75627
75628 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75629 + if (!(pgprot_val(prot) & _PAGE_NX))
75630 + flags |= VM_KERNEXEC;
75631 +#endif
75632 +
75633 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75634 __builtin_return_address(0));
75635 if (!area)
75636 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75637 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75638 goto fail;
75639
75640 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75641 + if (!(pgprot_val(prot) & _PAGE_NX))
75642 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75643 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75644 + else
75645 +#endif
75646 +
75647 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75648 start, end, node, gfp_mask, caller);
75649 if (!area)
75650 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75651 * For tight control over page level allocator and protection flags
75652 * use __vmalloc() instead.
75653 */
75654 -
75655 void *vmalloc_exec(unsigned long size)
75656 {
75657 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75658 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75659 -1, __builtin_return_address(0));
75660 }
75661
75662 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75663 unsigned long uaddr = vma->vm_start;
75664 unsigned long usize = vma->vm_end - vma->vm_start;
75665
75666 + BUG_ON(vma->vm_mirror);
75667 +
75668 if ((PAGE_SIZE-1) & (unsigned long)addr)
75669 return -EINVAL;
75670
75671 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75672 {
75673 struct vm_struct *v = p;
75674
75675 - seq_printf(m, "0x%p-0x%p %7ld",
75676 + seq_printf(m, "0x%pK-0x%pK %7ld",
75677 v->addr, v->addr + v->size, v->size);
75678
75679 if (v->caller)
75680 diff --git a/mm/vmstat.c b/mm/vmstat.c
75681 index df7a674..8b4a4f3 100644
75682 --- a/mm/vmstat.c
75683 +++ b/mm/vmstat.c
75684 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75685 *
75686 * vm_stat contains the global counters
75687 */
75688 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75689 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75690 EXPORT_SYMBOL(vm_stat);
75691
75692 #ifdef CONFIG_SMP
75693 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75694 v = p->vm_stat_diff[i];
75695 p->vm_stat_diff[i] = 0;
75696 local_irq_restore(flags);
75697 - atomic_long_add(v, &zone->vm_stat[i]);
75698 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75699 global_diff[i] += v;
75700 #ifdef CONFIG_NUMA
75701 /* 3 seconds idle till flush */
75702 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75703
75704 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75705 if (global_diff[i])
75706 - atomic_long_add(global_diff[i], &vm_stat[i]);
75707 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75708 }
75709
75710 #endif
75711 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75712 start_cpu_timer(cpu);
75713 #endif
75714 #ifdef CONFIG_PROC_FS
75715 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75716 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75717 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75718 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75719 + {
75720 + mode_t gr_mode = S_IRUGO;
75721 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75722 + gr_mode = S_IRUSR;
75723 +#endif
75724 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75725 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75726 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75727 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75728 +#else
75729 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75730 +#endif
75731 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75732 + }
75733 #endif
75734 return 0;
75735 }
75736 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75737 index 9096bcb..43ed7bb 100644
75738 --- a/net/8021q/vlan.c
75739 +++ b/net/8021q/vlan.c
75740 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75741 err = -EPERM;
75742 if (!capable(CAP_NET_ADMIN))
75743 break;
75744 - if ((args.u.name_type >= 0) &&
75745 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75746 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75747 struct vlan_net *vn;
75748
75749 vn = net_generic(net, vlan_net_id);
75750 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75751 index 6449bae..8c1f454 100644
75752 --- a/net/9p/trans_fd.c
75753 +++ b/net/9p/trans_fd.c
75754 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75755 oldfs = get_fs();
75756 set_fs(get_ds());
75757 /* The cast to a user pointer is valid due to the set_fs() */
75758 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75759 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75760 set_fs(oldfs);
75761
75762 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75763 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75764 index 876fbe8..8bbea9f 100644
75765 --- a/net/atm/atm_misc.c
75766 +++ b/net/atm/atm_misc.c
75767 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75768 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75769 return 1;
75770 atm_return(vcc, truesize);
75771 - atomic_inc(&vcc->stats->rx_drop);
75772 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75773 return 0;
75774 }
75775 EXPORT_SYMBOL(atm_charge);
75776 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75777 }
75778 }
75779 atm_return(vcc, guess);
75780 - atomic_inc(&vcc->stats->rx_drop);
75781 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75782 return NULL;
75783 }
75784 EXPORT_SYMBOL(atm_alloc_charge);
75785 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75786
75787 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75788 {
75789 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75790 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75791 __SONET_ITEMS
75792 #undef __HANDLE_ITEM
75793 }
75794 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75795
75796 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75797 {
75798 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75799 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75800 __SONET_ITEMS
75801 #undef __HANDLE_ITEM
75802 }
75803 diff --git a/net/atm/lec.h b/net/atm/lec.h
75804 index a86aff9..3a0d6f6 100644
75805 --- a/net/atm/lec.h
75806 +++ b/net/atm/lec.h
75807 @@ -48,7 +48,7 @@ struct lane2_ops {
75808 const u8 *tlvs, u32 sizeoftlvs);
75809 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75810 const u8 *tlvs, u32 sizeoftlvs);
75811 -};
75812 +} __no_const;
75813
75814 /*
75815 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75816 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75817 index 0919a88..a23d54e 100644
75818 --- a/net/atm/mpc.h
75819 +++ b/net/atm/mpc.h
75820 @@ -33,7 +33,7 @@ struct mpoa_client {
75821 struct mpc_parameters parameters; /* parameters for this client */
75822
75823 const struct net_device_ops *old_ops;
75824 - struct net_device_ops new_ops;
75825 + net_device_ops_no_const new_ops;
75826 };
75827
75828
75829 diff --git a/net/atm/proc.c b/net/atm/proc.c
75830 index 0d020de..011c7bb 100644
75831 --- a/net/atm/proc.c
75832 +++ b/net/atm/proc.c
75833 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75834 const struct k_atm_aal_stats *stats)
75835 {
75836 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75837 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75838 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75839 - atomic_read(&stats->rx_drop));
75840 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75841 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75842 + atomic_read_unchecked(&stats->rx_drop));
75843 }
75844
75845 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75846 diff --git a/net/atm/resources.c b/net/atm/resources.c
75847 index 23f45ce..c748f1a 100644
75848 --- a/net/atm/resources.c
75849 +++ b/net/atm/resources.c
75850 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75851 static void copy_aal_stats(struct k_atm_aal_stats *from,
75852 struct atm_aal_stats *to)
75853 {
75854 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75855 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75856 __AAL_STAT_ITEMS
75857 #undef __HANDLE_ITEM
75858 }
75859 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75860 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75861 struct atm_aal_stats *to)
75862 {
75863 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75864 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75865 __AAL_STAT_ITEMS
75866 #undef __HANDLE_ITEM
75867 }
75868 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75869 index 469daab..9fc7f8d 100644
75870 --- a/net/batman-adv/bat_iv_ogm.c
75871 +++ b/net/batman-adv/bat_iv_ogm.c
75872 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
75873
75874 /* randomize initial seqno to avoid collision */
75875 get_random_bytes(&random_seqno, sizeof(random_seqno));
75876 - atomic_set(&hard_iface->seqno, random_seqno);
75877 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75878
75879 hard_iface->packet_len = BATADV_OGM_HLEN;
75880 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75881 @@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
75882 "Sending own" :
75883 "Forwarding"));
75884 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
75885 - "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75886 + "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75887 fwd_str, (packet_num > 0 ? "aggregated " : ""),
75888 batadv_ogm_packet->orig,
75889 ntohl(batadv_ogm_packet->seqno),
75890 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
75891
75892 /* change sequence number to network order */
75893 batadv_ogm_packet->seqno =
75894 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75895 - atomic_inc(&hard_iface->seqno);
75896 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75897 + atomic_inc_unchecked(&hard_iface->seqno);
75898
75899 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75900 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
75901 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
75902 return;
75903
75904 /* could be changed by schedule_own_packet() */
75905 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75906 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75907
75908 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
75909 has_directlink_flag = 1;
75910 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75911 index 282bf6e..4b2603d 100644
75912 --- a/net/batman-adv/hard-interface.c
75913 +++ b/net/batman-adv/hard-interface.c
75914 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
75915 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75916 dev_add_pack(&hard_iface->batman_adv_ptype);
75917
75918 - atomic_set(&hard_iface->frag_seqno, 1);
75919 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75920 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
75921 hard_iface->net_dev->name);
75922
75923 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
75924 /* This can't be called via a bat_priv callback because
75925 * we have no bat_priv yet.
75926 */
75927 - atomic_set(&hard_iface->seqno, 1);
75928 + atomic_set_unchecked(&hard_iface->seqno, 1);
75929 hard_iface->packet_buff = NULL;
75930
75931 return hard_iface;
75932 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75933 index 21c5357..768be1a 100644
75934 --- a/net/batman-adv/soft-interface.c
75935 +++ b/net/batman-adv/soft-interface.c
75936 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
75937
75938 /* set broadcast sequence number */
75939 bcast_packet->seqno =
75940 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75941 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75942
75943 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
75944
75945 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
75946 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
75947
75948 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
75949 - atomic_set(&bat_priv->bcast_seqno, 1);
75950 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75951 atomic_set(&bat_priv->ttvn, 0);
75952 atomic_set(&bat_priv->tt_local_changes, 0);
75953 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75954 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75955 index 12635fd..d99d837 100644
75956 --- a/net/batman-adv/types.h
75957 +++ b/net/batman-adv/types.h
75958 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
75959 int16_t if_num;
75960 char if_status;
75961 struct net_device *net_dev;
75962 - atomic_t seqno;
75963 - atomic_t frag_seqno;
75964 + atomic_unchecked_t seqno;
75965 + atomic_unchecked_t frag_seqno;
75966 unsigned char *packet_buff;
75967 int packet_len;
75968 struct kobject *hardif_obj;
75969 @@ -176,7 +176,7 @@ struct batadv_priv {
75970 atomic_t orig_interval; /* uint */
75971 atomic_t hop_penalty; /* uint */
75972 atomic_t log_level; /* uint */
75973 - atomic_t bcast_seqno;
75974 + atomic_unchecked_t bcast_seqno;
75975 atomic_t bcast_queue_left;
75976 atomic_t batman_queue_left;
75977 atomic_t ttvn; /* translation table version number */
75978 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75979 index 0016464..0ef3e53 100644
75980 --- a/net/batman-adv/unicast.c
75981 +++ b/net/batman-adv/unicast.c
75982 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
75983 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
75984 frag2->flags = large_tail;
75985
75986 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75987 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75988 frag1->seqno = htons(seqno - 1);
75989 frag2->seqno = htons(seqno);
75990
75991 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75992 index d5ace1e..231c4bf 100644
75993 --- a/net/bluetooth/hci_sock.c
75994 +++ b/net/bluetooth/hci_sock.c
75995 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
75996 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
75997 }
75998
75999 - len = min_t(unsigned int, len, sizeof(uf));
76000 + len = min((size_t)len, sizeof(uf));
76001 if (copy_from_user(&uf, optval, len)) {
76002 err = -EFAULT;
76003 break;
76004 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76005 index 38c00f1..e9d566e 100644
76006 --- a/net/bluetooth/l2cap_core.c
76007 +++ b/net/bluetooth/l2cap_core.c
76008 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76009 break;
76010
76011 case L2CAP_CONF_RFC:
76012 - if (olen == sizeof(rfc))
76013 - memcpy(&rfc, (void *)val, olen);
76014 + if (olen != sizeof(rfc))
76015 + break;
76016 +
76017 + memcpy(&rfc, (void *)val, olen);
76018
76019 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76020 rfc.mode != chan->mode)
76021 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76022 index 34bbe1c..451c19b 100644
76023 --- a/net/bluetooth/l2cap_sock.c
76024 +++ b/net/bluetooth/l2cap_sock.c
76025 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76026 struct sock *sk = sock->sk;
76027 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76028 struct l2cap_options opts;
76029 - int len, err = 0;
76030 + int err = 0;
76031 + size_t len = optlen;
76032 u32 opt;
76033
76034 BT_DBG("sk %p", sk);
76035 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76036 opts.max_tx = chan->max_tx;
76037 opts.txwin_size = chan->tx_win;
76038
76039 - len = min_t(unsigned int, sizeof(opts), optlen);
76040 + len = min(sizeof(opts), len);
76041 if (copy_from_user((char *) &opts, optval, len)) {
76042 err = -EFAULT;
76043 break;
76044 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76045 struct bt_security sec;
76046 struct bt_power pwr;
76047 struct l2cap_conn *conn;
76048 - int len, err = 0;
76049 + int err = 0;
76050 + size_t len = optlen;
76051 u32 opt;
76052
76053 BT_DBG("sk %p", sk);
76054 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76055
76056 sec.level = BT_SECURITY_LOW;
76057
76058 - len = min_t(unsigned int, sizeof(sec), optlen);
76059 + len = min(sizeof(sec), len);
76060 if (copy_from_user((char *) &sec, optval, len)) {
76061 err = -EFAULT;
76062 break;
76063 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76064
76065 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76066
76067 - len = min_t(unsigned int, sizeof(pwr), optlen);
76068 + len = min(sizeof(pwr), len);
76069 if (copy_from_user((char *) &pwr, optval, len)) {
76070 err = -EFAULT;
76071 break;
76072 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76073 index 1a17850..65a3129 100644
76074 --- a/net/bluetooth/rfcomm/sock.c
76075 +++ b/net/bluetooth/rfcomm/sock.c
76076 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76077 struct sock *sk = sock->sk;
76078 struct bt_security sec;
76079 int err = 0;
76080 - size_t len;
76081 + size_t len = optlen;
76082 u32 opt;
76083
76084 BT_DBG("sk %p", sk);
76085 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76086
76087 sec.level = BT_SECURITY_LOW;
76088
76089 - len = min_t(unsigned int, sizeof(sec), optlen);
76090 + len = min(sizeof(sec), len);
76091 if (copy_from_user((char *) &sec, optval, len)) {
76092 err = -EFAULT;
76093 break;
76094 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76095 index 56f1823..da44330 100644
76096 --- a/net/bluetooth/rfcomm/tty.c
76097 +++ b/net/bluetooth/rfcomm/tty.c
76098 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76099 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76100
76101 spin_lock_irqsave(&dev->port.lock, flags);
76102 - if (dev->port.count > 0) {
76103 + if (atomic_read(&dev->port.count) > 0) {
76104 spin_unlock_irqrestore(&dev->port.lock, flags);
76105 return;
76106 }
76107 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76108 return -ENODEV;
76109
76110 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76111 - dev->channel, dev->port.count);
76112 + dev->channel, atomic_read(&dev->port.count));
76113
76114 spin_lock_irqsave(&dev->port.lock, flags);
76115 - if (++dev->port.count > 1) {
76116 + if (atomic_inc_return(&dev->port.count) > 1) {
76117 spin_unlock_irqrestore(&dev->port.lock, flags);
76118 return 0;
76119 }
76120 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76121 return;
76122
76123 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76124 - dev->port.count);
76125 + atomic_read(&dev->port.count));
76126
76127 spin_lock_irqsave(&dev->port.lock, flags);
76128 - if (!--dev->port.count) {
76129 + if (!atomic_dec_return(&dev->port.count)) {
76130 spin_unlock_irqrestore(&dev->port.lock, flags);
76131 if (dev->tty_dev->parent)
76132 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76133 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76134 index 5fe2ff3..121d696 100644
76135 --- a/net/bridge/netfilter/ebtables.c
76136 +++ b/net/bridge/netfilter/ebtables.c
76137 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76138 tmp.valid_hooks = t->table->valid_hooks;
76139 }
76140 mutex_unlock(&ebt_mutex);
76141 - if (copy_to_user(user, &tmp, *len) != 0){
76142 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76143 BUGPRINT("c2u Didn't work\n");
76144 ret = -EFAULT;
76145 break;
76146 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76147 goto out;
76148 tmp.valid_hooks = t->valid_hooks;
76149
76150 - if (copy_to_user(user, &tmp, *len) != 0) {
76151 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76152 ret = -EFAULT;
76153 break;
76154 }
76155 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76156 tmp.entries_size = t->table->entries_size;
76157 tmp.valid_hooks = t->table->valid_hooks;
76158
76159 - if (copy_to_user(user, &tmp, *len) != 0) {
76160 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76161 ret = -EFAULT;
76162 break;
76163 }
76164 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76165 index 44f270f..1f5602d 100644
76166 --- a/net/caif/cfctrl.c
76167 +++ b/net/caif/cfctrl.c
76168 @@ -10,6 +10,7 @@
76169 #include <linux/spinlock.h>
76170 #include <linux/slab.h>
76171 #include <linux/pkt_sched.h>
76172 +#include <linux/sched.h>
76173 #include <net/caif/caif_layer.h>
76174 #include <net/caif/cfpkt.h>
76175 #include <net/caif/cfctrl.h>
76176 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76177 memset(&dev_info, 0, sizeof(dev_info));
76178 dev_info.id = 0xff;
76179 cfsrvl_init(&this->serv, 0, &dev_info, false);
76180 - atomic_set(&this->req_seq_no, 1);
76181 - atomic_set(&this->rsp_seq_no, 1);
76182 + atomic_set_unchecked(&this->req_seq_no, 1);
76183 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76184 this->serv.layer.receive = cfctrl_recv;
76185 sprintf(this->serv.layer.name, "ctrl");
76186 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76187 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76188 struct cfctrl_request_info *req)
76189 {
76190 spin_lock_bh(&ctrl->info_list_lock);
76191 - atomic_inc(&ctrl->req_seq_no);
76192 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76193 + atomic_inc_unchecked(&ctrl->req_seq_no);
76194 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76195 list_add_tail(&req->list, &ctrl->list);
76196 spin_unlock_bh(&ctrl->info_list_lock);
76197 }
76198 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76199 if (p != first)
76200 pr_warn("Requests are not received in order\n");
76201
76202 - atomic_set(&ctrl->rsp_seq_no,
76203 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76204 p->sequence_no);
76205 list_del(&p->list);
76206 goto out;
76207 diff --git a/net/can/gw.c b/net/can/gw.c
76208 index b54d5e6..91c3b25 100644
76209 --- a/net/can/gw.c
76210 +++ b/net/can/gw.c
76211 @@ -96,7 +96,7 @@ struct cf_mod {
76212 struct {
76213 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76214 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76215 - } csumfunc;
76216 + } __no_const csumfunc;
76217 };
76218
76219
76220 diff --git a/net/compat.c b/net/compat.c
76221 index 74ed1d7..3695bd9 100644
76222 --- a/net/compat.c
76223 +++ b/net/compat.c
76224 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76225 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76226 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76227 return -EFAULT;
76228 - kmsg->msg_name = compat_ptr(tmp1);
76229 - kmsg->msg_iov = compat_ptr(tmp2);
76230 - kmsg->msg_control = compat_ptr(tmp3);
76231 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76232 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76233 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76234 return 0;
76235 }
76236
76237 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76238
76239 if (kern_msg->msg_namelen) {
76240 if (mode == VERIFY_READ) {
76241 - int err = move_addr_to_kernel(kern_msg->msg_name,
76242 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76243 kern_msg->msg_namelen,
76244 kern_address);
76245 if (err < 0)
76246 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76247 kern_msg->msg_name = NULL;
76248
76249 tot_len = iov_from_user_compat_to_kern(kern_iov,
76250 - (struct compat_iovec __user *)kern_msg->msg_iov,
76251 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76252 kern_msg->msg_iovlen);
76253 if (tot_len >= 0)
76254 kern_msg->msg_iov = kern_iov;
76255 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76256
76257 #define CMSG_COMPAT_FIRSTHDR(msg) \
76258 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76259 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76260 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76261 (struct compat_cmsghdr __user *)NULL)
76262
76263 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76264 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76265 (ucmlen) <= (unsigned long) \
76266 ((mhdr)->msg_controllen - \
76267 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76268 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76269
76270 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76271 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76272 {
76273 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76274 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76275 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76276 msg->msg_controllen)
76277 return NULL;
76278 return (struct compat_cmsghdr __user *)ptr;
76279 @@ -219,7 +219,7 @@ Efault:
76280
76281 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76282 {
76283 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76284 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76285 struct compat_cmsghdr cmhdr;
76286 struct compat_timeval ctv;
76287 struct compat_timespec cts[3];
76288 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76289
76290 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76291 {
76292 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76293 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76294 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76295 int fdnum = scm->fp->count;
76296 struct file **fp = scm->fp->fp;
76297 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76298 return -EFAULT;
76299 old_fs = get_fs();
76300 set_fs(KERNEL_DS);
76301 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76302 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76303 set_fs(old_fs);
76304
76305 return err;
76306 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76307 len = sizeof(ktime);
76308 old_fs = get_fs();
76309 set_fs(KERNEL_DS);
76310 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76311 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76312 set_fs(old_fs);
76313
76314 if (!err) {
76315 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76316 case MCAST_JOIN_GROUP:
76317 case MCAST_LEAVE_GROUP:
76318 {
76319 - struct compat_group_req __user *gr32 = (void *)optval;
76320 + struct compat_group_req __user *gr32 = (void __user *)optval;
76321 struct group_req __user *kgr =
76322 compat_alloc_user_space(sizeof(struct group_req));
76323 u32 interface;
76324 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76325 case MCAST_BLOCK_SOURCE:
76326 case MCAST_UNBLOCK_SOURCE:
76327 {
76328 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76329 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76330 struct group_source_req __user *kgsr = compat_alloc_user_space(
76331 sizeof(struct group_source_req));
76332 u32 interface;
76333 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76334 }
76335 case MCAST_MSFILTER:
76336 {
76337 - struct compat_group_filter __user *gf32 = (void *)optval;
76338 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76339 struct group_filter __user *kgf;
76340 u32 interface, fmode, numsrc;
76341
76342 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76343 char __user *optval, int __user *optlen,
76344 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76345 {
76346 - struct compat_group_filter __user *gf32 = (void *)optval;
76347 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76348 struct group_filter __user *kgf;
76349 int __user *koptlen;
76350 u32 interface, fmode, numsrc;
76351 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76352
76353 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76354 return -EINVAL;
76355 - if (copy_from_user(a, args, nas[call]))
76356 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76357 return -EFAULT;
76358 a0 = a[0];
76359 a1 = a[1];
76360 diff --git a/net/core/datagram.c b/net/core/datagram.c
76361 index 0337e2b..47914a0 100644
76362 --- a/net/core/datagram.c
76363 +++ b/net/core/datagram.c
76364 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76365 }
76366
76367 kfree_skb(skb);
76368 - atomic_inc(&sk->sk_drops);
76369 + atomic_inc_unchecked(&sk->sk_drops);
76370 sk_mem_reclaim_partial(sk);
76371
76372 return err;
76373 diff --git a/net/core/dev.c b/net/core/dev.c
76374 index 2fb9f59..d9a07df 100644
76375 --- a/net/core/dev.c
76376 +++ b/net/core/dev.c
76377 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76378 if (no_module && capable(CAP_NET_ADMIN))
76379 no_module = request_module("netdev-%s", name);
76380 if (no_module && capable(CAP_SYS_MODULE)) {
76381 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76382 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76383 +#else
76384 if (!request_module("%s", name))
76385 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76386 name);
76387 +#endif
76388 }
76389 }
76390 EXPORT_SYMBOL(dev_load);
76391 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76392 {
76393 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76394 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76395 - atomic_long_inc(&dev->rx_dropped);
76396 + atomic_long_inc_unchecked(&dev->rx_dropped);
76397 kfree_skb(skb);
76398 return NET_RX_DROP;
76399 }
76400 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76401 nf_reset(skb);
76402
76403 if (unlikely(!is_skb_forwardable(dev, skb))) {
76404 - atomic_long_inc(&dev->rx_dropped);
76405 + atomic_long_inc_unchecked(&dev->rx_dropped);
76406 kfree_skb(skb);
76407 return NET_RX_DROP;
76408 }
76409 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76410
76411 struct dev_gso_cb {
76412 void (*destructor)(struct sk_buff *skb);
76413 -};
76414 +} __no_const;
76415
76416 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76417
76418 @@ -2928,7 +2932,7 @@ enqueue:
76419
76420 local_irq_restore(flags);
76421
76422 - atomic_long_inc(&skb->dev->rx_dropped);
76423 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76424 kfree_skb(skb);
76425 return NET_RX_DROP;
76426 }
76427 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76428 }
76429 EXPORT_SYMBOL(netif_rx_ni);
76430
76431 -static void net_tx_action(struct softirq_action *h)
76432 +static void net_tx_action(void)
76433 {
76434 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76435
76436 @@ -3331,7 +3335,7 @@ ncls:
76437 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76438 } else {
76439 drop:
76440 - atomic_long_inc(&skb->dev->rx_dropped);
76441 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76442 kfree_skb(skb);
76443 /* Jamal, now you will not able to escape explaining
76444 * me how you were going to use this. :-)
76445 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76446 }
76447 EXPORT_SYMBOL(netif_napi_del);
76448
76449 -static void net_rx_action(struct softirq_action *h)
76450 +static void net_rx_action(void)
76451 {
76452 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76453 unsigned long time_limit = jiffies + 2;
76454 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76455 else
76456 seq_printf(seq, "%04x", ntohs(pt->type));
76457
76458 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76459 + seq_printf(seq, " %-8s %p\n",
76460 + pt->dev ? pt->dev->name : "", NULL);
76461 +#else
76462 seq_printf(seq, " %-8s %pF\n",
76463 pt->dev ? pt->dev->name : "", pt->func);
76464 +#endif
76465 }
76466
76467 return 0;
76468 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76469 } else {
76470 netdev_stats_to_stats64(storage, &dev->stats);
76471 }
76472 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76473 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76474 return storage;
76475 }
76476 EXPORT_SYMBOL(dev_get_stats);
76477 diff --git a/net/core/flow.c b/net/core/flow.c
76478 index e318c7e..168b1d0 100644
76479 --- a/net/core/flow.c
76480 +++ b/net/core/flow.c
76481 @@ -61,7 +61,7 @@ struct flow_cache {
76482 struct timer_list rnd_timer;
76483 };
76484
76485 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76486 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76487 EXPORT_SYMBOL(flow_cache_genid);
76488 static struct flow_cache flow_cache_global;
76489 static struct kmem_cache *flow_cachep __read_mostly;
76490 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76491
76492 static int flow_entry_valid(struct flow_cache_entry *fle)
76493 {
76494 - if (atomic_read(&flow_cache_genid) != fle->genid)
76495 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76496 return 0;
76497 if (fle->object && !fle->object->ops->check(fle->object))
76498 return 0;
76499 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76500 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76501 fcp->hash_count++;
76502 }
76503 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76504 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76505 flo = fle->object;
76506 if (!flo)
76507 goto ret_object;
76508 @@ -280,7 +280,7 @@ nocache:
76509 }
76510 flo = resolver(net, key, family, dir, flo, ctx);
76511 if (fle) {
76512 - fle->genid = atomic_read(&flow_cache_genid);
76513 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76514 if (!IS_ERR(flo))
76515 fle->object = flo;
76516 else
76517 diff --git a/net/core/iovec.c b/net/core/iovec.c
76518 index 7e7aeb0..2a998cb 100644
76519 --- a/net/core/iovec.c
76520 +++ b/net/core/iovec.c
76521 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76522 if (m->msg_namelen) {
76523 if (mode == VERIFY_READ) {
76524 void __user *namep;
76525 - namep = (void __user __force *) m->msg_name;
76526 + namep = (void __force_user *) m->msg_name;
76527 err = move_addr_to_kernel(namep, m->msg_namelen,
76528 address);
76529 if (err < 0)
76530 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76531 }
76532
76533 size = m->msg_iovlen * sizeof(struct iovec);
76534 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76535 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76536 return -EFAULT;
76537
76538 m->msg_iov = iov;
76539 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76540 index 2c5a0a0..a45f90c 100644
76541 --- a/net/core/rtnetlink.c
76542 +++ b/net/core/rtnetlink.c
76543 @@ -58,7 +58,7 @@ struct rtnl_link {
76544 rtnl_doit_func doit;
76545 rtnl_dumpit_func dumpit;
76546 rtnl_calcit_func calcit;
76547 -};
76548 +} __no_const;
76549
76550 static DEFINE_MUTEX(rtnl_mutex);
76551
76552 diff --git a/net/core/scm.c b/net/core/scm.c
76553 index 040cebe..5b1e312 100644
76554 --- a/net/core/scm.c
76555 +++ b/net/core/scm.c
76556 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76557 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76558 {
76559 struct cmsghdr __user *cm
76560 - = (__force struct cmsghdr __user *)msg->msg_control;
76561 + = (struct cmsghdr __force_user *)msg->msg_control;
76562 struct cmsghdr cmhdr;
76563 int cmlen = CMSG_LEN(len);
76564 int err;
76565 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76566 err = -EFAULT;
76567 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76568 goto out;
76569 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76570 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76571 goto out;
76572 cmlen = CMSG_SPACE(len);
76573 if (msg->msg_controllen < cmlen)
76574 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76575 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76576 {
76577 struct cmsghdr __user *cm
76578 - = (__force struct cmsghdr __user*)msg->msg_control;
76579 + = (struct cmsghdr __force_user *)msg->msg_control;
76580
76581 int fdmax = 0;
76582 int fdnum = scm->fp->count;
76583 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76584 if (fdnum < fdmax)
76585 fdmax = fdnum;
76586
76587 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76588 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76589 i++, cmfptr++)
76590 {
76591 struct socket *sock;
76592 diff --git a/net/core/sock.c b/net/core/sock.c
76593 index a6000fb..d4aee72 100644
76594 --- a/net/core/sock.c
76595 +++ b/net/core/sock.c
76596 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76597 struct sk_buff_head *list = &sk->sk_receive_queue;
76598
76599 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76600 - atomic_inc(&sk->sk_drops);
76601 + atomic_inc_unchecked(&sk->sk_drops);
76602 trace_sock_rcvqueue_full(sk, skb);
76603 return -ENOMEM;
76604 }
76605 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76606 return err;
76607
76608 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76609 - atomic_inc(&sk->sk_drops);
76610 + atomic_inc_unchecked(&sk->sk_drops);
76611 return -ENOBUFS;
76612 }
76613
76614 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76615 skb_dst_force(skb);
76616
76617 spin_lock_irqsave(&list->lock, flags);
76618 - skb->dropcount = atomic_read(&sk->sk_drops);
76619 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76620 __skb_queue_tail(list, skb);
76621 spin_unlock_irqrestore(&list->lock, flags);
76622
76623 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76624 skb->dev = NULL;
76625
76626 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76627 - atomic_inc(&sk->sk_drops);
76628 + atomic_inc_unchecked(&sk->sk_drops);
76629 goto discard_and_relse;
76630 }
76631 if (nested)
76632 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76633 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76634 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76635 bh_unlock_sock(sk);
76636 - atomic_inc(&sk->sk_drops);
76637 + atomic_inc_unchecked(&sk->sk_drops);
76638 goto discard_and_relse;
76639 }
76640
76641 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76642 struct timeval tm;
76643 } v;
76644
76645 - int lv = sizeof(int);
76646 - int len;
76647 + unsigned int lv = sizeof(int);
76648 + unsigned int len;
76649
76650 if (get_user(len, optlen))
76651 return -EFAULT;
76652 - if (len < 0)
76653 + if (len > INT_MAX)
76654 return -EINVAL;
76655
76656 memset(&v, 0, sizeof(v));
76657 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76658
76659 case SO_PEERNAME:
76660 {
76661 - char address[128];
76662 + char address[_K_SS_MAXSIZE];
76663
76664 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76665 return -ENOTCONN;
76666 - if (lv < len)
76667 + if (lv < len || sizeof address < len)
76668 return -EINVAL;
76669 if (copy_to_user(optval, address, len))
76670 return -EFAULT;
76671 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76672
76673 if (len > lv)
76674 len = lv;
76675 - if (copy_to_user(optval, &v, len))
76676 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76677 return -EFAULT;
76678 lenout:
76679 if (put_user(len, optlen))
76680 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76681 */
76682 smp_wmb();
76683 atomic_set(&sk->sk_refcnt, 1);
76684 - atomic_set(&sk->sk_drops, 0);
76685 + atomic_set_unchecked(&sk->sk_drops, 0);
76686 }
76687 EXPORT_SYMBOL(sock_init_data);
76688
76689 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76690 index 9d8755e..26de8bc 100644
76691 --- a/net/core/sock_diag.c
76692 +++ b/net/core/sock_diag.c
76693 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76694
76695 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76696 {
76697 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76698 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76699 cookie[1] != INET_DIAG_NOCOOKIE) &&
76700 ((u32)(unsigned long)sk != cookie[0] ||
76701 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76702 return -ESTALE;
76703 else
76704 +#endif
76705 return 0;
76706 }
76707 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76708
76709 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76710 {
76711 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76712 + cookie[0] = 0;
76713 + cookie[1] = 0;
76714 +#else
76715 cookie[0] = (u32)(unsigned long)sk;
76716 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76717 +#endif
76718 }
76719 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76720
76721 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76722 index a55eecc..dd8428c 100644
76723 --- a/net/decnet/sysctl_net_decnet.c
76724 +++ b/net/decnet/sysctl_net_decnet.c
76725 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76726
76727 if (len > *lenp) len = *lenp;
76728
76729 - if (copy_to_user(buffer, addr, len))
76730 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76731 return -EFAULT;
76732
76733 *lenp = len;
76734 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76735
76736 if (len > *lenp) len = *lenp;
76737
76738 - if (copy_to_user(buffer, devname, len))
76739 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76740 return -EFAULT;
76741
76742 *lenp = len;
76743 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76744 index f444ac7..b7bdda9 100644
76745 --- a/net/ipv4/fib_frontend.c
76746 +++ b/net/ipv4/fib_frontend.c
76747 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76748 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76749 fib_sync_up(dev);
76750 #endif
76751 - atomic_inc(&net->ipv4.dev_addr_genid);
76752 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76753 rt_cache_flush(dev_net(dev));
76754 break;
76755 case NETDEV_DOWN:
76756 fib_del_ifaddr(ifa, NULL);
76757 - atomic_inc(&net->ipv4.dev_addr_genid);
76758 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76759 if (ifa->ifa_dev->ifa_list == NULL) {
76760 /* Last address was deleted from this interface.
76761 * Disable IP.
76762 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76763 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76764 fib_sync_up(dev);
76765 #endif
76766 - atomic_inc(&net->ipv4.dev_addr_genid);
76767 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76768 rt_cache_flush(dev_net(dev));
76769 break;
76770 case NETDEV_DOWN:
76771 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76772 index 9633661..4e0bc08 100644
76773 --- a/net/ipv4/fib_semantics.c
76774 +++ b/net/ipv4/fib_semantics.c
76775 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76776 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76777 nh->nh_gw,
76778 nh->nh_parent->fib_scope);
76779 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76780 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76781
76782 return nh->nh_saddr;
76783 }
76784 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76785 index 7880af9..70f92a3 100644
76786 --- a/net/ipv4/inet_hashtables.c
76787 +++ b/net/ipv4/inet_hashtables.c
76788 @@ -18,12 +18,15 @@
76789 #include <linux/sched.h>
76790 #include <linux/slab.h>
76791 #include <linux/wait.h>
76792 +#include <linux/security.h>
76793
76794 #include <net/inet_connection_sock.h>
76795 #include <net/inet_hashtables.h>
76796 #include <net/secure_seq.h>
76797 #include <net/ip.h>
76798
76799 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76800 +
76801 /*
76802 * Allocate and initialize a new local port bind bucket.
76803 * The bindhash mutex for snum's hash chain must be held here.
76804 @@ -530,6 +533,8 @@ ok:
76805 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76806 spin_unlock(&head->lock);
76807
76808 + gr_update_task_in_ip_table(current, inet_sk(sk));
76809 +
76810 if (tw) {
76811 inet_twsk_deschedule(tw, death_row);
76812 while (twrefcnt) {
76813 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76814 index c7527f6..d8bba61 100644
76815 --- a/net/ipv4/inetpeer.c
76816 +++ b/net/ipv4/inetpeer.c
76817 @@ -503,8 +503,8 @@ relookup:
76818 if (p) {
76819 p->daddr = *daddr;
76820 atomic_set(&p->refcnt, 1);
76821 - atomic_set(&p->rid, 0);
76822 - atomic_set(&p->ip_id_count,
76823 + atomic_set_unchecked(&p->rid, 0);
76824 + atomic_set_unchecked(&p->ip_id_count,
76825 (daddr->family == AF_INET) ?
76826 secure_ip_id(daddr->addr.a4) :
76827 secure_ipv6_id(daddr->addr.a6));
76828 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76829 index 8d07c97..d0812ef 100644
76830 --- a/net/ipv4/ip_fragment.c
76831 +++ b/net/ipv4/ip_fragment.c
76832 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76833 return 0;
76834
76835 start = qp->rid;
76836 - end = atomic_inc_return(&peer->rid);
76837 + end = atomic_inc_return_unchecked(&peer->rid);
76838 qp->rid = end;
76839
76840 rc = qp->q.fragments && (end - start) > max;
76841 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76842 index 5eea4a8..49819c2 100644
76843 --- a/net/ipv4/ip_sockglue.c
76844 +++ b/net/ipv4/ip_sockglue.c
76845 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76846 len = min_t(unsigned int, len, opt->optlen);
76847 if (put_user(len, optlen))
76848 return -EFAULT;
76849 - if (copy_to_user(optval, opt->__data, len))
76850 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76851 + copy_to_user(optval, opt->__data, len))
76852 return -EFAULT;
76853 return 0;
76854 }
76855 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76856 if (sk->sk_type != SOCK_STREAM)
76857 return -ENOPROTOOPT;
76858
76859 - msg.msg_control = optval;
76860 + msg.msg_control = (void __force_kernel *)optval;
76861 msg.msg_controllen = len;
76862 msg.msg_flags = flags;
76863
76864 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76865 index 67e8a6b..386764d 100644
76866 --- a/net/ipv4/ipconfig.c
76867 +++ b/net/ipv4/ipconfig.c
76868 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76869
76870 mm_segment_t oldfs = get_fs();
76871 set_fs(get_ds());
76872 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76873 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76874 set_fs(oldfs);
76875 return res;
76876 }
76877 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76878
76879 mm_segment_t oldfs = get_fs();
76880 set_fs(get_ds());
76881 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76882 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76883 set_fs(oldfs);
76884 return res;
76885 }
76886 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76887
76888 mm_segment_t oldfs = get_fs();
76889 set_fs(get_ds());
76890 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76891 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76892 set_fs(oldfs);
76893 return res;
76894 }
76895 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76896 index 97e61ea..cac1bbb 100644
76897 --- a/net/ipv4/netfilter/arp_tables.c
76898 +++ b/net/ipv4/netfilter/arp_tables.c
76899 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
76900 #endif
76901
76902 static int get_info(struct net *net, void __user *user,
76903 - const int *len, int compat)
76904 + int len, int compat)
76905 {
76906 char name[XT_TABLE_MAXNAMELEN];
76907 struct xt_table *t;
76908 int ret;
76909
76910 - if (*len != sizeof(struct arpt_getinfo)) {
76911 - duprintf("length %u != %Zu\n", *len,
76912 + if (len != sizeof(struct arpt_getinfo)) {
76913 + duprintf("length %u != %Zu\n", len,
76914 sizeof(struct arpt_getinfo));
76915 return -EINVAL;
76916 }
76917 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
76918 info.size = private->size;
76919 strcpy(info.name, name);
76920
76921 - if (copy_to_user(user, &info, *len) != 0)
76922 + if (copy_to_user(user, &info, len) != 0)
76923 ret = -EFAULT;
76924 else
76925 ret = 0;
76926 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
76927
76928 switch (cmd) {
76929 case ARPT_SO_GET_INFO:
76930 - ret = get_info(sock_net(sk), user, len, 1);
76931 + ret = get_info(sock_net(sk), user, *len, 1);
76932 break;
76933 case ARPT_SO_GET_ENTRIES:
76934 ret = compat_get_entries(sock_net(sk), user, len);
76935 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
76936
76937 switch (cmd) {
76938 case ARPT_SO_GET_INFO:
76939 - ret = get_info(sock_net(sk), user, len, 0);
76940 + ret = get_info(sock_net(sk), user, *len, 0);
76941 break;
76942
76943 case ARPT_SO_GET_ENTRIES:
76944 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76945 index 170b1fd..6105b91 100644
76946 --- a/net/ipv4/netfilter/ip_tables.c
76947 +++ b/net/ipv4/netfilter/ip_tables.c
76948 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
76949 #endif
76950
76951 static int get_info(struct net *net, void __user *user,
76952 - const int *len, int compat)
76953 + int len, int compat)
76954 {
76955 char name[XT_TABLE_MAXNAMELEN];
76956 struct xt_table *t;
76957 int ret;
76958
76959 - if (*len != sizeof(struct ipt_getinfo)) {
76960 - duprintf("length %u != %zu\n", *len,
76961 + if (len != sizeof(struct ipt_getinfo)) {
76962 + duprintf("length %u != %zu\n", len,
76963 sizeof(struct ipt_getinfo));
76964 return -EINVAL;
76965 }
76966 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
76967 info.size = private->size;
76968 strcpy(info.name, name);
76969
76970 - if (copy_to_user(user, &info, *len) != 0)
76971 + if (copy_to_user(user, &info, len) != 0)
76972 ret = -EFAULT;
76973 else
76974 ret = 0;
76975 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76976
76977 switch (cmd) {
76978 case IPT_SO_GET_INFO:
76979 - ret = get_info(sock_net(sk), user, len, 1);
76980 + ret = get_info(sock_net(sk), user, *len, 1);
76981 break;
76982 case IPT_SO_GET_ENTRIES:
76983 ret = compat_get_entries(sock_net(sk), user, len);
76984 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76985
76986 switch (cmd) {
76987 case IPT_SO_GET_INFO:
76988 - ret = get_info(sock_net(sk), user, len, 0);
76989 + ret = get_info(sock_net(sk), user, *len, 0);
76990 break;
76991
76992 case IPT_SO_GET_ENTRIES:
76993 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76994 index 6232d47..6b88607 100644
76995 --- a/net/ipv4/ping.c
76996 +++ b/net/ipv4/ping.c
76997 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76998 sk_rmem_alloc_get(sp),
76999 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77000 atomic_read(&sp->sk_refcnt), sp,
77001 - atomic_read(&sp->sk_drops), len);
77002 + atomic_read_unchecked(&sp->sk_drops), len);
77003 }
77004
77005 static int ping_seq_show(struct seq_file *seq, void *v)
77006 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77007 index d23c657..cb69cc2 100644
77008 --- a/net/ipv4/raw.c
77009 +++ b/net/ipv4/raw.c
77010 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77011 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77012 {
77013 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77014 - atomic_inc(&sk->sk_drops);
77015 + atomic_inc_unchecked(&sk->sk_drops);
77016 kfree_skb(skb);
77017 return NET_RX_DROP;
77018 }
77019 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77020
77021 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77022 {
77023 + struct icmp_filter filter;
77024 +
77025 if (optlen > sizeof(struct icmp_filter))
77026 optlen = sizeof(struct icmp_filter);
77027 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77028 + if (copy_from_user(&filter, optval, optlen))
77029 return -EFAULT;
77030 + raw_sk(sk)->filter = filter;
77031 return 0;
77032 }
77033
77034 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77035 {
77036 int len, ret = -EFAULT;
77037 + struct icmp_filter filter;
77038
77039 if (get_user(len, optlen))
77040 goto out;
77041 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77042 if (len > sizeof(struct icmp_filter))
77043 len = sizeof(struct icmp_filter);
77044 ret = -EFAULT;
77045 - if (put_user(len, optlen) ||
77046 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77047 + filter = raw_sk(sk)->filter;
77048 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77049 goto out;
77050 ret = 0;
77051 out: return ret;
77052 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77053 sk_wmem_alloc_get(sp),
77054 sk_rmem_alloc_get(sp),
77055 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77056 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77057 + atomic_read(&sp->sk_refcnt),
77058 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77059 + NULL,
77060 +#else
77061 + sp,
77062 +#endif
77063 + atomic_read_unchecked(&sp->sk_drops));
77064 }
77065
77066 static int raw_seq_show(struct seq_file *seq, void *v)
77067 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77068 index 2a1383c..ff99572 100644
77069 --- a/net/ipv4/route.c
77070 +++ b/net/ipv4/route.c
77071 @@ -2523,7 +2523,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77072
77073 static __net_init int rt_genid_init(struct net *net)
77074 {
77075 - atomic_set(&net->rt_genid, 0);
77076 + atomic_set_unchecked(&net->rt_genid, 0);
77077 get_random_bytes(&net->ipv4.dev_addr_genid,
77078 sizeof(net->ipv4.dev_addr_genid));
77079 return 0;
77080 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77081 index d377f48..c2211ed 100644
77082 --- a/net/ipv4/tcp_input.c
77083 +++ b/net/ipv4/tcp_input.c
77084 @@ -4728,7 +4728,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77085 * simplifies code)
77086 */
77087 static void
77088 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77089 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77090 struct sk_buff *head, struct sk_buff *tail,
77091 u32 start, u32 end)
77092 {
77093 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77094 index db7bfad..bfea796 100644
77095 --- a/net/ipv4/tcp_ipv4.c
77096 +++ b/net/ipv4/tcp_ipv4.c
77097 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77098 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77099
77100
77101 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77102 +extern int grsec_enable_blackhole;
77103 +#endif
77104 +
77105 #ifdef CONFIG_TCP_MD5SIG
77106 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77107 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77108 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77109 return 0;
77110
77111 reset:
77112 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77113 + if (!grsec_enable_blackhole)
77114 +#endif
77115 tcp_v4_send_reset(rsk, skb);
77116 discard:
77117 kfree_skb(skb);
77118 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77119 TCP_SKB_CB(skb)->sacked = 0;
77120
77121 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77122 - if (!sk)
77123 + if (!sk) {
77124 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77125 + ret = 1;
77126 +#endif
77127 goto no_tcp_socket;
77128 -
77129 + }
77130 process:
77131 - if (sk->sk_state == TCP_TIME_WAIT)
77132 + if (sk->sk_state == TCP_TIME_WAIT) {
77133 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77134 + ret = 2;
77135 +#endif
77136 goto do_time_wait;
77137 + }
77138
77139 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77140 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77141 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77142 bad_packet:
77143 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77144 } else {
77145 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77146 + if (!grsec_enable_blackhole || (ret == 1 &&
77147 + (skb->dev->flags & IFF_LOOPBACK)))
77148 +#endif
77149 tcp_v4_send_reset(NULL, skb);
77150 }
77151
77152 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77153 0, /* non standard timer */
77154 0, /* open_requests have no inode */
77155 atomic_read(&sk->sk_refcnt),
77156 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77157 + NULL,
77158 +#else
77159 req,
77160 +#endif
77161 len);
77162 }
77163
77164 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77165 sock_i_uid(sk),
77166 icsk->icsk_probes_out,
77167 sock_i_ino(sk),
77168 - atomic_read(&sk->sk_refcnt), sk,
77169 + atomic_read(&sk->sk_refcnt),
77170 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77171 + NULL,
77172 +#else
77173 + sk,
77174 +#endif
77175 jiffies_to_clock_t(icsk->icsk_rto),
77176 jiffies_to_clock_t(icsk->icsk_ack.ato),
77177 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77178 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77179 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77180 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77181 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77182 - atomic_read(&tw->tw_refcnt), tw, len);
77183 + atomic_read(&tw->tw_refcnt),
77184 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77185 + NULL,
77186 +#else
77187 + tw,
77188 +#endif
77189 + len);
77190 }
77191
77192 #define TMPSZ 150
77193 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77194 index 6ff7f10..38de56e 100644
77195 --- a/net/ipv4/tcp_minisocks.c
77196 +++ b/net/ipv4/tcp_minisocks.c
77197 @@ -27,6 +27,10 @@
77198 #include <net/inet_common.h>
77199 #include <net/xfrm.h>
77200
77201 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77202 +extern int grsec_enable_blackhole;
77203 +#endif
77204 +
77205 int sysctl_tcp_syncookies __read_mostly = 1;
77206 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77207
77208 @@ -707,6 +711,10 @@ listen_overflow:
77209
77210 embryonic_reset:
77211 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77212 +
77213 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77214 + if (!grsec_enable_blackhole)
77215 +#endif
77216 if (!(flg & TCP_FLAG_RST))
77217 req->rsk_ops->send_reset(sk, skb);
77218
77219 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77220 index 4526fe6..1a34e43 100644
77221 --- a/net/ipv4/tcp_probe.c
77222 +++ b/net/ipv4/tcp_probe.c
77223 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77224 if (cnt + width >= len)
77225 break;
77226
77227 - if (copy_to_user(buf + cnt, tbuf, width))
77228 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77229 return -EFAULT;
77230 cnt += width;
77231 }
77232 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77233 index b774a03..3873efe 100644
77234 --- a/net/ipv4/tcp_timer.c
77235 +++ b/net/ipv4/tcp_timer.c
77236 @@ -22,6 +22,10 @@
77237 #include <linux/gfp.h>
77238 #include <net/tcp.h>
77239
77240 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77241 +extern int grsec_lastack_retries;
77242 +#endif
77243 +
77244 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77245 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77246 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77247 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77248 }
77249 }
77250
77251 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77252 + if ((sk->sk_state == TCP_LAST_ACK) &&
77253 + (grsec_lastack_retries > 0) &&
77254 + (grsec_lastack_retries < retry_until))
77255 + retry_until = grsec_lastack_retries;
77256 +#endif
77257 +
77258 if (retransmits_timed_out(sk, retry_until,
77259 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77260 /* Has it gone just too far? */
77261 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77262 index 2814f66..fa2b223 100644
77263 --- a/net/ipv4/udp.c
77264 +++ b/net/ipv4/udp.c
77265 @@ -87,6 +87,7 @@
77266 #include <linux/types.h>
77267 #include <linux/fcntl.h>
77268 #include <linux/module.h>
77269 +#include <linux/security.h>
77270 #include <linux/socket.h>
77271 #include <linux/sockios.h>
77272 #include <linux/igmp.h>
77273 @@ -111,6 +112,10 @@
77274 #include <trace/events/skb.h>
77275 #include "udp_impl.h"
77276
77277 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77278 +extern int grsec_enable_blackhole;
77279 +#endif
77280 +
77281 struct udp_table udp_table __read_mostly;
77282 EXPORT_SYMBOL(udp_table);
77283
77284 @@ -569,6 +574,9 @@ found:
77285 return s;
77286 }
77287
77288 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77289 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77290 +
77291 /*
77292 * This routine is called by the ICMP module when it gets some
77293 * sort of error condition. If err < 0 then the socket should
77294 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77295 dport = usin->sin_port;
77296 if (dport == 0)
77297 return -EINVAL;
77298 +
77299 + err = gr_search_udp_sendmsg(sk, usin);
77300 + if (err)
77301 + return err;
77302 } else {
77303 if (sk->sk_state != TCP_ESTABLISHED)
77304 return -EDESTADDRREQ;
77305 +
77306 + err = gr_search_udp_sendmsg(sk, NULL);
77307 + if (err)
77308 + return err;
77309 +
77310 daddr = inet->inet_daddr;
77311 dport = inet->inet_dport;
77312 /* Open fast path for connected socket.
77313 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77314 udp_lib_checksum_complete(skb)) {
77315 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77316 IS_UDPLITE(sk));
77317 - atomic_inc(&sk->sk_drops);
77318 + atomic_inc_unchecked(&sk->sk_drops);
77319 __skb_unlink(skb, rcvq);
77320 __skb_queue_tail(&list_kill, skb);
77321 }
77322 @@ -1194,6 +1211,10 @@ try_again:
77323 if (!skb)
77324 goto out;
77325
77326 + err = gr_search_udp_recvmsg(sk, skb);
77327 + if (err)
77328 + goto out_free;
77329 +
77330 ulen = skb->len - sizeof(struct udphdr);
77331 copied = len;
77332 if (copied > ulen)
77333 @@ -1227,7 +1248,7 @@ try_again:
77334 if (unlikely(err)) {
77335 trace_kfree_skb(skb, udp_recvmsg);
77336 if (!peeked) {
77337 - atomic_inc(&sk->sk_drops);
77338 + atomic_inc_unchecked(&sk->sk_drops);
77339 UDP_INC_STATS_USER(sock_net(sk),
77340 UDP_MIB_INERRORS, is_udplite);
77341 }
77342 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77343
77344 drop:
77345 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77346 - atomic_inc(&sk->sk_drops);
77347 + atomic_inc_unchecked(&sk->sk_drops);
77348 kfree_skb(skb);
77349 return -1;
77350 }
77351 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77352 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77353
77354 if (!skb1) {
77355 - atomic_inc(&sk->sk_drops);
77356 + atomic_inc_unchecked(&sk->sk_drops);
77357 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77358 IS_UDPLITE(sk));
77359 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77360 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77361 goto csum_error;
77362
77363 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77364 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77365 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77366 +#endif
77367 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77368
77369 /*
77370 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77371 sk_wmem_alloc_get(sp),
77372 sk_rmem_alloc_get(sp),
77373 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77374 - atomic_read(&sp->sk_refcnt), sp,
77375 - atomic_read(&sp->sk_drops), len);
77376 + atomic_read(&sp->sk_refcnt),
77377 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77378 + NULL,
77379 +#else
77380 + sp,
77381 +#endif
77382 + atomic_read_unchecked(&sp->sk_drops), len);
77383 }
77384
77385 int udp4_seq_show(struct seq_file *seq, void *v)
77386 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77387 index b10374d..0baa1f9 100644
77388 --- a/net/ipv6/addrconf.c
77389 +++ b/net/ipv6/addrconf.c
77390 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77391 p.iph.ihl = 5;
77392 p.iph.protocol = IPPROTO_IPV6;
77393 p.iph.ttl = 64;
77394 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77395 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77396
77397 if (ops->ndo_do_ioctl) {
77398 mm_segment_t oldfs = get_fs();
77399 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77400 index ba6d13d..6899122 100644
77401 --- a/net/ipv6/ipv6_sockglue.c
77402 +++ b/net/ipv6/ipv6_sockglue.c
77403 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77404 if (sk->sk_type != SOCK_STREAM)
77405 return -ENOPROTOOPT;
77406
77407 - msg.msg_control = optval;
77408 + msg.msg_control = (void __force_kernel *)optval;
77409 msg.msg_controllen = len;
77410 msg.msg_flags = flags;
77411
77412 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77413 index d7cb045..8c0ded6 100644
77414 --- a/net/ipv6/netfilter/ip6_tables.c
77415 +++ b/net/ipv6/netfilter/ip6_tables.c
77416 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77417 #endif
77418
77419 static int get_info(struct net *net, void __user *user,
77420 - const int *len, int compat)
77421 + int len, int compat)
77422 {
77423 char name[XT_TABLE_MAXNAMELEN];
77424 struct xt_table *t;
77425 int ret;
77426
77427 - if (*len != sizeof(struct ip6t_getinfo)) {
77428 - duprintf("length %u != %zu\n", *len,
77429 + if (len != sizeof(struct ip6t_getinfo)) {
77430 + duprintf("length %u != %zu\n", len,
77431 sizeof(struct ip6t_getinfo));
77432 return -EINVAL;
77433 }
77434 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77435 info.size = private->size;
77436 strcpy(info.name, name);
77437
77438 - if (copy_to_user(user, &info, *len) != 0)
77439 + if (copy_to_user(user, &info, len) != 0)
77440 ret = -EFAULT;
77441 else
77442 ret = 0;
77443 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77444
77445 switch (cmd) {
77446 case IP6T_SO_GET_INFO:
77447 - ret = get_info(sock_net(sk), user, len, 1);
77448 + ret = get_info(sock_net(sk), user, *len, 1);
77449 break;
77450 case IP6T_SO_GET_ENTRIES:
77451 ret = compat_get_entries(sock_net(sk), user, len);
77452 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77453
77454 switch (cmd) {
77455 case IP6T_SO_GET_INFO:
77456 - ret = get_info(sock_net(sk), user, len, 0);
77457 + ret = get_info(sock_net(sk), user, *len, 0);
77458 break;
77459
77460 case IP6T_SO_GET_ENTRIES:
77461 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77462 index 4a5f78b..3f22ebe 100644
77463 --- a/net/ipv6/raw.c
77464 +++ b/net/ipv6/raw.c
77465 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77466 {
77467 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77468 skb_checksum_complete(skb)) {
77469 - atomic_inc(&sk->sk_drops);
77470 + atomic_inc_unchecked(&sk->sk_drops);
77471 kfree_skb(skb);
77472 return NET_RX_DROP;
77473 }
77474 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77475 struct raw6_sock *rp = raw6_sk(sk);
77476
77477 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77478 - atomic_inc(&sk->sk_drops);
77479 + atomic_inc_unchecked(&sk->sk_drops);
77480 kfree_skb(skb);
77481 return NET_RX_DROP;
77482 }
77483 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77484
77485 if (inet->hdrincl) {
77486 if (skb_checksum_complete(skb)) {
77487 - atomic_inc(&sk->sk_drops);
77488 + atomic_inc_unchecked(&sk->sk_drops);
77489 kfree_skb(skb);
77490 return NET_RX_DROP;
77491 }
77492 @@ -604,7 +604,7 @@ out:
77493 return err;
77494 }
77495
77496 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77497 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77498 struct flowi6 *fl6, struct dst_entry **dstp,
77499 unsigned int flags)
77500 {
77501 @@ -916,12 +916,15 @@ do_confirm:
77502 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77503 char __user *optval, int optlen)
77504 {
77505 + struct icmp6_filter filter;
77506 +
77507 switch (optname) {
77508 case ICMPV6_FILTER:
77509 if (optlen > sizeof(struct icmp6_filter))
77510 optlen = sizeof(struct icmp6_filter);
77511 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77512 + if (copy_from_user(&filter, optval, optlen))
77513 return -EFAULT;
77514 + raw6_sk(sk)->filter = filter;
77515 return 0;
77516 default:
77517 return -ENOPROTOOPT;
77518 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77519 char __user *optval, int __user *optlen)
77520 {
77521 int len;
77522 + struct icmp6_filter filter;
77523
77524 switch (optname) {
77525 case ICMPV6_FILTER:
77526 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77527 len = sizeof(struct icmp6_filter);
77528 if (put_user(len, optlen))
77529 return -EFAULT;
77530 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77531 + filter = raw6_sk(sk)->filter;
77532 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77533 return -EFAULT;
77534 return 0;
77535 default:
77536 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77537 0, 0L, 0,
77538 sock_i_uid(sp), 0,
77539 sock_i_ino(sp),
77540 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77541 + atomic_read(&sp->sk_refcnt),
77542 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77543 + NULL,
77544 +#else
77545 + sp,
77546 +#endif
77547 + atomic_read_unchecked(&sp->sk_drops));
77548 }
77549
77550 static int raw6_seq_show(struct seq_file *seq, void *v)
77551 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77552 index 7e32d42..5d975ba 100644
77553 --- a/net/ipv6/tcp_ipv6.c
77554 +++ b/net/ipv6/tcp_ipv6.c
77555 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77556 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77557 }
77558
77559 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77560 +extern int grsec_enable_blackhole;
77561 +#endif
77562 +
77563 static void tcp_v6_hash(struct sock *sk)
77564 {
77565 if (sk->sk_state != TCP_CLOSE) {
77566 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77567 return 0;
77568
77569 reset:
77570 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77571 + if (!grsec_enable_blackhole)
77572 +#endif
77573 tcp_v6_send_reset(sk, skb);
77574 discard:
77575 if (opt_skb)
77576 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77577 TCP_SKB_CB(skb)->sacked = 0;
77578
77579 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77580 - if (!sk)
77581 + if (!sk) {
77582 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77583 + ret = 1;
77584 +#endif
77585 goto no_tcp_socket;
77586 + }
77587
77588 process:
77589 - if (sk->sk_state == TCP_TIME_WAIT)
77590 + if (sk->sk_state == TCP_TIME_WAIT) {
77591 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77592 + ret = 2;
77593 +#endif
77594 goto do_time_wait;
77595 + }
77596
77597 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77598 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77599 @@ -1646,6 +1661,10 @@ no_tcp_socket:
77600 bad_packet:
77601 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77602 } else {
77603 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77604 + if (!grsec_enable_blackhole || (ret == 1 &&
77605 + (skb->dev->flags & IFF_LOOPBACK)))
77606 +#endif
77607 tcp_v6_send_reset(NULL, skb);
77608 }
77609
77610 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
77611 uid,
77612 0, /* non standard timer */
77613 0, /* open_requests have no inode */
77614 - 0, req);
77615 + 0,
77616 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77617 + NULL
77618 +#else
77619 + req
77620 +#endif
77621 + );
77622 }
77623
77624 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77625 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77626 sock_i_uid(sp),
77627 icsk->icsk_probes_out,
77628 sock_i_ino(sp),
77629 - atomic_read(&sp->sk_refcnt), sp,
77630 + atomic_read(&sp->sk_refcnt),
77631 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77632 + NULL,
77633 +#else
77634 + sp,
77635 +#endif
77636 jiffies_to_clock_t(icsk->icsk_rto),
77637 jiffies_to_clock_t(icsk->icsk_ack.ato),
77638 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77639 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77640 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77641 tw->tw_substate, 0, 0,
77642 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77643 - atomic_read(&tw->tw_refcnt), tw);
77644 + atomic_read(&tw->tw_refcnt),
77645 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77646 + NULL
77647 +#else
77648 + tw
77649 +#endif
77650 + );
77651 }
77652
77653 static int tcp6_seq_show(struct seq_file *seq, void *v)
77654 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77655 index 07e2bfe..328dae8 100644
77656 --- a/net/ipv6/udp.c
77657 +++ b/net/ipv6/udp.c
77658 @@ -51,6 +51,10 @@
77659 #include <trace/events/skb.h>
77660 #include "udp_impl.h"
77661
77662 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77663 +extern int grsec_enable_blackhole;
77664 +#endif
77665 +
77666 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77667 {
77668 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77669 @@ -395,7 +399,7 @@ try_again:
77670 if (unlikely(err)) {
77671 trace_kfree_skb(skb, udpv6_recvmsg);
77672 if (!peeked) {
77673 - atomic_inc(&sk->sk_drops);
77674 + atomic_inc_unchecked(&sk->sk_drops);
77675 if (is_udp4)
77676 UDP_INC_STATS_USER(sock_net(sk),
77677 UDP_MIB_INERRORS,
77678 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77679 return rc;
77680 drop:
77681 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77682 - atomic_inc(&sk->sk_drops);
77683 + atomic_inc_unchecked(&sk->sk_drops);
77684 kfree_skb(skb);
77685 return -1;
77686 }
77687 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77688 if (likely(skb1 == NULL))
77689 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77690 if (!skb1) {
77691 - atomic_inc(&sk->sk_drops);
77692 + atomic_inc_unchecked(&sk->sk_drops);
77693 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77694 IS_UDPLITE(sk));
77695 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77696 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77697 goto discard;
77698
77699 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77700 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77701 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77702 +#endif
77703 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77704
77705 kfree_skb(skb);
77706 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77707 0, 0L, 0,
77708 sock_i_uid(sp), 0,
77709 sock_i_ino(sp),
77710 - atomic_read(&sp->sk_refcnt), sp,
77711 - atomic_read(&sp->sk_drops));
77712 + atomic_read(&sp->sk_refcnt),
77713 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77714 + NULL,
77715 +#else
77716 + sp,
77717 +#endif
77718 + atomic_read_unchecked(&sp->sk_drops));
77719 }
77720
77721 int udp6_seq_show(struct seq_file *seq, void *v)
77722 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77723 index 6b9d5a0..4dffaf1 100644
77724 --- a/net/irda/ircomm/ircomm_tty.c
77725 +++ b/net/irda/ircomm/ircomm_tty.c
77726 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77727 add_wait_queue(&self->open_wait, &wait);
77728
77729 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77730 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77731 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77732
77733 /* As far as I can see, we protect open_count - Jean II */
77734 spin_lock_irqsave(&self->spinlock, flags);
77735 if (!tty_hung_up_p(filp)) {
77736 extra_count = 1;
77737 - self->open_count--;
77738 + local_dec(&self->open_count);
77739 }
77740 spin_unlock_irqrestore(&self->spinlock, flags);
77741 - self->blocked_open++;
77742 + local_inc(&self->blocked_open);
77743
77744 while (1) {
77745 if (tty->termios->c_cflag & CBAUD) {
77746 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77747 }
77748
77749 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77750 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77751 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77752
77753 schedule();
77754 }
77755 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77756 if (extra_count) {
77757 /* ++ is not atomic, so this should be protected - Jean II */
77758 spin_lock_irqsave(&self->spinlock, flags);
77759 - self->open_count++;
77760 + local_inc(&self->open_count);
77761 spin_unlock_irqrestore(&self->spinlock, flags);
77762 }
77763 - self->blocked_open--;
77764 + local_dec(&self->blocked_open);
77765
77766 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77767 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77768 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77769
77770 if (!retval)
77771 self->flags |= ASYNC_NORMAL_ACTIVE;
77772 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77773 }
77774 /* ++ is not atomic, so this should be protected - Jean II */
77775 spin_lock_irqsave(&self->spinlock, flags);
77776 - self->open_count++;
77777 + local_inc(&self->open_count);
77778
77779 tty->driver_data = self;
77780 self->tty = tty;
77781 spin_unlock_irqrestore(&self->spinlock, flags);
77782
77783 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77784 - self->line, self->open_count);
77785 + self->line, local_read(&self->open_count));
77786
77787 /* Not really used by us, but lets do it anyway */
77788 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77789 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77790 return;
77791 }
77792
77793 - if ((tty->count == 1) && (self->open_count != 1)) {
77794 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77795 /*
77796 * Uh, oh. tty->count is 1, which means that the tty
77797 * structure will be freed. state->count should always
77798 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77799 */
77800 IRDA_DEBUG(0, "%s(), bad serial port count; "
77801 "tty->count is 1, state->count is %d\n", __func__ ,
77802 - self->open_count);
77803 - self->open_count = 1;
77804 + local_read(&self->open_count));
77805 + local_set(&self->open_count, 1);
77806 }
77807
77808 - if (--self->open_count < 0) {
77809 + if (local_dec_return(&self->open_count) < 0) {
77810 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77811 - __func__, self->line, self->open_count);
77812 - self->open_count = 0;
77813 + __func__, self->line, local_read(&self->open_count));
77814 + local_set(&self->open_count, 0);
77815 }
77816 - if (self->open_count) {
77817 + if (local_read(&self->open_count)) {
77818 spin_unlock_irqrestore(&self->spinlock, flags);
77819
77820 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77821 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77822 tty->closing = 0;
77823 self->tty = NULL;
77824
77825 - if (self->blocked_open) {
77826 + if (local_read(&self->blocked_open)) {
77827 if (self->close_delay)
77828 schedule_timeout_interruptible(self->close_delay);
77829 wake_up_interruptible(&self->open_wait);
77830 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77831 spin_lock_irqsave(&self->spinlock, flags);
77832 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77833 self->tty = NULL;
77834 - self->open_count = 0;
77835 + local_set(&self->open_count, 0);
77836 spin_unlock_irqrestore(&self->spinlock, flags);
77837
77838 wake_up_interruptible(&self->open_wait);
77839 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77840 seq_putc(m, '\n');
77841
77842 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77843 - seq_printf(m, "Open count: %d\n", self->open_count);
77844 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77845 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77846 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77847
77848 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77849 index cd6f7a9..e63fe89 100644
77850 --- a/net/iucv/af_iucv.c
77851 +++ b/net/iucv/af_iucv.c
77852 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77853
77854 write_lock_bh(&iucv_sk_list.lock);
77855
77856 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77857 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77858 while (__iucv_get_sock_by_name(name)) {
77859 sprintf(name, "%08x",
77860 - atomic_inc_return(&iucv_sk_list.autobind_name));
77861 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77862 }
77863
77864 write_unlock_bh(&iucv_sk_list.lock);
77865 diff --git a/net/key/af_key.c b/net/key/af_key.c
77866 index 34e4185..8823368 100644
77867 --- a/net/key/af_key.c
77868 +++ b/net/key/af_key.c
77869 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77870 static u32 get_acqseq(void)
77871 {
77872 u32 res;
77873 - static atomic_t acqseq;
77874 + static atomic_unchecked_t acqseq;
77875
77876 do {
77877 - res = atomic_inc_return(&acqseq);
77878 + res = atomic_inc_return_unchecked(&acqseq);
77879 } while (!res);
77880 return res;
77881 }
77882 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77883 index bb61f77..3788d63 100644
77884 --- a/net/mac80211/ieee80211_i.h
77885 +++ b/net/mac80211/ieee80211_i.h
77886 @@ -28,6 +28,7 @@
77887 #include <net/ieee80211_radiotap.h>
77888 #include <net/cfg80211.h>
77889 #include <net/mac80211.h>
77890 +#include <asm/local.h>
77891 #include "key.h"
77892 #include "sta_info.h"
77893 #include "debug.h"
77894 @@ -840,7 +841,7 @@ struct ieee80211_local {
77895 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77896 spinlock_t queue_stop_reason_lock;
77897
77898 - int open_count;
77899 + local_t open_count;
77900 int monitors, cooked_mntrs;
77901 /* number of interfaces with corresponding FIF_ flags */
77902 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77903 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77904 index bfb57dc..77c4b81 100644
77905 --- a/net/mac80211/iface.c
77906 +++ b/net/mac80211/iface.c
77907 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77908 break;
77909 }
77910
77911 - if (local->open_count == 0) {
77912 + if (local_read(&local->open_count) == 0) {
77913 res = drv_start(local);
77914 if (res)
77915 goto err_del_bss;
77916 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77917 break;
77918 }
77919
77920 - if (local->monitors == 0 && local->open_count == 0) {
77921 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77922 res = ieee80211_add_virtual_monitor(local);
77923 if (res)
77924 goto err_stop;
77925 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77926 mutex_unlock(&local->mtx);
77927
77928 if (coming_up)
77929 - local->open_count++;
77930 + local_inc(&local->open_count);
77931
77932 if (hw_reconf_flags)
77933 ieee80211_hw_config(local, hw_reconf_flags);
77934 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77935 err_del_interface:
77936 drv_remove_interface(local, sdata);
77937 err_stop:
77938 - if (!local->open_count)
77939 + if (!local_read(&local->open_count))
77940 drv_stop(local);
77941 err_del_bss:
77942 sdata->bss = NULL;
77943 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77944 }
77945
77946 if (going_down)
77947 - local->open_count--;
77948 + local_dec(&local->open_count);
77949
77950 switch (sdata->vif.type) {
77951 case NL80211_IFTYPE_AP_VLAN:
77952 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77953
77954 ieee80211_recalc_ps(local, -1);
77955
77956 - if (local->open_count == 0) {
77957 + if (local_read(&local->open_count) == 0) {
77958 if (local->ops->napi_poll)
77959 napi_disable(&local->napi);
77960 ieee80211_clear_tx_pending(local);
77961 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77962 }
77963 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77964
77965 - if (local->monitors == local->open_count && local->monitors > 0)
77966 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77967 ieee80211_add_virtual_monitor(local);
77968 }
77969
77970 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77971 index c26e231..8916637 100644
77972 --- a/net/mac80211/main.c
77973 +++ b/net/mac80211/main.c
77974 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77975 local->hw.conf.power_level = power;
77976 }
77977
77978 - if (changed && local->open_count) {
77979 + if (changed && local_read(&local->open_count)) {
77980 ret = drv_config(local, changed);
77981 /*
77982 * Goal:
77983 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77984 index 5c572e7..ecf75ce 100644
77985 --- a/net/mac80211/pm.c
77986 +++ b/net/mac80211/pm.c
77987 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77988 struct ieee80211_sub_if_data *sdata;
77989 struct sta_info *sta;
77990
77991 - if (!local->open_count)
77992 + if (!local_read(&local->open_count))
77993 goto suspend;
77994
77995 ieee80211_scan_cancel(local);
77996 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77997 cancel_work_sync(&local->dynamic_ps_enable_work);
77998 del_timer_sync(&local->dynamic_ps_timer);
77999
78000 - local->wowlan = wowlan && local->open_count;
78001 + local->wowlan = wowlan && local_read(&local->open_count);
78002 if (local->wowlan) {
78003 int err = drv_suspend(local, wowlan);
78004 if (err < 0) {
78005 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78006 drv_remove_interface(local, sdata);
78007
78008 /* stop hardware - this must stop RX */
78009 - if (local->open_count)
78010 + if (local_read(&local->open_count))
78011 ieee80211_stop_device(local);
78012
78013 suspend:
78014 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78015 index 3313c11..bec9f17 100644
78016 --- a/net/mac80211/rate.c
78017 +++ b/net/mac80211/rate.c
78018 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78019
78020 ASSERT_RTNL();
78021
78022 - if (local->open_count)
78023 + if (local_read(&local->open_count))
78024 return -EBUSY;
78025
78026 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78027 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78028 index c97a065..ff61928 100644
78029 --- a/net/mac80211/rc80211_pid_debugfs.c
78030 +++ b/net/mac80211/rc80211_pid_debugfs.c
78031 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78032
78033 spin_unlock_irqrestore(&events->lock, status);
78034
78035 - if (copy_to_user(buf, pb, p))
78036 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78037 return -EFAULT;
78038
78039 return p;
78040 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78041 index 39b82fe..5469ef4 100644
78042 --- a/net/mac80211/util.c
78043 +++ b/net/mac80211/util.c
78044 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78045 }
78046 #endif
78047 /* everything else happens only if HW was up & running */
78048 - if (!local->open_count)
78049 + if (!local_read(&local->open_count))
78050 goto wake_up;
78051
78052 /*
78053 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78054 index c19b214..471fad1 100644
78055 --- a/net/netfilter/Kconfig
78056 +++ b/net/netfilter/Kconfig
78057 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78058
78059 To compile it as a module, choose M here. If unsure, say N.
78060
78061 +config NETFILTER_XT_MATCH_GRADM
78062 + tristate '"gradm" match support'
78063 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78064 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78065 + ---help---
78066 + The gradm match allows to match on grsecurity RBAC being enabled.
78067 + It is useful when iptables rules are applied early on bootup to
78068 + prevent connections to the machine (except from a trusted host)
78069 + while the RBAC system is disabled.
78070 +
78071 config NETFILTER_XT_MATCH_HASHLIMIT
78072 tristate '"hashlimit" match support'
78073 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78074 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78075 index 1c5160f..145ae21 100644
78076 --- a/net/netfilter/Makefile
78077 +++ b/net/netfilter/Makefile
78078 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78079 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78080 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78081 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78082 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78083 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78084 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78085 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78086 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78087 index 1548df9..98ad9b4 100644
78088 --- a/net/netfilter/ipvs/ip_vs_conn.c
78089 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78090 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78091 /* Increase the refcnt counter of the dest */
78092 atomic_inc(&dest->refcnt);
78093
78094 - conn_flags = atomic_read(&dest->conn_flags);
78095 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78096 if (cp->protocol != IPPROTO_UDP)
78097 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78098 flags = cp->flags;
78099 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78100 atomic_set(&cp->refcnt, 1);
78101
78102 atomic_set(&cp->n_control, 0);
78103 - atomic_set(&cp->in_pkts, 0);
78104 + atomic_set_unchecked(&cp->in_pkts, 0);
78105
78106 atomic_inc(&ipvs->conn_count);
78107 if (flags & IP_VS_CONN_F_NO_CPORT)
78108 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78109
78110 /* Don't drop the entry if its number of incoming packets is not
78111 located in [0, 8] */
78112 - i = atomic_read(&cp->in_pkts);
78113 + i = atomic_read_unchecked(&cp->in_pkts);
78114 if (i > 8 || i < 0) return 0;
78115
78116 if (!todrop_rate[i]) return 0;
78117 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78118 index b54ecce..fc5f6cf 100644
78119 --- a/net/netfilter/ipvs/ip_vs_core.c
78120 +++ b/net/netfilter/ipvs/ip_vs_core.c
78121 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78122 ret = cp->packet_xmit(skb, cp, pd->pp);
78123 /* do not touch skb anymore */
78124
78125 - atomic_inc(&cp->in_pkts);
78126 + atomic_inc_unchecked(&cp->in_pkts);
78127 ip_vs_conn_put(cp);
78128 return ret;
78129 }
78130 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78131 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78132 pkts = sysctl_sync_threshold(ipvs);
78133 else
78134 - pkts = atomic_add_return(1, &cp->in_pkts);
78135 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78136
78137 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78138 ip_vs_sync_conn(net, cp, pkts);
78139 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78140 index f51013c..c99ee52 100644
78141 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78142 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78143 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78144 ip_vs_rs_hash(ipvs, dest);
78145 write_unlock_bh(&ipvs->rs_lock);
78146 }
78147 - atomic_set(&dest->conn_flags, conn_flags);
78148 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78149
78150 /* bind the service */
78151 if (!dest->svc) {
78152 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78153 " %-7s %-6d %-10d %-10d\n",
78154 &dest->addr.in6,
78155 ntohs(dest->port),
78156 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78157 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78158 atomic_read(&dest->weight),
78159 atomic_read(&dest->activeconns),
78160 atomic_read(&dest->inactconns));
78161 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78162 "%-7s %-6d %-10d %-10d\n",
78163 ntohl(dest->addr.ip),
78164 ntohs(dest->port),
78165 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78166 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78167 atomic_read(&dest->weight),
78168 atomic_read(&dest->activeconns),
78169 atomic_read(&dest->inactconns));
78170 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78171
78172 entry.addr = dest->addr.ip;
78173 entry.port = dest->port;
78174 - entry.conn_flags = atomic_read(&dest->conn_flags);
78175 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78176 entry.weight = atomic_read(&dest->weight);
78177 entry.u_threshold = dest->u_threshold;
78178 entry.l_threshold = dest->l_threshold;
78179 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78180 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78181 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78182 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78183 - (atomic_read(&dest->conn_flags) &
78184 + (atomic_read_unchecked(&dest->conn_flags) &
78185 IP_VS_CONN_F_FWD_MASK)) ||
78186 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78187 atomic_read(&dest->weight)) ||
78188 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78189 index effa10c..9058928 100644
78190 --- a/net/netfilter/ipvs/ip_vs_sync.c
78191 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78192 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78193 cp = cp->control;
78194 if (cp) {
78195 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78196 - pkts = atomic_add_return(1, &cp->in_pkts);
78197 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78198 else
78199 pkts = sysctl_sync_threshold(ipvs);
78200 ip_vs_sync_conn(net, cp->control, pkts);
78201 @@ -758,7 +758,7 @@ control:
78202 if (!cp)
78203 return;
78204 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78205 - pkts = atomic_add_return(1, &cp->in_pkts);
78206 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78207 else
78208 pkts = sysctl_sync_threshold(ipvs);
78209 goto sloop;
78210 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78211
78212 if (opt)
78213 memcpy(&cp->in_seq, opt, sizeof(*opt));
78214 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78215 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78216 cp->state = state;
78217 cp->old_state = cp->state;
78218 /*
78219 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78220 index c3c6291..3376d73 100644
78221 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78222 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78223 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78224 else
78225 rc = NF_ACCEPT;
78226 /* do not touch skb anymore */
78227 - atomic_inc(&cp->in_pkts);
78228 + atomic_inc_unchecked(&cp->in_pkts);
78229 goto out;
78230 }
78231
78232 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78233 else
78234 rc = NF_ACCEPT;
78235 /* do not touch skb anymore */
78236 - atomic_inc(&cp->in_pkts);
78237 + atomic_inc_unchecked(&cp->in_pkts);
78238 goto out;
78239 }
78240
78241 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78242 index 2ceec64..a5b8a61 100644
78243 --- a/net/netfilter/nf_conntrack_core.c
78244 +++ b/net/netfilter/nf_conntrack_core.c
78245 @@ -1529,6 +1529,10 @@ err_extend:
78246 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78247 #define DYING_NULLS_VAL ((1<<30)+1)
78248
78249 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78250 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78251 +#endif
78252 +
78253 static int nf_conntrack_init_net(struct net *net)
78254 {
78255 int ret;
78256 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78257 goto err_stat;
78258 }
78259
78260 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78261 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78262 +#else
78263 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78264 +#endif
78265 if (!net->ct.slabname) {
78266 ret = -ENOMEM;
78267 goto err_slabname;
78268 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78269 index 5cfb5be..217c6d8 100644
78270 --- a/net/netfilter/nfnetlink_log.c
78271 +++ b/net/netfilter/nfnetlink_log.c
78272 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78273 };
78274
78275 static DEFINE_SPINLOCK(instances_lock);
78276 -static atomic_t global_seq;
78277 +static atomic_unchecked_t global_seq;
78278
78279 #define INSTANCE_BUCKETS 16
78280 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78281 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78282 /* global sequence number */
78283 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78284 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78285 - htonl(atomic_inc_return(&global_seq))))
78286 + htonl(atomic_inc_return_unchecked(&global_seq))))
78287 goto nla_put_failure;
78288
78289 if (data_len) {
78290 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78291 new file mode 100644
78292 index 0000000..6905327
78293 --- /dev/null
78294 +++ b/net/netfilter/xt_gradm.c
78295 @@ -0,0 +1,51 @@
78296 +/*
78297 + * gradm match for netfilter
78298 + * Copyright © Zbigniew Krzystolik, 2010
78299 + *
78300 + * This program is free software; you can redistribute it and/or modify
78301 + * it under the terms of the GNU General Public License; either version
78302 + * 2 or 3 as published by the Free Software Foundation.
78303 + */
78304 +#include <linux/module.h>
78305 +#include <linux/moduleparam.h>
78306 +#include <linux/skbuff.h>
78307 +#include <linux/netfilter/x_tables.h>
78308 +#include <linux/grsecurity.h>
78309 +#include <linux/netfilter/xt_gradm.h>
78310 +
78311 +static bool
78312 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78313 +{
78314 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78315 + bool retval = false;
78316 + if (gr_acl_is_enabled())
78317 + retval = true;
78318 + return retval ^ info->invflags;
78319 +}
78320 +
78321 +static struct xt_match gradm_mt_reg __read_mostly = {
78322 + .name = "gradm",
78323 + .revision = 0,
78324 + .family = NFPROTO_UNSPEC,
78325 + .match = gradm_mt,
78326 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78327 + .me = THIS_MODULE,
78328 +};
78329 +
78330 +static int __init gradm_mt_init(void)
78331 +{
78332 + return xt_register_match(&gradm_mt_reg);
78333 +}
78334 +
78335 +static void __exit gradm_mt_exit(void)
78336 +{
78337 + xt_unregister_match(&gradm_mt_reg);
78338 +}
78339 +
78340 +module_init(gradm_mt_init);
78341 +module_exit(gradm_mt_exit);
78342 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78343 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78344 +MODULE_LICENSE("GPL");
78345 +MODULE_ALIAS("ipt_gradm");
78346 +MODULE_ALIAS("ip6t_gradm");
78347 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78348 index 4fe4fb4..87a89e5 100644
78349 --- a/net/netfilter/xt_statistic.c
78350 +++ b/net/netfilter/xt_statistic.c
78351 @@ -19,7 +19,7 @@
78352 #include <linux/module.h>
78353
78354 struct xt_statistic_priv {
78355 - atomic_t count;
78356 + atomic_unchecked_t count;
78357 } ____cacheline_aligned_in_smp;
78358
78359 MODULE_LICENSE("GPL");
78360 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78361 break;
78362 case XT_STATISTIC_MODE_NTH:
78363 do {
78364 - oval = atomic_read(&info->master->count);
78365 + oval = atomic_read_unchecked(&info->master->count);
78366 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78367 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78368 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78369 if (nval == 0)
78370 ret = !ret;
78371 break;
78372 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78373 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78374 if (info->master == NULL)
78375 return -ENOMEM;
78376 - atomic_set(&info->master->count, info->u.nth.count);
78377 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78378
78379 return 0;
78380 }
78381 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78382 index 9172179..a4035c4 100644
78383 --- a/net/netlink/af_netlink.c
78384 +++ b/net/netlink/af_netlink.c
78385 @@ -769,7 +769,7 @@ static void netlink_overrun(struct sock *sk)
78386 sk->sk_error_report(sk);
78387 }
78388 }
78389 - atomic_inc(&sk->sk_drops);
78390 + atomic_inc_unchecked(&sk->sk_drops);
78391 }
78392
78393 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78394 @@ -2059,7 +2059,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78395 sk_wmem_alloc_get(s),
78396 nlk->cb,
78397 atomic_read(&s->sk_refcnt),
78398 - atomic_read(&s->sk_drops),
78399 + atomic_read_unchecked(&s->sk_drops),
78400 sock_i_ino(s)
78401 );
78402
78403 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78404 index 7261eb8..44e8ac6 100644
78405 --- a/net/netrom/af_netrom.c
78406 +++ b/net/netrom/af_netrom.c
78407 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78408 struct sock *sk = sock->sk;
78409 struct nr_sock *nr = nr_sk(sk);
78410
78411 + memset(sax, 0, sizeof(*sax));
78412 lock_sock(sk);
78413 if (peer != 0) {
78414 if (sk->sk_state != TCP_ESTABLISHED) {
78415 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78416 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78417 } else {
78418 sax->fsa_ax25.sax25_family = AF_NETROM;
78419 - sax->fsa_ax25.sax25_ndigis = 0;
78420 sax->fsa_ax25.sax25_call = nr->source_addr;
78421 *uaddr_len = sizeof(struct sockaddr_ax25);
78422 }
78423 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78424 index c5c9e2a..4814ab1 100644
78425 --- a/net/packet/af_packet.c
78426 +++ b/net/packet/af_packet.c
78427 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78428
78429 spin_lock(&sk->sk_receive_queue.lock);
78430 po->stats.tp_packets++;
78431 - skb->dropcount = atomic_read(&sk->sk_drops);
78432 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78433 __skb_queue_tail(&sk->sk_receive_queue, skb);
78434 spin_unlock(&sk->sk_receive_queue.lock);
78435 sk->sk_data_ready(sk, skb->len);
78436 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78437 drop_n_acct:
78438 spin_lock(&sk->sk_receive_queue.lock);
78439 po->stats.tp_drops++;
78440 - atomic_inc(&sk->sk_drops);
78441 + atomic_inc_unchecked(&sk->sk_drops);
78442 spin_unlock(&sk->sk_receive_queue.lock);
78443
78444 drop_n_restore:
78445 @@ -2642,6 +2642,7 @@ out:
78446
78447 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78448 {
78449 + struct sock_extended_err ee;
78450 struct sock_exterr_skb *serr;
78451 struct sk_buff *skb, *skb2;
78452 int copied, err;
78453 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78454 sock_recv_timestamp(msg, sk, skb);
78455
78456 serr = SKB_EXT_ERR(skb);
78457 + ee = serr->ee;
78458 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78459 - sizeof(serr->ee), &serr->ee);
78460 + sizeof ee, &ee);
78461
78462 msg->msg_flags |= MSG_ERRQUEUE;
78463 err = copied;
78464 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78465 case PACKET_HDRLEN:
78466 if (len > sizeof(int))
78467 len = sizeof(int);
78468 - if (copy_from_user(&val, optval, len))
78469 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78470 return -EFAULT;
78471 switch (val) {
78472 case TPACKET_V1:
78473 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78474 len = lv;
78475 if (put_user(len, optlen))
78476 return -EFAULT;
78477 - if (copy_to_user(optval, data, len))
78478 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78479 return -EFAULT;
78480 return 0;
78481 }
78482 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78483 index 5a940db..f0b9c12 100644
78484 --- a/net/phonet/af_phonet.c
78485 +++ b/net/phonet/af_phonet.c
78486 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78487 {
78488 struct phonet_protocol *pp;
78489
78490 - if (protocol >= PHONET_NPROTO)
78491 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78492 return NULL;
78493
78494 rcu_read_lock();
78495 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78496 {
78497 int err = 0;
78498
78499 - if (protocol >= PHONET_NPROTO)
78500 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78501 return -EINVAL;
78502
78503 err = proto_register(pp->prot, 1);
78504 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78505 index 576f22c..bc7a71b 100644
78506 --- a/net/phonet/pep.c
78507 +++ b/net/phonet/pep.c
78508 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78509
78510 case PNS_PEP_CTRL_REQ:
78511 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78512 - atomic_inc(&sk->sk_drops);
78513 + atomic_inc_unchecked(&sk->sk_drops);
78514 break;
78515 }
78516 __skb_pull(skb, 4);
78517 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78518 }
78519
78520 if (pn->rx_credits == 0) {
78521 - atomic_inc(&sk->sk_drops);
78522 + atomic_inc_unchecked(&sk->sk_drops);
78523 err = -ENOBUFS;
78524 break;
78525 }
78526 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78527 }
78528
78529 if (pn->rx_credits == 0) {
78530 - atomic_inc(&sk->sk_drops);
78531 + atomic_inc_unchecked(&sk->sk_drops);
78532 err = NET_RX_DROP;
78533 break;
78534 }
78535 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78536 index 0acc943..c727611 100644
78537 --- a/net/phonet/socket.c
78538 +++ b/net/phonet/socket.c
78539 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78540 pn->resource, sk->sk_state,
78541 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78542 sock_i_uid(sk), sock_i_ino(sk),
78543 - atomic_read(&sk->sk_refcnt), sk,
78544 - atomic_read(&sk->sk_drops), &len);
78545 + atomic_read(&sk->sk_refcnt),
78546 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78547 + NULL,
78548 +#else
78549 + sk,
78550 +#endif
78551 + atomic_read_unchecked(&sk->sk_drops), &len);
78552 }
78553 seq_printf(seq, "%*s\n", 127 - len, "");
78554 return 0;
78555 diff --git a/net/rds/cong.c b/net/rds/cong.c
78556 index e5b65ac..f3b6fb7 100644
78557 --- a/net/rds/cong.c
78558 +++ b/net/rds/cong.c
78559 @@ -78,7 +78,7 @@
78560 * finds that the saved generation number is smaller than the global generation
78561 * number, it wakes up the process.
78562 */
78563 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78564 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78565
78566 /*
78567 * Congestion monitoring
78568 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78569 rdsdebug("waking map %p for %pI4\n",
78570 map, &map->m_addr);
78571 rds_stats_inc(s_cong_update_received);
78572 - atomic_inc(&rds_cong_generation);
78573 + atomic_inc_unchecked(&rds_cong_generation);
78574 if (waitqueue_active(&map->m_waitq))
78575 wake_up(&map->m_waitq);
78576 if (waitqueue_active(&rds_poll_waitq))
78577 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78578
78579 int rds_cong_updated_since(unsigned long *recent)
78580 {
78581 - unsigned long gen = atomic_read(&rds_cong_generation);
78582 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78583
78584 if (likely(*recent == gen))
78585 return 0;
78586 diff --git a/net/rds/ib.h b/net/rds/ib.h
78587 index 8d2b3d5..227ec5b 100644
78588 --- a/net/rds/ib.h
78589 +++ b/net/rds/ib.h
78590 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78591 /* sending acks */
78592 unsigned long i_ack_flags;
78593 #ifdef KERNEL_HAS_ATOMIC64
78594 - atomic64_t i_ack_next; /* next ACK to send */
78595 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78596 #else
78597 spinlock_t i_ack_lock; /* protect i_ack_next */
78598 u64 i_ack_next; /* next ACK to send */
78599 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78600 index a1e1162..265e129 100644
78601 --- a/net/rds/ib_cm.c
78602 +++ b/net/rds/ib_cm.c
78603 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78604 /* Clear the ACK state */
78605 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78606 #ifdef KERNEL_HAS_ATOMIC64
78607 - atomic64_set(&ic->i_ack_next, 0);
78608 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78609 #else
78610 ic->i_ack_next = 0;
78611 #endif
78612 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78613 index 8d19491..05a3e65 100644
78614 --- a/net/rds/ib_recv.c
78615 +++ b/net/rds/ib_recv.c
78616 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78617 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78618 int ack_required)
78619 {
78620 - atomic64_set(&ic->i_ack_next, seq);
78621 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78622 if (ack_required) {
78623 smp_mb__before_clear_bit();
78624 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78625 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78626 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78627 smp_mb__after_clear_bit();
78628
78629 - return atomic64_read(&ic->i_ack_next);
78630 + return atomic64_read_unchecked(&ic->i_ack_next);
78631 }
78632 #endif
78633
78634 diff --git a/net/rds/iw.h b/net/rds/iw.h
78635 index 04ce3b1..48119a6 100644
78636 --- a/net/rds/iw.h
78637 +++ b/net/rds/iw.h
78638 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78639 /* sending acks */
78640 unsigned long i_ack_flags;
78641 #ifdef KERNEL_HAS_ATOMIC64
78642 - atomic64_t i_ack_next; /* next ACK to send */
78643 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78644 #else
78645 spinlock_t i_ack_lock; /* protect i_ack_next */
78646 u64 i_ack_next; /* next ACK to send */
78647 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78648 index a91e1db..cf3053f 100644
78649 --- a/net/rds/iw_cm.c
78650 +++ b/net/rds/iw_cm.c
78651 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78652 /* Clear the ACK state */
78653 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78654 #ifdef KERNEL_HAS_ATOMIC64
78655 - atomic64_set(&ic->i_ack_next, 0);
78656 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78657 #else
78658 ic->i_ack_next = 0;
78659 #endif
78660 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78661 index 4503335..db566b4 100644
78662 --- a/net/rds/iw_recv.c
78663 +++ b/net/rds/iw_recv.c
78664 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78665 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78666 int ack_required)
78667 {
78668 - atomic64_set(&ic->i_ack_next, seq);
78669 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78670 if (ack_required) {
78671 smp_mb__before_clear_bit();
78672 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78673 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78674 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78675 smp_mb__after_clear_bit();
78676
78677 - return atomic64_read(&ic->i_ack_next);
78678 + return atomic64_read_unchecked(&ic->i_ack_next);
78679 }
78680 #endif
78681
78682 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78683 index edac9ef..16bcb98 100644
78684 --- a/net/rds/tcp.c
78685 +++ b/net/rds/tcp.c
78686 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78687 int val = 1;
78688
78689 set_fs(KERNEL_DS);
78690 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78691 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78692 sizeof(val));
78693 set_fs(oldfs);
78694 }
78695 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78696 index 1b4fd68..2234175 100644
78697 --- a/net/rds/tcp_send.c
78698 +++ b/net/rds/tcp_send.c
78699 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78700
78701 oldfs = get_fs();
78702 set_fs(KERNEL_DS);
78703 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78704 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78705 sizeof(val));
78706 set_fs(oldfs);
78707 }
78708 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78709 index 05996d0..5a1dfe0 100644
78710 --- a/net/rxrpc/af_rxrpc.c
78711 +++ b/net/rxrpc/af_rxrpc.c
78712 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78713 __be32 rxrpc_epoch;
78714
78715 /* current debugging ID */
78716 -atomic_t rxrpc_debug_id;
78717 +atomic_unchecked_t rxrpc_debug_id;
78718
78719 /* count of skbs currently in use */
78720 atomic_t rxrpc_n_skbs;
78721 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78722 index e4d9cbc..b229649 100644
78723 --- a/net/rxrpc/ar-ack.c
78724 +++ b/net/rxrpc/ar-ack.c
78725 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78726
78727 _enter("{%d,%d,%d,%d},",
78728 call->acks_hard, call->acks_unacked,
78729 - atomic_read(&call->sequence),
78730 + atomic_read_unchecked(&call->sequence),
78731 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78732
78733 stop = 0;
78734 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78735
78736 /* each Tx packet has a new serial number */
78737 sp->hdr.serial =
78738 - htonl(atomic_inc_return(&call->conn->serial));
78739 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78740
78741 hdr = (struct rxrpc_header *) txb->head;
78742 hdr->serial = sp->hdr.serial;
78743 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78744 */
78745 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78746 {
78747 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78748 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78749 }
78750
78751 /*
78752 @@ -629,7 +629,7 @@ process_further:
78753
78754 latest = ntohl(sp->hdr.serial);
78755 hard = ntohl(ack.firstPacket);
78756 - tx = atomic_read(&call->sequence);
78757 + tx = atomic_read_unchecked(&call->sequence);
78758
78759 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78760 latest,
78761 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78762 goto maybe_reschedule;
78763
78764 send_ACK_with_skew:
78765 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78766 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78767 ntohl(ack.serial));
78768 send_ACK:
78769 mtu = call->conn->trans->peer->if_mtu;
78770 @@ -1173,7 +1173,7 @@ send_ACK:
78771 ackinfo.rxMTU = htonl(5692);
78772 ackinfo.jumbo_max = htonl(4);
78773
78774 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78775 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78776 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78777 ntohl(hdr.serial),
78778 ntohs(ack.maxSkew),
78779 @@ -1191,7 +1191,7 @@ send_ACK:
78780 send_message:
78781 _debug("send message");
78782
78783 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78784 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78785 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78786 send_message_2:
78787
78788 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78789 index a3bbb36..3341fb9 100644
78790 --- a/net/rxrpc/ar-call.c
78791 +++ b/net/rxrpc/ar-call.c
78792 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78793 spin_lock_init(&call->lock);
78794 rwlock_init(&call->state_lock);
78795 atomic_set(&call->usage, 1);
78796 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78797 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78798 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78799
78800 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78801 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78802 index 4106ca9..a338d7a 100644
78803 --- a/net/rxrpc/ar-connection.c
78804 +++ b/net/rxrpc/ar-connection.c
78805 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78806 rwlock_init(&conn->lock);
78807 spin_lock_init(&conn->state_lock);
78808 atomic_set(&conn->usage, 1);
78809 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78810 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78811 conn->avail_calls = RXRPC_MAXCALLS;
78812 conn->size_align = 4;
78813 conn->header_size = sizeof(struct rxrpc_header);
78814 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78815 index e7ed43a..6afa140 100644
78816 --- a/net/rxrpc/ar-connevent.c
78817 +++ b/net/rxrpc/ar-connevent.c
78818 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78819
78820 len = iov[0].iov_len + iov[1].iov_len;
78821
78822 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78823 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78824 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78825
78826 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78827 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78828 index 529572f..c758ca7 100644
78829 --- a/net/rxrpc/ar-input.c
78830 +++ b/net/rxrpc/ar-input.c
78831 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78832 /* track the latest serial number on this connection for ACK packet
78833 * information */
78834 serial = ntohl(sp->hdr.serial);
78835 - hi_serial = atomic_read(&call->conn->hi_serial);
78836 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78837 while (serial > hi_serial)
78838 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78839 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78840 serial);
78841
78842 /* request ACK generation for any ACK or DATA packet that requests
78843 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78844 index a693aca..81e7293 100644
78845 --- a/net/rxrpc/ar-internal.h
78846 +++ b/net/rxrpc/ar-internal.h
78847 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78848 int error; /* error code for local abort */
78849 int debug_id; /* debug ID for printks */
78850 unsigned int call_counter; /* call ID counter */
78851 - atomic_t serial; /* packet serial number counter */
78852 - atomic_t hi_serial; /* highest serial number received */
78853 + atomic_unchecked_t serial; /* packet serial number counter */
78854 + atomic_unchecked_t hi_serial; /* highest serial number received */
78855 u8 avail_calls; /* number of calls available */
78856 u8 size_align; /* data size alignment (for security) */
78857 u8 header_size; /* rxrpc + security header size */
78858 @@ -346,7 +346,7 @@ struct rxrpc_call {
78859 spinlock_t lock;
78860 rwlock_t state_lock; /* lock for state transition */
78861 atomic_t usage;
78862 - atomic_t sequence; /* Tx data packet sequence counter */
78863 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78864 u32 abort_code; /* local/remote abort code */
78865 enum { /* current state of call */
78866 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78867 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78868 */
78869 extern atomic_t rxrpc_n_skbs;
78870 extern __be32 rxrpc_epoch;
78871 -extern atomic_t rxrpc_debug_id;
78872 +extern atomic_unchecked_t rxrpc_debug_id;
78873 extern struct workqueue_struct *rxrpc_workqueue;
78874
78875 /*
78876 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78877 index 87f7135..74d3703 100644
78878 --- a/net/rxrpc/ar-local.c
78879 +++ b/net/rxrpc/ar-local.c
78880 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78881 spin_lock_init(&local->lock);
78882 rwlock_init(&local->services_lock);
78883 atomic_set(&local->usage, 1);
78884 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78885 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78886 memcpy(&local->srx, srx, sizeof(*srx));
78887 }
78888
78889 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78890 index e1ac183..b43e10e 100644
78891 --- a/net/rxrpc/ar-output.c
78892 +++ b/net/rxrpc/ar-output.c
78893 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78894 sp->hdr.cid = call->cid;
78895 sp->hdr.callNumber = call->call_id;
78896 sp->hdr.seq =
78897 - htonl(atomic_inc_return(&call->sequence));
78898 + htonl(atomic_inc_return_unchecked(&call->sequence));
78899 sp->hdr.serial =
78900 - htonl(atomic_inc_return(&conn->serial));
78901 + htonl(atomic_inc_return_unchecked(&conn->serial));
78902 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78903 sp->hdr.userStatus = 0;
78904 sp->hdr.securityIndex = conn->security_ix;
78905 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78906 index bebaa43..2644591 100644
78907 --- a/net/rxrpc/ar-peer.c
78908 +++ b/net/rxrpc/ar-peer.c
78909 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78910 INIT_LIST_HEAD(&peer->error_targets);
78911 spin_lock_init(&peer->lock);
78912 atomic_set(&peer->usage, 1);
78913 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78914 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78915 memcpy(&peer->srx, srx, sizeof(*srx));
78916
78917 rxrpc_assess_MTU_size(peer);
78918 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78919 index 38047f7..9f48511 100644
78920 --- a/net/rxrpc/ar-proc.c
78921 +++ b/net/rxrpc/ar-proc.c
78922 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78923 atomic_read(&conn->usage),
78924 rxrpc_conn_states[conn->state],
78925 key_serial(conn->key),
78926 - atomic_read(&conn->serial),
78927 - atomic_read(&conn->hi_serial));
78928 + atomic_read_unchecked(&conn->serial),
78929 + atomic_read_unchecked(&conn->hi_serial));
78930
78931 return 0;
78932 }
78933 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78934 index 92df566..87ec1bf 100644
78935 --- a/net/rxrpc/ar-transport.c
78936 +++ b/net/rxrpc/ar-transport.c
78937 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78938 spin_lock_init(&trans->client_lock);
78939 rwlock_init(&trans->conn_lock);
78940 atomic_set(&trans->usage, 1);
78941 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78942 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78943
78944 if (peer->srx.transport.family == AF_INET) {
78945 switch (peer->srx.transport_type) {
78946 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78947 index f226709..0e735a8 100644
78948 --- a/net/rxrpc/rxkad.c
78949 +++ b/net/rxrpc/rxkad.c
78950 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78951
78952 len = iov[0].iov_len + iov[1].iov_len;
78953
78954 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78955 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78956 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78957
78958 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78959 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78960
78961 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78962
78963 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78964 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78965 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78966
78967 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78968 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78969 index 1e2eee8..ce3967e 100644
78970 --- a/net/sctp/proc.c
78971 +++ b/net/sctp/proc.c
78972 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78973 seq_printf(seq,
78974 "%8pK %8pK %-3d %-3d %-2d %-4d "
78975 "%4d %8d %8d %7d %5lu %-5d %5d ",
78976 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78977 + assoc, sk,
78978 + sctp_sk(sk)->type, sk->sk_state,
78979 assoc->state, hash,
78980 assoc->assoc_id,
78981 assoc->sndbuf_used,
78982 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78983 index 5e25981..dbda919 100644
78984 --- a/net/sctp/socket.c
78985 +++ b/net/sctp/socket.c
78986 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78987 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78988 if (space_left < addrlen)
78989 return -ENOMEM;
78990 + if (addrlen > sizeof(temp) || addrlen < 0)
78991 + return -EFAULT;
78992 if (copy_to_user(to, &temp, addrlen))
78993 return -EFAULT;
78994 to += addrlen;
78995 diff --git a/net/socket.c b/net/socket.c
78996 index edc3c4a..4b4e4a8 100644
78997 --- a/net/socket.c
78998 +++ b/net/socket.c
78999 @@ -88,6 +88,7 @@
79000 #include <linux/nsproxy.h>
79001 #include <linux/magic.h>
79002 #include <linux/slab.h>
79003 +#include <linux/in.h>
79004
79005 #include <asm/uaccess.h>
79006 #include <asm/unistd.h>
79007 @@ -105,6 +106,8 @@
79008 #include <linux/sockios.h>
79009 #include <linux/atalk.h>
79010
79011 +#include <linux/grsock.h>
79012 +
79013 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79014 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79015 unsigned long nr_segs, loff_t pos);
79016 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79017 &sockfs_dentry_operations, SOCKFS_MAGIC);
79018 }
79019
79020 -static struct vfsmount *sock_mnt __read_mostly;
79021 +struct vfsmount *sock_mnt __read_mostly;
79022
79023 static struct file_system_type sock_fs_type = {
79024 .name = "sockfs",
79025 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79026 return -EAFNOSUPPORT;
79027 if (type < 0 || type >= SOCK_MAX)
79028 return -EINVAL;
79029 + if (protocol < 0)
79030 + return -EINVAL;
79031
79032 /* Compatibility.
79033
79034 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79035 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79036 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79037
79038 + if(!gr_search_socket(family, type, protocol)) {
79039 + retval = -EACCES;
79040 + goto out;
79041 + }
79042 +
79043 + if (gr_handle_sock_all(family, type, protocol)) {
79044 + retval = -EACCES;
79045 + goto out;
79046 + }
79047 +
79048 retval = sock_create(family, type, protocol, &sock);
79049 if (retval < 0)
79050 goto out;
79051 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79052 if (sock) {
79053 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79054 if (err >= 0) {
79055 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79056 + err = -EACCES;
79057 + goto error;
79058 + }
79059 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79060 + if (err)
79061 + goto error;
79062 +
79063 err = security_socket_bind(sock,
79064 (struct sockaddr *)&address,
79065 addrlen);
79066 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79067 (struct sockaddr *)
79068 &address, addrlen);
79069 }
79070 +error:
79071 fput_light(sock->file, fput_needed);
79072 }
79073 return err;
79074 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79075 if ((unsigned int)backlog > somaxconn)
79076 backlog = somaxconn;
79077
79078 + if (gr_handle_sock_server_other(sock->sk)) {
79079 + err = -EPERM;
79080 + goto error;
79081 + }
79082 +
79083 + err = gr_search_listen(sock);
79084 + if (err)
79085 + goto error;
79086 +
79087 err = security_socket_listen(sock, backlog);
79088 if (!err)
79089 err = sock->ops->listen(sock, backlog);
79090
79091 +error:
79092 fput_light(sock->file, fput_needed);
79093 }
79094 return err;
79095 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79096 newsock->type = sock->type;
79097 newsock->ops = sock->ops;
79098
79099 + if (gr_handle_sock_server_other(sock->sk)) {
79100 + err = -EPERM;
79101 + sock_release(newsock);
79102 + goto out_put;
79103 + }
79104 +
79105 + err = gr_search_accept(sock);
79106 + if (err) {
79107 + sock_release(newsock);
79108 + goto out_put;
79109 + }
79110 +
79111 /*
79112 * We don't need try_module_get here, as the listening socket (sock)
79113 * has the protocol module (sock->ops->owner) held.
79114 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79115 fd_install(newfd, newfile);
79116 err = newfd;
79117
79118 + gr_attach_curr_ip(newsock->sk);
79119 +
79120 out_put:
79121 fput_light(sock->file, fput_needed);
79122 out:
79123 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79124 int, addrlen)
79125 {
79126 struct socket *sock;
79127 + struct sockaddr *sck;
79128 struct sockaddr_storage address;
79129 int err, fput_needed;
79130
79131 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79132 if (err < 0)
79133 goto out_put;
79134
79135 + sck = (struct sockaddr *)&address;
79136 +
79137 + if (gr_handle_sock_client(sck)) {
79138 + err = -EACCES;
79139 + goto out_put;
79140 + }
79141 +
79142 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79143 + if (err)
79144 + goto out_put;
79145 +
79146 err =
79147 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79148 if (err)
79149 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79150 * checking falls down on this.
79151 */
79152 if (copy_from_user(ctl_buf,
79153 - (void __user __force *)msg_sys->msg_control,
79154 + (void __force_user *)msg_sys->msg_control,
79155 ctl_len))
79156 goto out_freectl;
79157 msg_sys->msg_control = ctl_buf;
79158 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79159 * kernel msghdr to use the kernel address space)
79160 */
79161
79162 - uaddr = (__force void __user *)msg_sys->msg_name;
79163 + uaddr = (void __force_user *)msg_sys->msg_name;
79164 uaddr_len = COMPAT_NAMELEN(msg);
79165 if (MSG_CMSG_COMPAT & flags) {
79166 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79167 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79168 }
79169
79170 ifr = compat_alloc_user_space(buf_size);
79171 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79172 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79173
79174 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79175 return -EFAULT;
79176 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79177 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79178
79179 if (copy_in_user(rxnfc, compat_rxnfc,
79180 - (void *)(&rxnfc->fs.m_ext + 1) -
79181 - (void *)rxnfc) ||
79182 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79183 + (void __user *)rxnfc) ||
79184 copy_in_user(&rxnfc->fs.ring_cookie,
79185 &compat_rxnfc->fs.ring_cookie,
79186 - (void *)(&rxnfc->fs.location + 1) -
79187 - (void *)&rxnfc->fs.ring_cookie) ||
79188 + (void __user *)(&rxnfc->fs.location + 1) -
79189 + (void __user *)&rxnfc->fs.ring_cookie) ||
79190 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79191 sizeof(rxnfc->rule_cnt)))
79192 return -EFAULT;
79193 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79194
79195 if (convert_out) {
79196 if (copy_in_user(compat_rxnfc, rxnfc,
79197 - (const void *)(&rxnfc->fs.m_ext + 1) -
79198 - (const void *)rxnfc) ||
79199 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79200 + (const void __user *)rxnfc) ||
79201 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79202 &rxnfc->fs.ring_cookie,
79203 - (const void *)(&rxnfc->fs.location + 1) -
79204 - (const void *)&rxnfc->fs.ring_cookie) ||
79205 + (const void __user *)(&rxnfc->fs.location + 1) -
79206 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79207 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79208 sizeof(rxnfc->rule_cnt)))
79209 return -EFAULT;
79210 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79211 old_fs = get_fs();
79212 set_fs(KERNEL_DS);
79213 err = dev_ioctl(net, cmd,
79214 - (struct ifreq __user __force *) &kifr);
79215 + (struct ifreq __force_user *) &kifr);
79216 set_fs(old_fs);
79217
79218 return err;
79219 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79220
79221 old_fs = get_fs();
79222 set_fs(KERNEL_DS);
79223 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79224 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79225 set_fs(old_fs);
79226
79227 if (cmd == SIOCGIFMAP && !err) {
79228 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79229 ret |= __get_user(rtdev, &(ur4->rt_dev));
79230 if (rtdev) {
79231 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79232 - r4.rt_dev = (char __user __force *)devname;
79233 + r4.rt_dev = (char __force_user *)devname;
79234 devname[15] = 0;
79235 } else
79236 r4.rt_dev = NULL;
79237 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79238 int __user *uoptlen;
79239 int err;
79240
79241 - uoptval = (char __user __force *) optval;
79242 - uoptlen = (int __user __force *) optlen;
79243 + uoptval = (char __force_user *) optval;
79244 + uoptlen = (int __force_user *) optlen;
79245
79246 set_fs(KERNEL_DS);
79247 if (level == SOL_SOCKET)
79248 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79249 char __user *uoptval;
79250 int err;
79251
79252 - uoptval = (char __user __force *) optval;
79253 + uoptval = (char __force_user *) optval;
79254
79255 set_fs(KERNEL_DS);
79256 if (level == SOL_SOCKET)
79257 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79258 index 128494e..775d0e0 100644
79259 --- a/net/sunrpc/sched.c
79260 +++ b/net/sunrpc/sched.c
79261 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79262 #ifdef RPC_DEBUG
79263 static void rpc_task_set_debuginfo(struct rpc_task *task)
79264 {
79265 - static atomic_t rpc_pid;
79266 + static atomic_unchecked_t rpc_pid;
79267
79268 - task->tk_pid = atomic_inc_return(&rpc_pid);
79269 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79270 }
79271 #else
79272 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79273 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79274 index 8343737..677025e 100644
79275 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79276 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79277 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79278 static unsigned int min_max_inline = 4096;
79279 static unsigned int max_max_inline = 65536;
79280
79281 -atomic_t rdma_stat_recv;
79282 -atomic_t rdma_stat_read;
79283 -atomic_t rdma_stat_write;
79284 -atomic_t rdma_stat_sq_starve;
79285 -atomic_t rdma_stat_rq_starve;
79286 -atomic_t rdma_stat_rq_poll;
79287 -atomic_t rdma_stat_rq_prod;
79288 -atomic_t rdma_stat_sq_poll;
79289 -atomic_t rdma_stat_sq_prod;
79290 +atomic_unchecked_t rdma_stat_recv;
79291 +atomic_unchecked_t rdma_stat_read;
79292 +atomic_unchecked_t rdma_stat_write;
79293 +atomic_unchecked_t rdma_stat_sq_starve;
79294 +atomic_unchecked_t rdma_stat_rq_starve;
79295 +atomic_unchecked_t rdma_stat_rq_poll;
79296 +atomic_unchecked_t rdma_stat_rq_prod;
79297 +atomic_unchecked_t rdma_stat_sq_poll;
79298 +atomic_unchecked_t rdma_stat_sq_prod;
79299
79300 /* Temporary NFS request map and context caches */
79301 struct kmem_cache *svc_rdma_map_cachep;
79302 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79303 len -= *ppos;
79304 if (len > *lenp)
79305 len = *lenp;
79306 - if (len && copy_to_user(buffer, str_buf, len))
79307 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79308 return -EFAULT;
79309 *lenp = len;
79310 *ppos += len;
79311 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79312 {
79313 .procname = "rdma_stat_read",
79314 .data = &rdma_stat_read,
79315 - .maxlen = sizeof(atomic_t),
79316 + .maxlen = sizeof(atomic_unchecked_t),
79317 .mode = 0644,
79318 .proc_handler = read_reset_stat,
79319 },
79320 {
79321 .procname = "rdma_stat_recv",
79322 .data = &rdma_stat_recv,
79323 - .maxlen = sizeof(atomic_t),
79324 + .maxlen = sizeof(atomic_unchecked_t),
79325 .mode = 0644,
79326 .proc_handler = read_reset_stat,
79327 },
79328 {
79329 .procname = "rdma_stat_write",
79330 .data = &rdma_stat_write,
79331 - .maxlen = sizeof(atomic_t),
79332 + .maxlen = sizeof(atomic_unchecked_t),
79333 .mode = 0644,
79334 .proc_handler = read_reset_stat,
79335 },
79336 {
79337 .procname = "rdma_stat_sq_starve",
79338 .data = &rdma_stat_sq_starve,
79339 - .maxlen = sizeof(atomic_t),
79340 + .maxlen = sizeof(atomic_unchecked_t),
79341 .mode = 0644,
79342 .proc_handler = read_reset_stat,
79343 },
79344 {
79345 .procname = "rdma_stat_rq_starve",
79346 .data = &rdma_stat_rq_starve,
79347 - .maxlen = sizeof(atomic_t),
79348 + .maxlen = sizeof(atomic_unchecked_t),
79349 .mode = 0644,
79350 .proc_handler = read_reset_stat,
79351 },
79352 {
79353 .procname = "rdma_stat_rq_poll",
79354 .data = &rdma_stat_rq_poll,
79355 - .maxlen = sizeof(atomic_t),
79356 + .maxlen = sizeof(atomic_unchecked_t),
79357 .mode = 0644,
79358 .proc_handler = read_reset_stat,
79359 },
79360 {
79361 .procname = "rdma_stat_rq_prod",
79362 .data = &rdma_stat_rq_prod,
79363 - .maxlen = sizeof(atomic_t),
79364 + .maxlen = sizeof(atomic_unchecked_t),
79365 .mode = 0644,
79366 .proc_handler = read_reset_stat,
79367 },
79368 {
79369 .procname = "rdma_stat_sq_poll",
79370 .data = &rdma_stat_sq_poll,
79371 - .maxlen = sizeof(atomic_t),
79372 + .maxlen = sizeof(atomic_unchecked_t),
79373 .mode = 0644,
79374 .proc_handler = read_reset_stat,
79375 },
79376 {
79377 .procname = "rdma_stat_sq_prod",
79378 .data = &rdma_stat_sq_prod,
79379 - .maxlen = sizeof(atomic_t),
79380 + .maxlen = sizeof(atomic_unchecked_t),
79381 .mode = 0644,
79382 .proc_handler = read_reset_stat,
79383 },
79384 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79385 index 41cb63b..c4a1489 100644
79386 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79387 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79388 @@ -501,7 +501,7 @@ next_sge:
79389 svc_rdma_put_context(ctxt, 0);
79390 goto out;
79391 }
79392 - atomic_inc(&rdma_stat_read);
79393 + atomic_inc_unchecked(&rdma_stat_read);
79394
79395 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79396 chl_map->ch[ch_no].count -= read_wr.num_sge;
79397 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79398 dto_q);
79399 list_del_init(&ctxt->dto_q);
79400 } else {
79401 - atomic_inc(&rdma_stat_rq_starve);
79402 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79403 clear_bit(XPT_DATA, &xprt->xpt_flags);
79404 ctxt = NULL;
79405 }
79406 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79407 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79408 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79409 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79410 - atomic_inc(&rdma_stat_recv);
79411 + atomic_inc_unchecked(&rdma_stat_recv);
79412
79413 /* Build up the XDR from the receive buffers. */
79414 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79415 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79416 index 42eb7ba..c887c45 100644
79417 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79418 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79419 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79420 write_wr.wr.rdma.remote_addr = to;
79421
79422 /* Post It */
79423 - atomic_inc(&rdma_stat_write);
79424 + atomic_inc_unchecked(&rdma_stat_write);
79425 if (svc_rdma_send(xprt, &write_wr))
79426 goto err;
79427 return 0;
79428 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79429 index 73b428b..5f3f8f3 100644
79430 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79431 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79432 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79433 return;
79434
79435 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79436 - atomic_inc(&rdma_stat_rq_poll);
79437 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79438
79439 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79440 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79441 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79442 }
79443
79444 if (ctxt)
79445 - atomic_inc(&rdma_stat_rq_prod);
79446 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79447
79448 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79449 /*
79450 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79451 return;
79452
79453 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79454 - atomic_inc(&rdma_stat_sq_poll);
79455 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79456 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79457 if (wc.status != IB_WC_SUCCESS)
79458 /* Close the transport */
79459 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79460 }
79461
79462 if (ctxt)
79463 - atomic_inc(&rdma_stat_sq_prod);
79464 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79465 }
79466
79467 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79468 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79469 spin_lock_bh(&xprt->sc_lock);
79470 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79471 spin_unlock_bh(&xprt->sc_lock);
79472 - atomic_inc(&rdma_stat_sq_starve);
79473 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79474
79475 /* See if we can opportunistically reap SQ WR to make room */
79476 sq_cq_reap(xprt);
79477 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79478 index e3a6e37..be2ea77 100644
79479 --- a/net/sysctl_net.c
79480 +++ b/net/sysctl_net.c
79481 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79482 struct ctl_table *table)
79483 {
79484 /* Allow network administrator to have same access as root. */
79485 - if (capable(CAP_NET_ADMIN)) {
79486 + if (capable_nolog(CAP_NET_ADMIN)) {
79487 int mode = (table->mode >> 6) & 7;
79488 return (mode << 6) | (mode << 3) | mode;
79489 }
79490 diff --git a/net/tipc/link.c b/net/tipc/link.c
79491 index 1c1e615..113e0ae 100644
79492 --- a/net/tipc/link.c
79493 +++ b/net/tipc/link.c
79494 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79495 struct tipc_msg fragm_hdr;
79496 struct sk_buff *buf, *buf_chain, *prev;
79497 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79498 - const unchar *sect_crs;
79499 + const unchar __user *sect_crs;
79500 int curr_sect;
79501 u32 fragm_no;
79502
79503 @@ -1212,7 +1212,7 @@ again:
79504
79505 if (!sect_rest) {
79506 sect_rest = msg_sect[++curr_sect].iov_len;
79507 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79508 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79509 }
79510
79511 if (sect_rest < fragm_rest)
79512 @@ -1231,7 +1231,7 @@ error:
79513 }
79514 } else
79515 skb_copy_to_linear_data_offset(buf, fragm_crs,
79516 - sect_crs, sz);
79517 + (const void __force_kernel *)sect_crs, sz);
79518 sect_crs += sz;
79519 sect_rest -= sz;
79520 fragm_crs += sz;
79521 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79522 index f2db8a8..9245aa4 100644
79523 --- a/net/tipc/msg.c
79524 +++ b/net/tipc/msg.c
79525 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79526 msg_sect[cnt].iov_len);
79527 else
79528 skb_copy_to_linear_data_offset(*buf, pos,
79529 - msg_sect[cnt].iov_base,
79530 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79531 msg_sect[cnt].iov_len);
79532 pos += msg_sect[cnt].iov_len;
79533 }
79534 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79535 index 5ed5965..90abe34 100644
79536 --- a/net/tipc/subscr.c
79537 +++ b/net/tipc/subscr.c
79538 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79539 {
79540 struct iovec msg_sect;
79541
79542 - msg_sect.iov_base = (void *)&sub->evt;
79543 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79544 msg_sect.iov_len = sizeof(struct tipc_event);
79545
79546 sub->evt.event = htohl(event, sub->swap);
79547 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79548 index c5ee4ff..e905948 100644
79549 --- a/net/unix/af_unix.c
79550 +++ b/net/unix/af_unix.c
79551 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79552 err = -ECONNREFUSED;
79553 if (!S_ISSOCK(inode->i_mode))
79554 goto put_fail;
79555 +
79556 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79557 + err = -EACCES;
79558 + goto put_fail;
79559 + }
79560 +
79561 u = unix_find_socket_byinode(inode);
79562 if (!u)
79563 goto put_fail;
79564 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79565 if (u) {
79566 struct dentry *dentry;
79567 dentry = unix_sk(u)->path.dentry;
79568 +
79569 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79570 + err = -EPERM;
79571 + sock_put(u);
79572 + goto fail;
79573 + }
79574 +
79575 if (dentry)
79576 touch_atime(&unix_sk(u)->path);
79577 } else
79578 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79579 */
79580 err = security_path_mknod(&path, dentry, mode, 0);
79581 if (!err) {
79582 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79583 + err = -EACCES;
79584 + goto out;
79585 + }
79586 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79587 if (!err) {
79588 res->mnt = mntget(path.mnt);
79589 res->dentry = dget(dentry);
79590 + gr_handle_create(dentry, path.mnt);
79591 }
79592 }
79593 +out:
79594 done_path_create(&path, dentry);
79595 return err;
79596 }
79597 diff --git a/net/wireless/core.h b/net/wireless/core.h
79598 index bc7430b..35349de 100644
79599 --- a/net/wireless/core.h
79600 +++ b/net/wireless/core.h
79601 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79602 struct mutex mtx;
79603
79604 /* rfkill support */
79605 - struct rfkill_ops rfkill_ops;
79606 + rfkill_ops_no_const rfkill_ops;
79607 struct rfkill *rfkill;
79608 struct work_struct rfkill_sync;
79609
79610 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79611 index b0eb7aa..7d73e82 100644
79612 --- a/net/wireless/wext-core.c
79613 +++ b/net/wireless/wext-core.c
79614 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79615 */
79616
79617 /* Support for very large requests */
79618 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79619 - (user_length > descr->max_tokens)) {
79620 + if (user_length > descr->max_tokens) {
79621 /* Allow userspace to GET more than max so
79622 * we can support any size GET requests.
79623 * There is still a limit : -ENOMEM.
79624 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79625 }
79626 }
79627
79628 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79629 - /*
79630 - * If this is a GET, but not NOMAX, it means that the extra
79631 - * data is not bounded by userspace, but by max_tokens. Thus
79632 - * set the length to max_tokens. This matches the extra data
79633 - * allocation.
79634 - * The driver should fill it with the number of tokens it
79635 - * provided, and it may check iwp->length rather than having
79636 - * knowledge of max_tokens. If the driver doesn't change the
79637 - * iwp->length, this ioctl just copies back max_token tokens
79638 - * filled with zeroes. Hopefully the driver isn't claiming
79639 - * them to be valid data.
79640 - */
79641 - iwp->length = descr->max_tokens;
79642 - }
79643 -
79644 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79645
79646 iwp->length += essid_compat;
79647 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79648 index 387848e..a6667a2 100644
79649 --- a/net/xfrm/xfrm_policy.c
79650 +++ b/net/xfrm/xfrm_policy.c
79651 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79652 {
79653 policy->walk.dead = 1;
79654
79655 - atomic_inc(&policy->genid);
79656 + atomic_inc_unchecked(&policy->genid);
79657
79658 if (del_timer(&policy->timer))
79659 xfrm_pol_put(policy);
79660 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79661 hlist_add_head(&policy->bydst, chain);
79662 xfrm_pol_hold(policy);
79663 net->xfrm.policy_count[dir]++;
79664 - atomic_inc(&flow_cache_genid);
79665 + atomic_inc_unchecked(&flow_cache_genid);
79666 rt_genid_bump(net);
79667 if (delpol)
79668 __xfrm_policy_unlink(delpol, dir);
79669 @@ -1533,7 +1533,7 @@ free_dst:
79670 goto out;
79671 }
79672
79673 -static int inline
79674 +static inline int
79675 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79676 {
79677 if (!*target) {
79678 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79679 return 0;
79680 }
79681
79682 -static int inline
79683 +static inline int
79684 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79685 {
79686 #ifdef CONFIG_XFRM_SUB_POLICY
79687 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79688 #endif
79689 }
79690
79691 -static int inline
79692 +static inline int
79693 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79694 {
79695 #ifdef CONFIG_XFRM_SUB_POLICY
79696 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79697
79698 xdst->num_pols = num_pols;
79699 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79700 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79701 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79702
79703 return xdst;
79704 }
79705 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79706 if (xdst->xfrm_genid != dst->xfrm->genid)
79707 return 0;
79708 if (xdst->num_pols > 0 &&
79709 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79710 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79711 return 0;
79712
79713 mtu = dst_mtu(dst->child);
79714 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79715 sizeof(pol->xfrm_vec[i].saddr));
79716 pol->xfrm_vec[i].encap_family = mp->new_family;
79717 /* flush bundles */
79718 - atomic_inc(&pol->genid);
79719 + atomic_inc_unchecked(&pol->genid);
79720 }
79721 }
79722
79723 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79724 index ff1720d..ed8475e 100644
79725 --- a/scripts/Makefile.build
79726 +++ b/scripts/Makefile.build
79727 @@ -111,7 +111,7 @@ endif
79728 endif
79729
79730 # Do not include host rules unless needed
79731 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79732 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
79733 include scripts/Makefile.host
79734 endif
79735
79736 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79737 index 686cb0d..9d653bf 100644
79738 --- a/scripts/Makefile.clean
79739 +++ b/scripts/Makefile.clean
79740 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79741 __clean-files := $(extra-y) $(always) \
79742 $(targets) $(clean-files) \
79743 $(host-progs) \
79744 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79745 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79746 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79747
79748 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79749
79750 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79751 index 1ac414f..38575f7 100644
79752 --- a/scripts/Makefile.host
79753 +++ b/scripts/Makefile.host
79754 @@ -31,6 +31,8 @@
79755 # Note: Shared libraries consisting of C++ files are not supported
79756
79757 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79758 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79759 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
79760
79761 # C code
79762 # Executables compiled from a single .c file
79763 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79764 # Shared libaries (only .c supported)
79765 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79766 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79767 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79768 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
79769 # Remove .so files from "xxx-objs"
79770 host-cobjs := $(filter-out %.so,$(host-cobjs))
79771 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
79772
79773 -#Object (.o) files used by the shared libaries
79774 +# Object (.o) files used by the shared libaries
79775 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
79776 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
79777
79778 # output directory for programs/.o files
79779 # hostprogs-y := tools/build may have been specified. Retrieve directory
79780 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
79781 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
79782 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
79783 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
79784 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
79785 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
79786 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
79787 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
79788
79789 obj-dirs += $(host-objdirs)
79790 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
79791 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
79792 $(call if_changed_dep,host-cshobjs)
79793
79794 +# Compile .c file, create position independent .o file
79795 +# host-cxxshobjs -> .o
79796 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
79797 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
79798 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
79799 + $(call if_changed_dep,host-cxxshobjs)
79800 +
79801 # Link a shared library, based on position independent .o files
79802 # *.o -> .so shared library (host-cshlib)
79803 quiet_cmd_host-cshlib = HOSTLLD -shared $@
79804 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
79805 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
79806 $(call if_changed,host-cshlib)
79807
79808 +# Link a shared library, based on position independent .o files
79809 +# *.o -> .so shared library (host-cxxshlib)
79810 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
79811 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
79812 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
79813 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
79814 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
79815 + $(call if_changed,host-cxxshlib)
79816 +
79817 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
79818 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
79819 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
79820
79821 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79822 index cb1f50c..cef2a7c 100644
79823 --- a/scripts/basic/fixdep.c
79824 +++ b/scripts/basic/fixdep.c
79825 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79826 /*
79827 * Lookup a value in the configuration string.
79828 */
79829 -static int is_defined_config(const char *name, int len, unsigned int hash)
79830 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79831 {
79832 struct item *aux;
79833
79834 @@ -211,10 +211,10 @@ static void clear_config(void)
79835 /*
79836 * Record the use of a CONFIG_* word.
79837 */
79838 -static void use_config(const char *m, int slen)
79839 +static void use_config(const char *m, unsigned int slen)
79840 {
79841 unsigned int hash = strhash(m, slen);
79842 - int c, i;
79843 + unsigned int c, i;
79844
79845 if (is_defined_config(m, slen, hash))
79846 return;
79847 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79848
79849 static void parse_config_file(const char *map, size_t len)
79850 {
79851 - const int *end = (const int *) (map + len);
79852 + const unsigned int *end = (const unsigned int *) (map + len);
79853 /* start at +1, so that p can never be < map */
79854 - const int *m = (const int *) map + 1;
79855 + const unsigned int *m = (const unsigned int *) map + 1;
79856 const char *p, *q;
79857
79858 for (; m < end; m++) {
79859 @@ -406,7 +406,7 @@ static void print_deps(void)
79860 static void traps(void)
79861 {
79862 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79863 - int *p = (int *)test;
79864 + unsigned int *p = (unsigned int *)test;
79865
79866 if (*p != INT_CONF) {
79867 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79868 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79869 new file mode 100644
79870 index 0000000..008ac1a
79871 --- /dev/null
79872 +++ b/scripts/gcc-plugin.sh
79873 @@ -0,0 +1,17 @@
79874 +#!/bin/bash
79875 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
79876 +#include "gcc-plugin.h"
79877 +#include "tree.h"
79878 +#include "tm.h"
79879 +#include "rtl.h"
79880 +#ifdef ENABLE_BUILD_WITH_CXX
79881 +#warning $2
79882 +#else
79883 +#warning $1
79884 +#endif
79885 +EOF`
79886 +if [ $? -eq 0 ]
79887 +then
79888 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
79889 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
79890 +fi
79891 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
79892 index b3d907e..a4782ab 100644
79893 --- a/scripts/link-vmlinux.sh
79894 +++ b/scripts/link-vmlinux.sh
79895 @@ -152,7 +152,7 @@ else
79896 fi;
79897
79898 # final build of init/
79899 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
79900 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
79901
79902 kallsymso=""
79903 kallsyms_vmlinux=""
79904 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79905 index 7ed6864..b6e90e6 100644
79906 --- a/scripts/mod/file2alias.c
79907 +++ b/scripts/mod/file2alias.c
79908 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79909 unsigned long size, unsigned long id_size,
79910 void *symval)
79911 {
79912 - int i;
79913 + unsigned int i;
79914
79915 if (size % id_size || size < id_size) {
79916 if (cross_build != 0)
79917 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79918 /* USB is special because the bcdDevice can be matched against a numeric range */
79919 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
79920 static void do_usb_entry(struct usb_device_id *id,
79921 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79922 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79923 unsigned char range_lo, unsigned char range_hi,
79924 unsigned char max, struct module *mod)
79925 {
79926 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79927 {
79928 unsigned int devlo, devhi;
79929 unsigned char chi, clo, max;
79930 - int ndigits;
79931 + unsigned int ndigits;
79932
79933 id->match_flags = TO_NATIVE(id->match_flags);
79934 id->idVendor = TO_NATIVE(id->idVendor);
79935 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79936 for (i = 0; i < count; i++) {
79937 const char *id = (char *)devs[i].id;
79938 char acpi_id[sizeof(devs[0].id)];
79939 - int j;
79940 + unsigned int j;
79941
79942 buf_printf(&mod->dev_table_buf,
79943 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79944 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79945
79946 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79947 const char *id = (char *)card->devs[j].id;
79948 - int i2, j2;
79949 + unsigned int i2, j2;
79950 int dup = 0;
79951
79952 if (!id[0])
79953 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79954 /* add an individual alias for every device entry */
79955 if (!dup) {
79956 char acpi_id[sizeof(card->devs[0].id)];
79957 - int k;
79958 + unsigned int k;
79959
79960 buf_printf(&mod->dev_table_buf,
79961 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79962 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79963 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79964 char *alias)
79965 {
79966 - int i, j;
79967 + unsigned int i, j;
79968
79969 sprintf(alias, "dmi*");
79970
79971 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79972 index 68e9f5e..ac7759b 100644
79973 --- a/scripts/mod/modpost.c
79974 +++ b/scripts/mod/modpost.c
79975 @@ -930,6 +930,7 @@ enum mismatch {
79976 ANY_INIT_TO_ANY_EXIT,
79977 ANY_EXIT_TO_ANY_INIT,
79978 EXPORT_TO_INIT_EXIT,
79979 + DATA_TO_TEXT
79980 };
79981
79982 struct sectioncheck {
79983 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
79984 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79985 .mismatch = EXPORT_TO_INIT_EXIT,
79986 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79987 +},
79988 +/* Do not reference code from writable data */
79989 +{
79990 + .fromsec = { DATA_SECTIONS, NULL },
79991 + .tosec = { TEXT_SECTIONS, NULL },
79992 + .mismatch = DATA_TO_TEXT
79993 }
79994 };
79995
79996 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
79997 continue;
79998 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79999 continue;
80000 - if (sym->st_value == addr)
80001 - return sym;
80002 /* Find a symbol nearby - addr are maybe negative */
80003 d = sym->st_value - addr;
80004 + if (d == 0)
80005 + return sym;
80006 if (d < 0)
80007 d = addr - sym->st_value;
80008 if (d < distance) {
80009 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80010 tosym, prl_to, prl_to, tosym);
80011 free(prl_to);
80012 break;
80013 + case DATA_TO_TEXT:
80014 +#if 0
80015 + fprintf(stderr,
80016 + "The %s %s:%s references\n"
80017 + "the %s %s:%s%s\n",
80018 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80019 +#endif
80020 + break;
80021 }
80022 fprintf(stderr, "\n");
80023 }
80024 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80025 static void check_sec_ref(struct module *mod, const char *modname,
80026 struct elf_info *elf)
80027 {
80028 - int i;
80029 + unsigned int i;
80030 Elf_Shdr *sechdrs = elf->sechdrs;
80031
80032 /* Walk through all sections */
80033 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80034 va_end(ap);
80035 }
80036
80037 -void buf_write(struct buffer *buf, const char *s, int len)
80038 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80039 {
80040 if (buf->size - buf->pos < len) {
80041 buf->size += len + SZ;
80042 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80043 if (fstat(fileno(file), &st) < 0)
80044 goto close_write;
80045
80046 - if (st.st_size != b->pos)
80047 + if (st.st_size != (off_t)b->pos)
80048 goto close_write;
80049
80050 tmp = NOFAIL(malloc(b->pos));
80051 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80052 index 51207e4..f7d603d 100644
80053 --- a/scripts/mod/modpost.h
80054 +++ b/scripts/mod/modpost.h
80055 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80056
80057 struct buffer {
80058 char *p;
80059 - int pos;
80060 - int size;
80061 + unsigned int pos;
80062 + unsigned int size;
80063 };
80064
80065 void __attribute__((format(printf, 2, 3)))
80066 buf_printf(struct buffer *buf, const char *fmt, ...);
80067
80068 void
80069 -buf_write(struct buffer *buf, const char *s, int len);
80070 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80071
80072 struct module {
80073 struct module *next;
80074 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80075 index 9dfcd6d..099068e 100644
80076 --- a/scripts/mod/sumversion.c
80077 +++ b/scripts/mod/sumversion.c
80078 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80079 goto out;
80080 }
80081
80082 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80083 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80084 warn("writing sum in %s failed: %s\n",
80085 filename, strerror(errno));
80086 goto out;
80087 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80088 index 5c11312..72742b5 100644
80089 --- a/scripts/pnmtologo.c
80090 +++ b/scripts/pnmtologo.c
80091 @@ -237,14 +237,14 @@ static void write_header(void)
80092 fprintf(out, " * Linux logo %s\n", logoname);
80093 fputs(" */\n\n", out);
80094 fputs("#include <linux/linux_logo.h>\n\n", out);
80095 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80096 + fprintf(out, "static unsigned char %s_data[] = {\n",
80097 logoname);
80098 }
80099
80100 static void write_footer(void)
80101 {
80102 fputs("\n};\n\n", out);
80103 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80104 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80105 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80106 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80107 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80108 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80109 fputs("\n};\n\n", out);
80110
80111 /* write logo clut */
80112 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80113 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80114 logoname);
80115 write_hex_cnt = 0;
80116 for (i = 0; i < logo_clutsize; i++) {
80117 diff --git a/security/Kconfig b/security/Kconfig
80118 index e9c6ac7..e7feb0d 100644
80119 --- a/security/Kconfig
80120 +++ b/security/Kconfig
80121 @@ -4,6 +4,896 @@
80122
80123 menu "Security options"
80124
80125 +menu "Grsecurity"
80126 +
80127 + config ARCH_TRACK_EXEC_LIMIT
80128 + bool
80129 +
80130 + config PAX_KERNEXEC_PLUGIN
80131 + bool
80132 +
80133 + config PAX_PER_CPU_PGD
80134 + bool
80135 +
80136 + config TASK_SIZE_MAX_SHIFT
80137 + int
80138 + depends on X86_64
80139 + default 47 if !PAX_PER_CPU_PGD
80140 + default 42 if PAX_PER_CPU_PGD
80141 +
80142 + config PAX_ENABLE_PAE
80143 + bool
80144 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80145 +
80146 + config PAX_USERCOPY_SLABS
80147 + bool
80148 +
80149 +config GRKERNSEC
80150 + bool "Grsecurity"
80151 + select CRYPTO
80152 + select CRYPTO_SHA256
80153 + select PROC_FS
80154 + select STOP_MACHINE
80155 + help
80156 + If you say Y here, you will be able to configure many features
80157 + that will enhance the security of your system. It is highly
80158 + recommended that you say Y here and read through the help
80159 + for each option so that you fully understand the features and
80160 + can evaluate their usefulness for your machine.
80161 +
80162 +choice
80163 + prompt "Configuration Method"
80164 + depends on GRKERNSEC
80165 + default GRKERNSEC_CONFIG_CUSTOM
80166 + help
80167 +
80168 +config GRKERNSEC_CONFIG_AUTO
80169 + bool "Automatic"
80170 + help
80171 + If you choose this configuration method, you'll be able to answer a small
80172 + number of simple questions about how you plan to use this kernel.
80173 + The settings of grsecurity and PaX will be automatically configured for
80174 + the highest commonly-used settings within the provided constraints.
80175 +
80176 + If you require additional configuration, custom changes can still be made
80177 + from the "custom configuration" menu.
80178 +
80179 +config GRKERNSEC_CONFIG_CUSTOM
80180 + bool "Custom"
80181 + help
80182 + If you choose this configuration method, you'll be able to configure all
80183 + grsecurity and PaX settings manually. Via this method, no options are
80184 + automatically enabled.
80185 +
80186 +endchoice
80187 +
80188 +choice
80189 + prompt "Usage Type"
80190 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80191 + default GRKERNSEC_CONFIG_SERVER
80192 + help
80193 +
80194 +config GRKERNSEC_CONFIG_SERVER
80195 + bool "Server"
80196 + help
80197 + Choose this option if you plan to use this kernel on a server.
80198 +
80199 +config GRKERNSEC_CONFIG_DESKTOP
80200 + bool "Desktop"
80201 + help
80202 + Choose this option if you plan to use this kernel on a desktop.
80203 +
80204 +endchoice
80205 +
80206 +choice
80207 + prompt "Virtualization Type"
80208 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80209 + default GRKERNSEC_CONFIG_VIRT_NONE
80210 + help
80211 +
80212 +config GRKERNSEC_CONFIG_VIRT_NONE
80213 + bool "None"
80214 + help
80215 + Choose this option if this kernel will be run on bare metal.
80216 +
80217 +config GRKERNSEC_CONFIG_VIRT_GUEST
80218 + bool "Guest"
80219 + help
80220 + Choose this option if this kernel will be run as a VM guest.
80221 +
80222 +config GRKERNSEC_CONFIG_VIRT_HOST
80223 + bool "Host"
80224 + help
80225 + Choose this option if this kernel will be run as a VM host.
80226 +
80227 +endchoice
80228 +
80229 +choice
80230 + prompt "Virtualization Hardware"
80231 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80232 + help
80233 +
80234 +config GRKERNSEC_CONFIG_VIRT_EPT
80235 + bool "EPT/RVI Processor Support"
80236 + depends on X86
80237 + help
80238 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80239 + hardware virtualization. This allows for additional kernel hardening protections
80240 + to operate without additional performance impact.
80241 +
80242 + To see if your Intel processor supports EPT, see:
80243 + http://ark.intel.com/Products/VirtualizationTechnology
80244 + (Most Core i3/5/7 support EPT)
80245 +
80246 + To see if your AMD processor supports RVI, see:
80247 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80248 +
80249 +config GRKERNSEC_CONFIG_VIRT_SOFT
80250 + bool "First-gen/No Hardware Virtualization"
80251 + help
80252 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80253 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80254 +
80255 +endchoice
80256 +
80257 +choice
80258 + prompt "Virtualization Software"
80259 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80260 + help
80261 +
80262 +config GRKERNSEC_CONFIG_VIRT_XEN
80263 + bool "Xen"
80264 + help
80265 + Choose this option if this kernel is running as a Xen guest or host.
80266 +
80267 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80268 + bool "VMWare"
80269 + help
80270 + Choose this option if this kernel is running as a VMWare guest or host.
80271 +
80272 +config GRKERNSEC_CONFIG_VIRT_KVM
80273 + bool "KVM"
80274 + help
80275 + Choose this option if this kernel is running as a KVM guest or host.
80276 +
80277 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80278 + bool "VirtualBox"
80279 + help
80280 + Choose this option if this kernel is running as a VirtualBox guest or host.
80281 +
80282 +endchoice
80283 +
80284 +choice
80285 + prompt "Required Priorities"
80286 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80287 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80288 + help
80289 +
80290 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80291 + bool "Performance"
80292 + help
80293 + Choose this option if performance is of highest priority for this deployment
80294 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80295 + and freed memory sanitizing will be disabled.
80296 +
80297 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80298 + bool "Security"
80299 + help
80300 + Choose this option if security is of highest priority for this deployment of
80301 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80302 + be enabled for this kernel. In a worst-case scenario, these features can
80303 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80304 +
80305 +endchoice
80306 +
80307 +menu "Default Special Groups"
80308 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80309 +
80310 +config GRKERNSEC_PROC_GID
80311 + int "GID exempted from /proc restrictions"
80312 + default 1001
80313 + help
80314 + Setting this GID determines which group will be exempted from
80315 + grsecurity's /proc restrictions, allowing users of the specified
80316 + group to view network statistics and the existence of other users'
80317 + processes on the system. This GID may also be chosen at boot time
80318 + via "grsec_proc_gid=" on the kernel commandline.
80319 +
80320 +config GRKERNSEC_TPE_UNTRUSTED_GID
80321 + int "GID for TPE-untrusted users"
80322 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80323 + default 1005
80324 + help
80325 + Setting this GID determines which group untrusted users should
80326 + be added to. These users will be placed under grsecurity's Trusted Path
80327 + Execution mechanism, preventing them from executing their own binaries.
80328 + The users will only be able to execute binaries in directories owned and
80329 + writable only by the root user. If the sysctl option is enabled, a sysctl
80330 + option with name "tpe_gid" is created.
80331 +
80332 +config GRKERNSEC_TPE_TRUSTED_GID
80333 + int "GID for TPE-trusted users"
80334 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80335 + default 1005
80336 + help
80337 + Setting this GID determines what group TPE restrictions will be
80338 + *disabled* for. If the sysctl option is enabled, a sysctl option
80339 + with name "tpe_gid" is created.
80340 +
80341 +config GRKERNSEC_SYMLINKOWN_GID
80342 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80343 + depends on GRKERNSEC_CONFIG_SERVER
80344 + default 1006
80345 + help
80346 + Setting this GID determines what group kernel-enforced
80347 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80348 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80349 +
80350 +
80351 +endmenu
80352 +
80353 +menu "Customize Configuration"
80354 +depends on GRKERNSEC
80355 +
80356 +menu "PaX"
80357 +
80358 +config PAX
80359 + bool "Enable various PaX features"
80360 + default y if GRKERNSEC_CONFIG_AUTO
80361 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80362 + help
80363 + This allows you to enable various PaX features. PaX adds
80364 + intrusion prevention mechanisms to the kernel that reduce
80365 + the risks posed by exploitable memory corruption bugs.
80366 +
80367 +menu "PaX Control"
80368 + depends on PAX
80369 +
80370 +config PAX_SOFTMODE
80371 + bool 'Support soft mode'
80372 + help
80373 + Enabling this option will allow you to run PaX in soft mode, that
80374 + is, PaX features will not be enforced by default, only on executables
80375 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80376 + support as they are the only way to mark executables for soft mode use.
80377 +
80378 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80379 + line option on boot. Furthermore you can control various PaX features
80380 + at runtime via the entries in /proc/sys/kernel/pax.
80381 +
80382 +config PAX_EI_PAX
80383 + bool 'Use legacy ELF header marking'
80384 + default y if GRKERNSEC_CONFIG_AUTO
80385 + help
80386 + Enabling this option will allow you to control PaX features on
80387 + a per executable basis via the 'chpax' utility available at
80388 + http://pax.grsecurity.net/. The control flags will be read from
80389 + an otherwise reserved part of the ELF header. This marking has
80390 + numerous drawbacks (no support for soft-mode, toolchain does not
80391 + know about the non-standard use of the ELF header) therefore it
80392 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80393 + support.
80394 +
80395 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80396 + support as well, they will override the legacy EI_PAX marks.
80397 +
80398 + If you enable none of the marking options then all applications
80399 + will run with PaX enabled on them by default.
80400 +
80401 +config PAX_PT_PAX_FLAGS
80402 + bool 'Use ELF program header marking'
80403 + default y if GRKERNSEC_CONFIG_AUTO
80404 + help
80405 + Enabling this option will allow you to control PaX features on
80406 + a per executable basis via the 'paxctl' utility available at
80407 + http://pax.grsecurity.net/. The control flags will be read from
80408 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80409 + has the benefits of supporting both soft mode and being fully
80410 + integrated into the toolchain (the binutils patch is available
80411 + from http://pax.grsecurity.net).
80412 +
80413 + Note that if you enable the legacy EI_PAX marking support as well,
80414 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80415 +
80416 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80417 + must make sure that the marks are the same if a binary has both marks.
80418 +
80419 + If you enable none of the marking options then all applications
80420 + will run with PaX enabled on them by default.
80421 +
80422 +config PAX_XATTR_PAX_FLAGS
80423 + bool 'Use filesystem extended attributes marking'
80424 + default y if GRKERNSEC_CONFIG_AUTO
80425 + select CIFS_XATTR if CIFS
80426 + select EXT2_FS_XATTR if EXT2_FS
80427 + select EXT3_FS_XATTR if EXT3_FS
80428 + select EXT4_FS_XATTR if EXT4_FS
80429 + select JFFS2_FS_XATTR if JFFS2_FS
80430 + select REISERFS_FS_XATTR if REISERFS_FS
80431 + select SQUASHFS_XATTR if SQUASHFS
80432 + select TMPFS_XATTR if TMPFS
80433 + select UBIFS_FS_XATTR if UBIFS_FS
80434 + help
80435 + Enabling this option will allow you to control PaX features on
80436 + a per executable basis via the 'setfattr' utility. The control
80437 + flags will be read from the user.pax.flags extended attribute of
80438 + the file. This marking has the benefit of supporting binary-only
80439 + applications that self-check themselves (e.g., skype) and would
80440 + not tolerate chpax/paxctl changes. The main drawback is that
80441 + extended attributes are not supported by some filesystems (e.g.,
80442 + isofs, udf, vfat) so copying files through such filesystems will
80443 + lose the extended attributes and these PaX markings.
80444 +
80445 + Note that if you enable the legacy EI_PAX marking support as well,
80446 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80447 +
80448 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80449 + must make sure that the marks are the same if a binary has both marks.
80450 +
80451 + If you enable none of the marking options then all applications
80452 + will run with PaX enabled on them by default.
80453 +
80454 +choice
80455 + prompt 'MAC system integration'
80456 + default PAX_HAVE_ACL_FLAGS
80457 + help
80458 + Mandatory Access Control systems have the option of controlling
80459 + PaX flags on a per executable basis, choose the method supported
80460 + by your particular system.
80461 +
80462 + - "none": if your MAC system does not interact with PaX,
80463 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80464 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80465 +
80466 + NOTE: this option is for developers/integrators only.
80467 +
80468 + config PAX_NO_ACL_FLAGS
80469 + bool 'none'
80470 +
80471 + config PAX_HAVE_ACL_FLAGS
80472 + bool 'direct'
80473 +
80474 + config PAX_HOOK_ACL_FLAGS
80475 + bool 'hook'
80476 +endchoice
80477 +
80478 +endmenu
80479 +
80480 +menu "Non-executable pages"
80481 + depends on PAX
80482 +
80483 +config PAX_NOEXEC
80484 + bool "Enforce non-executable pages"
80485 + default y if GRKERNSEC_CONFIG_AUTO
80486 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80487 + help
80488 + By design some architectures do not allow for protecting memory
80489 + pages against execution or even if they do, Linux does not make
80490 + use of this feature. In practice this means that if a page is
80491 + readable (such as the stack or heap) it is also executable.
80492 +
80493 + There is a well known exploit technique that makes use of this
80494 + fact and a common programming mistake where an attacker can
80495 + introduce code of his choice somewhere in the attacked program's
80496 + memory (typically the stack or the heap) and then execute it.
80497 +
80498 + If the attacked program was running with different (typically
80499 + higher) privileges than that of the attacker, then he can elevate
80500 + his own privilege level (e.g. get a root shell, write to files for
80501 + which he does not have write access to, etc).
80502 +
80503 + Enabling this option will let you choose from various features
80504 + that prevent the injection and execution of 'foreign' code in
80505 + a program.
80506 +
80507 + This will also break programs that rely on the old behaviour and
80508 + expect that dynamically allocated memory via the malloc() family
80509 + of functions is executable (which it is not). Notable examples
80510 + are the XFree86 4.x server, the java runtime and wine.
80511 +
80512 +config PAX_PAGEEXEC
80513 + bool "Paging based non-executable pages"
80514 + default y if GRKERNSEC_CONFIG_AUTO
80515 + 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)
80516 + select S390_SWITCH_AMODE if S390
80517 + select S390_EXEC_PROTECT if S390
80518 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80519 + help
80520 + This implementation is based on the paging feature of the CPU.
80521 + On i386 without hardware non-executable bit support there is a
80522 + variable but usually low performance impact, however on Intel's
80523 + P4 core based CPUs it is very high so you should not enable this
80524 + for kernels meant to be used on such CPUs.
80525 +
80526 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80527 + with hardware non-executable bit support there is no performance
80528 + impact, on ppc the impact is negligible.
80529 +
80530 + Note that several architectures require various emulations due to
80531 + badly designed userland ABIs, this will cause a performance impact
80532 + but will disappear as soon as userland is fixed. For example, ppc
80533 + userland MUST have been built with secure-plt by a recent toolchain.
80534 +
80535 +config PAX_SEGMEXEC
80536 + bool "Segmentation based non-executable pages"
80537 + default y if GRKERNSEC_CONFIG_AUTO
80538 + depends on PAX_NOEXEC && X86_32
80539 + help
80540 + This implementation is based on the segmentation feature of the
80541 + CPU and has a very small performance impact, however applications
80542 + will be limited to a 1.5 GB address space instead of the normal
80543 + 3 GB.
80544 +
80545 +config PAX_EMUTRAMP
80546 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80547 + default y if PARISC
80548 + help
80549 + There are some programs and libraries that for one reason or
80550 + another attempt to execute special small code snippets from
80551 + non-executable memory pages. Most notable examples are the
80552 + signal handler return code generated by the kernel itself and
80553 + the GCC trampolines.
80554 +
80555 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80556 + such programs will no longer work under your kernel.
80557 +
80558 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80559 + utilities to enable trampoline emulation for the affected programs
80560 + yet still have the protection provided by the non-executable pages.
80561 +
80562 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80563 + your system will not even boot.
80564 +
80565 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80566 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80567 + for the affected files.
80568 +
80569 + NOTE: enabling this feature *may* open up a loophole in the
80570 + protection provided by non-executable pages that an attacker
80571 + could abuse. Therefore the best solution is to not have any
80572 + files on your system that would require this option. This can
80573 + be achieved by not using libc5 (which relies on the kernel
80574 + signal handler return code) and not using or rewriting programs
80575 + that make use of the nested function implementation of GCC.
80576 + Skilled users can just fix GCC itself so that it implements
80577 + nested function calls in a way that does not interfere with PaX.
80578 +
80579 +config PAX_EMUSIGRT
80580 + bool "Automatically emulate sigreturn trampolines"
80581 + depends on PAX_EMUTRAMP && PARISC
80582 + default y
80583 + help
80584 + Enabling this option will have the kernel automatically detect
80585 + and emulate signal return trampolines executing on the stack
80586 + that would otherwise lead to task termination.
80587 +
80588 + This solution is intended as a temporary one for users with
80589 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80590 + Modula-3 runtime, etc) or executables linked to such, basically
80591 + everything that does not specify its own SA_RESTORER function in
80592 + normal executable memory like glibc 2.1+ does.
80593 +
80594 + On parisc you MUST enable this option, otherwise your system will
80595 + not even boot.
80596 +
80597 + NOTE: this feature cannot be disabled on a per executable basis
80598 + and since it *does* open up a loophole in the protection provided
80599 + by non-executable pages, the best solution is to not have any
80600 + files on your system that would require this option.
80601 +
80602 +config PAX_MPROTECT
80603 + bool "Restrict mprotect()"
80604 + default y if GRKERNSEC_CONFIG_AUTO
80605 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80606 + help
80607 + Enabling this option will prevent programs from
80608 + - changing the executable status of memory pages that were
80609 + not originally created as executable,
80610 + - making read-only executable pages writable again,
80611 + - creating executable pages from anonymous memory,
80612 + - making read-only-after-relocations (RELRO) data pages writable again.
80613 +
80614 + You should say Y here to complete the protection provided by
80615 + the enforcement of non-executable pages.
80616 +
80617 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80618 + this feature on a per file basis.
80619 +
80620 +config PAX_MPROTECT_COMPAT
80621 + bool "Use legacy/compat protection demoting (read help)"
80622 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80623 + depends on PAX_MPROTECT
80624 + help
80625 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80626 + by sending the proper error code to the application. For some broken
80627 + userland, this can cause problems with Python or other applications. The
80628 + current implementation however allows for applications like clamav to
80629 + detect if JIT compilation/execution is allowed and to fall back gracefully
80630 + to an interpreter-based mode if it does not. While we encourage everyone
80631 + to use the current implementation as-is and push upstream to fix broken
80632 + userland (note that the RWX logging option can assist with this), in some
80633 + environments this may not be possible. Having to disable MPROTECT
80634 + completely on certain binaries reduces the security benefit of PaX,
80635 + so this option is provided for those environments to revert to the old
80636 + behavior.
80637 +
80638 +config PAX_ELFRELOCS
80639 + bool "Allow ELF text relocations (read help)"
80640 + depends on PAX_MPROTECT
80641 + default n
80642 + help
80643 + Non-executable pages and mprotect() restrictions are effective
80644 + in preventing the introduction of new executable code into an
80645 + attacked task's address space. There remain only two venues
80646 + for this kind of attack: if the attacker can execute already
80647 + existing code in the attacked task then he can either have it
80648 + create and mmap() a file containing his code or have it mmap()
80649 + an already existing ELF library that does not have position
80650 + independent code in it and use mprotect() on it to make it
80651 + writable and copy his code there. While protecting against
80652 + the former approach is beyond PaX, the latter can be prevented
80653 + by having only PIC ELF libraries on one's system (which do not
80654 + need to relocate their code). If you are sure this is your case,
80655 + as is the case with all modern Linux distributions, then leave
80656 + this option disabled. You should say 'n' here.
80657 +
80658 +config PAX_ETEXECRELOCS
80659 + bool "Allow ELF ET_EXEC text relocations"
80660 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80661 + select PAX_ELFRELOCS
80662 + default y
80663 + help
80664 + On some architectures there are incorrectly created applications
80665 + that require text relocations and would not work without enabling
80666 + this option. If you are an alpha, ia64 or parisc user, you should
80667 + enable this option and disable it once you have made sure that
80668 + none of your applications need it.
80669 +
80670 +config PAX_EMUPLT
80671 + bool "Automatically emulate ELF PLT"
80672 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80673 + default y
80674 + help
80675 + Enabling this option will have the kernel automatically detect
80676 + and emulate the Procedure Linkage Table entries in ELF files.
80677 + On some architectures such entries are in writable memory, and
80678 + become non-executable leading to task termination. Therefore
80679 + it is mandatory that you enable this option on alpha, parisc,
80680 + sparc and sparc64, otherwise your system would not even boot.
80681 +
80682 + NOTE: this feature *does* open up a loophole in the protection
80683 + provided by the non-executable pages, therefore the proper
80684 + solution is to modify the toolchain to produce a PLT that does
80685 + not need to be writable.
80686 +
80687 +config PAX_DLRESOLVE
80688 + bool 'Emulate old glibc resolver stub'
80689 + depends on PAX_EMUPLT && SPARC
80690 + default n
80691 + help
80692 + This option is needed if userland has an old glibc (before 2.4)
80693 + that puts a 'save' instruction into the runtime generated resolver
80694 + stub that needs special emulation.
80695 +
80696 +config PAX_KERNEXEC
80697 + bool "Enforce non-executable kernel pages"
80698 + 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))
80699 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80700 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80701 + select PAX_KERNEXEC_PLUGIN if X86_64
80702 + help
80703 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80704 + that is, enabling this option will make it harder to inject
80705 + and execute 'foreign' code in kernel memory itself.
80706 +
80707 +choice
80708 + prompt "Return Address Instrumentation Method"
80709 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80710 + depends on PAX_KERNEXEC_PLUGIN
80711 + help
80712 + Select the method used to instrument function pointer dereferences.
80713 + Note that binary modules cannot be instrumented by this approach.
80714 +
80715 + Note that the implementation requires a gcc with plugin support,
80716 + i.e., gcc 4.5 or newer. You may need to install the supporting
80717 + headers explicitly in addition to the normal gcc package.
80718 +
80719 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80720 + bool "bts"
80721 + help
80722 + This method is compatible with binary only modules but has
80723 + a higher runtime overhead.
80724 +
80725 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80726 + bool "or"
80727 + depends on !PARAVIRT
80728 + help
80729 + This method is incompatible with binary only modules but has
80730 + a lower runtime overhead.
80731 +endchoice
80732 +
80733 +config PAX_KERNEXEC_PLUGIN_METHOD
80734 + string
80735 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80736 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80737 + default ""
80738 +
80739 +config PAX_KERNEXEC_MODULE_TEXT
80740 + int "Minimum amount of memory reserved for module code"
80741 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
80742 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80743 + depends on PAX_KERNEXEC && X86_32 && MODULES
80744 + help
80745 + Due to implementation details the kernel must reserve a fixed
80746 + amount of memory for module code at compile time that cannot be
80747 + changed at runtime. Here you can specify the minimum amount
80748 + in MB that will be reserved. Due to the same implementation
80749 + details this size will always be rounded up to the next 2/4 MB
80750 + boundary (depends on PAE) so the actually available memory for
80751 + module code will usually be more than this minimum.
80752 +
80753 + The default 4 MB should be enough for most users but if you have
80754 + an excessive number of modules (e.g., most distribution configs
80755 + compile many drivers as modules) or use huge modules such as
80756 + nvidia's kernel driver, you will need to adjust this amount.
80757 + A good rule of thumb is to look at your currently loaded kernel
80758 + modules and add up their sizes.
80759 +
80760 +endmenu
80761 +
80762 +menu "Address Space Layout Randomization"
80763 + depends on PAX
80764 +
80765 +config PAX_ASLR
80766 + bool "Address Space Layout Randomization"
80767 + default y if GRKERNSEC_CONFIG_AUTO
80768 + help
80769 + Many if not most exploit techniques rely on the knowledge of
80770 + certain addresses in the attacked program. The following options
80771 + will allow the kernel to apply a certain amount of randomization
80772 + to specific parts of the program thereby forcing an attacker to
80773 + guess them in most cases. Any failed guess will most likely crash
80774 + the attacked program which allows the kernel to detect such attempts
80775 + and react on them. PaX itself provides no reaction mechanisms,
80776 + instead it is strongly encouraged that you make use of Nergal's
80777 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80778 + (http://www.grsecurity.net/) built-in crash detection features or
80779 + develop one yourself.
80780 +
80781 + By saying Y here you can choose to randomize the following areas:
80782 + - top of the task's kernel stack
80783 + - top of the task's userland stack
80784 + - base address for mmap() requests that do not specify one
80785 + (this includes all libraries)
80786 + - base address of the main executable
80787 +
80788 + It is strongly recommended to say Y here as address space layout
80789 + randomization has negligible impact on performance yet it provides
80790 + a very effective protection.
80791 +
80792 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80793 + this feature on a per file basis.
80794 +
80795 +config PAX_RANDKSTACK
80796 + bool "Randomize kernel stack base"
80797 + default y if GRKERNSEC_CONFIG_AUTO
80798 + depends on X86_TSC && X86
80799 + help
80800 + By saying Y here the kernel will randomize every task's kernel
80801 + stack on every system call. This will not only force an attacker
80802 + to guess it but also prevent him from making use of possible
80803 + leaked information about it.
80804 +
80805 + Since the kernel stack is a rather scarce resource, randomization
80806 + may cause unexpected stack overflows, therefore you should very
80807 + carefully test your system. Note that once enabled in the kernel
80808 + configuration, this feature cannot be disabled on a per file basis.
80809 +
80810 +config PAX_RANDUSTACK
80811 + bool "Randomize user stack base"
80812 + default y if GRKERNSEC_CONFIG_AUTO
80813 + depends on PAX_ASLR
80814 + help
80815 + By saying Y here the kernel will randomize every task's userland
80816 + stack. The randomization is done in two steps where the second
80817 + one may apply a big amount of shift to the top of the stack and
80818 + cause problems for programs that want to use lots of memory (more
80819 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80820 + For this reason the second step can be controlled by 'chpax' or
80821 + 'paxctl' on a per file basis.
80822 +
80823 +config PAX_RANDMMAP
80824 + bool "Randomize mmap() base"
80825 + default y if GRKERNSEC_CONFIG_AUTO
80826 + depends on PAX_ASLR
80827 + help
80828 + By saying Y here the kernel will use a randomized base address for
80829 + mmap() requests that do not specify one themselves. As a result
80830 + all dynamically loaded libraries will appear at random addresses
80831 + and therefore be harder to exploit by a technique where an attacker
80832 + attempts to execute library code for his purposes (e.g. spawn a
80833 + shell from an exploited program that is running at an elevated
80834 + privilege level).
80835 +
80836 + Furthermore, if a program is relinked as a dynamic ELF file, its
80837 + base address will be randomized as well, completing the full
80838 + randomization of the address space layout. Attacking such programs
80839 + becomes a guess game. You can find an example of doing this at
80840 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80841 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80842 +
80843 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80844 + feature on a per file basis.
80845 +
80846 +endmenu
80847 +
80848 +menu "Miscellaneous hardening features"
80849 +
80850 +config PAX_MEMORY_SANITIZE
80851 + bool "Sanitize all freed memory"
80852 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80853 + depends on !HIBERNATION
80854 + help
80855 + By saying Y here the kernel will erase memory pages as soon as they
80856 + are freed. This in turn reduces the lifetime of data stored in the
80857 + pages, making it less likely that sensitive information such as
80858 + passwords, cryptographic secrets, etc stay in memory for too long.
80859 +
80860 + This is especially useful for programs whose runtime is short, long
80861 + lived processes and the kernel itself benefit from this as long as
80862 + they operate on whole memory pages and ensure timely freeing of pages
80863 + that may hold sensitive information.
80864 +
80865 + The tradeoff is performance impact, on a single CPU system kernel
80866 + compilation sees a 3% slowdown, other systems and workloads may vary
80867 + and you are advised to test this feature on your expected workload
80868 + before deploying it.
80869 +
80870 + Note that this feature does not protect data stored in live pages,
80871 + e.g., process memory swapped to disk may stay there for a long time.
80872 +
80873 +config PAX_MEMORY_STACKLEAK
80874 + bool "Sanitize kernel stack"
80875 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80876 + depends on X86
80877 + help
80878 + By saying Y here the kernel will erase the kernel stack before it
80879 + returns from a system call. This in turn reduces the information
80880 + that a kernel stack leak bug can reveal.
80881 +
80882 + Note that such a bug can still leak information that was put on
80883 + the stack by the current system call (the one eventually triggering
80884 + the bug) but traces of earlier system calls on the kernel stack
80885 + cannot leak anymore.
80886 +
80887 + The tradeoff is performance impact: on a single CPU system kernel
80888 + compilation sees a 1% slowdown, other systems and workloads may vary
80889 + and you are advised to test this feature on your expected workload
80890 + before deploying it.
80891 +
80892 + Note that the full feature requires a gcc with plugin support,
80893 + i.e., gcc 4.5 or newer. You may need to install the supporting
80894 + headers explicitly in addition to the normal gcc package. Using
80895 + older gcc versions means that functions with large enough stack
80896 + frames may leave uninitialized memory behind that may be exposed
80897 + to a later syscall leaking the stack.
80898 +
80899 +config PAX_MEMORY_UDEREF
80900 + bool "Prevent invalid userland pointer dereference"
80901 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
80902 + depends on X86 && !UML_X86 && !XEN
80903 + select PAX_PER_CPU_PGD if X86_64
80904 + help
80905 + By saying Y here the kernel will be prevented from dereferencing
80906 + userland pointers in contexts where the kernel expects only kernel
80907 + pointers. This is both a useful runtime debugging feature and a
80908 + security measure that prevents exploiting a class of kernel bugs.
80909 +
80910 + The tradeoff is that some virtualization solutions may experience
80911 + a huge slowdown and therefore you should not enable this feature
80912 + for kernels meant to run in such environments. Whether a given VM
80913 + solution is affected or not is best determined by simply trying it
80914 + out, the performance impact will be obvious right on boot as this
80915 + mechanism engages from very early on. A good rule of thumb is that
80916 + VMs running on CPUs without hardware virtualization support (i.e.,
80917 + the majority of IA-32 CPUs) will likely experience the slowdown.
80918 +
80919 +config PAX_REFCOUNT
80920 + bool "Prevent various kernel object reference counter overflows"
80921 + default y if GRKERNSEC_CONFIG_AUTO
80922 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80923 + help
80924 + By saying Y here the kernel will detect and prevent overflowing
80925 + various (but not all) kinds of object reference counters. Such
80926 + overflows can normally occur due to bugs only and are often, if
80927 + not always, exploitable.
80928 +
80929 + The tradeoff is that data structures protected by an overflowed
80930 + refcount will never be freed and therefore will leak memory. Note
80931 + that this leak also happens even without this protection but in
80932 + that case the overflow can eventually trigger the freeing of the
80933 + data structure while it is still being used elsewhere, resulting
80934 + in the exploitable situation that this feature prevents.
80935 +
80936 + Since this has a negligible performance impact, you should enable
80937 + this feature.
80938 +
80939 +config PAX_USERCOPY
80940 + bool "Harden heap object copies between kernel and userland"
80941 + default y if GRKERNSEC_CONFIG_AUTO
80942 + depends on X86 || PPC || SPARC || ARM
80943 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80944 + select PAX_USERCOPY_SLABS
80945 + help
80946 + By saying Y here the kernel will enforce the size of heap objects
80947 + when they are copied in either direction between the kernel and
80948 + userland, even if only a part of the heap object is copied.
80949 +
80950 + Specifically, this checking prevents information leaking from the
80951 + kernel heap during kernel to userland copies (if the kernel heap
80952 + object is otherwise fully initialized) and prevents kernel heap
80953 + overflows during userland to kernel copies.
80954 +
80955 + Note that the current implementation provides the strictest bounds
80956 + checks for the SLUB allocator.
80957 +
80958 + Enabling this option also enables per-slab cache protection against
80959 + data in a given cache being copied into/out of via userland
80960 + accessors. Though the whitelist of regions will be reduced over
80961 + time, it notably protects important data structures like task structs.
80962 +
80963 + If frame pointers are enabled on x86, this option will also restrict
80964 + copies into and out of the kernel stack to local variables within a
80965 + single frame.
80966 +
80967 + Since this has a negligible performance impact, you should enable
80968 + this feature.
80969 +
80970 +config PAX_SIZE_OVERFLOW
80971 + bool "Prevent various integer overflows in function size parameters"
80972 + default y if GRKERNSEC_CONFIG_AUTO
80973 + depends on X86
80974 + help
80975 + By saying Y here the kernel recomputes expressions of function
80976 + arguments marked by a size_overflow attribute with double integer
80977 + precision (DImode/TImode for 32/64 bit integer types).
80978 +
80979 + The recomputed argument is checked against TYPE_MAX and an event
80980 + is logged on overflow and the triggering process is killed.
80981 +
80982 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
80983 +
80984 + Note that the implementation requires a gcc with plugin support,
80985 + i.e., gcc 4.5 or newer. You may need to install the supporting
80986 + headers explicitly in addition to the normal gcc package.
80987 +
80988 +config PAX_LATENT_ENTROPY
80989 + bool "Generate some entropy during boot"
80990 + default y if GRKERNSEC_CONFIG_AUTO
80991 + help
80992 + By saying Y here the kernel will instrument early boot code to
80993 + extract some entropy from both original and artificially created
80994 + program state. This will help especially embedded systems where
80995 + there is little 'natural' source of entropy normally. The cost
80996 + is some slowdown of the boot process.
80997 +
80998 + Note that the implementation requires a gcc with plugin support,
80999 + i.e., gcc 4.5 or newer. You may need to install the supporting
81000 + headers explicitly in addition to the normal gcc package.
81001 +
81002 + Note that entropy extracted this way is not cryptographically
81003 + secure!
81004 +
81005 +endmenu
81006 +
81007 +endmenu
81008 +
81009 +source grsecurity/Kconfig
81010 +
81011 +endmenu
81012 +
81013 +endmenu
81014 +
81015 source security/keys/Kconfig
81016
81017 config SECURITY_DMESG_RESTRICT
81018 @@ -103,7 +993,7 @@ config INTEL_TXT
81019 config LSM_MMAP_MIN_ADDR
81020 int "Low address space for LSM to protect from user allocation"
81021 depends on SECURITY && SECURITY_SELINUX
81022 - default 32768 if ARM
81023 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81024 default 65536
81025 help
81026 This is the portion of low virtual memory which should be protected
81027 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81028 index 8ea39aa..8569ac5 100644
81029 --- a/security/apparmor/lsm.c
81030 +++ b/security/apparmor/lsm.c
81031 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81032 return error;
81033 }
81034
81035 -static struct security_operations apparmor_ops = {
81036 +static struct security_operations apparmor_ops __read_only = {
81037 .name = "apparmor",
81038
81039 .ptrace_access_check = apparmor_ptrace_access_check,
81040 diff --git a/security/commoncap.c b/security/commoncap.c
81041 index 6dbae46..d5611fd 100644
81042 --- a/security/commoncap.c
81043 +++ b/security/commoncap.c
81044 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81045 return 0;
81046 }
81047
81048 +/* returns:
81049 + 1 for suid privilege
81050 + 2 for sgid privilege
81051 + 3 for fscap privilege
81052 +*/
81053 +int is_privileged_binary(const struct dentry *dentry)
81054 +{
81055 + struct cpu_vfs_cap_data capdata;
81056 + struct inode *inode = dentry->d_inode;
81057 +
81058 + if (!inode || S_ISDIR(inode->i_mode))
81059 + return 0;
81060 +
81061 + if (inode->i_mode & S_ISUID)
81062 + return 1;
81063 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81064 + return 2;
81065 +
81066 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81067 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81068 + return 3;
81069 + }
81070 +
81071 + return 0;
81072 +}
81073 +
81074 /*
81075 * Attempt to get the on-exec apply capability sets for an executable file from
81076 * its xattrs and, if present, apply them to the proposed credentials being
81077 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81078 const struct cred *cred = current_cred();
81079 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81080
81081 + if (gr_acl_enable_at_secure())
81082 + return 1;
81083 +
81084 if (!uid_eq(cred->uid, root_uid)) {
81085 if (bprm->cap_effective)
81086 return 1;
81087 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81088 index e7c99fd..5b2fa24 100644
81089 --- a/security/integrity/ima/ima.h
81090 +++ b/security/integrity/ima/ima.h
81091 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81092 extern spinlock_t ima_queue_lock;
81093
81094 struct ima_h_table {
81095 - atomic_long_t len; /* number of stored measurements in the list */
81096 - atomic_long_t violations;
81097 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81098 + atomic_long_unchecked_t violations;
81099 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81100 };
81101 extern struct ima_h_table ima_htable;
81102 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81103 index 032ff03..c428a74 100644
81104 --- a/security/integrity/ima/ima_api.c
81105 +++ b/security/integrity/ima/ima_api.c
81106 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81107 int result;
81108
81109 /* can overflow, only indicator */
81110 - atomic_long_inc(&ima_htable.violations);
81111 + atomic_long_inc_unchecked(&ima_htable.violations);
81112
81113 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81114 if (!entry) {
81115 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81116 index 38477c9..87a60c7 100644
81117 --- a/security/integrity/ima/ima_fs.c
81118 +++ b/security/integrity/ima/ima_fs.c
81119 @@ -28,12 +28,12 @@
81120 static int valid_policy = 1;
81121 #define TMPBUFLEN 12
81122 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81123 - loff_t *ppos, atomic_long_t *val)
81124 + loff_t *ppos, atomic_long_unchecked_t *val)
81125 {
81126 char tmpbuf[TMPBUFLEN];
81127 ssize_t len;
81128
81129 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81130 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81131 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81132 }
81133
81134 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81135 index 55a6271..ad829c3 100644
81136 --- a/security/integrity/ima/ima_queue.c
81137 +++ b/security/integrity/ima/ima_queue.c
81138 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81139 INIT_LIST_HEAD(&qe->later);
81140 list_add_tail_rcu(&qe->later, &ima_measurements);
81141
81142 - atomic_long_inc(&ima_htable.len);
81143 + atomic_long_inc_unchecked(&ima_htable.len);
81144 key = ima_hash_key(entry->digest);
81145 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81146 return 0;
81147 diff --git a/security/keys/compat.c b/security/keys/compat.c
81148 index 1c26176..64a1ba2 100644
81149 --- a/security/keys/compat.c
81150 +++ b/security/keys/compat.c
81151 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81152 if (ret == 0)
81153 goto no_payload_free;
81154
81155 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81156 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81157
81158 if (iov != iovstack)
81159 kfree(iov);
81160 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81161 index 3364fbf..1f10f31 100644
81162 --- a/security/keys/keyctl.c
81163 +++ b/security/keys/keyctl.c
81164 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81165 /*
81166 * Copy the iovec data from userspace
81167 */
81168 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81169 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81170 unsigned ioc)
81171 {
81172 for (; ioc > 0; ioc--) {
81173 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81174 * If successful, 0 will be returned.
81175 */
81176 long keyctl_instantiate_key_common(key_serial_t id,
81177 - const struct iovec *payload_iov,
81178 + const struct iovec __user *payload_iov,
81179 unsigned ioc,
81180 size_t plen,
81181 key_serial_t ringid)
81182 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81183 [0].iov_len = plen
81184 };
81185
81186 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81187 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81188 }
81189
81190 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81191 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81192 if (ret == 0)
81193 goto no_payload_free;
81194
81195 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81196 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81197
81198 if (iov != iovstack)
81199 kfree(iov);
81200 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81201 index 81e7852..2b2ecc3 100644
81202 --- a/security/keys/keyring.c
81203 +++ b/security/keys/keyring.c
81204 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81205 ret = -EFAULT;
81206
81207 for (loop = 0; loop < klist->nkeys; loop++) {
81208 + key_serial_t serial;
81209 key = rcu_deref_link_locked(klist, loop,
81210 keyring);
81211 + serial = key->serial;
81212
81213 tmp = sizeof(key_serial_t);
81214 if (tmp > buflen)
81215 tmp = buflen;
81216
81217 - if (copy_to_user(buffer,
81218 - &key->serial,
81219 - tmp) != 0)
81220 + if (copy_to_user(buffer, &serial, tmp))
81221 goto error;
81222
81223 buflen -= tmp;
81224 diff --git a/security/min_addr.c b/security/min_addr.c
81225 index f728728..6457a0c 100644
81226 --- a/security/min_addr.c
81227 +++ b/security/min_addr.c
81228 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81229 */
81230 static void update_mmap_min_addr(void)
81231 {
81232 +#ifndef SPARC
81233 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81234 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81235 mmap_min_addr = dac_mmap_min_addr;
81236 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81237 #else
81238 mmap_min_addr = dac_mmap_min_addr;
81239 #endif
81240 +#endif
81241 }
81242
81243 /*
81244 diff --git a/security/security.c b/security/security.c
81245 index 860aeb3..45765c0 100644
81246 --- a/security/security.c
81247 +++ b/security/security.c
81248 @@ -20,6 +20,7 @@
81249 #include <linux/ima.h>
81250 #include <linux/evm.h>
81251 #include <linux/fsnotify.h>
81252 +#include <linux/mm.h>
81253 #include <linux/mman.h>
81254 #include <linux/mount.h>
81255 #include <linux/personality.h>
81256 @@ -32,8 +33,8 @@
81257 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81258 CONFIG_DEFAULT_SECURITY;
81259
81260 -static struct security_operations *security_ops;
81261 -static struct security_operations default_security_ops = {
81262 +static struct security_operations *security_ops __read_only;
81263 +static struct security_operations default_security_ops __read_only = {
81264 .name = "default",
81265 };
81266
81267 @@ -74,7 +75,9 @@ int __init security_init(void)
81268
81269 void reset_security_ops(void)
81270 {
81271 + pax_open_kernel();
81272 security_ops = &default_security_ops;
81273 + pax_close_kernel();
81274 }
81275
81276 /* Save user chosen LSM */
81277 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81278 index 6c77f63..7496c76 100644
81279 --- a/security/selinux/hooks.c
81280 +++ b/security/selinux/hooks.c
81281 @@ -95,8 +95,6 @@
81282
81283 #define NUM_SEL_MNT_OPTS 5
81284
81285 -extern struct security_operations *security_ops;
81286 -
81287 /* SECMARK reference count */
81288 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81289
81290 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81291
81292 #endif
81293
81294 -static struct security_operations selinux_ops = {
81295 +static struct security_operations selinux_ops __read_only = {
81296 .name = "selinux",
81297
81298 .ptrace_access_check = selinux_ptrace_access_check,
81299 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81300 index 65f67cb..3f141ef 100644
81301 --- a/security/selinux/include/xfrm.h
81302 +++ b/security/selinux/include/xfrm.h
81303 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81304
81305 static inline void selinux_xfrm_notify_policyload(void)
81306 {
81307 - atomic_inc(&flow_cache_genid);
81308 + atomic_inc_unchecked(&flow_cache_genid);
81309 rt_genid_bump(&init_net);
81310 }
81311 #else
81312 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81313 index 8221514..5c4775f 100644
81314 --- a/security/smack/smack_lsm.c
81315 +++ b/security/smack/smack_lsm.c
81316 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81317 return 0;
81318 }
81319
81320 -struct security_operations smack_ops = {
81321 +struct security_operations smack_ops __read_only = {
81322 .name = "smack",
81323
81324 .ptrace_access_check = smack_ptrace_access_check,
81325 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81326 index c2d04a5..e6a1aeb 100644
81327 --- a/security/tomoyo/tomoyo.c
81328 +++ b/security/tomoyo/tomoyo.c
81329 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81330 * tomoyo_security_ops is a "struct security_operations" which is used for
81331 * registering TOMOYO.
81332 */
81333 -static struct security_operations tomoyo_security_ops = {
81334 +static struct security_operations tomoyo_security_ops __read_only = {
81335 .name = "tomoyo",
81336 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81337 .cred_prepare = tomoyo_cred_prepare,
81338 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81339 index 51d6709..1f3dbe2 100644
81340 --- a/security/yama/Kconfig
81341 +++ b/security/yama/Kconfig
81342 @@ -1,6 +1,6 @@
81343 config SECURITY_YAMA
81344 bool "Yama support"
81345 - depends on SECURITY
81346 + depends on SECURITY && !GRKERNSEC
81347 select SECURITYFS
81348 select SECURITY_PATH
81349 default n
81350 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81351 index 4cedc69..e59d8a3 100644
81352 --- a/sound/aoa/codecs/onyx.c
81353 +++ b/sound/aoa/codecs/onyx.c
81354 @@ -54,7 +54,7 @@ struct onyx {
81355 spdif_locked:1,
81356 analog_locked:1,
81357 original_mute:2;
81358 - int open_count;
81359 + local_t open_count;
81360 struct codec_info *codec_info;
81361
81362 /* mutex serializes concurrent access to the device
81363 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81364 struct onyx *onyx = cii->codec_data;
81365
81366 mutex_lock(&onyx->mutex);
81367 - onyx->open_count++;
81368 + local_inc(&onyx->open_count);
81369 mutex_unlock(&onyx->mutex);
81370
81371 return 0;
81372 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81373 struct onyx *onyx = cii->codec_data;
81374
81375 mutex_lock(&onyx->mutex);
81376 - onyx->open_count--;
81377 - if (!onyx->open_count)
81378 + if (local_dec_and_test(&onyx->open_count))
81379 onyx->spdif_locked = onyx->analog_locked = 0;
81380 mutex_unlock(&onyx->mutex);
81381
81382 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81383 index ffd2025..df062c9 100644
81384 --- a/sound/aoa/codecs/onyx.h
81385 +++ b/sound/aoa/codecs/onyx.h
81386 @@ -11,6 +11,7 @@
81387 #include <linux/i2c.h>
81388 #include <asm/pmac_low_i2c.h>
81389 #include <asm/prom.h>
81390 +#include <asm/local.h>
81391
81392 /* PCM3052 register definitions */
81393
81394 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81395 index 08fde00..0bf641a 100644
81396 --- a/sound/core/oss/pcm_oss.c
81397 +++ b/sound/core/oss/pcm_oss.c
81398 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81399 if (in_kernel) {
81400 mm_segment_t fs;
81401 fs = snd_enter_user();
81402 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81403 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81404 snd_leave_user(fs);
81405 } else {
81406 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81407 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81408 }
81409 if (ret != -EPIPE && ret != -ESTRPIPE)
81410 break;
81411 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81412 if (in_kernel) {
81413 mm_segment_t fs;
81414 fs = snd_enter_user();
81415 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81416 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81417 snd_leave_user(fs);
81418 } else {
81419 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81420 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81421 }
81422 if (ret == -EPIPE) {
81423 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81424 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81425 struct snd_pcm_plugin_channel *channels;
81426 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81427 if (!in_kernel) {
81428 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81429 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81430 return -EFAULT;
81431 buf = runtime->oss.buffer;
81432 }
81433 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81434 }
81435 } else {
81436 tmp = snd_pcm_oss_write2(substream,
81437 - (const char __force *)buf,
81438 + (const char __force_kernel *)buf,
81439 runtime->oss.period_bytes, 0);
81440 if (tmp <= 0)
81441 goto err;
81442 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81443 struct snd_pcm_runtime *runtime = substream->runtime;
81444 snd_pcm_sframes_t frames, frames1;
81445 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81446 - char __user *final_dst = (char __force __user *)buf;
81447 + char __user *final_dst = (char __force_user *)buf;
81448 if (runtime->oss.plugin_first) {
81449 struct snd_pcm_plugin_channel *channels;
81450 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81451 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81452 xfer += tmp;
81453 runtime->oss.buffer_used -= tmp;
81454 } else {
81455 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81456 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81457 runtime->oss.period_bytes, 0);
81458 if (tmp <= 0)
81459 goto err;
81460 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81461 size1);
81462 size1 /= runtime->channels; /* frames */
81463 fs = snd_enter_user();
81464 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81465 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81466 snd_leave_user(fs);
81467 }
81468 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81469 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81470 index 91cdf94..4085161 100644
81471 --- a/sound/core/pcm_compat.c
81472 +++ b/sound/core/pcm_compat.c
81473 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81474 int err;
81475
81476 fs = snd_enter_user();
81477 - err = snd_pcm_delay(substream, &delay);
81478 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81479 snd_leave_user(fs);
81480 if (err < 0)
81481 return err;
81482 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81483 index 53b5ada..2db94c8 100644
81484 --- a/sound/core/pcm_native.c
81485 +++ b/sound/core/pcm_native.c
81486 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81487 switch (substream->stream) {
81488 case SNDRV_PCM_STREAM_PLAYBACK:
81489 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81490 - (void __user *)arg);
81491 + (void __force_user *)arg);
81492 break;
81493 case SNDRV_PCM_STREAM_CAPTURE:
81494 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81495 - (void __user *)arg);
81496 + (void __force_user *)arg);
81497 break;
81498 default:
81499 result = -EINVAL;
81500 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81501 index 5cf8d65..912a79c 100644
81502 --- a/sound/core/seq/seq_device.c
81503 +++ b/sound/core/seq/seq_device.c
81504 @@ -64,7 +64,7 @@ struct ops_list {
81505 int argsize; /* argument size */
81506
81507 /* operators */
81508 - struct snd_seq_dev_ops ops;
81509 + struct snd_seq_dev_ops *ops;
81510
81511 /* registred devices */
81512 struct list_head dev_list; /* list of devices */
81513 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81514
81515 mutex_lock(&ops->reg_mutex);
81516 /* copy driver operators */
81517 - ops->ops = *entry;
81518 + ops->ops = entry;
81519 ops->driver |= DRIVER_LOADED;
81520 ops->argsize = argsize;
81521
81522 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81523 dev->name, ops->id, ops->argsize, dev->argsize);
81524 return -EINVAL;
81525 }
81526 - if (ops->ops.init_device(dev) >= 0) {
81527 + if (ops->ops->init_device(dev) >= 0) {
81528 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81529 ops->num_init_devices++;
81530 } else {
81531 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81532 dev->name, ops->id, ops->argsize, dev->argsize);
81533 return -EINVAL;
81534 }
81535 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81536 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81537 dev->status = SNDRV_SEQ_DEVICE_FREE;
81538 dev->driver_data = NULL;
81539 ops->num_init_devices--;
81540 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81541 index 2d5514b..3afae9c 100644
81542 --- a/sound/drivers/mts64.c
81543 +++ b/sound/drivers/mts64.c
81544 @@ -29,6 +29,7 @@
81545 #include <sound/initval.h>
81546 #include <sound/rawmidi.h>
81547 #include <sound/control.h>
81548 +#include <asm/local.h>
81549
81550 #define CARD_NAME "Miditerminal 4140"
81551 #define DRIVER_NAME "MTS64"
81552 @@ -67,7 +68,7 @@ struct mts64 {
81553 struct pardevice *pardev;
81554 int pardev_claimed;
81555
81556 - int open_count;
81557 + local_t open_count;
81558 int current_midi_output_port;
81559 int current_midi_input_port;
81560 u8 mode[MTS64_NUM_INPUT_PORTS];
81561 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81562 {
81563 struct mts64 *mts = substream->rmidi->private_data;
81564
81565 - if (mts->open_count == 0) {
81566 + if (local_read(&mts->open_count) == 0) {
81567 /* We don't need a spinlock here, because this is just called
81568 if the device has not been opened before.
81569 So there aren't any IRQs from the device */
81570 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81571
81572 msleep(50);
81573 }
81574 - ++(mts->open_count);
81575 + local_inc(&mts->open_count);
81576
81577 return 0;
81578 }
81579 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81580 struct mts64 *mts = substream->rmidi->private_data;
81581 unsigned long flags;
81582
81583 - --(mts->open_count);
81584 - if (mts->open_count == 0) {
81585 + if (local_dec_return(&mts->open_count) == 0) {
81586 /* We need the spinlock_irqsave here because we can still
81587 have IRQs at this point */
81588 spin_lock_irqsave(&mts->lock, flags);
81589 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81590
81591 msleep(500);
81592
81593 - } else if (mts->open_count < 0)
81594 - mts->open_count = 0;
81595 + } else if (local_read(&mts->open_count) < 0)
81596 + local_set(&mts->open_count, 0);
81597
81598 return 0;
81599 }
81600 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81601 index b953fb4..1999c01 100644
81602 --- a/sound/drivers/opl4/opl4_lib.c
81603 +++ b/sound/drivers/opl4/opl4_lib.c
81604 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81605 MODULE_DESCRIPTION("OPL4 driver");
81606 MODULE_LICENSE("GPL");
81607
81608 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81609 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81610 {
81611 int timeout = 10;
81612 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81613 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81614 index 8364855..59f2e2b 100644
81615 --- a/sound/drivers/portman2x4.c
81616 +++ b/sound/drivers/portman2x4.c
81617 @@ -48,6 +48,7 @@
81618 #include <sound/initval.h>
81619 #include <sound/rawmidi.h>
81620 #include <sound/control.h>
81621 +#include <asm/local.h>
81622
81623 #define CARD_NAME "Portman 2x4"
81624 #define DRIVER_NAME "portman"
81625 @@ -85,7 +86,7 @@ struct portman {
81626 struct pardevice *pardev;
81627 int pardev_claimed;
81628
81629 - int open_count;
81630 + local_t open_count;
81631 int mode[PORTMAN_NUM_INPUT_PORTS];
81632 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81633 };
81634 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81635 index ea995af..f1bfa37 100644
81636 --- a/sound/firewire/amdtp.c
81637 +++ b/sound/firewire/amdtp.c
81638 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81639 ptr = s->pcm_buffer_pointer + data_blocks;
81640 if (ptr >= pcm->runtime->buffer_size)
81641 ptr -= pcm->runtime->buffer_size;
81642 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81643 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81644
81645 s->pcm_period_pointer += data_blocks;
81646 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81647 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
81648 */
81649 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81650 {
81651 - ACCESS_ONCE(s->source_node_id_field) =
81652 + ACCESS_ONCE_RW(s->source_node_id_field) =
81653 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81654 }
81655 EXPORT_SYMBOL(amdtp_out_stream_update);
81656 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81657 index b680c5e..061b7a0 100644
81658 --- a/sound/firewire/amdtp.h
81659 +++ b/sound/firewire/amdtp.h
81660 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
81661 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81662 struct snd_pcm_substream *pcm)
81663 {
81664 - ACCESS_ONCE(s->pcm) = pcm;
81665 + ACCESS_ONCE_RW(s->pcm) = pcm;
81666 }
81667
81668 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
81669 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81670 index d428ffe..751ef78 100644
81671 --- a/sound/firewire/isight.c
81672 +++ b/sound/firewire/isight.c
81673 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81674 ptr += count;
81675 if (ptr >= runtime->buffer_size)
81676 ptr -= runtime->buffer_size;
81677 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81678 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81679
81680 isight->period_counter += count;
81681 if (isight->period_counter >= runtime->period_size) {
81682 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81683 if (err < 0)
81684 return err;
81685
81686 - ACCESS_ONCE(isight->pcm_active) = true;
81687 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81688
81689 return 0;
81690 }
81691 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81692 {
81693 struct isight *isight = substream->private_data;
81694
81695 - ACCESS_ONCE(isight->pcm_active) = false;
81696 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81697
81698 mutex_lock(&isight->mutex);
81699 isight_stop_streaming(isight);
81700 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81701
81702 switch (cmd) {
81703 case SNDRV_PCM_TRIGGER_START:
81704 - ACCESS_ONCE(isight->pcm_running) = true;
81705 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81706 break;
81707 case SNDRV_PCM_TRIGGER_STOP:
81708 - ACCESS_ONCE(isight->pcm_running) = false;
81709 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81710 break;
81711 default:
81712 return -EINVAL;
81713 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81714 index 7bd5e33..1fcab12 100644
81715 --- a/sound/isa/cmi8330.c
81716 +++ b/sound/isa/cmi8330.c
81717 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81718
81719 struct snd_pcm *pcm;
81720 struct snd_cmi8330_stream {
81721 - struct snd_pcm_ops ops;
81722 + snd_pcm_ops_no_const ops;
81723 snd_pcm_open_callback_t open;
81724 void *private_data; /* sb or wss */
81725 } streams[2];
81726 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81727 index b2b3c01..e1c1e1f 100644
81728 --- a/sound/oss/sb_audio.c
81729 +++ b/sound/oss/sb_audio.c
81730 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
81731 buf16 = (signed short *)(localbuf + localoffs);
81732 while (c)
81733 {
81734 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81735 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81736 if (copy_from_user(lbuf8,
81737 userbuf+useroffs + p,
81738 locallen))
81739 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81740 index 7d8803a..559f8d0 100644
81741 --- a/sound/oss/swarm_cs4297a.c
81742 +++ b/sound/oss/swarm_cs4297a.c
81743 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
81744 {
81745 struct cs4297a_state *s;
81746 u32 pwr, id;
81747 - mm_segment_t fs;
81748 int rval;
81749 #ifndef CONFIG_BCM_CS4297A_CSWARM
81750 u64 cfg;
81751 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
81752 if (!rval) {
81753 char *sb1250_duart_present;
81754
81755 +#if 0
81756 + mm_segment_t fs;
81757 fs = get_fs();
81758 set_fs(KERNEL_DS);
81759 -#if 0
81760 val = SOUND_MASK_LINE;
81761 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81762 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81763 val = initvol[i].vol;
81764 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81765 }
81766 + set_fs(fs);
81767 // cs4297a_write_ac97(s, 0x18, 0x0808);
81768 #else
81769 // cs4297a_write_ac97(s, 0x5e, 0x180);
81770 cs4297a_write_ac97(s, 0x02, 0x0808);
81771 cs4297a_write_ac97(s, 0x18, 0x0808);
81772 #endif
81773 - set_fs(fs);
81774
81775 list_add(&s->list, &cs4297a_devs);
81776
81777 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81778 index e5a7e19..4049063 100644
81779 --- a/sound/pci/hda/hda_codec.h
81780 +++ b/sound/pci/hda/hda_codec.h
81781 @@ -614,7 +614,7 @@ struct hda_bus_ops {
81782 /* notify power-up/down from codec to controller */
81783 void (*pm_notify)(struct hda_bus *bus);
81784 #endif
81785 -};
81786 +} __no_const;
81787
81788 /* template to pass to the bus constructor */
81789 struct hda_bus_template {
81790 @@ -714,6 +714,7 @@ struct hda_codec_ops {
81791 #endif
81792 void (*reboot_notify)(struct hda_codec *codec);
81793 };
81794 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81795
81796 /* record for amp information cache */
81797 struct hda_cache_head {
81798 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
81799 struct snd_pcm_substream *substream);
81800 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81801 struct snd_pcm_substream *substream);
81802 -};
81803 +} __no_const;
81804
81805 /* PCM information for each substream */
81806 struct hda_pcm_stream {
81807 @@ -802,7 +803,7 @@ struct hda_codec {
81808 const char *modelname; /* model name for preset */
81809
81810 /* set by patch */
81811 - struct hda_codec_ops patch_ops;
81812 + hda_codec_ops_no_const patch_ops;
81813
81814 /* PCM to create, set by patch_ops.build_pcms callback */
81815 unsigned int num_pcms;
81816 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81817 index 0da778a..bc38b84 100644
81818 --- a/sound/pci/ice1712/ice1712.h
81819 +++ b/sound/pci/ice1712/ice1712.h
81820 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81821 unsigned int mask_flags; /* total mask bits */
81822 struct snd_akm4xxx_ops {
81823 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81824 - } ops;
81825 + } __no_const ops;
81826 };
81827
81828 struct snd_ice1712_spdif {
81829 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81830 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81831 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81832 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81833 - } ops;
81834 + } __no_const ops;
81835 };
81836
81837
81838 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
81839 index bddc405..2c0733c 100644
81840 --- a/sound/pci/ymfpci/ymfpci.h
81841 +++ b/sound/pci/ymfpci/ymfpci.h
81842 @@ -358,7 +358,7 @@ struct snd_ymfpci {
81843 spinlock_t reg_lock;
81844 spinlock_t voice_lock;
81845 wait_queue_head_t interrupt_sleep;
81846 - atomic_t interrupt_sleep_count;
81847 + atomic_unchecked_t interrupt_sleep_count;
81848 struct snd_info_entry *proc_entry;
81849 const struct firmware *dsp_microcode;
81850 const struct firmware *controller_microcode;
81851 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81852 index 62b2363..ee77972 100644
81853 --- a/sound/pci/ymfpci/ymfpci_main.c
81854 +++ b/sound/pci/ymfpci/ymfpci_main.c
81855 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81856 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81857 break;
81858 }
81859 - if (atomic_read(&chip->interrupt_sleep_count)) {
81860 - atomic_set(&chip->interrupt_sleep_count, 0);
81861 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81862 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81863 wake_up(&chip->interrupt_sleep);
81864 }
81865 __end:
81866 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81867 continue;
81868 init_waitqueue_entry(&wait, current);
81869 add_wait_queue(&chip->interrupt_sleep, &wait);
81870 - atomic_inc(&chip->interrupt_sleep_count);
81871 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81872 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81873 remove_wait_queue(&chip->interrupt_sleep, &wait);
81874 }
81875 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81876 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81877 spin_unlock(&chip->reg_lock);
81878
81879 - if (atomic_read(&chip->interrupt_sleep_count)) {
81880 - atomic_set(&chip->interrupt_sleep_count, 0);
81881 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81882 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81883 wake_up(&chip->interrupt_sleep);
81884 }
81885 }
81886 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81887 spin_lock_init(&chip->reg_lock);
81888 spin_lock_init(&chip->voice_lock);
81889 init_waitqueue_head(&chip->interrupt_sleep);
81890 - atomic_set(&chip->interrupt_sleep_count, 0);
81891 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81892 chip->card = card;
81893 chip->pci = pci;
81894 chip->irq = -1;
81895 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
81896 new file mode 100644
81897 index 0000000..50f2f2f
81898 --- /dev/null
81899 +++ b/tools/gcc/.gitignore
81900 @@ -0,0 +1 @@
81901 +size_overflow_hash.h
81902 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81903 new file mode 100644
81904 index 0000000..1d09b7e
81905 --- /dev/null
81906 +++ b/tools/gcc/Makefile
81907 @@ -0,0 +1,43 @@
81908 +#CC := gcc
81909 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81910 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81911 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81912 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81913 +
81914 +ifeq ($(PLUGINCC),$(HOSTCC))
81915 +HOSTLIBS := hostlibs
81916 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81917 +else
81918 +HOSTLIBS := hostcxxlibs
81919 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
81920 +endif
81921 +
81922 +$(HOSTLIBS)-y := constify_plugin.so
81923 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81924 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81925 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81926 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81927 +$(HOSTLIBS)-y += colorize_plugin.so
81928 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81929 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
81930 +
81931 +always := $($(HOSTLIBS)-y)
81932 +
81933 +constify_plugin-objs := constify_plugin.o
81934 +stackleak_plugin-objs := stackleak_plugin.o
81935 +kallocstat_plugin-objs := kallocstat_plugin.o
81936 +kernexec_plugin-objs := kernexec_plugin.o
81937 +checker_plugin-objs := checker_plugin.o
81938 +colorize_plugin-objs := colorize_plugin.o
81939 +size_overflow_plugin-objs := size_overflow_plugin.o
81940 +latent_entropy_plugin-objs := latent_entropy_plugin.o
81941 +
81942 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
81943 +
81944 +quiet_cmd_build_size_overflow_hash = GENHASH $@
81945 + cmd_build_size_overflow_hash = \
81946 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
81947 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
81948 + $(call if_changed,build_size_overflow_hash)
81949 +
81950 +targets += size_overflow_hash.h
81951 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81952 new file mode 100644
81953 index 0000000..d41b5af
81954 --- /dev/null
81955 +++ b/tools/gcc/checker_plugin.c
81956 @@ -0,0 +1,171 @@
81957 +/*
81958 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81959 + * Licensed under the GPL v2
81960 + *
81961 + * Note: the choice of the license means that the compilation process is
81962 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81963 + * but for the kernel it doesn't matter since it doesn't link against
81964 + * any of the gcc libraries
81965 + *
81966 + * gcc plugin to implement various sparse (source code checker) features
81967 + *
81968 + * TODO:
81969 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81970 + *
81971 + * BUGS:
81972 + * - none known
81973 + */
81974 +#include "gcc-plugin.h"
81975 +#include "config.h"
81976 +#include "system.h"
81977 +#include "coretypes.h"
81978 +#include "tree.h"
81979 +#include "tree-pass.h"
81980 +#include "flags.h"
81981 +#include "intl.h"
81982 +#include "toplev.h"
81983 +#include "plugin.h"
81984 +//#include "expr.h" where are you...
81985 +#include "diagnostic.h"
81986 +#include "plugin-version.h"
81987 +#include "tm.h"
81988 +#include "function.h"
81989 +#include "basic-block.h"
81990 +#include "gimple.h"
81991 +#include "rtl.h"
81992 +#include "emit-rtl.h"
81993 +#include "tree-flow.h"
81994 +#include "target.h"
81995 +
81996 +extern void c_register_addr_space (const char *str, addr_space_t as);
81997 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
81998 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
81999 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82000 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82001 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82002 +
82003 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82004 +extern rtx emit_move_insn(rtx x, rtx y);
82005 +
82006 +int plugin_is_GPL_compatible;
82007 +
82008 +static struct plugin_info checker_plugin_info = {
82009 + .version = "201111150100",
82010 +};
82011 +
82012 +#define ADDR_SPACE_KERNEL 0
82013 +#define ADDR_SPACE_FORCE_KERNEL 1
82014 +#define ADDR_SPACE_USER 2
82015 +#define ADDR_SPACE_FORCE_USER 3
82016 +#define ADDR_SPACE_IOMEM 0
82017 +#define ADDR_SPACE_FORCE_IOMEM 0
82018 +#define ADDR_SPACE_PERCPU 0
82019 +#define ADDR_SPACE_FORCE_PERCPU 0
82020 +#define ADDR_SPACE_RCU 0
82021 +#define ADDR_SPACE_FORCE_RCU 0
82022 +
82023 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82024 +{
82025 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82026 +}
82027 +
82028 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82029 +{
82030 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82031 +}
82032 +
82033 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82034 +{
82035 + return default_addr_space_valid_pointer_mode(mode, as);
82036 +}
82037 +
82038 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82039 +{
82040 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82041 +}
82042 +
82043 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82044 +{
82045 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82046 +}
82047 +
82048 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82049 +{
82050 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82051 + return true;
82052 +
82053 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82054 + return true;
82055 +
82056 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82057 + return true;
82058 +
82059 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82060 + return true;
82061 +
82062 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82063 + return true;
82064 +
82065 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82066 + return true;
82067 +
82068 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82069 + return true;
82070 +
82071 + return subset == superset;
82072 +}
82073 +
82074 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82075 +{
82076 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82077 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82078 +
82079 + return op;
82080 +}
82081 +
82082 +static void register_checker_address_spaces(void *event_data, void *data)
82083 +{
82084 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82085 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82086 + c_register_addr_space("__user", ADDR_SPACE_USER);
82087 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82088 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82089 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82090 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82091 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82092 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82093 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82094 +
82095 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82096 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82097 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82098 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82099 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82100 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82101 + targetm.addr_space.convert = checker_addr_space_convert;
82102 +}
82103 +
82104 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82105 +{
82106 + const char * const plugin_name = plugin_info->base_name;
82107 + const int argc = plugin_info->argc;
82108 + const struct plugin_argument * const argv = plugin_info->argv;
82109 + int i;
82110 +
82111 + if (!plugin_default_version_check(version, &gcc_version)) {
82112 + error(G_("incompatible gcc/plugin versions"));
82113 + return 1;
82114 + }
82115 +
82116 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82117 +
82118 + for (i = 0; i < argc; ++i)
82119 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82120 +
82121 + if (TARGET_64BIT == 0)
82122 + return 0;
82123 +
82124 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82125 +
82126 + return 0;
82127 +}
82128 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82129 new file mode 100644
82130 index 0000000..846aeb0
82131 --- /dev/null
82132 +++ b/tools/gcc/colorize_plugin.c
82133 @@ -0,0 +1,148 @@
82134 +/*
82135 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82136 + * Licensed under the GPL v2
82137 + *
82138 + * Note: the choice of the license means that the compilation process is
82139 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82140 + * but for the kernel it doesn't matter since it doesn't link against
82141 + * any of the gcc libraries
82142 + *
82143 + * gcc plugin to colorize diagnostic output
82144 + *
82145 + */
82146 +
82147 +#include "gcc-plugin.h"
82148 +#include "config.h"
82149 +#include "system.h"
82150 +#include "coretypes.h"
82151 +#include "tree.h"
82152 +#include "tree-pass.h"
82153 +#include "flags.h"
82154 +#include "intl.h"
82155 +#include "toplev.h"
82156 +#include "plugin.h"
82157 +#include "diagnostic.h"
82158 +#include "plugin-version.h"
82159 +#include "tm.h"
82160 +
82161 +int plugin_is_GPL_compatible;
82162 +
82163 +static struct plugin_info colorize_plugin_info = {
82164 + .version = "201203092200",
82165 + .help = NULL,
82166 +};
82167 +
82168 +#define GREEN "\033[32m\033[2m"
82169 +#define LIGHTGREEN "\033[32m\033[1m"
82170 +#define YELLOW "\033[33m\033[2m"
82171 +#define LIGHTYELLOW "\033[33m\033[1m"
82172 +#define RED "\033[31m\033[2m"
82173 +#define LIGHTRED "\033[31m\033[1m"
82174 +#define BLUE "\033[34m\033[2m"
82175 +#define LIGHTBLUE "\033[34m\033[1m"
82176 +#define BRIGHT "\033[m\033[1m"
82177 +#define NORMAL "\033[m"
82178 +
82179 +static diagnostic_starter_fn old_starter;
82180 +static diagnostic_finalizer_fn old_finalizer;
82181 +
82182 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82183 +{
82184 + const char *color;
82185 + char *newprefix;
82186 +
82187 + switch (diagnostic->kind) {
82188 + case DK_NOTE:
82189 + color = LIGHTBLUE;
82190 + break;
82191 +
82192 + case DK_PEDWARN:
82193 + case DK_WARNING:
82194 + color = LIGHTYELLOW;
82195 + break;
82196 +
82197 + case DK_ERROR:
82198 + case DK_FATAL:
82199 + case DK_ICE:
82200 + case DK_PERMERROR:
82201 + case DK_SORRY:
82202 + color = LIGHTRED;
82203 + break;
82204 +
82205 + default:
82206 + color = NORMAL;
82207 + }
82208 +
82209 + old_starter(context, diagnostic);
82210 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82211 + return;
82212 + pp_destroy_prefix(context->printer);
82213 + pp_set_prefix(context->printer, newprefix);
82214 +}
82215 +
82216 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82217 +{
82218 + old_finalizer(context, diagnostic);
82219 +}
82220 +
82221 +static void colorize_arm(void)
82222 +{
82223 + old_starter = diagnostic_starter(global_dc);
82224 + old_finalizer = diagnostic_finalizer(global_dc);
82225 +
82226 + diagnostic_starter(global_dc) = start_colorize;
82227 + diagnostic_finalizer(global_dc) = finalize_colorize;
82228 +}
82229 +
82230 +static unsigned int execute_colorize_rearm(void)
82231 +{
82232 + if (diagnostic_starter(global_dc) == start_colorize)
82233 + return 0;
82234 +
82235 + colorize_arm();
82236 + return 0;
82237 +}
82238 +
82239 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82240 + .pass = {
82241 + .type = SIMPLE_IPA_PASS,
82242 + .name = "colorize_rearm",
82243 + .gate = NULL,
82244 + .execute = execute_colorize_rearm,
82245 + .sub = NULL,
82246 + .next = NULL,
82247 + .static_pass_number = 0,
82248 + .tv_id = TV_NONE,
82249 + .properties_required = 0,
82250 + .properties_provided = 0,
82251 + .properties_destroyed = 0,
82252 + .todo_flags_start = 0,
82253 + .todo_flags_finish = 0
82254 + }
82255 +};
82256 +
82257 +static void colorize_start_unit(void *gcc_data, void *user_data)
82258 +{
82259 + colorize_arm();
82260 +}
82261 +
82262 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82263 +{
82264 + const char * const plugin_name = plugin_info->base_name;
82265 + struct register_pass_info colorize_rearm_pass_info = {
82266 + .pass = &pass_ipa_colorize_rearm.pass,
82267 + .reference_pass_name = "*free_lang_data",
82268 + .ref_pass_instance_number = 1,
82269 + .pos_op = PASS_POS_INSERT_AFTER
82270 + };
82271 +
82272 + if (!plugin_default_version_check(version, &gcc_version)) {
82273 + error(G_("incompatible gcc/plugin versions"));
82274 + return 1;
82275 + }
82276 +
82277 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82278 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82279 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82280 + return 0;
82281 +}
82282 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82283 new file mode 100644
82284 index 0000000..92ed719
82285 --- /dev/null
82286 +++ b/tools/gcc/constify_plugin.c
82287 @@ -0,0 +1,331 @@
82288 +/*
82289 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82290 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82291 + * Licensed under the GPL v2, or (at your option) v3
82292 + *
82293 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82294 + *
82295 + * Homepage:
82296 + * http://www.grsecurity.net/~ephox/const_plugin/
82297 + *
82298 + * Usage:
82299 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82300 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82301 + */
82302 +
82303 +#include "gcc-plugin.h"
82304 +#include "config.h"
82305 +#include "system.h"
82306 +#include "coretypes.h"
82307 +#include "tree.h"
82308 +#include "tree-pass.h"
82309 +#include "flags.h"
82310 +#include "intl.h"
82311 +#include "toplev.h"
82312 +#include "plugin.h"
82313 +#include "diagnostic.h"
82314 +#include "plugin-version.h"
82315 +#include "tm.h"
82316 +#include "function.h"
82317 +#include "basic-block.h"
82318 +#include "gimple.h"
82319 +#include "rtl.h"
82320 +#include "emit-rtl.h"
82321 +#include "tree-flow.h"
82322 +
82323 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82324 +
82325 +int plugin_is_GPL_compatible;
82326 +
82327 +static struct plugin_info const_plugin_info = {
82328 + .version = "201205300030",
82329 + .help = "no-constify\tturn off constification\n",
82330 +};
82331 +
82332 +static void deconstify_tree(tree node);
82333 +
82334 +static void deconstify_type(tree type)
82335 +{
82336 + tree field;
82337 +
82338 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82339 + tree type = TREE_TYPE(field);
82340 +
82341 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82342 + continue;
82343 + if (!TYPE_READONLY(type))
82344 + continue;
82345 +
82346 + deconstify_tree(field);
82347 + }
82348 + TYPE_READONLY(type) = 0;
82349 + C_TYPE_FIELDS_READONLY(type) = 0;
82350 +}
82351 +
82352 +static void deconstify_tree(tree node)
82353 +{
82354 + tree old_type, new_type, field;
82355 +
82356 + old_type = TREE_TYPE(node);
82357 +
82358 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82359 +
82360 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82361 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82362 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82363 + DECL_FIELD_CONTEXT(field) = new_type;
82364 +
82365 + deconstify_type(new_type);
82366 +
82367 + TREE_READONLY(node) = 0;
82368 + TREE_TYPE(node) = new_type;
82369 +}
82370 +
82371 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82372 +{
82373 + tree type;
82374 +
82375 + *no_add_attrs = true;
82376 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82377 + error("%qE attribute does not apply to functions", name);
82378 + return NULL_TREE;
82379 + }
82380 +
82381 + if (TREE_CODE(*node) == VAR_DECL) {
82382 + error("%qE attribute does not apply to variables", name);
82383 + return NULL_TREE;
82384 + }
82385 +
82386 + if (TYPE_P(*node)) {
82387 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82388 + *no_add_attrs = false;
82389 + else
82390 + error("%qE attribute applies to struct and union types only", name);
82391 + return NULL_TREE;
82392 + }
82393 +
82394 + type = TREE_TYPE(*node);
82395 +
82396 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82397 + error("%qE attribute applies to struct and union types only", name);
82398 + return NULL_TREE;
82399 + }
82400 +
82401 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82402 + error("%qE attribute is already applied to the type", name);
82403 + return NULL_TREE;
82404 + }
82405 +
82406 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82407 + error("%qE attribute used on type that is not constified", name);
82408 + return NULL_TREE;
82409 + }
82410 +
82411 + if (TREE_CODE(*node) == TYPE_DECL) {
82412 + deconstify_tree(*node);
82413 + return NULL_TREE;
82414 + }
82415 +
82416 + return NULL_TREE;
82417 +}
82418 +
82419 +static void constify_type(tree type)
82420 +{
82421 + TYPE_READONLY(type) = 1;
82422 + C_TYPE_FIELDS_READONLY(type) = 1;
82423 +}
82424 +
82425 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82426 +{
82427 + *no_add_attrs = true;
82428 + if (!TYPE_P(*node)) {
82429 + error("%qE attribute applies to types only", name);
82430 + return NULL_TREE;
82431 + }
82432 +
82433 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82434 + error("%qE attribute applies to struct and union types only", name);
82435 + return NULL_TREE;
82436 + }
82437 +
82438 + *no_add_attrs = false;
82439 + constify_type(*node);
82440 + return NULL_TREE;
82441 +}
82442 +
82443 +static struct attribute_spec no_const_attr = {
82444 + .name = "no_const",
82445 + .min_length = 0,
82446 + .max_length = 0,
82447 + .decl_required = false,
82448 + .type_required = false,
82449 + .function_type_required = false,
82450 + .handler = handle_no_const_attribute,
82451 +#if BUILDING_GCC_VERSION >= 4007
82452 + .affects_type_identity = true
82453 +#endif
82454 +};
82455 +
82456 +static struct attribute_spec do_const_attr = {
82457 + .name = "do_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_do_const_attribute,
82464 +#if BUILDING_GCC_VERSION >= 4007
82465 + .affects_type_identity = true
82466 +#endif
82467 +};
82468 +
82469 +static void register_attributes(void *event_data, void *data)
82470 +{
82471 + register_attribute(&no_const_attr);
82472 + register_attribute(&do_const_attr);
82473 +}
82474 +
82475 +static bool is_fptr(tree field)
82476 +{
82477 + tree ptr = TREE_TYPE(field);
82478 +
82479 + if (TREE_CODE(ptr) != POINTER_TYPE)
82480 + return false;
82481 +
82482 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82483 +}
82484 +
82485 +static bool walk_struct(tree node)
82486 +{
82487 + tree field;
82488 +
82489 + if (TYPE_FIELDS(node) == NULL_TREE)
82490 + return false;
82491 +
82492 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82493 + gcc_assert(!TYPE_READONLY(node));
82494 + deconstify_type(node);
82495 + return false;
82496 + }
82497 +
82498 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82499 + tree type = TREE_TYPE(field);
82500 + enum tree_code code = TREE_CODE(type);
82501 +
82502 + if (node == type)
82503 + return false;
82504 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82505 + if (!(walk_struct(type)))
82506 + return false;
82507 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82508 + return false;
82509 + }
82510 + return true;
82511 +}
82512 +
82513 +static void finish_type(void *event_data, void *data)
82514 +{
82515 + tree type = (tree)event_data;
82516 +
82517 + if (type == NULL_TREE || type == error_mark_node)
82518 + return;
82519 +
82520 + if (TYPE_READONLY(type))
82521 + return;
82522 +
82523 + if (walk_struct(type))
82524 + constify_type(type);
82525 +}
82526 +
82527 +static unsigned int check_local_variables(void);
82528 +
82529 +struct gimple_opt_pass pass_local_variable = {
82530 + {
82531 + .type = GIMPLE_PASS,
82532 + .name = "check_local_variables",
82533 + .gate = NULL,
82534 + .execute = check_local_variables,
82535 + .sub = NULL,
82536 + .next = NULL,
82537 + .static_pass_number = 0,
82538 + .tv_id = TV_NONE,
82539 + .properties_required = 0,
82540 + .properties_provided = 0,
82541 + .properties_destroyed = 0,
82542 + .todo_flags_start = 0,
82543 + .todo_flags_finish = 0
82544 + }
82545 +};
82546 +
82547 +static unsigned int check_local_variables(void)
82548 +{
82549 + tree var;
82550 + referenced_var_iterator rvi;
82551 +
82552 +#if BUILDING_GCC_VERSION == 4005
82553 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82554 +#else
82555 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82556 +#endif
82557 + tree type = TREE_TYPE(var);
82558 +
82559 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82560 + continue;
82561 +
82562 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82563 + continue;
82564 +
82565 + if (!TYPE_READONLY(type))
82566 + continue;
82567 +
82568 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82569 +// continue;
82570 +
82571 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82572 +// continue;
82573 +
82574 + if (walk_struct(type)) {
82575 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82576 + return 1;
82577 + }
82578 + }
82579 + return 0;
82580 +}
82581 +
82582 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82583 +{
82584 + const char * const plugin_name = plugin_info->base_name;
82585 + const int argc = plugin_info->argc;
82586 + const struct plugin_argument * const argv = plugin_info->argv;
82587 + int i;
82588 + bool constify = true;
82589 +
82590 + struct register_pass_info local_variable_pass_info = {
82591 + .pass = &pass_local_variable.pass,
82592 + .reference_pass_name = "*referenced_vars",
82593 + .ref_pass_instance_number = 1,
82594 + .pos_op = PASS_POS_INSERT_AFTER
82595 + };
82596 +
82597 + if (!plugin_default_version_check(version, &gcc_version)) {
82598 + error(G_("incompatible gcc/plugin versions"));
82599 + return 1;
82600 + }
82601 +
82602 + for (i = 0; i < argc; ++i) {
82603 + if (!(strcmp(argv[i].key, "no-constify"))) {
82604 + constify = false;
82605 + continue;
82606 + }
82607 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82608 + }
82609 +
82610 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82611 + if (constify) {
82612 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82613 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82614 + }
82615 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82616 +
82617 + return 0;
82618 +}
82619 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82620 new file mode 100644
82621 index 0000000..02c6bec
82622 --- /dev/null
82623 +++ b/tools/gcc/generate_size_overflow_hash.sh
82624 @@ -0,0 +1,94 @@
82625 +#!/bin/bash
82626 +
82627 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82628 +
82629 +header1="size_overflow_hash.h"
82630 +database="size_overflow_hash.data"
82631 +n=65536
82632 +
82633 +usage() {
82634 +cat <<EOF
82635 +usage: $0 options
82636 +OPTIONS:
82637 + -h|--help help
82638 + -o header file
82639 + -d database file
82640 + -n hash array size
82641 +EOF
82642 + return 0
82643 +}
82644 +
82645 +while true
82646 +do
82647 + case "$1" in
82648 + -h|--help) usage && exit 0;;
82649 + -n) n=$2; shift 2;;
82650 + -o) header1="$2"; shift 2;;
82651 + -d) database="$2"; shift 2;;
82652 + --) shift 1; break ;;
82653 + *) break ;;
82654 + esac
82655 +done
82656 +
82657 +create_defines() {
82658 + for i in `seq 1 32`
82659 + do
82660 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
82661 + done
82662 + echo >> "$header1"
82663 +}
82664 +
82665 +create_structs () {
82666 + rm -f "$header1"
82667 +
82668 + create_defines
82669 +
82670 + cat "$database" | while read data
82671 + do
82672 + data_array=($data)
82673 + struct_hash_name="${data_array[0]}"
82674 + funcn="${data_array[1]}"
82675 + params="${data_array[2]}"
82676 + next="${data_array[5]}"
82677 +
82678 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
82679 +
82680 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
82681 + echo -en "\t.param\t= " >> "$header1"
82682 + line=
82683 + for param_num in ${params//-/ };
82684 + do
82685 + line="${line}PARAM"$param_num"|"
82686 + done
82687 +
82688 + echo -e "${line%?},\n};\n" >> "$header1"
82689 + done
82690 +}
82691 +
82692 +create_headers () {
82693 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
82694 +}
82695 +
82696 +create_array_elements () {
82697 + index=0
82698 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
82699 + do
82700 + data_array=($data)
82701 + i="${data_array[3]}"
82702 + hash="${data_array[4]}"
82703 + while [[ $index -lt $i ]]
82704 + do
82705 + echo -e "\t["$index"]\t= NULL," >> "$header1"
82706 + index=$(($index + 1))
82707 + done
82708 + index=$(($index + 1))
82709 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
82710 + done
82711 + echo '};' >> $header1
82712 +}
82713 +
82714 +create_structs
82715 +create_headers
82716 +create_array_elements
82717 +
82718 +exit 0
82719 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82720 new file mode 100644
82721 index 0000000..a86e422
82722 --- /dev/null
82723 +++ b/tools/gcc/kallocstat_plugin.c
82724 @@ -0,0 +1,167 @@
82725 +/*
82726 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82727 + * Licensed under the GPL v2
82728 + *
82729 + * Note: the choice of the license means that the compilation process is
82730 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82731 + * but for the kernel it doesn't matter since it doesn't link against
82732 + * any of the gcc libraries
82733 + *
82734 + * gcc plugin to find the distribution of k*alloc sizes
82735 + *
82736 + * TODO:
82737 + *
82738 + * BUGS:
82739 + * - none known
82740 + */
82741 +#include "gcc-plugin.h"
82742 +#include "config.h"
82743 +#include "system.h"
82744 +#include "coretypes.h"
82745 +#include "tree.h"
82746 +#include "tree-pass.h"
82747 +#include "flags.h"
82748 +#include "intl.h"
82749 +#include "toplev.h"
82750 +#include "plugin.h"
82751 +//#include "expr.h" where are you...
82752 +#include "diagnostic.h"
82753 +#include "plugin-version.h"
82754 +#include "tm.h"
82755 +#include "function.h"
82756 +#include "basic-block.h"
82757 +#include "gimple.h"
82758 +#include "rtl.h"
82759 +#include "emit-rtl.h"
82760 +
82761 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82762 +
82763 +int plugin_is_GPL_compatible;
82764 +
82765 +static const char * const kalloc_functions[] = {
82766 + "__kmalloc",
82767 + "kmalloc",
82768 + "kmalloc_large",
82769 + "kmalloc_node",
82770 + "kmalloc_order",
82771 + "kmalloc_order_trace",
82772 + "kmalloc_slab",
82773 + "kzalloc",
82774 + "kzalloc_node",
82775 +};
82776 +
82777 +static struct plugin_info kallocstat_plugin_info = {
82778 + .version = "201111150100",
82779 +};
82780 +
82781 +static unsigned int execute_kallocstat(void);
82782 +
82783 +static struct gimple_opt_pass kallocstat_pass = {
82784 + .pass = {
82785 + .type = GIMPLE_PASS,
82786 + .name = "kallocstat",
82787 + .gate = NULL,
82788 + .execute = execute_kallocstat,
82789 + .sub = NULL,
82790 + .next = NULL,
82791 + .static_pass_number = 0,
82792 + .tv_id = TV_NONE,
82793 + .properties_required = 0,
82794 + .properties_provided = 0,
82795 + .properties_destroyed = 0,
82796 + .todo_flags_start = 0,
82797 + .todo_flags_finish = 0
82798 + }
82799 +};
82800 +
82801 +static bool is_kalloc(const char *fnname)
82802 +{
82803 + size_t i;
82804 +
82805 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82806 + if (!strcmp(fnname, kalloc_functions[i]))
82807 + return true;
82808 + return false;
82809 +}
82810 +
82811 +static unsigned int execute_kallocstat(void)
82812 +{
82813 + basic_block bb;
82814 +
82815 + // 1. loop through BBs and GIMPLE statements
82816 + FOR_EACH_BB(bb) {
82817 + gimple_stmt_iterator gsi;
82818 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82819 + // gimple match:
82820 + tree fndecl, size;
82821 + gimple call_stmt;
82822 + const char *fnname;
82823 +
82824 + // is it a call
82825 + call_stmt = gsi_stmt(gsi);
82826 + if (!is_gimple_call(call_stmt))
82827 + continue;
82828 + fndecl = gimple_call_fndecl(call_stmt);
82829 + if (fndecl == NULL_TREE)
82830 + continue;
82831 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82832 + continue;
82833 +
82834 + // is it a call to k*alloc
82835 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82836 + if (!is_kalloc(fnname))
82837 + continue;
82838 +
82839 + // is the size arg the result of a simple const assignment
82840 + size = gimple_call_arg(call_stmt, 0);
82841 + while (true) {
82842 + gimple def_stmt;
82843 + expanded_location xloc;
82844 + size_t size_val;
82845 +
82846 + if (TREE_CODE(size) != SSA_NAME)
82847 + break;
82848 + def_stmt = SSA_NAME_DEF_STMT(size);
82849 + if (!def_stmt || !is_gimple_assign(def_stmt))
82850 + break;
82851 + if (gimple_num_ops(def_stmt) != 2)
82852 + break;
82853 + size = gimple_assign_rhs1(def_stmt);
82854 + if (!TREE_CONSTANT(size))
82855 + continue;
82856 + xloc = expand_location(gimple_location(def_stmt));
82857 + if (!xloc.file)
82858 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82859 + size_val = TREE_INT_CST_LOW(size);
82860 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82861 + break;
82862 + }
82863 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82864 +//debug_tree(gimple_call_fn(call_stmt));
82865 +//print_node(stderr, "pax", fndecl, 4);
82866 + }
82867 + }
82868 +
82869 + return 0;
82870 +}
82871 +
82872 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82873 +{
82874 + const char * const plugin_name = plugin_info->base_name;
82875 + struct register_pass_info kallocstat_pass_info = {
82876 + .pass = &kallocstat_pass.pass,
82877 + .reference_pass_name = "ssa",
82878 + .ref_pass_instance_number = 1,
82879 + .pos_op = PASS_POS_INSERT_AFTER
82880 + };
82881 +
82882 + if (!plugin_default_version_check(version, &gcc_version)) {
82883 + error(G_("incompatible gcc/plugin versions"));
82884 + return 1;
82885 + }
82886 +
82887 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82888 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82889 +
82890 + return 0;
82891 +}
82892 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82893 new file mode 100644
82894 index 0000000..98011fa
82895 --- /dev/null
82896 +++ b/tools/gcc/kernexec_plugin.c
82897 @@ -0,0 +1,427 @@
82898 +/*
82899 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82900 + * Licensed under the GPL v2
82901 + *
82902 + * Note: the choice of the license means that the compilation process is
82903 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82904 + * but for the kernel it doesn't matter since it doesn't link against
82905 + * any of the gcc libraries
82906 + *
82907 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82908 + *
82909 + * TODO:
82910 + *
82911 + * BUGS:
82912 + * - none known
82913 + */
82914 +#include "gcc-plugin.h"
82915 +#include "config.h"
82916 +#include "system.h"
82917 +#include "coretypes.h"
82918 +#include "tree.h"
82919 +#include "tree-pass.h"
82920 +#include "flags.h"
82921 +#include "intl.h"
82922 +#include "toplev.h"
82923 +#include "plugin.h"
82924 +//#include "expr.h" where are you...
82925 +#include "diagnostic.h"
82926 +#include "plugin-version.h"
82927 +#include "tm.h"
82928 +#include "function.h"
82929 +#include "basic-block.h"
82930 +#include "gimple.h"
82931 +#include "rtl.h"
82932 +#include "emit-rtl.h"
82933 +#include "tree-flow.h"
82934 +
82935 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82936 +extern rtx emit_move_insn(rtx x, rtx y);
82937 +
82938 +int plugin_is_GPL_compatible;
82939 +
82940 +static struct plugin_info kernexec_plugin_info = {
82941 + .version = "201111291120",
82942 + .help = "method=[bts|or]\tinstrumentation method\n"
82943 +};
82944 +
82945 +static unsigned int execute_kernexec_reload(void);
82946 +static unsigned int execute_kernexec_fptr(void);
82947 +static unsigned int execute_kernexec_retaddr(void);
82948 +static bool kernexec_cmodel_check(void);
82949 +
82950 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82951 +static void (*kernexec_instrument_retaddr)(rtx);
82952 +
82953 +static struct gimple_opt_pass kernexec_reload_pass = {
82954 + .pass = {
82955 + .type = GIMPLE_PASS,
82956 + .name = "kernexec_reload",
82957 + .gate = kernexec_cmodel_check,
82958 + .execute = execute_kernexec_reload,
82959 + .sub = NULL,
82960 + .next = NULL,
82961 + .static_pass_number = 0,
82962 + .tv_id = TV_NONE,
82963 + .properties_required = 0,
82964 + .properties_provided = 0,
82965 + .properties_destroyed = 0,
82966 + .todo_flags_start = 0,
82967 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82968 + }
82969 +};
82970 +
82971 +static struct gimple_opt_pass kernexec_fptr_pass = {
82972 + .pass = {
82973 + .type = GIMPLE_PASS,
82974 + .name = "kernexec_fptr",
82975 + .gate = kernexec_cmodel_check,
82976 + .execute = execute_kernexec_fptr,
82977 + .sub = NULL,
82978 + .next = NULL,
82979 + .static_pass_number = 0,
82980 + .tv_id = TV_NONE,
82981 + .properties_required = 0,
82982 + .properties_provided = 0,
82983 + .properties_destroyed = 0,
82984 + .todo_flags_start = 0,
82985 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82986 + }
82987 +};
82988 +
82989 +static struct rtl_opt_pass kernexec_retaddr_pass = {
82990 + .pass = {
82991 + .type = RTL_PASS,
82992 + .name = "kernexec_retaddr",
82993 + .gate = kernexec_cmodel_check,
82994 + .execute = execute_kernexec_retaddr,
82995 + .sub = NULL,
82996 + .next = NULL,
82997 + .static_pass_number = 0,
82998 + .tv_id = TV_NONE,
82999 + .properties_required = 0,
83000 + .properties_provided = 0,
83001 + .properties_destroyed = 0,
83002 + .todo_flags_start = 0,
83003 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83004 + }
83005 +};
83006 +
83007 +static bool kernexec_cmodel_check(void)
83008 +{
83009 + tree section;
83010 +
83011 + if (ix86_cmodel != CM_KERNEL)
83012 + return false;
83013 +
83014 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83015 + if (!section || !TREE_VALUE(section))
83016 + return true;
83017 +
83018 + section = TREE_VALUE(TREE_VALUE(section));
83019 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83020 + return true;
83021 +
83022 + return false;
83023 +}
83024 +
83025 +/*
83026 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83027 + */
83028 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83029 +{
83030 + gimple asm_movabs_stmt;
83031 +
83032 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83033 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83034 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83035 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83036 + update_stmt(asm_movabs_stmt);
83037 +}
83038 +
83039 +/*
83040 + * find all asm() stmts that clobber r10 and add a reload of r10
83041 + */
83042 +static unsigned int execute_kernexec_reload(void)
83043 +{
83044 + basic_block bb;
83045 +
83046 + // 1. loop through BBs and GIMPLE statements
83047 + FOR_EACH_BB(bb) {
83048 + gimple_stmt_iterator gsi;
83049 +
83050 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83051 + // gimple match: __asm__ ("" : : : "r10");
83052 + gimple asm_stmt;
83053 + size_t nclobbers;
83054 +
83055 + // is it an asm ...
83056 + asm_stmt = gsi_stmt(gsi);
83057 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83058 + continue;
83059 +
83060 + // ... clobbering r10
83061 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83062 + while (nclobbers--) {
83063 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83064 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83065 + continue;
83066 + kernexec_reload_fptr_mask(&gsi);
83067 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83068 + break;
83069 + }
83070 + }
83071 + }
83072 +
83073 + return 0;
83074 +}
83075 +
83076 +/*
83077 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83078 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83079 + */
83080 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83081 +{
83082 + gimple assign_intptr, assign_new_fptr, call_stmt;
83083 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83084 +
83085 + call_stmt = gsi_stmt(*gsi);
83086 + old_fptr = gimple_call_fn(call_stmt);
83087 +
83088 + // create temporary unsigned long variable used for bitops and cast fptr to it
83089 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83090 + add_referenced_var(intptr);
83091 + mark_sym_for_renaming(intptr);
83092 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83093 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83094 + update_stmt(assign_intptr);
83095 +
83096 + // apply logical or to temporary unsigned long and bitmask
83097 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83098 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83099 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83100 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83101 + update_stmt(assign_intptr);
83102 +
83103 + // cast temporary unsigned long back to a temporary fptr variable
83104 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83105 + add_referenced_var(new_fptr);
83106 + mark_sym_for_renaming(new_fptr);
83107 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83108 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83109 + update_stmt(assign_new_fptr);
83110 +
83111 + // replace call stmt fn with the new fptr
83112 + gimple_call_set_fn(call_stmt, new_fptr);
83113 + update_stmt(call_stmt);
83114 +}
83115 +
83116 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83117 +{
83118 + gimple asm_or_stmt, call_stmt;
83119 + tree old_fptr, new_fptr, input, output;
83120 + VEC(tree, gc) *inputs = NULL;
83121 + VEC(tree, gc) *outputs = NULL;
83122 +
83123 + call_stmt = gsi_stmt(*gsi);
83124 + old_fptr = gimple_call_fn(call_stmt);
83125 +
83126 + // create temporary fptr variable
83127 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83128 + add_referenced_var(new_fptr);
83129 + mark_sym_for_renaming(new_fptr);
83130 +
83131 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83132 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83133 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83134 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83135 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83136 + VEC_safe_push(tree, gc, inputs, input);
83137 + VEC_safe_push(tree, gc, outputs, output);
83138 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83139 + gimple_asm_set_volatile(asm_or_stmt, true);
83140 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83141 + update_stmt(asm_or_stmt);
83142 +
83143 + // replace call stmt fn with the new fptr
83144 + gimple_call_set_fn(call_stmt, new_fptr);
83145 + update_stmt(call_stmt);
83146 +}
83147 +
83148 +/*
83149 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83150 + */
83151 +static unsigned int execute_kernexec_fptr(void)
83152 +{
83153 + basic_block bb;
83154 +
83155 + // 1. loop through BBs and GIMPLE statements
83156 + FOR_EACH_BB(bb) {
83157 + gimple_stmt_iterator gsi;
83158 +
83159 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83160 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83161 + tree fn;
83162 + gimple call_stmt;
83163 +
83164 + // is it a call ...
83165 + call_stmt = gsi_stmt(gsi);
83166 + if (!is_gimple_call(call_stmt))
83167 + continue;
83168 + fn = gimple_call_fn(call_stmt);
83169 + if (TREE_CODE(fn) == ADDR_EXPR)
83170 + continue;
83171 + if (TREE_CODE(fn) != SSA_NAME)
83172 + gcc_unreachable();
83173 +
83174 + // ... through a function pointer
83175 + fn = SSA_NAME_VAR(fn);
83176 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83177 + continue;
83178 + fn = TREE_TYPE(fn);
83179 + if (TREE_CODE(fn) != POINTER_TYPE)
83180 + continue;
83181 + fn = TREE_TYPE(fn);
83182 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83183 + continue;
83184 +
83185 + kernexec_instrument_fptr(&gsi);
83186 +
83187 +//debug_tree(gimple_call_fn(call_stmt));
83188 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83189 + }
83190 + }
83191 +
83192 + return 0;
83193 +}
83194 +
83195 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83196 +static void kernexec_instrument_retaddr_bts(rtx insn)
83197 +{
83198 + rtx btsq;
83199 + rtvec argvec, constraintvec, labelvec;
83200 + int line;
83201 +
83202 + // create asm volatile("btsq $63,(%%rsp)":::)
83203 + argvec = rtvec_alloc(0);
83204 + constraintvec = rtvec_alloc(0);
83205 + labelvec = rtvec_alloc(0);
83206 + line = expand_location(RTL_LOCATION(insn)).line;
83207 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83208 + MEM_VOLATILE_P(btsq) = 1;
83209 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83210 + emit_insn_before(btsq, insn);
83211 +}
83212 +
83213 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83214 +static void kernexec_instrument_retaddr_or(rtx insn)
83215 +{
83216 + rtx orq;
83217 + rtvec argvec, constraintvec, labelvec;
83218 + int line;
83219 +
83220 + // create asm volatile("orq %%r10,(%%rsp)":::)
83221 + argvec = rtvec_alloc(0);
83222 + constraintvec = rtvec_alloc(0);
83223 + labelvec = rtvec_alloc(0);
83224 + line = expand_location(RTL_LOCATION(insn)).line;
83225 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83226 + MEM_VOLATILE_P(orq) = 1;
83227 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83228 + emit_insn_before(orq, insn);
83229 +}
83230 +
83231 +/*
83232 + * find all asm level function returns and forcibly set the highest bit of the return address
83233 + */
83234 +static unsigned int execute_kernexec_retaddr(void)
83235 +{
83236 + rtx insn;
83237 +
83238 + // 1. find function returns
83239 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83240 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83241 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83242 + rtx body;
83243 +
83244 + // is it a retn
83245 + if (!JUMP_P(insn))
83246 + continue;
83247 + body = PATTERN(insn);
83248 + if (GET_CODE(body) == PARALLEL)
83249 + body = XVECEXP(body, 0, 0);
83250 + if (GET_CODE(body) != RETURN)
83251 + continue;
83252 + kernexec_instrument_retaddr(insn);
83253 + }
83254 +
83255 +// print_simple_rtl(stderr, get_insns());
83256 +// print_rtl(stderr, get_insns());
83257 +
83258 + return 0;
83259 +}
83260 +
83261 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83262 +{
83263 + const char * const plugin_name = plugin_info->base_name;
83264 + const int argc = plugin_info->argc;
83265 + const struct plugin_argument * const argv = plugin_info->argv;
83266 + int i;
83267 + struct register_pass_info kernexec_reload_pass_info = {
83268 + .pass = &kernexec_reload_pass.pass,
83269 + .reference_pass_name = "ssa",
83270 + .ref_pass_instance_number = 1,
83271 + .pos_op = PASS_POS_INSERT_AFTER
83272 + };
83273 + struct register_pass_info kernexec_fptr_pass_info = {
83274 + .pass = &kernexec_fptr_pass.pass,
83275 + .reference_pass_name = "ssa",
83276 + .ref_pass_instance_number = 1,
83277 + .pos_op = PASS_POS_INSERT_AFTER
83278 + };
83279 + struct register_pass_info kernexec_retaddr_pass_info = {
83280 + .pass = &kernexec_retaddr_pass.pass,
83281 + .reference_pass_name = "pro_and_epilogue",
83282 + .ref_pass_instance_number = 1,
83283 + .pos_op = PASS_POS_INSERT_AFTER
83284 + };
83285 +
83286 + if (!plugin_default_version_check(version, &gcc_version)) {
83287 + error(G_("incompatible gcc/plugin versions"));
83288 + return 1;
83289 + }
83290 +
83291 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83292 +
83293 + if (TARGET_64BIT == 0)
83294 + return 0;
83295 +
83296 + for (i = 0; i < argc; ++i) {
83297 + if (!strcmp(argv[i].key, "method")) {
83298 + if (!argv[i].value) {
83299 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83300 + continue;
83301 + }
83302 + if (!strcmp(argv[i].value, "bts")) {
83303 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83304 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83305 + } else if (!strcmp(argv[i].value, "or")) {
83306 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83307 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83308 + fix_register("r10", 1, 1);
83309 + } else
83310 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83311 + continue;
83312 + }
83313 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83314 + }
83315 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83316 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83317 +
83318 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83319 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83320 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83321 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83322 +
83323 + return 0;
83324 +}
83325 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83326 new file mode 100644
83327 index 0000000..b8008f7
83328 --- /dev/null
83329 +++ b/tools/gcc/latent_entropy_plugin.c
83330 @@ -0,0 +1,295 @@
83331 +/*
83332 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83333 + * Licensed under the GPL v2
83334 + *
83335 + * Note: the choice of the license means that the compilation process is
83336 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83337 + * but for the kernel it doesn't matter since it doesn't link against
83338 + * any of the gcc libraries
83339 + *
83340 + * gcc plugin to help generate a little bit of entropy from program state,
83341 + * used during boot in the kernel
83342 + *
83343 + * TODO:
83344 + * - add ipa pass to identify not explicitly marked candidate functions
83345 + * - mix in more program state (function arguments/return values, loop variables, etc)
83346 + * - more instrumentation control via attribute parameters
83347 + *
83348 + * BUGS:
83349 + * - LTO needs -flto-partition=none for now
83350 + */
83351 +#include "gcc-plugin.h"
83352 +#include "config.h"
83353 +#include "system.h"
83354 +#include "coretypes.h"
83355 +#include "tree.h"
83356 +#include "tree-pass.h"
83357 +#include "flags.h"
83358 +#include "intl.h"
83359 +#include "toplev.h"
83360 +#include "plugin.h"
83361 +//#include "expr.h" where are you...
83362 +#include "diagnostic.h"
83363 +#include "plugin-version.h"
83364 +#include "tm.h"
83365 +#include "function.h"
83366 +#include "basic-block.h"
83367 +#include "gimple.h"
83368 +#include "rtl.h"
83369 +#include "emit-rtl.h"
83370 +#include "tree-flow.h"
83371 +
83372 +int plugin_is_GPL_compatible;
83373 +
83374 +static tree latent_entropy_decl;
83375 +
83376 +static struct plugin_info latent_entropy_plugin_info = {
83377 + .version = "201207271820",
83378 + .help = NULL
83379 +};
83380 +
83381 +static unsigned int execute_latent_entropy(void);
83382 +static bool gate_latent_entropy(void);
83383 +
83384 +static struct gimple_opt_pass latent_entropy_pass = {
83385 + .pass = {
83386 + .type = GIMPLE_PASS,
83387 + .name = "latent_entropy",
83388 + .gate = gate_latent_entropy,
83389 + .execute = execute_latent_entropy,
83390 + .sub = NULL,
83391 + .next = NULL,
83392 + .static_pass_number = 0,
83393 + .tv_id = TV_NONE,
83394 + .properties_required = PROP_gimple_leh | PROP_cfg,
83395 + .properties_provided = 0,
83396 + .properties_destroyed = 0,
83397 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83398 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83399 + }
83400 +};
83401 +
83402 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83403 +{
83404 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83405 + *no_add_attrs = true;
83406 + error("%qE attribute only applies to functions", name);
83407 + }
83408 + return NULL_TREE;
83409 +}
83410 +
83411 +static struct attribute_spec latent_entropy_attr = {
83412 + .name = "latent_entropy",
83413 + .min_length = 0,
83414 + .max_length = 0,
83415 + .decl_required = true,
83416 + .type_required = false,
83417 + .function_type_required = false,
83418 + .handler = handle_latent_entropy_attribute,
83419 +#if BUILDING_GCC_VERSION >= 4007
83420 + .affects_type_identity = false
83421 +#endif
83422 +};
83423 +
83424 +static void register_attributes(void *event_data, void *data)
83425 +{
83426 + register_attribute(&latent_entropy_attr);
83427 +}
83428 +
83429 +static bool gate_latent_entropy(void)
83430 +{
83431 + tree latent_entropy_attr;
83432 +
83433 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83434 + return latent_entropy_attr != NULL_TREE;
83435 +}
83436 +
83437 +static unsigned HOST_WIDE_INT seed;
83438 +static unsigned HOST_WIDE_INT get_random_const(void)
83439 +{
83440 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83441 + return seed;
83442 +}
83443 +
83444 +static enum tree_code get_op(tree *rhs)
83445 +{
83446 + static enum tree_code op;
83447 + unsigned HOST_WIDE_INT random_const;
83448 +
83449 + random_const = get_random_const();
83450 +
83451 + switch (op) {
83452 + case BIT_XOR_EXPR:
83453 + op = PLUS_EXPR;
83454 + break;
83455 +
83456 + case PLUS_EXPR:
83457 + if (rhs) {
83458 + op = LROTATE_EXPR;
83459 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83460 + break;
83461 + }
83462 +
83463 + case LROTATE_EXPR:
83464 + default:
83465 + op = BIT_XOR_EXPR;
83466 + break;
83467 + }
83468 + if (rhs)
83469 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83470 + return op;
83471 +}
83472 +
83473 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83474 +{
83475 + gimple_stmt_iterator gsi;
83476 + gimple assign;
83477 + tree addxorrol, rhs;
83478 + enum tree_code op;
83479 +
83480 + op = get_op(&rhs);
83481 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83482 + assign = gimple_build_assign(local_entropy, addxorrol);
83483 + find_referenced_vars_in(assign);
83484 +//debug_bb(bb);
83485 + gsi = gsi_after_labels(bb);
83486 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83487 + update_stmt(assign);
83488 +}
83489 +
83490 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83491 +{
83492 + gimple_stmt_iterator gsi;
83493 + gimple assign;
83494 + tree addxorrol, temp;
83495 +
83496 + // 1. create temporary copy of latent_entropy
83497 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83498 + add_referenced_var(temp);
83499 + mark_sym_for_renaming(temp);
83500 +
83501 + // 2. read...
83502 + assign = gimple_build_assign(temp, latent_entropy_decl);
83503 + find_referenced_vars_in(assign);
83504 + gsi = gsi_after_labels(bb);
83505 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83506 + update_stmt(assign);
83507 +
83508 + // 3. ...modify...
83509 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83510 + assign = gimple_build_assign(temp, addxorrol);
83511 + find_referenced_vars_in(assign);
83512 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83513 + update_stmt(assign);
83514 +
83515 + // 4. ...write latent_entropy
83516 + assign = gimple_build_assign(latent_entropy_decl, temp);
83517 + find_referenced_vars_in(assign);
83518 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83519 + update_stmt(assign);
83520 +}
83521 +
83522 +static unsigned int execute_latent_entropy(void)
83523 +{
83524 + basic_block bb;
83525 + gimple assign;
83526 + gimple_stmt_iterator gsi;
83527 + tree local_entropy;
83528 +
83529 + if (!latent_entropy_decl) {
83530 + struct varpool_node *node;
83531 +
83532 + for (node = varpool_nodes; node; node = node->next) {
83533 + tree var = node->decl;
83534 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83535 + continue;
83536 + latent_entropy_decl = var;
83537 +// debug_tree(var);
83538 + break;
83539 + }
83540 + if (!latent_entropy_decl) {
83541 +// debug_tree(current_function_decl);
83542 + return 0;
83543 + }
83544 + }
83545 +
83546 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83547 +
83548 + // 1. create local entropy variable
83549 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83550 + add_referenced_var(local_entropy);
83551 + mark_sym_for_renaming(local_entropy);
83552 +
83553 + // 2. initialize local entropy variable
83554 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83555 + if (dom_info_available_p(CDI_DOMINATORS))
83556 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83557 + gsi = gsi_start_bb(bb);
83558 +
83559 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83560 +// gimple_set_location(assign, loc);
83561 + find_referenced_vars_in(assign);
83562 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83563 + update_stmt(assign);
83564 + bb = bb->next_bb;
83565 +
83566 + // 3. instrument each BB with an operation on the local entropy variable
83567 + while (bb != EXIT_BLOCK_PTR) {
83568 + perturb_local_entropy(bb, local_entropy);
83569 + bb = bb->next_bb;
83570 + };
83571 +
83572 + // 4. mix local entropy into the global entropy variable
83573 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83574 + return 0;
83575 +}
83576 +
83577 +static void start_unit_callback(void *gcc_data, void *user_data)
83578 +{
83579 +#if BUILDING_GCC_VERSION >= 4007
83580 + seed = get_random_seed(false);
83581 +#else
83582 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83583 + seed *= seed;
83584 +#endif
83585 +
83586 + if (in_lto_p)
83587 + return;
83588 +
83589 + // extern u64 latent_entropy
83590 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83591 +
83592 + TREE_STATIC(latent_entropy_decl) = 1;
83593 + TREE_PUBLIC(latent_entropy_decl) = 1;
83594 + TREE_USED(latent_entropy_decl) = 1;
83595 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83596 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83597 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83598 + DECL_INITIAL(latent_entropy_decl) = NULL;
83599 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83600 +// varpool_finalize_decl(latent_entropy_decl);
83601 +// varpool_mark_needed_node(latent_entropy_decl);
83602 +}
83603 +
83604 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83605 +{
83606 + const char * const plugin_name = plugin_info->base_name;
83607 + struct register_pass_info latent_entropy_pass_info = {
83608 + .pass = &latent_entropy_pass.pass,
83609 + .reference_pass_name = "optimized",
83610 + .ref_pass_instance_number = 1,
83611 + .pos_op = PASS_POS_INSERT_BEFORE
83612 + };
83613 +
83614 + if (!plugin_default_version_check(version, &gcc_version)) {
83615 + error(G_("incompatible gcc/plugin versions"));
83616 + return 1;
83617 + }
83618 +
83619 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83620 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83621 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83622 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83623 +
83624 + return 0;
83625 +}
83626 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83627 new file mode 100644
83628 index 0000000..9332f17
83629 --- /dev/null
83630 +++ b/tools/gcc/size_overflow_hash.data
83631 @@ -0,0 +1,3597 @@
83632 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
83633 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
83634 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
83635 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
83636 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
83637 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
83638 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
83639 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
83640 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
83641 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
83642 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
83643 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
83644 +_000014_hash kmemdup 2 64015 _000014_hash NULL
83645 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
83646 +_000016_hash memdup_user 2 59590 _000016_hash NULL
83647 +_000017_hash module_alloc 1 63630 _000017_hash NULL
83648 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
83649 +_000019_hash read_kcore 3 63488 _000019_hash NULL
83650 +_000020_hash read_ldt 2 47570 _000020_hash NULL
83651 +_000021_hash read_zero 3 19366 _000021_hash NULL
83652 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
83653 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
83654 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
83655 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
83656 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
83657 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
83658 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
83659 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
83660 +_000031_hash adu_write 3 30487 _000031_hash NULL
83661 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
83662 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
83663 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
83664 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
83665 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
83666 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
83667 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
83668 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
83669 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
83670 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
83671 +_000044_hash alloc_context 1 3194 _000044_hash NULL
83672 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
83673 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
83674 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
83675 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
83676 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
83677 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
83678 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
83679 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
83680 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
83681 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
83682 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
83683 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
83684 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
83685 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
83686 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
83687 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
83688 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
83689 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
83690 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
83691 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
83692 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
83693 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
83694 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
83695 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
83696 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
83697 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
83698 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
83699 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
83700 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
83701 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
83702 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
83703 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
83704 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
83705 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
83706 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
83707 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
83708 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
83709 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
83710 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
83711 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
83712 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
83713 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
83714 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
83715 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
83716 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
83717 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
83718 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
83719 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
83720 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
83721 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
83722 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
83723 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
83724 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
83725 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
83726 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
83727 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
83728 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
83729 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
83730 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
83731 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
83732 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
83733 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
83734 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
83735 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
83736 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
83737 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
83738 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
83739 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
83740 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
83741 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
83742 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
83743 +_000122_hash change_xattr 5 61390 _000122_hash NULL
83744 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
83745 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
83746 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
83747 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
83748 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
83749 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
83750 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
83751 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
83752 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
83753 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
83754 +_000133_hash cmm_write 3 2896 _000133_hash NULL
83755 +_000134_hash cm_write 3 36858 _000134_hash NULL
83756 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
83757 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
83758 +_000137_hash command_file_write 3 31318 _000137_hash NULL
83759 +_000138_hash command_write 3 58841 _000138_hash NULL
83760 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
83761 +_000140_hash concat_writev 3 21451 _000140_hash NULL
83762 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
83763 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
83764 +_000143_hash copy_items 6 50140 _000143_hash NULL
83765 +_000144_hash copy_macs 4 45534 _000144_hash NULL
83766 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
83767 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
83768 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
83769 +_000148_hash cosa_write 3 1774 _000148_hash NULL
83770 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
83771 +_000150_hash create_entry 2 33479 _000150_hash NULL
83772 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
83773 +_000153_hash create_xattr 5 54106 _000153_hash NULL
83774 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
83775 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
83776 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
83777 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
83778 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
83779 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
83780 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
83781 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
83782 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
83783 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
83784 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
83785 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
83786 +_000168_hash dev_config 3 8506 _000168_hash NULL
83787 +_000169_hash device_write 3 45156 _000169_hash NULL
83788 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
83789 +_000171_hash devres_alloc 2 551 _000171_hash NULL
83790 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
83791 +_000173_hash direct_entry 3 38836 _000173_hash NULL
83792 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
83793 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
83794 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
83795 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
83796 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
83797 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
83798 +_000180_hash dm_read 3 15674 _000180_hash NULL
83799 +_000181_hash dm_write 3 2513 _000181_hash NULL
83800 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
83801 +_000183_hash dns_query 3 9676 _000183_hash NULL
83802 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
83803 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
83804 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
83805 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
83806 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
83807 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
83808 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
83809 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
83810 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
83811 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
83812 +_000194_hash dsp_write 2 46218 _000194_hash NULL
83813 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
83814 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
83815 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
83816 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
83817 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
83818 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
83819 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
83820 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
83821 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
83822 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
83823 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
83824 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
83825 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
83826 +_000208_hash ep_read 3 58813 _000208_hash NULL
83827 +_000209_hash ep_write 3 59008 _000209_hash NULL
83828 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
83829 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
83830 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
83831 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
83832 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
83833 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
83834 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
83835 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
83836 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
83837 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
83838 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
83839 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
83840 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
83841 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
83842 +_000225_hash fl_create 5 56435 _000225_hash NULL
83843 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
83844 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
83845 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
83846 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
83847 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
83848 +_000231_hash get_arg 3 5694 _000231_hash NULL
83849 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
83850 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
83851 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
83852 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
83853 +_000236_hash get_registers 3 26187 _000236_hash NULL
83854 +_000237_hash get_scq 2 10897 _000237_hash NULL
83855 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
83856 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
83857 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
83858 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
83859 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
83860 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
83861 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
83862 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
83863 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
83864 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
83865 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
83866 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
83867 +_000250_hash handle_request 9 10024 _000250_hash NULL
83868 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
83869 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
83870 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
83871 +_000254_hash heap_init 2 49617 _000254_hash NULL
83872 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
83873 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
83874 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
83875 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
83876 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
83877 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
83878 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
83879 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
83880 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
83881 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
83882 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
83883 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
83884 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
83885 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
83886 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
83887 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
83888 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
83889 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
83890 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
83891 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
83892 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
83893 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
83894 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
83895 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
83896 +_000279_hash if_write 3 51756 _000279_hash NULL
83897 +_000280_hash ilo_write 3 64378 _000280_hash NULL
83898 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
83899 +_000282_hash init_data_container 1 60709 _000282_hash NULL
83900 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
83901 +_000284_hash insert_dent 7 65034 _000284_hash NULL
83902 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
83903 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
83904 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
83905 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
83906 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
83907 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
83908 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
83909 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
83910 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
83911 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
83912 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
83913 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
83914 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
83915 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
83916 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
83917 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
83918 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
83919 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
83920 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
83921 +_000304_hash isdn_read 3 50021 _000304_hash NULL
83922 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
83923 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
83924 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
83925 +_000308_hash iso_callback 3 43208 _000308_hash NULL
83926 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
83927 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
83928 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
83929 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
83930 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
83931 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
83932 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
83933 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
83934 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
83935 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
83936 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
83937 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
83938 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
83939 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
83940 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
83941 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
83942 +_000328_hash kone_receive 4 4690 _000328_hash NULL
83943 +_000329_hash kone_send 4 63435 _000329_hash NULL
83944 +_000330_hash krealloc 2 14908 _000330_hash NULL
83945 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
83946 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
83947 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
83948 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
83949 +_000335_hash kzalloc 1 54740 _000335_hash NULL
83950 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
83951 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
83952 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
83953 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
83954 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
83955 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
83956 +_000342_hash __lgread 4 31668 _000342_hash NULL
83957 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
83958 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
83959 +_000345_hash listxattr 3 12769 _000345_hash NULL
83960 +_000346_hash load_msg 2 95 _000346_hash NULL
83961 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
83962 +_000348_hash lp_write 3 9511 _000348_hash NULL
83963 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
83964 +_000350_hash mce_write 3 26201 _000350_hash NULL
83965 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
83966 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
83967 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
83968 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
83969 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
83970 +_000357_hash mem_rw 3 22085 _000357_hash NULL
83971 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
83972 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
83973 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
83974 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
83975 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
83976 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
83977 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
83978 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
83979 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
83980 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
83981 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
83982 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
83983 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
83984 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
83985 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
83986 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
83987 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
83988 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
83989 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
83990 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
83991 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
83992 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
83993 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
83994 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
83995 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
83996 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
83997 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
83998 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
83999 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84000 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84001 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84002 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84003 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84004 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84005 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84006 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84007 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84008 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84009 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84010 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84011 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84012 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84013 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84014 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84015 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84016 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84017 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84018 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84019 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84020 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84021 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84022 +_000415_hash parse_command 2 37079 _000415_hash NULL
84023 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84024 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84025 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84026 +_000419_hash pg_write 3 40766 _000419_hash NULL
84027 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84028 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84029 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84030 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84031 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84032 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84033 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84034 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84035 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84036 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84037 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84038 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84039 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84040 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84041 +_000434_hash pp_read 3 33210 _000434_hash NULL
84042 +_000435_hash pp_write 3 39554 _000435_hash NULL
84043 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84044 +_000437_hash printer_write 3 60276 _000437_hash NULL
84045 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84046 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84047 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84048 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84049 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84050 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84051 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84052 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84053 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84054 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84055 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84056 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84057 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84058 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84059 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84060 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84061 +_000456_hash pt_write 3 40159 _000456_hash NULL
84062 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84063 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84064 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84065 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84066 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84067 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84068 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84069 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84070 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84071 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84072 +_000467_hash read 3 9397 _000467_hash NULL
84073 +_000468_hash read_buf 2 20469 _000468_hash NULL
84074 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84075 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84076 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84077 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84078 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84079 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84080 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84081 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84082 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84083 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84084 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84085 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84086 +_000481_hash revalidate 2 19043 _000481_hash NULL
84087 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84088 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84089 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84090 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84091 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84092 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84093 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84094 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84095 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84096 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84097 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84098 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84099 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84100 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84101 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84102 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84103 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84104 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84105 +_000500_hash savemem 3 58129 _000500_hash NULL
84106 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84107 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84108 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84109 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84110 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84111 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84112 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84113 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84114 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84115 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84116 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84117 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84118 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84119 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84120 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84121 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84122 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84123 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84124 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84125 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84126 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84127 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84128 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84129 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84130 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84131 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84132 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84133 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84134 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84135 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84136 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84137 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84138 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84139 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84140 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84141 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84142 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84143 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84144 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84145 +_000542_hash set_registers 3 53582 _000542_hash NULL
84146 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84147 +_000544_hash setup_req 3 5848 _000544_hash NULL
84148 +_000545_hash setxattr 4 37006 _000545_hash NULL
84149 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84150 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84151 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84152 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84153 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84154 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84155 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84156 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84157 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84158 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84159 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84160 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84161 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84162 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84163 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84164 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84165 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84166 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84167 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84168 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84169 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84170 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84171 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84172 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84173 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84174 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84175 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84176 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84177 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84178 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84179 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84180 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84181 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84182 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84183 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84184 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84185 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84186 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84187 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84188 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84189 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84190 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84191 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84192 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84193 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84194 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84195 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84196 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84197 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84198 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84199 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84200 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84201 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84202 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84203 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84204 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84205 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84206 +_000606_hash tower_write 3 8580 _000606_hash NULL
84207 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84208 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84209 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84210 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84211 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84212 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84213 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84214 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84215 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84216 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84217 +_000617_hash uea_request 4 47613 _000617_hash NULL
84218 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84219 +_000619_hash uio_write 3 43202 _000619_hash NULL
84220 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84221 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84222 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84223 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84224 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84225 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84226 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84227 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84228 +_000629_hash user_update 3 41332 _000629_hash NULL
84229 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84230 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84231 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84232 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84233 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84234 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84235 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84236 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84237 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84238 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84239 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84240 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84241 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84242 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84243 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84244 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84245 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84246 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84247 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84248 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84249 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84250 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84251 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84252 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84253 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84254 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84255 +_000659_hash write 3 62671 _000659_hash NULL
84256 +_000660_hash write_flush 3 50803 _000660_hash NULL
84257 +_000661_hash write_rio 3 54837 _000661_hash NULL
84258 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84259 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84260 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84261 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84262 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84263 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84264 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84265 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84266 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84267 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84268 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84269 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84270 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84271 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84272 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84273 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84274 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84275 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84276 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84277 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84278 +_000684_hash addtgt 3 54703 _000684_hash NULL
84279 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84280 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84281 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84282 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84283 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84284 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84285 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84286 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84287 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84288 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84289 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84290 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84291 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84292 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84293 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84294 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84295 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84296 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84297 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84298 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84299 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84300 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84301 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84302 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84303 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84304 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84305 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84306 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84307 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84308 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84309 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84310 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84311 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84312 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84313 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84314 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84315 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84316 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84317 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84318 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84319 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84320 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84321 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84322 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84323 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84324 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84325 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84326 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84327 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84328 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84329 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84330 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84331 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84332 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84333 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84334 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84335 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84336 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84337 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84338 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84339 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84340 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84341 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84342 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84343 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84344 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84345 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84346 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84347 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84348 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84349 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84350 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84351 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84352 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84353 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84354 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84355 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84356 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84357 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84358 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84359 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84360 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84361 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84362 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84363 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84364 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84365 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84366 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84367 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84368 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84369 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84370 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84371 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84372 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84373 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84374 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84375 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84376 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84377 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84378 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84379 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84380 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84381 +_000799_hash construct_key 3 11329 _000799_hash NULL
84382 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84383 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84384 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84385 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84386 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84387 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84388 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84389 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84390 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84391 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84392 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84393 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84394 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84395 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84396 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84397 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84398 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84399 +_000819_hash depth_write 3 3021 _000819_hash NULL
84400 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84401 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84402 +_000822_hash dev_write 3 7708 _000822_hash NULL
84403 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84404 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84405 +_000825_hash disconnect 4 32521 _000825_hash NULL
84406 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84407 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84408 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84409 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84410 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84411 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84412 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84413 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84414 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84415 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84416 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84417 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84418 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84419 +_000840_hash do_sync 1 9604 _000840_hash NULL
84420 +_000841_hash dup_array 3 33551 _000841_hash NULL
84421 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84422 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84423 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84424 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84425 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84426 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84427 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84428 +_000849_hash enable_write 3 30456 _000849_hash NULL
84429 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84430 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84431 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84432 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84433 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84434 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84435 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84436 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84437 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84438 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84439 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84440 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84441 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84442 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84443 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84444 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84445 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84446 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84447 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84448 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84449 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84450 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84451 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84452 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84453 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84454 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84455 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84456 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84457 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84458 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84459 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84460 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84461 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84462 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84463 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84464 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84465 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84466 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84467 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84468 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84469 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84470 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84471 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84472 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84473 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84474 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84475 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84476 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84477 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84478 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84479 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84480 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84481 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84482 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84483 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84484 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84485 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84486 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84487 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84488 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84489 +_000915_hash init_q 4 132 _000915_hash NULL
84490 +_000916_hash init_state 2 60165 _000916_hash NULL
84491 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84492 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84493 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84494 +_000920_hash interfaces 2 38859 _000920_hash NULL
84495 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84496 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84497 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84498 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84499 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84500 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84501 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84502 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84503 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84504 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84505 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84506 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84507 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84508 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84509 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84510 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84511 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84512 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84513 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84514 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84515 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84516 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84517 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84518 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84519 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84520 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84521 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84522 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84523 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84524 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84525 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84526 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84527 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84528 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84529 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84530 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84531 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84532 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84533 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84534 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84535 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84536 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84537 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84538 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84539 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84540 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84541 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84542 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84543 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84544 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84545 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84546 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84547 +_000977_hash lc_create 3 48662 _000977_hash NULL
84548 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84549 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84550 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84551 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84552 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84553 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84554 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84555 +_000985_hash mem_read 3 57631 _000985_hash NULL
84556 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84557 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84558 +_000988_hash mem_write 3 22232 _000988_hash NULL
84559 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84560 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84561 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84562 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84563 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84564 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84565 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84566 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84567 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84568 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84569 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84570 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84571 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84572 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84573 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84574 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84575 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84576 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84577 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84578 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84579 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84580 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84581 +_001014_hash new_dir 3 31919 _001014_hash NULL
84582 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84583 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84584 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84585 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84586 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84587 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
84588 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
84589 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
84590 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
84591 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
84592 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
84593 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
84594 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
84595 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
84596 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
84597 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
84598 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
84599 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
84600 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
84601 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
84602 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
84603 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
84604 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
84605 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
84606 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
84607 +_001046_hash osst_write 3 31581 _001046_hash NULL
84608 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
84609 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
84610 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
84611 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
84612 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
84613 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
84614 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
84615 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
84616 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
84617 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
84618 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
84619 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
84620 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
84621 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
84622 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
84623 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
84624 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
84625 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
84626 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
84627 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
84628 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
84629 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
84630 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
84631 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
84632 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
84633 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
84634 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
84635 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
84636 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
84637 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
84638 +_001083_hash proc_write 3 51003 _001083_hash NULL
84639 +_001084_hash profile_load 3 58267 _001084_hash NULL
84640 +_001085_hash profile_remove 3 8556 _001085_hash NULL
84641 +_001086_hash profile_replace 3 14652 _001086_hash NULL
84642 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
84643 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
84644 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
84645 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
84646 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
84647 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
84648 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
84649 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
84650 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
84651 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
84652 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
84653 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
84654 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
84655 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
84656 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
84657 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
84658 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
84659 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
84660 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
84661 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
84662 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
84663 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
84664 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
84665 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
84666 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
84667 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
84668 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
84669 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
84670 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
84671 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
84672 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
84673 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
84674 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
84675 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
84676 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
84677 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
84678 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
84679 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
84680 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
84681 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
84682 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
84683 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
84684 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
84685 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
84686 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
84687 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
84688 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
84689 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
84690 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
84691 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
84692 +_001139_hash self_check_write 5 50856 _001139_hash NULL
84693 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
84694 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
84695 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
84696 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
84697 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
84698 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
84699 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
84700 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
84701 +_001148_hash set_connectable 4 56458 _001148_hash NULL
84702 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
84703 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
84704 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
84705 +_001152_hash setkey 3 14987 _001152_hash NULL
84706 +_001153_hash set_le 4 30581 _001153_hash NULL
84707 +_001154_hash set_link_security 4 4502 _001154_hash NULL
84708 +_001155_hash set_local_name 4 55757 _001155_hash NULL
84709 +_001156_hash set_powered 4 12129 _001156_hash NULL
84710 +_001157_hash set_ssp 4 62411 _001157_hash NULL
84711 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
84712 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
84713 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
84714 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
84715 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
84716 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
84717 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
84718 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
84719 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
84720 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
84721 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
84722 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
84723 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
84724 +_001174_hash skb_pad 2 17302 _001174_hash NULL
84725 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
84726 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
84727 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
84728 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
84729 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
84730 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
84731 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
84732 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
84733 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
84734 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
84735 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
84736 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
84737 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
84738 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
84739 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
84740 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
84741 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
84742 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
84743 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
84744 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
84745 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
84746 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
84747 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
84748 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
84749 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
84750 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
84751 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
84752 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
84753 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
84754 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
84755 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
84756 +_001208_hash sound_write 3 5102 _001208_hash NULL
84757 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
84758 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
84759 +_001213_hash spidev_message 3 5518 _001213_hash NULL
84760 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
84761 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
84762 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
84763 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
84764 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
84765 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
84766 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
84767 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
84768 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
84769 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
84770 +_001227_hash st_write 3 16874 _001227_hash NULL
84771 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
84772 +_001229_hash symtab_init 2 61050 _001229_hash NULL
84773 +_001230_hash sys_bind 3 10799 _001230_hash NULL
84774 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
84775 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
84776 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
84777 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
84778 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
84779 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
84780 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
84781 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
84782 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
84783 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
84784 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
84785 +_001242_hash sys_select 1 38827 _001242_hash NULL
84786 +_001243_hash sys_semop 3 39457 _001243_hash NULL
84787 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
84788 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
84789 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
84790 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
84791 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
84792 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
84793 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
84794 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
84795 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
84796 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
84797 +_001254_hash timeout_write 3 50991 _001254_hash NULL
84798 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
84799 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
84800 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
84801 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
84802 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
84803 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
84804 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
84805 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
84806 +_001264_hash tty_write 3 5494 _001264_hash NULL
84807 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
84808 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
84809 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
84810 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
84811 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
84812 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
84813 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
84814 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
84815 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
84816 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
84817 +_001277_hash vhci_write 3 2224 _001277_hash NULL
84818 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
84819 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
84820 +_001281_hash vmalloc 1 15464 _001281_hash NULL
84821 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
84822 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
84823 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
84824 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
84825 +_001286_hash vzalloc 1 47421 _001286_hash NULL
84826 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
84827 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
84828 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
84829 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
84830 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
84831 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
84832 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
84833 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
84834 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
84835 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
84836 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
84837 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
84838 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
84839 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
84840 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
84841 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
84842 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
84843 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
84844 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
84845 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
84846 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
84847 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
84848 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
84849 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
84850 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
84851 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
84852 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
84853 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
84854 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
84855 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
84856 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
84857 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
84858 +_001319_hash add_child 4 45201 _001319_hash NULL
84859 +_001320_hash add_port 2 54941 _001320_hash NULL
84860 +_001321_hash adu_read 3 24177 _001321_hash NULL
84861 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
84862 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
84863 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
84864 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
84865 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
84866 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
84867 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
84868 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
84869 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
84870 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
84871 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
84872 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
84873 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
84874 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
84875 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
84876 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
84877 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
84878 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
84879 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
84880 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
84881 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
84882 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
84883 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
84884 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
84885 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
84886 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
84887 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
84888 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
84889 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
84890 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
84891 +_001356_hash async_setkey 3 35521 _001356_hash NULL
84892 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
84893 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
84894 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
84895 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
84896 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
84897 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
84898 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
84899 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
84900 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
84901 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
84902 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
84903 +_001370_hash ax25_output 2 22736 _001370_hash NULL
84904 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
84905 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
84906 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
84907 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
84908 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
84909 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
84910 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
84911 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
84912 +_001380_hash bm_init 2 13529 _001380_hash NULL
84913 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
84914 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
84915 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
84916 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
84917 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
84918 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
84919 +_001387_hash cache_read 3 24790 _001387_hash NULL
84920 +_001388_hash cache_write 3 13589 _001388_hash NULL
84921 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
84922 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
84923 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
84924 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
84925 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
84926 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
84927 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
84928 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
84929 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
84930 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
84931 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
84932 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
84933 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
84934 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
84935 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
84936 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
84937 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
84938 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
84939 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
84940 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
84941 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
84942 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
84943 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
84944 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
84945 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
84946 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
84947 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
84948 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
84949 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
84950 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
84951 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
84952 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
84953 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
84954 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
84955 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
84956 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
84957 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
84958 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
84959 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
84960 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
84961 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
84962 +_001435_hash do_readlink 2 43518 _001435_hash NULL
84963 +_001436_hash __do_replace 5 37227 _001436_hash NULL
84964 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
84965 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
84966 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
84967 +_001440_hash dump_midi 3 51040 _001440_hash NULL
84968 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
84969 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
84970 +_001443_hash ep0_read 3 38095 _001443_hash NULL
84971 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
84972 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
84973 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
84974 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
84975 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
84976 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
84977 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
84978 +_001451_hash filldir 3 55137 _001451_hash NULL
84979 +_001452_hash filldir64 3 46469 _001452_hash NULL
84980 +_001453_hash find_skb 2 20431 _001453_hash NULL
84981 +_001454_hash from_buffer 3 18625 _001454_hash NULL
84982 +_001455_hash fsm_init 2 16134 _001455_hash NULL
84983 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
84984 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
84985 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
84986 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
84987 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
84988 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
84989 +_001462_hash get_packet 3 41914 _001462_hash NULL
84990 +_001463_hash get_packet 3 5747 _001463_hash NULL
84991 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
84992 +_001465_hash get_skb 2 63008 _001465_hash NULL
84993 +_001466_hash get_subdir 3 62581 _001466_hash NULL
84994 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
84995 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
84996 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
84997 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
84998 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
84999 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85000 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85001 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85002 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85003 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85004 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85005 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85006 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85007 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85008 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85009 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85010 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85011 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85012 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85013 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85014 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85015 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85016 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85017 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85018 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85019 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85020 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85021 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85022 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85023 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85024 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85025 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85026 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85027 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85028 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85029 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85030 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85031 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85032 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85033 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85034 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85035 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85036 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85037 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85038 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85039 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85040 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85041 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85042 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85043 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85044 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85045 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85046 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85047 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85048 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85049 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85050 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85051 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85052 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85053 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85054 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85055 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85056 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85057 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85058 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85059 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85060 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85061 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85062 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85063 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85064 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85065 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85066 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85067 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85068 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85069 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85070 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85071 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85072 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85073 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85074 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85075 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85076 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85077 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85078 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85079 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85080 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85081 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85082 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85083 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85084 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85085 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85086 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85087 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85088 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85089 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85090 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85091 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85092 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85093 +_001575_hash new_skb 1 21148 _001575_hash NULL
85094 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85095 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85096 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85097 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85098 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85099 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85100 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85101 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85102 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85103 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85104 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85105 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85106 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85107 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85108 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85109 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85110 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85111 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85112 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85113 +_001599_hash override_release 2 52032 _001599_hash NULL
85114 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85115 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85116 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85117 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85118 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85119 +_001605_hash pg_read 3 17276 _001605_hash NULL
85120 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85121 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85122 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85123 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85124 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85125 +_001611_hash printer_read 3 54851 _001611_hash NULL
85126 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85127 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85128 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85129 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85130 +_001616_hash pt_read 3 49136 _001616_hash NULL
85131 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85132 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85133 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85134 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85135 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85136 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85137 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85138 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85139 +_001625_hash read_flush 3 43851 _001625_hash NULL
85140 +_001626_hash read_profile 3 27859 _001626_hash NULL
85141 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85142 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85143 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85144 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85145 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85146 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85147 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85148 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85149 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85150 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85151 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85152 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85153 +_001640_hash rx 4 57944 _001640_hash NULL
85154 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85155 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85156 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85157 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85158 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85159 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85160 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85161 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85162 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85163 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85164 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85165 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85166 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85167 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85168 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85169 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85170 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85171 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85172 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85173 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85174 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85175 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85176 +_001663_hash send_command 4 10832 _001663_hash NULL
85177 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85178 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85179 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85180 +_001667_hash set_arg 3 42824 _001667_hash NULL
85181 +_001668_hash sg_read 3 25799 _001668_hash NULL
85182 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85183 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85184 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85185 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85186 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85187 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85188 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85189 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85190 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85191 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85192 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85193 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85194 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85195 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85196 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85197 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85198 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85199 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85200 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85201 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85202 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85203 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85204 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85205 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85206 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85207 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85208 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85209 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85210 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85211 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85212 +_001704_hash store_msg 3 56417 _001704_hash NULL
85213 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85214 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85215 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85216 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85217 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85218 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85219 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85220 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85221 +_001713_hash syslog_print 2 307 _001713_hash NULL
85222 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85223 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85224 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85225 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85226 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85227 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85228 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85229 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85230 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85231 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85232 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85233 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85234 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85235 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85236 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85237 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85238 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85239 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85240 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85241 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85242 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85243 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85244 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85245 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85246 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85247 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85248 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85249 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85250 +_001746_hash uio_read 3 49300 _001746_hash NULL
85251 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85252 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85253 +_001749_hash unlink1 3 63059 _001749_hash NULL
85254 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85255 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85256 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85257 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85258 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85259 +_001756_hash user_read 3 51881 _001756_hash NULL
85260 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85261 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85262 +_001759_hash venus_create 4 20555 _001759_hash NULL
85263 +_001760_hash venus_link 5 32165 _001760_hash NULL
85264 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85265 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85266 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85267 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85268 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85269 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85270 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85271 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85272 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85273 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85274 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85275 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85276 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85277 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85278 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85279 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85280 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85281 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85282 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85283 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85284 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85285 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85286 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85287 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85288 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85289 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85290 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85291 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85292 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85293 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85294 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85295 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85296 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85297 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85298 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85299 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85300 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85301 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85302 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85303 +_001803_hash add_partition 2 55588 _001803_hash NULL
85304 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85305 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85306 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85307 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85308 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85309 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85310 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85311 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85312 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85313 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85314 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85315 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85316 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85317 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85318 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85319 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85320 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85321 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85322 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85323 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85324 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85325 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85326 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85327 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85328 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85329 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85330 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85331 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85332 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85333 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85334 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85335 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85336 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85337 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85338 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85339 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85340 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85341 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85342 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85343 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85344 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85345 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85346 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85347 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85348 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85349 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85350 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85351 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85352 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85353 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85354 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85355 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85356 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85357 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85358 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85359 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85360 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85361 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85362 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85363 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85364 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85365 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85366 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85367 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85368 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85369 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85370 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85371 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85372 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85373 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85374 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85375 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85376 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85377 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85378 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85379 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85380 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85381 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85382 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85383 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85384 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85385 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85386 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85387 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85388 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85389 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85390 +_001892_hash check_header 2 56930 _001892_hash NULL
85391 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85392 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85393 +_001895_hash console_store 4 36007 _001895_hash NULL
85394 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85395 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85396 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85397 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85398 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85399 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85400 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85401 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85402 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85403 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85404 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85405 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85406 +_001912_hash debug_output 3 18575 _001912_hash NULL
85407 +_001913_hash debug_read 3 19322 _001913_hash NULL
85408 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85409 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85410 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85411 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85412 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85413 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85414 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85415 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85416 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85417 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85418 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85419 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85420 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85421 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85422 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85423 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85424 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85425 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85426 +_001933_hash filter_read 3 61692 _001933_hash NULL
85427 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85428 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85429 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85430 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85431 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85432 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85433 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85434 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85435 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85436 +_001943_hash handle_response 5 55951 _001943_hash NULL
85437 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85438 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85439 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85440 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85441 +_001948_hash help 4 14971 _001948_hash NULL
85442 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85443 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85444 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85445 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85446 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85447 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85448 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85449 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85450 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85451 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85452 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85453 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85454 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85455 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85456 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85457 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85458 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85459 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85460 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85461 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85462 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85463 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85464 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85465 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85466 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85467 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85468 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85469 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85470 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85471 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85472 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85473 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85474 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85475 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85476 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85477 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85478 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85479 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85480 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85481 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85482 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85483 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85484 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85485 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85486 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85487 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85488 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85489 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85490 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85491 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85492 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85493 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85494 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85495 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85496 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85497 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85498 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85499 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85500 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85501 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85502 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85503 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85504 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85505 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85506 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85507 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85508 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85509 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85510 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85511 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85512 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85513 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85514 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85515 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85516 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85517 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85518 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85519 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85520 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85521 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85522 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85523 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85524 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85525 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85526 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85527 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85528 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85529 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85530 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85531 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85532 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85533 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85534 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85535 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85536 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85537 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85538 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85539 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85540 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85541 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85542 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85543 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85544 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85545 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85546 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85547 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85548 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85549 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85550 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85551 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85552 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85553 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85554 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85555 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85556 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85557 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85558 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85559 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85560 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85561 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85562 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85563 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85564 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85565 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85566 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85567 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85568 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85569 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85570 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85571 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85572 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85573 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85574 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85575 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85576 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85577 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85578 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85579 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85580 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85581 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85582 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85583 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85584 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85585 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85586 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85587 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
85588 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
85589 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
85590 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
85591 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
85592 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
85593 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
85594 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
85595 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
85596 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
85597 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
85598 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
85599 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
85600 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
85601 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
85602 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
85603 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
85604 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
85605 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
85606 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
85607 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
85608 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
85609 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
85610 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
85611 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
85612 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
85613 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
85614 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
85615 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
85616 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
85617 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
85618 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
85619 +_002136_hash osst_read 3 40237 _002136_hash NULL
85620 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
85621 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
85622 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
85623 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
85624 +_002143_hash page_readlink 3 23346 _002143_hash NULL
85625 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
85626 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
85627 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
85628 +_002148_hash pep_reply 5 50582 _002148_hash NULL
85629 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
85630 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
85631 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
85632 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
85633 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
85634 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
85635 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
85636 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
85637 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
85638 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
85639 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
85640 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
85641 +_002161_hash proc_read 3 43614 _002161_hash NULL
85642 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
85643 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
85644 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
85645 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
85646 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
85647 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
85648 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
85649 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
85650 +_002170_hash queues_read 3 24877 _002170_hash NULL
85651 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
85652 +_002172_hash rcname_read 3 25919 _002172_hash NULL
85653 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
85654 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
85655 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
85656 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
85657 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
85658 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
85659 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
85660 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
85661 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
85662 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
85663 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
85664 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
85665 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
85666 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
85667 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
85668 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
85669 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
85670 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
85671 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
85672 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
85673 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
85674 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
85675 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
85676 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
85677 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
85678 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
85679 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
85680 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
85681 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
85682 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
85683 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
85684 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
85685 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
85686 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
85687 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
85688 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
85689 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
85690 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
85691 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
85692 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
85693 +_002213_hash receive_packet 2 12367 _002213_hash NULL
85694 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
85695 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
85696 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
85697 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
85698 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
85699 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
85700 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
85701 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
85702 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
85703 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
85704 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
85705 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
85706 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
85707 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
85708 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
85709 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
85710 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
85711 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
85712 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
85713 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
85714 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
85715 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
85716 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
85717 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
85718 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
85719 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
85720 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
85721 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
85722 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
85723 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
85724 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
85725 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
85726 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
85727 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
85728 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
85729 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
85730 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
85731 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
85732 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
85733 +_002254_hash send_msg 4 37323 _002254_hash NULL
85734 +_002255_hash send_packet 4 52960 _002255_hash NULL
85735 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
85736 +_002257_hash sge_rx 3 50594 _002257_hash NULL
85737 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
85738 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
85739 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
85740 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
85741 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
85742 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
85743 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
85744 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
85745 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
85746 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
85747 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
85748 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
85749 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
85750 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
85751 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
85752 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
85753 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
85754 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
85755 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
85756 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
85757 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
85758 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
85759 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
85760 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
85761 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
85762 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
85763 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
85764 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
85765 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
85766 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
85767 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
85768 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
85769 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
85770 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
85771 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
85772 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
85773 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
85774 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
85775 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
85776 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
85777 +_002306_hash st_read 3 51251 _002306_hash NULL
85778 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
85779 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
85780 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
85781 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
85782 +_002311_hash sys_readv 3 50664 _002311_hash NULL
85783 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
85784 +_002313_hash sys_writev 3 28384 _002313_hash NULL
85785 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
85786 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
85787 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
85788 +_002317_hash teiup_create 3 43201 _002317_hash NULL
85789 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
85790 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
85791 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
85792 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
85793 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
85794 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
85795 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
85796 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
85797 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
85798 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
85799 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
85800 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
85801 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
85802 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
85803 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
85804 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
85805 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
85806 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
85807 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
85808 +_002341_hash um_idi_read 3 850 _002341_hash NULL
85809 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
85810 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
85811 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
85812 +_002345_hash use_pool 2 64607 _002345_hash NULL
85813 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
85814 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
85815 +_002348_hash vhci_read 3 47878 _002348_hash NULL
85816 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
85817 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
85818 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
85819 +_002353_hash waiters_read 3 40902 _002353_hash NULL
85820 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
85821 +_002355_hash write_pbl 4 59583 _002355_hash NULL
85822 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
85823 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
85824 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
85825 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
85826 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
85827 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
85828 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
85829 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
85830 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
85831 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
85832 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
85833 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
85834 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
85835 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
85836 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
85837 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
85838 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
85839 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
85840 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
85841 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
85842 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
85843 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
85844 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
85845 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
85846 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
85847 +_002382_hash bioset_create 1 5580 _002382_hash NULL
85848 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
85849 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
85850 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
85851 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
85852 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
85853 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
85854 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
85855 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
85856 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
85857 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
85858 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
85859 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
85860 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
85861 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
85862 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
85863 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
85864 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
85865 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
85866 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
85867 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
85868 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
85869 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
85870 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
85871 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
85872 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
85873 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
85874 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
85875 +_002411_hash depth_read 3 31112 _002411_hash NULL
85876 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
85877 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
85878 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
85879 +_002415_hash divas_write 3 63901 _002415_hash NULL
85880 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
85881 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
85882 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
85883 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
85884 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
85885 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
85886 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
85887 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
85888 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
85889 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
85890 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
85891 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
85892 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
85893 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
85894 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
85895 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
85896 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
85897 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
85898 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
85899 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
85900 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
85901 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
85902 +_002439_hash got_frame 2 16028 _002439_hash NULL
85903 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
85904 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
85905 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
85906 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
85907 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
85908 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
85909 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
85910 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
85911 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
85912 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
85913 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
85914 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
85915 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
85916 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
85917 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
85918 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
85919 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
85920 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
85921 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
85922 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
85923 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
85924 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
85925 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
85926 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
85927 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
85928 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
85929 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
85930 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
85931 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
85932 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
85933 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
85934 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
85935 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
85936 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
85937 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
85938 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
85939 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
85940 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
85941 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
85942 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
85943 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
85944 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
85945 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
85946 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
85947 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
85948 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
85949 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
85950 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
85951 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
85952 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
85953 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
85954 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
85955 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
85956 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
85957 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
85958 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
85959 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
85960 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
85961 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
85962 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
85963 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
85964 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
85965 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
85966 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
85967 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
85968 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
85969 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
85970 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
85971 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
85972 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
85973 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
85974 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
85975 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
85976 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
85977 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
85978 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
85979 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
85980 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
85981 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
85982 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
85983 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
85984 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
85985 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
85986 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
85987 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
85988 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
85989 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
85990 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
85991 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
85992 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
85993 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
85994 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
85995 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
85996 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
85997 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
85998 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
85999 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86000 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86001 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86002 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86003 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86004 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86005 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86006 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86007 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86008 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86009 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86010 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86011 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86012 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86013 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86014 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86015 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86016 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86017 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86018 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86019 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86020 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86021 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86022 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86023 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86024 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86025 +_002570_hash map_addr 6 4666 _002570_hash NULL
86026 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86027 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86028 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86029 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86030 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86031 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86032 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86033 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86034 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86035 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86036 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86037 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86038 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86039 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86040 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86041 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86042 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86043 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86044 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86045 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86046 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86047 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86048 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86049 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86050 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86051 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86052 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86053 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86054 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86055 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86056 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86057 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86058 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86059 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86060 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86061 +_002612_hash power_read 3 15939 _002612_hash NULL
86062 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86063 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86064 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86065 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86066 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86067 +_002618_hash prison_create 1 43623 _002618_hash NULL
86068 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86069 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86070 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86071 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86072 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86073 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86074 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86075 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86076 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86077 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86078 +_002629_hash read_dma 3 55086 _002629_hash NULL
86079 +_002630_hash read_fifo 3 826 _002630_hash NULL
86080 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86081 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86082 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86083 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86084 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86085 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86086 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86087 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86088 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86089 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86090 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86091 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86092 +_002644_hash rx_data 4 60442 _002644_hash NULL
86093 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86094 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86095 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86096 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86097 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86098 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86099 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86100 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86101 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86102 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86103 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86104 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86105 +_002658_hash send_stream 4 3397 _002658_hash NULL
86106 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86107 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86108 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86109 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86110 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86111 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86112 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86113 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86114 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86115 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86116 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86117 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86118 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86119 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86120 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86121 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86122 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86123 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86124 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86125 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86126 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86127 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86128 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86129 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86130 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86131 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86132 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86133 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86134 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86135 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86136 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86137 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86138 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86139 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86140 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86141 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86142 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86143 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86144 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86145 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86146 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86147 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86148 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86149 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86150 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86151 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86152 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86153 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86154 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86155 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86156 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86157 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86158 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86159 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86160 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86161 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86162 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86163 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86164 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86165 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86166 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86167 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86168 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86169 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86170 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86171 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86172 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86173 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86174 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86175 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86176 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86177 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86178 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86179 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86180 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86181 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86182 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86183 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86184 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86185 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86186 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86187 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86188 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86189 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86190 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86191 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86192 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86193 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86194 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86195 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86196 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86197 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86198 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86199 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86200 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86201 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86202 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86203 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86204 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86205 +_002770_hash push_rx 3 28939 _002770_hash NULL
86206 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86207 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86208 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86209 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86210 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86211 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86212 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86213 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86214 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86215 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86216 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86217 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86218 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86219 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86220 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86221 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86222 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86223 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86224 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86225 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86226 +_002794_hash write_leb 5 36957 _002794_hash NULL
86227 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86228 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86229 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86230 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86231 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86232 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86233 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86234 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86235 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86236 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86237 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86238 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86239 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86240 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86241 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86242 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86243 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86244 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86245 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86246 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86247 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86248 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86249 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86250 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86251 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86252 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86253 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86254 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86255 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86256 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86257 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86258 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86259 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86260 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86261 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86262 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86263 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86264 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86265 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86266 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86267 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86268 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86269 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86270 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86271 +_002846_hash recover_head 3 17904 _002846_hash NULL
86272 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86273 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86274 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86275 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86276 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86277 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86278 +_002853_hash write_head 4 30481 _002853_hash NULL
86279 +_002854_hash write_node 4 33121 _002854_hash NULL
86280 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86281 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86282 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86283 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86284 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86285 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86286 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86287 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86288 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86289 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86290 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86291 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86292 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86293 +_002869_hash create_log 2 8225 _002869_hash NULL
86294 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86295 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86296 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86297 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86298 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86299 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86300 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86301 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86302 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86303 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86304 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86305 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86306 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86307 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86308 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86309 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86310 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86311 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86312 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86313 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86314 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86315 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86316 +_002893_hash _malloc 1 54077 _002893_hash NULL
86317 +_002894_hash mei_read 3 6507 _002894_hash NULL
86318 +_002895_hash mei_write 3 4005 _002895_hash NULL
86319 +_002896_hash msg_set 3 51725 _002896_hash NULL
86320 +_002897_hash newpart 6 47485 _002897_hash NULL
86321 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86322 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86323 +_002900_hash packet_came 3 18072 _002900_hash NULL
86324 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86325 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86326 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86327 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86328 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86329 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86330 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86331 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86332 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86333 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86334 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86335 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86336 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86337 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86338 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86339 +_002923_hash sep_read 3 17161 _002923_hash NULL
86340 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86341 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86342 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86343 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86344 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86345 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86346 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86347 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86348 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86349 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86350 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86351 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86352 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86353 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86354 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86355 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86356 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86357 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86358 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86359 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86360 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86361 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86362 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86363 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86364 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86365 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86366 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86367 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86368 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86369 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86370 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86371 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86372 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86373 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86374 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86375 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86376 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86377 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86378 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86379 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86380 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86381 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86382 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86383 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86384 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86385 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86386 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86387 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86388 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86389 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86390 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86391 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86392 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86393 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86394 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86395 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86396 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86397 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86398 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86399 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86400 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86401 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86402 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86403 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86404 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86405 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86406 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86407 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86408 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86409 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86410 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86411 +_003003_hash flash_read 3 57843 _003003_hash NULL
86412 +_003004_hash flash_write 3 62354 _003004_hash NULL
86413 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86414 +_003006_hash gather_array 3 56641 _003006_hash NULL
86415 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86416 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86417 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86418 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86419 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86420 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86421 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86422 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86423 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86424 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86425 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86426 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86427 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86428 +_003021_hash options_write 3 47243 _003021_hash NULL
86429 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86430 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86431 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86432 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86433 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86434 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86435 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86436 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86437 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86438 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86439 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86440 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86441 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86442 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86443 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86444 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86445 +_003038_hash split 2 11691 _003038_hash NULL
86446 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86447 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86448 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86449 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86450 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86451 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86452 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86453 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86454 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86455 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86456 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86457 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86458 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86459 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86460 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86461 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86462 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86463 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86464 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86465 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86466 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86467 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86468 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86469 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86470 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86471 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86472 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86473 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86474 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86475 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86476 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86477 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86478 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86479 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86480 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86481 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86482 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86483 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86484 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86485 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86486 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86487 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86488 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86489 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86490 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86491 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86492 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86493 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86494 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86495 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86496 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86497 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86498 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86499 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86500 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86501 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86502 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86503 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86504 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86505 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86506 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86507 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86508 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86509 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86510 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86511 +_003108_hash conf_read 3 55786 _003108_hash NULL
86512 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86513 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86514 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86515 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86516 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86517 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86518 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86519 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86520 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86521 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86522 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86523 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86524 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86525 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86526 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86527 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86528 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86529 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86530 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86531 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86532 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86533 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86534 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86535 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86536 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86537 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86538 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86539 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86540 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86541 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86542 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86543 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86544 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86545 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86546 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86547 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86548 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86549 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86550 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86551 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86552 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86553 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86554 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86555 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86556 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86557 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86558 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86559 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86560 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86561 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86562 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86563 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86564 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86565 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86566 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86567 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86568 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86569 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86570 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86571 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86572 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86573 +_003175_hash get_info 3 55681 _003175_hash NULL
86574 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86575 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86576 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86577 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86578 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86579 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86580 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86581 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86582 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86583 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86584 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86585 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86586 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86587 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
86588 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
86589 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
86590 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
86591 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
86592 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
86593 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
86594 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
86595 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
86596 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
86597 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
86598 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
86599 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
86600 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
86601 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
86602 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
86603 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
86604 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
86605 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
86606 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
86607 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
86608 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
86609 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
86610 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
86611 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
86612 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
86613 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
86614 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
86615 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
86616 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
86617 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
86618 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
86619 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
86620 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
86621 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
86622 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
86623 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
86624 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
86625 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
86626 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
86627 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
86628 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
86629 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
86630 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
86631 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
86632 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
86633 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
86634 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
86635 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
86636 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
86637 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
86638 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
86639 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
86640 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
86641 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
86642 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
86643 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
86644 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
86645 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
86646 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
86647 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
86648 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
86649 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
86650 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
86651 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
86652 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
86653 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
86654 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
86655 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
86656 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
86657 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
86658 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
86659 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
86660 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
86661 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
86662 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
86663 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
86664 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
86665 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
86666 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
86667 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
86668 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
86669 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
86670 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
86671 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
86672 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
86673 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
86674 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
86675 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
86676 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
86677 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
86678 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
86679 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
86680 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
86681 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
86682 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
86683 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
86684 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
86685 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
86686 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
86687 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
86688 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
86689 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
86690 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
86691 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
86692 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
86693 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
86694 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
86695 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
86696 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
86697 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
86698 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
86699 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
86700 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
86701 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
86702 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
86703 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
86704 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
86705 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
86706 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
86707 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
86708 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
86709 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
86710 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
86711 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
86712 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
86713 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
86714 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
86715 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
86716 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
86717 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
86718 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
86719 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
86720 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
86721 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
86722 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
86723 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
86724 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
86725 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
86726 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
86727 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
86728 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
86729 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
86730 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
86731 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
86732 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
86733 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
86734 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
86735 +_003340_hash alloc_private 2 22399 _003340_hash NULL
86736 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
86737 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
86738 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
86739 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
86740 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
86741 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
86742 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
86743 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
86744 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
86745 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
86746 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
86747 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
86748 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
86749 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
86750 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
86751 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
86752 +_003359_hash comedi_read 3 13199 _003359_hash NULL
86753 +_003360_hash comedi_write 3 47926 _003360_hash NULL
86754 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
86755 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
86756 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
86757 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
86758 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
86759 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
86760 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
86761 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
86762 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
86763 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
86764 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
86765 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
86766 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
86767 +_003377_hash dev_read 3 56369 _003377_hash NULL
86768 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
86769 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
86770 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
86771 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
86772 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
86773 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
86774 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
86775 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
86776 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
86777 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
86778 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
86779 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
86780 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
86781 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
86782 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
86783 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
86784 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
86785 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
86786 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
86787 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
86788 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
86789 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
86790 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
86791 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
86792 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
86793 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
86794 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
86795 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
86796 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
86797 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
86798 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
86799 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
86800 +_003412_hash fb_read 3 33506 _003412_hash NULL
86801 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
86802 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
86803 +_003415_hash fb_write 3 46924 _003415_hash NULL
86804 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
86805 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
86806 +_003418_hash fops_read 3 40672 _003418_hash NULL
86807 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
86808 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
86809 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
86810 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
86811 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
86812 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
86813 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
86814 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
86815 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
86816 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
86817 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
86818 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
86819 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
86820 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
86821 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
86822 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
86823 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
86824 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
86825 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
86826 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
86827 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
86828 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
86829 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
86830 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
86831 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
86832 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
86833 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
86834 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
86835 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
86836 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
86837 +_003451_hash lirc_write 3 20604 _003451_hash NULL
86838 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
86839 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
86840 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
86841 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
86842 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
86843 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
86844 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
86845 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
86846 +_003461_hash mmio_read 4 40348 _003461_hash NULL
86847 +_003462_hash netlink_send 5 38434 _003462_hash NULL
86848 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
86849 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
86850 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
86851 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
86852 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
86853 +_003468_hash odev_update 2 50169 _003468_hash NULL
86854 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
86855 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
86856 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
86857 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
86858 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
86859 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
86860 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
86861 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
86862 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
86863 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
86864 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
86865 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
86866 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
86867 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
86868 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
86869 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
86870 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
86871 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
86872 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
86873 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
86874 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
86875 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
86876 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
86877 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
86878 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
86879 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
86880 +_003497_hash play_iframe 3 8219 _003497_hash NULL
86881 +_003498_hash probes_write 3 29711 _003498_hash NULL
86882 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
86883 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
86884 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
86885 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
86886 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
86887 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
86888 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
86889 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
86890 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
86891 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
86892 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
86893 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
86894 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
86895 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
86896 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
86897 +_003514_hash qc_capture 3 19298 _003514_hash NULL
86898 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
86899 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
86900 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
86901 +_003518_hash Realloc 2 34961 _003518_hash NULL
86902 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
86903 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
86904 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
86905 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
86906 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
86907 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
86908 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
86909 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
86910 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
86911 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
86912 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
86913 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
86914 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
86915 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
86916 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
86917 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
86918 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
86919 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
86920 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
86921 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
86922 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
86923 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
86924 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
86925 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
86926 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
86927 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
86928 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
86929 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
86930 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
86931 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
86932 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
86933 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
86934 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
86935 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
86936 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
86937 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
86938 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
86939 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
86940 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
86941 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
86942 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
86943 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
86944 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
86945 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
86946 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
86947 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
86948 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
86949 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
86950 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
86951 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
86952 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
86953 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
86954 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
86955 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
86956 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
86957 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
86958 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
86959 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
86960 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
86961 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
86962 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
86963 +_003584_hash ts_read 3 44687 _003584_hash NULL
86964 +_003585_hash ts_write 3 64336 _003585_hash NULL
86965 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
86966 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
86967 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
86968 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
86969 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
86970 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
86971 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
86972 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
86973 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
86974 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
86975 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
86976 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
86977 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
86978 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
86979 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
86980 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
86981 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
86982 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
86983 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
86984 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
86985 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
86986 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
86987 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
86988 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
86989 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
86990 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
86991 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
86992 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
86993 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
86994 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
86995 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
86996 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
86997 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
86998 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
86999 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87000 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87001 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87002 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87003 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87004 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87005 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87006 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87007 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87008 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87009 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87010 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87011 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87012 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87013 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87014 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87015 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87016 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87017 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87018 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87019 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87020 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87021 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87022 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87023 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87024 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87025 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87026 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87027 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87028 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87029 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87030 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87031 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87032 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87033 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87034 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87035 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87036 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87037 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87038 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87039 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87040 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87041 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87042 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87043 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87044 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87045 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87046 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87047 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87048 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87049 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87050 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87051 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87052 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87053 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87054 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87055 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87056 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87057 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87058 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87059 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87060 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87061 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87062 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87063 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87064 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87065 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87066 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87067 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87068 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87069 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87070 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87071 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87072 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87073 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87074 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87075 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87076 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87077 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87078 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87079 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87080 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87081 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87082 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87083 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87084 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87085 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87086 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87087 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87088 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87089 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87090 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87091 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87092 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87093 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87094 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87095 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87096 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87097 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87098 +_003729_hash vmap 2 15025 _003729_hash NULL
87099 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87100 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87101 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87102 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87103 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87104 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87105 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87106 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87107 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87108 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87109 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87110 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87111 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87112 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87113 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87114 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87115 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87116 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87117 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87118 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87119 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87120 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87121 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87122 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87123 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87124 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87125 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87126 +_003766_hash video_read 3 28148 _003766_hash NULL
87127 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87128 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87129 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87130 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87131 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87132 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87133 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87134 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87135 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87136 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87137 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87138 +_003783_hash do_test 1 15766 _003783_hash NULL
87139 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87140 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87141 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87142 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87143 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87144 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87145 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87146 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87147 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87148 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87149 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87150 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87151 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87152 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87153 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87154 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87155 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87156 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87157 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87158 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87159 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87160 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87161 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87162 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87163 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87164 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87165 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87166 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87167 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87168 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87169 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87170 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87171 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87172 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87173 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87174 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87175 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87176 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87177 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87178 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87179 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87180 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87181 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87182 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87183 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87184 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87185 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87186 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87187 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87188 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87189 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87190 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87191 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87192 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87193 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87194 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87195 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87196 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87197 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87198 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87199 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87200 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87201 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87202 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87203 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87204 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87205 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87206 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87207 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87208 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87209 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87210 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87211 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87212 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87213 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87214 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87215 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87216 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87217 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87218 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87219 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87220 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87221 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87222 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87223 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87224 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87225 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87226 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87227 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87228 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87229 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87230 new file mode 100644
87231 index 0000000..244559e
87232 --- /dev/null
87233 +++ b/tools/gcc/size_overflow_plugin.c
87234 @@ -0,0 +1,1879 @@
87235 +/*
87236 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87237 + * Licensed under the GPL v2, or (at your option) v3
87238 + *
87239 + * Homepage:
87240 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87241 + *
87242 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87243 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87244 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87245 + *
87246 + * Usage:
87247 + * $ 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
87248 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87249 + */
87250 +
87251 +#include "gcc-plugin.h"
87252 +#include "config.h"
87253 +#include "system.h"
87254 +#include "coretypes.h"
87255 +#include "tree.h"
87256 +#include "tree-pass.h"
87257 +#include "intl.h"
87258 +#include "plugin-version.h"
87259 +#include "tm.h"
87260 +#include "toplev.h"
87261 +#include "function.h"
87262 +#include "tree-flow.h"
87263 +#include "plugin.h"
87264 +#include "gimple.h"
87265 +#include "c-common.h"
87266 +#include "diagnostic.h"
87267 +#include "cfgloop.h"
87268 +
87269 +#if BUILDING_GCC_VERSION >= 4007
87270 +#include "c-tree.h"
87271 +#else
87272 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87273 +#endif
87274 +
87275 +struct size_overflow_hash {
87276 + const struct size_overflow_hash * const next;
87277 + const char * const name;
87278 + const unsigned int param;
87279 +};
87280 +
87281 +#include "size_overflow_hash.h"
87282 +
87283 +enum marked {
87284 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87285 +};
87286 +
87287 +#define __unused __attribute__((__unused__))
87288 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87289 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87290 +#define BEFORE_STMT true
87291 +#define AFTER_STMT false
87292 +#define CREATE_NEW_VAR NULL_TREE
87293 +#define CODES_LIMIT 32
87294 +#define MAX_PARAM 32
87295 +#define MY_STMT GF_PLF_1
87296 +#define NO_CAST_CHECK GF_PLF_2
87297 +
87298 +#if BUILDING_GCC_VERSION == 4005
87299 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87300 +#endif
87301 +
87302 +int plugin_is_GPL_compatible;
87303 +void debug_gimple_stmt(gimple gs);
87304 +
87305 +static tree expand(struct pointer_set_t *visited, tree lhs);
87306 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87307 +static tree report_size_overflow_decl;
87308 +static const_tree const_char_ptr_type_node;
87309 +static unsigned int handle_function(void);
87310 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87311 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87312 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87313 +
87314 +static struct plugin_info size_overflow_plugin_info = {
87315 + .version = "20120930beta",
87316 + .help = "no-size-overflow\tturn off size overflow checking\n",
87317 +};
87318 +
87319 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87320 +{
87321 + unsigned int arg_count;
87322 + enum tree_code code = TREE_CODE(*node);
87323 +
87324 + switch (code) {
87325 + case FUNCTION_DECL:
87326 + arg_count = type_num_arguments(TREE_TYPE(*node));
87327 + break;
87328 + case FUNCTION_TYPE:
87329 + case METHOD_TYPE:
87330 + arg_count = type_num_arguments(*node);
87331 + break;
87332 + default:
87333 + *no_add_attrs = true;
87334 + error("%s: %qE attribute only applies to functions", __func__, name);
87335 + return NULL_TREE;
87336 + }
87337 +
87338 + for (; args; args = TREE_CHAIN(args)) {
87339 + tree position = TREE_VALUE(args);
87340 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87341 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87342 + *no_add_attrs = true;
87343 + }
87344 + }
87345 + return NULL_TREE;
87346 +}
87347 +
87348 +static const char* get_asm_name(tree node)
87349 +{
87350 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87351 +}
87352 +
87353 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87354 +{
87355 + unsigned int arg_count, arg_num;
87356 + enum tree_code code = TREE_CODE(*node);
87357 +
87358 + switch (code) {
87359 + case FUNCTION_DECL:
87360 + arg_count = type_num_arguments(TREE_TYPE(*node));
87361 + break;
87362 + case FUNCTION_TYPE:
87363 + case METHOD_TYPE:
87364 + arg_count = type_num_arguments(*node);
87365 + break;
87366 + case FIELD_DECL:
87367 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87368 + if (arg_num != 0) {
87369 + *no_add_attrs = true;
87370 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87371 + }
87372 + return NULL_TREE;
87373 + default:
87374 + *no_add_attrs = true;
87375 + error("%qE attribute only applies to functions", name);
87376 + return NULL_TREE;
87377 + }
87378 +
87379 + for (; args; args = TREE_CHAIN(args)) {
87380 + tree position = TREE_VALUE(args);
87381 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87382 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87383 + *no_add_attrs = true;
87384 + }
87385 + }
87386 + return NULL_TREE;
87387 +}
87388 +
87389 +static struct attribute_spec size_overflow_attr = {
87390 + .name = "size_overflow",
87391 + .min_length = 1,
87392 + .max_length = -1,
87393 + .decl_required = true,
87394 + .type_required = false,
87395 + .function_type_required = false,
87396 + .handler = handle_size_overflow_attribute,
87397 +#if BUILDING_GCC_VERSION >= 4007
87398 + .affects_type_identity = false
87399 +#endif
87400 +};
87401 +
87402 +static struct attribute_spec intentional_overflow_attr = {
87403 + .name = "intentional_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_intentional_overflow_attribute,
87410 +#if BUILDING_GCC_VERSION >= 4007
87411 + .affects_type_identity = false
87412 +#endif
87413 +};
87414 +
87415 +static void register_attributes(void __unused *event_data, void __unused *data)
87416 +{
87417 + register_attribute(&size_overflow_attr);
87418 + register_attribute(&intentional_overflow_attr);
87419 +}
87420 +
87421 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87422 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87423 +{
87424 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87425 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87426 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87427 +
87428 + unsigned int m = 0x57559429;
87429 + unsigned int n = 0x5052acdb;
87430 + const unsigned int *key4 = (const unsigned int *)key;
87431 + unsigned int h = len;
87432 + unsigned int k = len + seed + n;
87433 + unsigned long long p;
87434 +
87435 + while (len >= 8) {
87436 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87437 + len -= 8;
87438 + }
87439 + if (len >= 4) {
87440 + cwmixb(key4[0]) key4 += 1;
87441 + len -= 4;
87442 + }
87443 + if (len)
87444 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87445 + cwmixb(h ^ (k + n));
87446 + return k ^ h;
87447 +
87448 +#undef cwfold
87449 +#undef cwmixa
87450 +#undef cwmixb
87451 +}
87452 +
87453 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87454 +{
87455 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87456 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87457 + return fn ^ codes;
87458 +}
87459 +
87460 +static inline tree get_original_function_decl(tree fndecl)
87461 +{
87462 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87463 + return DECL_ABSTRACT_ORIGIN(fndecl);
87464 + return fndecl;
87465 +}
87466 +
87467 +static inline gimple get_def_stmt(const_tree node)
87468 +{
87469 + gcc_assert(node != NULL_TREE);
87470 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87471 + return SSA_NAME_DEF_STMT(node);
87472 +}
87473 +
87474 +static unsigned char get_tree_code(const_tree type)
87475 +{
87476 + switch (TREE_CODE(type)) {
87477 + case ARRAY_TYPE:
87478 + return 0;
87479 + case BOOLEAN_TYPE:
87480 + return 1;
87481 + case ENUMERAL_TYPE:
87482 + return 2;
87483 + case FUNCTION_TYPE:
87484 + return 3;
87485 + case INTEGER_TYPE:
87486 + return 4;
87487 + case POINTER_TYPE:
87488 + return 5;
87489 + case RECORD_TYPE:
87490 + return 6;
87491 + case UNION_TYPE:
87492 + return 7;
87493 + case VOID_TYPE:
87494 + return 8;
87495 + case REAL_TYPE:
87496 + return 9;
87497 + case VECTOR_TYPE:
87498 + return 10;
87499 + case REFERENCE_TYPE:
87500 + return 11;
87501 + case OFFSET_TYPE:
87502 + return 12;
87503 + case COMPLEX_TYPE:
87504 + return 13;
87505 + default:
87506 + debug_tree((tree)type);
87507 + gcc_unreachable();
87508 + }
87509 +}
87510 +
87511 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87512 +{
87513 + gcc_assert(type != NULL_TREE);
87514 +
87515 + while (type && len < CODES_LIMIT) {
87516 + tree_codes[len] = get_tree_code(type);
87517 + len++;
87518 + type = TREE_TYPE(type);
87519 + }
87520 + return len;
87521 +}
87522 +
87523 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87524 +{
87525 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87526 + enum tree_code code = TREE_CODE(type);
87527 + size_t len = 0;
87528 +
87529 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87530 +
87531 + arg = TYPE_ARG_TYPES(type);
87532 + // skip builtins __builtin_constant_p
87533 + if (!arg && DECL_BUILT_IN(fndecl))
87534 + return 0;
87535 +
87536 + if (TREE_CODE_CLASS(code) == tcc_type)
87537 + result = type;
87538 + else
87539 + result = DECL_RESULT(fndecl);
87540 +
87541 + gcc_assert(result != NULL_TREE);
87542 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87543 +
87544 + if (arg == NULL_TREE) {
87545 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87546 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87547 + if (arg_field == NULL_TREE)
87548 + return 0;
87549 + arg = TREE_TYPE(arg_field);
87550 + len = add_type_codes(arg, tree_codes, len);
87551 + gcc_assert(len != 0);
87552 + return len;
87553 + }
87554 +
87555 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87556 + while (arg && len < CODES_LIMIT) {
87557 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87558 + arg = TREE_CHAIN(arg);
87559 + }
87560 +
87561 + gcc_assert(len != 0);
87562 + return len;
87563 +}
87564 +
87565 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87566 +{
87567 + unsigned int hash;
87568 + const struct size_overflow_hash *entry;
87569 + unsigned char tree_codes[CODES_LIMIT];
87570 + size_t len;
87571 + const char *func_name = get_asm_name(fndecl);
87572 +
87573 + len = get_function_decl(fndecl, tree_codes);
87574 + if (len == 0)
87575 + return NULL;
87576 +
87577 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87578 +
87579 + entry = size_overflow_hash[hash];
87580 + while (entry) {
87581 + if (!strcmp(entry->name, func_name))
87582 + return entry;
87583 + entry = entry->next;
87584 + }
87585 +
87586 + return NULL;
87587 +}
87588 +
87589 +static void check_arg_type(const_tree arg)
87590 +{
87591 + const_tree type = TREE_TYPE(arg);
87592 + enum tree_code code = TREE_CODE(type);
87593 +
87594 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
87595 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
87596 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
87597 +}
87598 +
87599 +static int find_arg_number(const_tree arg, tree func)
87600 +{
87601 + tree var;
87602 + unsigned int argnum = 1;
87603 +
87604 + if (TREE_CODE(arg) == SSA_NAME)
87605 + arg = SSA_NAME_VAR(arg);
87606 +
87607 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
87608 + if (strcmp(NAME(arg), NAME(var))) {
87609 + argnum++;
87610 + continue;
87611 + }
87612 + check_arg_type(var);
87613 + return argnum;
87614 + }
87615 + gcc_unreachable();
87616 +}
87617 +
87618 +static tree create_new_var(tree type)
87619 +{
87620 + tree new_var = create_tmp_var(type, "cicus");
87621 +
87622 + add_referenced_var(new_var);
87623 + mark_sym_for_renaming(new_var);
87624 + return new_var;
87625 +}
87626 +
87627 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
87628 +{
87629 + gimple assign;
87630 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87631 + tree type = TREE_TYPE(rhs1);
87632 + tree lhs = create_new_var(type);
87633 +
87634 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
87635 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87636 +
87637 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87638 + update_stmt(assign);
87639 + gimple_set_plf(assign, MY_STMT, true);
87640 + return assign;
87641 +}
87642 +
87643 +static bool is_bool(const_tree node)
87644 +{
87645 + const_tree type;
87646 +
87647 + if (node == NULL_TREE)
87648 + return false;
87649 +
87650 + type = TREE_TYPE(node);
87651 + if (!INTEGRAL_TYPE_P(type))
87652 + return false;
87653 + if (TREE_CODE(type) == BOOLEAN_TYPE)
87654 + return true;
87655 + if (TYPE_PRECISION(type) == 1)
87656 + return true;
87657 + return false;
87658 +}
87659 +
87660 +static tree cast_a_tree(tree type, tree var)
87661 +{
87662 + gcc_assert(type != NULL_TREE);
87663 + gcc_assert(var != NULL_TREE);
87664 + gcc_assert(fold_convertible_p(type, var));
87665 +
87666 + return fold_convert(type, var);
87667 +}
87668 +
87669 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
87670 +{
87671 + gimple assign;
87672 +
87673 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
87674 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
87675 + gcc_unreachable();
87676 +
87677 + if (lhs == CREATE_NEW_VAR)
87678 + lhs = create_new_var(dst_type);
87679 +
87680 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
87681 +
87682 + if (!gsi_end_p(*gsi)) {
87683 + location_t loc = gimple_location(gsi_stmt(*gsi));
87684 + gimple_set_location(assign, loc);
87685 + }
87686 +
87687 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87688 +
87689 + if (before)
87690 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
87691 + else
87692 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
87693 + update_stmt(assign);
87694 + gimple_set_plf(assign, MY_STMT, true);
87695 +
87696 + return assign;
87697 +}
87698 +
87699 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
87700 +{
87701 + const_gimple assign;
87702 + gimple_stmt_iterator gsi;
87703 +
87704 + if (new_rhs1 == NULL_TREE)
87705 + return NULL_TREE;
87706 +
87707 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
87708 + gsi = gsi_for_stmt(stmt);
87709 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
87710 + return gimple_get_lhs(assign);
87711 + }
87712 + return new_rhs1;
87713 +}
87714 +
87715 +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)
87716 +{
87717 + tree size_overflow_type = get_size_overflow_type(stmt, node);
87718 +
87719 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87720 +
87721 + if (new_rhs2 != NULL_TREE)
87722 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
87723 +
87724 + if (new_rhs3 != NULL_TREE)
87725 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
87726 +
87727 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
87728 +}
87729 +
87730 +
87731 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
87732 +{
87733 + tree size_overflow_type, lhs;
87734 + gimple stmt;
87735 + gimple_stmt_iterator gsi;
87736 +
87737 + if (rhs1 == NULL_TREE) {
87738 + debug_gimple_stmt(oldstmt);
87739 + error("%s: rhs1 is NULL_TREE", __func__);
87740 + gcc_unreachable();
87741 + }
87742 +
87743 + if (gimple_code(oldstmt) == GIMPLE_ASM)
87744 + lhs = rhs1;
87745 + else
87746 + lhs = gimple_get_lhs(oldstmt);
87747 +
87748 + gsi = gsi_for_stmt(oldstmt);
87749 + pointer_set_insert(visited, oldstmt);
87750 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
87751 + basic_block next_bb, cur_bb;
87752 + const_edge e;
87753 +
87754 + gcc_assert(before == false);
87755 + gcc_assert(stmt_can_throw_internal(oldstmt));
87756 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
87757 + gcc_assert(!gsi_end_p(gsi));
87758 +
87759 + cur_bb = gimple_bb(oldstmt);
87760 + next_bb = cur_bb->next_bb;
87761 + e = find_edge(cur_bb, next_bb);
87762 + gcc_assert(e != NULL);
87763 + gcc_assert(e->flags & EDGE_FALLTHRU);
87764 +
87765 + gsi = gsi_after_labels(next_bb);
87766 + gcc_assert(!gsi_end_p(gsi));
87767 +
87768 + before = true;
87769 + oldstmt = gsi_stmt(gsi);
87770 + }
87771 +
87772 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
87773 +
87774 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
87775 + gimple_set_plf(stmt, MY_STMT, true);
87776 + return gimple_get_lhs(stmt);
87777 +}
87778 +
87779 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
87780 +{
87781 + gimple stmt;
87782 + gimple_stmt_iterator gsi;
87783 + tree new_var, lhs = gimple_get_lhs(oldstmt);
87784 +
87785 + if (gimple_plf(oldstmt, MY_STMT))
87786 + return lhs;
87787 +
87788 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
87789 + rhs1 = gimple_assign_rhs1(oldstmt);
87790 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
87791 + }
87792 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
87793 + rhs2 = gimple_assign_rhs2(oldstmt);
87794 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
87795 + }
87796 +
87797 + stmt = gimple_copy(oldstmt);
87798 + gimple_set_location(stmt, gimple_location(oldstmt));
87799 + gimple_set_plf(stmt, MY_STMT, true);
87800 +
87801 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
87802 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
87803 +
87804 + if (is_bool(lhs))
87805 + new_var = SSA_NAME_VAR(lhs);
87806 + else
87807 + new_var = create_new_var(size_overflow_type);
87808 + new_var = make_ssa_name(new_var, stmt);
87809 + gimple_set_lhs(stmt, new_var);
87810 +
87811 + if (rhs1 != NULL_TREE) {
87812 + if (!gimple_assign_cast_p(oldstmt))
87813 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
87814 + gimple_assign_set_rhs1(stmt, rhs1);
87815 + }
87816 +
87817 + if (rhs2 != NULL_TREE)
87818 + gimple_assign_set_rhs2(stmt, rhs2);
87819 +#if BUILDING_GCC_VERSION >= 4007
87820 + if (rhs3 != NULL_TREE)
87821 + gimple_assign_set_rhs3(stmt, rhs3);
87822 +#endif
87823 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
87824 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
87825 +
87826 + gsi = gsi_for_stmt(oldstmt);
87827 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
87828 + update_stmt(stmt);
87829 + pointer_set_insert(visited, oldstmt);
87830 + return gimple_get_lhs(stmt);
87831 +}
87832 +
87833 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
87834 +{
87835 + basic_block bb;
87836 + gimple phi;
87837 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
87838 +
87839 + bb = gsi_bb(gsi);
87840 +
87841 + phi = create_phi_node(result, bb);
87842 + gsi = gsi_last(phi_nodes(bb));
87843 + gsi_remove(&gsi, false);
87844 +
87845 + gsi = gsi_for_stmt(oldstmt);
87846 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
87847 + gimple_set_bb(phi, bb);
87848 + gimple_set_plf(phi, MY_STMT, true);
87849 + return phi;
87850 +}
87851 +
87852 +static basic_block create_a_first_bb(void)
87853 +{
87854 + basic_block first_bb;
87855 +
87856 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87857 + if (dom_info_available_p(CDI_DOMINATORS))
87858 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
87859 + return first_bb;
87860 +}
87861 +
87862 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
87863 +{
87864 + basic_block bb;
87865 + const_gimple newstmt;
87866 + gimple_stmt_iterator gsi;
87867 + bool before = BEFORE_STMT;
87868 +
87869 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
87870 + gsi = gsi_for_stmt(get_def_stmt(arg));
87871 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
87872 + return gimple_get_lhs(newstmt);
87873 + }
87874 +
87875 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
87876 + gsi = gsi_after_labels(bb);
87877 + if (bb->index == 0) {
87878 + bb = create_a_first_bb();
87879 + gsi = gsi_start_bb(bb);
87880 + }
87881 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
87882 + return gimple_get_lhs(newstmt);
87883 +}
87884 +
87885 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
87886 +{
87887 + gimple newstmt;
87888 + gimple_stmt_iterator gsi;
87889 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
87890 + gimple def_newstmt = get_def_stmt(new_rhs);
87891 +
87892 + gsi_insert = gsi_insert_after;
87893 + gsi = gsi_for_stmt(def_newstmt);
87894 +
87895 + switch (gimple_code(get_def_stmt(arg))) {
87896 + case GIMPLE_PHI:
87897 + newstmt = gimple_build_assign(new_var, new_rhs);
87898 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
87899 + gsi_insert = gsi_insert_before;
87900 + break;
87901 + case GIMPLE_ASM:
87902 + case GIMPLE_CALL:
87903 + newstmt = gimple_build_assign(new_var, new_rhs);
87904 + break;
87905 + case GIMPLE_ASSIGN:
87906 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
87907 + break;
87908 + default:
87909 + /* unknown gimple_code (handle_build_new_phi_arg) */
87910 + gcc_unreachable();
87911 + }
87912 +
87913 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
87914 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
87915 + gimple_set_plf(newstmt, MY_STMT, true);
87916 + update_stmt(newstmt);
87917 + return newstmt;
87918 +}
87919 +
87920 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
87921 +{
87922 + const_gimple newstmt;
87923 + gimple def_stmt;
87924 + tree new_rhs;
87925 +
87926 + new_rhs = expand(visited, arg);
87927 + if (new_rhs == NULL_TREE)
87928 + return NULL_TREE;
87929 +
87930 + def_stmt = get_def_stmt(new_rhs);
87931 + if (gimple_code(def_stmt) == GIMPLE_NOP)
87932 + return NULL_TREE;
87933 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
87934 +
87935 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
87936 + return gimple_get_lhs(newstmt);
87937 +}
87938 +
87939 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
87940 +{
87941 + gimple phi, oldstmt = get_def_stmt(orig_result);
87942 + tree new_result, size_overflow_type;
87943 + unsigned int i;
87944 + unsigned int n = gimple_phi_num_args(oldstmt);
87945 +
87946 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
87947 +
87948 + new_result = create_new_var(size_overflow_type);
87949 +
87950 + pointer_set_insert(visited, oldstmt);
87951 + phi = overflow_create_phi_node(oldstmt, new_result);
87952 + for (i = 0; i < n; i++) {
87953 + tree arg, lhs;
87954 +
87955 + arg = gimple_phi_arg_def(oldstmt, i);
87956 + if (is_gimple_constant(arg))
87957 + arg = cast_a_tree(size_overflow_type, arg);
87958 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
87959 + if (lhs == NULL_TREE)
87960 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
87961 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
87962 + }
87963 +
87964 + update_stmt(phi);
87965 + return gimple_phi_result(phi);
87966 +}
87967 +
87968 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
87969 +{
87970 + const_gimple assign;
87971 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87972 + tree origtype = TREE_TYPE(orig_rhs);
87973 +
87974 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
87975 +
87976 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87977 + return gimple_get_lhs(assign);
87978 +}
87979 +
87980 +static void change_rhs1(gimple stmt, tree new_rhs1)
87981 +{
87982 + tree assign_rhs;
87983 + const_tree rhs = gimple_assign_rhs1(stmt);
87984 +
87985 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
87986 + gimple_assign_set_rhs1(stmt, assign_rhs);
87987 + update_stmt(stmt);
87988 +}
87989 +
87990 +static bool check_mode_type(const_gimple stmt)
87991 +{
87992 + const_tree lhs = gimple_get_lhs(stmt);
87993 + const_tree lhs_type = TREE_TYPE(lhs);
87994 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
87995 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
87996 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
87997 +
87998 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
87999 + return false;
88000 +
88001 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88002 + return false;
88003 +
88004 + return true;
88005 +}
88006 +
88007 +static bool check_undefined_integer_operation(const_gimple stmt)
88008 +{
88009 + const_gimple def_stmt;
88010 + const_tree lhs = gimple_get_lhs(stmt);
88011 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88012 + const_tree rhs1_type = TREE_TYPE(rhs1);
88013 + const_tree lhs_type = TREE_TYPE(lhs);
88014 +
88015 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88016 + return false;
88017 +
88018 + def_stmt = get_def_stmt(rhs1);
88019 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88020 + return false;
88021 +
88022 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88023 + return false;
88024 + return true;
88025 +}
88026 +
88027 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88028 +{
88029 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88030 + enum machine_mode lhs_mode, rhs_mode;
88031 + gimple def_stmt = get_def_stmt(no_const_rhs);
88032 +
88033 + if (!gimple_assign_cast_p(def_stmt))
88034 + return false;
88035 +
88036 + rhs1 = gimple_assign_rhs1(def_stmt);
88037 + lhs = gimple_get_lhs(def_stmt);
88038 + rhs1_type = TREE_TYPE(rhs1);
88039 + lhs_type = TREE_TYPE(lhs);
88040 + rhs_mode = TYPE_MODE(rhs1_type);
88041 + lhs_mode = TYPE_MODE(lhs_type);
88042 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88043 + return false;
88044 +
88045 + return true;
88046 +}
88047 +
88048 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88049 +{
88050 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88051 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88052 + const_tree rhs1_type = TREE_TYPE(rhs1);
88053 + const_tree lhs_type = TREE_TYPE(lhs);
88054 +
88055 + new_rhs1 = expand(visited, rhs1);
88056 +
88057 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88058 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88059 +
88060 + if (gimple_plf(stmt, MY_STMT))
88061 + return lhs;
88062 +
88063 + if (gimple_plf(stmt, NO_CAST_CHECK))
88064 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88065 +
88066 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88067 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88068 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88069 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88070 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88071 + }
88072 +
88073 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88074 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88075 +
88076 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88077 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88078 +
88079 + change_rhs1(stmt, new_rhs1);
88080 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88081 +
88082 + rhs1 = gimple_assign_rhs1(stmt);
88083 + rhs1_type = TREE_TYPE(rhs1);
88084 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88085 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88086 +
88087 + if (!check_mode_type(stmt))
88088 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88089 +
88090 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88091 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88092 +
88093 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88094 +
88095 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88096 +}
88097 +
88098 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88099 +{
88100 + gimple def_stmt = get_def_stmt(lhs);
88101 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88102 +
88103 + if (is_gimple_constant(rhs1))
88104 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88105 +
88106 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88107 + switch (TREE_CODE(rhs1)) {
88108 + case SSA_NAME:
88109 + return handle_unary_rhs(visited, def_stmt);
88110 + case ARRAY_REF:
88111 + case BIT_FIELD_REF:
88112 + case ADDR_EXPR:
88113 + case COMPONENT_REF:
88114 + case INDIRECT_REF:
88115 +#if BUILDING_GCC_VERSION >= 4006
88116 + case MEM_REF:
88117 +#endif
88118 + case PARM_DECL:
88119 + case TARGET_MEM_REF:
88120 + case VAR_DECL:
88121 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88122 +
88123 + default:
88124 + debug_gimple_stmt(def_stmt);
88125 + debug_tree(rhs1);
88126 + gcc_unreachable();
88127 + }
88128 +}
88129 +
88130 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88131 +{
88132 + gimple cond_stmt;
88133 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88134 +
88135 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88136 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88137 + update_stmt(cond_stmt);
88138 +}
88139 +
88140 +static tree create_string_param(tree string)
88141 +{
88142 + tree i_type, a_type;
88143 + const int length = TREE_STRING_LENGTH(string);
88144 +
88145 + gcc_assert(length > 0);
88146 +
88147 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88148 + a_type = build_array_type(char_type_node, i_type);
88149 +
88150 + TREE_TYPE(string) = a_type;
88151 + TREE_CONSTANT(string) = 1;
88152 + TREE_READONLY(string) = 1;
88153 +
88154 + return build1(ADDR_EXPR, ptr_type_node, string);
88155 +}
88156 +
88157 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88158 +{
88159 + gimple func_stmt;
88160 + const_gimple def_stmt;
88161 + const_tree loc_line;
88162 + tree loc_file, ssa_name, current_func;
88163 + expanded_location xloc;
88164 + char ssa_name_buf[256];
88165 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88166 +
88167 + def_stmt = get_def_stmt(arg);
88168 + xloc = expand_location(gimple_location(def_stmt));
88169 +
88170 + if (!gimple_has_location(def_stmt)) {
88171 + xloc = expand_location(gimple_location(stmt));
88172 + if (!gimple_has_location(stmt))
88173 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88174 + }
88175 +
88176 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88177 +
88178 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88179 + loc_file = create_string_param(loc_file);
88180 +
88181 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88182 + current_func = create_string_param(current_func);
88183 +
88184 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88185 + ssa_name = build_string(256, ssa_name_buf);
88186 + ssa_name = create_string_param(ssa_name);
88187 +
88188 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88189 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88190 +
88191 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88192 +}
88193 +
88194 +static void __unused print_the_code_insertions(const_gimple stmt)
88195 +{
88196 + location_t loc = gimple_location(stmt);
88197 +
88198 + inform(loc, "Integer size_overflow check applied here.");
88199 +}
88200 +
88201 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88202 +{
88203 + basic_block cond_bb, join_bb, bb_true;
88204 + edge e;
88205 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88206 +
88207 + cond_bb = gimple_bb(stmt);
88208 + if (before)
88209 + gsi_prev(&gsi);
88210 + if (gsi_end_p(gsi))
88211 + e = split_block_after_labels(cond_bb);
88212 + else
88213 + e = split_block(cond_bb, gsi_stmt(gsi));
88214 + cond_bb = e->src;
88215 + join_bb = e->dest;
88216 + e->flags = EDGE_FALSE_VALUE;
88217 + e->probability = REG_BR_PROB_BASE;
88218 +
88219 + bb_true = create_empty_bb(cond_bb);
88220 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88221 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88222 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88223 +
88224 + if (dom_info_available_p(CDI_DOMINATORS)) {
88225 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88226 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88227 + }
88228 +
88229 + if (current_loops != NULL) {
88230 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88231 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88232 + }
88233 +
88234 + insert_cond(cond_bb, arg, cond_code, type_value);
88235 + insert_cond_result(bb_true, stmt, arg, min);
88236 +
88237 +// print_the_code_insertions(stmt);
88238 +}
88239 +
88240 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88241 +{
88242 + const_tree rhs_type = TREE_TYPE(rhs);
88243 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88244 +
88245 + gcc_assert(rhs_type != NULL_TREE);
88246 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88247 + return;
88248 +
88249 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88250 +
88251 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88252 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88253 +
88254 + gcc_assert(!TREE_OVERFLOW(type_max));
88255 +
88256 + cast_rhs_type = TREE_TYPE(cast_rhs);
88257 + type_max_type = TREE_TYPE(type_max);
88258 + type_min_type = TREE_TYPE(type_min);
88259 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88260 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88261 +
88262 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88263 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88264 +}
88265 +
88266 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88267 +{
88268 + gimple change_rhs_def_stmt;
88269 + tree lhs = gimple_get_lhs(def_stmt);
88270 + tree lhs_type = TREE_TYPE(lhs);
88271 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88272 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88273 +
88274 + if (change_rhs == NULL_TREE)
88275 + return get_size_overflow_type(def_stmt, lhs);
88276 +
88277 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88278 +
88279 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88280 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88281 +
88282 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88283 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88284 +
88285 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88286 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88287 +
88288 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88289 + debug_gimple_stmt(def_stmt);
88290 + gcc_unreachable();
88291 + }
88292 +
88293 + return get_size_overflow_type(def_stmt, lhs);
88294 +}
88295 +
88296 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88297 +{
88298 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88299 + return false;
88300 + if (!is_gimple_constant(rhs))
88301 + return false;
88302 + return true;
88303 +}
88304 +
88305 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88306 +{
88307 + gimple def_stmt;
88308 +
88309 + def_stmt = get_def_stmt(new_rhs);
88310 + // get_size_overflow_type
88311 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88312 + gcc_assert(gimple_assign_cast_p(def_stmt));
88313 + return gimple_assign_rhs1(def_stmt);
88314 +}
88315 +
88316 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88317 +{
88318 + gimple_stmt_iterator gsi;
88319 + const_gimple cast_stmt;
88320 + gimple def_stmt;
88321 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88322 +
88323 + if (mode != TImode && mode != DImode) {
88324 + def_stmt = get_def_stmt(new_rhs);
88325 + gcc_assert(gimple_assign_cast_p(def_stmt));
88326 + new_rhs = gimple_assign_rhs1(def_stmt);
88327 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88328 + }
88329 +
88330 + gcc_assert(mode == TImode || mode == DImode);
88331 +
88332 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88333 + return new_rhs;
88334 +
88335 + gsi = gsi_for_stmt(stmt);
88336 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88337 + new_rhs = gimple_get_lhs(cast_stmt);
88338 +
88339 + if (mode == DImode)
88340 + return new_rhs;
88341 +
88342 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88343 +
88344 + return new_rhs;
88345 +}
88346 +
88347 +static bool is_an_integer_trunction(const_gimple stmt)
88348 +{
88349 + gimple rhs1_def_stmt, rhs2_def_stmt;
88350 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88351 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88352 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88353 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88354 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88355 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88356 +
88357 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88358 + return false;
88359 +
88360 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88361 +
88362 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88363 + return false;
88364 +
88365 + rhs1_def_stmt = get_def_stmt(rhs1);
88366 + rhs2_def_stmt = get_def_stmt(rhs2);
88367 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88368 + return false;
88369 +
88370 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88371 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88372 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88373 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88374 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88375 + return false;
88376 +
88377 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88378 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88379 + return true;
88380 +}
88381 +
88382 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88383 +{
88384 + tree new_rhs1, new_rhs2;
88385 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88386 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88387 + gimple assign, stmt = get_def_stmt(lhs);
88388 + tree rhs1 = gimple_assign_rhs1(stmt);
88389 + tree rhs2 = gimple_assign_rhs2(stmt);
88390 +
88391 + if (!is_an_integer_trunction(stmt))
88392 + return NULL_TREE;
88393 +
88394 + new_rhs1 = expand(visited, rhs1);
88395 + new_rhs2 = expand(visited, rhs2);
88396 +
88397 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88398 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88399 +
88400 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88401 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88402 +
88403 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88404 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88405 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88406 + }
88407 +
88408 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88409 + new_lhs = gimple_get_lhs(assign);
88410 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88411 +
88412 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88413 +}
88414 +
88415 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88416 +{
88417 + const_gimple def_stmt;
88418 +
88419 + if (TREE_CODE(rhs) != SSA_NAME)
88420 + return false;
88421 +
88422 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88423 + return false;
88424 +
88425 + def_stmt = get_def_stmt(rhs);
88426 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88427 + return false;
88428 +
88429 + return true;
88430 +}
88431 +
88432 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88433 +{
88434 + tree new_rhs, size_overflow_type, orig_rhs;
88435 + void (*gimple_assign_set_rhs)(gimple, tree);
88436 + tree rhs1 = gimple_assign_rhs1(stmt);
88437 + tree rhs2 = gimple_assign_rhs2(stmt);
88438 + tree lhs = gimple_get_lhs(stmt);
88439 +
88440 + if (change_rhs == NULL_TREE)
88441 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88442 +
88443 + if (new_rhs2 == NULL_TREE) {
88444 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88445 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88446 + orig_rhs = rhs1;
88447 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88448 + } else {
88449 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88450 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88451 + orig_rhs = rhs2;
88452 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88453 + }
88454 +
88455 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88456 +
88457 + if (check_overflow)
88458 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88459 +
88460 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88461 + gimple_assign_set_rhs(stmt, new_rhs);
88462 + update_stmt(stmt);
88463 +
88464 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88465 +}
88466 +
88467 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88468 +{
88469 + tree rhs1, rhs2, new_lhs;
88470 + gimple def_stmt = get_def_stmt(lhs);
88471 + tree new_rhs1 = NULL_TREE;
88472 + tree new_rhs2 = NULL_TREE;
88473 +
88474 + rhs1 = gimple_assign_rhs1(def_stmt);
88475 + rhs2 = gimple_assign_rhs2(def_stmt);
88476 +
88477 + /* no DImode/TImode division in the 32/64 bit kernel */
88478 + switch (gimple_assign_rhs_code(def_stmt)) {
88479 + case RDIV_EXPR:
88480 + case TRUNC_DIV_EXPR:
88481 + case CEIL_DIV_EXPR:
88482 + case FLOOR_DIV_EXPR:
88483 + case ROUND_DIV_EXPR:
88484 + case TRUNC_MOD_EXPR:
88485 + case CEIL_MOD_EXPR:
88486 + case FLOOR_MOD_EXPR:
88487 + case ROUND_MOD_EXPR:
88488 + case EXACT_DIV_EXPR:
88489 + case POINTER_PLUS_EXPR:
88490 + case BIT_AND_EXPR:
88491 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88492 + default:
88493 + break;
88494 + }
88495 +
88496 + new_lhs = handle_integer_truncation(visited, lhs);
88497 + if (new_lhs != NULL_TREE)
88498 + return new_lhs;
88499 +
88500 + if (TREE_CODE(rhs1) == SSA_NAME)
88501 + new_rhs1 = expand(visited, rhs1);
88502 + if (TREE_CODE(rhs2) == SSA_NAME)
88503 + new_rhs2 = expand(visited, rhs2);
88504 +
88505 + if (is_a_neg_overflow(def_stmt, rhs2))
88506 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88507 + if (is_a_neg_overflow(def_stmt, rhs1))
88508 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88509 +
88510 + if (is_a_constant_overflow(def_stmt, rhs2))
88511 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88512 + if (is_a_constant_overflow(def_stmt, rhs1))
88513 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88514 +
88515 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88516 +}
88517 +
88518 +#if BUILDING_GCC_VERSION >= 4007
88519 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88520 +{
88521 + if (is_gimple_constant(rhs))
88522 + return cast_a_tree(size_overflow_type, rhs);
88523 + if (TREE_CODE(rhs) != SSA_NAME)
88524 + return NULL_TREE;
88525 + return expand(visited, rhs);
88526 +}
88527 +
88528 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88529 +{
88530 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88531 + gimple def_stmt = get_def_stmt(lhs);
88532 +
88533 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88534 +
88535 + rhs1 = gimple_assign_rhs1(def_stmt);
88536 + rhs2 = gimple_assign_rhs2(def_stmt);
88537 + rhs3 = gimple_assign_rhs3(def_stmt);
88538 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88539 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88540 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88541 +
88542 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88543 +}
88544 +#endif
88545 +
88546 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88547 +{
88548 + const_tree type;
88549 +
88550 + gcc_assert(node != NULL_TREE);
88551 +
88552 + type = TREE_TYPE(node);
88553 +
88554 + if (gimple_plf(stmt, MY_STMT))
88555 + return TREE_TYPE(node);
88556 +
88557 + switch (TYPE_MODE(type)) {
88558 + case QImode:
88559 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88560 + case HImode:
88561 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88562 + case SImode:
88563 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88564 + case DImode:
88565 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88566 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88567 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88568 + default:
88569 + debug_tree((tree)node);
88570 + error("%s: unsupported gcc configuration.", __func__);
88571 + gcc_unreachable();
88572 + }
88573 +}
88574 +
88575 +static tree expand_visited(gimple def_stmt)
88576 +{
88577 + const_gimple next_stmt;
88578 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88579 +
88580 + gsi_next(&gsi);
88581 + next_stmt = gsi_stmt(gsi);
88582 +
88583 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88584 +
88585 + switch (gimple_code(next_stmt)) {
88586 + case GIMPLE_ASSIGN:
88587 + return gimple_get_lhs(next_stmt);
88588 + case GIMPLE_PHI:
88589 + return gimple_phi_result(next_stmt);
88590 + case GIMPLE_CALL:
88591 + return gimple_call_lhs(next_stmt);
88592 + default:
88593 + return NULL_TREE;
88594 + }
88595 +}
88596 +
88597 +static tree expand(struct pointer_set_t *visited, tree lhs)
88598 +{
88599 + gimple def_stmt;
88600 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
88601 +
88602 + if (is_gimple_constant(lhs))
88603 + return NULL_TREE;
88604 +
88605 + if (TREE_CODE(lhs) == ADDR_EXPR)
88606 + return NULL_TREE;
88607 +
88608 + if (code == REAL_TYPE)
88609 + return NULL_TREE;
88610 +
88611 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
88612 +
88613 +
88614 + def_stmt = get_def_stmt(lhs);
88615 +
88616 + if (!def_stmt)
88617 + return NULL_TREE;
88618 +
88619 + if (gimple_plf(def_stmt, MY_STMT))
88620 + return lhs;
88621 +
88622 + if (pointer_set_contains(visited, def_stmt))
88623 + return expand_visited(def_stmt);
88624 +
88625 + switch (gimple_code(def_stmt)) {
88626 + case GIMPLE_NOP:
88627 + return NULL_TREE;
88628 + case GIMPLE_PHI:
88629 + return build_new_phi(visited, lhs);
88630 + case GIMPLE_CALL:
88631 + case GIMPLE_ASM:
88632 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88633 + case GIMPLE_ASSIGN:
88634 + switch (gimple_num_ops(def_stmt)) {
88635 + case 2:
88636 + return handle_unary_ops(visited, lhs);
88637 + case 3:
88638 + return handle_binary_ops(visited, lhs);
88639 +#if BUILDING_GCC_VERSION >= 4007
88640 + case 4:
88641 + return handle_ternary_ops(visited, lhs);
88642 +#endif
88643 + }
88644 + default:
88645 + debug_gimple_stmt(def_stmt);
88646 + error("%s: unknown gimple code", __func__);
88647 + gcc_unreachable();
88648 + }
88649 +}
88650 +
88651 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
88652 +{
88653 + const_gimple assign;
88654 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88655 + tree origtype = TREE_TYPE(origarg);
88656 +
88657 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
88658 +
88659 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88660 +
88661 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
88662 + update_stmt(stmt);
88663 +}
88664 +
88665 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
88666 +{
88667 + const char *origid;
88668 + tree arg;
88669 + const_tree origarg;
88670 +
88671 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
88672 + return true;
88673 +
88674 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
88675 + while (origarg && *argnum) {
88676 + (*argnum)--;
88677 + origarg = TREE_CHAIN(origarg);
88678 + }
88679 +
88680 + gcc_assert(*argnum == 0);
88681 +
88682 + gcc_assert(origarg != NULL_TREE);
88683 + origid = NAME(origarg);
88684 + *argnum = 0;
88685 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
88686 + if (!strcmp(origid, NAME(arg)))
88687 + return true;
88688 + (*argnum)++;
88689 + }
88690 + return false;
88691 +}
88692 +
88693 +static bool skip_types(const_tree var)
88694 +{
88695 + switch (TREE_CODE(var)) {
88696 + case ADDR_EXPR:
88697 +#if BUILDING_GCC_VERSION >= 4006
88698 + case MEM_REF:
88699 +#endif
88700 + case ARRAY_REF:
88701 + case BIT_FIELD_REF:
88702 + case INDIRECT_REF:
88703 + case TARGET_MEM_REF:
88704 + case VAR_DECL:
88705 + return true;
88706 + default:
88707 + break;
88708 + }
88709 + return false;
88710 +}
88711 +
88712 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
88713 +{
88714 + gimple phi = get_def_stmt(result);
88715 + unsigned int i, n = gimple_phi_num_args(phi);
88716 +
88717 + if (!phi)
88718 + return false;
88719 +
88720 + pointer_set_insert(visited, phi);
88721 + for (i = 0; i < n; i++) {
88722 + const_tree arg = gimple_phi_arg_def(phi, i);
88723 + if (pre_expand(visited, arg))
88724 + return true;
88725 + }
88726 + return false;
88727 +}
88728 +
88729 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
88730 +{
88731 + gimple def_stmt = get_def_stmt(lhs);
88732 + const_tree rhs;
88733 +
88734 + if (!def_stmt)
88735 + return false;
88736 +
88737 + rhs = gimple_assign_rhs1(def_stmt);
88738 + if (pre_expand(visited, rhs))
88739 + return true;
88740 + return false;
88741 +}
88742 +
88743 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
88744 +{
88745 + bool rhs1_found, rhs2_found;
88746 + gimple def_stmt = get_def_stmt(lhs);
88747 + const_tree rhs1, rhs2;
88748 +
88749 + if (!def_stmt)
88750 + return false;
88751 +
88752 + rhs1 = gimple_assign_rhs1(def_stmt);
88753 + rhs2 = gimple_assign_rhs2(def_stmt);
88754 + rhs1_found = pre_expand(visited, rhs1);
88755 + rhs2_found = pre_expand(visited, rhs2);
88756 +
88757 + return rhs1_found || rhs2_found;
88758 +}
88759 +
88760 +static const_tree search_field_decl(const_tree comp_ref)
88761 +{
88762 + const_tree field = NULL_TREE;
88763 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
88764 +
88765 + for (i = 0; i < len; i++) {
88766 + field = TREE_OPERAND(comp_ref, i);
88767 + if (TREE_CODE(field) == FIELD_DECL)
88768 + break;
88769 + }
88770 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
88771 + return field;
88772 +}
88773 +
88774 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
88775 +{
88776 + const_tree attr, p;
88777 +
88778 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
88779 + if (!attr || !TREE_VALUE(attr))
88780 + return MARKED_NO;
88781 +
88782 + p = TREE_VALUE(attr);
88783 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
88784 + return MARKED_NOT_INTENTIONAL;
88785 +
88786 + do {
88787 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
88788 + return MARKED_YES;
88789 + p = TREE_CHAIN(p);
88790 + } while (p);
88791 +
88792 + return MARKED_NO;
88793 +}
88794 +
88795 +static void print_missing_msg(tree func, unsigned int argnum)
88796 +{
88797 + unsigned int new_hash;
88798 + size_t len;
88799 + unsigned char tree_codes[CODES_LIMIT];
88800 + location_t loc = DECL_SOURCE_LOCATION(func);
88801 + const char *curfunc = get_asm_name(func);
88802 +
88803 + len = get_function_decl(func, tree_codes);
88804 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
88805 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
88806 +}
88807 +
88808 +static unsigned int search_missing_attribute(const_tree arg)
88809 +{
88810 + const_tree type = TREE_TYPE(arg);
88811 + tree func = get_original_function_decl(current_function_decl);
88812 + unsigned int argnum;
88813 + const struct size_overflow_hash *hash;
88814 +
88815 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
88816 +
88817 + if (TREE_CODE(type) == POINTER_TYPE)
88818 + return 0;
88819 +
88820 + argnum = find_arg_number(arg, func);
88821 + if (argnum == 0)
88822 + return 0;
88823 +
88824 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
88825 + return argnum;
88826 +
88827 + hash = get_function_hash(func);
88828 + if (!hash || !(hash->param & (1U << argnum))) {
88829 + print_missing_msg(func, argnum);
88830 + return 0;
88831 + }
88832 + return argnum;
88833 +}
88834 +
88835 +static bool is_already_marked(const_tree lhs)
88836 +{
88837 + unsigned int argnum;
88838 + const_tree fndecl;
88839 +
88840 + argnum = search_missing_attribute(lhs);
88841 + fndecl = get_original_function_decl(current_function_decl);
88842 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
88843 + return true;
88844 + return false;
88845 +}
88846 +
88847 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
88848 +{
88849 + const_gimple def_stmt;
88850 +
88851 + if (is_gimple_constant(lhs))
88852 + return false;
88853 +
88854 + if (skip_types(lhs))
88855 + return false;
88856 +
88857 + if (TREE_CODE(lhs) == PARM_DECL)
88858 + return is_already_marked(lhs);
88859 +
88860 + if (TREE_CODE(lhs) == COMPONENT_REF) {
88861 + const_tree field, attr;
88862 +
88863 + field = search_field_decl(lhs);
88864 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
88865 + if (!attr || !TREE_VALUE(attr))
88866 + return false;
88867 + return true;
88868 + }
88869 +
88870 + def_stmt = get_def_stmt(lhs);
88871 +
88872 + if (!def_stmt)
88873 + return false;
88874 +
88875 + if (pointer_set_contains(visited, def_stmt))
88876 + return false;
88877 +
88878 + switch (gimple_code(def_stmt)) {
88879 + case GIMPLE_NOP:
88880 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
88881 + return is_already_marked(lhs);
88882 + return false;
88883 + case GIMPLE_PHI:
88884 + return walk_phi(visited, lhs);
88885 + case GIMPLE_CALL:
88886 + case GIMPLE_ASM:
88887 + return false;
88888 + case GIMPLE_ASSIGN:
88889 + switch (gimple_num_ops(def_stmt)) {
88890 + case 2:
88891 + return walk_unary_ops(visited, lhs);
88892 + case 3:
88893 + return walk_binary_ops(visited, lhs);
88894 + }
88895 + default:
88896 + debug_gimple_stmt((gimple)def_stmt);
88897 + error("%s: unknown gimple code", __func__);
88898 + gcc_unreachable();
88899 + }
88900 +}
88901 +
88902 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
88903 +{
88904 + struct pointer_set_t *visited;
88905 + bool is_found;
88906 + enum marked is_marked;
88907 + location_t loc;
88908 +
88909 + visited = pointer_set_create();
88910 + is_found = pre_expand(visited, arg);
88911 + pointer_set_destroy(visited);
88912 +
88913 + is_marked = mark_status(fndecl, argnum + 1);
88914 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
88915 + return true;
88916 +
88917 + if (is_found) {
88918 + loc = DECL_SOURCE_LOCATION(fndecl);
88919 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
88920 + return true;
88921 + }
88922 + return false;
88923 +}
88924 +
88925 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
88926 +{
88927 + struct pointer_set_t *visited;
88928 + tree arg, newarg;
88929 + bool match;
88930 +
88931 + match = get_function_arg(&argnum, fndecl);
88932 + if (!match)
88933 + return;
88934 + gcc_assert(gimple_call_num_args(stmt) > argnum);
88935 + arg = gimple_call_arg(stmt, argnum);
88936 + if (arg == NULL_TREE)
88937 + return;
88938 +
88939 + if (is_gimple_constant(arg))
88940 + return;
88941 +
88942 + if (search_attributes(fndecl, arg, argnum))
88943 + return;
88944 +
88945 + if (TREE_CODE(arg) != SSA_NAME)
88946 + return;
88947 +
88948 + check_arg_type(arg);
88949 +
88950 + visited = pointer_set_create();
88951 + newarg = expand(visited, arg);
88952 + pointer_set_destroy(visited);
88953 +
88954 + if (newarg == NULL_TREE)
88955 + return;
88956 +
88957 + change_function_arg(stmt, arg, argnum, newarg);
88958 +
88959 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
88960 +}
88961 +
88962 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
88963 +{
88964 + tree p = TREE_VALUE(attr);
88965 + do {
88966 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
88967 + p = TREE_CHAIN(p);
88968 + } while (p);
88969 +}
88970 +
88971 +static void handle_function_by_hash(gimple stmt, tree fndecl)
88972 +{
88973 + tree orig_fndecl;
88974 + unsigned int num;
88975 + const struct size_overflow_hash *hash;
88976 +
88977 + orig_fndecl = get_original_function_decl(fndecl);
88978 + if (C_DECL_IMPLICIT(orig_fndecl))
88979 + return;
88980 + hash = get_function_hash(orig_fndecl);
88981 + if (!hash)
88982 + return;
88983 +
88984 + for (num = 1; num <= MAX_PARAM; num++)
88985 + if (hash->param & (1U << num))
88986 + handle_function_arg(stmt, fndecl, num - 1);
88987 +}
88988 +
88989 +static void set_plf_false(void)
88990 +{
88991 + basic_block bb;
88992 +
88993 + FOR_ALL_BB(bb) {
88994 + gimple_stmt_iterator si;
88995 +
88996 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
88997 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
88998 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
88999 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89000 + }
89001 +}
89002 +
89003 +static unsigned int handle_function(void)
89004 +{
89005 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89006 +
89007 + set_plf_false();
89008 +
89009 + do {
89010 + gimple_stmt_iterator gsi;
89011 + next = bb->next_bb;
89012 +
89013 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89014 + tree fndecl, attr;
89015 + gimple stmt = gsi_stmt(gsi);
89016 +
89017 + if (!(is_gimple_call(stmt)))
89018 + continue;
89019 + fndecl = gimple_call_fndecl(stmt);
89020 + if (fndecl == NULL_TREE)
89021 + continue;
89022 + if (gimple_call_num_args(stmt) == 0)
89023 + continue;
89024 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89025 + if (!attr || !TREE_VALUE(attr))
89026 + handle_function_by_hash(stmt, fndecl);
89027 + else
89028 + handle_function_by_attribute(stmt, attr, fndecl);
89029 + gsi = gsi_for_stmt(stmt);
89030 + next = gimple_bb(stmt)->next_bb;
89031 + }
89032 + bb = next;
89033 + } while (bb);
89034 + return 0;
89035 +}
89036 +
89037 +static struct gimple_opt_pass size_overflow_pass = {
89038 + .pass = {
89039 + .type = GIMPLE_PASS,
89040 + .name = "size_overflow",
89041 + .gate = NULL,
89042 + .execute = handle_function,
89043 + .sub = NULL,
89044 + .next = NULL,
89045 + .static_pass_number = 0,
89046 + .tv_id = TV_NONE,
89047 + .properties_required = PROP_cfg | PROP_referenced_vars,
89048 + .properties_provided = 0,
89049 + .properties_destroyed = 0,
89050 + .todo_flags_start = 0,
89051 + .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
89052 + }
89053 +};
89054 +
89055 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89056 +{
89057 + tree fntype;
89058 +
89059 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89060 +
89061 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89062 + fntype = build_function_type_list(void_type_node,
89063 + const_char_ptr_type_node,
89064 + unsigned_type_node,
89065 + const_char_ptr_type_node,
89066 + const_char_ptr_type_node,
89067 + NULL_TREE);
89068 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89069 +
89070 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89071 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89072 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89073 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89074 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89075 +}
89076 +
89077 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89078 +{
89079 + int i;
89080 + const char * const plugin_name = plugin_info->base_name;
89081 + const int argc = plugin_info->argc;
89082 + const struct plugin_argument * const argv = plugin_info->argv;
89083 + bool enable = true;
89084 +
89085 + struct register_pass_info size_overflow_pass_info = {
89086 + .pass = &size_overflow_pass.pass,
89087 + .reference_pass_name = "ssa",
89088 + .ref_pass_instance_number = 1,
89089 + .pos_op = PASS_POS_INSERT_AFTER
89090 + };
89091 +
89092 + if (!plugin_default_version_check(version, &gcc_version)) {
89093 + error(G_("incompatible gcc/plugin versions"));
89094 + return 1;
89095 + }
89096 +
89097 + for (i = 0; i < argc; ++i) {
89098 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89099 + enable = false;
89100 + continue;
89101 + }
89102 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89103 + }
89104 +
89105 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89106 + if (enable) {
89107 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89108 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89109 + }
89110 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89111 +
89112 + return 0;
89113 +}
89114 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89115 new file mode 100644
89116 index 0000000..38d2014
89117 --- /dev/null
89118 +++ b/tools/gcc/stackleak_plugin.c
89119 @@ -0,0 +1,313 @@
89120 +/*
89121 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89122 + * Licensed under the GPL v2
89123 + *
89124 + * Note: the choice of the license means that the compilation process is
89125 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89126 + * but for the kernel it doesn't matter since it doesn't link against
89127 + * any of the gcc libraries
89128 + *
89129 + * gcc plugin to help implement various PaX features
89130 + *
89131 + * - track lowest stack pointer
89132 + *
89133 + * TODO:
89134 + * - initialize all local variables
89135 + *
89136 + * BUGS:
89137 + * - none known
89138 + */
89139 +#include "gcc-plugin.h"
89140 +#include "config.h"
89141 +#include "system.h"
89142 +#include "coretypes.h"
89143 +#include "tree.h"
89144 +#include "tree-pass.h"
89145 +#include "flags.h"
89146 +#include "intl.h"
89147 +#include "toplev.h"
89148 +#include "plugin.h"
89149 +//#include "expr.h" where are you...
89150 +#include "diagnostic.h"
89151 +#include "plugin-version.h"
89152 +#include "tm.h"
89153 +#include "function.h"
89154 +#include "basic-block.h"
89155 +#include "gimple.h"
89156 +#include "rtl.h"
89157 +#include "emit-rtl.h"
89158 +
89159 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89160 +
89161 +int plugin_is_GPL_compatible;
89162 +
89163 +static int track_frame_size = -1;
89164 +static const char track_function[] = "pax_track_stack";
89165 +static const char check_function[] = "pax_check_alloca";
89166 +static bool init_locals;
89167 +
89168 +static struct plugin_info stackleak_plugin_info = {
89169 + .version = "201203140940",
89170 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89171 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89172 +};
89173 +
89174 +static bool gate_stackleak_track_stack(void);
89175 +static unsigned int execute_stackleak_tree_instrument(void);
89176 +static unsigned int execute_stackleak_final(void);
89177 +
89178 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89179 + .pass = {
89180 + .type = GIMPLE_PASS,
89181 + .name = "stackleak_tree_instrument",
89182 + .gate = gate_stackleak_track_stack,
89183 + .execute = execute_stackleak_tree_instrument,
89184 + .sub = NULL,
89185 + .next = NULL,
89186 + .static_pass_number = 0,
89187 + .tv_id = TV_NONE,
89188 + .properties_required = PROP_gimple_leh | PROP_cfg,
89189 + .properties_provided = 0,
89190 + .properties_destroyed = 0,
89191 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89192 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89193 + }
89194 +};
89195 +
89196 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89197 + .pass = {
89198 + .type = RTL_PASS,
89199 + .name = "stackleak_final",
89200 + .gate = gate_stackleak_track_stack,
89201 + .execute = execute_stackleak_final,
89202 + .sub = NULL,
89203 + .next = NULL,
89204 + .static_pass_number = 0,
89205 + .tv_id = TV_NONE,
89206 + .properties_required = 0,
89207 + .properties_provided = 0,
89208 + .properties_destroyed = 0,
89209 + .todo_flags_start = 0,
89210 + .todo_flags_finish = TODO_dump_func
89211 + }
89212 +};
89213 +
89214 +static bool gate_stackleak_track_stack(void)
89215 +{
89216 + return track_frame_size >= 0;
89217 +}
89218 +
89219 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89220 +{
89221 + gimple check_alloca;
89222 + tree fntype, fndecl, alloca_size;
89223 +
89224 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89225 + fndecl = build_fn_decl(check_function, fntype);
89226 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89227 +
89228 + // insert call to void pax_check_alloca(unsigned long size)
89229 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89230 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89231 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89232 +}
89233 +
89234 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89235 +{
89236 + gimple track_stack;
89237 + tree fntype, fndecl;
89238 +
89239 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89240 + fndecl = build_fn_decl(track_function, fntype);
89241 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89242 +
89243 + // insert call to void pax_track_stack(void)
89244 + track_stack = gimple_build_call(fndecl, 0);
89245 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89246 +}
89247 +
89248 +#if BUILDING_GCC_VERSION == 4005
89249 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89250 +{
89251 + tree fndecl;
89252 +
89253 + if (!is_gimple_call(stmt))
89254 + return false;
89255 + fndecl = gimple_call_fndecl(stmt);
89256 + if (!fndecl)
89257 + return false;
89258 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89259 + return false;
89260 +// print_node(stderr, "pax", fndecl, 4);
89261 + return DECL_FUNCTION_CODE(fndecl) == code;
89262 +}
89263 +#endif
89264 +
89265 +static bool is_alloca(gimple stmt)
89266 +{
89267 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89268 + return true;
89269 +
89270 +#if BUILDING_GCC_VERSION >= 4007
89271 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89272 + return true;
89273 +#endif
89274 +
89275 + return false;
89276 +}
89277 +
89278 +static unsigned int execute_stackleak_tree_instrument(void)
89279 +{
89280 + basic_block bb, entry_bb;
89281 + bool prologue_instrumented = false, is_leaf = true;
89282 +
89283 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89284 +
89285 + // 1. loop through BBs and GIMPLE statements
89286 + FOR_EACH_BB(bb) {
89287 + gimple_stmt_iterator gsi;
89288 +
89289 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89290 + gimple stmt;
89291 +
89292 + stmt = gsi_stmt(gsi);
89293 +
89294 + if (is_gimple_call(stmt))
89295 + is_leaf = false;
89296 +
89297 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89298 + if (!is_alloca(stmt))
89299 + continue;
89300 +
89301 + // 2. insert stack overflow check before each __builtin_alloca call
89302 + stackleak_check_alloca(&gsi);
89303 +
89304 + // 3. insert track call after each __builtin_alloca call
89305 + stackleak_add_instrumentation(&gsi);
89306 + if (bb == entry_bb)
89307 + prologue_instrumented = true;
89308 + }
89309 + }
89310 +
89311 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89312 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89313 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89314 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89315 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89316 + return 0;
89317 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89318 + return 0;
89319 +
89320 + // 4. insert track call at the beginning
89321 + if (!prologue_instrumented) {
89322 + gimple_stmt_iterator gsi;
89323 +
89324 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89325 + if (dom_info_available_p(CDI_DOMINATORS))
89326 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89327 + gsi = gsi_start_bb(bb);
89328 + stackleak_add_instrumentation(&gsi);
89329 + }
89330 +
89331 + return 0;
89332 +}
89333 +
89334 +static unsigned int execute_stackleak_final(void)
89335 +{
89336 + rtx insn;
89337 +
89338 + if (cfun->calls_alloca)
89339 + return 0;
89340 +
89341 + // keep calls only if function frame is big enough
89342 + if (get_frame_size() >= track_frame_size)
89343 + return 0;
89344 +
89345 + // 1. find pax_track_stack calls
89346 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89347 + // 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))
89348 + rtx body;
89349 +
89350 + if (!CALL_P(insn))
89351 + continue;
89352 + body = PATTERN(insn);
89353 + if (GET_CODE(body) != CALL)
89354 + continue;
89355 + body = XEXP(body, 0);
89356 + if (GET_CODE(body) != MEM)
89357 + continue;
89358 + body = XEXP(body, 0);
89359 + if (GET_CODE(body) != SYMBOL_REF)
89360 + continue;
89361 + if (strcmp(XSTR(body, 0), track_function))
89362 + continue;
89363 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89364 + // 2. delete call
89365 + insn = delete_insn_and_edges(insn);
89366 +#if BUILDING_GCC_VERSION >= 4007
89367 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89368 + insn = delete_insn_and_edges(insn);
89369 +#endif
89370 + }
89371 +
89372 +// print_simple_rtl(stderr, get_insns());
89373 +// print_rtl(stderr, get_insns());
89374 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89375 +
89376 + return 0;
89377 +}
89378 +
89379 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89380 +{
89381 + const char * const plugin_name = plugin_info->base_name;
89382 + const int argc = plugin_info->argc;
89383 + const struct plugin_argument * const argv = plugin_info->argv;
89384 + int i;
89385 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89386 + .pass = &stackleak_tree_instrument_pass.pass,
89387 +// .reference_pass_name = "tree_profile",
89388 + .reference_pass_name = "optimized",
89389 + .ref_pass_instance_number = 1,
89390 + .pos_op = PASS_POS_INSERT_BEFORE
89391 + };
89392 + struct register_pass_info stackleak_final_pass_info = {
89393 + .pass = &stackleak_final_rtl_opt_pass.pass,
89394 + .reference_pass_name = "final",
89395 + .ref_pass_instance_number = 1,
89396 + .pos_op = PASS_POS_INSERT_BEFORE
89397 + };
89398 +
89399 + if (!plugin_default_version_check(version, &gcc_version)) {
89400 + error(G_("incompatible gcc/plugin versions"));
89401 + return 1;
89402 + }
89403 +
89404 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89405 +
89406 + for (i = 0; i < argc; ++i) {
89407 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89408 + if (!argv[i].value) {
89409 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89410 + continue;
89411 + }
89412 + track_frame_size = atoi(argv[i].value);
89413 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89414 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89415 + continue;
89416 + }
89417 + if (!strcmp(argv[i].key, "initialize-locals")) {
89418 + if (argv[i].value) {
89419 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89420 + continue;
89421 + }
89422 + init_locals = true;
89423 + continue;
89424 + }
89425 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89426 + }
89427 +
89428 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89429 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89430 +
89431 + return 0;
89432 +}
89433 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89434 index 6789d78..4afd019e 100644
89435 --- a/tools/perf/util/include/asm/alternative-asm.h
89436 +++ b/tools/perf/util/include/asm/alternative-asm.h
89437 @@ -5,4 +5,7 @@
89438
89439 #define altinstruction_entry #
89440
89441 + .macro pax_force_retaddr rip=0, reload=0
89442 + .endm
89443 +
89444 #endif
89445 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
89446 index af0f22f..9a7d479 100644
89447 --- a/usr/gen_init_cpio.c
89448 +++ b/usr/gen_init_cpio.c
89449 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
89450 int retval;
89451 int rc = -1;
89452 int namesize;
89453 - int i;
89454 + unsigned int i;
89455
89456 mode |= S_IFREG;
89457
89458 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
89459 *env_var = *expanded = '\0';
89460 strncat(env_var, start + 2, end - start - 2);
89461 strncat(expanded, new_location, start - new_location);
89462 - strncat(expanded, getenv(env_var), PATH_MAX);
89463 - strncat(expanded, end + 1, PATH_MAX);
89464 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
89465 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
89466 strncpy(new_location, expanded, PATH_MAX);
89467 + new_location[PATH_MAX] = 0;
89468 } else
89469 break;
89470 }
89471 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89472 index d617f69..6b445d2 100644
89473 --- a/virt/kvm/kvm_main.c
89474 +++ b/virt/kvm/kvm_main.c
89475 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89476
89477 static cpumask_var_t cpus_hardware_enabled;
89478 static int kvm_usage_count = 0;
89479 -static atomic_t hardware_enable_failed;
89480 +static atomic_unchecked_t hardware_enable_failed;
89481
89482 struct kmem_cache *kvm_vcpu_cache;
89483 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89484 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89485 /* We can read the guest memory with __xxx_user() later on. */
89486 if (user_alloc &&
89487 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89488 - !access_ok(VERIFY_WRITE,
89489 + !__access_ok(VERIFY_WRITE,
89490 (void __user *)(unsigned long)mem->userspace_addr,
89491 mem->memory_size)))
89492 goto out;
89493 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89494
89495 if (r) {
89496 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89497 - atomic_inc(&hardware_enable_failed);
89498 + atomic_inc_unchecked(&hardware_enable_failed);
89499 printk(KERN_INFO "kvm: enabling virtualization on "
89500 "CPU%d failed\n", cpu);
89501 }
89502 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89503
89504 kvm_usage_count++;
89505 if (kvm_usage_count == 1) {
89506 - atomic_set(&hardware_enable_failed, 0);
89507 + atomic_set_unchecked(&hardware_enable_failed, 0);
89508 on_each_cpu(hardware_enable_nolock, NULL, 1);
89509
89510 - if (atomic_read(&hardware_enable_failed)) {
89511 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89512 hardware_disable_all_nolock();
89513 r = -EBUSY;
89514 }
89515 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89516 kvm_arch_vcpu_put(vcpu);
89517 }
89518
89519 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89520 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89521 struct module *module)
89522 {
89523 int r;
89524 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89525 if (!vcpu_align)
89526 vcpu_align = __alignof__(struct kvm_vcpu);
89527 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89528 - 0, NULL);
89529 + SLAB_USERCOPY, NULL);
89530 if (!kvm_vcpu_cache) {
89531 r = -ENOMEM;
89532 goto out_free_3;
89533 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89534 if (r)
89535 goto out_free;
89536
89537 - kvm_chardev_ops.owner = module;
89538 - kvm_vm_fops.owner = module;
89539 - kvm_vcpu_fops.owner = module;
89540 + pax_open_kernel();
89541 + *(void **)&kvm_chardev_ops.owner = module;
89542 + *(void **)&kvm_vm_fops.owner = module;
89543 + *(void **)&kvm_vcpu_fops.owner = module;
89544 + pax_close_kernel();
89545
89546 r = misc_register(&kvm_dev);
89547 if (r) {